From 14bcf1b8a8ada10beee5f13a5bec9854d4e58a13 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 11:30:06 -0500 Subject: Adding a disposition property in to the header and defaults --- libdbusmenu-glib/defaults.c | 1 + libdbusmenu-glib/menuitem.h | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libdbusmenu-glib/defaults.c b/libdbusmenu-glib/defaults.c index aa479b1..a5caf0b 100644 --- a/libdbusmenu-glib/defaults.c +++ b/libdbusmenu-glib/defaults.c @@ -87,6 +87,7 @@ dbusmenu_defaults_init (DbusmenuDefaults *self) dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, G_VARIANT_TYPE_INT32, NULL); dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_SHORTCUT, G_VARIANT_TYPE("aas"), NULL); dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY, G_VARIANT_TYPE_STRING, NULL); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_DISPOSITION, G_VARIANT_TYPE_STRING, g_variant_new_string(DBUSMENU_MENUITEM_DISPOSITION_NORMAL)); /* Separator defaults */ dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_SEPARATOR, DBUSMENU_MENUITEM_PROP_VISIBLE, G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(TRUE)); diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index afd1d4e..96a780e 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -184,6 +184,13 @@ G_BEGIN_DECLS * #DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU. Type: #G_VARIANT_TYPE_STRING */ #define DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY "children-display" +/** + * DBUSMENU_MENUITEM_PROP_DISPOSITION: + * + * #DbusmenuMenuitem property to tell what type of information that the + * menu item is displaying to the user. Type: #G_VARIANT_TYPE_STRING + */ +#define DBUSMENU_MENUITEM_PROP_DISPOSITION "disposition" /** * DBUSMENU_MENUITEM_TOGGLE_CHECK: @@ -267,6 +274,38 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU "submenu" +/** + * DBUSMENU_MENUITEM_DISPOSITION_NORMAL: + * + * Used in #DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu + * item displayed in the normal manner. Default value. + */ +#define DBUSMENU_MENUITEM_DISPOSITION_NORMAL "normal" +/** + * DBUSMENU_MENUITEM_DISPOSITION_INFORMATION: + * + * Used in #DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu + * item displayed in a way that conveys it's giving additional + * information to the user. + */ +#define DBUSMENU_MENUITEM_DISPOSITION_INFORMATION "information" +/** + * DBUSMENU_MENUITEM_DISPOSITION_WARNING: + * + * Used in #DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu + * item displayed in a way that conveys it's giving a warning + * to the user. + */ +#define DBUSMENU_MENUITEM_DISPOSITION_WARNING "warning" +/** + * DBUSMENU_MENUITEM_DISPOSITION_ALERT: + * + * Used in #DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu + * item displayed in a way that conveys it's giving an alert + * to the user. + */ +#define DBUSMENU_MENUITEM_DISPOSITION_ALERT "alert" + /** * DBUSMENU_MENUITEM_EVENT_ACTIVATED: * -- cgit v1.2.3 From 963f191abe4422b152cd048ace48172095dcb566 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 11:35:02 -0500 Subject: Updating the protocol spec --- libdbusmenu-glib/dbus-menu.xml | 13 +++++++++++++ libdbusmenu-glib/menuitem.h | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-glib/dbus-menu.xml b/libdbusmenu-glib/dbus-menu.xml index a36c148..4b5a5d8 100644 --- a/libdbusmenu-glib/dbus-menu.xml +++ b/libdbusmenu-glib/dbus-menu.xml @@ -157,6 +157,19 @@ License version 3 and version 2.1 along with this program. If not, see "" + + disposition + string + + How the menuitem feels the information it's displaying to the + user should be presented. + - "normal" a standard menu item + - "informative" providing additional information to the user + - "warning" looking at potentially harmful results + - "alert" something bad could potentially happen + + "normal" + Vendor specific properties can be added by prefixing them with diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 96a780e..ea18b65 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -282,13 +282,13 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_DISPOSITION_NORMAL "normal" /** - * DBUSMENU_MENUITEM_DISPOSITION_INFORMATION: + * DBUSMENU_MENUITEM_DISPOSITION_INFORMATIVE: * * Used in #DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu * item displayed in a way that conveys it's giving additional * information to the user. */ -#define DBUSMENU_MENUITEM_DISPOSITION_INFORMATION "information" +#define DBUSMENU_MENUITEM_DISPOSITION_INFORMATIVE "informative" /** * DBUSMENU_MENUITEM_DISPOSITION_WARNING: * -- cgit v1.2.3 From dd3f0434bf7dc121dd8b949e354c305181fd5b66 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 11:39:13 -0500 Subject: Putting in some headers to make this file easier to read --- libdbusmenu-glib/menuitem.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index ea18b65..985e1a3 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -41,7 +41,9 @@ G_BEGIN_DECLS #define DBUSMENU_IS_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_MENUITEM)) #define DBUSMENU_MENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_MENUITEM, DbusmenuMenuitemClass)) - +/* ***************************************** */ +/* ********* GLib Object Signals ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED: * @@ -103,6 +105,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_SIGNAL_EVENT "event" +/* ***************************************** */ +/* ********* Menuitem Properties ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_PROP_TYPE: * @@ -192,6 +197,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_PROP_DISPOSITION "disposition" +/* ***************************************** */ +/* ********* Toggle Values ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_TOGGLE_CHECK: * @@ -207,6 +215,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_TOGGLE_RADIO "radio" +/* ***************************************** */ +/* ********* Toggle States ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED: * @@ -229,6 +240,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN -1 +/* ***************************************** */ +/* ********* Icon specials ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_ICON_NAME_BLANK: * @@ -237,6 +251,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_ICON_NAME_BLANK "blank-icon" +/* ***************************************** */ +/* ********* Shortcut Modifiers ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_SHORTCUT_CONTROL: * @@ -266,6 +283,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_SHORTCUT_SUPER "Super" +/* ***************************************** */ +/* ********* Child Display Types ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU: * @@ -274,6 +294,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU "submenu" +/* ***************************************** */ +/* ********* Menuitem Dispositions ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_DISPOSITION_NORMAL: * @@ -306,6 +329,9 @@ G_BEGIN_DECLS */ #define DBUSMENU_MENUITEM_DISPOSITION_ALERT "alert" +/* ***************************************** */ +/* ********* Dbusmenu Events ********* */ +/* ***************************************** */ /** * DBUSMENU_MENUITEM_EVENT_ACTIVATED: * -- cgit v1.2.3 From 8fe875304b33e6c3c3028cd40e9731c1b3501ef0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 13:05:03 -0500 Subject: Adding infrastructure to watch for the disposition property. --- libdbusmenu-gtk/client.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 5e59f8e..3b26304 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -701,6 +701,20 @@ process_submenu (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant, D return; } +/* Process the disposition changing */ +static void +process_disposition (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant, DbusmenuGtkClient * gtkclient) +{ + /* We can only handle generic menu items here. Perhaps someone else + will find the value useful. Not us. */ + if (!IS_GENERICMENUITEM(gmi)) { + return; + } + + + return; +} + /* Whenever we have a property change on a DbusmenuMenuitem we need to be responsive to that. */ static void @@ -720,6 +734,8 @@ menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, Db process_toggle_state(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) { process_submenu(mi, gmi, variant, gtkclient); + } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_DISPOSITION)) { + process_disposition(mi, gmi, variant, gtkclient); } return; @@ -856,6 +872,7 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)); process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)); process_submenu(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY), client); + process_disposition(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_DISPOSITION), client); refresh_shortcut(client, item); /* Oh, we're a child, let's deal with that */ -- cgit v1.2.3 From 7a2748dfec79a0ce7ee26e0fb382a713ab8bae21 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 13:26:52 -0500 Subject: Adding an enum for the the disposition and functions to set and get it --- libdbusmenu-gtk/genericmenuitem.h | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/libdbusmenu-gtk/genericmenuitem.h b/libdbusmenu-gtk/genericmenuitem.h index 5e3c640..17759e3 100644 --- a/libdbusmenu-gtk/genericmenuitem.h +++ b/libdbusmenu-gtk/genericmenuitem.h @@ -42,11 +42,12 @@ G_BEGIN_DECLS #define IS_GENERICMENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GENERICMENUITEM_TYPE)) #define GENERICMENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GENERICMENUITEM_TYPE, GenericmenuitemClass)) -typedef struct _Genericmenuitem Genericmenuitem; -typedef struct _GenericmenuitemClass GenericmenuitemClass; -typedef struct _GenericmenuitemPrivate GenericmenuitemPrivate; -typedef enum _GenericmenuitemCheckType GenericmenuitemCheckType; -typedef enum _GenericmenuitemState GenericmenuitemState; +typedef struct _Genericmenuitem Genericmenuitem; +typedef struct _GenericmenuitemClass GenericmenuitemClass; +typedef struct _GenericmenuitemPrivate GenericmenuitemPrivate; +typedef enum _GenericmenuitemCheckType GenericmenuitemCheckType; +typedef enum _GenericmenuitemState GenericmenuitemState; +typedef enum _GenericmenuitemDisposition GenericmenuitemDisposition; /* GenericmenuitemClass: @@ -77,14 +78,24 @@ enum _GenericmenuitemState { GENERICMENUITEM_STATE_INDETERMINATE }; -GType genericmenuitem_get_type (void); -void genericmenuitem_set_check_type (Genericmenuitem * item, - GenericmenuitemCheckType check_type); -void genericmenuitem_set_state (Genericmenuitem * item, - GenericmenuitemState state); -void genericmenuitem_set_image (Genericmenuitem * item, - GtkWidget * image); -GtkWidget * genericmenuitem_get_image (Genericmenuitem * item); +enum _GenericmenuitemDisposition { + GENERICMENUITEM_DISPOSITION_NORMAL, + GENERICMENUITEM_DISPOSITION_INFORMATIONAL, + GENERICMENUITEM_DISPOSITION_WARNING, + GENERICMENUITEM_DISPOSITION_ALERT +}; + +GType genericmenuitem_get_type (void); +void genericmenuitem_set_check_type (Genericmenuitem * item, + GenericmenuitemCheckType check_type); +void genericmenuitem_set_state (Genericmenuitem * item, + GenericmenuitemState state); +void genericmenuitem_set_image (Genericmenuitem * item, + GtkWidget * image); +GtkWidget * genericmenuitem_get_image (Genericmenuitem * item); +void genericmenuitem_set_disposition (Genericmenuitem * item, + GenericmenuitemDisposition disposition); +GenericmenuitemDisposition genericmenuitem_get_disposition (Genericmenuitem * item); G_END_DECLS -- cgit v1.2.3 From 43b297e2056a9915e4c26f998c1b4631debb7455 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 14:31:31 -0500 Subject: Adding in a disposition type and get proper enum generation --- .bzrignore | 3 + libdbusmenu-gtk/Makefile.am | 22 ++++- libdbusmenu-gtk/genericmenuitem-enum-types.c.in | 116 ++++++++++++++++++++++++ libdbusmenu-gtk/genericmenuitem-enum-types.h.in | 65 +++++++++++++ libdbusmenu-gtk/genericmenuitem.h | 38 +++++--- 5 files changed, 231 insertions(+), 13 deletions(-) create mode 100644 libdbusmenu-gtk/genericmenuitem-enum-types.c.in create mode 100644 libdbusmenu-gtk/genericmenuitem-enum-types.h.in diff --git a/.bzrignore b/.bzrignore index ea8b315..0073e93 100644 --- a/.bzrignore +++ b/.bzrignore @@ -254,3 +254,6 @@ tests/test-gtk-submenu tests/test-gtk-submenu-client tests/test-gtk-submenu-server tests/test-json-01.output.json +genericmenuitem-enum-types.c +genericmenuitem-enum-types.h +libdbusmenu_gtk3_la-genericmenuitem-enum-types.lo diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 9a979d7..4b3461e 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -1,6 +1,4 @@ -CLEANFILES = - if USE_GTK3 VER=3 GTKGIR=Gtk-3.0 @@ -13,10 +11,28 @@ GTKVALA=gtk+-2.0 lib_LTLIBRARIES = libdbusmenu-gtk.la endif +BUILT_SOURCES = +CLEANFILES = +DISTCLEANFILES = EXTRA_DIST = \ dbusmenu-gtk-0.4.pc.in \ dbusmenu-gtk3-0.4.pc.in +############## +# Enum Stuff +############## + +include $(top_srcdir)/Makefile.am.enum + +glib_enum_h = genericmenuitem-enum-types.h +glib_enum_c = genericmenuitem-enum-types.c +glib_enum_headers = $(srcdir)/genericmenuitem.h + + +##################### +# Include Directory +##################### + libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ @@ -31,6 +47,8 @@ libdbusmenu_gtk_la_SOURCES = \ client.c \ genericmenuitem.h \ genericmenuitem.c \ + genericmenuitem-enum-types.h \ + genericmenuitem-enum-types.c \ menu.h \ menu.c \ menuitem.h \ diff --git a/libdbusmenu-gtk/genericmenuitem-enum-types.c.in b/libdbusmenu-gtk/genericmenuitem-enum-types.c.in new file mode 100644 index 0000000..8b2c046 --- /dev/null +++ b/libdbusmenu-gtk/genericmenuitem-enum-types.c.in @@ -0,0 +1,116 @@ +/*** BEGIN file-header ***/ +/* +Enums from the dbusmenu headers + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the + Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by + the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#include "genericmenuitem-enum-types.h" + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +#include "@basename@" +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +/** + @enum_name@_get_type: + + Builds a GLib type for the #@EnumName@ enumeration. + + Return value: A unique #GType for the #@EnumName@ enum. +*/ +GType +@enum_name@_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY(etype == 0)) { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL} + }; + + etype = g_@type@_register_static (g_intern_static_string("@EnumName@"), values); + } + + return etype; +} + +/** + @enum_name@_get_nick: + @value: The value of @EnumName@ to get the nick of + + Looks up in the enum table for the nick of @value. + + Return value: The nick for the given value or #NULL on error +*/ +const gchar * +@enum_name@_get_nick (@EnumName@ value) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(@enum_name@_get_type())); + g_return_val_if_fail(class != NULL, NULL); + + const gchar * ret = NULL; + GEnumValue * val = g_enum_get_value(class, value); + if (val != NULL) { + ret = val->value_nick; + } + + g_type_class_unref(class); + return ret; +} + +/** + @enum_name@_get_value_from_nick: + @nick: The enum nick to lookup + + Looks up in the enum table for the value of @nick. + + Return value: The value for the given @nick +*/ +@EnumName@ +@enum_name@_get_value_from_nick (const gchar * nick) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(@enum_name@_get_type())); + g_return_val_if_fail(class != NULL, 0); + + @EnumName@ ret = 0; + GEnumValue * val = g_enum_get_value_by_nick(class, nick); + if (val != NULL) { + ret = val->value; + } + + g_type_class_unref(class); + return ret; +} + + +/*** END value-tail ***/ diff --git a/libdbusmenu-gtk/genericmenuitem-enum-types.h.in b/libdbusmenu-gtk/genericmenuitem-enum-types.h.in new file mode 100644 index 0000000..5758438 --- /dev/null +++ b/libdbusmenu-gtk/genericmenuitem-enum-types.h.in @@ -0,0 +1,65 @@ +/*** BEGIN file-header ***/ +/* +Enums from the dbusmenu headers + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the + Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by + the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef __DBUSMENU_ENUM_TYPES_H__ +#define __DBUSMENU_ENUM_TYPES_H__ + +#include + +G_BEGIN_DECLS + +/*** END file-header ***/ + +/*** BEGIN file-tail ***/ + +G_END_DECLS + +#endif /* __DBUSMENU_ENUM_TYPES_H__ */ +/*** END file-tail ***/ + +/*** BEGIN file-production ***/ +/* Enumerations from file: "@filename@" */ +#include "@basename@" + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ + +GType @enum_name@_get_type (void) G_GNUC_CONST; +const gchar * @enum_name@_get_nick (@EnumName@ value) G_GNUC_CONST; +@EnumName@ @enum_name@_get_value_from_nick (const gchar * nick) G_GNUC_CONST; + +/** + DBUSMENU_TYPE_@ENUMSHORT@: + + Gets the #GType value for the type associated with the + #@EnumName@ enumerated type. +*/ +#define DBUSMENU_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) + +/*** END value-header ***/ diff --git a/libdbusmenu-gtk/genericmenuitem.h b/libdbusmenu-gtk/genericmenuitem.h index 17759e3..74db2ae 100644 --- a/libdbusmenu-gtk/genericmenuitem.h +++ b/libdbusmenu-gtk/genericmenuitem.h @@ -45,9 +45,6 @@ G_BEGIN_DECLS typedef struct _Genericmenuitem Genericmenuitem; typedef struct _GenericmenuitemClass GenericmenuitemClass; typedef struct _GenericmenuitemPrivate GenericmenuitemPrivate; -typedef enum _GenericmenuitemCheckType GenericmenuitemCheckType; -typedef enum _GenericmenuitemState GenericmenuitemState; -typedef enum _GenericmenuitemDisposition GenericmenuitemDisposition; /* GenericmenuitemClass: @@ -66,24 +63,43 @@ struct _Genericmenuitem { GenericmenuitemPrivate * priv; }; -enum _GenericmenuitemCheckType { +/** + * GenericmenuitemCheckType: + * @GENERICMENUITEM_CHECK_TYPE_NONE: No check + * @GENERICMENUITEM_CHECK_TYPE_CHECKBOX: Nice little check + * @GENERICMENUITEM_CHECK_TYPE_RADIO: Radio button + */ +typedef enum { /*< prefix=GENERICMENUITEM_CHECK_TYPE >*/ GENERICMENUITEM_CHECK_TYPE_NONE, GENERICMENUITEM_CHECK_TYPE_CHECKBOX, GENERICMENUITEM_CHECK_TYPE_RADIO -}; - -enum _GenericmenuitemState { +} GenericmenuitemCheckType; + +/** + * GenericmenuitemState: + * @GENERICMENUITEM_STATE_UNCHECKED: No check visisble + * @GENERICMENUITEM_STATE_CHECKED: Check visible + * @GENERICMENUITEM_STATE_INDETERMINATE: We have no clue + */ +typedef enum { /*< prefix=GENERICMENUITEM_STATE >*/ GENERICMENUITEM_STATE_UNCHECKED, GENERICMENUITEM_STATE_CHECKED, GENERICMENUITEM_STATE_INDETERMINATE -}; - -enum _GenericmenuitemDisposition { +} GenericmenuitemState; + +/** + * GenericmenuitemDisposition: + * @GENERICMENUITEM_DISPOSITION_NORMAL: Normal state + * @GENERICMENUITEM_DISPOSITION_INFORMATIONAL: Item is informational + * @GENERICMENUITEM_DISPOSITION_WARNING: Oh, you should watch out for this one + * @GENERICMENUITEM_DISPOSITION_ALERT: Boom! + */ +typedef enum { /*< prefix=GENERICMENUITEM_DISPOSITION >*/ GENERICMENUITEM_DISPOSITION_NORMAL, GENERICMENUITEM_DISPOSITION_INFORMATIONAL, GENERICMENUITEM_DISPOSITION_WARNING, GENERICMENUITEM_DISPOSITION_ALERT -}; +} GenericmenuitemDisposition; GType genericmenuitem_get_type (void); void genericmenuitem_set_check_type (Genericmenuitem * item, -- cgit v1.2.3 From ad97e244ced1ced06977af114823ce5705d75948 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 14:49:45 -0500 Subject: Make sure that we get rid of the enum stuff as well --- libdbusmenu-gtk/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 4b3461e..4ec464b 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -107,7 +107,7 @@ INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_buildd if HAVE_INTROSPECTION -introspection_sources = $(filter-out genericmenuitem.%, $(libdbusmenu_gtkinclude_HEADERS) $(libdbusmenu_gtk_la_SOURCES)) +introspection_sources = $(filter-out genericmenuitem%, $(libdbusmenu_gtkinclude_HEADERS) $(libdbusmenu_gtk_la_SOURCES)) DbusmenuGtk$(VER)-0.4.gir: libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_INCLUDES = \ -- cgit v1.2.3 From ffac09f199ebffe13b1032eaf03e3d6f00a9da78 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 14:54:42 -0500 Subject: Set the disposition from the value given and from the enum. --- libdbusmenu-gtk/client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 3b26304..1051f20 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -31,10 +31,12 @@ License version 3 and version 2.1 along with this program. If not, see #endif #include +#include #include "client.h" #include "menuitem.h" #include "genericmenuitem.h" +#include "genericmenuitem-enum-types.h" /* Private */ struct _DbusmenuGtkClientPrivate { @@ -711,7 +713,7 @@ process_disposition (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * varian return; } - + genericmenuitem_set_disposition(GENERICMENUITEM(gmi), genericmenuitem_disposition_get_value_from_nick(g_variant_get_string(variant, NULL))); return; } -- cgit v1.2.3 From f545dc8264a5b1986673c583c59f87a97b866833 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 14:58:27 -0500 Subject: Add in a disposition and set it at init --- libdbusmenu-gtk/genericmenuitem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 3652ceb..f939332 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -40,6 +40,7 @@ License version 3 and version 2.1 along with this program. If not, see struct _GenericmenuitemPrivate { GenericmenuitemCheckType check_type; GenericmenuitemState state; + GenericmenuitemDisposition disposition; }; /* Private macro */ @@ -102,6 +103,7 @@ genericmenuitem_init (Genericmenuitem *self) self->priv->check_type = GENERICMENUITEM_CHECK_TYPE_NONE; self->priv->state = GENERICMENUITEM_STATE_UNCHECKED; + self->priv->disposition = GENERICMENUITEM_DISPOSITION_NORMAL; return; } -- cgit v1.2.3 From 85b3b5d2a138697f7252f0f00666bd06fa7f628b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 15:11:33 -0500 Subject: Implement the setter and getter for disposition --- libdbusmenu-gtk/genericmenuitem.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index f939332..43def6d 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -468,3 +468,41 @@ genericmenuitem_get_image (Genericmenuitem * menu_item) return imagew; } + +/** + * genericmenuitem_set_disposition: + * @item: A #Genericmenuitem + * @disposition: The disposition of the item + * + * Sets the disposition of the menuitem. + */ +void +genericmenuitem_set_disposition (Genericmenuitem * item, GenericmenuitemDisposition disposition) +{ + g_return_if_fail(IS_GENERICMENUITEM(item)); + + if (item->priv->disposition == disposition) + return; + + item->priv->disposition = disposition; + + set_label(GTK_MENU_ITEM(item), get_label(GTK_MENU_ITEM(item))); + + return; +} + +/** + * genericmenuitem_get_disposition: + * @item: A #Genericmenuitem + * + * Gets the disposition of the menuitem. + * + * Return value: The disposition of the menuitem. + */ +GenericmenuitemDisposition +genericmenuitem_get_disposition (Genericmenuitem * item) +{ + g_return_val_if_fail(IS_GENERICMENUITEM(item), GENERICMENUITEM_DISPOSITION_NORMAL); + + return item->priv->disposition; +} -- cgit v1.2.3 From 5119e754260bc615509f625195aff42f92ed4a1f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 16:02:47 -0500 Subject: Create a local string with a color if the disposition is non-normal --- libdbusmenu-gtk/genericmenuitem.c | 53 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 43def6d..e474446 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -30,6 +30,8 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif +#include + #include "genericmenuitem.h" /* @@ -174,12 +176,52 @@ get_hpadding (GtkWidget * widget) return padding; } +/* Get the value to put in the span for the disposition */ +static gchar * +get_text_color (GenericmenuitemDisposition disposition, GtkStyleContext * context) +{ + struct {const gchar * color_name; const gchar * default_color;} values[] = { + /* NORMAL */ { NULL, NULL}, + /* INFO */ { "informational_color", "blue"}, + /* WARN */ { "warning_color", "orange"}, + /* ALERT */ { "error_color", "red"} + }; + + GdkRGBA color; + + if (gtk_style_context_lookup_color(context, values[disposition].color_name, &color)) { + return g_strdup_printf("rgb(%d, %d, %d)", (gint)(color.red * 255), (gint)(color.green * 255), (gint)(color.blue * 255)); + } + + return g_strdup(values[disposition].default_color); +} + /* Set the label on the item */ static void set_label (GtkMenuItem * menu_item, const gchar * label) { if (label == NULL) return; + /* Build a label that might include the colors of the disposition + so that it gets rendered in the menuitem. */ + gchar * local_label = NULL; + switch (GENERICMENUITEM(menu_item)->priv->disposition) { + case GENERICMENUITEM_DISPOSITION_NORMAL: + local_label = g_strdup(label); + break; + case GENERICMENUITEM_DISPOSITION_INFORMATIONAL: + case GENERICMENUITEM_DISPOSITION_WARNING: + case GENERICMENUITEM_DISPOSITION_ALERT: { + gchar * color = get_text_color(GENERICMENUITEM(menu_item)->priv->disposition, gtk_widget_get_style_context(GTK_WIDGET(menu_item))); + local_label = g_markup_printf_escaped("%s", color, label); + g_free(color); + break; + } + default: + g_warn_if_reached(); + break; + } + GtkWidget * child = gtk_bin_get_child(GTK_BIN(menu_item)); GtkLabel * labelw = NULL; gboolean suppress_update = FALSE; @@ -213,8 +255,9 @@ set_label (GtkMenuItem * menu_item, const gchar * label) update the one that we already have. */ if (labelw == NULL) { /* Build it */ - labelw = GTK_LABEL(gtk_accel_label_new(label)); + labelw = GTK_LABEL(gtk_accel_label_new(local_label)); gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE); + gtk_label_set_use_markup(GTK_LABEL(labelw), TRUE); gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5); gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item)); gtk_widget_show(GTK_WIDGET(labelw)); @@ -234,7 +277,7 @@ set_label (GtkMenuItem * menu_item, const gchar * label) getting in. */ suppress_update = TRUE; } else { - gtk_label_set_label(labelw, label); + gtk_label_set_markup_with_mnemonic(labelw, local_label); } } @@ -243,6 +286,12 @@ set_label (GtkMenuItem * menu_item, const gchar * label) g_object_notify(G_OBJECT(menu_item), "label"); } + /* Clean up this */ + if (local_label != NULL) { + g_free(local_label); + local_label = NULL; + } + return; } -- cgit v1.2.3 From abe4a9be07841b4eb735e32b47e86d67b16fddef Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 16:14:36 -0500 Subject: Adding disposition tests --- tests/test-gtk-label.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test-gtk-label.json b/tests/test-gtk-label.json index 0189fbe..e1abff1 100644 --- a/tests/test-gtk-label.json +++ b/tests/test-gtk-label.json @@ -367,5 +367,26 @@ QmCC", "toggle-state": -1 } ] + }, + {"id": 1, "type": "standard", + "label": "value1", + "submenu": [ + {"id": 60, + "label": "Disposition Normal", + "disposition": "normal" + }, + {"id": 61, + "label": "Disposition Info", + "disposition": "informational" + }, + {"id": 62, + "label": "Disposition Warning", + "disposition": "warning" + }, + {"id": 63, + "label": "Disposition Alert", + "disposition": "alert" + } + ] } ] -- cgit v1.2.3 From c9245e5be5eba930ebb83b6dc1ac3f0ba30ca4a6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 16:17:37 -0500 Subject: Adding in a mnemonic test --- tests/test-gtk-label.json | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test-gtk-label.json b/tests/test-gtk-label.json index e1abff1..86d18e8 100644 --- a/tests/test-gtk-label.json +++ b/tests/test-gtk-label.json @@ -388,5 +388,37 @@ QmCC", "disposition": "alert" } ] + }, + {"id": 1, "type": "standard", + "label": "value1", + "submenu": [ + {"id": 70, + "label": "_Mnemonic" + }, + {"id": 71, + "label": "M_nemonic" + }, + {"id": 72, + "label": "Mn_emonic" + }, + {"id": 73, + "label": "Mne_monic" + }, + {"id": 74, + "label": "Mnem_onic" + }, + {"id": 75, + "label": "Mnemo_nic" + }, + {"id": 76, + "label": "Mnemon_ic" + }, + {"id": 77, + "label": "Mnemoni_c" + }, + {"id": 78, + "label": "__Underline__" + } + ] } ] -- cgit v1.2.3 From 007c157b059f3b3619d7a6c4aa3ff79f5b46f539 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 22 Aug 2011 21:43:13 -0500 Subject: Fixing the comparision so that we don't block updates --- libdbusmenu-gtk/genericmenuitem.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index e474446..b1d7a29 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -198,22 +198,22 @@ get_text_color (GenericmenuitemDisposition disposition, GtkStyleContext * contex /* Set the label on the item */ static void -set_label (GtkMenuItem * menu_item, const gchar * label) +set_label (GtkMenuItem * menu_item, const gchar * in_label) { - if (label == NULL) return; + if (in_label == NULL) return; /* Build a label that might include the colors of the disposition so that it gets rendered in the menuitem. */ gchar * local_label = NULL; switch (GENERICMENUITEM(menu_item)->priv->disposition) { case GENERICMENUITEM_DISPOSITION_NORMAL: - local_label = g_strdup(label); + local_label = g_strdup(in_label); break; case GENERICMENUITEM_DISPOSITION_INFORMATIONAL: case GENERICMENUITEM_DISPOSITION_WARNING: case GENERICMENUITEM_DISPOSITION_ALERT: { gchar * color = get_text_color(GENERICMENUITEM(menu_item)->priv->disposition, gtk_widget_get_style_context(GTK_WIDGET(menu_item))); - local_label = g_markup_printf_escaped("%s", color, label); + local_label = g_markup_printf_escaped("%s", color, in_label); g_free(color); break; } @@ -260,6 +260,7 @@ set_label (GtkMenuItem * menu_item, const gchar * label) gtk_label_set_use_markup(GTK_LABEL(labelw), TRUE); gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5); gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item)); + gtk_label_set_markup_with_mnemonic(labelw, local_label); gtk_widget_show(GTK_WIDGET(labelw)); /* Check to see if it needs to be in the bin for this @@ -271,7 +272,7 @@ set_label (GtkMenuItem * menu_item, const gchar * label) } } else { /* Oh, just an update. No biggie. */ - if (!g_strcmp0(label, gtk_label_get_label(labelw))) { + if (!g_strcmp0(local_label, gtk_label_get_label(labelw))) { /* The only reason to suppress the update is if we had a label and the value was the same as the one we're getting in. */ -- cgit v1.2.3 From 6735be264a1faf2d589e0a1523b6476face95c91 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 23 Aug 2011 09:47:18 -0500 Subject: Fixing the color names --- libdbusmenu-gtk/genericmenuitem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index b1d7a29..1d2f958 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -182,9 +182,9 @@ get_text_color (GenericmenuitemDisposition disposition, GtkStyleContext * contex { struct {const gchar * color_name; const gchar * default_color;} values[] = { /* NORMAL */ { NULL, NULL}, - /* INFO */ { "informational_color", "blue"}, - /* WARN */ { "warning_color", "orange"}, - /* ALERT */ { "error_color", "red"} + /* INFO */ { "informational-color", "blue"}, + /* WARN */ { "warning-color", "orange"}, + /* ALERT */ { "error-color", "red"} }; GdkRGBA color; -- cgit v1.2.3