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-dbus-category.h"
26 #include <glib-object.h>
27 #include <dbus/dbus-glib.h>
29 #define MM_DBUS_APPLICATION_GET_PRIVATE(o) \
30 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_DBUS_APPLICATION, MMDBusApplicationDetails))
32 struct _MMDBusApplicationDetails
{
36 G_DEFINE_TYPE (MMDBusApplication
, mm_dbus_application
, MM_TYPE_APPLICATION
);
39 create_and_append_category (MMApplication
*app
,
42 const char *icon_name
)
46 cat
= mm_dbus_category_new (MM_DBUS_APPLICATION (app
), name
, g_themed_icon_new (icon_name
));
47 categories
= g_list_prepend (categories
, cat
);
51 mm_dbus_application_get_categories (MMApplication
*app
, GError
**ret_error
)
53 DBusGProxy
*app_proxy
;
54 DBusGConnection
*connection
;
55 char **cat_names
, **cat_icon_names
;
58 GList
*categories
= NULL
;
60 const char *remote_name
= mm_application_get_id (app
);
62 connection
= dbus_g_bus_get (DBUS_BUS_SESSION
, &error
);
64 g_set_error (ret_error
,
66 MM_DBUS_ERROR_BUS_UNAVAILABLE
,
67 "Unable to get a connection to the session bus: %s", error
->message
);
72 app_proxy
= dbus_g_proxy_new_for_name (connection
,
74 MM_DBUS_APPLICATION (app
)->details
->path
,
75 "org.gnome.MediaManager.Application");
76 ret
= dbus_g_proxy_call (app_proxy
,
86 g_set_error (ret_error
,
88 MM_DBUS_ERROR_REMOTE_METHOD_FAILED
,
89 "Error while calling GetCategories on %s: %s", remote_name
,
95 if (G_N_ELEMENTS (cat_names
) != G_N_ELEMENTS (cat_icon_names
)) {
96 /* something must be broken, return */
97 g_set_error (ret_error
,
99 MM_DBUS_ERROR_REMOTE_METHOD_FAILED
,
100 "Error in GetCategories on %s: the length of the returned "
101 "arrays do not match", remote_name
);
105 /* create the category objects */
106 for (idx
= 0; idx
< G_N_ELEMENTS (cat_names
); idx
++) {
107 create_and_append_category (app
, categories
, cat_names
[idx
],
108 cat_icon_names
[idx
]);
112 g_strfreev (cat_names
);
113 g_strfreev (cat_icon_names
);
116 g_object_unref (app_proxy
);
121 mm_dbus_application_finalize (GObject
*o
)
123 g_free (MM_DBUS_APPLICATION (o
)->details
->path
);
125 G_OBJECT_CLASS (mm_dbus_application_parent_class
)->finalize (o
);
129 mm_dbus_application_class_init (MMDBusApplicationClass
*klass
)
131 MMApplicationClass
*app_class
= MM_APPLICATION_CLASS (klass
);
133 app_class
->get_categories
= mm_dbus_application_get_categories
;
134 G_OBJECT_CLASS (klass
)->finalize
= mm_dbus_application_finalize
;
136 g_type_class_add_private (klass
, sizeof (MMDBusApplicationDetails
));
140 mm_dbus_application_init (MMDBusApplication
*app
)
142 MMDBusApplicationDetails
*details
= app
->details
= MM_DBUS_APPLICATION_GET_PRIVATE (app
);
143 details
->path
= NULL
;
149 mm_dbus_application_new (const char *desktop_id
,
150 MMApplicationType supported_type
,
156 app
= MM_APPLICATION (g_object_new (MM_TYPE_DBUS_APPLICATION
, NULL
));
157 mm_application_set_attributes (app
, desktop_id
, supported_type
, name
);
158 MM_DBUS_APPLICATION (app
)->details
->path
= g_strdup (path
);
164 mm_dbus_application_get_path (MMDBusApplication
*app
)
166 g_return_val_if_fail (MM_IS_DBUS_APPLICATION (app
), NULL
);
168 return app
->details
->path
;