From 8ea0fde8939236cca0d11aa726fe5d98f6de6526 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 13:10:43 -0500 Subject: Changing the define name to have room for more locdown keys --- src/session-service.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index f6b666f..a64f701 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -56,8 +56,8 @@ with this program. If not, see . #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" -#define LOCKDOWN_DIR "/desktop/gnome/lockdown" -#define LOCKDOWN_KEY LOCKDOWN_DIR "/disable_user_switching" +#define LOCKDOWN_DIR "/desktop/gnome/lockdown" +#define LOCKDOWN_KEY_USER LOCKDOWN_DIR "/disable_user_switching" typedef struct _ActivateData ActivateData; struct _ActivateData @@ -103,7 +103,7 @@ lockdown_changed (GConfClient *client, if (!value || !key) return; - if (g_strcmp0 (key, LOCKDOWN_KEY) == 0) + if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0) { if (switch_menuitem) { @@ -127,7 +127,7 @@ ensure_gconf_client (void) gconf_client = gconf_client_get_default (); notify_lockdown_id = gconf_client_notify_add (gconf_client, - LOCKDOWN_KEY, + LOCKDOWN_KEY_USER, lockdown_changed, NULL, NULL, @@ -484,7 +484,7 @@ rebuild_items (DbusmenuMenuitem *root, dbusmenu_menuitem_child_append (root, switch_menuitem); g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); - if (gconf_client_get_bool (gconf_client, LOCKDOWN_KEY, NULL)) + if (gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL)) { dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } -- cgit v1.2.3 From df71f47685081f5125fb12c7bb170d88538e9523 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 13:28:19 -0500 Subject: Reacting to changes in the screensaver lockdown key. --- src/session-service.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index a64f701..7ebc00a 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -58,6 +58,7 @@ with this program. If not, see . #define LOCKDOWN_DIR "/desktop/gnome/lockdown" #define LOCKDOWN_KEY_USER LOCKDOWN_DIR "/disable_user_switching" +#define LOCKDOWN_KEY_SCREENSAVER LOCKDOWN_DIR "/disable_lock_screen" typedef struct _ActivateData ActivateData; struct _ActivateData @@ -97,26 +98,32 @@ lockdown_changed (GConfClient *client, GConfEntry *entry, gpointer user_data) { - GConfValue *value = gconf_entry_get_value (entry); - const gchar *key = gconf_entry_get_key (entry); + GConfValue *value = gconf_entry_get_value (entry); + const gchar *key = gconf_entry_get_key (entry); - if (!value || !key) - return; + if (value == NULL || key == NULL) { + return; + } - if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0) - { - if (switch_menuitem) - { - if (gconf_value_get_bool (value)) - { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } - else - { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - } - } - } + if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0) { + if (switch_menuitem != NULL) { + if (gconf_value_get_bool (value)) { + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } else { + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + } + } + } if (g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { + if (lock_menuitem != NULL) { + if (gconf_value_get_bool (value)) { + dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } else { + dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + } + } + } + + return; } static void -- cgit v1.2.3 From aa52289c19291ffa9bc4ed70f67d1f683cbf6381 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 13:29:01 -0500 Subject: Embarassing 4 letter word to forget. Guess the compiler would add it back anyway though. --- src/session-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index 7ebc00a..24623aa 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -113,7 +113,7 @@ lockdown_changed (GConfClient *client, dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } } - } if (g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { + } else if (g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { if (lock_menuitem != NULL) { if (gconf_value_get_bool (value)) { dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); -- cgit v1.2.3 From da365cbe9598860cc4e74938ded3ad735a6db396 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 14:11:55 -0500 Subject: Tracking the separator next to the lock item as well. --- src/session-service.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index 24623aa..b976236 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -73,6 +73,7 @@ static UsersServiceDbus *dbus_interface = NULL; static SessionDbus *session_dbus = NULL; static DbusmenuMenuitem *lock_menuitem = NULL; +static DbusmenuMenuitem *lock_separator = NULL; static DbusmenuMenuitem *switch_menuitem = NULL; static DbusmenuMenuitem * root_menuitem = NULL; @@ -116,9 +117,11 @@ lockdown_changed (GConfClient *client, } else if (g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { if (lock_menuitem != NULL) { if (gconf_value_get_bool (value)) { - dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (lock_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } else { - dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool (lock_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } } } @@ -464,12 +467,14 @@ rebuild_items (DbusmenuMenuitem *root, } else { dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); } + lock_separator = NULL; if (can_activate == TRUE) { DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator1); + lock_separator = separator1; if (check_guest_session ()) { @@ -554,6 +559,9 @@ rebuild_items (DbusmenuMenuitem *root, DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); + if (lock_separator == NULL) { + lock_separator = separator; + } logout_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { -- cgit v1.2.3 From 065984db24fa4e8723d9dd5add9eec0e71d43ace Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 14:45:48 -0500 Subject: Switching around the GConf notification setup to do an entire directory. --- src/session-service.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index b976236..72a93eb 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -91,7 +91,6 @@ static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; static GConfClient * gconf_client = NULL; -static guint notify_lockdown_id = 0; static void lockdown_changed (GConfClient *client, @@ -129,20 +128,17 @@ lockdown_changed (GConfClient *client, return; } +/* Ensures that we have a GConf client and if we build one + set up the signal handler. */ static void ensure_gconf_client (void) { - if (!gconf_client) - { - gconf_client = gconf_client_get_default (); - - notify_lockdown_id = gconf_client_notify_add (gconf_client, - LOCKDOWN_KEY_USER, - lockdown_changed, - NULL, - NULL, - NULL); - } + if (!gconf_client) { + gconf_client = gconf_client_get_default (); + gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add(gconf_client, LOCKDOWN_DIR, lockdown_changed, NULL, NULL, NULL); + } + return; } /* A return from the command to sleep the system. Make sure -- cgit v1.2.3 From 523c02493e72d1e99e23082e9b14af51fd54ae18 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 15:21:26 -0500 Subject: Switching from hiding entries to just rebuilding the menus. --- src/session-service.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index 72a93eb..c0703bb 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -92,6 +92,8 @@ static DbusmenuMenuitem * shutdown_mi = NULL; static GConfClient * gconf_client = NULL; +static void rebuild_items (DbusmenuMenuitem *root, UsersServiceDbus *service); + static void lockdown_changed (GConfClient *client, guint cnxd_id, @@ -105,24 +107,8 @@ lockdown_changed (GConfClient *client, return; } - if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0) { - if (switch_menuitem != NULL) { - if (gconf_value_get_bool (value)) { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } else { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - } - } - } else if (g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { - if (lock_menuitem != NULL) { - if (gconf_value_get_bool (value)) { - dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - dbusmenu_menuitem_property_set_bool (lock_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } else { - dbusmenu_menuitem_property_set_bool (lock_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - dbusmenu_menuitem_property_set_bool (lock_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - } - } + if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0 || g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { + rebuild_items(root_menuitem, dbus_interface); } return; -- cgit v1.2.3 From 29bd57b57fe4cf4e964fdecf034cb2ecb8cd04b1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 15:33:36 -0500 Subject: Changing the lockdown key to do all the switching instead of just the switch user item. --- src/session-service.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index c0703bb..66d468f 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -434,7 +434,10 @@ rebuild_items (DbusmenuMenuitem *root, gboolean can_activate; GList *children; - can_activate = users_service_dbus_can_activate_session (service); + ensure_gconf_client (); + + can_activate = users_service_dbus_can_activate_session (service) && + !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); children = dbusmenu_menuitem_take_children (root); g_list_foreach (children, (GFunc)g_object_unref, NULL); @@ -470,22 +473,12 @@ rebuild_items (DbusmenuMenuitem *root, if (check_new_session ()) { - ensure_gconf_client (); switch_menuitem = dbusmenu_menuitem_new (); dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_TYPE, MENU_SWITCH_TYPE); dbusmenu_menuitem_property_set (switch_menuitem, MENU_SWITCH_USER, g_get_user_name()); dbusmenu_menuitem_child_append (root, switch_menuitem); g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); - - if (gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL)) - { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } - else - { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - } } GList * users = NULL; -- cgit v1.2.3 From c334ecccf05654c102b112cf7d76d2f38768924f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 15:36:48 -0500 Subject: Removing the lock separator as we don't need it anymore. --- src/session-service.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index 66d468f..cadce43 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -73,7 +73,6 @@ static UsersServiceDbus *dbus_interface = NULL; static SessionDbus *session_dbus = NULL; static DbusmenuMenuitem *lock_menuitem = NULL; -static DbusmenuMenuitem *lock_separator = NULL; static DbusmenuMenuitem *switch_menuitem = NULL; static DbusmenuMenuitem * root_menuitem = NULL; @@ -452,14 +451,12 @@ rebuild_items (DbusmenuMenuitem *root, } else { dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); } - lock_separator = NULL; if (can_activate == TRUE) { DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator1); - lock_separator = separator1; if (check_guest_session ()) { @@ -534,9 +531,6 @@ rebuild_items (DbusmenuMenuitem *root, DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); - if (lock_separator == NULL) { - lock_separator = separator; - } logout_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { -- cgit v1.2.3 From bdba7e5c6a5081c599ade54e4798f9f1af0b536e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 15:52:17 -0500 Subject: Handling the locking of the screen in the rebuild function. --- src/session-service.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index cadce43..53c305c 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -431,32 +431,38 @@ rebuild_items (DbusmenuMenuitem *root, GList *u; UserData *user; gboolean can_activate; + gboolean can_lockscreen; GList *children; ensure_gconf_client (); can_activate = users_service_dbus_can_activate_session (service) && !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); + can_lockscreen = !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL); children = dbusmenu_menuitem_take_children (root); g_list_foreach (children, (GFunc)g_object_unref, NULL); g_list_free (children); - lock_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); - g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); - dbusmenu_menuitem_child_append(root, lock_menuitem); - if (!will_lock_screen()) { - dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); - } else { - dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + if (can_lockscreen) { + lock_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); + g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); + dbusmenu_menuitem_child_append(root, lock_menuitem); + if (!will_lock_screen()) { + dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + } else { + dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + } } if (can_activate == TRUE) { - DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator1); + if (can_lockscreen) { + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(root, separator1); + } if (check_guest_session ()) { @@ -528,9 +534,11 @@ rebuild_items (DbusmenuMenuitem *root, g_list_free(users); } - DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator); + if (can_lockscreen || can_activate) { + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(root, separator); + } logout_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { -- cgit v1.2.3 From acc3a9675f035777b3b32335edb7854860bfb9ba Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 16:00:43 -0500 Subject: Adding some comments to describe a long function. --- src/session-service.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index 53c305c..3ee1f6c 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -434,16 +434,21 @@ rebuild_items (DbusmenuMenuitem *root, gboolean can_lockscreen; GList *children; + /* Make sure we have a valid GConf client, and build one + if needed */ ensure_gconf_client (); + /* Check to see which menu items we're allowed to have */ can_activate = users_service_dbus_can_activate_session (service) && !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); can_lockscreen = !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL); + /* Remove the old menu items if that makes sense */ children = dbusmenu_menuitem_take_children (root); g_list_foreach (children, (GFunc)g_object_unref, NULL); g_list_free (children); + /* Lock screen item */ if (can_lockscreen) { lock_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); @@ -456,6 +461,7 @@ rebuild_items (DbusmenuMenuitem *root, } } + /* Build all of the user switching items */ if (can_activate == TRUE) { if (can_lockscreen) { @@ -534,12 +540,16 @@ rebuild_items (DbusmenuMenuitem *root, g_list_free(users); } + /* If there were a bunch of items before us, we need a + separator. */ if (can_lockscreen || can_activate) { DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); } + /* Start going through the session based items. */ + logout_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { dbusmenu_menuitem_property_set(logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out")); -- cgit v1.2.3 From eb8756b0a8b55f904dd74103fa33d67b1da11575 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 16:02:06 -0500 Subject: Only setup signals if we're building the proxy for the first time. --- src/session-service.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index 3ee1f6c..9cde4b0 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -266,19 +266,19 @@ setup_up (void) { UP_ADDRESS, UP_OBJECT, DBUS_INTERFACE_PROPERTIES); + /* Connect to changed signal */ + dbus_g_proxy_add_signal(up_main_proxy, + "Changed", + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal(up_main_proxy, + "Changed", + G_CALLBACK(up_changed_cb), + NULL, + NULL); } g_return_if_fail(up_prop_proxy != NULL); - /* Connect to changed signal */ - dbus_g_proxy_add_signal(up_main_proxy, - "Changed", - G_TYPE_INVALID); - - dbus_g_proxy_connect_signal(up_main_proxy, - "Changed", - G_CALLBACK(up_changed_cb), - NULL, - NULL); /* Force an original "changed" event */ up_changed_cb(up_main_proxy, NULL); -- cgit v1.2.3 From cef6711749d305967d0341920f08aef46d6390d7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 16:16:53 -0500 Subject: Switching the suspend/hibernate handling to a cached value. And that way we can regen the menus without looking up the values. --- src/session-service.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/session-service.c') diff --git a/src/session-service.c b/src/session-service.c index 9cde4b0..9eb6d88 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -89,6 +89,9 @@ static DbusmenuMenuitem * logout_mi = NULL; static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; +static gboolean can_hibernate = TRUE; +static gboolean can_suspend = TRUE; + static GConfClient * gconf_client = NULL; static void rebuild_items (DbusmenuMenuitem *root, UsersServiceDbus *service); @@ -175,8 +178,10 @@ suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) } g_debug("Got Suspend: %s", g_value_get_boolean(&candoit) ? "true" : "false"); - if (suspend_mi != NULL) { - dbusmenu_menuitem_property_set_value(suspend_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, &candoit); + gboolean local_can_suspend = g_value_get_boolean(&candoit); + if (local_can_suspend != can_suspend) { + can_suspend = local_can_suspend; + rebuild_items(root_menuitem, dbus_interface); } return; @@ -198,8 +203,10 @@ hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) } g_debug("Got Hibernate: %s", g_value_get_boolean(&candoit) ? "true" : "false"); - if (suspend_mi != NULL) { - dbusmenu_menuitem_property_set_value(hibernate_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, &candoit); + gboolean local_can_hibernate = g_value_get_boolean(&candoit); + if (local_can_hibernate != can_hibernate) { + can_hibernate = local_can_hibernate; + rebuild_items(root_menuitem, dbus_interface); } return; @@ -559,17 +566,19 @@ rebuild_items (DbusmenuMenuitem *root, dbusmenu_menuitem_child_append(root, logout_mi); g_signal_connect(G_OBJECT(logout_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "logout"); - suspend_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set_bool(suspend_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - dbusmenu_menuitem_property_set(suspend_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sleep")); - dbusmenu_menuitem_child_append(root, suspend_mi); - g_signal_connect(G_OBJECT(suspend_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Suspend"); - - hibernate_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set_bool(hibernate_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - dbusmenu_menuitem_property_set(hibernate_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Hibernate")); - dbusmenu_menuitem_child_append(root, hibernate_mi); - g_signal_connect(G_OBJECT(hibernate_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Hibernate"); + if (can_suspend) { + suspend_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(suspend_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sleep")); + dbusmenu_menuitem_child_append(root, suspend_mi); + g_signal_connect(G_OBJECT(suspend_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Suspend"); + } + + if (can_hibernate) { + hibernate_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(hibernate_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Hibernate")); + dbusmenu_menuitem_child_append(root, hibernate_mi); + g_signal_connect(G_OBJECT(hibernate_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Hibernate"); + } restart_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_TYPE, RESTART_ITEM_TYPE); -- cgit v1.2.3