diff options
Diffstat (limited to 'mate-session/gsm-manager.c')
-rw-r--r-- | mate-session/gsm-manager.c | 89 |
1 files changed, 70 insertions, 19 deletions
diff --git a/mate-session/gsm-manager.c b/mate-session/gsm-manager.c index b4986ac..eda565b 100644 --- a/mate-session/gsm-manager.c +++ b/mate-session/gsm-manager.c @@ -38,7 +38,9 @@ #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#ifdef HAVE_UPOWER #include <upower.h> +#endif #include <gtk/gtk.h> /* for logout dialog */ #include <gio/gio.h> /* for gsettings */ @@ -144,9 +146,10 @@ struct GsmManagerPrivate DBusGProxy *bus_proxy; DBusGConnection *connection; - +#ifdef HAVE_UPOWER /* Interface with other parts of the system */ UpClient *up_client; +#endif }; enum { @@ -335,13 +338,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 +628,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 +677,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) { @@ -1105,10 +1145,11 @@ manager_perhaps_lock (GsmManager *manager) static void manager_attempt_hibernate (GsmManager *manager) { +#ifdef HAVE_UPOWER gboolean can_hibernate; GError *error; gboolean ret; - +#endif #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) { @@ -1121,8 +1162,11 @@ manager_attempt_hibernate (GsmManager *manager) gsm_systemd_attempt_hibernate (systemd); } +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) else { #endif +#ifdef HAVE_UPOWER can_hibernate = up_client_get_can_hibernate (manager->priv->up_client); if (can_hibernate) { @@ -1137,7 +1181,8 @@ manager_attempt_hibernate (GsmManager *manager) g_error_free (error); } } -#ifdef HAVE_SYSTEMD +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) } #endif } @@ -1145,10 +1190,11 @@ manager_attempt_hibernate (GsmManager *manager) static void manager_attempt_suspend (GsmManager *manager) { +#ifdef HAVE_UPOWER gboolean can_suspend; GError *error; gboolean ret; - +#endif #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) { @@ -1161,8 +1207,11 @@ manager_attempt_suspend (GsmManager *manager) gsm_systemd_attempt_suspend (systemd); } +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) else { #endif +#ifdef HAVE_UPOWER can_suspend = up_client_get_can_suspend (manager->priv->up_client); if (can_suspend) { @@ -1177,7 +1226,8 @@ manager_attempt_suspend (GsmManager *manager) g_error_free (error); } } -#ifdef HAVE_SYSTEMD +#endif +#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER) } #endif } @@ -1484,11 +1534,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; } @@ -2349,12 +2400,12 @@ gsm_manager_dispose (GObject *object) g_object_unref (manager->priv->settings_screensaver); manager->priv->settings_screensaver = NULL; } - +#ifdef HAVE_UPOWER if (manager->priv->up_client != NULL) { g_object_unref (manager->priv->up_client); manager->priv->up_client = NULL; } - +#endif G_OBJECT_CLASS (gsm_manager_parent_class)->dispose (object); } @@ -2561,9 +2612,9 @@ gsm_manager_init (GsmManager *manager) "status-changed", G_CALLBACK (on_presence_status_changed), manager); - +#ifdef HAVE_UPOWER manager->priv->up_client = up_client_new (); - +#endif g_signal_connect (manager->priv->settings_session, "changed", G_CALLBACK (on_gsettings_key_changed), @@ -3232,12 +3283,12 @@ gsm_manager_can_shutdown (GsmManager *manager, #endif gboolean can_suspend; gboolean can_hibernate; - +#ifdef HAVE_UPOWER g_object_get (manager->priv->up_client, "can-suspend", &can_suspend, "can-hibernate", &can_hibernate, NULL); - +#endif g_debug ("GsmManager: CanShutdown called"); g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE); |