9fc6786d532646f0c5da7e139739b05e8c105f54
[empathy.git] / libempathy / empathy-account-manager.c
1 /*
2  * Copyright (C) 2008 Collabora Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  * 
18  * Authors: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
19  */
20
21 #include "config.h"
22
23 #include <libmissioncontrol/mc-account-monitor.h>
24
25 #include "empathy-account-manager.h"
26 #include "empathy-marshal.h"
27 #include "empathy-utils.h"
28
29 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
30 #include <libempathy/empathy-debug.h>
31
32 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountManager)
33
34 typedef struct {
35   McAccountMonitor *monitor;
36   MissionControl   *mc;
37
38   GHashTable       *accounts;
39   GHashTable       *connections;
40   int               connected;
41   int               connecting;
42   gboolean          dispose_run;
43 } EmpathyAccountManagerPriv;
44
45 typedef struct {
46   TpConnection *connection;
47   McPresence presence;
48   TpConnectionStatus status;
49   gboolean is_enabled;
50
51   guint source_id;
52 } AccountData;
53
54 enum {
55   ACCOUNT_CREATED,
56   ACCOUNT_DELETED,
57   ACCOUNT_ENABLED,
58   ACCOUNT_DISABLED,
59   ACCOUNT_CHANGED,
60   ACCOUNT_CONNECTION_CHANGED,
61   ACCOUNT_PRESENCE_CHANGED,
62   NEW_CONNECTION,
63   LAST_SIGNAL
64 };
65
66 static guint signals[LAST_SIGNAL];
67 static EmpathyAccountManager *manager_singleton = NULL;
68
69 G_DEFINE_TYPE (EmpathyAccountManager, empathy_account_manager, G_TYPE_OBJECT);
70
71 static AccountData *
72 account_data_new (McPresence presence,
73                   TpConnectionStatus status,
74                   gboolean is_enabled)
75 {
76   AccountData *retval;
77
78   retval = g_slice_new0 (AccountData);
79   retval->presence = presence;
80   retval->status = status;
81   retval->is_enabled = is_enabled;
82   retval->source_id = 0;
83
84   return retval;
85 }
86
87 static AccountData *
88 account_data_new_default (MissionControl *mc,
89                           McAccount *account)
90 {
91   McPresence actual_p;
92   TpConnectionStatus actual_c;
93   GError *err = NULL;
94
95   actual_p = mission_control_get_presence_actual (mc, &err);
96   if (err != NULL)
97     {
98       actual_p = MC_PRESENCE_UNSET;
99       g_clear_error (&err);
100     }
101
102   actual_c = mission_control_get_connection_status (mc, account, &err);
103
104   if (err != NULL)
105     {
106       actual_c = TP_CONNECTION_STATUS_DISCONNECTED;
107       g_error_free (err);
108     }
109
110   return account_data_new (actual_p, actual_c, mc_account_is_enabled (account));
111 }
112
113 static void
114 connection_invalidated_cb (TpProxy *connection,
115                            guint    domain,
116                            gint     code,
117                            gchar   *message,
118                            EmpathyAccountManager *manager)
119 {
120   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
121   McAccount *account;
122   AccountData *data;
123
124   DEBUG ("Message: %s", message);
125   account = g_hash_table_lookup (priv->connections, connection);
126   data = g_hash_table_lookup (priv->accounts, account);
127   g_object_unref (data->connection);
128   data->connection = NULL;
129   g_hash_table_remove (priv->connections, connection);
130 }
131
132 static void
133 account_data_free (AccountData *data)
134 {
135   if (data->source_id > 0)
136     {
137       g_source_remove (data->source_id);
138       data->source_id = 0;
139     }
140   if (data->connection != NULL)
141     {
142       g_object_unref (data->connection);
143       data->connection = NULL;
144     }
145
146   g_slice_free (AccountData, data);
147 }
148
149 static void
150 account_created_cb (McAccountMonitor *mon,
151                     gchar *account_name,
152                     EmpathyAccountManager *manager)
153 {
154   McAccount *account;
155   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
156   TpConnectionStatus initial_status;
157
158   account = mc_account_lookup (account_name);
159
160   if (account)
161     {
162       AccountData *data;
163
164       data = account_data_new_default (priv->mc, account);
165
166       initial_status = mission_control_get_connection_status (priv->mc,
167                                                               account, NULL);
168
169       if (initial_status == TP_CONNECTION_STATUS_CONNECTED)
170         priv->connected++;
171       else if (initial_status == TP_CONNECTION_STATUS_CONNECTING)
172         priv->connecting++;
173
174       /* the reference returned by mc_account_lookup is owned by the
175        * hash table.
176        */
177       g_hash_table_insert (priv->accounts, account, data);
178
179       g_signal_emit (manager, signals[ACCOUNT_CREATED], 0, account);
180     }
181 }
182
183 static void
184 account_deleted_cb (McAccountMonitor *mon,
185                     gchar *account_name,
186                     EmpathyAccountManager *manager)
187 {
188   McAccount *account;
189   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
190
191   account = mc_account_lookup (account_name);
192
193   if (account)
194     {
195       g_hash_table_remove (priv->accounts, account);
196       g_signal_emit (manager, signals[ACCOUNT_DELETED], 0, account);
197       g_object_unref (account);
198     }
199 }
200
201 static void
202 account_changed_cb (McAccountMonitor *mon,
203                     gchar *account_name,
204                     EmpathyAccountManager *manager)
205 {
206   McAccount *account;
207
208   account = mc_account_lookup (account_name);
209
210   if (account)
211     {
212       g_signal_emit (manager, signals[ACCOUNT_CHANGED], 0, account);
213       g_object_unref (account);
214     }
215 }
216
217 static void
218 account_disabled_cb (McAccountMonitor *mon,
219                      gchar *account_name,
220                      EmpathyAccountManager *manager)
221 {
222   McAccount *account;
223   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
224   AccountData *data;
225
226   account = mc_account_lookup (account_name);
227
228   if (account)
229     {
230       data = g_hash_table_lookup (priv->accounts, account);
231       g_assert (data);
232       data->is_enabled = FALSE;
233
234       g_signal_emit (manager, signals[ACCOUNT_DISABLED], 0, account);
235       g_object_unref (account);
236     }
237 }
238
239 static void
240 account_enabled_cb (McAccountMonitor *mon,
241                     gchar *account_name,
242                     EmpathyAccountManager *manager)
243 {
244   McAccount *account;
245   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
246   AccountData *data;
247
248   account = mc_account_lookup (account_name);
249
250   if (account)
251     {
252       data = g_hash_table_lookup (priv->accounts, account);
253       g_assert (data);
254       data->is_enabled = TRUE;
255
256       g_signal_emit (manager, signals[ACCOUNT_ENABLED], 0, account);
257       g_object_unref (account);
258     }
259 }
260
261 static void
262 update_connection_numbers (EmpathyAccountManager *manager,
263                            TpConnectionStatus status,
264                            TpConnectionStatus old_s)
265 {
266   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
267
268   if (status == TP_CONNECTION_STATUS_CONNECTED)
269     {
270       priv->connected++;
271       if (old_s == TP_CONNECTION_STATUS_CONNECTING)
272         priv->connecting--;
273     }
274
275   if (status == TP_CONNECTION_STATUS_CONNECTING)
276     {
277       priv->connecting++;
278       if (old_s == TP_CONNECTION_STATUS_CONNECTED)
279         priv->connected--;
280     }
281
282   if (status == TP_CONNECTION_STATUS_DISCONNECTED)
283     {
284       if (old_s == TP_CONNECTION_STATUS_CONNECTED)
285         priv->connected--;
286
287       if (old_s == TP_CONNECTION_STATUS_CONNECTING)
288         priv->connecting--;
289     }
290 }
291
292 static gboolean
293 remove_data_timeout (gpointer _data)
294 {
295   AccountData *data = _data;
296
297   data->source_id = 0;
298
299   return FALSE;
300 }
301
302 static void
303 connection_ready_cb (TpConnection *connection,
304                      const GError *error,
305                      gpointer manager)
306 {
307   /* Errors will be handled in invalidated callback */
308   if (error != NULL)
309     return;
310
311   g_signal_emit (manager, signals[NEW_CONNECTION], 0, connection);
312 }
313
314 typedef struct {
315   TpConnectionStatus status;
316   McPresence presence;
317   TpConnectionStatusReason reason;
318   gchar *unique_name;
319   EmpathyAccountManager *manager;
320 } ChangedSignalData;
321
322 static gboolean
323 account_status_changed_idle_cb (ChangedSignalData *signal_data)
324 {
325   McAccount *account;
326   AccountData *data;
327   McPresence presence, old_p;
328   TpConnectionStatus status, old_s;
329   gboolean emit_presence = FALSE, emit_connection = FALSE;
330   EmpathyAccountManager *manager = signal_data->manager;
331   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
332
333   presence = signal_data->presence;
334   status = signal_data->status;
335   account = mc_account_lookup (signal_data->unique_name);
336
337   if (account)
338     {
339       data = g_hash_table_lookup (priv->accounts, account);
340       g_assert (data);
341
342       old_p = data->presence;
343       old_s = data->status;
344
345       if (old_p != presence)
346         {
347           data->presence = presence;
348           emit_presence = TRUE;
349         }
350
351       if (old_s != status)
352         {
353           data->status = status;
354           update_connection_numbers (manager, status, old_s);
355
356           if (status == TP_CONNECTION_STATUS_CONNECTED)
357             {
358                 if (data->source_id > 0) {
359                   g_source_remove (data->source_id);
360                   data->source_id = 0;
361                 }
362
363                 data->source_id = g_timeout_add_seconds (10,
364                                                          remove_data_timeout,
365                                                          data);
366             }
367           emit_connection = TRUE;
368         }
369
370       if (data->connection == NULL)
371         {
372           data->connection = mission_control_get_tpconnection (priv->mc,
373               account, NULL);
374           if (data->connection != NULL)
375             {
376               g_signal_connect (data->connection, "invalidated",
377                   G_CALLBACK (connection_invalidated_cb), manager);
378               g_hash_table_insert (priv->connections,
379                   g_object_ref (data->connection), g_object_ref (account));
380               tp_connection_call_when_ready (data->connection,
381                   connection_ready_cb, manager);
382             }
383         }
384
385       if (emit_presence)
386         g_signal_emit (manager, signals[ACCOUNT_PRESENCE_CHANGED], 0,
387                        account, presence, old_p);
388
389       if (emit_connection)
390         g_signal_emit (manager, signals[ACCOUNT_CONNECTION_CHANGED], 0,
391                        account, signal_data->reason, status, old_s);
392
393       g_object_unref (account);
394     }
395
396   g_object_unref (signal_data->manager);
397   g_free (signal_data->unique_name);
398   g_slice_free (ChangedSignalData, signal_data);
399
400   return FALSE;
401 }
402
403 static void
404 account_status_changed_cb (MissionControl *mc,
405                            TpConnectionStatus status,
406                            McPresence presence,
407                            TpConnectionStatusReason reason,
408                            const gchar *unique_name,
409                            EmpathyAccountManager *manager)
410 {
411   ChangedSignalData *data;
412
413   data = g_slice_new0 (ChangedSignalData);
414   data->status = status;
415   data->presence = presence;
416   data->reason = reason;
417   data->unique_name = g_strdup (unique_name);
418   data->manager = g_object_ref (manager);
419
420   g_idle_add ((GSourceFunc) account_status_changed_idle_cb, data);
421 }
422
423 static void
424 empathy_account_manager_init (EmpathyAccountManager *manager)
425 {
426   EmpathyAccountManagerPriv *priv;
427   GList *mc_accounts, *l;
428
429   priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
430                                       EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerPriv);
431   manager->priv = priv;
432   priv->monitor = mc_account_monitor_new ();
433   priv->mc = empathy_mission_control_dup_singleton ();
434   priv->connected = priv->connecting = 0;
435   priv->dispose_run = FALSE;
436
437   priv->accounts = g_hash_table_new_full (empathy_account_hash,
438                                           empathy_account_equal,
439                                           g_object_unref, 
440                                           (GDestroyNotify) account_data_free);
441   priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal,
442                                              g_object_unref, g_object_unref);
443
444   mc_accounts = mc_accounts_list ();
445
446   for (l = mc_accounts; l; l = l->next)
447     account_created_cb (priv->monitor, (char *) mc_account_get_unique_name (l->data), manager);
448
449   g_signal_connect (priv->monitor, "account-created",
450                     G_CALLBACK (account_created_cb), manager);
451   g_signal_connect (priv->monitor, "account-deleted",
452                     G_CALLBACK (account_deleted_cb), manager);
453   g_signal_connect (priv->monitor, "account-disabled",
454                     G_CALLBACK (account_disabled_cb), manager);
455   g_signal_connect (priv->monitor, "account-enabled",
456                     G_CALLBACK (account_enabled_cb), manager);
457   g_signal_connect (priv->monitor, "account-changed",
458                     G_CALLBACK (account_changed_cb), manager);
459
460   dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged",
461                                G_CALLBACK (account_status_changed_cb),
462                                manager, NULL);
463
464   mc_accounts_list_free (mc_accounts);
465 }
466
467 static void
468 do_finalize (GObject *obj)
469 {
470   EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (obj);
471   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
472
473   g_hash_table_unref (priv->accounts);
474   g_hash_table_unref (priv->connections);
475
476   G_OBJECT_CLASS (empathy_account_manager_parent_class)->finalize (obj);
477 }
478
479 static void
480 do_dispose (GObject *obj)
481 {
482   EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (obj);
483   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
484
485   if (priv->dispose_run)
486     return;
487
488   priv->dispose_run = TRUE;
489
490   dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
491                                   "AccountStatusChanged",
492                                   G_CALLBACK (account_status_changed_cb),
493                                   obj);
494
495   if (priv->monitor)
496     {
497       g_signal_handlers_disconnect_by_func (priv->monitor,
498                                             account_created_cb, obj);
499       g_signal_handlers_disconnect_by_func (priv->monitor,
500                                             account_deleted_cb, obj);
501       g_signal_handlers_disconnect_by_func (priv->monitor,
502                                             account_disabled_cb, obj);
503       g_signal_handlers_disconnect_by_func (priv->monitor,
504                                             account_enabled_cb, obj);
505       g_signal_handlers_disconnect_by_func (priv->monitor,
506                                             account_changed_cb, obj);
507       g_object_unref (priv->monitor);
508       priv->monitor = NULL;
509     }
510
511   if (priv->mc)
512     g_object_unref (priv->mc);
513
514   g_hash_table_remove_all (priv->accounts);
515
516   G_OBJECT_CLASS (empathy_account_manager_parent_class)->dispose (obj);
517 }
518
519 static GObject*
520 do_constructor (GType type,
521                 guint n_construct_params,
522                 GObjectConstructParam *construct_params)
523 {
524   GObject *retval;
525
526   if (!manager_singleton)
527     {
528       retval = G_OBJECT_CLASS (empathy_account_manager_parent_class)->constructor (type,
529                                                                                    n_construct_params,
530                                                                                    construct_params);
531       manager_singleton = EMPATHY_ACCOUNT_MANAGER (retval);
532       g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
533     }
534   else
535     {
536       retval = g_object_ref (manager_singleton);
537     }
538
539   return retval;
540 }
541
542 static void
543 empathy_account_manager_class_init (EmpathyAccountManagerClass *klass)
544 {
545   GObjectClass *oclass = G_OBJECT_CLASS (klass);
546
547   oclass->finalize = do_finalize;
548   oclass->dispose = do_dispose;
549   oclass->constructor = do_constructor;
550
551   signals[ACCOUNT_CREATED] =
552     g_signal_new ("account-created",
553                   G_TYPE_FROM_CLASS (klass),
554                   G_SIGNAL_RUN_LAST,
555                   0,
556                   NULL, NULL,
557                   g_cclosure_marshal_VOID__OBJECT,
558                   G_TYPE_NONE,
559                   1, MC_TYPE_ACCOUNT);
560
561   signals[ACCOUNT_DELETED] =
562     g_signal_new ("account-deleted",
563                   G_TYPE_FROM_CLASS (klass),
564                   G_SIGNAL_RUN_LAST,
565                   0,
566                   NULL, NULL,
567                   g_cclosure_marshal_VOID__OBJECT,
568                   G_TYPE_NONE,
569                   1, MC_TYPE_ACCOUNT);
570
571   signals[ACCOUNT_ENABLED] =
572     g_signal_new ("account-enabled",
573                   G_TYPE_FROM_CLASS (klass),
574                   G_SIGNAL_RUN_LAST,
575                   0,
576                   NULL, NULL,
577                   g_cclosure_marshal_VOID__OBJECT,
578                   G_TYPE_NONE,
579                   1, MC_TYPE_ACCOUNT);
580
581   signals[ACCOUNT_DISABLED] =
582     g_signal_new ("account-disabled",
583                   G_TYPE_FROM_CLASS (klass),
584                   G_SIGNAL_RUN_LAST,
585                   0,
586                   NULL, NULL,
587                   g_cclosure_marshal_VOID__OBJECT,
588                   G_TYPE_NONE,
589                   1, MC_TYPE_ACCOUNT);
590
591   signals[ACCOUNT_CHANGED] =
592     g_signal_new ("account-changed",
593                   G_TYPE_FROM_CLASS (klass),
594                   G_SIGNAL_RUN_LAST,
595                   0,
596                   NULL, NULL,
597                   g_cclosure_marshal_VOID__OBJECT,
598                   G_TYPE_NONE,
599                   1, MC_TYPE_ACCOUNT);
600
601   signals[ACCOUNT_CONNECTION_CHANGED] =
602     g_signal_new ("account-connection-changed",
603                   G_TYPE_FROM_CLASS (klass),
604                   G_SIGNAL_RUN_LAST,
605                   0,
606                   NULL, NULL,
607                   _empathy_marshal_VOID__OBJECT_INT_UINT_UINT,
608                   G_TYPE_NONE,
609                   4, MC_TYPE_ACCOUNT,
610                   G_TYPE_INT,   /* reason */
611                   G_TYPE_UINT,  /* actual connection */
612                   G_TYPE_UINT); /* previous connection */
613
614   signals[ACCOUNT_PRESENCE_CHANGED] =
615     g_signal_new ("account-presence-changed",
616                   G_TYPE_FROM_CLASS (klass),
617                   G_SIGNAL_RUN_LAST,
618                   0,
619                   NULL, NULL,
620                   _empathy_marshal_VOID__OBJECT_INT_INT,
621                   G_TYPE_NONE,
622                   3, MC_TYPE_ACCOUNT,
623                   G_TYPE_INT,  /* actual presence */
624                   G_TYPE_INT); /* previous presence */
625
626   signals[NEW_CONNECTION] =
627     g_signal_new ("new-connection",
628                   G_TYPE_FROM_CLASS (klass),
629                   G_SIGNAL_RUN_LAST,
630                   0,
631                   NULL, NULL,
632                   g_cclosure_marshal_VOID__OBJECT,
633                   G_TYPE_NONE,
634                   1, TP_TYPE_CONNECTION);
635   
636   g_type_class_add_private (oclass, sizeof (EmpathyAccountManagerPriv));
637 }
638
639 /* public methods */
640
641 EmpathyAccountManager *
642 empathy_account_manager_dup_singleton (void)
643 {
644   return g_object_new (EMPATHY_TYPE_ACCOUNT_MANAGER, NULL);
645 }
646
647 int
648 empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager)
649 {
650   EmpathyAccountManagerPriv *priv;
651
652   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), 0);
653
654   priv = GET_PRIV (manager);
655
656   return priv->connected;
657 }
658
659 int
660 empathy_account_manager_get_connecting_accounts (EmpathyAccountManager *manager)
661 {
662   EmpathyAccountManagerPriv *priv;
663
664   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), 0);
665
666   priv = GET_PRIV (manager);
667
668   return priv->connecting;
669 }
670
671 gboolean
672 empathy_account_manager_is_account_just_connected (EmpathyAccountManager *manager,
673                                                    McAccount *account)
674 {
675   EmpathyAccountManagerPriv *priv;
676   AccountData *data;
677
678   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), FALSE);
679
680   priv = GET_PRIV (manager);
681   data = g_hash_table_lookup (priv->accounts, account);
682
683   g_assert (data);
684
685   return (data->source_id > 0);
686 }
687
688 /**
689  * empathy_account_manager_get_count:
690  * @manager: a #EmpathyAccountManager
691  *
692  * Get the number of accounts.
693  *
694  * Returns: the number of accounts.
695  **/
696 int
697 empathy_account_manager_get_count (EmpathyAccountManager *manager)
698 {
699   EmpathyAccountManagerPriv *priv;
700
701   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), 0);
702
703   priv = GET_PRIV (manager);
704
705   return g_hash_table_size (priv->accounts);
706 }
707
708 McAccount *
709 empathy_account_manager_get_account (EmpathyAccountManager *manager,
710                                      TpConnection          *connection)
711 {
712   EmpathyAccountManagerPriv *priv;
713
714   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), 0);
715
716   priv = GET_PRIV (manager);
717
718   return g_hash_table_lookup (priv->connections, connection);
719 }
720
721 GList *
722 empathy_account_manager_dup_accounts (EmpathyAccountManager *manager)
723 {
724   EmpathyAccountManagerPriv *priv;
725   GList *ret;
726
727   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), NULL);
728
729   priv = GET_PRIV (manager);
730
731   ret = g_hash_table_get_keys (priv->accounts);
732   g_list_foreach (ret, (GFunc) g_object_ref, NULL);
733
734   return ret;
735 }
736
737 /**
738  * empathy_account_manager_get_connection:
739  * @manager: a #EmpathyAccountManager
740  * @account: a #McAccount
741  *
742  * Get the connection of the accounts, or NULL if account is offline or the
743  * connection is not yet ready.
744  *
745  * Returns: the connection of the accounts.
746  **/
747 TpConnection *
748 empathy_account_manager_get_connection (EmpathyAccountManager *manager,
749                                         McAccount *account)
750 {
751   EmpathyAccountManagerPriv *priv;
752   AccountData *data;
753
754   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), NULL);
755   g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
756
757   priv = GET_PRIV (manager);
758
759   data = g_hash_table_lookup (priv->accounts, account);
760   if (data && data->connection && tp_connection_is_ready (data->connection))
761     return data->connection;
762
763   return NULL;
764 }
765
766 GList *
767 empathy_account_manager_dup_connections (EmpathyAccountManager *manager)
768 {
769   EmpathyAccountManagerPriv *priv;
770   GHashTableIter iter;
771   gpointer connection;
772   GList *ret = NULL;
773
774   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_MANAGER (manager), NULL);
775
776   priv = GET_PRIV (manager);
777
778   g_hash_table_iter_init (&iter, priv->connections);
779   while (g_hash_table_iter_next (&iter, &connection, NULL)) 
780     if (connection != NULL && tp_connection_is_ready (connection))
781       ret = g_list_prepend (ret, g_object_ref (connection));
782
783   return ret;
784 }
785