From a4eb496c3b8f5455357ef2760e003e04d781f885 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Mar 2010 20:56:35 -0600 Subject: A bunch of properties to make our new menu item type. --- src/dbus-shared-names.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 253cba8..9d39ab3 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -42,4 +42,8 @@ with this program. If not, see . #define USER_ITEM_PROP_NAME "user-item-name" #define USER_ITEM_PROP_LOGGED_IN "user-item-logged-in" +#define RESTART_ITEM_TYPE "x-canonical-restart-item" +#define RESTART_ITEM_LABEL "restart-label" +#define RESTART_ITEM_ICON "restart-icon" + #endif /* __DBUS_SHARED_NAMES_H__ */ -- cgit v1.2.3 From fb8754f048176039d268157a22da3745773bd15b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 12:25:58 -0600 Subject: Adding in a handler and renderer for the restart required item --- src/indicator-session.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/indicator-session.c b/src/indicator-session.c index a815e40..fab3463 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -69,6 +69,7 @@ static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); @@ -108,6 +109,7 @@ indicator_session_init (IndicatorSession *self) DbusmenuClient * client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(self->menu)); dbusmenu_client_add_type_handler(client, MENU_SWITCH_TYPE, build_menu_switch); dbusmenu_client_add_type_handler(client, USER_ITEM_TYPE, new_user_item); + dbusmenu_client_add_type_handler(client, RESTART_ITEM_TYPE, build_restart_item); return; } @@ -253,6 +255,60 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G static const gchar * dbusmenu_item_data = "dbusmenu-item"; +/* IF the label or icon changes we need to grab that and update + the menu item */ +static void +restart_property_change (DbusmenuMenuitem * item, const gchar * property, const GValue * value, gpointer user_data) +{ + DbusmenuGtkClient * client = DBUSMENU_GTKCLIENT(user_data); + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(client, item); + + if (g_strcmp0(property, RESTART_ITEM_LABEL) == 0) { + gtk_menu_item_set_label(gmi, g_value_get_string(value)); + } else if (g_strcmp0(property, RESTART_ITEM_ICON) == 0) { + GtkWidget * image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(gmi)); + + if (image == NULL) { + image = gtk_image_new_from_icon_name(g_value_get_string(value), GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gmi), image); + } else { + gtk_image_set_from_icon_name(GTK_IMAGE(image), g_value_get_string(value), GTK_ICON_SIZE_MENU); + } + } + + return; +} + +/* Builds the restart item which is a more traditional GTK image + menu item that puts the graphic into the gutter. */ +static gboolean +build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_image_menu_item_new()); + if (gmi == NULL) { + return FALSE; + } + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + + g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(restart_property_change), client); + + /* Grab the inital values and put them into the item */ + const GValue * value; + value = dbusmenu_menuitem_property_get_value(newitem, RESTART_ITEM_LABEL); + if (value != NULL) { + restart_property_change(newitem, RESTART_ITEM_LABEL, value, client); + } + + value = dbusmenu_menuitem_property_get_value(newitem, RESTART_ITEM_ICON); + if (value != NULL) { + restart_property_change(newitem, RESTART_ITEM_ICON, value, client); + } + + return TRUE; +} + + /* Callback for when the style changes so we can reevaluate the size of the user name with the potentially new font. */ static void @@ -265,7 +321,6 @@ switch_style_set (GtkWidget * widget, GtkStyle * prev_style, gpointer user_data) return; } - /* This function checks to see if the user name is short enough to not need ellipsing itself, or if, it will get ellipsed by the standard label processor. */ -- cgit v1.2.3 From 9bfcbd2b420b19a43d1704c6562d4709ebb570f6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 12:39:47 -0600 Subject: Changing the service to use the new menu item --- src/gconf-helper.c | 5 +++-- src/session-service.c | 17 +++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/gconf-helper.c b/src/gconf-helper.c index 9262b19..5efc439 100644 --- a/src/gconf-helper.c +++ b/src/gconf-helper.c @@ -30,6 +30,7 @@ with this program. If not, see . #include #include +#include "dbus-shared-names.h" #include "gconf-helper.h" static GConfClient * gconf_client = NULL; @@ -50,11 +51,11 @@ static void update_menu_entries_callback (GConfClient *client, guint cnxn_id, GC if(g_strcmp0 (key, SUPPRESS_KEY) == 0) { if (gconf_value_get_bool (value)) { dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out")); - dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart")); + dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, RESTART_ITEM_LABEL, _("Restart")); dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch Off")); } else { dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out...")); - dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart...")); + dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, RESTART_ITEM_LABEL, _("Restart...")); dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch Off...")); } } diff --git a/src/session-service.c b/src/session-service.c index febf007..51a930a 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -555,10 +555,11 @@ rebuild_items (DbusmenuMenuitem *root, g_signal_connect(G_OBJECT(hibernate_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Hibernate"); restart_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_TYPE, RESTART_ITEM_TYPE); if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart")); + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); } else { - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart...")); + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart...")); } dbusmenu_menuitem_child_append(root, restart_mi); g_signal_connect(G_OBJECT(restart_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "restart"); @@ -615,18 +616,18 @@ restart_dir_changed (void) if (restart_required) { if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart Required")); + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart Required")); } else { - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart Required...")); + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart Required...")); } - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_ICON_NAME, "emblem-important"); + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_ICON, "emblem-important"); } else { if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart")); + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); } else { - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart...")); + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart...")); } - dbusmenu_menuitem_property_remove(restart_mi, DBUSMENU_MENUITEM_PROP_ICON_NAME); + dbusmenu_menuitem_property_remove(restart_mi, RESTART_ITEM_ICON); } return; -- cgit v1.2.3