From 301bb865986d1cbb81b94b7f9c3b3b7a616b8cca Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 27 Jun 2008 16:17:31 +0200 Subject: [PATCH] Update MMManager to list applications provided by DBus. --- src/mm-manager.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/src/mm-manager.c b/src/mm-manager.c index ed6fe34..806b458 100644 --- a/src/mm-manager.c +++ b/src/mm-manager.c @@ -20,6 +20,9 @@ #include #include +#include +#include "mm-application.h" +#include "mm-dbus-application.h" #include "mm-manager.h" @@ -54,6 +57,103 @@ mm_manager_class_init (MMManagerClass *klass) } static void +insert_dbus_application (GHashTable *applications, + DBusGConnection *connection, + const char *name, + const char *path) +{ + DBusGProxy *app_proxy; + guint supported_type; + char *desktop_id = NULL; + gboolean res; + MMApplication *app; + GError *error = NULL; + + app_proxy = dbus_g_proxy_new_for_name (connection, + name, path, + "org.gnome.MediaManager.Application"); + res = dbus_g_proxy_call (app_proxy, + "GetApplicationInfo", + &error, + G_TYPE_INVALID, + G_TYPE_UINT, + &supported_type, + G_TYPE_STRING, + &desktop_id, + G_TYPE_INVALID); + if (!res) { + g_warning ("Unable to get application info for the app at path %s: %s", path, + error->message); + g_object_unref (app_proxy); + g_error_free (error); + return; + } + + app = mm_dbus_application_new (desktop_id, supported_type, + name, path); + g_hash_table_insert (applications, + g_strdup (name), /* key */ + app); /* value */ + g_free (desktop_id); + g_object_unref (app_proxy); +} + +static void +insert_dbus_applications (GHashTable *applications) +{ + DBusGConnection *connection; + DBusGProxy *dbus_manager_proxy; + GError *error = NULL; + gboolean res; + char **registered_names = NULL; + char **registered_paths = NULL; + int idx, total_apps; + + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (error) { + g_warning ("Error while connecting to the session bus: %s", error->message); + g_error_free (error); + return; + } + + dbus_manager_proxy = dbus_g_proxy_new_for_name (connection, + "org.gnome.MediaManager.Manager", + "/org/gnome/MediaManager/Manager", + "org.gnome.MediaManager.Manager"); + res = dbus_g_proxy_call (dbus_manager_proxy, + "GetRegisteredApps", + &error, + G_TYPE_INVALID, + G_TYPE_STRV, + ®istered_names, + G_TYPE_STRV, + ®istered_paths, + G_TYPE_INVALID); + if (!res) { + g_warning ("Error while calling GetRegisteredApps on the dbus manager: %s", + error->message); + g_object_unref (dbus_manager_proxy); + g_error_free (error); + return; + } + + if ((total_apps = G_N_ELEMENTS (registered_names)) != G_N_ELEMENTS (registered_paths)) { + /* wtf, something is broken here, we'd better return */ + goto out; + } + + for (idx = 0; idx < total_apps; idx++) { + insert_dbus_application (applications, connection, + registered_names[idx], registered_paths[idx]); + } + +out: + g_strfreev (registered_names); + g_strfreev (registered_paths); + g_object_unref (dbus_manager_proxy); +} + +static void populate_applications_table (MMManager *manager) { GHashTable *applications = manager->details->applications; @@ -71,6 +171,9 @@ populate_applications_table (MMManager *manager) g_strdup (id), /* key */ application); /* value */ } + + /* now insert all the application registered on the DBus manager */ + insert_dbus_applications (applications); } static void -- 2.11.4.GIT