Start documenting objects.
[mmediamanager.git] / libmmanager / mm-dbus-category.c
blob141443dc9d35bb7a4d5aee48ff7553681c580a89
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 <glib.h>
22 #include <glib-object.h>
23 #include <dbus/dbus-glib.h>
24 #include "mm-dbus-category.h"
25 #include "mm-category.h"
26 #include "mm-dbus-application.h"
27 #include "mm-string-utils.h"
28 #include "mm-error.h"
30 G_DEFINE_TYPE (MMDBusCategory, mm_dbus_category, MM_TYPE_CATEGORY);
32 static MMHitCollection *
33 mm_dbus_category_get_hits (MMCategory *c,
34 MMFilter *f,
35 GError **ret_error)
37 DBusGConnection *connection;
38 DBusGProxy *app_proxy;
39 MMApplication *app;
40 MMHitCollection *hit_collection = NULL;
41 GError *error = NULL;
42 gboolean ret;
43 char *serial_filter;
44 char *serial_hit_collection = NULL;
46 g_return_val_if_fail (c != NULL, NULL);
47 g_return_val_if_fail (MM_IS_CATEGORY (c), NULL);
48 g_return_val_if_fail (f != NULL, NULL);
49 g_return_val_if_fail (MM_IS_FILTER (f), NULL);
51 connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
52 if (!connection) {
53 g_set_error (ret_error,
54 MM_DBUS_ERROR_QUARK,
55 MM_DBUS_ERROR_BUS_UNAVAILABLE,
56 "Unable to get a connection to the session bus: %s", error->message);
57 g_error_free (error);
58 return NULL;
61 app = mm_category_get_application (c);
62 app_proxy = dbus_g_proxy_new_for_name (connection,
63 mm_application_get_id (app),
64 mm_dbus_application_get_path (MM_DBUS_APPLICATION (app)),
65 "org.gnome.MediaManager.Application");
66 serial_filter = mm_filter_serialize (f, &error);
67 if (error) {
68 g_set_error (ret_error,
69 MM_DBUS_ERROR_QUARK,
70 MM_DBUS_ERROR_SERIALIZE_FAIL,
71 "Unable to serialize the filter object: %s", error->message);
72 g_error_free (error);
73 goto out;
75 ret = dbus_g_proxy_call (app_proxy,
76 "GetHits",
77 &error,
78 G_TYPE_STRING,
79 mm_category_get_name (c),
80 G_TYPE_STRING,
81 serial_filter,
82 G_TYPE_INVALID,
83 G_TYPE_STRING,
84 &serial_hit_collection,
85 G_TYPE_INVALID);
86 if (!ret) {
87 g_set_error (ret_error,
88 MM_DBUS_ERROR_QUARK,
89 MM_DBUS_ERROR_REMOTE_METHOD_FAILED,
90 "Error while calling GetHits on %s: %s", mm_application_get_id (app),
91 error->message);
92 g_error_free (error);
93 goto out;
96 hit_collection = mm_hit_collection_unserialize (serial_hit_collection, &error);
97 if (error) {
98 g_set_error (ret_error,
99 MM_DBUS_ERROR_QUARK,
100 MM_DBUS_ERROR_UNSERIALIZE_FAIL,
101 "Unable to unserialize the HitCollection: %s", error->message);
102 g_error_free (error);
103 goto out;
106 out:
107 g_free (serial_filter);
108 g_free (serial_hit_collection);
109 g_object_unref (app_proxy);
110 g_object_unref (app);
112 return hit_collection;
115 static void
116 mm_dbus_category_class_init (MMDBusCategoryClass *klass)
118 MMCategoryClass *cat_class = MM_CATEGORY_CLASS (klass);
120 cat_class->get_hits = mm_dbus_category_get_hits;
123 static void
124 mm_dbus_category_init (MMDBusCategory *cat)
126 /* empty */
129 /* public methods */
132 * mm_dbus_category_new:
133 * @app: a #MMDBusApplication.
134 * @name: the name of the category.
135 * @icon: the icon of the category.
137 * Builds a new #MMCategory with the specified name and icon. The new object
138 * will own a reference to both the application and the icon.
140 * Return value: a #MMCategory.
143 MMCategory *
144 mm_dbus_category_new (MMDBusApplication *app,
145 const char *name,
146 GIcon *icon)
148 MMCategory *category;
150 category = MM_CATEGORY (g_object_new (MM_TYPE_DBUS_CATEGORY, NULL));
151 mm_category_set_attributes (category, MM_APPLICATION (app), name, icon);
153 return category;