From b856f7cd47db470f4369aa28ad87dc1925bf68a5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Nov 2010 16:31:51 -0600 Subject: Switching to getting the name with GDBus --- tools/testapp/main.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'tools') diff --git a/tools/testapp/main.c b/tools/testapp/main.c index f489407..67e962d 100644 --- a/tools/testapp/main.c +++ b/tools/testapp/main.c @@ -26,9 +26,7 @@ License version 3 and version 2.1 along with this program. If not, see */ #include - -#include -#include +#include #include @@ -117,6 +115,24 @@ void init_menu(DbusmenuMenuitem *root, const char *filename) } } +static void +on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data) +{ + DbusmenuServer *server = dbusmenu_server_new("/MenuBar"); + DbusmenuMenuitem *root = dbusmenu_menuitem_new_with_id(0); + init_menu(root, (gchar *)user_data); + dbusmenu_server_set_root(server, root); + + return; +} + +static void +name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data) +{ + g_error("Unable to get name '%s' on DBus", name); + return; +} + int main (int argc, char ** argv) { g_type_init(); @@ -127,25 +143,14 @@ int main (int argc, char ** argv) } const char *filename = argv[1]; - GError * error = NULL; - DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); - guint nameret = 0; - - if (!org_freedesktop_DBus_request_name(bus_proxy, "org.dbusmenu.test", 0, &nameret, &error)) { - g_error("Unable to call to request name"); - return 1; - } - - if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - g_error("Unable to get name"); - return 1; - } - - DbusmenuServer *server = dbusmenu_server_new("/MenuBar"); - DbusmenuMenuitem *root = dbusmenu_menuitem_new_with_id(0); - init_menu(root, filename); - dbusmenu_server_set_root(server, root); + g_bus_own_name(G_BUS_TYPE_SESSION, + "org.dbusmenu.test", + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus, + NULL, + name_lost, + (gpointer)filename, + NULL); g_main_loop_run(g_main_loop_new(NULL, FALSE)); -- cgit v1.2.3 From e9e8e1c31e0a32e23e2526622d2435f60c24a084 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 11:12:28 -0600 Subject: Porting the dumper to GDBus --- tools/dbusmenu-dumper.c | 154 ++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 124 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 3256f7e..4580e4c 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -21,7 +21,6 @@ with this program. If not, see . */ #include -#include #include #include @@ -30,111 +29,10 @@ with this program. If not, see . #include #include -#include #include static GMainLoop * mainloop = NULL; -static gchar * value2string (const GValue * value, int depth); - -static gchar * -strv_dumper(const GValue * value) -{ - gchar ** strv = (gchar **)g_value_get_boxed(value); - - gchar * joined = g_strjoinv("\", \"", strv); - gchar * retval = g_strdup_printf("[\"%s\"]", joined); - g_free(joined); - return retval; -} - -typedef struct _collection_iterator_t collection_iterator_t; -struct _collection_iterator_t { - gchar * space; - GPtrArray * array; - gboolean first; - int depth; -}; - -static void -collection_iterate (const GValue * value, gpointer user_data) -{ - collection_iterator_t * iter = (collection_iterator_t *)user_data; - - gchar * str = value2string(value, iter->depth); - gchar * retval = NULL; - - if (iter->first) { - iter->first = FALSE; - retval = g_strdup_printf("\n%s%s", iter->space, str); - } else { - retval = g_strdup_printf(",\n%s%s", iter->space, str); - } - - g_ptr_array_add(iter->array, retval); - g_free(str); - - return; -} - -static gchar * -collection_dumper (const GValue * value, int depth) -{ - gchar * space = g_strnfill(depth, ' '); - GPtrArray * array = g_ptr_array_new_with_free_func(g_free); - - g_ptr_array_add(array, g_strdup("[")); - - collection_iterator_t iter; - iter.space = space; - iter.array = array; - iter.first = TRUE; - iter.depth = depth + 2; - - dbus_g_type_collection_value_iterate(value, collection_iterate, &iter); - - g_ptr_array_add(array, g_strdup_printf("\n%s]", space)); - - g_free(space); - - gchar * retstr = NULL; - if (array->len == 3) { - retstr = g_strdup_printf("[%s]", ((gchar *)array->pdata[1]) + depth + 1/*for newline*/); - } else { - retstr = g_strjoinv(NULL, (gchar **)array->pdata); - } - - g_ptr_array_free(array, TRUE); - - return retstr; -} - -static gchar * -value2string (const GValue * value, int depth) -{ - gchar * str = NULL; - - if (value == NULL) { - return g_strdup("(null)"); - } - - if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { - str = collection_dumper(value, depth); - } else if (G_VALUE_TYPE(value) == G_TYPE_STRV) { - str = strv_dumper(value); - } else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN) { - if (g_value_get_boolean(value)) { - str = g_strdup("true"); - } else { - str = g_strdup("false"); - } - } else { - str = g_strdup_value_contents(value); - } - - return str; -} - static gint list_str_cmp (gconstpointer a, gconstpointer b) { @@ -151,10 +49,11 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * properties = g_list_sort(properties_raw, list_str_cmp); GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { - const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); - gchar * str = value2string(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */); + GVariant * variant = dbusmenu_menuitem_property_get_variant(item, (gchar *)property->data); + gchar * str = g_variant_print(variant, FALSE); g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str); g_free(str); + g_variant_unref(variant); } g_list_free(properties); @@ -350,39 +249,46 @@ static gchar * dbusobject = NULL; static gboolean init_dbus_vars_from_window(Window window) { - DBusGConnection *connection; GError *error; - DBusGProxy *proxy; + GDBusProxy *proxy; error = NULL; - connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - if (connection == NULL) { - g_printerr("Failed to open connection to bus: %s\n", error->message); + + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.ayatana.AppMenu.Registrar", + "/org/ayatana/AppMenu/Registrar", + "org.ayatana.AppMenu.Registrar", + NULL, + &error); + if (error != NULL) { + g_warning("Unable to get registrar proxy: %s", error->message); g_error_free(error); return FALSE; } - proxy = dbus_g_proxy_new_for_name (connection, - "org.ayatana.AppMenu.Registrar", - "/org/ayatana/AppMenu/Registrar", - "org.ayatana.AppMenu.Registrar"); - error = NULL; - if (!dbus_g_proxy_call (proxy, "GetMenuForWindow", &error, - G_TYPE_UINT, window, G_TYPE_INVALID, - G_TYPE_STRING, &dbusname, DBUS_TYPE_G_OBJECT_PATH, &dbusobject, G_TYPE_INVALID)) - { - g_printerr("ERROR: %s\n", error->message); + GVariant * retval; + + retval = g_dbus_proxy_call_sync(proxy, + "GetMenuForWindow", + g_variant_new("u", window), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (error != NULL) { + g_warning("Unable to call 'GetMenuForWindow' on registrar: %s", error->message); g_error_free(error); - g_object_unref(proxy); return FALSE; } - if (!g_strcmp0(dbusobject, "/")) { - return FALSE; - } + g_variant_get(retval, "so", &dbusname, &dbusobject); - g_object_unref (proxy); + g_variant_unref(retval); + g_object_unref(proxy); return TRUE; } -- cgit v1.2.3 From a8b425c5868c73739f60997ebc2013df3b3d6d4b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 13 Jan 2011 09:53:15 -0600 Subject: Ayatana purge --- tools/dbusmenu-bench | 2 +- tools/dbusmenu-dumper.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-bench b/tools/dbusmenu-bench index 4b58da8..dcf5f6f 100755 --- a/tools/dbusmenu-bench +++ b/tools/dbusmenu-bench @@ -35,7 +35,7 @@ from xml.etree import ElementTree as ET import dbus -DBUS_INTERFACE = "org.ayatana.dbusmenu" +DBUS_INTERFACE = "com.canonical.dbusmenu" DBUS_SERVICE = "org.dbusmenu.test" DBUS_PATH = "/MenuBar" diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 4580e4c..bd986e8 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -257,9 +257,9 @@ init_dbus_vars_from_window(Window window) proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, - "org.ayatana.AppMenu.Registrar", - "/org/ayatana/AppMenu/Registrar", - "org.ayatana.AppMenu.Registrar", + "com.canonical.AppMenu.Registrar", + "/com/canonical/AppMenu/Registrar", + "com.canonical.AppMenu.Registrar", NULL, &error); if (error != NULL) { -- cgit v1.2.3