diff options
author | Aurelien Gateau <aurelien.gateau@canonical.com> | 2010-02-02 19:02:34 -0800 |
---|---|---|
committer | Aurelien Gateau <aurelien.gateau@canonical.com> | 2010-02-02 19:02:34 -0800 |
commit | 96512c9c06438eb32d8af0e29229f84455fffc64 (patch) | |
tree | 8ae6ea2529bfac9174a83880f57d5dd607c9867b /libdbusmenu-glib | |
parent | 29d3e5fa54df93e5a139ecd34f1d51cb28dcb6b2 (diff) | |
download | libdbusmenu-96512c9c06438eb32d8af0e29229f84455fffc64.tar.gz libdbusmenu-96512c9c06438eb32d8af0e29229f84455fffc64.tar.bz2 libdbusmenu-96512c9c06438eb32d8af0e29229f84455fffc64.zip |
- Allow id to be 0.
- Fix default item type.
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r-- | libdbusmenu-glib/client.c | 25 | ||||
-rw-r--r-- | libdbusmenu-glib/client.h | 4 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 15 |
3 files changed, 21 insertions, 23 deletions
diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 5d07fc6..66984e2 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -99,7 +99,7 @@ static void layout_update (DBusGProxy * proxy, gint revision, guint parent, Dbus static void id_prop_update (DBusGProxy * proxy, gint id, gchar * property, GValue * value, DbusmenuClient * client); static void id_update (DBusGProxy * proxy, gint id, DbusmenuClient * client); static void build_proxies (DbusmenuClient * client); -static guint parse_node_get_id (xmlNodePtr node); +static gint parse_node_get_id (xmlNodePtr node); static DbusmenuMenuitem * parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * item, DbusmenuMenuitem * parent, DBusGProxy * proxy); static gint parse_layout (DbusmenuClient * client, const gchar * layout); static void update_layout_cb (DBusGProxy * proxy, guint rev, gchar * xml, GError * in_error, void * data); @@ -517,20 +517,20 @@ build_proxies (DbusmenuClient * client) /* Get the ID attribute of the node, parse it and return it. Also we're checking to ensure the node is a 'menu' here. */ -static guint +static gint parse_node_get_id (xmlNodePtr node) { if (g_strcmp0((gchar *)node->name, "menu") != 0) { /* This kills some nodes early */ g_warning("XML Node is not 'menu' it is '%s'", node->name); - return 0; + return -1; } xmlAttrPtr attrib; for (attrib = node->properties; attrib != NULL; attrib = attrib->next) { if (g_strcmp0((gchar *)attrib->name, "id") == 0) { if (attrib->children != NULL) { - gint id = (guint)g_ascii_strtoull((gchar *)attrib->children->content, NULL, 10); + gint id = (guint)g_ascii_strtoll((gchar *)attrib->children->content, NULL, 10); /* g_debug ("Found ID: %d", id); */ return id; } @@ -539,7 +539,7 @@ parse_node_get_id (xmlNodePtr node) } g_warning("Unable to find an ID on the node"); - return 0; + return -1; } /* A small helper that calls _property_set on each hash table @@ -643,10 +643,13 @@ static DbusmenuMenuitem * parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * item, DbusmenuMenuitem * parent, DBusGProxy * proxy) { gint id = parse_node_get_id(node); + if (id < 0) { + return NULL; + } #ifdef MASSIVEDEBUGGING g_debug("Client looking at node with id: %d", id); #endif - if (item == NULL || dbusmenu_menuitem_get_id(item) != id || id == 0) { + if (item == NULL || dbusmenu_menuitem_get_id(item) != id) { if (item != NULL) { if (parent != NULL) { dbusmenu_menuitem_child_delete(parent, item); @@ -655,11 +658,6 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it item = NULL; } - if (id == 0) { - g_warning("ID from XML file is zero"); - return NULL; - } - /* Build a new item */ item = dbusmenu_menuitem_new_with_id(id); if (parent == NULL) { @@ -689,7 +687,10 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it for (children = node->children, position = 0; children != NULL; children = children->next, position++) { /* g_debug("Looking at child: %d", position); */ - guint childid = parse_node_get_id(children); + gint childid = parse_node_get_id(children); + if (childid < 0) { + continue; + } DbusmenuMenuitem * childmi = NULL; GList * childsearch = NULL; diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index b42bc83..15192f4 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -50,9 +50,9 @@ G_BEGIN_DECLS #define DBUSMENU_CLIENT_PROP_DBUS_NAME "dbus-name" #define DBUSMENU_CLIENT_PROP_DBUS_OBJECT "dbus-object" -#define DBUSMENU_CLIENT_TYPES_DEFAULT "menuitem" +#define DBUSMENU_CLIENT_TYPES_DEFAULT "standard" #define DBUSMENU_CLIENT_TYPES_SEPARATOR "separator" -#define DBUSMENU_CLIENT_TYPES_IMAGE "menuitem" +#define DBUSMENU_CLIENT_TYPES_IMAGE "standard" /** DbusmenuClientClass: diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 08cc27b..7e1e1ac 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -207,7 +207,7 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) G_TYPE_NONE, 0, G_TYPE_NONE); g_object_class_install_property (object_class, PROP_ID, - g_param_spec_uint("id", "ID for the menu item", + g_param_spec_int("id", "ID for the menu item", "This is a unique indentifier for the menu item.", 0, 30000, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); @@ -246,7 +246,7 @@ g_value_transform_STRING_INT (const GValue * in, GValue * out) return; } -static guint menuitem_next_id = 1; +static gint menuitem_next_id = 1; /* A small little function to both clear the insides of a value as well as the memory it itself uses. */ @@ -315,9 +315,9 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) switch (id) { case PROP_ID: - priv->id = g_value_get_uint(value); + priv->id = g_value_get_int(value); if (priv->id > menuitem_next_id) { - menuitem_next_id = priv->id; + menuitem_next_id = priv->id + 1; } break; } @@ -332,10 +332,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) switch (id) { case PROP_ID: - if (priv->id == 0) { - priv->id = menuitem_next_id++; - } - g_value_set_uint(value, priv->id); + g_value_set_int(value, priv->id); break; } @@ -355,7 +352,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) DbusmenuMenuitem * dbusmenu_menuitem_new (void) { - return g_object_new(DBUSMENU_TYPE_MENUITEM, NULL); + return g_object_new(DBUSMENU_TYPE_MENUITEM, "id", menuitem_next_id++, NULL); } /** |