ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #01595
[Merge] lp:~dbarth/dbusmenu/convenience-functions into lp:dbusmenu
David Barth has proposed merging lp:~dbarth/dbusmenu/convenience-functions into lp:dbusmenu.
Requested reviews:
DBus Menu Team (dbusmenu-team)
Proposing to add 2 functions to encode the defaults for the 'visible' and 'enabled' properties correctly. After fixing the issue in indicator-appmenu, it seems important to help application developers make sure they conform to the specification and get properties defaults correctly.
Also, while I'm at it, helping add a separator to a menu in one line, to save 5-6 lines of boilerplate code.
--
https://code.launchpad.net/~dbarth/dbusmenu/convenience-functions/+merge/27622
Your team ayatana-commits is subscribed to branch lp:dbusmenu.
=== modified file 'libdbusmenu-glib/menuitem.c'
--- libdbusmenu-glib/menuitem.c 2010-06-08 04:00:17 +0000
+++ libdbusmenu-glib/menuitem.c 2010-06-15 13:09:25 +0000
@@ -33,6 +33,7 @@
#include "menuitem.h"
#include "menuitem-marshal.h"
#include "menuitem-private.h"
+#include "client.h" /* for the DBUSMENU_CLIENT_TYPES_SEPARATOR definition */
#ifdef MASSIVEDEBUGGING
#define LABEL(x) dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(x), DBUSMENU_MENUITEM_PROP_LABEL)
@@ -1349,3 +1350,65 @@
return;
}
+
+/* Convenience functions */
+/**
+ dbusmenu_menuitem_is_visible:
+ @mi: The #DbusmenuMenuitem to look for the property on.
+
+ Look up the well-known 'visible' property on @mi and
+ return whether the item is considered visible or not.
+
+ Return TRUE if the property doesn't exist.
+
+ Return value: The value of the 'visible' property or TRUE.
+*/
+gboolean dbusmenu_menuitem_is_visible (DbusmenuMenuitem * mi)
+{
+ if (dbusmenu_menuitem_property_get_value (mi, DBUSMENU_MENUITEM_PROP_VISIBLE) != NULL)
+ return dbusmenu_menuitem_property_get_bool (mi, DBUSMENU_MENUITEM_PROP_VISIBLE);
+ else
+ return TRUE; /* visible by default */
+}
+
+/**
+ dbusmenu_menuitem_is_enabled:
+ @mi: The #DbusmenuMenuitem to look for the property on.
+
+ Look up the well-known 'enabled' property on @mi and
+ return whether the item is considered enabled or not.
+
+ Return TRUE if the property doesn't exist.
+
+ Return value: The value of the 'enabled' property or TRUE.
+*/
+gboolean dbusmenu_menuitem_is_enabled (DbusmenuMenuitem * mi)
+{
+ if (dbusmenu_menuitem_property_get_value (mi, DBUSMENU_MENUITEM_PROP_ENABLED) != NULL)
+ return dbusmenu_menuitem_property_get_bool (mi, DBUSMENU_MENUITEM_PROP_ENABLED);
+ else
+ return TRUE; /* enabled by default */
+}
+
+/**
+ dbusmenu_menuitem_child_append_separator:
+ @mi: The #DbusmenuMenuitem which will become a new parent
+
+ This is a convenience function that creates a separator
+ item and adds it to the list of children on @mi at the end
+ of that list.
+
+ Return value: the separator #DbusmenuMenuitem
+*/
+DbusmenuMenuitem * dbusmenu_menuitem_child_append_separator (DbusmenuMenuitem *mi)
+{
+ DbusmenuMenuitem *separator = dbusmenu_menuitem_new ();
+
+ if (separator != NULL) {
+ dbusmenu_menuitem_property_set (separator, DBUSMENU_MENUITEM_PROP_TYPE,
+ DBUSMENU_CLIENT_TYPES_SEPARATOR);
+ dbusmenu_menuitem_child_append (mi, separator);
+ }
+
+ return separator;
+}
=== modified file 'libdbusmenu-glib/menuitem.h'
--- libdbusmenu-glib/menuitem.h 2010-06-08 02:15:04 +0000
+++ libdbusmenu-glib/menuitem.h 2010-06-15 13:09:25 +0000
@@ -186,6 +186,11 @@
void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp);
void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi, dbusmenu_menuitem_about_to_show_cb cb, gpointer cb_data);
+/* Convenience functions */
+gboolean dbusmenu_menuitem_is_visible (DbusmenuMenuitem * mi);
+gboolean dbusmenu_menuitem_is_enabled (DbusmenuMenuitem * mi);
+DbusmenuMenuitem * dbusmenu_menuitem_child_append_separator (DbusmenuMenuitem *mi);
+
/**
* SECTION:menuitem
* @short_description: A lowlevel represenation of a menuitem
Follow ups