From ba9f514d7ebe85cc6188f1ee06564350e897076b Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 25 Jun 2008 18:54:03 +0200 Subject: [PATCH] Add a first implementation of the DBus application. --- src/Makefile.am | 2 + src/mm-dbus-application.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++ src/mm-dbus-application.h | 60 ++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 src/mm-dbus-application.c create mode 100644 src/mm-dbus-application.h diff --git a/src/Makefile.am b/src/Makefile.am index 4b44d3f..3d12f81 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,6 +38,7 @@ libmmanager_includedir=$(includedir)/libmmanager libmmanager_headers = \ mm.h \ mm-application.h \ + mm-dbus-application.h \ mm-so-application.h \ mm-application-provider.h \ mm-category.h \ @@ -63,6 +64,7 @@ libmmanager_include_HEADERS = \ libmmanager_la_SOURCES = \ mm-application.c \ + mm-dbus-application.c \ mm-so-application.c \ mm-application-provider.c \ mm-category.c \ diff --git a/src/mm-dbus-application.c b/src/mm-dbus-application.c new file mode 100644 index 0000000..ae13df4 --- /dev/null +++ b/src/mm-dbus-application.c @@ -0,0 +1,151 @@ +/* MManager - a Desktop wide manager for multimedia applications. + * + * Copyright (C) 2008 Cosimo Cecchi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "mm-application.h" +#include "mm-dbus-application.h" +#include "mm-category.h" +#include +#include +#include + +#define MM_DBUS_APPLICATION_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_DBUS_APPLICATION, MMDBusApplicationDetails)) + +struct _MMDBusApplicationDetails { + char *path; +}; + +G_DEFINE_TYPE (MMDBusApplication, mm_dbus_application, MM_TYPE_APPLICATION); + +static void +create_and_append_category (MMApplication *app, + GList *categories, + const char *name, + const char *icon_name) +{ + MMCategory *cat; + + cat = mm_category_new (app, name, g_themed_icon_new (icon_name)); + categories = g_list_prepend (categories, cat); +} + +static GList * +mm_dbus_application_get_categories (MMApplication *app) +{ + DBusGProxy *app_proxy; + DBusGConnection *connection; + char **cat_names, **cat_icon_names; + gboolean ret; + int idx; + GList *categories = NULL; + GError *error = NULL; + const char *remote_name = mm_application_get_id (app); + + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (!connection) { + g_warning ("Unable to get a connection to the session bus: %s", error->message); + g_error_free (error); + return NULL; + } + + app_proxy = dbus_g_proxy_new_for_name (connection, + remote_name, + MM_DBUS_APPLICATION (app)->details->path, + "org.gnome.MediaManager.Application"); + ret = dbus_g_proxy_call (app_proxy, + "GetCategories", + &error, + G_TYPE_INVALID, + G_TYPE_STRV, + &cat_names, + G_TYPE_STRV, + &cat_icon_names, + G_TYPE_INVALID); + if (!ret) { + g_warning ("Error while calling GetCategories on %s: %s", remote_name, + error->message); + g_error_free (error); + goto out; + } + + if (G_N_ELEMENTS (cat_names) != G_N_ELEMENTS (cat_icon_names)) { + /* something must be broken, return */ + g_warning ("Error in GetCategories on %s: the length of the returned " + "arrays do not match", remote_name); + goto free; + } + + /* create the category objects */ + for (idx = 0; idx < G_N_ELEMENTS (cat_names); idx++) { + create_and_append_category (app, categories, cat_names[idx], + cat_icon_names[idx]); + } + +free: + g_strfreev (cat_names); + g_strfreev (cat_icon_names); + +out: + g_object_unref (app_proxy); + return categories; +} + +static void +mm_dbus_application_finalize (GObject *o) +{ + g_free (MM_DBUS_APPLICATION (o)->details->path); + + G_OBJECT_CLASS (mm_dbus_application_parent_class)->finalize (o); +} + +static void +mm_dbus_application_class_init (MMDBusApplicationClass *klass) +{ + MMApplicationClass *app_class = MM_APPLICATION_CLASS (klass); + + app_class->get_categories = mm_dbus_application_get_categories; + G_OBJECT_CLASS (klass)->finalize = mm_dbus_application_finalize; + + g_type_class_add_private (klass, sizeof (MMDBusApplicationDetails)); +} + +static void +mm_dbus_application_init (MMDBusApplication *app) +{ + MMDBusApplicationDetails *details = app->details = MM_DBUS_APPLICATION_GET_PRIVATE (app); + details->path = NULL; +} + +/* public methods */ + +MMApplication * +mm_dbus_application_new (const char *desktop_id, + MMApplicationType supported_type, + const char *name, + const char *path) +{ + MMApplication *app; + + app = MM_APPLICATION (g_object_new (MM_TYPE_DBUS_APPLICATION, NULL)); + mm_application_set_attributes (app, desktop_id, supported_type, name); + MM_DBUS_APPLICATION (app)->details->path = g_strdup (path); + + return app; +} diff --git a/src/mm-dbus-application.h b/src/mm-dbus-application.h new file mode 100644 index 0000000..9dd8f11 --- /dev/null +++ b/src/mm-dbus-application.h @@ -0,0 +1,60 @@ +/* MManager - a Desktop wide manager for multimedia applications. + * + * Copyright (C) 2008 Cosimo Cecchi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __MM_DBUS_APPLICATION_H__ +#define __MM_DBUS_APPLICATION_H__ + +#include +#include +#include "mm-application.h" + +#define MM_TYPE_DBUS_APPLICATION (mm_dbus_application_get_type()) +#define MM_DBUS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ + MM_TYPE_DBUS_APPLICATION, MMDBusApplication)) +#define MM_DBUS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\ + MM_TYPE_DBUS_APPLICATION, MMDBusApplicationClass)) +#define MM_IS_DBUS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ + MM_TYPE_DBUS_APPLICATION)) +#define MM_IS_DBUS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj),\ + MM_TYPE_DBUS_APPLICATION)) +#define MM_DBUS_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),\ + MM_TYPE_DBUS_APPLICATION, MMDBusApplicationClass)) + +typedef struct _MMDBusApplication MMDBusApplication; +typedef struct _MMDBusApplicationClass MMDBusApplicationClass; +typedef struct _MMDBusApplicationDetails MMDBusApplicationDetails; + +struct _MMDBusApplication { + MMApplication parent; + MMDBusApplicationDetails *details; +}; + +struct _MMDBusApplicationClass { + MMApplicationClass parent_class; +}; + +/* public methods */ +GType mm_dbus_application_get_type (void); +MMApplication * mm_dbus_application_new (const char *desktop_id, + MMApplicationType supported_type, + const char *name, + const char *path); + +#endif /* __MM_DBUS_APPLICATION_H__ */ -- 2.11.4.GIT