aboutsummaryrefslogtreecommitdiff
path: root/src/menu-dbus.c
blob: cb4d531e691ee38832c19f3dd94cfe22ae4816d4 (plain)
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

#include "menu-dbus.h"

GtkWidget *
_dbus_menu_make_menuitem_val (DBusGProxy * proxy, guint id)
{



}

GtkWidget *
_dbus_menu_make_menuitem_recurse (DBusGProxy * proxy, guint id)
{
	GError * error = NULL;
	GArray * items = NULL;
	gboolean proxyret;

	/* TODO: switch to begin_call */
	proxyret = dbus_g_proxy_call (proxy, "GetSubmenuItems", &error,
	                              G_TYPE_UINT, id,
	                              G_TYPE_INVALID,
	                              DBUS_TYPE_G_UINT_ARRAY, &items,
	                              G_TYPE_INVALID);

	if (!proxyret) {
		/* TODO: clear error */
		return NULL;
	}

	GtkWidget * menu = gtk_menu_new();
	gint i;
	for (i = 0; i < items->len; i++) {
		guint id = g_array_index(items, guint, i);
		GtkWidget * item = _dbus_menu_make_menuitem_val(proxy, id);
		if (item != NULL) {
			gtk_menu_append(menu, item);
			gtk_widget_show(item);
		}
	}

	return menu;
}

GtkWidget *
dbus_menu_make_menuitem (DBusGConnection * bus, const char * name, const char * object, guint menu_id)
{
	DBusGProxy * iface = dbus_g_proxy_new_for_name_owner (bus, name, object, "com.canonical.menu", NULL);
	if (iface == NULL) {
		return NULL;
	}

	return _dbus_menu_make_menuitem_recurse(iface, menu_id);
}