From 2b1220bd8455a79ff0f3da340cf9337c159d1720 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 10:07:09 -0400 Subject: Making a tools directory --- tools/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tools/Makefile.am (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..7299564 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,3 @@ + +# Stuff will go here. + -- cgit v1.2.3 From 3f56fb5dd3989a6926d6285345df8d71f9053924 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 10:12:45 -0400 Subject: A stub dbusmenu dumper --- tools/Makefile.am | 13 ++++++++++++- tools/dbusmenu-dumper.c | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tools/dbusmenu-dumper.c (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am index 7299564..415050f 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,3 +1,14 @@ -# Stuff will go here. +libexec_PROGRAMS = dbusmenu-dumper + +dbusmenu_dumper_SOURCES = \ + dbusmenu-dumper.c + +dbusmenu_dumper_CFLAGS = \ + -I $(srcdir)/.. \ + $(DBUSMENUGLIB_CFLAGS) -Wall -Werror + +dbusmenu_dumper_LDADD = \ + ../libdbusmenu-glib/libdbusmenu-glib.la \ + $(DBUSMENUGLIB_LIBS) diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c new file mode 100644 index 0000000..0382609 --- /dev/null +++ b/tools/dbusmenu-dumper.c @@ -0,0 +1,8 @@ + +int +main (int argc, char ** argv) +{ + + return 0; +} + -- cgit v1.2.3 From 15658f9f9026a02a87d251aa0128df8ce382ddb9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 14:18:46 -0400 Subject: Headers. --- tools/dbusmenu-dumper.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 0382609..0277fd0 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -1,3 +1,32 @@ +/* +A small tool to grab the dbusmenu structure that a program is +exporting. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include + +#include +#include + + + int main (int argc, char ** argv) -- cgit v1.2.3 From 16e4975a08b5c1024cb974d0785e51eca3c0ab48 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 14:41:33 -0400 Subject: Adding preferences for the dbus stuff. --- tools/dbusmenu-dumper.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 0277fd0..753c682 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -25,12 +25,53 @@ with this program. If not, see . #include #include +static gchar * dbusname = NULL; +static gchar * dbusobject = NULL; +static gboolean +option_dbusname (const gchar * arg, const gchar * value, gpointer data, GError ** error) +{ + if (dbusname != NULL) { + g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "DBus name already set to '%s' can't reset it to '%s'.", dbusname, value); + return FALSE; + } + + dbusname = g_strdup(value); + return TRUE; +} + +static gboolean +option_dbusobject (const gchar * arg, const gchar * value, gpointer data, GError ** error) +{ + if (dbusobject != NULL) { + g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "DBus name already set to '%s' can't reset it to '%s'.", dbusobject, value); + return FALSE; + } + dbusobject = g_strdup(value); + return TRUE; +} + +static GOptionEntry general_options[] = { + {"dbus-name", 'd', 0, G_OPTION_ARG_CALLBACK, option_dbusname, "The name of the program to connect to (i.e. org.test.bob", "dbusname"}, + {"dbus-object", 'o', 0, G_OPTION_ARG_CALLBACK, option_dbusobject, "The path to the Dbus object (i.e /org/test/bob/alvin)", "dbusobject"} +}; int main (int argc, char ** argv) { + GError * error = NULL; + GOptionContext * context; + + context = g_option_context_new("- Grab the entires in a DBus Menu"); + + g_option_context_add_main_entries(context, general_options, "dbusmenu-dumper"); + + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("option parsing failed: %s\n", error->message); + g_error_free(error); + return 1; + } return 0; } -- cgit v1.2.3 From 0eda58a6e59f479c788e05cc781b2a178d6ff8c0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 14:45:47 -0400 Subject: Checking the dbusname and object to ensure that we get them. --- tools/dbusmenu-dumper.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 753c682..ed3b4b3 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -52,6 +52,13 @@ option_dbusobject (const gchar * arg, const gchar * value, gpointer data, GError return TRUE; } +void +usage (void) +{ + g_print("dbusmenu-dumper --dbus-name= --dbus-object=\n"); + return; +} + static GOptionEntry general_options[] = { {"dbus-name", 'd', 0, G_OPTION_ARG_CALLBACK, option_dbusname, "The name of the program to connect to (i.e. org.test.bob", "dbusname"}, {"dbus-object", 'o', 0, G_OPTION_ARG_CALLBACK, option_dbusobject, "The path to the Dbus object (i.e /org/test/bob/alvin)", "dbusobject"} @@ -73,6 +80,18 @@ main (int argc, char ** argv) return 1; } + if (dbusname == NULL) { + g_print("ERROR: dbus-name not specified\n"); + usage(); + return 1; + } + + if (dbusobject == NULL) { + g_print("ERROR: dbus-object not specified\n"); + usage(); + return 1; + } + return 0; } -- cgit v1.2.3 From 8f0b3d1a97d235c9da9601a00222e5b51be3738b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 18:21:35 -0400 Subject: Getting the client and the root item --- tools/dbusmenu-dumper.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index ed3b4b3..9768b7d 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -92,6 +92,22 @@ main (int argc, char ** argv) return 1; } + DbusmenuClient * client = dbusmenu_client_new (dbusname, dbusobject); + if (client == NULL) { + g_print("ERROR: Unable to create Dbusmenu Client\n"); + return 1; + } + + DbusmenuMenuitem * root = dbusmenu_client_get_root(client); + if (root == NULL) { + g_print("ERROR: Unable to create Dbusmenu Root\n"); + return 1; + } + + g_print("{\n"); + + g_print("}\n"); + return 0; } -- cgit v1.2.3 From e3136699a6d00c24715326e2c9016f8b04425860 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 18:26:01 -0400 Subject: Making all of the error printouts actually go to STD ERR --- tools/dbusmenu-dumper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 9768b7d..a4075f1 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -55,7 +55,7 @@ option_dbusobject (const gchar * arg, const gchar * value, gpointer data, GError void usage (void) { - g_print("dbusmenu-dumper --dbus-name= --dbus-object=\n"); + g_printerr("dbusmenu-dumper --dbus-name= --dbus-object=\n"); return; } @@ -75,32 +75,32 @@ main (int argc, char ** argv) g_option_context_add_main_entries(context, general_options, "dbusmenu-dumper"); if (!g_option_context_parse(context, &argc, &argv, &error)) { - g_print("option parsing failed: %s\n", error->message); + g_printerr("option parsing failed: %s\n", error->message); g_error_free(error); return 1; } if (dbusname == NULL) { - g_print("ERROR: dbus-name not specified\n"); + g_printerr("ERROR: dbus-name not specified\n"); usage(); return 1; } if (dbusobject == NULL) { - g_print("ERROR: dbus-object not specified\n"); + g_printerr("ERROR: dbus-object not specified\n"); usage(); return 1; } DbusmenuClient * client = dbusmenu_client_new (dbusname, dbusobject); if (client == NULL) { - g_print("ERROR: Unable to create Dbusmenu Client\n"); + g_printerr("ERROR: Unable to create Dbusmenu Client\n"); return 1; } DbusmenuMenuitem * root = dbusmenu_client_get_root(client); if (root == NULL) { - g_print("ERROR: Unable to create Dbusmenu Root\n"); + g_printerr("ERROR: Unable to create Dbusmenu Root\n"); return 1; } -- cgit v1.2.3 From 3a5abcd25eee470e2c6b1fb8a29a6fff510f231e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 18:36:42 -0400 Subject: Watching for the root changing and then using that to start profiling the dbusmenu --- tools/dbusmenu-dumper.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index a4075f1..b0790c3 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -25,6 +25,27 @@ with this program. If not, see . #include #include +static GMainLoop * mainloop = NULL; + +static void +new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) +{ + if (newroot == NULL) { + g_printerr("ERROR: Unable to create Dbusmenu Root\n"); + g_main_loop_quit(mainloop); + return; + } + + g_print("{\n"); + + g_print("}\n"); + + + + return; +} + + static gchar * dbusname = NULL; static gchar * dbusobject = NULL; @@ -98,15 +119,10 @@ main (int argc, char ** argv) return 1; } - DbusmenuMenuitem * root = dbusmenu_client_get_root(client); - if (root == NULL) { - g_printerr("ERROR: Unable to create Dbusmenu Root\n"); - return 1; - } - - g_print("{\n"); + g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(new_root_cb), NULL); - g_print("}\n"); + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); return 0; } -- cgit v1.2.3 From 2fc8aa2cd7049bd3159af5f419e87b72a1ca8231 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 21:53:50 -0400 Subject: Fleshing out printing a menu item. --- tools/dbusmenu-dumper.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index b0790c3..740398e 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -27,6 +27,39 @@ with this program. If not, see . static GMainLoop * mainloop = NULL; +static void +print_menuitem (DbusmenuMenuitem * item, int depth) +{ + gchar * space = g_strnfill(depth, ' '); + g_print("%s\"id\": %d", space, dbusmenu_menuitem_get_id(item)); + + GList * properties = dbusmenu_menuitem_properties_list(item); + GList * property; + for (property = properties; property != NULL; property = g_list_next(property)) { + g_print("\n%s\"%s\": %s", space, (gchar *)property->data, dbusmenu_menuitem_property_get(item, (gchar *)property->data)); + } + g_list_free(properties); + + GList * children = dbusmenu_menuitem_get_children(item); + if (children != NULL) { + gchar * childspace = g_strnfill(depth + 4, ' '); + g_print("\n%s\"submenu\": [\n%s{", space, childspace); + GList * child; + for (child = children; child != NULL; child = g_list_next(child)) { + print_menuitem(DBUSMENU_MENUITEM(child->data), depth + 4 + 2); + if (child->next != NULL) { + g_print("\n%s},\n%s{", childspace, childspace); + } + } + g_print("\n%s}\n%s]", childspace, space); + g_free(childspace); + } + + g_free(space); + + return; +} + static void new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) { @@ -37,11 +70,9 @@ new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) } g_print("{\n"); - + print_menuitem(newroot, 2); g_print("}\n"); - - return; } -- cgit v1.2.3 From b66fdf661dc9a14d3e842f045062a8f4937642c3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 21:55:39 -0400 Subject: Forgot to init the type stuff. --- tools/dbusmenu-dumper.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 740398e..25b9047 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -119,6 +119,7 @@ static GOptionEntry general_options[] = { int main (int argc, char ** argv) { + g_type_init(); GError * error = NULL; GOptionContext * context; -- cgit v1.2.3 From 6a4bff121edff594b2e8a458fe0ae681ee23efbe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 22:01:45 -0400 Subject: Adding some more carriage returns. --- tools/dbusmenu-dumper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 25b9047..9d0d420 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -43,12 +43,12 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * children = dbusmenu_menuitem_get_children(item); if (children != NULL) { gchar * childspace = g_strnfill(depth + 4, ' '); - g_print("\n%s\"submenu\": [\n%s{", space, childspace); + g_print("\n%s\"submenu\": [\n%s{\n", space, childspace); GList * child; for (child = children; child != NULL; child = g_list_next(child)) { print_menuitem(DBUSMENU_MENUITEM(child->data), depth + 4 + 2); if (child->next != NULL) { - g_print("\n%s},\n%s{", childspace, childspace); + g_print("\n%s},\n%s{\n", childspace, childspace); } } g_print("\n%s}\n%s]", childspace, space); @@ -71,8 +71,9 @@ new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) g_print("{\n"); print_menuitem(newroot, 2); - g_print("}\n"); + g_print("\n}\n"); + g_main_quit(mainloop); return; } -- cgit v1.2.3 From 6d6d74a630bc7212b506089d4b0cf8f6d6d9ec60 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 22:18:28 -0400 Subject: Putting a couple second timeout in to make sure we get all the properties. --- tools/dbusmenu-dumper.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 9d0d420..3cff162 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -60,6 +60,19 @@ print_menuitem (DbusmenuMenuitem * item, int depth) return; } +static gboolean +root_timeout (gpointer data) +{ + DbusmenuMenuitem * newroot = DBUSMENU_MENUITEM(data); + + g_print("{\n"); + print_menuitem(newroot, 2); + g_print("\n}\n"); + + g_main_quit(mainloop); + return FALSE; +} + static void new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) { @@ -69,11 +82,7 @@ new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) return; } - g_print("{\n"); - print_menuitem(newroot, 2); - g_print("\n}\n"); - - g_main_quit(mainloop); + g_timeout_add_seconds(2, root_timeout, newroot); return; } -- cgit v1.2.3 From 43d3d3a1ad4338110116e9312800a030c7f1606f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 22:20:17 -0400 Subject: Adding quotes around the values of properties. --- tools/dbusmenu-dumper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 3cff162..74c992d 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -36,7 +36,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * properties = dbusmenu_menuitem_properties_list(item); GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { - g_print("\n%s\"%s\": %s", space, (gchar *)property->data, dbusmenu_menuitem_property_get(item, (gchar *)property->data)); + g_print("\n%s\"%s\": \"%s\"", space, (gchar *)property->data, dbusmenu_menuitem_property_get(item, (gchar *)property->data)); } g_list_free(properties); -- cgit v1.2.3 From b2a5f6ab7a6672a02722beb40fd5e4484e68c780 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 5 Oct 2009 22:28:14 -0400 Subject: Putting commas on the properties. --- tools/dbusmenu-dumper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 74c992d..5704311 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -36,14 +36,14 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * properties = dbusmenu_menuitem_properties_list(item); GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { - g_print("\n%s\"%s\": \"%s\"", space, (gchar *)property->data, dbusmenu_menuitem_property_get(item, (gchar *)property->data)); + g_print(",\n%s\"%s\": \"%s\"", space, (gchar *)property->data, dbusmenu_menuitem_property_get(item, (gchar *)property->data)); } g_list_free(properties); GList * children = dbusmenu_menuitem_get_children(item); if (children != NULL) { gchar * childspace = g_strnfill(depth + 4, ' '); - g_print("\n%s\"submenu\": [\n%s{\n", space, childspace); + g_print(",\n%s\"submenu\": [\n%s{\n", space, childspace); GList * child; for (child = children; child != NULL; child = g_list_next(child)) { print_menuitem(DBUSMENU_MENUITEM(child->data), depth + 4 + 2); -- cgit v1.2.3