aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-07-12 09:26:50 -0500
committerTed Gould <ted@gould.cx>2010-07-12 09:26:50 -0500
commit7ef183418aaee73864e44d93b32e80962fdea07a (patch)
tree4bf494ab0e9a5605e97f4066bb4ac9d5fb851462 /src
parent1ddd622e7f2ab0142c826459e1a38fec926c4dc6 (diff)
parent25b69bb08e3e5a3df7037f8ac786422ff53f6425 (diff)
downloadlibayatana-appindicator-7ef183418aaee73864e44d93b32e80962fdea07a.tar.gz
libayatana-appindicator-7ef183418aaee73864e44d93b32e80962fdea07a.tar.bz2
libayatana-appindicator-7ef183418aaee73864e44d93b32e80962fdea07a.zip
Putting in a basic approver API.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/application-service-appstore.c103
-rw-r--r--src/application-service-appstore.h11
-rw-r--r--src/application-service-watcher.c14
-rw-r--r--src/dbus-shared.h2
-rw-r--r--src/notification-approver.xml22
-rw-r--r--src/notification-watcher.xml7
7 files changed, 156 insertions, 4 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 787ba2f..68be1c0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -116,6 +116,7 @@ libappindicator_la_LIBADD = \
DBUS_SPECS = \
dbus-properties.xml \
application-service.xml \
+ notification-approver.xml \
notification-item.xml \
notification-watcher.xml
diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c
index 886fe92..311fcb1 100644
--- a/src/application-service-appstore.c
+++ b/src/application-service-appstore.c
@@ -31,6 +31,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "application-service-marshal.h"
#include "dbus-properties-client.h"
#include "dbus-shared.h"
+#include "notification-approver-client.h"
/* DBus Prototypes */
static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps, GError ** error);
@@ -53,9 +54,15 @@ static gboolean _application_service_server_get_applications (ApplicationService
struct _ApplicationServiceAppstorePrivate {
DBusGConnection * bus;
GList * applications;
+ GList * approvers;
AppLruFile * lrufile;
};
+typedef struct _Approver Approver;
+struct _Approver {
+ DBusGProxy * proxy;
+};
+
typedef struct _Application Application;
struct _Application {
gchar * id;
@@ -94,6 +101,9 @@ static void application_service_appstore_dispose (GObject *object);
static void application_service_appstore_finalize (GObject *object);
static AppIndicatorStatus string_to_status(const gchar * status_string);
static void apply_status (Application * app, AppIndicatorStatus status);
+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);
G_DEFINE_TYPE (ApplicationServiceAppstore, application_service_appstore, G_TYPE_OBJECT);
@@ -142,6 +152,7 @@ application_service_appstore_init (ApplicationServiceAppstore *self)
ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE (self);
priv->applications = NULL;
+ priv->approvers = NULL;
priv->lrufile = NULL;
GError * error = NULL;
@@ -172,6 +183,12 @@ application_service_appstore_dispose (GObject *object)
((Application *)priv->applications->data)->dbus_object);
}
+ if (priv->approvers != NULL) {
+ g_list_foreach(priv->approvers, approver_free, NULL);
+ g_list_free(priv->approvers);
+ priv->approvers = NULL;
+ }
+
G_OBJECT_CLASS (application_service_appstore_parent_class)->dispose (object);
return;
}
@@ -236,11 +253,23 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err
app->icon_path = g_strdup("");
}
+ /* TODO: Calling approvers, but we're ignoring the results. So, eh. */
+ g_list_foreach(priv->approvers, check_with_old_approver, app);
+
apply_status(app, string_to_status(g_value_get_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_STATUS))));
return;
}
+/* 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)
@@ -745,3 +774,77 @@ _application_service_server_get_applications (ApplicationServiceAppstore * appst
return TRUE;
}
+/* 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);
+
+ if (approver->proxy != NULL) {
+ g_object_unref(approver->proxy);
+ approver->proxy = NULL;
+ }
+
+ g_free(approver);
+ return;
+}
+
+/* What did the approver tell us? */
+static void
+approver_request_cb (DBusGProxy *proxy, gboolean OUT_approved, GError *error, gpointer userdata)
+{
+ g_debug("Approver responded: %s", OUT_approved ? "approve" : "rejected");
+ 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;
+
+ org_ayatana_StatusNotifierApprover_approve_item_async(approver->proxy,
+ app->id,
+ app->category,
+ 0,
+ app->dbus_name,
+ app->dbus_object,
+ approver_request_cb,
+ 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);
+
+ GError * error = NULL;
+ approver->proxy = dbus_g_proxy_new_for_name_owner(priv->bus,
+ dbus_name,
+ dbus_object,
+ NOTIFICATION_APPROVER_DBUS_IFACE,
+ &error);
+ if (error != NULL) {
+ g_warning("Unable to get approver interface on '%s:%s' : %s", dbus_name, dbus_object, error->message);
+ g_error_free(error);
+ g_free(approver);
+ return;
+ }
+
+ priv->approvers = g_list_prepend(priv->approvers, approver);
+
+ g_list_foreach(priv->applications, check_with_new_approver, approver);
+
+ return;
+}
+
diff --git a/src/application-service-appstore.h b/src/application-service-appstore.h
index 86d989b..e8ba8c1 100644
--- a/src/application-service-appstore.h
+++ b/src/application-service-appstore.h
@@ -57,11 +57,14 @@ struct _ApplicationServiceAppstore {
ApplicationServiceAppstore * application_service_appstore_new (AppLruFile * lrufile);
GType application_service_appstore_get_type (void);
void application_service_appstore_application_add (ApplicationServiceAppstore * appstore,
- const gchar * dbus_name,
- const gchar * dbus_object);
+ const gchar * dbus_name,
+ const gchar * dbus_object);
void application_service_appstore_application_remove (ApplicationServiceAppstore * appstore,
- const gchar * dbus_name,
- const gchar * dbus_object);
+ const gchar * dbus_name,
+ const gchar * dbus_object);
+void application_service_appstore_approver_add (ApplicationServiceAppstore * appstore,
+ const gchar * dbus_name,
+ const gchar * dbus_object);
G_END_DECLS
diff --git a/src/application-service-watcher.c b/src/application-service-watcher.c
index eff249d..4fe3bc7 100644
--- a/src/application-service-watcher.c
+++ b/src/application-service-watcher.c
@@ -34,6 +34,7 @@ static gboolean _notification_watcher_server_register_status_notifier_item (Appl
static gboolean _notification_watcher_server_registered_status_notifier_items (ApplicationServiceWatcher * appwatcher, GArray ** apps);
static gboolean _notification_watcher_server_protocol_version (ApplicationServiceWatcher * appwatcher, char ** version);
static gboolean _notification_watcher_server_register_notification_host (ApplicationServiceWatcher * appwatcher, const gchar * host);
+static gboolean _notification_watcher_server_register_notification_approver (ApplicationServiceWatcher * appwatcher, const gchar * path, const GArray * categories, DBusGMethodInvocation * method);
static gboolean _notification_watcher_server_is_notification_host_registered (ApplicationServiceWatcher * appwatcher, gboolean * haveHost);
static void get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer data);
@@ -249,3 +250,16 @@ get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer data)
return;
}
+
+static gboolean
+_notification_watcher_server_register_notification_approver (ApplicationServiceWatcher * appwatcher, const gchar * path, const GArray * categories, DBusGMethodInvocation * method)
+{
+ ApplicationServiceWatcherPrivate * priv = APPLICATION_SERVICE_WATCHER_GET_PRIVATE(appwatcher);
+
+ application_service_appstore_approver_add(priv->appstore,
+ dbus_g_method_get_sender(method),
+ path);
+
+ dbus_g_method_return(method, G_TYPE_NONE);
+ return TRUE;
+}
diff --git a/src/dbus-shared.h b/src/dbus-shared.h
index f158b1c..1d8d89c 100644
--- a/src/dbus-shared.h
+++ b/src/dbus-shared.h
@@ -31,3 +31,5 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define NOTIFICATION_ITEM_DBUS_IFACE "org.kde.StatusNotifierItem"
#define NOTIFICATION_ITEM_DEFAULT_OBJ "/StatusNotifierItem"
+#define NOTIFICATION_APPROVER_DBUS_IFACE "org.ayatana.StatusNotifierApprover"
+
diff --git a/src/notification-approver.xml b/src/notification-approver.xml
new file mode 100644
index 0000000..b1e69b9
--- /dev/null
+++ b/src/notification-approver.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<node name="/">
+ <interface name="org.ayatana.StatusNotifierApprover">
+
+<!-- Methods -->
+ <method name="ApproveItem">
+ <!-- KSNI ID -->
+ <arg type="s" name="id" direction="in" />
+ <!-- KSNI Category -->
+ <arg type="s" name="category" direction="in" />
+ <!-- Application PID -->
+ <arg type="u" name="pid" direction="in" />
+ <!-- Application DBus Address -->
+ <arg type="s" name="address" direction="in" />
+ <!-- Application DBus Path for KSNI interface -->
+ <arg type="o" name="path" direction="in" />
+ <!-- So, what do you think? -->
+ <arg type="b" name="approved" direction="out" />
+ </method>
+
+ </interface>
+</node>
diff --git a/src/notification-watcher.xml b/src/notification-watcher.xml
index c2324f1..cc7882d 100644
--- a/src/notification-watcher.xml
+++ b/src/notification-watcher.xml
@@ -22,6 +22,13 @@
<method name="IsNotificationHostRegistered">
<arg type="b" name="hasHost" direction="out" />
</method>
+ <method name="RegisterNotificationApprover">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true" />
+ <!-- The path where to find the approver interface -->
+ <arg type="o" name="path" direction="in" />
+ <!-- List of categories to approve, none represents all -->
+ <arg type="as" name="categories" direction="in" />
+ </method>
<!-- Signals -->
<signal name="ServiceRegistered">