From 2c5a103b59a53d5fb586572e38d65e7afb5ecb44 Mon Sep 17 00:00:00 2001 From: raveit65 Date: Thu, 31 Oct 2013 01:39:36 +0100 Subject: session: support_autostart_delay --- mate-session/gsm-manager.c | 54 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'mate-session/gsm-manager.c') 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); + } } } } @@ -621,6 +624,30 @@ on_phase_timeout (GsmManager *manager) return FALSE; } +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, @@ -628,6 +655,7 @@ _start_app (const char *id, { 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; } -- cgit v1.2.1