1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include "mm-application.h"
22 #include "mm-dbus-application.h"
23 #include "mm-category.h"
25 #include <glib-object.h>
26 #include <dbus/dbus-glib.h>
28 #define MM_DBUS_APPLICATION_GET_PRIVATE(o) \
29 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_DBUS_APPLICATION, MMDBusApplicationDetails))
31 struct _MMDBusApplicationDetails
{
35 G_DEFINE_TYPE (MMDBusApplication
, mm_dbus_application
, MM_TYPE_APPLICATION
);
38 create_and_append_category (MMApplication
*app
,
41 const char *icon_name
)
45 cat
= mm_category_new (app
, name
, g_themed_icon_new (icon_name
));
46 categories
= g_list_prepend (categories
, cat
);
50 mm_dbus_application_get_categories (MMApplication
*app
)
52 DBusGProxy
*app_proxy
;
53 DBusGConnection
*connection
;
54 char **cat_names
, **cat_icon_names
;
57 GList
*categories
= NULL
;
59 const char *remote_name
= mm_application_get_id (app
);
61 connection
= dbus_g_bus_get (DBUS_BUS_SESSION
, &error
);
63 g_warning ("Unable to get a connection to the session bus: %s", error
->message
);
68 app_proxy
= dbus_g_proxy_new_for_name (connection
,
70 MM_DBUS_APPLICATION (app
)->details
->path
,
71 "org.gnome.MediaManager.Application");
72 ret
= dbus_g_proxy_call (app_proxy
,
82 g_warning ("Error while calling GetCategories on %s: %s", remote_name
,
88 if (G_N_ELEMENTS (cat_names
) != G_N_ELEMENTS (cat_icon_names
)) {
89 /* something must be broken, return */
90 g_warning ("Error in GetCategories on %s: the length of the returned "
91 "arrays do not match", remote_name
);
95 /* create the category objects */
96 for (idx
= 0; idx
< G_N_ELEMENTS (cat_names
); idx
++) {
97 create_and_append_category (app
, categories
, cat_names
[idx
],
102 g_strfreev (cat_names
);
103 g_strfreev (cat_icon_names
);
106 g_object_unref (app_proxy
);
111 mm_dbus_application_finalize (GObject
*o
)
113 g_free (MM_DBUS_APPLICATION (o
)->details
->path
);
115 G_OBJECT_CLASS (mm_dbus_application_parent_class
)->finalize (o
);
119 mm_dbus_application_class_init (MMDBusApplicationClass
*klass
)
121 MMApplicationClass
*app_class
= MM_APPLICATION_CLASS (klass
);
123 app_class
->get_categories
= mm_dbus_application_get_categories
;
124 G_OBJECT_CLASS (klass
)->finalize
= mm_dbus_application_finalize
;
126 g_type_class_add_private (klass
, sizeof (MMDBusApplicationDetails
));
130 mm_dbus_application_init (MMDBusApplication
*app
)
132 MMDBusApplicationDetails
*details
= app
->details
= MM_DBUS_APPLICATION_GET_PRIVATE (app
);
133 details
->path
= NULL
;
139 mm_dbus_application_new (const char *desktop_id
,
140 MMApplicationType supported_type
,
146 app
= MM_APPLICATION (g_object_new (MM_TYPE_DBUS_APPLICATION
, NULL
));
147 mm_application_set_attributes (app
, desktop_id
, supported_type
, name
);
148 MM_DBUS_APPLICATION (app
)->details
->path
= g_strdup (path
);