Use the GErrors in MMDBusCategories.
[mmediamanager.git] / src / mm-dbus-category.c
blob8e048f8211c26ea87c440be126ed4113bfd07c5d
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"
29 G_DEFINE_TYPE (MMDBusCategory, mm_dbus_category, MM_TYPE_CATEGORY);
31 static MMHitCollection *
32 mm_dbus_category_get_hits (MMCategory *c,
33 MMFilter *f)
35 DBusGConnection *connection;
36 DBusGProxy *app_proxy;
37 MMApplication *app;
38 MMHitCollection *hit_collection = NULL;
39 GError *error = NULL;
40 gboolean ret;
41 char *serial_filter;
42 char *serial_hit_collection = NULL;
44 g_return_val_if_fail (c != NULL, NULL);
45 g_return_val_if_fail (MM_IS_CATEGORY (c), NULL);
46 g_return_val_if_fail (f != NULL, NULL);
47 g_return_val_if_fail (MM_IS_FILTER (f), NULL);
49 connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
50 if (!connection) {
51 g_warning ("Unable to get a connection to the session bus: %s", error->message);
52 g_error_free (error);
53 return NULL;
56 app = mm_category_get_application (c);
57 app_proxy = dbus_g_proxy_new_for_name (connection,
58 mm_application_get_id (app),
59 mm_dbus_application_get_path (MM_DBUS_APPLICATION (app)),
60 "org.gnome.MediaManager.Application");
61 serial_filter = mm_filter_serialize (f, &error);
62 if (error) {
63 g_warning ("Unable to serialize the filter object: %s", error->message);
64 g_error_free (error);
65 goto out;
67 ret = dbus_g_proxy_call (app_proxy,
68 "GetHits",
69 &error,
70 G_TYPE_STRING,
71 mm_category_get_name (c),
72 G_TYPE_STRING,
73 serial_filter,
74 G_TYPE_INVALID,
75 G_TYPE_STRING,
76 &serial_hit_collection,
77 G_TYPE_INVALID);
78 if (!ret) {
79 g_warning ("Error while calling GetHits on %s: %s", mm_application_get_id (app),
80 error->message);
81 g_error_free (error);
82 goto out;
85 hit_collection = mm_hit_collection_unserialize (serial_hit_collection, &error);
86 if (error) {
87 g_warning ("Unable to unserialize the HitCollection: %s", error->message);
88 g_error_free (error);
89 goto out;
92 out:
93 g_free (serial_filter);
94 g_free (serial_hit_collection);
95 g_object_unref (app_proxy);
97 return hit_collection;
100 static void
101 mm_dbus_category_class_init (MMDBusCategoryClass *klass)
103 MMCategoryClass *cat_class = MM_CATEGORY_CLASS (klass);
105 cat_class->get_hits = mm_dbus_category_get_hits;
108 static void
109 mm_dbus_category_init (MMDBusCategory *cat)
111 /* empty */
114 /* public methods */
115 MMCategory *
116 mm_dbus_category_new (MMDBusApplication *app,
117 const char *name,
118 GIcon *icon)
120 MMCategory *category;
122 category = MM_CATEGORY (g_object_new (MM_TYPE_DBUS_CATEGORY, NULL));
123 mm_category_set_attributes (category, MM_APPLICATION (app), name, icon);
125 return category;