Re: [gnome-flashback] Hiding the users name in the user menu



Hi,

This patch adds a new gsettings key that allows to
hide the user name label. The result off this is, that
only the icon is shown in the panel.

By default the flag is true meaning the user name label is shown, so noting is changed unless this flag is explicitly disabled in the dconf-editor.

Could anyone review the patch and give me some feedback.

From ef575d1f4fdce6fc0989583cecd820caf55fccf0 Mon Sep 17 00:00:00 2001
From: Sebastian Geiger <sbastig gmx net>
Date: Sat, 5 Oct 2013 00:02:02 +0200
Subject: [PATCH] User menu: Make user name label optional

 * Currently the built-in "User menu" applet
   does not have a way to hide the user name label.
   This patch adds a new gsettings key that allows to
   hide the user name label. The result off this is, that
   only the icon is shown in the panel.
---
 data/org.gnome.gnome-panel.gschema.xml.in.in |  9 +++++++++
 gnome-panel/panel-menu-items.c               | 13 ++++++++++++-
 gnome-panel/panel-schemas.h                  |  3 +++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/data/org.gnome.gnome-panel.gschema.xml.in.in b/data/org.gnome.gnome-panel.gschema.xml.in.in
index ab8682b..173625a 100644
--- a/data/org.gnome.gnome-panel.gschema.xml.in.in
+++ b/data/org.gnome.gnome-panel.gschema.xml.in.in
@@ -5,6 +5,7 @@
     <child name="layout" schema="org.gnome.gnome-panel.layout"/>
     <child name="lockdown" schema="org.gnome.gnome-panel.lockdown"/>
     <child name="run-dialog" schema="org.gnome.gnome-panel.run-dialog"/>
+    <child name="applets" schema="org.gnome.gnome-panel.applets" />
   </schema>

<schema id="org.gnome.gnome-panel.general" path="/org/gnome/gnome-panel/general/">
@@ -74,4 +75,12 @@
     </key>
   </schema>

+ <schema id="org.gnome.gnome-panel.applets" path="/org/gnome/gnome-panel/applet/">
+    <key type="b" name="show-user-name">
+      <default>true</default>
+      <_summary>Control if the user name is shown.</_summary>
+ <_description>Set to false to hide the name of the logged-in user in the 'User menu' applet, true otherwise. If set to false, only the icon will be shown in the panel.</_description>
+    </key>
+  </schema>
+
 </schemalist>
diff --git a/gnome-panel/panel-menu-items.c b/gnome-panel/panel-menu-items.c
index be60a00..60ffad6 100644
--- a/gnome-panel/panel-menu-items.c
+++ b/gnome-panel/panel-menu-items.c
@@ -62,6 +62,7 @@
 #include "panel-recent.h"
 #include "panel-stock-icons.h"
 #include "panel-util.h"
+#include "panel-schemas.h"

 #define DESKTOP_IS_HOME_DIR_DIR "/apps/nautilus/preferences"
#define DESKTOP_IS_HOME_DIR_KEY "/apps/nautilus/preferences/desktop_is_home_dir"
@@ -1709,6 +1710,7 @@ panel_desktop_menu_item_new (gboolean use_image,
        PanelDesktopMenuItem *menuitem;
        char                 *name;
        const char           *icon_name;
+       GSettings *settings;
 #ifdef HAVE_TELEPATHY_GLIB
        PanelSessionManager  *manager;
 #endif
@@ -1716,6 +1718,9 @@ panel_desktop_menu_item_new (gboolean use_image,
        menuitem = g_object_new (PANEL_TYPE_DESKTOP_MENU_ITEM, NULL);

        name = panel_util_get_user_name ();
+
+       settings = g_settings_new (PANEL_APPLETS_SCHEMA);
+
 #ifdef HAVE_TELEPATHY_GLIB
        icon_name = PANEL_ICON_USER_AVAILABLE;
 #else
@@ -1725,7 +1730,12 @@ panel_desktop_menu_item_new (gboolean use_image,
        /* if we're in a menubar, we don't want to use setup_* as it changes
         * the size requests and can make the panels bigger than we'd like */
        if (in_menubar) {
-               gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), name);
+ gboolean show_user_name = g_settings_get_boolean (settings, "show-user-name");
+               if(show_user_name) {
+                       gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), name);
+               } else {
+                       gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), "");
+               }
                menuitem->priv->icon_size = panel_menu_bar_object_icon_get_size ();

                if (use_image) {
@@ -1756,6 +1766,7 @@ panel_desktop_menu_item_new (gboolean use_image,
 #endif

        g_free (name);
+       g_object_unref (settings);

        menuitem->priv->menu = panel_desktop_menu_item_create_menu (menuitem,
                                                                    append_lock_logout);
diff --git a/gnome-panel/panel-schemas.h b/gnome-panel/panel-schemas.h
index a2543ac..917f0eb 100644
--- a/gnome-panel/panel-schemas.h
+++ b/gnome-panel/panel-schemas.h
@@ -77,4 +77,7 @@
 #define PANEL_MENU_BUTTON_CUSTOM_ICON_KEY "custom-icon"
 #define PANEL_MENU_BUTTON_MENU_PATH_KEY   "menu-path"

+#define PANEL_APPLETS_SCHEMA            "org.gnome.gnome-panel.applets"
+#define PANEL_APPLETS_SHOW_USER_MENU    "show-user-menu"
+
 #endif /* __PANEL_SCHEMAS_H__ */
--
1.8.1.2






On 02/10/13 23:00, Lanoxx wrote:
Hi,

I have been wanting to change this for some time now, but never found
the time to go through the code and find the right place. The "User
menu" creats a widget in the panel that shows an icon (either a computer
or a speech bubble) plus the name of the currently logged in user. Since
the user name can get very long and on my notebook I do not have that
much screen real estate I would like to make this optional. After
searching a bit through the code I came up with the following change:

Obviously I would need to save the show_user_name state somewhere and
make it available through preferences. My question is, where would be a
suitable place to save this?

--- a/gnome-panel/panel-menu-items.c
+++ b/gnome-panel/panel-menu-items.c
@@ -1725,7 +1725,11 @@ panel_desktop_menu_item_new (gboolean use_image,
      /* if we're in a menubar, we don't want to use setup_* as it changes
       * the size requests and can make the panels bigger than we'd like */
      if (in_menubar) {
-        gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), name);
+        gboolean show_user_name = FALSE;
+        if(show_user_name) {
+            gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), name);
+        } else {
+            gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), "");
+        }

Btw. the code concerning the applets is quite messy and not documented
at all. If anyone wants to go and clean it up I would be happy to help.

Regards
Sebastian


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