From d5c42deb18871b62b28db9b10c0dd0a64f23dcd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 18 Dec 2012 20:08:50 +0100 Subject: Indicator-application: removing the deprecated approver support --- .bzrignore | 4 - src/Makefile.am | 7 +- src/application-service-appstore.c | 324 +------------------------------------ src/application-service-appstore.h | 3 - src/application-service-watcher.c | 16 -- src/dbus-shared.h | 3 - src/notification-approver.xml | 29 ---- src/notification-watcher.xml | 7 - tests/Makefile.am | 35 +--- tests/test-approver.c | 254 ----------------------------- 10 files changed, 5 insertions(+), 677 deletions(-) delete mode 100644 src/notification-approver.xml delete mode 100644 tests/test-approver.c diff --git a/.bzrignore b/.bzrignore index 1290cba..f73cbd7 100644 --- a/.bzrignore +++ b/.bzrignore @@ -104,13 +104,9 @@ docs/reference/libappindicator-decl.txt.bak docs/reference/libappindicator-decl-list.txt.bak src/AppIndicator-0.1.vapi bindings/mono/policy.appindicator-sharp.dll -src/notification-approver-client.h -src/notification-approver-server.h tests/test-approver tests/test-approver-tester bindings/mono/policy.0.0.appindicator-sharp.config bindings/mono/policy.0.0.appindicator-sharp.dll src/libapplication_la-generate-id.lo src/libappindicator_la-generate-id.lo -gen-notification-approver.xml.c -gen-notification-approver.xml.h diff --git a/src/Makefile.am b/src/Makefile.am index 1d8875e..7deb087 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -73,8 +73,7 @@ glib_marshal_prefix = _application_service_marshal ################################## GDBUS_SPECS = \ - application-service.xml \ - notification-approver.xml + application-service.xml DBUS_SPECS = \ notification-watcher.xml @@ -107,9 +106,7 @@ BUILT_SOURCES += \ $(DBUS_SPECS:.xml=-client.h) \ $(DBUS_SPECS:.xml=-server.h) \ gen-application-service.xml.c \ - gen-application-service.xml.h \ - gen-notification-approver.xml.c \ - gen-notification-approver.xml.h + gen-application-service.xml.h CLEANFILES += $(BUILT_SOURCES) diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 2663003..596c0f3 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -69,7 +69,6 @@ struct _ApplicationServiceAppstorePrivate { GDBusConnection * bus; guint dbus_registration; GList * applications; - GList * approvers; GHashTable * ordering_overrides; }; @@ -80,14 +79,6 @@ typedef enum { #define STATE2STRING(x) ((x) == VISIBLE_STATE_HIDDEN ? "hidden" : "visible") -typedef struct _Approver Approver; -struct _Approver { - ApplicationServiceAppstore * appstore; /* not ref'd */ - GCancellable * proxy_cancel; - GDBusProxy * proxy; - guint name_watcher; -}; - typedef struct _Application Application; struct _Application { gchar * id; @@ -113,8 +104,6 @@ struct _Application { gchar * title; gboolean currently_free; guint ordering_index; - GList * approver_cancels; - GList * approved_by; visible_state_t visible_state; guint name_watcher; }; @@ -141,16 +130,11 @@ static void load_override_file (GHashTable * hash, const gchar * filename); static AppIndicatorStatus string_to_status(const gchar * status_string); static void apply_status (Application * app); static AppIndicatorCategory string_to_cat(const gchar * cat_string); -static void approver_free (gpointer papprover, gpointer user_data); -static void check_with_new_approver (gpointer papp, gpointer papprove); -static void check_with_old_approver (gpointer papprove, gpointer papp); static Application * find_application (ApplicationServiceAppstore * appstore, const gchar * address, const gchar * object); static Application * find_application_by_menu (ApplicationServiceAppstore * appstore, const gchar * address, const gchar * menuobject); static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data); static void dbus_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); static void app_receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); -static void approver_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); -static void approver_receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); static void get_all_properties (Application * app); static void application_free (Application * app); @@ -195,7 +179,6 @@ application_service_appstore_init (ApplicationServiceAppstore *self) ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE (self); priv->applications = NULL; - priv->approvers = NULL; priv->bus_cancel = NULL; priv->dbus_registration = 0; @@ -343,12 +326,6 @@ application_service_appstore_dispose (GObject *object) ((Application *)priv->applications->data)->dbus_object); } - if (priv->approvers != NULL) { - g_list_foreach(priv->approvers, approver_free, object); - g_list_free(priv->approvers); - priv->approvers = NULL; - } - if (priv->dbus_registration != 0) { g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration); /* Don't care if it fails, there's nothing we can do */ @@ -605,8 +582,6 @@ got_all_properties (GObject * source_object, GAsyncResult * res, app->title = g_strdup(""); } - g_list_foreach(priv->approvers, check_with_old_approver, app); - apply_status(app); if (app->queued_props) { @@ -648,15 +623,6 @@ get_all_properties (Application * app) } } -/* Check the application against an approver */ -static void -check_with_old_approver (gpointer papprove, gpointer papp) -{ - /* Funny the parallels, eh? */ - check_with_new_approver(papp, papprove); - return; -} - /* Simple translation function -- could be optimized */ static AppIndicatorStatus string_to_status(const gchar * status_string) @@ -812,14 +778,6 @@ application_free (Application * app) if (app->title != NULL) { g_free(app->title); } - if (app->approver_cancels != NULL) { - g_list_foreach(app->approver_cancels, (GFunc)g_cancellable_cancel, NULL); - g_list_foreach(app->approver_cancels, (GFunc)g_object_unref, NULL); - g_list_free(app->approver_cancels); - } - if (app->approved_by != NULL) { - g_list_free(app->approved_by); - } g_free(app); return; @@ -883,14 +841,12 @@ static void apply_status (Application * app) { ApplicationServiceAppstore * appstore = app->appstore; - ApplicationServiceAppstorePrivate * priv = appstore->priv; - /* g_debug("Applying status. Status: %d Approved by: %d Approvers: %d Visible: %d", app->status, g_list_length(app->approved_by), g_list_length(priv->approvers), app->visible_state); */ + /* g_debug("Applying status. Status: %d Visible: %d", app->status, app->visible_state); */ visible_state_t goal_state = VISIBLE_STATE_HIDDEN; - if (app->status != APP_INDICATOR_STATUS_PASSIVE && - g_list_length(app->approved_by) >= g_list_length(priv->approvers)) { + if (app->status != APP_INDICATOR_STATUS_PASSIVE) { goal_state = VISIBLE_STATE_SHOWN; } @@ -1073,8 +1029,6 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst app->title = NULL; app->currently_free = FALSE; app->ordering_index = 0; - app->approver_cancels = NULL; - app->approved_by = NULL; app->visible_state = VISIBLE_STATE_HIDDEN; app->name_watcher = 0; app->props_cancel = NULL; @@ -1390,277 +1344,3 @@ get_applications (ApplicationServiceAppstore * appstore) return NULL; } } - -/* Removes and approver from our list of approvers and - then sees if that changes our status. Most likely this - could make us visible if this approver rejected us. */ -static void -remove_approver (gpointer papp, gpointer pproxy) -{ - Application * app = (Application *)papp; - - /* Check for any pending approvals and cancel them */ - GList * iter = app->approver_cancels; - while (iter != NULL) { - GCancellable * cancel = (GCancellable *)iter->data; - GDBusProxy * proxy = (GDBusProxy *)g_object_get_data(G_OBJECT(cancel), "proxy"); - if (proxy == pproxy) { - g_cancellable_cancel(cancel); - g_object_unref(cancel); - - GList * next = iter->next; - app->approver_cancels = g_list_delete_link(app->approver_cancels, iter); - iter = next; - } else { - iter = iter->next; - } - } - - app->approved_by = g_list_remove(app->approved_by, pproxy); - apply_status(app); - return; -} - -/* Frees the data associated with an approver */ -static void -approver_free (gpointer papprover, gpointer user_data) -{ - Approver * approver = (Approver *)papprover; - g_return_if_fail(approver != NULL); - - ApplicationServiceAppstore * appstore = APPLICATION_SERVICE_APPSTORE(user_data); - g_list_foreach(appstore->priv->applications, remove_approver, approver->proxy); - - if (approver->name_watcher != 0) { - g_dbus_connection_signal_unsubscribe(g_dbus_proxy_get_connection(approver->proxy), approver->name_watcher); - approver->name_watcher = 0; - } - - if (approver->proxy != NULL) { - g_object_unref(approver->proxy); - approver->proxy = NULL; - } - - if (approver->proxy_cancel != NULL) { - g_cancellable_cancel(approver->proxy_cancel); - g_object_unref(approver->proxy_cancel); - approver->proxy_cancel = NULL; - } - - g_free(approver); - return; -} - -/* What did the approver tell us? */ -static void -approver_request_cb (GObject *object, GAsyncResult *res, gpointer user_data) -{ - GDBusProxy * proxy = G_DBUS_PROXY(object); - GCancellable * cancel = (GCancellable *)user_data; - GError * error = NULL; - gboolean approved = TRUE; /* default to approved */ - GVariant * result; - - result = g_dbus_proxy_call_finish(proxy, res, &error); - - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - g_error_free (error); - return; // Must exit before accessing freed memory - } - - Application * app = (Application *)g_object_get_data(G_OBJECT(cancel), "app"); - app->approver_cancels = g_list_remove(app->approver_cancels, cancel); - g_object_unref(cancel); - - if (error == NULL) { - g_variant_get(result, "(b)", &approved); - g_debug("Approver responded: %s", approved ? "approve" : "rejected"); - g_variant_unref(result); - } - else { - g_debug("Approver responded error: %s", error->message); - g_error_free (error); - } - - if (approved) { - app->approved_by = g_list_prepend(app->approved_by, proxy); - } else { - app->approved_by = g_list_remove(app->approved_by, proxy); - } - - apply_status(app); - return; -} - -/* Run the applications through the new approver */ -static void -check_with_new_approver (gpointer papp, gpointer papprove) -{ - Application * app = (Application *)papp; - Approver * approver = (Approver *)papprove; - GCancellable * cancel = NULL; - - cancel = g_cancellable_new(); - g_object_set_data(G_OBJECT(cancel), "app", app); - g_object_set_data(G_OBJECT(cancel), "proxy", approver->proxy); - app->approver_cancels = g_list_prepend(app->approver_cancels, cancel); - - g_dbus_proxy_call(approver->proxy, "ApproveItem", - g_variant_new("(ssuso)", app->id, app->category, - 0, app->dbus_name, app->dbus_object), - G_DBUS_CALL_FLAGS_NONE, -1, cancel, - approver_request_cb, cancel); - - return; -} - -/* A signal when an approver changes the why that it thinks about - a particular indicator. */ -void -approver_revise_judgement (Approver * approver, gboolean new_status, const gchar * address, const gchar * path) -{ - g_return_if_fail(address != NULL && address[0] != '\0'); - g_return_if_fail(path != NULL && path[0] != '\0'); - - Application * app = find_application(approver->appstore, address, path); - - if (app == NULL) { - g_warning("Unable to update approver status of application (%s:%s) as it was not found", address, path); - return; - } - - if (new_status) { - app->approved_by = g_list_prepend(app->approved_by, approver->proxy); - } else { - app->approved_by = g_list_remove(app->approved_by, approver->proxy); - } - apply_status(app); - - return; -} - -/* Adds a new approver to the app store */ -void -application_service_appstore_approver_add (ApplicationServiceAppstore * appstore, const gchar * dbus_name, const gchar * dbus_object) -{ - g_return_if_fail(IS_APPLICATION_SERVICE_APPSTORE(appstore)); - g_return_if_fail(dbus_name != NULL); - g_return_if_fail(dbus_object != NULL); - ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE (appstore); - - Approver * approver = g_new0(Approver, 1); - approver->appstore = appstore; - approver->proxy_cancel = NULL; - approver->proxy = NULL; - approver->name_watcher = 0; - - approver->proxy_cancel = g_cancellable_new(); - g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - dbus_name, - dbus_object, - NOTIFICATION_APPROVER_DBUS_IFACE, - approver->proxy_cancel, - approver_proxy_cb, - approver); - - priv->approvers = g_list_prepend(priv->approvers, approver); - - return; -} - -static void -approver_name_changed (GDBusConnection * connection, const gchar * sender_name, - const gchar * object_path, const gchar * interface_name, - const gchar * signal_name, GVariant * parameters, - gpointer user_data) -{ - Approver * approver = (Approver *)user_data; - ApplicationServiceAppstore * appstore = approver->appstore; - - gchar * new_name = NULL; - g_variant_get(parameters, "(sss)", NULL, NULL, &new_name); - - if (new_name == NULL || new_name[0] == 0) { - appstore->priv->approvers = g_list_remove(appstore->priv->approvers, approver); - approver_free(approver, appstore); - } - - g_free(new_name); - return; -} - -/* Callback from trying to create the proxy for the approver. */ -static void -approver_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) -{ - GError * error = NULL; - - Approver * approver = (Approver *)user_data; - g_return_if_fail(approver != NULL); - - GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); - - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - g_error_free (error); - return; // Must exit before accessing freed memory - } - - ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE (approver->appstore); - - if (approver->proxy_cancel != NULL) { - g_object_unref(approver->proxy_cancel); - approver->proxy_cancel = NULL; - } - - if (error != NULL) { - g_critical("Could not grab DBus proxy for approver: %s", error->message); - g_error_free(error); - return; - } - - /* Okay, we're good to grab the proxy at this point, we're - sure that it's ours. */ - approver->proxy = proxy; - - /* We've got it, let's watch it for destruction */ - approver->name_watcher = g_dbus_connection_signal_subscribe( - g_dbus_proxy_get_connection(proxy), - "org.freedesktop.DBus", - "org.freedesktop.DBus", - "NameOwnerChanged", - "/org/freedesktop/DBus", - g_dbus_proxy_get_name(proxy), - G_DBUS_SIGNAL_FLAGS_NONE, - approver_name_changed, - approver, - NULL); - - g_signal_connect(proxy, "g-signal", G_CALLBACK(approver_receive_signal), - approver); - - g_list_foreach(priv->applications, check_with_new_approver, approver); - - return; -} - -/* Receives all signals from the service, routed to the appropriate functions */ -static void -approver_receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, - GVariant * parameters, gpointer user_data) -{ - Approver * approver = (Approver *)user_data; - - if (g_strcmp0(signal_name, "ReviseJudgement") == 0) { - gboolean approved = FALSE; - gchar * address = NULL; - gchar * path = NULL; - g_variant_get(parameters, "(bso)", &approved, &address, &path); - approver_revise_judgement(approver, approved, address, path); - g_free(address); - g_free(path); - } - - return; -} diff --git a/src/application-service-appstore.h b/src/application-service-appstore.h index aa2824b..7508658 100644 --- a/src/application-service-appstore.h +++ b/src/application-service-appstore.h @@ -63,9 +63,6 @@ void application_service_appstore_application_add (ApplicationServiceApp void application_service_appstore_application_remove (ApplicationServiceAppstore * appstore, const gchar * dbus_name, const gchar * dbus_object); -void application_service_appstore_approver_add (ApplicationServiceAppstore * appstore, - const gchar * dbus_name, - const gchar * dbus_object); gchar** application_service_appstore_application_get_list (ApplicationServiceAppstore * appstore); G_END_DECLS diff --git a/src/application-service-watcher.c b/src/application-service-watcher.c index 1c12eee..edbf05b 100644 --- a/src/application-service-watcher.c +++ b/src/application-service-watcher.c @@ -48,7 +48,6 @@ enum { static gboolean _notification_watcher_server_register_status_notifier_item (ApplicationServiceWatcher * appwatcher, const gchar * service, DBusGMethodInvocation * method); static gboolean _notification_watcher_server_register_status_notifier_host (ApplicationServiceWatcher * appwatcher, const gchar * host); -static gboolean _notification_watcher_server_x_ayatana_register_notification_approver (ApplicationServiceWatcher * appwatcher, const gchar * path, const GArray * categories, DBusGMethodInvocation * method); static void get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer data); #include "notification-watcher-server.h" @@ -289,18 +288,3 @@ get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer data) return; } - -static gboolean -_notification_watcher_server_x_ayatana_register_notification_approver (ApplicationServiceWatcher * appwatcher, const gchar * path, const GArray * categories, DBusGMethodInvocation * method) -{ - ApplicationServiceWatcherPrivate * priv = APPLICATION_SERVICE_WATCHER_GET_PRIVATE(appwatcher); - - char * sender = dbus_g_method_get_sender(method); - application_service_appstore_approver_add(priv->appstore, - sender, - path); - g_free(sender); - - dbus_g_method_return(method, G_TYPE_NONE); - return TRUE; -} diff --git a/src/dbus-shared.h b/src/dbus-shared.h index ce27bd9..64ad2d3 100644 --- a/src/dbus-shared.h +++ b/src/dbus-shared.h @@ -31,6 +31,3 @@ with this program. If not, see . #define NOTIFICATION_ITEM_DBUS_IFACE "org.kde.StatusNotifierItem" #define NOTIFICATION_ITEM_DEFAULT_OBJ "/StatusNotifierItem" - -#define NOTIFICATION_APPROVER_DBUS_IFACE "com.canonical.StatusNotifierApprover" - diff --git a/src/notification-approver.xml b/src/notification-approver.xml deleted file mode 100644 index a72ca92..0000000 --- a/src/notification-approver.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/notification-watcher.xml b/src/notification-watcher.xml index b03c5e3..e1897f5 100644 --- a/src/notification-watcher.xml +++ b/src/notification-watcher.xml @@ -15,13 +15,6 @@ - - - - - - - diff --git a/tests/Makefile.am b/tests/Makefile.am index c8bc3eb..20ac513 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,40 +1,7 @@ -check_PROGRAMS = \ - test-approver +check_PROGRAMS = TESTS = DISTCLEANFILES = $(TESTS) EXTRA_DIST = run-xvfb.sh - -DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf - -######################################### -## test-approver -######################################### - -test_approver_SOURCES = \ - $(top_srcdir)/src/gen-notification-approver.xml.c \ - test-approver.c - -test_approver_CFLAGS = \ - $(INDICATOR_CFLAGS) \ - $(APPINDICATOR_CFLAGS) \ - -Wall -Werror \ - -I$(top_srcdir)/src \ - -I$(top_builddir)/src - -test_approver_LDADD = \ - $(INDICATOR_LIBS) \ - $(APPINDICATOR_LIBS) - -test-approver-tester: test-approver Makefile.am - @echo "#!/bin/bash" > $@ - @echo export INDICATOR_SERVICE_SHUTDOWN_TIMEOUT=1000 >> $@ - @echo . $(srcdir)/run-xvfb.sh >> $@ - @echo $(DBUS_RUNNER) --task $(builddir)/test-approver --task-name Approver --task $(top_builddir)/src/indicator-application-service --task-name Service --ignore-return >> $@ - @chmod +x $@ - -TESTS += test-approver-tester - - diff --git a/tests/test-approver.c b/tests/test-approver.c deleted file mode 100644 index bacdc67..0000000 --- a/tests/test-approver.c +++ /dev/null @@ -1,254 +0,0 @@ -#include -#include -#include - -#include "dbus-shared.h" -#include "libappindicator/app-indicator.h" -#include "gen-notification-approver.xml.h" - -#define APPROVER_PATH "/my/approver" - -#define INDICATOR_ID "test-indicator-id" -#define INDICATOR_ICON "test-indicator-icon-name" -#define INDICATOR_CATEGORY APP_INDICATOR_CATEGORY_APPLICATION_STATUS - -#define TEST_APPROVER_TYPE (test_approver_get_type ()) -#define TEST_APPROVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_APPROVER_TYPE, TestApprover)) -#define TEST_APPROVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_APPROVER_TYPE, TestApproverClass)) -#define IS_TEST_APPROVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_APPROVER_TYPE)) -#define IS_TEST_APPROVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_APPROVER_TYPE)) -#define TEST_APPROVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_APPROVER_TYPE, TestApproverClass)) - -typedef struct _TestApprover TestApprover; -typedef struct _TestApproverClass TestApproverClass; - -struct _TestApproverClass { - GObjectClass parent_class; -}; - -struct _TestApprover { - GObject parent; -}; - -GType test_approver_get_type (void); - -static void test_approver_class_init (TestApproverClass *klass); -static void test_approver_init (TestApprover *self); -static GVariant * approve_item (TestApprover * ta, const gchar * id); -static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data); - -/* GDBus Stuff */ -static GDBusNodeInfo * node_info = NULL; -static GDBusInterfaceInfo * interface_info = NULL; -static GDBusInterfaceVTable interface_table = { - method_call: bus_method_call, - get_property: NULL, /* No properties */ - set_property: NULL /* No properties */ -}; - -GMainLoop * main_loop = NULL; -GDBusConnection * session_bus = NULL; -GDBusProxy * bus_proxy = NULL; -GDBusProxy * watcher_proxy = NULL; -AppIndicator * app_indicator = NULL; -gboolean passed = FALSE; - -G_DEFINE_TYPE (TestApprover, test_approver, G_TYPE_OBJECT); - -static void -test_approver_class_init (TestApproverClass *klass) -{ - /* Setting up the DBus interfaces */ - if (node_info == NULL) { - GError * error = NULL; - - node_info = g_dbus_node_info_new_for_xml(_notification_approver, &error); - if (error != NULL) { - g_error("Unable to parse Approver Service Interface description: %s", error->message); - g_error_free(error); - } - } - - if (interface_info == NULL) { - interface_info = g_dbus_node_info_lookup_interface(node_info, NOTIFICATION_APPROVER_DBUS_IFACE); - - if (interface_info == NULL) { - g_error("Unable to find interface '" NOTIFICATION_APPROVER_DBUS_IFACE "'"); - } - } - - return; -} - -static void -test_approver_init (TestApprover *self) -{ - GError * error = NULL; - - /* Now register our object on our new connection */ - g_dbus_connection_register_object(session_bus, - APPROVER_PATH, - interface_info, - &interface_table, - self, - NULL, - &error); - - if (error != NULL) { - g_error("Unable to register the object to DBus: %s", error->message); - g_error_free(error); - return; - } - - return; -} - -static GVariant * -approve_item (TestApprover * ta, const gchar * id) -{ - g_debug("Asked to approve indicator"); - - if (g_strcmp0(id, INDICATOR_ID) == 0) { - passed = TRUE; - } - - g_main_loop_quit(main_loop); - - return g_variant_new("(b)", TRUE); -} - -/* A method has been called from our dbus inteface. Figure out what it - is and dispatch it. */ -static void -bus_method_call (GDBusConnection * connection, const gchar * sender, - const gchar * path, const gchar * interface, - const gchar * method, GVariant * params, - GDBusMethodInvocation * invocation, gpointer user_data) -{ - TestApprover * ta = (TestApprover *)user_data; - GVariant * retval = NULL; - - if (g_strcmp0(method, "ApproveItem") == 0) { - const gchar * id; - g_variant_get(params, "(&ssuso)", &id, NULL, NULL, NULL, NULL); - retval = approve_item(ta, id); - } else { - g_warning("Calling method '%s' on the indicator service and it's unknown", method); - } - - g_dbus_method_invocation_return_value(invocation, retval); - return; -} - -static void -register_cb (GObject *object, GAsyncResult *res, gpointer user_data) -{ - GDBusProxy * proxy = G_DBUS_PROXY(object); - GError * error = NULL; - GVariant * result; - - result = g_dbus_proxy_call_finish(proxy, res, &error); - - if (result != NULL) { - g_variant_unref(result); - result = NULL; - } - - if (error != NULL) { - g_warning("Unable to register approver: %s", error->message); - g_error_free(error); - g_main_loop_quit(main_loop); - return; - } - - g_debug("Building App Indicator"); - app_indicator = app_indicator_new(INDICATOR_ID, INDICATOR_ICON, INDICATOR_CATEGORY); - - GtkWidget * menu = gtk_menu_new(); - GtkWidget * mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); - - app_indicator_set_menu(app_indicator, GTK_MENU(menu)); - - return; -} - -gint owner_count = 0; -gboolean -check_for_service (gpointer user_data) -{ - g_debug("Checking for Watcher"); - - if (owner_count > 100) { - g_warning("Couldn't find watcher after 100 tries."); - g_main_loop_quit(main_loop); - return FALSE; - } - - owner_count++; - - gboolean has_owner = FALSE; - gchar * owner = g_dbus_proxy_get_name_owner(bus_proxy); - has_owner = (owner != NULL); - g_free (owner); - - if (has_owner) { - g_debug("Registering Approver"); - GVariantBuilder * builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - g_dbus_proxy_call(bus_proxy, "XAyatanaRegisterNotificationApprover", - g_variant_new("(oas)", APPROVER_PATH, builder), - G_DBUS_CALL_FLAGS_NONE, -1, NULL, register_cb, - NULL); - return FALSE; - } - - return TRUE; -} - -gboolean -fail_timeout (gpointer user_data) -{ - g_debug("Failure timeout initiated."); - g_main_loop_quit(main_loop); - return FALSE; -} - -int -main (int argc, char ** argv) -{ - GError * error = NULL; - - gtk_init(&argc, &argv); - g_debug("Initing"); - - session_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); - TestApprover * approver = g_object_new(TEST_APPROVER_TYPE, NULL); - - bus_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, NOTIFICATION_WATCHER_DBUS_ADDR, NOTIFICATION_WATCHER_DBUS_OBJ, NOTIFICATION_WATCHER_DBUS_IFACE, NULL, &error); - if (error != NULL) { - g_warning("Unable to get bus proxy: %s", error->message); - g_error_free(error); - return -1; - } - - watcher_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, NOTIFICATION_WATCHER_DBUS_ADDR, NOTIFICATION_WATCHER_DBUS_OBJ, NOTIFICATION_WATCHER_DBUS_IFACE, NULL, &error); - if (error != NULL) { - g_warning("Unable to get watcher bus: %s", error->message); - g_error_free(error); - return -1; - } - - g_timeout_add(100, check_for_service, NULL); - g_timeout_add_seconds(2, fail_timeout, NULL); - - main_loop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(main_loop); - - g_object_unref(approver); - - if (!passed) { - return -1; - } - - return 0; -} -- cgit v1.2.3