diff options
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r-- | libdbusmenu-glib/Makefile.am | 2 | ||||
-rw-r--r-- | libdbusmenu-glib/client-menuitem.c | 2 | ||||
-rw-r--r-- | libdbusmenu-glib/client-private.h | 3 | ||||
-rw-r--r-- | libdbusmenu-glib/client.c | 56 | ||||
-rw-r--r-- | libdbusmenu-glib/dbus-menu.xml | 13 | ||||
-rw-r--r-- | libdbusmenu-glib/defaults.c | 5 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem-proxy.c | 2 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 21 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.h | 67 | ||||
-rw-r--r-- | libdbusmenu-glib/server.c | 131 |
10 files changed, 222 insertions, 80 deletions
diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index 5b04415..7d4ea5d 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -189,6 +189,7 @@ endif # VAPI Files ######################### +if HAVE_VALA if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi @@ -200,4 +201,5 @@ Dbusmenu-0.4.vapi: Dbusmenu-0.4.gir CLEANFILES += $(vapi_DATA) endif +endif diff --git a/libdbusmenu-glib/client-menuitem.c b/libdbusmenu-glib/client-menuitem.c index 60f8637..483470a 100644 --- a/libdbusmenu-glib/client-menuitem.c +++ b/libdbusmenu-glib/client-menuitem.c @@ -106,7 +106,7 @@ static void handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp) { DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi); - dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, variant, timestamp); + dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, variant, timestamp, mi); return; } diff --git a/libdbusmenu-glib/client-private.h b/libdbusmenu-glib/client-private.h index f6df372..44c0066 100644 --- a/libdbusmenu-glib/client-private.h +++ b/libdbusmenu-glib/client-private.h @@ -37,7 +37,8 @@ void dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, GVariant * variant, - guint timestamp); + guint timestamp, + DbusmenuMenuitem * mi); void dbusmenu_client_send_about_to_show(DbusmenuClient * client, gint id, void (*cb) (gpointer user_data), diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index a98ae98..1ee8641 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -331,6 +331,8 @@ dbusmenu_client_class_init (DbusmenuClientClass *klass) return; } +#define LAYOUT_PROPS_COUNT 5 + static void dbusmenu_client_init (DbusmenuClient *self) { @@ -351,13 +353,14 @@ dbusmenu_client_init (DbusmenuClient *self) priv->layoutcall = NULL; - gchar * layout_props[5]; + gchar * layout_props[LAYOUT_PROPS_COUNT + 1]; layout_props[0] = DBUSMENU_MENUITEM_PROP_TYPE; layout_props[1] = DBUSMENU_MENUITEM_PROP_LABEL; layout_props[2] = DBUSMENU_MENUITEM_PROP_VISIBLE; layout_props[3] = DBUSMENU_MENUITEM_PROP_ENABLED; - layout_props[4] = NULL; - priv->layout_props = g_variant_new_strv((const gchar * const *)layout_props, 4); + layout_props[4] = DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY; + layout_props[LAYOUT_PROPS_COUNT] = NULL; + priv->layout_props = g_variant_new_strv((const gchar * const *)layout_props, LAYOUT_PROPS_COUNT); g_variant_ref_sink(priv->layout_props); priv->current_revision = 0; @@ -441,6 +444,9 @@ dbusmenu_client_dispose (GObject *object) priv->menuproxy_cancel = NULL; } if (priv->menuproxy != NULL) { + g_signal_handlers_disconnect_matched(priv->menuproxy, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, object); g_object_unref(G_OBJECT(priv->menuproxy)); priv->menuproxy = NULL; } @@ -598,10 +604,10 @@ get_properties_callback (GObject *obj, GAsyncResult * res, gpointer user_data) } /* Callback all the folks we can find */ - GVariant * child = g_variant_get_child_value(params, 0); + GVariant * parent = g_variant_get_child_value(params, 0); GVariantIter iter; - g_variant_iter_init(&iter, child); - g_variant_unref(child); + g_variant_iter_init(&iter, parent); + GVariant * child; while ((child = g_variant_iter_next_value(&iter)) != NULL) { if (g_strcmp0(g_variant_get_type_string(child), "(ia{sv})") != 0) { g_warning("Properties return signature is not '(ia{sv})' it is '%s'", g_variant_get_type_string(child)); @@ -632,6 +638,7 @@ get_properties_callback (GObject *obj, GAsyncResult * res, gpointer user_data) g_variant_unref(properties); g_variant_unref(child); } + g_variant_unref(parent); g_variant_unref(params); /* Provide errors for those who we can't */ @@ -1232,7 +1239,7 @@ menuproxy_signal_cb (GDBusProxy * proxy, gchar * sender, gchar * signal, GVarian } else if (priv->root == NULL) { /* Drop out here, all the rest of these really need to have a root node so we can just ignore them if there isn't one. */ - } else if (g_strcmp0(signal, "ItemPropertiesUpdated") == 0) { + } else if (g_strcmp0(signal, "ItemsPropertiesUpdated") == 0) { /* Remove before adding just incase there is a duplicate, against the rules, but we can handle it so let's do it. */ GVariantIter ritems; @@ -1333,8 +1340,16 @@ menuitem_get_properties_cb (GVariant * properties, GError * error, gpointer data if (error != NULL) { g_warning("Error getting properties on a menuitem: %s", error->message); - g_object_unref(data); - return; + goto out; + } + + if (properties == NULL) { + goto out; + } + + if (!g_variant_is_of_type(properties, G_VARIANT_TYPE("a{sv}"))) { + g_warning("Properties are of type '%s' instead of type '%s'", g_variant_get_type_string(properties), "a{sv}"); + goto out; } GVariantIter iter; @@ -1347,6 +1362,7 @@ menuitem_get_properties_cb (GVariant * properties, GError * error, gpointer data dbusmenu_menuitem_property_set_variant(item, key, value); } +out: g_object_unref(data); return; @@ -1365,12 +1381,16 @@ menuitem_get_properties_replace_cb (GVariant * properties, GError * error, gpoin g_warning("Unable to replace properties on %d: %s", dbusmenu_menuitem_get_id(DBUSMENU_MENUITEM(data)), error->message); have_error = TRUE; } + + if (properties == NULL) { + have_error = TRUE; + } /* Get the list of the current properties */ GList * current_props = dbusmenu_menuitem_properties_list(DBUSMENU_MENUITEM(data)); GList * tmp = NULL; - if (properties != NULL) { + if (!have_error && g_variant_is_of_type(properties, G_VARIANT_TYPE("a{sv}"))) { GVariantIter iter; g_variant_iter_init(&iter, properties); gchar * name; GVariant * value; @@ -1378,7 +1398,7 @@ menuitem_get_properties_replace_cb (GVariant * properties, GError * error, gpoin /* Remove the entries from the current list that we have new values for. This way we don't create signals of them being removed with the duplication of the value being changed. */ - while (g_variant_iter_loop(&iter, "{sv}", &name, &value) && have_error == FALSE) { + while (g_variant_iter_loop(&iter, "{sv}", &name, &value)) { for (tmp = current_props; tmp != NULL; tmp = g_list_next(tmp)) { if (g_strcmp0((gchar *)tmp->data, name) == 0) { current_props = g_list_delete_link(current_props, tmp); @@ -1414,8 +1434,12 @@ menuitem_get_properties_new_cb (GVariant * properties, GError * error, gpointer if (error != NULL) { g_warning("Error getting properties on a new menuitem: %s", error->message); - g_object_unref(propdata->item); - return; + goto out; + } + + if (properties == NULL) { + g_warning("Not realizing new item as properties for it were unavailable"); + goto out; } DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(propdata->client); @@ -1449,6 +1473,7 @@ menuitem_get_properties_new_cb (GVariant * properties, GError * error, gpointer g_signal_emit(G_OBJECT(propdata->client), signals[NEW_MENUITEM], 0, propdata->item, TRUE); } +out: g_object_unref(propdata->item); g_free(propdata); @@ -1475,6 +1500,7 @@ menuitem_call_cb (GObject * proxy, GAsyncResult * res, gpointer userdata) g_variant_unref(edata->variant); g_free(edata->event); g_object_unref(edata->menuitem); + g_object_unref(edata->client); g_free(edata); if (G_UNLIKELY(error != NULL)) { @@ -1490,14 +1516,13 @@ menuitem_call_cb (GObject * proxy, GAsyncResult * res, gpointer userdata) /* Sends the event over DBus to the server on the other side of the bus. */ void -dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, GVariant * variant, guint timestamp) +dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, GVariant * variant, guint timestamp, DbusmenuMenuitem * mi) { g_return_if_fail(DBUSMENU_IS_CLIENT(client)); g_return_if_fail(id >= 0); g_return_if_fail(name != NULL); DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); - DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { g_warning("Asked to activate a menuitem %d that we don't know about", id); return; @@ -1509,6 +1534,7 @@ dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name event_data_t * edata = g_new0(event_data_t, 1); edata->client = client; + g_object_ref(client); edata->menuitem = mi; g_object_ref(edata->menuitem); edata->event = g_strdup(name); 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 9eaf9e5..a5caf0b 100644 --- a/libdbusmenu-glib/defaults.c +++ b/libdbusmenu-glib/defaults.c @@ -81,12 +81,13 @@ dbusmenu_defaults_init (DbusmenuDefaults *self) /* Standard defaults */ dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_VISIBLE, G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(TRUE)); dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_ENABLED, G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(TRUE)); - dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_LABEL, G_VARIANT_TYPE_STRING, g_variant_new_string(_("Label Empty"))); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_LABEL, G_VARIANT_TYPE_STRING, g_variant_new_string(_("Label Empty"))); dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_ICON_NAME, G_VARIANT_TYPE_STRING, NULL); dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, G_VARIANT_TYPE_STRING, NULL); 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_ARRAY, 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-proxy.c b/libdbusmenu-glib/menuitem-proxy.c index ae6a334..fdbd892 100644 --- a/libdbusmenu-glib/menuitem-proxy.c +++ b/libdbusmenu-glib/menuitem-proxy.c @@ -188,6 +188,7 @@ proxy_item_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, gui DbusmenuMenuitemProxy * pmi = DBUSMENU_MENUITEM_PROXY(user_data); DbusmenuMenuitemProxy * child_pmi = dbusmenu_menuitem_proxy_new(child); dbusmenu_menuitem_child_add_position(DBUSMENU_MENUITEM(pmi), DBUSMENU_MENUITEM(child_pmi), position); + g_object_unref (child_pmi); return; } @@ -283,6 +284,7 @@ add_menuitem (DbusmenuMenuitemProxy * pmi, DbusmenuMenuitem * mi) for (child = children; child != NULL; child = g_list_next(child)) { DbusmenuMenuitemProxy * child_pmi = dbusmenu_menuitem_proxy_new(DBUSMENU_MENUITEM(child->data)); dbusmenu_menuitem_child_append(DBUSMENU_MENUITEM(pmi), DBUSMENU_MENUITEM(child_pmi)); + g_object_unref (child_pmi); } return; diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 70b5fd2..4e037ee 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -446,7 +446,7 @@ send_about_to_show (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gp { g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); - if (dbusmenu_menuitem_get_children(mi) == NULL) { + if (dbusmenu_menuitem_get_children(mi) == NULL && g_strcmp0(DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU, dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) != 0) { g_warning("About to Show called on an item wihtout submenus. We're ignoring it."); } else { gboolean dummy; @@ -575,7 +575,7 @@ dbusmenu_menuitem_set_realized (DbusmenuMenuitem * mi) * has. The list is valid until another child related function * is called, where it might be changed. * - * Return value: (transfer none): A #GList of pointers to #DbusmenuMenuitem objects. + * Return value: (transfer none) (element-type Dbusmenu.Menuitem): A #GList of pointers to #DbusmenuMenuitem objects. */ GList * dbusmenu_menuitem_get_children (DbusmenuMenuitem * mi) @@ -1694,25 +1694,20 @@ dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, GVari #endif DbusmenuMenuitemClass * class = DBUSMENU_MENUITEM_GET_CLASS(mi); - /* We need to keep a ref to the variant because the signal - handler will drop the floating ref and then we'll be up - a creek if we don't have our own later. */ - if (variant != NULL) { - g_variant_ref_sink(variant); + gboolean handled = FALSE; + if (variant == NULL) { + variant = g_variant_new_int32(0); } - gboolean handled = FALSE; + g_variant_ref_sink(variant); + g_signal_emit(G_OBJECT(mi), signals[EVENT], g_quark_from_string(name), name, variant, timestamp, &handled); if (!handled && class->handle_event != NULL) { class->handle_event(mi, name, variant, timestamp); } - if (variant != NULL) { - g_variant_unref(variant); - } - - return; + g_variant_unref(variant); } /** 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 a41e6ce..9c085f7 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -455,6 +455,7 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) g_return_if_fail(priv->bus_lookup != NULL); } + g_object_ref(obj); g_bus_get(G_BUS_TYPE_SESSION, priv->bus_lookup, bus_got_cb, obj); } else { register_object(DBUSMENU_SERVER(obj)); @@ -694,6 +695,7 @@ bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data) if (error != NULL) { g_warning("Unable to get session bus: %s", error->message); g_error_free(error); + g_object_unref(G_OBJECT(user_data)); return; } @@ -706,6 +708,7 @@ bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data) register_object(DBUSMENU_SERVER(user_data)); + g_object_unref(G_OBJECT(user_data)); return; } @@ -949,11 +952,13 @@ menuitem_property_idle (gpointer user_data) } } + /* these are going to be standard references in all code paths and must be unrefed */ GVariant * megadata[2]; gboolean gotsomething = FALSE; if (item_init) { megadata[0] = g_variant_builder_end(&itembuilder); + g_variant_ref_sink(megadata[0]); gotsomething = TRUE; } else { GError * error = NULL; @@ -967,13 +972,14 @@ menuitem_property_idle (gpointer user_data) if (removeitem_init) { megadata[1] = g_variant_builder_end(&removeitembuilder); + g_variant_ref_sink(megadata[1]); 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); } } @@ -983,14 +989,14 @@ menuitem_property_idle (gpointer user_data) NULL, priv->dbusobject, DBUSMENU_INTERFACE, - "ItemPropertiesUpdated", + "ItemsPropertiesUpdated", g_variant_new_tuple(megadata, 2), NULL); - } else { - g_variant_unref(megadata[0]); - g_variant_unref(megadata[1]); } + g_variant_unref(megadata[0]); + g_variant_unref(megadata[1]); + /* Clean everything up */ prop_array_teardown(priv->prop_array); priv->prop_array = NULL; @@ -1188,12 +1194,16 @@ error_quark (void) static void bus_get_layout (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { + g_return_if_fail(DBUSMENU_IS_SERVER(server)); DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + g_return_if_fail(priv != NULL); /* Input */ - gint parent = g_variant_get_int32(g_variant_get_child_value(params, 0)); - gint recurse = g_variant_get_int32(g_variant_get_child_value(params, 1)); - const gchar ** props = g_variant_get_strv(g_variant_get_child_value(params, 2), NULL); + gint32 parent; + gint32 recurse; + const gchar ** props; + + g_variant_get(params, "(ii^a&s)", &parent, &recurse, &props); /* Output */ guint revision = priv->layout_revision; @@ -1206,6 +1216,7 @@ bus_get_layout (DbusmenuServer * server, GVariant * params, GDBusMethodInvocatio items = dbusmenu_menuitem_build_variant(mi, props, recurse); } } + g_free(props); /* What happens if we don't have anything? */ if (items == NULL) { @@ -1252,9 +1263,11 @@ bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat "There currently isn't a layout in this server"); return; } - - gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); - const gchar * property = g_variant_get_string(g_variant_get_child_value(params, 1), NULL); + + gint32 id; + const gchar * property; + + g_variant_get(params, "(i&s)", &id, &property); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); @@ -1296,7 +1309,8 @@ bus_get_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvoc return; } - gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); + gint32 id; + g_variant_get(params, "(i)", &id); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); @@ -1324,28 +1338,43 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); if (priv->root == NULL) { + /* Allow a request for just id 0 when root is null. Return no properties. + So that a request always returns a valid structure no matter the + state of the structure in the server. + */ GVariant * idlist = g_variant_get_child_value(params, 0); - if (g_variant_n_children(idlist) == 1 && g_variant_get_int32(g_variant_get_child_value(idlist, 0)) == 0) { - GVariant * final = g_variant_parse(g_variant_type_new("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, NULL); - g_dbus_method_invocation_return_value(invocation, final); - return; - } + if (g_variant_n_children(idlist) == 1) { - g_dbus_method_invocation_return_error(invocation, - error_quark(), - NO_VALID_LAYOUT, - "There currently isn't a layout in this server"); + GVariant *id_v = g_variant_get_child_value(idlist, 0); + gint32 id = g_variant_get_int32(id_v); + g_variant_unref(id_v); + + if (id == 0) { + + GVariant * final = g_variant_parse(G_VARIANT_TYPE("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, NULL); + g_dbus_method_invocation_return_value(invocation, final); + g_variant_unref(final); + } + } else { + + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + } + g_variant_unref(idlist); return; } - GVariantIter ids; - g_variant_iter_init(&ids, g_variant_get_child_value(params, 0)); + GVariantIter *ids; + g_variant_get(params, "(aias)", &ids, NULL); + /* TODO: implementation ignores propertyNames declared in XML */ GVariantBuilder builder; gboolean builder_init = FALSE; - gint id; - while (g_variant_iter_next(&ids, "i", &id)) { + gint32 id; + while (g_variant_iter_loop(ids, "i", &id)) { DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) continue; @@ -1361,7 +1390,7 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho if (props == NULL) { GError * error = NULL; - props = g_variant_parse(g_variant_type_new("a{sv}"), "{}", NULL, NULL, &error); + props = g_variant_parse(G_VARIANT_TYPE("a{sv}"), "{}", NULL, NULL, &error); if (error != NULL) { g_warning("Unable to parse '{}' as a 'a{sv}': %s", error->message); g_error_free(error); @@ -1374,18 +1403,20 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho g_variant_builder_add_value(&builder, mi_data); } + g_variant_iter_free(ids); + /* a standard reference that must be unrefed */ GVariant * ret = NULL; if (builder_init) { ret = g_variant_builder_end(&builder); + g_variant_ref_sink(ret); } else { GError * error = NULL; - ret = g_variant_parse(g_variant_type_new("a(ia{sv})"), "[]", NULL, NULL, NULL); + ret = g_variant_parse(G_VARIANT_TYPE("a(ia{sv})"), "[]", NULL, NULL, &error); if (error != NULL) { g_warning("Unable to parse '[]' as a 'a(ia{sv})': %s", error->message); g_error_free(error); - ret = NULL; } } @@ -1393,6 +1424,7 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho if (ret != NULL) { g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_add_value(&builder, ret); + g_variant_unref(ret); final = g_variant_builder_end(&builder); } else { g_warning("Error building property list, final variant is NULL"); @@ -1431,7 +1463,8 @@ static void bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); + gint32 id; + g_variant_get(params, "(i)", &id); if (priv->root == NULL) { g_dbus_method_invocation_return_error(invocation, @@ -1465,7 +1498,7 @@ bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat ret = g_variant_new_tuple(&end, 1); } else { GError * error = NULL; - ret = g_variant_parse(g_variant_type_new("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, &error); + ret = g_variant_parse(G_VARIANT_TYPE("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, &error); if (error != NULL) { g_warning("Unable to parse '([(0, {})],)' as a '(a(ia{sv}))': %s", error->message); g_error_free(error); @@ -1517,32 +1550,35 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i return; } - gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); + gint32 id; + gchar *etype; + GVariant *data; + guint32 ts; + + g_variant_get(params, "(isvu)", &id, &etype, &data, &ts); + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { + g_dbus_method_invocation_return_error(invocation, error_quark(), INVALID_MENUITEM_ID, "The ID supplied %d does not refer to a menu item we have", id); - return; - } - - idle_event_t * event_data = g_new0(idle_event_t, 1); - event_data->mi = mi; - g_object_ref(event_data->mi); - event_data->eventid = g_strdup(g_variant_get_string(g_variant_get_child_value(params, 1), NULL)); - event_data->timestamp = g_variant_get_uint32(g_variant_get_child_value(params, 3)); - event_data->variant = g_variant_get_child_value(params, 2); + g_free(etype); + g_variant_unref(data); - if (g_variant_is_of_type(event_data->variant, G_VARIANT_TYPE_VARIANT)) { - event_data->variant = g_variant_get_variant(event_data->variant); - } + } else { - g_variant_ref_sink(event_data->variant); + idle_event_t * event_data = g_new0(idle_event_t, 1); + event_data->mi = g_object_ref(mi); + event_data->eventid = etype; + event_data->timestamp = ts; + event_data->variant = data; /* give away our reference */ - g_timeout_add(0, event_local_handler, event_data); + g_timeout_add(0, event_local_handler, event_data); + } g_dbus_method_invocation_return_value(invocation, NULL); return; @@ -1562,7 +1598,8 @@ bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvoca return; } - gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); + gint32 id; + g_variant_get(params, "(i)", &id); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { |