ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #01258
[Merge] lp:~dbarth/indicator-me/display-mode-gconf-key into lp:indicator-me
David Barth has proposed merging lp:~dbarth/indicator-me/display-mode-gconf-key into lp:indicator-me with lp:~dbarth/indicator-me/misc-fixes as a prerequisite.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
gconf key to be able to set the indicator display mode (username, realname, anonymous)
--
https://code.launchpad.net/~dbarth/indicator-me/display-mode-gconf-key/+merge/21968
Your team ayatana-commits is subscribed to branch lp:indicator-me.
=== modified file 'src/indicator-me.c'
--- src/indicator-me.c 2010-03-23 18:43:19 +0000
+++ src/indicator-me.c 2010-03-23 18:43:19 +0000
@@ -137,14 +137,19 @@
static void
username_cb (DBusGProxy * proxy, char * username, GError *error, gpointer userdata)
{
- if (label == NULL)
+ if (label == NULL) {
label = GTK_LABEL(gtk_label_new(NULL));
+ if (label == NULL) return;
+ }
if (username != NULL && username[0] != '\0') {
g_debug ("Updating username label");
gtk_label_set_text (label, username);
gtk_widget_show(GTK_WIDGET(label));
+ } else {
+ gtk_widget_hide(GTK_WIDGET(label));
}
+
}
static GtkLabel *
@@ -218,6 +223,9 @@
dbus_g_proxy_add_signal(status_proxy, "StatusIconsChanged", G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(status_proxy, "StatusIconsChanged", G_CALLBACK(status_icon_changed), NULL, NULL);
+
+ dbus_g_proxy_add_signal(status_proxy, "UserChanged", G_TYPE_STRING, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal(status_proxy, "UserChanged", G_CALLBACK(username_cb), NULL, NULL);
}
org_ayatana_indicator_me_service_status_icons_async(status_proxy, status_icon_cb, NULL);
@@ -324,6 +332,8 @@
if (!g_strcmp0(prop, DBUSMENU_ABOUT_ME_MENUITEM_PROP_ICON)) {
/* reload the avatar icon */
about_me_menu_item_load_avatar (item, g_value_get_string(value));
+ } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) {
+ /* normal, ignore */
} else {
g_warning("Indicator Item property '%s' unknown", prop);
}
=== modified file 'src/me-service.c'
--- src/me-service.c 2010-03-23 18:43:19 +0000
+++ src/me-service.c 2010-03-23 18:43:19 +0000
@@ -90,6 +90,7 @@
static StatusProviderStatus global_status = STATUS_PROVIDER_STATUS_DISCONNECTED;
static GFileMonitor *avatar_monitor = NULL;
static DbusmenuMenuitem *broadcast_field = NULL;
+static DbusmenuMenuitem * useritem = NULL;
static void
status_update (void) {
@@ -294,31 +295,47 @@
return FALSE;
}
-#define GCONF_ANONYMOUS "/system/indicator/me/anonymous"
+#define GCONF_NAMESPACE "/system/indicator/me"
+#define GCONF_DISPLAY "/system/indicator/me/display"
-static gboolean
-anonymous_mode (void)
+static void
+display_mode_changed ()
{
- GConfClient *context = NULL;
- GConfValue *option = NULL;
- gboolean value = FALSE; /* not anonymous, by default */
-
- context = gconf_client_get_default ();
- if (! context) {
- g_warning ("Couldn't get a gconf context");
- return FALSE;
- }
-
- option = gconf_client_get (context, GCONF_ANONYMOUS, NULL);
+ GConfClient *context = gconf_client_get_default ();
+ g_return_if_fail (context != NULL);
+
+ GConfValue *option = gconf_client_get (context, GCONF_DISPLAY, NULL);
+ gint value = 1; /* username, by default */
+
+ g_debug ("display_mode_changed");
+
if (option != NULL &&
- option->type == GCONF_VALUE_BOOL)
- value = gconf_value_get_bool (option);
+ option->type == GCONF_VALUE_INT)
+ value = gconf_value_get_int (option);
+
+ switch (value) {
+ case 0: /* anonymous */
+ status_service_dbus_set_username (dbus_interface, "");
+ break;
+ default:
+ case 1:
+ status_service_dbus_set_username (dbus_interface, g_get_user_name ());
+ break;
+ case 2:
+ status_service_dbus_set_username (dbus_interface, g_get_real_name ());
+ break;
+ }
+
+ dbusmenu_menuitem_property_set_bool (useritem,
+ DBUSMENU_MENUITEM_PROP_VISIBLE,
+ (value == 0) ? FALSE : TRUE);
g_object_unref (context);
- return value;
+ return;
}
+
static void
avatar_changed_cb (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data)
{
@@ -337,24 +354,10 @@
static void
build_user_item (DbusmenuMenuitem * root)
{
- struct passwd * pwd = NULL;
-
- if (anonymous_mode ())
- return;
-
- pwd = getpwuid(getuid());
-
- if (pwd != NULL && pwd->pw_name != NULL && pwd->pw_name[0] != '\0') {
- status_service_dbus_set_username(dbus_interface, pwd->pw_name);
- } else {
- g_warning ("PWD: %s", (pwd == NULL ? "(pwd null)" : (pwd->pw_name == NULL ? "(pw_name null)" : pwd->pw_name)));
-
- /* that's kind of an anonymous mode too if ever that can happen */
- return;
- }
-
- DbusmenuMenuitem * useritem = dbusmenu_menuitem_new();
+ useritem = dbusmenu_menuitem_new();
+ dbusmenu_menuitem_property_set(useritem, DBUSMENU_ABOUT_ME_MENUITEM_PROP_NAME, g_get_real_name ());
dbusmenu_menuitem_property_set_bool(useritem, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
+ dbusmenu_menuitem_property_set_bool(useritem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
dbusmenu_menuitem_property_set(useritem, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_ABOUT_ME_MENUITEM_TYPE);
dbusmenu_menuitem_child_append(root, useritem);
@@ -377,21 +380,18 @@
g_free(gam);
}
- if (pwd != NULL && pwd->pw_gecos != NULL) {
- gchar * name = g_strdup(pwd->pw_gecos);
- gchar * walker = name;
- while (*walker != '\0' && *walker != ',') { walker++; }
- *walker = '\0';
-
- if (name[0] != '\0') {
- dbusmenu_menuitem_property_set(useritem, DBUSMENU_ABOUT_ME_MENUITEM_PROP_NAME, name);
- } else {
- /* fallback on the username, at least we know it's not null from above */
- dbusmenu_menuitem_property_set(useritem, DBUSMENU_ABOUT_ME_MENUITEM_PROP_NAME, pwd->pw_name);
- }
-
- g_free(name);
- }
+ /* set the menu name */
+ display_mode_changed ();
+
+ /* and receive display mode notifications to update it later */
+ GConfClient *context = gconf_client_get_default ();
+ if (context != NULL) {
+ gconf_client_add_dir (context, GCONF_NAMESPACE,
+ GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ gconf_client_notify_add (context, GCONF_DISPLAY,
+ display_mode_changed, NULL, NULL, NULL);
+ g_object_unref (context);
+ }
return;
}
Follow ups