← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~bratsche/indicator-session/lockdown into lp:indicator-session

 

Cody Russell has proposed merging lp:~bratsche/indicator-session/lockdown into lp:indicator-session.

    Requested reviews:
    Indicator Applet Developers (indicator-applet-developers)
Related bugs:
  #504360 Switch user ... cannot be removed
  https://bugs.launchpad.net/bugs/504360


This works when you login to your session, but note that it doesn't currently work if the gconf key changes during your session.  I'm not exactly sure, but we'll file a bug to deal with that separately.
-- 
https://code.launchpad.net/~bratsche/indicator-session/lockdown/+merge/18857
Your team ayatana-commits is subscribed to branch lp:indicator-session.
=== modified file 'src/session-service.c'
--- src/session-service.c	2010-02-05 00:58:28 +0000
+++ src/session-service.c	2010-02-08 17:27:16 +0000
@@ -50,6 +50,9 @@
 
 #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"
+
 typedef struct _ActivateData ActivateData;
 struct _ActivateData
 {
@@ -62,6 +65,7 @@
 static UsersServiceDbus  *dbus_interface = NULL;
 
 static DbusmenuMenuitem  *lock_menuitem = NULL;
+static DbusmenuMenuitem  *switch_menuitem = NULL;
 
 static gint   count;
 static GList *users;
@@ -80,6 +84,53 @@
 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,
+                  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 || !key)
+    return;
+
+  if (g_strcmp0 (key, LOCKDOWN_KEY) == 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);
+            }
+        }
+    }
+}
+
+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,
+                                                    lockdown_changed,
+                                                    NULL,
+                                                    NULL,
+                                                    NULL);
+    }
+}
+
 /* A return from the command to sleep the system.  Make sure
    that we unthrottle the screensaver. */
 static void
@@ -441,13 +492,24 @@
 
       if (check_new_session ())
         {
-          mi = dbusmenu_menuitem_new ();
-          dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch User..."));
-          dbusmenu_menuitem_child_append (root, mi);
-          g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL);
+          ensure_gconf_client ();
+
+          switch_menuitem = dbusmenu_menuitem_new ();
+          dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch User..."));
+          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))
+            {
+              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);
+            }
         }
     }
-	
+
 	DbusmenuMenuitem * separator = dbusmenu_menuitem_new();
 	dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
 	dbusmenu_menuitem_child_append(root, separator);


Follow ups