diff --git a/ChangeLog b/ChangeLog index 8027b135613a1c6ee7df1b6188d3cf3b518f1fdf..2b7dc1529f3a002079c5816afa322c36d0eb7ed2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ +2009-04-04 11:30 Ali aliov@xfce.org + * : Fix issue with multiple suspend callback + 2009-04-03 13:37 Ali aliov@xfce.org * : Fix issue with battery critical level in the settings dialog diff --git a/src/xfpm-engine.c b/src/xfpm-engine.c index cc8c4f941a62b6835d6d661d341497cacf395be1..1d9cadc27282705ac756aa0dfdcf193fd6b17cf5 100644 --- a/src/xfpm-engine.c +++ b/src/xfpm-engine.c @@ -88,6 +88,8 @@ struct XfpmEnginePrivate gboolean has_lcd_brightness; gboolean has_lid; + + gboolean block; }; enum @@ -172,13 +174,17 @@ xfpm_engine_shutdown_request (XfpmEngine * engine, } else if (shutdown == XFPM_DO_HIBERNATE) { - g_timeout_add_seconds (2, (GSourceFunc) xfpm_engine_do_hibernate, - engine); + xfpm_shutdown_add_callback (engine->priv->shutdown, + (GSourceFunc) xfpm_engine_do_hibernate, + 2, + engine); } else if (shutdown == XFPM_DO_SUSPEND) { - g_timeout_add_seconds (2, (GSourceFunc) xfpm_engine_do_suspend, - engine); + xfpm_shutdown_add_callback (engine->priv->shutdown, + (GSourceFunc) xfpm_engine_do_suspend, + 2, + engine); } if (lock_screen) diff --git a/src/xfpm-shutdown.c b/src/xfpm-shutdown.c index ce4d7ea98d9526b9a78c2a142ed073ae75a06fd6..c005ad641991ab84b10f0bdf28b8b1173bb94ced 100644 --- a/src/xfpm-shutdown.c +++ b/src/xfpm-shutdown.c @@ -350,6 +350,21 @@ xfpm_shutdown_new(void) return XFPM_SHUTDOWN (xfpm_shutdown_object); } +gboolean xfpm_shutdown_add_callback (XfpmShutdown *shutdown, + GSourceFunc func, + guint timeout, + gpointer data) +{ + g_return_val_if_fail (XFPM_IS_SHUTDOWN (shutdown), FALSE); + + if (shutdown->priv->block_shutdown) + return FALSE; + + g_timeout_add_seconds (timeout, func, data); + shutdown->priv->block_shutdown = TRUE; + return TRUE; +} + void xfpm_shutdown (XfpmShutdown *shutdown, GError **error) { g_return_if_fail (XFPM_IS_SHUTDOWN(shutdown)); @@ -360,9 +375,8 @@ void xfpm_shutdown (XfpmShutdown *shutdown, GError **error) return; } - if ( shutdown->priv->block_shutdown ) - return; xfpm_shutdown_internal (dbus_g_connection_get_connection(shutdown->priv->bus), "Shutdown", NULL); + shutdown->priv->block_shutdown = FALSE; } void xfpm_hibernate (XfpmShutdown *shutdown, GError **error) @@ -378,13 +392,9 @@ void xfpm_hibernate (XfpmShutdown *shutdown, GError **error) return; } - if ( shutdown->priv->block_shutdown ) - return; - - shutdown->priv->block_shutdown = TRUE; xfpm_shutdown_internal (dbus_g_connection_get_connection(shutdown->priv->bus), "Hibernate", &error_internal); shutdown->priv->block_shutdown = FALSE; - + if ( error_internal ) { g_warning ("%s", error_internal->message); @@ -410,10 +420,6 @@ void xfpm_suspend (XfpmShutdown *shutdown, GError **error) return; } - if ( shutdown->priv->block_shutdown ) - return; - - shutdown->priv->block_shutdown = TRUE; xfpm_shutdown_internal (dbus_g_connection_get_connection(shutdown->priv->bus), "Suspend", &error_internal); shutdown->priv->block_shutdown = FALSE; diff --git a/src/xfpm-shutdown.h b/src/xfpm-shutdown.h index c45afae83d447d7602de5c3087e1e333975a30d6..12e55e153519e017b22835457f24d265d3fac374 100644 --- a/src/xfpm-shutdown.h +++ b/src/xfpm-shutdown.h @@ -54,6 +54,12 @@ typedef struct GType xfpm_shutdown_get_type (void) G_GNUC_CONST; XfpmShutdown *xfpm_shutdown_new (void); +gboolean xfpm_shutdown_add_callback (XfpmShutdown *shutdown, + GSourceFunc func, + guint timeout, + gpointer data); + + void xfpm_shutdown (XfpmShutdown *shutdown, GError **error); diff --git a/src/xfpm-tray-icon.c b/src/xfpm-tray-icon.c index 5656139bee9aa40b92bdf46d3e82fcd774b38d56..4d4ea6c987c4ec87154e600da1fc258f2fb82046 100644 --- a/src/xfpm-tray-icon.c +++ b/src/xfpm-tray-icon.c @@ -171,7 +171,11 @@ xfpm_tray_icon_hibernate_cb (GtkWidget *w, XfpmTrayIcon *tray) lock_screen = xfpm_xfconf_get_property_bool (tray->priv->conf, LOCK_SCREEN_ON_SLEEP); if ( lock_screen ) xfpm_lock_screen (); - g_timeout_add_seconds (4, (GSourceFunc) xfpm_tray_icon_do_hibernate, tray); + + xfpm_shutdown_add_callback (tray->priv->shutdown, + (GSourceFunc) xfpm_tray_icon_do_hibernate, + 2, + tray); xfpm_send_message_to_network_manager ("sleep"); } } @@ -198,7 +202,12 @@ xfpm_tray_icon_suspend_cb (GtkWidget *w, XfpmTrayIcon *tray) lock_screen = xfpm_xfconf_get_property_bool (tray->priv->conf, LOCK_SCREEN_ON_SLEEP); if ( lock_screen ) xfpm_lock_screen (); - g_timeout_add_seconds (4, (GSourceFunc) xfpm_tray_icon_do_suspend, tray); + + xfpm_shutdown_add_callback (tray->priv->shutdown, + (GSourceFunc) xfpm_tray_icon_do_suspend, + 2, + tray); + xfpm_send_message_to_network_manager ("sleep"); } } @@ -208,7 +217,7 @@ xfpm_tray_icon_exit_activated_cb (GtkWidget *w, gpointer data) { gboolean ret; - ret = xfce_confirm (_("Exit Xfce power manager"), + ret = xfce_confirm (_("Quit the Xfce power manager"), GTK_STOCK_YES, _("Quit")); if ( ret )