From 29e2c7e6daf9362367af0d801da0aa54174bb480 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 14:44:39 -0500 Subject: Add in the key for locking the screen and making that part of will_lock --- src/lock-helper.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lock-helper.c b/src/lock-helper.c index b38be65..b0340ea 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -19,9 +19,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include #include #include "lock-helper.h" +#define GCONF_DIR "/apps/gnome-screensaver" +#define GCONF_KEY GCONF_DIR "/lock_enabled" + static DBusGProxy * gss_proxy = NULL; static GMainLoop * gss_mainloop = NULL; static guint cookie = 0; @@ -29,6 +33,8 @@ static DBusGProxyCall * cookie_call = NULL; static gboolean is_guest = FALSE; +static GConfClient * gconf_client = NULL; + void build_gss_proxy (void); /* Checks to see if there is an error and reports @@ -124,7 +130,11 @@ will_lock_screen (void) return FALSE; } - return TRUE; + if (gconf_client == NULL) { + gconf_client = gconf_client_get_default(); + } + + return !gconf_client_get_bool (gconf_client, GCONF_KEY, NULL); } /* When the screensave go active, if we've got a mainloop -- cgit v1.2.3 From 0cfa0d154f3e3fcea6c4d0c946fa665c0b12aa9a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 14:47:41 -0500 Subject: Bad boolean --- src/lock-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lock-helper.c b/src/lock-helper.c index b0340ea..894801e 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -134,7 +134,7 @@ will_lock_screen (void) gconf_client = gconf_client_get_default(); } - return !gconf_client_get_bool (gconf_client, GCONF_KEY, NULL); + return gconf_client_get_bool (gconf_client, GCONF_KEY, NULL); } /* When the screensave go active, if we've got a mainloop -- cgit v1.2.3 From 9bf67d563e8b819364327c1635095ea885faf543 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:02:04 -0500 Subject: Instead of making the item disabled, change the text when we won't lock the screen. --- src/session-service.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index fb20f3b..5614ab4 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -509,14 +509,13 @@ rebuild_items (DbusmenuMenuitem *root, /* Lock screen item */ 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); + if (will_lock_screen()) { + dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); } else { - dbusmenu_menuitem_property_set_bool(lock_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Start Screensaver")); } + g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); + dbusmenu_menuitem_child_append(root, lock_menuitem); } /* Build all of the user switching items */ -- cgit v1.2.3 From 0b1551709e115304dadfecc6c4224be8545dfcce Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:16:00 -0500 Subject: Adding a function for updating the logout menuitem. --- src/lock-helper.c | 11 +++++++++++ src/lock-helper.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/lock-helper.c b/src/lock-helper.c index 20149ab..4b57f19 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -231,3 +231,14 @@ lock_screen_setup (gpointer data) return FALSE; } +void +lock_screen_update_item (DbusmenuMenuitem * mi) +{ + if (gconf_client == NULL) { + gconf_client = gconf_client_get_default(); + } + + + + +} diff --git a/src/lock-helper.h b/src/lock-helper.h index 37f1448..1d707d8 100644 --- a/src/lock-helper.h +++ b/src/lock-helper.h @@ -31,4 +31,6 @@ gboolean will_lock_screen (void); void lock_screen (DbusmenuMenuitem * mi, guint timestamp, gpointer data); gboolean lock_screen_setup (gpointer data); +void lock_screen_update_item (DbusmenuMenuitem * mi); + #endif /* LOCK_HELPER_H__ */ -- cgit v1.2.3 From c5050f03e27166026a55b21353d3ee058e077523 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:16:50 -0500 Subject: Connecting in the update item. --- src/session-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/session-service.c b/src/session-service.c index 5614ab4..b5fb42e 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -516,6 +516,7 @@ rebuild_items (DbusmenuMenuitem *root, } g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); dbusmenu_menuitem_child_append(root, lock_menuitem); + lock_screen_update_item(lock_menuitem); } /* Build all of the user switching items */ -- cgit v1.2.3 From c8438f91c8b1d588bc0d353b93852e27c3434a34 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:26:29 -0500 Subject: Adding in the mechanism to actually do the callback and change the label. --- src/lock-helper.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/lock-helper.c b/src/lock-helper.c index 4b57f19..3c2a7d5 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include #include #include #include "lock-helper.h" @@ -231,6 +232,28 @@ lock_screen_setup (gpointer data) return FALSE; } +/* When the GConf key changes we need to adjust the text on + what we're going to do with the menu item */ +static void +lockscreen_update (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) { + DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data; + const gchar * key = gconf_entry_get_key (entry); + + if(g_strcmp0 (key, GCONF_KEY) == 0) { + if (will_lock_screen()) { + dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); + } else { + dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Start Screensaver")); + } + } +} + +/* Notification handler for lock menuitems. */ +guint lock_notify = 0; + +/* Sets the menu item to be updating. There can + only be one. So we clear and reset if we get + another. */ void lock_screen_update_item (DbusmenuMenuitem * mi) { @@ -238,7 +261,19 @@ lock_screen_update_item (DbusmenuMenuitem * mi) gconf_client = gconf_client_get_default(); } + if (lock_notify == 0) { + gconf_client_add_dir (gconf_client, + GCONF_DIR, + GCONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + } + if (lock_notify != 0) { + gconf_client_notify_remove(gconf_client, lock_notify); + lock_notify = 0; + } + lock_notify = gconf_client_notify_add(gconf_client, GCONF_KEY, lockscreen_update, mi, NULL, NULL); + return; } -- cgit v1.2.3 From 62e8f11279fbf512ddae6591460f1746e768eb9a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:27:07 -0500 Subject: Adding lock-helper.c in as it has translatable strings now. --- po/POTFILES.in | 1 + 1 file changed, 1 insertion(+) diff --git a/po/POTFILES.in b/po/POTFILES.in index 6492f1e..3a8bad7 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,6 +1,7 @@ [encoding: UTF-8] data/indicator-session.schemas.in src/gconf-helper.c +src/lock-helper.c src/gtk-logout-helper.c src/dialog.c src/indicator-session.c -- cgit v1.2.3 From 02de3c1bb351ef18c404c4cd7fc2cf1e1a89a4eb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:35:01 -0500 Subject: Forgot to make this static. --- src/lock-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lock-helper.c b/src/lock-helper.c index 3c2a7d5..e150cbc 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -249,7 +249,7 @@ lockscreen_update (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpoin } /* Notification handler for lock menuitems. */ -guint lock_notify = 0; +static guint lock_notify = 0; /* Sets the menu item to be updating. There can only be one. So we clear and reset if we get -- cgit v1.2.3 From c0b109efe19528618028937b092a7f86d51add41 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:36:28 -0500 Subject: Splitting out the params here. --- src/lock-helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lock-helper.c b/src/lock-helper.c index e150cbc..86669f6 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -273,7 +273,12 @@ lock_screen_update_item (DbusmenuMenuitem * mi) lock_notify = 0; } - lock_notify = gconf_client_notify_add(gconf_client, GCONF_KEY, lockscreen_update, mi, NULL, NULL); + lock_notify = gconf_client_notify_add(gconf_client, + GCONF_KEY, + lockscreen_update, + mi, + NULL, + NULL); return; } -- cgit v1.2.3 From 6eea2650dc1b6b0ecc16b9de2b1c2471f90454e7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Mar 2010 16:52:17 -0500 Subject: Make sure to call to activate teh screensaver if we can't lock it. Oh, and that takes a reply. --- src/lock-helper.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/lock-helper.c b/src/lock-helper.c index 86669f6..ba6b182 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -186,24 +186,45 @@ activate_timeout (gpointer data) return FALSE; } +/* Handle errors from activating the screensaver */ +static void +active_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer user_data) +{ + GError * error = NULL; + + dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INVALID); + + if (error != NULL) { + g_warning("Unable to activate screensaver: %s", error->message); + g_error_free(error); + } + + return; +} + /* A fun little function to actually lock the screen. If, that's what you want, let's do it! */ void lock_screen (DbusmenuMenuitem * mi, guint timestamp, gpointer data) { g_debug("Lock Screen"); - if (!will_lock_screen()) { - g_debug("\tUser is guest, blocking lock"); - return; - } build_gss_proxy(); g_return_if_fail(gss_proxy != NULL); - dbus_g_proxy_call_no_reply(gss_proxy, - "Lock", - G_TYPE_INVALID, - G_TYPE_INVALID); + if (will_lock_screen()) { + dbus_g_proxy_call_no_reply(gss_proxy, + "Lock", + G_TYPE_INVALID, + G_TYPE_INVALID); + } else { + dbus_g_proxy_begin_call(gss_proxy, + "SetActive", + active_cb, NULL, + NULL, + G_TYPE_BOOLEAN, TRUE, + G_TYPE_INVALID); + } if (gss_mainloop == NULL) { gss_mainloop = g_main_loop_new(NULL, FALSE); -- cgit v1.2.3