[gdm-list] [PATCH 3/3] Add preferences dialog for user switch applet



Ports code from fast-user-switch-applet to add a preferences menu item
and dialog. Currently only the screen locking setting is supported.
---
 ChangeLog                                          |   12 ++
 .../GNOME_FastUserSwitchApplet.xml                 |    6 +
 gui/user-switch-applet/Makefile.am                 |    6 +
 gui/user-switch-applet/applet.c                    |  124 ++++++++++++++++
 .../gdm-user-switch-applet.glade                   |  156 ++++++++++++++++++++
 5 files changed, 304 insertions(+), 0 deletions(-)
 create mode 100644 gui/user-switch-applet/gdm-user-switch-applet.glade

diff --git a/ChangeLog b/ChangeLog
index b04c234..1ed82d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-10-12  Dan Nicholson <dbn lists gmail com>
 
+	* gui/user-switch-applet/applet.c (fill_applet), (prefs_cb),
+	(prefs_lock_check_toggled_cb), (make_label_bold):
+	Create preferences dialog from menu and support setting the lock
+	screen setting.
+	* gui/user-switch-applet/GNOME_FastUserSwitchApplet.xml:
+	Add menu item for Preferences dialog.
+	* gui/user-switch-applet/Makefile.am:
+	* gui/user-switch-applet/gdm-user-switch-applet.glade:
+	Install new glade file for preferences.
+
+2008-10-12  Dan Nicholson <dbn lists gmail com>
+
 	* gui/user-switch-applet/applet.c (do_switch), (fill_applet):
 	Register per-applet GConf keys. Check for
 	"lock_screen_after_switch" GConf key before locking the screen.
diff --git a/gui/user-switch-applet/GNOME_FastUserSwitchApplet.xml b/gui/user-switch-applet/GNOME_FastUserSwitchApplet.xml
index 6b4b184..721947f 100644
--- a/gui/user-switch-applet/GNOME_FastUserSwitchApplet.xml
+++ b/gui/user-switch-applet/GNOME_FastUserSwitchApplet.xml
@@ -12,6 +12,12 @@
       <separator
        name="GdmSeparator"/>
       <menuitem
+       name="Preferences Item"
+       verb="GdmPreferences"
+       _label="_Preferences"
+       pixtype="stock"
+       pixname="gtk-properties"/>
+      <menuitem
        name="Help Item"
        verb="GdmHelp"
        _label="_Help"
diff --git a/gui/user-switch-applet/Makefile.am b/gui/user-switch-applet/Makefile.am
index a14b08d..fc2a2db 100644
--- a/gui/user-switch-applet/Makefile.am
+++ b/gui/user-switch-applet/Makefile.am
@@ -49,6 +49,12 @@ $(server_in_files): $(server_in_files:.server.in=.server.in.in)
 
 @INTLTOOL_SERVER_RULE@
 
+# Glade UI
+gladedir = $(pkgdatadir)
+dist_glade_DATA =				\
+	gdm-user-switch-applet.glade		\
+	$(NULL)
+
 # GConf Schema
 schemadir =					\
 	$(GCONF_SCHEMA_FILE_DIR)		\
diff --git a/gui/user-switch-applet/applet.c b/gui/user-switch-applet/applet.c
index 2a5ab3b..e7d34fd 100644
--- a/gui/user-switch-applet/applet.c
+++ b/gui/user-switch-applet/applet.c
@@ -48,6 +48,8 @@
 #define LOCKDOWN_DIR    "/desktop/gnome/lockdown"
 #define LOCKDOWN_KEY    LOCKDOWN_DIR "/disable_user_switching"
 
+#define GLADE_XML_FILE  "gdm-user-switch-applet.glade"
+
 typedef struct _GdmAppletData
 {
         PanelApplet    *applet;
@@ -56,6 +58,8 @@ typedef struct _GdmAppletData
         GdmUserManager *manager;
         GdmUser        *user;
 
+        GtkWidget      *prefs;
+
         GtkWidget      *menubar;
         GtkWidget      *menuitem;
         GtkWidget      *menu;
@@ -84,6 +88,7 @@ typedef struct _SelectorResponseData
 static GtkTooltips *tooltips = NULL;
 
 static void reset_icon (GdmAppletData *adata);
+static void make_label_bold (GtkLabel *label);
 
 static gboolean applet_factory (PanelApplet   *applet,
                                 const char    *iid,
@@ -218,6 +223,93 @@ admin_cb (BonoboUIComponent *ui_container,
 }
 
 static void
+prefs_lock_check_toggled_cb (GtkToggleButton *button,
+                             gpointer         data)
+{
+        GdmAppletData *adata = data;
+
+        panel_applet_gconf_set_bool (adata->applet, LOCK_KEY,
+                                     gtk_toggle_button_get_active (button),
+                                     NULL);
+}
+
+static void
+prefs_cb (BonoboUIComponent *ui_container,
+          gpointer           data,
+          const char       *cname)
+{
+        GdmAppletData *adata;
+        GladeXML *xml;
+        GtkWidget *warning_box, *label, *username_radio, *text_radio,
+                  *icon_radio, *check;
+        char *key;
+        gboolean has_lockdown, label_setup_done;
+
+        adata = data;
+
+        if (adata->prefs) {
+                gtk_window_set_screen (GTK_WINDOW (adata->prefs),
+                                       gtk_widget_get_screen (GTK_WIDGET (adata->applet)));
+                gtk_window_present (GTK_WINDOW (adata->prefs));
+                return;
+        }
+
+        xml = glade_xml_new (DATADIR "/gdm/" GLADE_XML_FILE,
+                             "prefs_dialog",
+                             NULL);
+        if (!xml)
+                return;
+
+        adata->prefs = glade_xml_get_widget (xml, "prefs_dialog");
+        gtk_dialog_set_default_response (GTK_DIALOG (adata->prefs),
+                                         GTK_RESPONSE_CLOSE);
+        gtk_window_set_transient_for (GTK_WINDOW (adata->prefs),
+                                      GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (adata->applet))));
+        gtk_window_set_screen (GTK_WINDOW (adata->prefs),
+                               gtk_widget_get_screen (GTK_WIDGET (adata->applet)));
+        g_signal_connect (adata->prefs, "response",
+                          G_CALLBACK (gtk_widget_destroy), NULL);
+        g_signal_connect (adata->prefs, "delete-event",
+                          G_CALLBACK (gtk_true), NULL);
+        g_object_add_weak_pointer (G_OBJECT (adata->prefs),
+                                   (gpointer *) &adata->prefs);
+
+        warning_box = glade_xml_get_widget (xml, "warning_box");
+
+        label = glade_xml_get_widget (xml, "appearance_label");
+        make_label_bold (GTK_LABEL (label));
+
+        label = glade_xml_get_widget (xml, "options_label");
+        make_label_bold (GTK_LABEL (label));
+
+        username_radio = glade_xml_get_widget (xml, "username_radio");
+        text_radio = glade_xml_get_widget (xml, "text_radio");
+        icon_radio = glade_xml_get_widget (xml, "icon_radio");
+
+        has_lockdown = panel_applet_get_locked_down (adata->applet);
+
+        /* [_] Lock the screen after switching */
+        check = glade_xml_get_widget (xml, "lock_check");
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
+                                      panel_applet_gconf_get_bool (adata->applet,
+                                                                   LOCK_KEY,
+                                                                   NULL));
+        g_signal_connect (check, "toggled",
+                          G_CALLBACK (prefs_lock_check_toggled_cb),
+                          adata);
+
+        label_setup_done = FALSE;
+        key = panel_applet_gconf_get_full_key (adata->applet, LOCK_KEY);
+        if (has_lockdown ||
+            !gconf_client_key_is_writable (adata->client, key, NULL))
+                gtk_widget_set_sensitive (check, FALSE);
+
+        g_free (key);
+
+        gtk_window_present (GTK_WINDOW (adata->prefs));
+}
+
+static void
 set_menuitem_icon (BonoboUIComponent *component,
                    const char        *item_path,
                    GtkIconTheme      *theme,
@@ -475,6 +567,9 @@ gdm_applet_data_free (GdmAppletData *adata)
         if (adata->user != NULL) {
                 g_object_unref (adata->user);
         }
+        if (adata->prefs != NULL) {
+                gtk_widget_destroy (adata->prefs);
+        }
         g_object_unref (adata->client);
         g_object_unref (adata->manager);
         g_object_unref (tooltips);
@@ -1130,12 +1225,36 @@ setup_current_user (GdmAppletData *adata)
         }
 }
 
+static void
+make_label_bold (GtkLabel *label)
+{
+        PangoAttrList *list;
+        PangoAttribute *attr;
+        gboolean existing_list;
+
+        list = gtk_label_get_attributes (label);
+        existing_list = (list != NULL);
+        if (!existing_list)
+                list = pango_attr_list_new ();
+        else
+                pango_attr_list_ref (list);
+
+        attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
+        attr->start_index = 0;
+        attr->end_index = (guint) -1;
+        pango_attr_list_insert (list, attr);
+
+        gtk_label_set_attributes (label, list);
+        pango_attr_list_unref (list);
+}
+
 static gboolean
 fill_applet (PanelApplet *applet)
 {
         static const BonoboUIVerb menu_verbs[] = {
                 BONOBO_UI_VERB ("GdmAboutMe", about_me_cb),
                 BONOBO_UI_VERB ("GdmUsersGroupsAdmin", admin_cb),
+                BONOBO_UI_VERB ("GdmPreferences", prefs_cb),
                 BONOBO_UI_VERB ("GdmAbout", about_cb),
                 BONOBO_UI_VERB_END
         };
@@ -1195,6 +1314,11 @@ fill_applet (PanelApplet *applet)
 
         popup_component = panel_applet_get_popup_component (applet);
 
+        if (panel_applet_get_locked_down (applet))
+                bonobo_ui_component_set_prop (popup_component,
+                                              "/commands/GdmPreferences",
+                                              "hidden", "0", NULL);
+
         /* Hide the admin context menu items if locked down or no cmd-line */
         if (gconf_client_get_bool (adata->client,
                                    "/desktop/gnome/lockdown/inhibit_command_line",
diff --git a/gui/user-switch-applet/gdm-user-switch-applet.glade b/gui/user-switch-applet/gdm-user-switch-applet.glade
new file mode 100644
index 0000000..dfb0833
--- /dev/null
+++ b/gui/user-switch-applet/gdm-user-switch-applet.glade
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--*- mode: xml -*-->
+<glade-interface>
+  <widget class="GtkDialog" id="prefs_dialog">
+    <property name="border_width">6</property>
+    <property name="title" translatable="yes">User Switcher Preferences</property>
+    <property name="type">GTK_WINDOW_TOPLEVEL</property>
+    <property name="window_position">GTK_WIN_POS_NONE</property>
+    <property name="modal">False</property>
+    <property name="resizable">False</property>
+    <property name="destroy_with_parent">False</property>
+    <property name="role">Prefs</property>
+    <property name="decorated">True</property>
+    <property name="skip_taskbar_hint">False</property>
+    <property name="skip_pager_hint">False</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+    <property name="focus_on_map">True</property>
+    <property name="has_separator">False</property>
+
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog_box">
+        <property name="visible">True</property>
+        <property name="homogeneous">False</property>
+        <property name="spacing">1</property>
+
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog_action_area">
+            <property name="visible">True</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+            <child>
+              <widget class="GtkButton" id="close_button">
+                <property name="visible">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="can_focus">True</property>
+                <property name="label">gtk-close</property>
+                <property name="use_stock">True</property>
+                <property name="relief">GTK_RELIEF_NORMAL</property>
+                <property name="focus_on_click">True</property>
+                <property name="response_id">-7</property>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="padding">0</property>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+
+        <child>
+          <widget class="GtkVBox" id="main_box">
+            <property name="border_width">6</property>
+            <property name="visible">True</property>
+            <property name="homogeneous">False</property>
+            <property name="spacing">12</property>
+
+            <child>
+              <widget class="GtkVBox" id="options_box">
+                <property name="visible">True</property>
+                <property name="homogeneous">False</property>
+                <property name="spacing">0</property>
+
+                <child>
+                  <widget class="GtkLabel" id="options_label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Options</property>
+                    <property name="use_underline">False</property>
+                    <property name="use_markup">False</property>
+                    <property name="justify">GTK_JUSTIFY_LEFT</property>
+                    <property name="wrap">False</property>
+                    <property name="selectable">False</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0.5</property>
+                    <property name="xpad">0</property>
+                    <property name="ypad">0</property>
+                    <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                    <property name="width_chars">-1</property>
+                    <property name="single_line_mode">False</property>
+                    <property name="angle">0</property>
+                  </widget>
+                  <packing>
+                    <property name="padding">0</property>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+
+                <child>
+                  <widget class="GtkAlignment" id="options_alignment">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.5</property>
+                    <property name="yalign">0.5</property>
+                    <property name="xscale">1</property>
+                    <property name="yscale">1</property>
+                    <property name="top_padding">6</property>
+                    <property name="bottom_padding">0</property>
+                    <property name="left_padding">12</property>
+                    <property name="right_padding">0</property>
+
+                    <child>
+                      <widget class="GtkVBox" id="options_box">
+                        <property name="visible">True</property>
+                        <property name="homogeneous">False</property>
+                        <property name="spacing">6</property>
+
+                        <child>
+                          <widget class="GtkCheckButton" id="lock_check">
+                            <property name="visible">True</property>
+                            <property name="tooltip" translatable="yes">When changing to a different display, activate the screensaver for this display.</property>
+                            <property name="can_focus">True</property>
+                            <property name="label" translatable="yes">_Lock the screen after switching users</property>
+                            <property name="use_underline">True</property>
+                            <property name="relief">GTK_RELIEF_NORMAL</property>
+                            <property name="focus_on_click">True</property>
+                            <property name="active">True</property>
+                            <property name="inconsistent">False</property>
+                            <property name="draw_indicator">True</property>
+                          </widget>
+                          <packing>
+                            <property name="padding">0</property>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="padding">0</property>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="padding">0</property>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="padding">0</property>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>
-- 
1.5.5.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]