aboutsummaryrefslogtreecommitdiff
path: root/tests/test-approver.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-07-09 20:44:07 -0500
committerTed Gould <ted@gould.cx>2010-07-09 20:44:07 -0500
commitfd3e18e471823583a29e673a639b9b14295b4a4c (patch)
treefe51f3bb7326e944b51347a7369f74d7aa14f368 /tests/test-approver.c
parent8072a97d30c0e3aaa9f02b89f53ae9af247e473b (diff)
downloadlibayatana-appindicator-fd3e18e471823583a29e673a639b9b14295b4a4c.tar.gz
libayatana-appindicator-fd3e18e471823583a29e673a639b9b14295b4a4c.tar.bz2
libayatana-appindicator-fd3e18e471823583a29e673a639b9b14295b4a4c.zip
Okay, so now we're detecing when the watcher comes up, and registering ourselves as the approver.
Diffstat (limited to 'tests/test-approver.c')
-rw-r--r--tests/test-approver.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/tests/test-approver.c b/tests/test-approver.c
index f411b0d..c51e1cb 100644
--- a/tests/test-approver.c
+++ b/tests/test-approver.c
@@ -1,6 +1,11 @@
#include <glib.h>
#include <glib-object.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include "notification-watcher-client.h"
+#include "dbus-shared.h"
+
#define APPROVER_PATH "/my/approver"
#define TEST_APPROVER_TYPE (test_approver_get_type ())
@@ -29,6 +34,10 @@ static void _notification_approver_server_approve_item (void);
#include "../src/notification-approver-server.h"
+GMainLoop * main_loop = NULL;
+DBusGConnection * session_bus = NULL;
+DBusGProxy * bus_proxy = NULL;
+
G_DEFINE_TYPE (TestApprover, test_approver, G_TYPE_OBJECT);
static void
@@ -43,8 +52,6 @@ test_approver_class_init (TestApproverClass *klass)
static void
test_approver_init (TestApprover *self)
{
- DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
-
dbus_g_connection_register_g_object(session_bus,
APPROVER_PATH,
G_OBJECT(self));
@@ -58,14 +65,48 @@ _notification_approver_server_approve_item (void)
return;
}
+gint owner_count = 0;
+gboolean
+check_for_service (gpointer user_data)
+{
+ if (owner_count > 100) {
+ g_main_loop_quit(main_loop);
+ return FALSE;
+ }
+
+ owner_count++;
+
+ gboolean has_owner = FALSE;
+ org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL);
+
+ if (has_owner) {
+ const char * cats = NULL;
+ DBusGProxy * proxy = dbus_g_proxy_new_for_name(session_bus,
+ NOTIFICATION_WATCHER_DBUS_ADDR,
+ NOTIFICATION_WATCHER_DBUS_OBJ,
+ NOTIFICATION_WATCHER_DBUS_IFACE);
+
+ org_kde_StatusNotifierWatcher_register_notification_approver (proxy, APPROVER_PATH, &cats, NULL);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
int
main (int argc, char ** argv)
{
g_type_init();
+ session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+
TestApprover * approver = g_object_new(TEST_APPROVER_TYPE, NULL);
- GMainLoop * main_loop = g_main_loop_new(NULL, FALSE);
+ bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+
+ g_timeout_add(100, check_for_service, NULL);
+
+ main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(main_loop);
g_object_unref(approver);