Commits

Ivan Vučica committed 0e39195 Draft

Some additional 'old' experiments (although the code already works as of previous commit).

Comments (0)

Files changed (4)

-CFLAGS=-I/usr/include/libdbusmenu-glib-0.4 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/libindicate-0.7
+CFLAGS=-I/usr/include/libdbusmenu-glib-0.4 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/libindicate-0.7 
 CXXFLAGS=$(CFLAGS)
-all: mini-dbusmenu
+all: mini-dbusmenu test-glib-simple-items
 
 mini-dbusmenu: mini-dbusmenu.o
-	clang -O0 mini-dbusmenu.o -ldbusmenu-glib -lX11 -lindicate -o mini-dbusmenu 
+	clang -O0 mini-dbusmenu.o -ldbusmenu-glib -ldbusmenu-jsonloader -lX11 -lindicate -o mini-dbusmenu 
+
+test-glib-simple-items: test-glib-simple-items.o
+	clang -O0 test-glib-simple-items.o -ldbusmenu-glib -ldbusmenu-jsonloader -lX11 -lindicate -o test-glib-simple-items
 
 #define INDICATE 0 // use libindicate?
 
-#if !INDICATE
 // defines GDBusProxy
 #include <gio/gio.h>
-#endif
 
 // Ordinarily should vary per-app, but we can hardcode
 // something for this example...
 			"/com/canonical/AppMenu/Registrar", // REG_OBJECT
 			"com.canonical.AppMenu.Registrar", // REG_IFACE
 			NULL, NULL);
+	printf("Registering window: %lu with registrar: 0x%08x\n", mdmWin, registrar);
 	GError * error = NULL;
 	g_dbus_proxy_call_sync(
 			registrar, "RegisterWindow",
 	return 0;
 	#endif
 #else
+	const char * MENU_PATH = windowxidpath;
+	const char * REG_OBJECT = "/com/canonical/AppMenu/Registrar";
+	const char * REG_IFACE = "com.canonical.AppMenu.Registrar";	
+	#define GDK_WINDOW_XID(x) mdmWin
 
 	DbusmenuMenuitem * root = dbusmenu_json_build_from_file((const gchar *)user_data);
 	g_return_val_if_fail(root != NULL, FALSE);
 }
 
 
-
-
+static void
+on_registrar_available (GDBusConnection * connection,
+                        const gchar     * name,
+                        const gchar     * name_owner,
+                        gpointer         user_data)
+{
+	idle_func("myapp.json");
+}
+static void
+on_registrar_unavailable (GDBusConnection * connection,
+                        const gchar     * name,
+                        gpointer         user_data)
+{
+	// ...
+}
 
 int main()
 {
 	XMapRaised(display, mdmWin);
 	XSelectInput(display, mdmWin, ButtonPress);
 	XFlush(display);
+	XSync(display, 0);
 	// Start up glib
 	g_type_init();
 
 	dbusmenu_menuitem_property_set(root, DBUSMENU_MENUITEM_PROP_LABEL, ("The Menu"));
 	dbusmenu_menuitem_child_append(base_root, root);
 
-
-
 	DbusmenuMenuitem * mi = dbusmenu_menuitem_new();
 	dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, ("Compose New Message, NOW"));
 //	g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(command_item_activate), EVO_COMPOSE_CMD);
 	dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, ("Contacts, NOW"));
 //	g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(command_item_activate), EVO_CONTACTS_CMD);
 	dbusmenu_menuitem_child_append(root, mi);
+	
 
 	dbusmenu_server_set_root(menu_server, base_root);
 #if INDICATE
 
 	// Add X11 events into the event loop
 	//http://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkeventsource.c
+#if 0
 	GSource *gsource = g_source_new(&event_funcs, sizeof(MdmEventSource));
 	MdmEventSource * source = (MdmEventSource*)gsource;
 	char *name = g_strdup_printf("MDM X11 Event source (%p)", display);
 
 	g_source_set_can_recurse(gsource, TRUE); // needed?
 	g_source_attach(gsource, NULL);
+#endif
 
-	g_idle_add(idle_func, NULL);
+#if 0
+	g_idle_add(idle_func, "myapp.json");
+#else
 
+				g_bus_watch_name (G_BUS_TYPE_SESSION,
+                                      "com.canonical.AppMenu.Registrar",
+                                      G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                      on_registrar_available,
+                                      on_registrar_unavailable,
+                                      NULL, //helper,
+                                      NULL);
+
+#endif
 	g_main_loop_run(mainloop);
 
 	return 0;
+{
+  "id": 0,
+  "children-display": 'submenu',
+  "submenu": [
+      {
+        "id": 2,
+        "label": 'Compose New Message, NOW'
+      },
+      {
+        "id": 3,
+        "label": 'Contacts, NOW'
+      }
+  ]
+}

test-glib-simple-items.c

+// http://bazaar.launchpad.net/~dbusmenu-team/dbusmenu/trunk.0.6/view/head:/tests/test-glib-simple-items.c
+
+#include <libdbusmenu-glib/server.h>
+#include <libdbusmenu-glib/menuitem.h>
+
+static DbusmenuMenuitem * root_menuitem = NULL;
+static GMainLoop * mainloop = NULL;
+
+gchar * dummies[] = {
+	"Bob", "Jim", "Alvin", "Mary", NULL
+};
+
+static void
+dummy_users (DbusmenuMenuitem * root) {
+	int count;
+	for (count = 0; dummies[count] != NULL; count++) {
+		DbusmenuMenuitem * mi = dbusmenu_menuitem_new();
+		g_debug("Creating item: %d %s", dbusmenu_menuitem_get_id(mi), dummies[count]);
+		g_debug("\tRoot ID: %d", dbusmenu_menuitem_get_id(root));
+		dbusmenu_menuitem_property_set(mi, "label", dummies[count]);
+		dbusmenu_menuitem_child_add_position(root, mi, count);
+	}
+
+	return;
+}
+
+static gboolean
+quititall (gpointer data)
+{
+	g_main_quit(mainloop);
+	return FALSE;
+}
+
+int
+main (int argc, char ** argv)
+{
+    g_type_init();
+
+    DbusmenuServer * server = dbusmenu_server_new("/test/object");
+    root_menuitem = dbusmenu_menuitem_new();
+    dbusmenu_server_set_root(server, root_menuitem);
+	g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem));
+
+	dummy_users(root_menuitem);
+
+	g_timeout_add_seconds(1, quititall, NULL);
+
+    mainloop = g_main_loop_new(NULL, FALSE);
+    g_main_loop_run(mainloop);
+
+    return 0;
+}