summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2013-11-06 10:17:31 -0800
committerStefano Karapetsas <[email protected]>2013-11-06 10:17:31 -0800
commitc17333cbd562c8021ad152b6a41d7eaa46617719 (patch)
tree06c2a96f31377d1413b647c0900a50dfcc17e4d7
parente7f6acc91eb1321bdb8fcb77194c18365a7d680a (diff)
parent2c5a103b59a53d5fb586572e38d65e7afb5ecb44 (diff)
downloadmate-session-manager-c17333cbd562c8021ad152b6a41d7eaa46617719.tar.bz2
mate-session-manager-c17333cbd562c8021ad152b6a41d7eaa46617719.tar.xz
Merge pull request #35 from NiceandGently/master
session: support_autostart_delay
-rw-r--r--egg/eggdesktopfile.c10
-rw-r--r--egg/eggdesktopfile.h3
-rw-r--r--mate-session/gsm-app.c13
-rw-r--r--mate-session/gsm-app.h2
-rw-r--r--mate-session/gsm-autostart-app.c23
-rw-r--r--mate-session/gsm-autostart-app.h1
-rw-r--r--mate-session/gsm-manager.c54
7 files changed, 98 insertions, 8 deletions
diff --git a/egg/eggdesktopfile.c b/egg/eggdesktopfile.c
index 3bb3d36..83f9a4e 100644
--- a/egg/eggdesktopfile.c
+++ b/egg/eggdesktopfile.c
@@ -420,6 +420,16 @@ egg_desktop_file_get_numeric (EggDesktopFile *desktop_file,
error);
}
+int
+egg_desktop_file_get_integer (EggDesktopFile *desktop_file,
+ const char *key,
+ GError **error)
+{
+ return g_key_file_get_integer (desktop_file->key_file,
+ EGG_DESKTOP_FILE_GROUP, key,
+ error);
+}
+
char **
egg_desktop_file_get_string_list (EggDesktopFile *desktop_file,
const char *key,
diff --git a/egg/eggdesktopfile.h b/egg/eggdesktopfile.h
index 44c093b..00ff6b7 100644
--- a/egg/eggdesktopfile.h
+++ b/egg/eggdesktopfile.h
@@ -129,6 +129,9 @@ gboolean egg_desktop_file_get_boolean (EggDesktopFile *desktop_file
double egg_desktop_file_get_numeric (EggDesktopFile *desktop_file,
const char *key,
GError **error);
+int egg_desktop_file_get_integer (EggDesktopFile *desktop_file,
+ const char *key,
+ GError **error);
char **egg_desktop_file_get_string_list (EggDesktopFile *desktop_file,
const char *key,
gsize *length,
diff --git a/mate-session/gsm-app.c b/mate-session/gsm-app.c
index cae685c..9b3ea39 100644
--- a/mate-session/gsm-app.c
+++ b/mate-session/gsm-app.c
@@ -246,6 +246,7 @@ gsm_app_class_init (GsmAppClass *klass)
klass->impl_get_autorestart = NULL;
klass->impl_provides = NULL;
klass->impl_is_running = NULL;
+ klass->impl_peek_autostart_delay = NULL;
g_object_class_install_property (object_class,
PROP_PHASE,
@@ -442,6 +443,18 @@ gsm_app_registered (GsmApp *app)
g_signal_emit (app, signals[REGISTERED], 0);
}
+int
+gsm_app_peek_autostart_delay (GsmApp *app)
+{
+ g_return_val_if_fail (GSM_IS_APP (app), FALSE);
+
+ if (GSM_APP_GET_CLASS (app)->impl_peek_autostart_delay) {
+ return GSM_APP_GET_CLASS (app)->impl_peek_autostart_delay (app);
+ } else {
+ return 0;
+ }
+}
+
void
gsm_app_exited (GsmApp *app)
{
diff --git a/mate-session/gsm-app.h b/mate-session/gsm-app.h
index a50c8db..a1adaa3 100644
--- a/mate-session/gsm-app.h
+++ b/mate-session/gsm-app.h
@@ -67,6 +67,7 @@ struct _GsmAppClass
GError **error);
gboolean (*impl_stop) (GsmApp *app,
GError **error);
+ int (*impl_peek_autostart_delay) (GsmApp *app);
gboolean (*impl_provides) (GsmApp *app,
const char *service);
gboolean (*impl_has_autostart_condition) (GsmApp *app,
@@ -117,6 +118,7 @@ gboolean gsm_app_provides (GsmApp *app,
gboolean gsm_app_has_autostart_condition (GsmApp *app,
const char *condition);
void gsm_app_registered (GsmApp *app);
+int gsm_app_peek_autostart_delay (GsmApp *app);
/* exported to bus */
gboolean gsm_app_get_app_id (GsmApp *app,
diff --git a/mate-session/gsm-autostart-app.c b/mate-session/gsm-autostart-app.c
index f19f6b6..04cc8e6 100644
--- a/mate-session/gsm-autostart-app.c
+++ b/mate-session/gsm-autostart-app.c
@@ -65,6 +65,7 @@ struct _GsmAutostartAppPrivate {
char *condition_string;
gboolean condition;
gboolean autorestart;
+ int autostart_delay;
GFileMonitor *condition_monitor;
GSettings *condition_settings;
@@ -101,6 +102,7 @@ gsm_autostart_app_init (GsmAutostartApp *app)
app->priv->pid = -1;
app->priv->condition_monitor = NULL;
app->priv->condition = FALSE;
+ app->priv->autostart_delay = -1;
}
static gboolean
@@ -482,6 +484,18 @@ load_desktop_file (GsmAutostartApp *app)
NULL);
setup_condition_monitor (app);
+ if (phase == GSM_MANAGER_PHASE_APPLICATION) {
+ /* Only accept an autostart delay for the application phase */
+ app->priv->autostart_delay = egg_desktop_file_get_integer (app->priv->desktop_file,
+ GSM_AUTOSTART_APP_DELAY_KEY,
+ NULL);
+ if (app->priv->autostart_delay < 0) {
+ g_warning ("Invalid autostart delay of %d for %s", app->priv->autostart_delay,
+ gsm_app_peek_id (GSM_APP (app)));
+ app->priv->autostart_delay = -1;
+ }
+ }
+
g_object_set (app,
"phase", phase,
"startup-id", startup_id,
@@ -1108,6 +1122,14 @@ gsm_autostart_app_get_app_id (GsmApp *app)
}
}
+static int
+gsm_autostart_app_peek_autostart_delay (GsmApp *app)
+{
+ GsmAutostartApp *aapp = GSM_AUTOSTART_APP (app);
+
+ return aapp->priv->autostart_delay;
+}
+
static GObject *
gsm_autostart_app_constructor (GType type,
guint n_construct_properties,
@@ -1148,6 +1170,7 @@ gsm_autostart_app_class_init (GsmAutostartAppClass *klass)
app_class->impl_has_autostart_condition = gsm_autostart_app_has_autostart_condition;
app_class->impl_get_app_id = gsm_autostart_app_get_app_id;
app_class->impl_get_autorestart = gsm_autostart_app_get_autorestart;
+ app_class->impl_peek_autostart_delay = gsm_autostart_app_peek_autostart_delay;
g_object_class_install_property (object_class,
PROP_DESKTOP_FILENAME,
diff --git a/mate-session/gsm-autostart-app.h b/mate-session/gsm-autostart-app.h
index 0502aa3..4c45338 100644
--- a/mate-session/gsm-autostart-app.h
+++ b/mate-session/gsm-autostart-app.h
@@ -70,6 +70,7 @@ GsmApp *gsm_autostart_app_new (const char *desktop_file);
#define GSM_AUTOSTART_APP_DBUS_PATH_KEY "X-MATE-DBus-Path"
#define GSM_AUTOSTART_APP_DBUS_ARGS_KEY "X-MATE-DBus-Start-Arguments"
#define GSM_AUTOSTART_APP_DISCARD_KEY "X-MATE-Autostart-discard-exec"
+#define GSM_AUTOSTART_APP_DELAY_KEY "X-MATE-Autostart-Delay"
#ifdef __cplusplus
}
diff --git a/mate-session/gsm-manager.c b/mate-session/gsm-manager.c
index b4986ac..cbe680b 100644
--- a/mate-session/gsm-manager.c
+++ b/mate-session/gsm-manager.c
@@ -335,13 +335,16 @@ app_condition_changed (GsmApp *app,
} else {
g_debug ("GsmManager: stopping app %s", gsm_app_peek_id (app));
- /* If we don't have a client then we should try to kill the app */
+ /* If we don't have a client then we should try to kill the app,
+ * if it is running */
error = NULL;
- res = gsm_app_stop (app, &error);
- if (error != NULL) {
- g_warning ("Not able to stop app from its condition: %s",
- error->message);
- g_error_free (error);
+ if (gsm_app_is_running (app)) {
+ res = gsm_app_stop (app, &error);
+ if (error != NULL) {
+ g_warning ("Not able to stop app from its condition: %s",
+ error->message);
+ g_error_free (error);
+ }
}
}
}
@@ -622,12 +625,37 @@ on_phase_timeout (GsmManager *manager)
}
static gboolean
+_autostart_delay_timeout (GsmApp *app)
+{
+ GError *error = NULL;
+ gboolean res;
+
+ if (!gsm_app_peek_is_disabled (app)
+ && !gsm_app_peek_is_conditionally_disabled (app)) {
+ res = gsm_app_start (app, &error);
+ if (!res) {
+ if (error != NULL) {
+ g_warning ("Could not launch application '%s': %s",
+ gsm_app_peek_app_id (app),
+ error->message);
+ g_error_free (error);
+ }
+ }
+ }
+
+ g_object_unref (app);
+
+ return FALSE;
+}
+
+static gboolean
_start_app (const char *id,
GsmApp *app,
GsmManager *manager)
{
GError *error;
gboolean res;
+ int delay;
if (gsm_app_peek_phase (app) != manager->priv->phase) {
goto out;
@@ -646,6 +674,15 @@ _start_app (const char *id,
goto out;
}
+ delay = gsm_app_peek_autostart_delay (app);
+ if (delay > 0) {
+ g_timeout_add_seconds (delay,
+ (GSourceFunc)_autostart_delay_timeout,
+ g_object_ref (app));
+ g_debug ("GsmManager: %s is scheduled to start in %d seconds", id, delay);
+ goto out;
+ }
+
error = NULL;
res = gsm_app_start (app, &error);
if (!res) {
@@ -1484,11 +1521,12 @@ _debug_app_for_phase (const char *id,
return FALSE;
}
- g_debug ("GsmManager:\tID: %s\tapp-id:%s\tis-disabled:%d\tis-conditionally-disabled:%d",
+ g_debug ("GsmManager:\tID: %s\tapp-id:%s\tis-disabled:%d\tis-conditionally-disabled:%d\tis-delayed:%d",
gsm_app_peek_id (app),
gsm_app_peek_app_id (app),
gsm_app_peek_is_disabled (app),
- gsm_app_peek_is_conditionally_disabled (app));
+ gsm_app_peek_is_conditionally_disabled (app),
+ (gsm_app_peek_autostart_delay (app) > 0));
return FALSE;
}