aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-session.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/indicator-session.c')
-rw-r--r--src/indicator-session.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/indicator-session.c b/src/indicator-session.c
index 0282616..4ae9c66 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>
@@ -74,6 +78,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);
@@ -114,6 +119,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,
@@ -308,6 +314,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
@@ -320,7 +380,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. */