~dbusmenu-team/libdbusmenu/trunk.16.10

« back to all changes in this revision

Viewing changes to tests/test-glib-properties-server.c

Merging in the properties branch to provide some basis to work with.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <glib.h>
 
2
 
 
3
#include <dbus/dbus.h>
 
4
#include <dbus/dbus-glib.h>
 
5
#include <dbus/dbus-glib-lowlevel.h>
 
6
 
 
7
#include <libdbusmenu-glib/menuitem.h>
 
8
#include <libdbusmenu-glib/server.h>
 
9
 
 
10
#include "test-glib-properties.h"
 
11
 
 
12
static void
 
13
set_props (DbusmenuMenuitem * mi, gchar ** props)
 
14
{
 
15
        if (props == NULL) return;
 
16
 
 
17
        guint i;
 
18
        for (i = 0; props[i] != NULL; i += 2) {
 
19
                dbusmenu_menuitem_property_set(mi, props[i], props[i+1]);
 
20
        }
 
21
 
 
22
        return;
 
23
}
 
24
 
 
25
static DbusmenuMenuitem *
 
26
layout2menuitem (proplayout_t * layout)
 
27
{
 
28
        if (layout == NULL || layout->id == 0) return NULL;
 
29
 
 
30
        DbusmenuMenuitem * local = dbusmenu_menuitem_new_with_id(layout->id);
 
31
        set_props(local, layout->properties);
 
32
        
 
33
        if (layout->submenu != NULL) {
 
34
                guint count;
 
35
                for (count = 0; layout->submenu[count].id != 0; count++) {
 
36
                        DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]);
 
37
                        if (child != NULL) {
 
38
                                dbusmenu_menuitem_child_append(local, child);
 
39
                        }
 
40
                }
 
41
        }
 
42
 
 
43
        g_debug("Layout to menu return: 0x%X", (unsigned int)local);
 
44
        return local;
 
45
}
 
46
 
 
47
static guint layouton = 0;
 
48
static DbusmenuServer * server = NULL;
 
49
static GMainLoop * mainloop = NULL;
 
50
 
 
51
static gboolean
 
52
timer_func (gpointer data)
 
53
{
 
54
        if (layouts[layouton].id == 0) {
 
55
                g_main_loop_quit(mainloop);
 
56
                return FALSE;
 
57
        }
 
58
        g_debug("Updating to Layout %d", layouton);
 
59
 
 
60
        dbusmenu_server_set_root(server, layout2menuitem(&layouts[layouton]));
 
61
        layouton++;
 
62
 
 
63
        return TRUE;
 
64
}
 
65
 
 
66
int
 
67
main (int argc, char ** argv)
 
68
{
 
69
        g_type_init();
 
70
 
 
71
        g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
 
72
 
 
73
        server = dbusmenu_server_new("/org/test");
 
74
 
 
75
        timer_func(NULL);
 
76
        g_timeout_add(2500, timer_func, NULL);
 
77
 
 
78
        mainloop = g_main_loop_new(NULL, FALSE);
 
79
        g_main_loop_run(mainloop);
 
80
 
 
81
        g_debug("Quiting");
 
82
 
 
83
        return 0;
 
84
}
 
85