]> git.0d.be Git - empathy.git/blob - src/empathy-import-utils.c
768d493fe927cf1949bbac36b1c8ad184c8f35d4
[empathy.git] / src / empathy-import-utils.c
1 /*
2  * Copyright (C) 2009 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: Jonny Lamb <jonny.lamb@collabora.co.uk>
19  *          Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
20  */
21
22 #include "libempathy/empathy-connection-managers.h"
23 #include "libempathy/empathy-utils.h"
24
25 #include "empathy-import-utils.h"
26 #include "empathy-import-pidgin.h"
27
28 EmpathyImportAccountData *
29 empathy_import_account_data_new (const gchar *source)
30 {
31   EmpathyImportAccountData *data;
32
33   g_return_val_if_fail (!EMP_STR_EMPTY (source), NULL);
34
35   data = g_slice_new0 (EmpathyImportAccountData);
36   data->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
37     (GDestroyNotify) tp_g_value_slice_free);
38   data->source = g_strdup (source);
39   data->protocol = NULL;
40   data->connection_manager = NULL;
41   data->enabled = FALSE;
42
43   return data;
44 }
45
46 void
47 empathy_import_account_data_free (EmpathyImportAccountData *data)
48 {
49   if (data == NULL)
50     return;
51   if (data->protocol != NULL)
52     g_free (data->protocol);
53   if (data->connection_manager != NULL)
54     g_free (data->connection_manager);
55   if (data->settings != NULL)
56     g_hash_table_unref (data->settings);
57   if (data->source != NULL)
58     g_free (data->source);
59
60   g_slice_free (EmpathyImportAccountData, data);
61 }
62
63 gboolean
64 empathy_import_accounts_to_import (void)
65 {
66   return empathy_import_pidgin_accounts_to_import ();
67 }
68
69 GList *
70 empathy_import_accounts_load (EmpathyImportApplication id)
71 {
72   if (id == EMPATHY_IMPORT_APPLICATION_PIDGIN)
73     return empathy_import_pidgin_load ();
74
75   return empathy_import_pidgin_load ();
76 }
77
78 gboolean
79 empathy_import_protocol_is_supported (const gchar *protocol,
80     TpConnectionManager **cm)
81 {
82   EmpathyConnectionManagers *manager;
83   GList *cms;
84   GList *l;
85   gboolean proto_is_supported = FALSE;
86
87   manager = empathy_connection_managers_dup_singleton ();
88   cms = empathy_connection_managers_get_cms (manager);
89
90   for (l = cms; l; l = l->next)
91     {
92
93       TpConnectionManager *tp_cm = l->data;
94       if (tp_connection_manager_has_protocol (tp_cm,
95           (const gchar*) protocol))
96         {
97           if (!tp_strdiff (protocol, "irc")
98               && !tp_strdiff (tp_connection_manager_get_name (tp_cm), "haze"))
99               continue;
100
101           if (!proto_is_supported)
102             {
103               *cm = tp_cm;
104               proto_is_supported = TRUE;
105
106               continue;
107             }
108
109           /* we have more than one CM for this protocol,
110            * select the one which is not haze.
111            */
112           if (!tp_strdiff (tp_connection_manager_get_name ((*cm)), "haze"))
113             {
114               *cm = tp_cm;
115               break;
116             }
117         }
118     }
119
120   g_object_unref (manager);
121
122   return proto_is_supported;
123 }