Skip to content
Permalink
Browse files

Add a delay setting to Startup Manager

Fixed issue #127
- capplet/gsm-app-dialog.c
- capplet/gsm-app-dialog.h
- capplet/gsm-properties-dialog.c
- capplet/gsp-app.c
- capplet/gsp-app.h
- capplet/gsp-keyfile.h
- data/session-properties.ui
  • Loading branch information...
yetist authored and lukefromdc committed Dec 14, 2018
1 parent 34ef232 commit 0e2eb8a311586599bbd3937d413da2f78eedb4d6
@@ -33,6 +33,7 @@
#define CAPPLET_NAME_ENTRY_WIDGET_NAME "session_properties_name_entry"
#define CAPPLET_COMMAND_ENTRY_WIDGET_NAME "session_properties_command_entry"
#define CAPPLET_COMMENT_ENTRY_WIDGET_NAME "session_properties_comment_entry"
#define CAPPLET_DELAY_SPIN_WIDGET_NAME "session_properties_delay_spin"
#define CAPPLET_BROWSE_WIDGET_NAME "session_properties_browse_button"

#ifdef __GNUC__
@@ -47,10 +48,12 @@ struct _GsmAppDialog
GtkWidget *name_entry;
GtkWidget *command_entry;
GtkWidget *comment_entry;
GtkWidget *delay_spin;
GtkWidget *browse_button;
char *name;
char *command;
char *comment;
guint delay;
};

static void gsm_app_dialog_class_init (GsmAppDialogClass *klass);
@@ -60,7 +63,8 @@ enum {
PROP_0,
PROP_NAME,
PROP_COMMAND,
PROP_COMMENT
PROP_COMMENT,
PROP_DELAY
};

G_DEFINE_TYPE (GsmAppDialog, gsm_app_dialog, GTK_TYPE_DIALOG)
@@ -151,6 +155,24 @@ on_entry_activate (GtkEntry *entry,
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
}

static gboolean
on_spin_output (GtkSpinButton *spin, GsmAppDialog *dialog)
{
GtkAdjustment *adjustment;
gchar *text;
int value;

adjustment = gtk_spin_button_get_adjustment (spin);
value = gtk_adjustment_get_value (adjustment);
dialog->delay = value;

text = g_strdup_printf (_("%d s"), value);
gtk_entry_set_text (GTK_ENTRY (spin), text);
g_free (text);

return TRUE;
}

static void
setup_dialog (GsmAppDialog *dialog)
{
@@ -237,6 +259,17 @@ setup_dialog (GsmAppDialog *dialog)
gtk_entry_set_text (GTK_ENTRY (dialog->comment_entry), dialog->comment);
}

dialog->delay_spin = GTK_WIDGET(gtk_builder_get_object (xml, CAPPLET_DELAY_SPIN_WIDGET_NAME));
g_signal_connect (dialog->delay_spin,
"output",
G_CALLBACK (on_spin_output),
dialog);
if (dialog->delay > 0) {
GtkAdjustment *adjustment;
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(dialog->delay_spin));
gtk_adjustment_set_value (adjustment, (gdouble) dialog->delay);
}

if (xml != NULL) {
g_object_unref (xml);
}
@@ -314,6 +347,16 @@ gsm_app_dialog_set_comment (GsmAppDialog *dialog,
g_object_notify (G_OBJECT (dialog), "comment");
}

static void
gsm_app_dialog_set_delay (GsmAppDialog *dialog,
guint delay)
{
g_return_if_fail (GSM_IS_APP_DIALOG (dialog));

dialog->delay = delay;
g_object_notify (G_OBJECT (dialog), "delay");
}

const char *
gsm_app_dialog_get_name (GsmAppDialog *dialog)
{
@@ -335,6 +378,13 @@ gsm_app_dialog_get_comment (GsmAppDialog *dialog)
return gtk_entry_get_text (GTK_ENTRY (dialog->comment_entry));
}

guint
gsm_app_dialog_get_delay (GsmAppDialog *dialog)
{
g_return_val_if_fail (GSM_IS_APP_DIALOG (dialog), 0);
return dialog->delay;
}

static void
gsm_app_dialog_set_property (GObject *object,
guint prop_id,
@@ -353,6 +403,9 @@ gsm_app_dialog_set_property (GObject *object,
case PROP_COMMENT:
gsm_app_dialog_set_comment (dialog, g_value_get_string (value));
break;
case PROP_DELAY:
gsm_app_dialog_set_delay (dialog, g_value_get_uint (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -377,6 +430,9 @@ gsm_app_dialog_get_property (GObject *object,
case PROP_COMMENT:
g_value_set_string (value, dialog->comment);
break;
case PROP_DELAY:
g_value_set_uint (value, dialog->delay);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -414,6 +470,15 @@ gsm_app_dialog_class_init (GsmAppDialogClass *klass)
"comment",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_DELAY,
g_param_spec_uint ("delay",
"delay",
"delay",
0,
100,
0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}

static void
@@ -425,14 +490,16 @@ gsm_app_dialog_init (GsmAppDialog *dialog)
GtkWidget *
gsm_app_dialog_new (const char *name,
const char *command,
const char *comment)
const char *comment,
guint delay)
{
GObject *object;

object = g_object_new (GSM_TYPE_APP_DIALOG,
"name", name,
"command", command,
"comment", comment,
"delay", delay,
NULL);

return GTK_WIDGET (object);
@@ -442,7 +509,8 @@ gboolean
gsm_app_dialog_run (GsmAppDialog *dialog,
char **name_p,
char **command_p,
char **comment_p)
char **comment_p,
guint *delay_p)
{
gboolean retval;

@@ -452,6 +520,7 @@ gsm_app_dialog_run (GsmAppDialog *dialog,
const char *name;
const char *exec;
const char *comment;
guint delay;
const char *error_msg;
GError *error;
char **argv;
@@ -460,6 +529,7 @@ gsm_app_dialog_run (GsmAppDialog *dialog,
name = gsm_app_dialog_get_name (GSM_APP_DIALOG (dialog));
exec = gsm_app_dialog_get_command (GSM_APP_DIALOG (dialog));
comment = gsm_app_dialog_get_comment (GSM_APP_DIALOG (dialog));
delay = gsm_app_dialog_get_delay (GSM_APP_DIALOG (dialog));

error = NULL;
error_msg = NULL;
@@ -514,6 +584,10 @@ gsm_app_dialog_run (GsmAppDialog *dialog,
*comment_p = g_strdup (comment);
}

if (delay_p) {
*delay_p = delay;
}

retval = TRUE;
break;
}
@@ -31,16 +31,19 @@ G_DECLARE_FINAL_TYPE (GsmAppDialog, gsm_app_dialog, GSM, APP_DIALOG, GtkDialog)

GtkWidget * gsm_app_dialog_new (const char *name,
const char *command,
const char *comment);
const char *comment,
guint delay);

gboolean gsm_app_dialog_run (GsmAppDialog *dialog,
char **name_p,
char **command_p,
char **comment_p);
char **comment_p,
guint *delay);

const char * gsm_app_dialog_get_name (GsmAppDialog *dialog);
const char * gsm_app_dialog_get_command (GsmAppDialog *dialog);
const char * gsm_app_dialog_get_comment (GsmAppDialog *dialog);
guint gsm_app_dialog_get_delay (GsmAppDialog *dialog);

G_END_DECLS

@@ -361,14 +361,15 @@ on_add_app_clicked (GtkWidget *widget,
char *name;
char *exec;
char *comment;
guint delay;

add_dialog = gsm_app_dialog_new (NULL, NULL, NULL);
add_dialog = gsm_app_dialog_new (NULL, NULL, NULL, 0);
gtk_window_set_transient_for (GTK_WINDOW (add_dialog),
GTK_WINDOW (dialog));

if (gsm_app_dialog_run (GSM_APP_DIALOG (add_dialog),
&name, &exec, &comment)) {
gsp_app_create (name, comment, exec);
&name, &exec, &comment, &delay)) {
gsp_app_create (name, comment, exec, delay);
g_free (name);
g_free (exec);
g_free (comment);
@@ -426,16 +427,18 @@ on_edit_app_clicked (GtkWidget *widget,
char *name;
char *exec;
char *comment;
guint delay;

edit_dialog = gsm_app_dialog_new (gsp_app_get_name (app),
gsp_app_get_exec (app),
gsp_app_get_comment (app));
gsp_app_get_comment (app),
gsp_app_get_delay (app));
gtk_window_set_transient_for (GTK_WINDOW (edit_dialog),
GTK_WINDOW (dialog));

if (gsm_app_dialog_run (GSM_APP_DIALOG (edit_dialog),
&name, &exec, &comment)) {
gsp_app_update (app, name, comment, exec);
&name, &exec, &comment, &delay)) {
gsp_app_update (app, name, comment, exec, delay);
g_free (name);
g_free (exec);
g_free (comment);
@@ -46,6 +46,7 @@
#define GSP_ASP_SAVE_MASK_NAME 0x0004
#define GSP_ASP_SAVE_MASK_EXEC 0x0008
#define GSP_ASP_SAVE_MASK_COMMENT 0x0010
#define GSP_ASP_SAVE_MASK_DELAY 0x0020
#define GSP_ASP_SAVE_MASK_ALL 0xffff

typedef struct {
@@ -59,6 +60,7 @@ typedef struct {
char *exec;
char *comment;
char *icon;
gint delay;

GIcon *gicon;
char *description;
@@ -487,6 +489,10 @@ _gsp_app_save (gpointer data)
priv->exec);
}

if (priv->save_mask & GSP_ASP_SAVE_MASK_DELAY) {
gsp_key_file_set_delay (keyfile, priv->delay);
}

_gsp_ensure_user_autostart_dir ();
if (gsp_key_file_to_file (keyfile, priv->path, NULL)) {
priv->skip_next_monitor_event = TRUE;
@@ -643,6 +649,17 @@ gsp_app_get_comment (GspApp *app)
return priv->comment;
}

guint
gsp_app_get_delay (GspApp *app)
{
GspAppPrivate *priv;

g_return_val_if_fail (GSP_IS_APP (app), 0);
priv = gsp_app_get_instance_private (app);

return priv->delay;
}

GIcon *
gsp_app_get_icon (GspApp *app)
{
@@ -716,7 +733,8 @@ void
gsp_app_update (GspApp *app,
const char *name,
const char *comment,
const char *exec)
const char *exec,
guint delay)
{
gboolean changed;
GspAppPrivate *priv;
@@ -751,6 +769,12 @@ gsp_app_update (GspApp *app,
priv->save_mask |= GSP_ASP_SAVE_MASK_EXEC;
}

if ( delay != priv->delay) {
changed = TRUE;
priv->delay = delay;
priv->save_mask |= GSP_ASP_SAVE_MASK_DELAY;
}

if (changed) {
_gsp_app_queue_save (app);
_gsp_app_emit_changed (app);
@@ -928,6 +952,7 @@ gsp_app_new (const char *path,
G_KEY_FILE_DESKTOP_KEY_EXEC);
priv->comment = gsp_key_file_get_locale_string (keyfile,
G_KEY_FILE_DESKTOP_KEY_COMMENT);
priv->delay = gsp_key_file_get_delay (keyfile);

if (gsm_util_text_is_blank (priv->name)) {
g_free (priv->name);
@@ -1035,7 +1060,8 @@ _gsp_find_free_basename (const char *suggested_basename)
void
gsp_app_create (const char *name,
const char *comment,
const char *exec)
const char *exec,
guint delay)
{
GspAppManager *manager;
GspAppPrivate *priv;
@@ -1074,6 +1100,7 @@ gsp_app_create (const char *name,
}
priv->exec = g_strdup (exec);
priv->comment = g_strdup (comment);
priv->delay = delay;
priv->icon = NULL;

priv->gicon = NULL;
@@ -44,11 +44,13 @@ GType gsp_app_get_type (void) G_GNUC_CONST;

void gsp_app_create (const char *name,
const char *comment,
const char *exec);
const char *exec,
guint delay);
void gsp_app_update (GspApp *app,
const char *name,
const char *comment,
const char *exec);
const char *exec,
guint delay);

gboolean gsp_app_copy_desktop_file (const char *uri);

@@ -66,6 +68,7 @@ void gsp_app_set_enabled (GspApp *app,
const char *gsp_app_get_name (GspApp *app);
const char *gsp_app_get_exec (GspApp *app);
const char *gsp_app_get_comment (GspApp *app);
guint gsp_app_get_delay (GspApp *app);

const char *gsp_app_get_description (GspApp *app);
GIcon *gsp_app_get_icon (GspApp *app);
Oops, something went wrong.

0 comments on commit 0e2eb8a

Please sign in to comment.
You can’t perform that action at this time.