From 088c421863751188f5702cd0703b343cb07a2dea Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 13 Nov 2009 12:02:08 -0600 Subject: Moving 'buildxml' into the private header file. --- libdbusmenu-glib/menuitem.h | 1 - 1 file changed, 1 deletion(-) (limited to 'libdbusmenu-glib/menuitem.h') diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 6c3c265..da969d6 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -136,7 +136,6 @@ GHashTable * dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi); void dbusmenu_menuitem_set_root (DbusmenuMenuitem * mi, gboolean root); gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi); -void dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array, gint revision); void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data); void dbusmenu_menuitem_activate (DbusmenuMenuitem * mi); -- cgit v1.2.3 From 54a9ab9d12ec6750da50629099d11dfa559d51ca Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 13 Nov 2009 12:04:58 -0600 Subject: Making the 'type' property a #define --- libdbusmenu-glib/client.c | 3 ++- libdbusmenu-glib/menuitem.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/menuitem.h') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index ab307bd..c0ea0d7 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -34,6 +34,7 @@ License version 3 and version 2.1 along with this program. If not, see #include #include "client.h" +#include "menuitem.h" #include "dbusmenu-client.h" #include "server-marshal.h" @@ -606,7 +607,7 @@ menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GEr const gchar * type; DbusmenuClientTypeHandler newfunc = NULL; - type = dbusmenu_menuitem_property_get(propdata->item, "type"); + type = dbusmenu_menuitem_property_get(propdata->item, DBUSMENU_MENUITEM_PROP_TYPE); if (type != NULL) { newfunc = g_hash_table_lookup(priv->type_handlers, type); } else { diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index da969d6..27a86a2 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -50,6 +50,7 @@ G_BEGIN_DECLS #define DBUSMENU_MENUITEM_SIGNAL_REALIZED "realized" #define DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID (g_signal_lookup(DBUSMENU_MENUITEM_SIGNAL_REALIZED, DBUSMENU_TYPE_MENUITEM)) +#define DBUSMENU_MENUITEM_PROP_TYPE "type" #define DBUSMENU_MENUITEM_PROP_VISIBLE "visible" #define DBUSMENU_MENUITEM_PROP_SENSITIVE "sensitive" #define DBUSMENU_MENUITEM_PROP_LABEL "label" -- cgit v1.2.3 From 2997a508fd49ebbbfa53d1c5fc5d0d56250de760 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 9 Dec 2009 21:50:25 -0600 Subject: Switching the menuitem internal storage to be a hashtable of values. --- libdbusmenu-glib/menuitem.c | 78 +++++++++++++++++++++++++++++++++++++++++---- libdbusmenu-glib/menuitem.h | 4 ++- libdbusmenu-glib/server.c | 16 ---------- 3 files changed, 75 insertions(+), 23 deletions(-) (limited to 'libdbusmenu-glib/menuitem.h') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index d486b53..77f8e90 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -213,6 +213,20 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) static guint menuitem_next_id = 1; +/* A small little function to both clear the insides of a + value as well as the memory it itself uses. */ +static void +g_value_free (gpointer data) +{ + if (data == NULL) return; + GValue * value = (GValue*)data; + g_value_unset(value); + g_free(data); + return; +} + +/* Initialize the values of the in the object, and build the + properties hash table. */ static void dbusmenu_menuitem_init (DbusmenuMenuitem *self) { @@ -221,7 +235,7 @@ dbusmenu_menuitem_init (DbusmenuMenuitem *self) priv->id = 0; priv->children = NULL; - priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_value_free); priv->root = FALSE; @@ -673,28 +687,59 @@ dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id) */ gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value) +{ + GValue val = {0}; + g_value_init(&val, G_TYPE_STRING); + g_value_set_static_string(&val, value); + return dbusmenu_menuitem_property_set_value(mi, property, &val); +} + +/** + dbusmenu_menuitem_property_set: + @mi: The #DbusmenuMenuitem to set the property on. + @property: Name of the property to set. + @value: The value of the property. + + Takes the pair of @property and @value and places them as a + property on @mi. If a property already exists by that name, + then the value is set to the new value. If not, the property + is added. If the value is changed or the property was previously + unset then the signal #DbusmenuMenuitem::prop-changed will be + emitted by this function. + + Return value: A boolean representing if the property value was set. +*/ +gboolean +dbusmenu_menuitem_property_set_value (DbusmenuMenuitem * mi, const gchar * property, const GValue * value) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); g_return_val_if_fail(property != NULL, FALSE); + g_return_val_if_fail(G_IS_VALUE(value), FALSE); DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); /* g_debug("Setting a property. ID: %d Prop: %s Value: %s", priv->id, property, value); */ + #if 0 gpointer lookup = g_hash_table_lookup(priv->properties, property); if (g_strcmp0((gchar *)lookup, value) == 0) { /* The value is the same as the value currently in the table so we don't really care. Just say everything's okay */ return TRUE; } + #endif gchar * lprop = g_strdup(property); - gchar * lval = g_strdup(value); + GValue * lval = g_new0(GValue, 1); + g_value_init(lval, G_VALUE_TYPE(value)); + g_value_copy(value, lval); g_hash_table_insert(priv->properties, lprop, lval); #ifdef MASSIVEDEBUGGING - g_debug("Menuitem %d (%s) signalling property '%s' changed to '%s'", ID(mi), LABEL(mi), property, g_utf8_strlen(value, 50) < 25 ? value : ""); + gchar * valstr = g_strdup_value_contents(lval); + g_debug("Menuitem %d (%s) signalling property '%s' changed to '%s'", ID(mi), LABEL(mi), property, g_utf8_strlen(valstr, 50) < 25 ? valstr : ""); + g_free(valstr); #endif - g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, value, TRUE); + g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, lprop, lval, TRUE); return TRUE; } @@ -710,19 +755,40 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c Return value: A string with the value of the property that shouldn't be free'd. Or #NULL if the property - is not set. + is not set or is not a string. */ const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property) +{ + const GValue * value = dbusmenu_menuitem_property_get_value(mi, property); + if (value == NULL) return NULL; + if (G_VALUE_TYPE(value) != G_TYPE_STRING) return NULL; + return g_value_get_string(value); +} + +/** + dbusmenu_menuitem_property_get_value: + @mi: The #DbusmenuMenuitem to look for the property on. + @property: The property to grab. + + Look up a property on @mi and return the value of it if + it exits. #NULL will be returned if the property doesn't + exist. + + Return value: A GValue for the property. +*/ +const GValue * +dbusmenu_menuitem_property_get_value (DbusmenuMenuitem * mi, const gchar * property) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); g_return_val_if_fail(property != NULL, NULL); DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); - return (const gchar *)g_hash_table_lookup(priv->properties, property); + return (const GValue *)g_hash_table_lookup(priv->properties, property); } + /** dbusmenu_menuitem_property_exit: @mi: The #DbusmenuMenuitem to look for the property on. diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 27a86a2..f0615d7 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -94,7 +94,7 @@ struct _DbusmenuMenuitemClass GObjectClass parent_class; /* Signals */ - void (*property_changed) (gchar * property, gchar * value); + void (*property_changed) (gchar * property, GValue * value); void (*item_activated) (void); void (*child_added) (DbusmenuMenuitem * child, guint position); void (*child_removed) (DbusmenuMenuitem * child); @@ -129,7 +129,9 @@ DbusmenuMenuitem * dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, guint id DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id); gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value); +gboolean dbusmenu_menuitem_property_set_value (DbusmenuMenuitem * mi, const gchar * property, const GValue * value); const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property); +const GValue * dbusmenu_menuitem_property_get_value (DbusmenuMenuitem * mi, const gchar * property); gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property); GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) G_GNUC_WARN_UNUSED_RESULT; GHashTable * dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi); diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 73c21e2..f61b0fb 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -442,16 +442,6 @@ _dbusmenu_server_get_property (DbusmenuServer * server, guint id, gchar * proper return TRUE; } -static void -value_table (gpointer pkey, gpointer pvalue, gpointer phash) -{ - GValue * value = g_new0(GValue, 1); - g_value_init(value, G_TYPE_STRING); - g_value_set_string(value, (gchar *)pvalue); - g_hash_table_insert((GHashTable *)phash, g_strdup((gchar *)pkey), value); - return; -} - static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, guint id, GPtrArray * properties, GHashTable ** dict, GError ** error) { @@ -471,12 +461,6 @@ _dbusmenu_server_get_properties (DbusmenuServer * server, guint id, GPtrArray * *dict = dbusmenu_menuitem_properties_copy(mi); - GHashTable * newtable = g_hash_table_new(g_str_hash, g_str_equal); - g_hash_table_foreach(*dict, value_table, newtable); - g_hash_table_destroy(*dict); - - *dict = newtable; - return TRUE; } -- cgit v1.2.3 From 24c71d792f77c57d1ede30b23100d020b6624511 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 9 Dec 2009 22:57:31 -0600 Subject: Cleaning up our types. No more image type (but leaving to not confuse) and adding in the properties needed for toggle stuff. --- libdbusmenu-glib/client.h | 2 +- libdbusmenu-glib/menuitem.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/menuitem.h') diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index fff9a6b..b42bc83 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -52,7 +52,7 @@ G_BEGIN_DECLS #define DBUSMENU_CLIENT_TYPES_DEFAULT "menuitem" #define DBUSMENU_CLIENT_TYPES_SEPARATOR "separator" -#define DBUSMENU_CLIENT_TYPES_IMAGE "imageitem" +#define DBUSMENU_CLIENT_TYPES_IMAGE "menuitem" /** DbusmenuClientClass: diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index f0615d7..be56fc8 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -56,6 +56,11 @@ G_BEGIN_DECLS #define DBUSMENU_MENUITEM_PROP_LABEL "label" #define DBUSMENU_MENUITEM_PROP_ICON "icon" #define DBUSMENU_MENUITEM_PROP_ICON_DATA "icon-data" +#define DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE "toggle-type" +#define DBUSMENU_MENUITEM_PROP_TOGGLE_CHECKED "toggle-checked" + +#define DBUSMENU_MENUITEM_TOGGLE_CHECK "checkmark" +#define DBUSMENU_MENUITEM_TOGGLE_RADIO "radio" /** DbusmenuMenuitem: -- cgit v1.2.3 From 030d27a1ca21c10ddad7f04848f60b0b2adc4c40 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 15 Dec 2009 11:50:59 -0600 Subject: Basic implementation of some helper getter/setters for GValues with int and bools --- libdbusmenu-glib/menuitem.c | 36 ++++++++++++++++++++++++++++++++++++ libdbusmenu-glib/menuitem.h | 4 ++++ 2 files changed, 40 insertions(+) (limited to 'libdbusmenu-glib/menuitem.h') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 77f8e90..76ce79c 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -694,6 +694,24 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c return dbusmenu_menuitem_property_set_value(mi, property, &val); } +gboolean +dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * property, const gboolean value) +{ + GValue val = {0}; + g_value_init(&val, G_TYPE_BOOLEAN); + g_value_set_boolean(&val, value); + return dbusmenu_menuitem_property_set_value(mi, property, &val); +} + +gboolean +dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * property, const gint value) +{ + GValue val = {0}; + g_value_init(&val, G_TYPE_INT); + g_value_set_int(&val, value); + return dbusmenu_menuitem_property_set_value(mi, property, &val); +} + /** dbusmenu_menuitem_property_set: @mi: The #DbusmenuMenuitem to set the property on. @@ -788,6 +806,24 @@ dbusmenu_menuitem_property_get_value (DbusmenuMenuitem * mi, const gchar * prope return (const GValue *)g_hash_table_lookup(priv->properties, property); } +gboolean +dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem * mi, const gchar * property) +{ + const GValue * value = dbusmenu_menuitem_property_get_value(mi, property); + if (value == NULL) return FALSE; + if (G_VALUE_TYPE(value) != G_TYPE_BOOLEAN) return FALSE; + return g_value_get_boolean(value); +} + +gint +dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * property) +{ + const GValue * value = dbusmenu_menuitem_property_get_value(mi, property); + if (value == NULL) return 0; + if (G_VALUE_TYPE(value) != G_TYPE_INT) return 0; + return g_value_get_int(value); +} + /** dbusmenu_menuitem_property_exit: diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index be56fc8..fc9e410 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -135,8 +135,12 @@ DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id); gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value); gboolean dbusmenu_menuitem_property_set_value (DbusmenuMenuitem * mi, const gchar * property, const GValue * value); +gboolean dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * property, const gboolean value); +gboolean dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * property, const gint value); const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property); const GValue * dbusmenu_menuitem_property_get_value (DbusmenuMenuitem * mi, const gchar * property); +gboolean dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem * mi, const gchar * property); +gint dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * property); gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property); GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) G_GNUC_WARN_UNUSED_RESULT; GHashTable * dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi); -- cgit v1.2.3 From b55ffff099bd5e808d6f8b25dc8dec902f9d3663 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Jan 2010 10:49:35 -0600 Subject: Adding #defines for the state of the box --- libdbusmenu-glib/menuitem.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-glib/menuitem.h') diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index fc9e410..aaafe17 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -62,6 +62,10 @@ G_BEGIN_DECLS #define DBUSMENU_MENUITEM_TOGGLE_CHECK "checkmark" #define DBUSMENU_MENUITEM_TOGGLE_RADIO "radio" +#define DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED "unchecked" +#define DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED "checked" +#define DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN "indeterminate" + /** DbusmenuMenuitem: -- cgit v1.2.3