1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
A small tool to grab the dbusmenu structure that a program is
exporting.
Copyright 2009 Canonical Ltd.
Authors:
Ted Gould <ted@canonical.com>
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 <http://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include <libdbusmenu-glib/client.h>
#include <libdbusmenu-glib/menuitem.h>
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;
}
void
usage (void)
{
g_print("dbusmenu-dumper --dbus-name=<name> --dbus-object=<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"}
};
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;
}
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;
}
|