~dbusmenu-team/libdbusmenu/trunk.16.10

« back to all changes in this revision

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

  • Committer: Ted Gould
  • Date: 2009-05-12 16:23:10 UTC
  • mfrom: (1.1.85 work)
  • Revision ID: ted@canonical.com-20090512162310-wz9hm3sks368ry8j
Merging in my working branch that brings in basic object functionality passing across DBus.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
A test for libdbusmenu to ensure its quality.
 
3
 
 
4
Copyright 2009 Canonical Ltd.
 
5
 
 
6
Authors:
 
7
    Ted Gould <ted@canonical.com>
 
8
 
 
9
This program is free software: you can redistribute it and/or modify it 
 
10
under the terms of the GNU General Public License version 3, as published 
 
11
by the Free Software Foundation.
 
12
 
 
13
This program is distributed in the hope that it will be useful, but 
 
14
WITHOUT ANY WARRANTY; without even the implied warranties of 
 
15
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
16
PURPOSE.  See the GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License along 
 
19
with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include <glib.h>
 
23
 
 
24
#include <dbus/dbus.h>
 
25
#include <dbus/dbus-glib.h>
 
26
#include <dbus/dbus-glib-lowlevel.h>
 
27
 
 
28
#include <libdbusmenu-glib/server.h>
 
29
#include <libdbusmenu-glib/menuitem.h>
 
30
 
 
31
#include "test-glib-layout.h"
 
32
 
 
33
 
 
34
static DbusmenuMenuitem *
 
35
layout2menuitem (layout_t * layout)
 
36
{
 
37
        if (layout == NULL || layout->id == 0) return NULL;
 
38
 
 
39
        DbusmenuMenuitem * local = dbusmenu_menuitem_new_with_id(layout->id);
 
40
        
 
41
        if (layout->submenu != NULL) {
 
42
                guint count;
 
43
                for (count = 0; layout->submenu[count].id != 0; count++) {
 
44
                        DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]);
 
45
                        if (child != NULL) {
 
46
                                dbusmenu_menuitem_child_append(local, child);
 
47
                        }
 
48
                }
 
49
        }
 
50
 
 
51
        g_debug("Layout to menu return: 0x%X", (unsigned int)local);
 
52
        return local;
 
53
}
 
54
 
 
55
static guint layouton = 0;
 
56
static DbusmenuServer * server = NULL;
 
57
static GMainLoop * mainloop = NULL;
 
58
 
 
59
static gboolean
 
60
timer_func (gpointer data)
 
61
{
 
62
        if (layouts[layouton].id == 0) {
 
63
                g_main_loop_quit(mainloop);
 
64
                return FALSE;
 
65
        }
 
66
        g_debug("Updating to Layout %d", layouton);
 
67
 
 
68
        dbusmenu_server_set_root(server, layout2menuitem(&layouts[layouton]));
 
69
        layouton++;
 
70
 
 
71
        return TRUE;
 
72
}
 
73
 
 
74
int
 
75
main (int argc, char ** argv)
 
76
{
 
77
        g_type_init();
 
78
 
 
79
        g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
 
80
 
 
81
        server = dbusmenu_server_new("/org/test");
 
82
 
 
83
        timer_func(NULL);
 
84
        g_timeout_add(2500, timer_func, NULL);
 
85
 
 
86
        mainloop = g_main_loop_new(NULL, FALSE);
 
87
        g_main_loop_run(mainloop);
 
88
 
 
89
        g_debug("Quiting");
 
90
 
 
91
        return 0;
 
92
}