aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore3
-rw-r--r--Makefile.am6
-rw-r--r--configure.ac30
-rw-r--r--docs/Makefile.am8
-rw-r--r--docs/libdbusmenu-glib/reference/libdbusmenu-glib-sections.txt5
-rw-r--r--docs/libdbusmenu-gtk/reference/Makefile.am2
-rw-r--r--libdbusmenu-glib/dbus-menu.xml13
-rw-r--r--libdbusmenu-glib/defaults.c1
-rw-r--r--libdbusmenu-glib/menuitem.h67
-rw-r--r--libdbusmenu-glib/server.c4
-rw-r--r--libdbusmenu-gtk/Makefile.am24
-rw-r--r--libdbusmenu-gtk/client.c19
-rw-r--r--libdbusmenu-gtk/genericmenuitem-enum-types.c.in116
-rw-r--r--libdbusmenu-gtk/genericmenuitem-enum-types.h.in65
-rw-r--r--libdbusmenu-gtk/genericmenuitem.c119
-rw-r--r--libdbusmenu-gtk/genericmenuitem.h71
-rw-r--r--tests/test-gtk-label.json53
-rw-r--r--tools/testapp/Makefile.am6
18 files changed, 562 insertions, 50 deletions
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/Makefile.am b/Makefile.am
index 2fb4c84..a69c377 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,6 +3,10 @@ EXTRA_DIST = \
COPYING-GPL3 \
m4/introspection.m4
+if WANT_TESTS
+TESTS_SUBDIR = tests
+endif
+
if WANT_LIBDBUSMENUGTK
LIBDBUSMENUGTK_SUBDIR = libdbusmenu-gtk
endif
@@ -11,7 +15,7 @@ SUBDIRS = \
libdbusmenu-glib \
$(LIBDBUSMENUGTK_SUBDIR) \
tools \
- tests \
+ $(TESTS_SUBDIR) \
docs \
po
diff --git a/configure.ac b/configure.ac
index 47ea915..895f9f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,11 +1,11 @@
-AC_INIT(libdbusmenu, 0.4.90, ted@canonical.com)
+AC_INIT(libdbusmenu, 0.4.93, ted@canonical.com)
AC_COPYRIGHT([Copyright 2009,2010 Canonical])
AC_PREREQ(2.62)
AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(libdbusmenu, 0.4.90, [-Wno-portability])
+AM_INIT_AUTOMAKE(libdbusmenu, 0.4.93, [-Wno-portability])
AM_MAINTAINER_MODE
@@ -65,7 +65,7 @@ AM_CONDITIONAL([WANT_LIBDBUSMENUGTK], [test "x$enable_gtk" != "xno"])
AC_ARG_WITH([gtk],
[AS_HELP_STRING([--with-gtk],
- [Which version of gtk to use @<:@default=2@:>@])],
+ [Which version of gtk to use @<:@default=3@:>@])],
[],
[with_gtk=3])
AM_CONDITIONAL([USE_GTK3], [test "x$with_gtk" = "x3"])
@@ -109,8 +109,17 @@ AC_SUBST(DBUSMENUDUMPER_LIBS)
JSON_GLIB_REQUIRED_VERSION=0.13.4
GIO_UNIX_REQUIRED_VERSION=2.24
+AC_ARG_ENABLE([tests],
+ AC_HELP_STRING([--disable-tests], [Disable tests]),
+ [enable_tests=$enableval], [enable_tests=auto])
+AM_CONDITIONAL([WANT_TESTS], [test "x$enable_tests" != "xno"])
+
+AS_IF([test "x$enable_tests" != "xno"],[
PKG_CHECK_MODULES(DBUSMENUTESTS, json-glib-1.0 >= $JSON_GLIB_REQUIRED_VERSION
- gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION)
+ gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION,
+ [have_tests=yes]
+)
+])
AC_SUBST(DBUSMENUTESTS_CFLAGS)
AC_SUBST(DBUSMENUTESTS_LIBS)
@@ -144,7 +153,7 @@ AC_PATH_PROG([XSLT_PROC], [xsltproc])
###########################
LIBDBUSMENU_CURRENT=4
-LIBDBUSMENU_REVISION=0
+LIBDBUSMENU_REVISION=3
LIBDBUSMENU_AGE=0
AC_SUBST(LIBDBUSMENU_CURRENT)
@@ -209,8 +218,13 @@ libdbusmenu Configuration:
GTK+ Version: $with_gtk
])
-AS_IF([test "x$enable_gtk" = "xyes"],
- AC_MSG_NOTICE([ Gtk: yes (gtk$with_gtk)]),
- AC_MSG_NOTICE([ Gtk: no])
+AS_IF([test "x$have_tests" = "xyes"],
+ AC_MSG_NOTICE([ Tests: yes]),
+ AC_MSG_NOTICE([ Tests: no])
+)
+
+AS_IF([test "x$enable_gtk" = "xno"],
+ AC_MSG_NOTICE([ Gtk: no]),
+ AC_MSG_NOTICE([ Gtk: yes (gtk$with_gtk)])
)
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 87ffe5f..23a4c86 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -1 +1,7 @@
-SUBDIRS = libdbusmenu-glib libdbusmenu-gtk
+if WANT_LIBDBUSMENUGTK
+LIBDBUSMENUGTK_SUBDIR = libdbusmenu-gtk
+endif
+
+SUBDIRS = \
+ libdbusmenu-glib \
+ $(LIBDBUSMENUGTK_SUBDIR)
diff --git a/docs/libdbusmenu-glib/reference/libdbusmenu-glib-sections.txt b/docs/libdbusmenu-glib/reference/libdbusmenu-glib-sections.txt
index 4d1e50a..d95ec4c 100644
--- a/docs/libdbusmenu-glib/reference/libdbusmenu-glib-sections.txt
+++ b/docs/libdbusmenu-glib/reference/libdbusmenu-glib-sections.txt
@@ -59,6 +59,7 @@ DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE
DBUSMENU_MENUITEM_PROP_TOGGLE_STATE
DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY
DBUSMENU_MENUITEM_PROP_SHORTCUT
+DBUSMENU_MENUITEM_PROP_DISPOSITION
DBUSMENU_MENUITEM_TOGGLE_CHECK
DBUSMENU_MENUITEM_TOGGLE_RADIO
DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
@@ -70,6 +71,10 @@ DBUSMENU_MENUITEM_SHORTCUT_ALT
DBUSMENU_MENUITEM_SHORTCUT_CONTROL
DBUSMENU_MENUITEM_SHORTCUT_SHIFT
DBUSMENU_MENUITEM_SHORTCUT_SUPER
+DBUSMENU_MENUITEM_DISPOSITION_NORMAL
+DBUSMENU_MENUITEM_DISPOSITION_INFORMATIVE
+DBUSMENU_MENUITEM_DISPOSITION_WARNING
+DBUSMENU_MENUITEM_DISPOSITION_ALERT
DBUSMENU_MENUITEM_EVENT_ACTIVATED
DBUSMENU_MENUITEM_EVENT_CLOSED
DBUSMENU_MENUITEM_EVENT_OPENED
diff --git a/docs/libdbusmenu-gtk/reference/Makefile.am b/docs/libdbusmenu-gtk/reference/Makefile.am
index 06d0009..62f80ba 100644
--- a/docs/libdbusmenu-gtk/reference/Makefile.am
+++ b/docs/libdbusmenu-gtk/reference/Makefile.am
@@ -54,7 +54,7 @@ CFILE_GLOB=$(top_srcdir)/libdbusmenu-gtk/*.c
# Header files to ignore when scanning.
# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h
-IGNORE_HFILES=genericmenuitem.h
+IGNORE_HFILES=genericmenuitem.h genericmenuitem-enum-types.h
# Images to copy into HTML directory.
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
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
</td>
<td>""</td>
</tr>
+ <tr>
+ <td>disposition</td>
+ <td>string</td>
+ <td>
+ 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
+ </td>
+ <td>"normal"</td>
+ </tr>
</table>
Vendor specific properties can be added by prefixing them with
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..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:
*
@@ -184,7 +189,17 @@ 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"
+/* ***************************************** */
+/* ********* Toggle Values ********* */
+/* ***************************************** */
/**
* DBUSMENU_MENUITEM_TOGGLE_CHECK:
*
@@ -200,6 +215,9 @@ G_BEGIN_DECLS
*/
#define DBUSMENU_MENUITEM_TOGGLE_RADIO "radio"
+/* ***************************************** */
+/* ********* Toggle States ********* */
+/* ***************************************** */
/**
* DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED:
*
@@ -222,6 +240,9 @@ G_BEGIN_DECLS
*/
#define DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN -1
+/* ***************************************** */
+/* ********* Icon specials ********* */
+/* ***************************************** */
/**
* DBUSMENU_MENUITEM_ICON_NAME_BLANK:
*
@@ -230,6 +251,9 @@ G_BEGIN_DECLS
*/
#define DBUSMENU_MENUITEM_ICON_NAME_BLANK "blank-icon"
+/* ***************************************** */
+/* ********* Shortcut Modifiers ********* */
+/* ***************************************** */
/**
* DBUSMENU_MENUITEM_SHORTCUT_CONTROL:
*
@@ -259,6 +283,9 @@ G_BEGIN_DECLS
*/
#define DBUSMENU_MENUITEM_SHORTCUT_SUPER "Super"
+/* ***************************************** */
+/* ********* Child Display Types ********* */
+/* ***************************************** */
/**
* DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU:
*
@@ -267,6 +294,44 @@ G_BEGIN_DECLS
*/
#define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU "submenu"
+/* ***************************************** */
+/* ********* Menuitem Dispositions ********* */
+/* ***************************************** */
+/**
+ * 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_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_INFORMATIVE "informative"
+/**
+ * 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 Events ********* */
+/* ***************************************** */
/**
* DBUSMENU_MENUITEM_EVENT_ACTIVATED:
*
diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c
index f81b3ed..c7057df 100644
--- a/libdbusmenu-glib/server.c
+++ b/libdbusmenu-glib/server.c
@@ -976,10 +976,10 @@ menuitem_property_idle (gpointer user_data)
gotsomething = TRUE;
} else {
GError * error = NULL;
- megadata[1] = g_variant_parse(G_VARIANT_TYPE("a(ia(s))"), "[ ]", NULL, NULL, &error);
+ megadata[1] = g_variant_parse(G_VARIANT_TYPE("a(ias)"), "[ ]", NULL, NULL, &error);
if (error != NULL) {
- g_warning("Unable to parse '[ ]' as a 'a(ia(s))': %s", error->message);
+ g_warning("Unable to parse '[ ]' as a 'a(ias)': %s", error->message);
g_error_free(error);
}
}
diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am
index 9a979d7..4ec464b 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 \
@@ -89,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 = \
diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c
index 5e59f8e..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 <gtk/gtk.h>
+#include <glib.h>
#include "client.h"
#include "menuitem.h"
#include "genericmenuitem.h"
+#include "genericmenuitem-enum-types.h"
/* Private */
struct _DbusmenuGtkClientPrivate {
@@ -701,6 +703,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;
+ }
+
+ genericmenuitem_set_disposition(GENERICMENUITEM(gmi), genericmenuitem_disposition_get_value_from_nick(g_variant_get_string(variant, NULL)));
+ return;
+}
+
/* Whenever we have a property change on a DbusmenuMenuitem
we need to be responsive to that. */
static void
@@ -720,6 +736,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 +874,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 */
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 <ted@canonical.com>
+
+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
+<http://www.gnu.org/licenses/>
+*/
+
+#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 <ted@canonical.com>
+
+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
+<http://www.gnu.org/licenses/>
+*/
+
+#ifndef __DBUSMENU_ENUM_TYPES_H__
+#define __DBUSMENU_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+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.c b/libdbusmenu-gtk/genericmenuitem.c
index 3652ceb..5488f93 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 <gdk/gdk.h>
+
#include "genericmenuitem.h"
/*
@@ -40,6 +42,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 +105,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;
}
@@ -165,18 +169,61 @@ set_label_helper (GtkWidget * widget, gpointer data)
style. It should be considered for caching when
optimizing. */
static gint
-get_hpadding (GtkWidget * widget)
+get_toggle_space (GtkWidget * widget)
{
gint padding = 0;
- gtk_widget_style_get(widget, "horizontal-padding", &padding, NULL);
+ gtk_widget_style_get(widget, "toggle-spacing", &padding, NULL);
return padding;
}
+/* Get the value to put in the span for the disposition */
+static gchar *
+get_text_color (GenericmenuitemDisposition disposition, GtkWidget * widget)
+{
+ 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"}
+ };
+
+#if GTK_CHECK_VERSION(3, 0, 0)
+ GtkStyleContext * context = gtk_widget_get_style_context(widget);
+ 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));
+ }
+#endif
+
+ return g_strdup(values[disposition].default_color);
+}
+
/* 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(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(menu_item));
+ local_label = g_markup_printf_escaped("<span fgcolor=\"%s\">%s</span>", color, in_label);
+ g_free(color);
+ break;
+ }
+ default:
+ g_warn_if_reached();
+ break;
+ }
GtkWidget * child = gtk_bin_get_child(GTK_BIN(menu_item));
GtkLabel * labelw = NULL;
@@ -194,10 +241,10 @@ set_label (GtkMenuItem * menu_item, const gchar * label)
/* We need to put the child into a new box and
make the box the child of the menu item. Basically
we're inserting a box in the middle. */
- GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
+ GtkWidget * hbox = gtk_hbox_new(FALSE, get_toggle_space(GTK_WIDGET(menu_item)));
g_object_ref(child);
gtk_container_remove(GTK_CONTAINER(menu_item), child);
- gtk_box_pack_start(GTK_BOX(hbox), child, FALSE, FALSE, get_hpadding(GTK_WIDGET(menu_item)));
+ gtk_box_pack_start(GTK_BOX(hbox), child, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(menu_item), hbox);
gtk_widget_show(hbox);
g_object_unref(child);
@@ -211,10 +258,12 @@ 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_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
@@ -222,17 +271,17 @@ set_label (GtkMenuItem * menu_item, const gchar * label)
if (child == NULL) {
gtk_container_add(GTK_CONTAINER(menu_item), GTK_WIDGET(labelw));
} else {
- gtk_box_pack_end(GTK_BOX(child), GTK_WIDGET(labelw), TRUE, TRUE, get_hpadding(GTK_WIDGET(menu_item)));
+ gtk_box_pack_end(GTK_BOX(child), GTK_WIDGET(labelw), TRUE, TRUE, 0);
}
} 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. */
suppress_update = TRUE;
} else {
- gtk_label_set_label(labelw, label);
+ gtk_label_set_markup_with_mnemonic(labelw, local_label);
}
}
@@ -241,6 +290,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;
}
@@ -401,10 +456,10 @@ genericmenuitem_set_image (Genericmenuitem * menu_item, GtkWidget * image)
/* We need to put the child into a new box and
make the box the child of the menu item. Basically
we're inserting a box in the middle. */
- GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
+ GtkWidget * hbox = gtk_hbox_new(FALSE, get_toggle_space(GTK_WIDGET(menu_item)));
g_object_ref(child);
gtk_container_remove(GTK_CONTAINER(menu_item), child);
- gtk_box_pack_end(GTK_BOX(hbox), child, TRUE, TRUE, get_hpadding(GTK_WIDGET(menu_item)));
+ gtk_box_pack_end(GTK_BOX(hbox), child, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(menu_item), hbox);
gtk_widget_show(hbox);
g_object_unref(child);
@@ -429,7 +484,7 @@ genericmenuitem_set_image (Genericmenuitem * menu_item, GtkWidget * image)
if (child == NULL) {
gtk_container_add(GTK_CONTAINER(menu_item), GTK_WIDGET(image));
} else {
- gtk_box_pack_start(GTK_BOX(child), GTK_WIDGET(image), FALSE, FALSE, get_hpadding(GTK_WIDGET(menu_item)));
+ gtk_box_pack_start(GTK_BOX(child), GTK_WIDGET(image), FALSE, FALSE, 0);
}
gtk_widget_show(image);
@@ -466,3 +521,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;
+}
diff --git a/libdbusmenu-gtk/genericmenuitem.h b/libdbusmenu-gtk/genericmenuitem.h
index 5e3c640..0b7df55 100644
--- a/libdbusmenu-gtk/genericmenuitem.h
+++ b/libdbusmenu-gtk/genericmenuitem.h
@@ -42,11 +42,9 @@ 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;
/*
GenericmenuitemClass:
@@ -65,26 +63,61 @@ 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
+ *
+ * Tracks what type of checkmark should be shown on the item
+ */
+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
+ *
+ * What the state of the check mark on the item is
+ */
+typedef enum { /*< prefix=GENERICMENUITEM_STATE >*/
GENERICMENUITEM_STATE_UNCHECKED,
GENERICMENUITEM_STATE_CHECKED,
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);
+} 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!
+ *
+ * What the disposition of the menu item is
+ */
+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,
+ 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
diff --git a/tests/test-gtk-label.json b/tests/test-gtk-label.json
index 0189fbe..86d18e8 100644
--- a/tests/test-gtk-label.json
+++ b/tests/test-gtk-label.json
@@ -367,5 +367,58 @@ 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"
+ }
+ ]
+ },
+ {"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__"
+ }
+ ]
}
]
diff --git a/tools/testapp/Makefile.am b/tools/testapp/Makefile.am
index 39de532..ee12ec9 100644
--- a/tools/testapp/Makefile.am
+++ b/tools/testapp/Makefile.am
@@ -5,7 +5,11 @@ else
VER=
endif
-libexec_PROGRAMS = dbusmenu-testapp
+libexec_PROGRAMS =
+
+if WANT_TESTS
+libexec_PROGRAMS += dbusmenu-testapp
+endif
dbusmenu_testapp_SOURCES = \
main.c