← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-session/lock-screen-sanity into lp:indicator-session

 

Ted Gould has proposed merging lp:~ted/indicator-session/lock-screen-sanity into lp:indicator-session.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


This changes the behavior of the menu item to always be "Lock Screen" and lock the screen.  While the other areas we lock in will check the GConf key.  Also it adds the keybinding to the menu item for the lock screen menu item.
-- 
https://code.launchpad.net/~ted/indicator-session/lock-screen-sanity/+merge/31986
Your team ayatana-commits is subscribed to branch lp:indicator-session.
=== modified file 'configure.ac'
--- configure.ac	2010-08-02 14:04:57 +0000
+++ configure.ac	2010-08-06 18:50:57 +0000
@@ -39,6 +39,7 @@
 DBUSMENUGLIB_REQUIRED_VERSION=0.1.1
 
 PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION
+						          dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION
                                   gio-unix-2.0
                                   indicator >= $INDICATOR_REQUIRED_VERSION)
 

=== modified file 'src/indicator-session.c'
--- src/indicator-session.c	2010-03-25 14:22:11 +0000
+++ src/indicator-session.c	2010-08-06 18:50:57 +0000
@@ -122,6 +122,9 @@
 	dbusmenu_client_add_type_handler(client, USER_ITEM_TYPE, new_user_item);
 	dbusmenu_client_add_type_handler(client, RESTART_ITEM_TYPE, build_restart_item);
 
+	GtkAccelGroup * agroup = gtk_accel_group_new();
+	dbusmenu_gtkclient_set_accel_group(DBUSMENU_GTKCLIENT(client), agroup);
+
 	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
 	self->service_proxy = dbus_g_proxy_new_for_name(session_bus,
 	                                                INDICATOR_SESSION_DBUS_NAME,

=== modified file 'src/lock-helper.c'
--- src/lock-helper.c	2010-03-16 21:52:17 +0000
+++ src/lock-helper.c	2010-08-06 18:50:57 +0000
@@ -176,9 +176,11 @@
 static gboolean
 activate_timeout (gpointer data)
 {
+	/* Clear the ID for the timeout */
 	guint * address = (guint *)data;
 	*address = 0;
 
+	/* Quit the mainloop */
 	if (gss_mainloop != NULL) {
 		g_main_loop_quit(gss_mainloop);
 	}
@@ -186,22 +188,6 @@
 	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
@@ -212,19 +198,10 @@
 	build_gss_proxy();
 	g_return_if_fail(gss_proxy != NULL);
 
-	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);
-	}
+	dbus_g_proxy_call_no_reply(gss_proxy,
+	                           "Lock",
+	                           G_TYPE_INVALID,
+	                           G_TYPE_INVALID);
 
 	if (gss_mainloop == NULL) {
 		gss_mainloop = g_main_loop_new(NULL, FALSE);
@@ -253,53 +230,3 @@
 	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-03-16 21:16:00 +0000
+++ src/lock-helper.h	2010-08-06 18:50:57 +0000
@@ -31,6 +31,4 @@
 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-08-02 13:50:07 +0000
+++ src/session-service.c	2010-08-06 18:50:57 +0000
@@ -36,6 +36,7 @@
 #include <libdbusmenu-glib/server.h>
 #include <libdbusmenu-glib/menuitem.h>
 #include <libdbusmenu-glib/client.h>
+#include <libdbusmenu-gtk/menuitem.h>
 
 #include <libindicator/indicator-service.h>
 
@@ -61,6 +62,9 @@
 #define LOCKDOWN_KEY_USER         LOCKDOWN_DIR "/disable_user_switching"
 #define LOCKDOWN_KEY_SCREENSAVER  LOCKDOWN_DIR "/disable_lock_screen"
 
+#define KEYBINDING_DIR            "/apps/gnome_settings_daemon/keybindings"
+#define KEY_LOCK_SCREEN           KEYBINDING_DIR "/screensaver"
+
 typedef struct _ActivateData ActivateData;
 struct _ActivateData
 {
@@ -119,6 +123,29 @@
 	return;
 }
 
+static void
+keybinding_changed (GConfClient *client,
+                    guint        cnxd_id,
+                    GConfEntry  *entry,
+                    gpointer     user_data)
+{
+	GConfValue  *value = gconf_entry_get_value (entry);
+	const gchar *key   = gconf_entry_get_key (entry);
+
+	if (value == NULL || key == NULL) {
+		return;
+	}
+
+	if (g_strcmp0 (key, KEY_LOCK_SCREEN) == 0) {
+		g_debug("Keybinding changed to: %s", gconf_value_get_string(value));
+		if (lock_menuitem != NULL) {
+			dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, gconf_value_get_string(value));
+		}
+	}
+
+	return;
+}
+
 /* Ensures that we have a GConf client and if we build one
    set up the signal handler. */
 static void
@@ -126,8 +153,12 @@
 {
 	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);
+
+		gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+		gconf_client_notify_add(gconf_client, KEYBINDING_DIR, keybinding_changed, NULL, NULL, NULL);
 	}
 	return;
 }
@@ -516,14 +547,19 @@
   /* Lock screen item */
   if (can_lockscreen) {
 	lock_menuitem = dbusmenu_menuitem_new();
-	if (will_lock_screen()) {
-		dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
+	dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
+
+	gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL);
+	if (shortcut != NULL) {
+		g_debug("Lock screen shortcut: %s", shortcut);
+		dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut);
+		g_free(shortcut);
 	} else {
-		dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Start Screensaver"));
+		g_debug("Unable to get lock screen shortcut.");
 	}
+
 	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);
   }
 
   /* Set to NULL just incase we don't end up building one */


Follow ups