2 * empathy-connection-managers.c - Source for EmpathyConnectionManagers
3 * Copyright (C) 2009 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <telepathy-glib/connection-manager.h>
26 #include <telepathy-glib/util.h>
28 #include "empathy-connection-managers.h"
29 #include "empathy-utils.h"
31 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
32 #include <libempathy/empathy-debug.h>
34 static GObject *managers = NULL;
36 G_DEFINE_TYPE(EmpathyConnectionManagers, empathy_connection_managers,
46 static guint signals[LAST_SIGNAL] = {0};
53 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyConnectionManagers)
56 /* private structure */
57 typedef struct _EmpathyConnectionManagersPriv
58 EmpathyConnectionManagersPriv;
60 struct _EmpathyConnectionManagersPriv
62 gboolean dispose_has_run;
70 #define EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE(o) \
71 (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
72 EMPATHY_TYPE_CONNECTION_MANAGERS, EmpathyConnectionManagersPriv))
75 empathy_connection_managers_init (EmpathyConnectionManagers *obj)
77 EmpathyConnectionManagersPriv *priv =
78 EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (obj);
80 priv->dbus = tp_dbus_daemon_dup (NULL);
81 g_assert (priv->dbus != NULL);
83 empathy_connection_managers_update (obj);
85 /* allocate any data required by the object here */
88 static void empathy_connection_managers_dispose (GObject *object);
89 static void empathy_connection_managers_finalize (GObject *object);
92 empathy_connection_managers_constructor (GType type,
93 guint n_construct_params,
94 GObjectConstructParam *construct_params)
97 return g_object_ref (managers);
100 G_OBJECT_CLASS (empathy_connection_managers_parent_class)->constructor
101 (type, n_construct_params, construct_params);
103 g_object_add_weak_pointer (managers, (gpointer) &managers);
111 empathy_connection_managers_get_property (GObject *object,
116 EmpathyConnectionManagers *managers = EMPATHY_CONNECTION_MANAGERS (object);
117 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
122 g_value_set_boolean (value, priv->ready);
125 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
131 empathy_connection_managers_class_init (
132 EmpathyConnectionManagersClass *empathy_connection_managers_class)
134 GObjectClass *object_class =
135 G_OBJECT_CLASS (empathy_connection_managers_class);
137 g_type_class_add_private (empathy_connection_managers_class, sizeof
138 (EmpathyConnectionManagersPriv));
140 object_class->constructor = empathy_connection_managers_constructor;
141 object_class->dispose = empathy_connection_managers_dispose;
142 object_class->finalize = empathy_connection_managers_finalize;
143 object_class->get_property = empathy_connection_managers_get_property;
145 g_object_class_install_property (object_class, PROP_READY,
146 g_param_spec_boolean ("ready",
148 "Whether the connection manager information is ready to be used",
150 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
152 signals[UPDATED] = g_signal_new ("updated",
153 G_TYPE_FROM_CLASS (object_class),
156 g_cclosure_marshal_VOID__VOID,
161 empathy_connection_managers_free_cm_list (EmpathyConnectionManagers *self)
163 EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
166 for (l = priv->cms ; l != NULL ; l = g_list_next (l))
168 g_object_unref (l->data);
170 g_list_free (priv->cms);
176 empathy_connection_managers_dispose (GObject *object)
178 EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object);
179 EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
181 if (priv->dispose_has_run)
184 priv->dispose_has_run = TRUE;
186 if (priv->dbus != NULL)
187 g_object_unref (priv->dbus);
190 empathy_connection_managers_free_cm_list (self);
192 /* release any references held by the object here */
194 if (G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose)
195 G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose (object);
199 empathy_connection_managers_finalize (GObject *object)
202 EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object);
203 EmpathyConnectionManagersPriv *priv =
204 EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (self);
206 /* free any data held directly by the object here */
208 G_OBJECT_CLASS (empathy_connection_managers_parent_class)->finalize (object);
212 EmpathyConnectionManagers *
213 empathy_connection_managers_dup_singleton (void)
215 return EMPATHY_CONNECTION_MANAGERS (
216 g_object_new (EMPATHY_TYPE_CONNECTION_MANAGERS, NULL));
220 empathy_connection_managers_is_ready (EmpathyConnectionManagers *managers)
222 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
227 empathy_connection_managers_listed_cb (TpConnectionManager * const *cms,
231 GObject *weak_object)
233 EmpathyConnectionManagers *self =
234 EMPATHY_CONNECTION_MANAGERS (weak_object);
235 EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
236 TpConnectionManager * const *iter;
238 empathy_connection_managers_free_cm_list (self);
242 DEBUG ("Failed to get connection managers: %s", error->message);
246 for (iter = cms ; iter != NULL && *iter != NULL; iter++)
248 /* only list cms that didn't hit errors */
249 if (tp_connection_manager_is_ready(*iter))
250 priv->cms = g_list_prepend (priv->cms, g_object_ref (*iter));
257 g_object_notify (weak_object, "ready");
259 g_signal_emit (weak_object, signals[UPDATED], 0);
263 empathy_connection_managers_update (EmpathyConnectionManagers *managers)
265 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
267 tp_list_connection_managers (priv->dbus,
268 empathy_connection_managers_listed_cb,
269 NULL, NULL, G_OBJECT (managers));
273 empathy_connection_managers_get_cms (EmpathyConnectionManagers *managers)
275 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
280 TpConnectionManager *
281 empathy_connection_managers_get_cm (EmpathyConnectionManagers *managers,
284 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
287 for (l = priv->cms ; l != NULL; l = g_list_next (l))
289 TpConnectionManager *c = TP_CONNECTION_MANAGER (l->data);
291 if (!tp_strdiff (c->name, cm))