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;
71 empathy_connection_managers_init (EmpathyConnectionManagers *obj)
73 EmpathyConnectionManagersPriv *priv =
74 G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
75 EMPATHY_TYPE_CONNECTION_MANAGERS, EmpathyConnectionManagersPriv);
79 priv->dbus = tp_dbus_daemon_dup (NULL);
80 g_assert (priv->dbus != NULL);
82 empathy_connection_managers_update (obj);
84 /* allocate any data required by the object here */
87 static void empathy_connection_managers_dispose (GObject *object);
88 static void empathy_connection_managers_finalize (GObject *object);
91 empathy_connection_managers_constructor (GType type,
92 guint n_construct_params,
93 GObjectConstructParam *construct_params)
96 return g_object_ref (managers);
99 G_OBJECT_CLASS (empathy_connection_managers_parent_class)->constructor
100 (type, n_construct_params, construct_params);
102 g_object_add_weak_pointer (managers, (gpointer) &managers);
110 empathy_connection_managers_get_property (GObject *object,
115 EmpathyConnectionManagers *managers = EMPATHY_CONNECTION_MANAGERS (object);
116 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
121 g_value_set_boolean (value, priv->ready);
124 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
130 empathy_connection_managers_class_init (
131 EmpathyConnectionManagersClass *empathy_connection_managers_class)
133 GObjectClass *object_class =
134 G_OBJECT_CLASS (empathy_connection_managers_class);
136 g_type_class_add_private (empathy_connection_managers_class, sizeof
137 (EmpathyConnectionManagersPriv));
139 object_class->constructor = empathy_connection_managers_constructor;
140 object_class->dispose = empathy_connection_managers_dispose;
141 object_class->finalize = empathy_connection_managers_finalize;
142 object_class->get_property = empathy_connection_managers_get_property;
144 g_object_class_install_property (object_class, PROP_READY,
145 g_param_spec_boolean ("ready",
147 "Whether the connection manager information is ready to be used",
149 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
151 signals[UPDATED] = g_signal_new ("updated",
152 G_TYPE_FROM_CLASS (object_class),
155 g_cclosure_marshal_VOID__VOID,
160 empathy_connection_managers_free_cm_list (EmpathyConnectionManagers *self)
162 EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
165 for (l = priv->cms ; l != NULL ; l = g_list_next (l))
167 g_object_unref (l->data);
169 g_list_free (priv->cms);
175 empathy_connection_managers_dispose (GObject *object)
177 EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object);
178 EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
180 if (priv->dispose_has_run)
183 priv->dispose_has_run = TRUE;
185 if (priv->dbus != NULL)
186 g_object_unref (priv->dbus);
189 empathy_connection_managers_free_cm_list (self);
191 /* release any references held by the object here */
193 if (G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose)
194 G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose (object);
198 empathy_connection_managers_finalize (GObject *object)
201 EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object);
202 EmpathyConnectionManagersPriv *priv =
203 EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (self);
205 /* free any data held directly by the object here */
207 G_OBJECT_CLASS (empathy_connection_managers_parent_class)->finalize (object);
211 EmpathyConnectionManagers *
212 empathy_connection_managers_dup_singleton (void)
214 return EMPATHY_CONNECTION_MANAGERS (
215 g_object_new (EMPATHY_TYPE_CONNECTION_MANAGERS, NULL));
219 empathy_connection_managers_is_ready (EmpathyConnectionManagers *managers)
221 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
226 empathy_connection_managers_listed_cb (TpConnectionManager * const *cms,
230 GObject *weak_object)
232 EmpathyConnectionManagers *self =
233 EMPATHY_CONNECTION_MANAGERS (weak_object);
234 EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
235 TpConnectionManager * const *iter;
237 empathy_connection_managers_free_cm_list (self);
241 DEBUG ("Failed to get connection managers: %s", error->message);
245 for (iter = cms ; iter != NULL && *iter != NULL; iter++)
247 /* only list cms that didn't hit errors */
248 if (tp_connection_manager_is_ready(*iter))
249 priv->cms = g_list_prepend (priv->cms, g_object_ref (*iter));
256 g_object_notify (weak_object, "ready");
258 g_signal_emit (weak_object, signals[UPDATED], 0);
262 empathy_connection_managers_update (EmpathyConnectionManagers *managers)
264 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
266 tp_list_connection_managers (priv->dbus,
267 empathy_connection_managers_listed_cb,
268 NULL, NULL, G_OBJECT (managers));
272 empathy_connection_managers_get_cms (EmpathyConnectionManagers *managers)
274 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
279 TpConnectionManager *
280 empathy_connection_managers_get_cm (EmpathyConnectionManagers *managers,
283 EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
286 for (l = priv->cms ; l != NULL; l = g_list_next (l))
288 TpConnectionManager *c = TP_CONNECTION_MANAGER (l->data);
290 if (!tp_strdiff (c->name, cm))