aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dbus-shared-names.h4
-rw-r--r--src/gconf-helper.c5
-rw-r--r--src/indicator-session.c63
-rw-r--r--src/session-service.c19
4 files changed, 78 insertions, 13 deletions
diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h
index 11d62bb..41ac219 100644
--- a/src/dbus-shared-names.h
+++ b/src/dbus-shared-names.h
@@ -45,6 +45,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#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"
+
#define ICON_DEFAULT "system-shutdown-panel"
#define ICON_RESTART "system-shutdown-panel"
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 <http://www.gnu.org/licenses/>.
#include <libdbusmenu-glib/server.h>
#include <libdbusmenu-glib/menuitem.h>
+#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/indicator-session.c b/src/indicator-session.c
index de18bb3..3349886 100644
--- a/src/indicator-session.c
+++ b/src/indicator-session.c
@@ -20,9 +20,13 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <glib.h>
#include <glib-object.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <libdbusmenu-gtk/menu.h>
@@ -73,6 +77,7 @@ static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem
static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
static void icon_changed (DBusGProxy * proxy, gchar * icon_name, gpointer user_data);
static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data);
+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);
@@ -113,6 +118,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);
DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
self->service_proxy = dbus_g_proxy_new_for_name(session_bus,
@@ -307,6 +313,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
@@ -319,7 +379,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. */
diff --git a/src/session-service.c b/src/session-service.c
index 75c8650..ace4a7d 100644
--- a/src/session-service.c
+++ b/src/session-service.c
@@ -557,10 +557,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");
@@ -617,21 +618,21 @@ 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");
if (session_dbus != NULL) {
session_dbus_set_name(session_dbus, ICON_RESTART);
}
- } else {
+ } 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);
if (session_dbus != NULL) {
session_dbus_set_name(session_dbus, ICON_DEFAULT);
}