diff options
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r-- | libdbusmenu-glib/Makefile.in | 11 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 19 | ||||
-rw-r--r-- | libdbusmenu-glib/server.c | 120 |
3 files changed, 92 insertions, 58 deletions
diff --git a/libdbusmenu-glib/Makefile.in b/libdbusmenu-glib/Makefile.in index 5c19fc4..11cce15 100644 --- a/libdbusmenu-glib/Makefile.in +++ b/libdbusmenu-glib/Makefile.in @@ -61,7 +61,12 @@ DIST_COMMON = $(libdbusmenu_glibinclude_HEADERS) $(srcdir)/Makefile.am \ @HAVE_INTROSPECTION_TRUE@ $(vapi_DATA) subdir = libdbusmenu-glib ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__aclocal_m4_deps = $(top_srcdir)/m4/gnome-doc-utils.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -178,6 +183,7 @@ DBUSMENUTESTS_LIBS = @DBUSMENUTESTS_LIBS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DISTCHECK_CONFIGURE_FLAGS = @DISTCHECK_CONFIGURE_FLAGS@ +DLLTOOL = @DLLTOOL@ DOC_USER_FORMATS = @DOC_USER_FORMATS@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ @@ -229,6 +235,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MKINSTALLDIRS = @MKINSTALLDIRS@ MSGFMT = @MSGFMT@ @@ -270,6 +277,7 @@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -302,7 +310,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index bdaf49f..4e037ee 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -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/server.c b/libdbusmenu-glib/server.c index be99421..f81b3ed 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -952,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; @@ -970,6 +972,7 @@ 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; @@ -989,11 +992,11 @@ menuitem_property_idle (gpointer user_data) "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; @@ -1194,9 +1197,11 @@ bus_get_layout (DbusmenuServer * server, GVariant * params, GDBusMethodInvocatio DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); /* 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; @@ -1209,6 +1214,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) { @@ -1255,9 +1261,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); @@ -1299,7 +1307,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); @@ -1327,28 +1336,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; @@ -1364,7 +1388,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); @@ -1377,18 +1401,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; } } @@ -1396,6 +1422,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"); @@ -1434,7 +1461,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, @@ -1468,7 +1496,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); @@ -1520,32 +1548,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; @@ -1565,7 +1596,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) { |