ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #01206
[Merge] lp:~ted/indicator-session/not-really-locking-screen into lp:indicator-session
Ted Gould has proposed merging lp:~ted/indicator-session/not-really-locking-screen into lp:indicator-session.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
Make it so that we follow the GConf key for the screensaver to see if
we're locking or not. If we're not, we update the label to make it
correct.
--
https://code.launchpad.net/~ted/indicator-session/not-really-locking-screen/+merge/21501
Your team ayatana-commits is subscribed to branch lp:indicator-session.
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2010-03-03 21:49:41 +0000
+++ po/POTFILES.in 2010-03-16 21:55:25 +0000
@@ -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
=== modified file 'src/lock-helper.c'
--- src/lock-helper.c 2010-03-16 01:47:28 +0000
+++ src/lock-helper.c 2010-03-16 21:55:25 +0000
@@ -19,9 +19,14 @@
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <glib/gi18n.h>
+#include <gconf/gconf-client.h>
#include <dbus/dbus-glib.h>
#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 +34,8 @@
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 +131,11 @@
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
@@ -175,24 +186,45 @@
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);
@@ -221,3 +253,53 @@
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. */
+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
+ another. */
+void
+lock_screen_update_item (DbusmenuMenuitem * mi)
+{
+ if (gconf_client == NULL) {
+ 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;
+}
=== modified file 'src/lock-helper.h'
--- src/lock-helper.h 2010-02-08 16:59:44 +0000
+++ src/lock-helper.h 2010-03-16 21:55:25 +0000
@@ -31,4 +31,6 @@
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__ */
=== modified file 'src/session-service.c'
--- src/session-service.c 2010-03-16 15:06:31 +0000
+++ src/session-service.c 2010-03-16 21:55:25 +0000
@@ -509,14 +509,14 @@
/* Lock screen item */
if (can_lockscreen) {
lock_menuitem = dbusmenu_menuitem_new();
- dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
+ if (will_lock_screen()) {
+ dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
+ } else {
+ 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);
- 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);
- }
+ lock_screen_update_item(lock_menuitem);
}
/* Build all of the user switching items */
Follow ups