diff options
Diffstat (limited to 'src/application-service-appstore.c')
-rw-r--r-- | src/application-service-appstore.c | 103 |
1 files changed, 103 insertions, 0 deletions
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; +} + |