]> git.0d.be Git - empathy.git/blob - src/empathy-auto-salut-account-helper.c
remove create_salut_account_if_needed as it's done in the assistant now
[empathy.git] / src / empathy-auto-salut-account-helper.c
1 /*
2  * Copyright (C) 2007-2010 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: Xavier Claessens <xclaesse@gmail.com>
19  *          Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
20  */
21
22 #include <glib.h>
23 #include <glib/gi18n.h>
24
25 #include <telepathy-glib/account-manager.h>
26 #include <telepathy-glib/util.h>
27 #include <libebook/e-book.h>
28
29 #include <libempathy/empathy-account-settings.h>
30 #include <libempathy-gtk/empathy-conf.h>
31
32 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
33 #include <libempathy/empathy-debug.h>
34
35 #include "empathy-auto-salut-account-helper.h"
36
37 /* Salut account creation. The TpAccountManager first argument
38  * must already be prepared when calling this function. */
39 gboolean
40 should_create_salut_account (TpAccountManager *manager)
41 {
42   gboolean salut_created = FALSE;
43   GList *accounts, *l;
44
45   /* Check if we already created a salut account */
46   empathy_conf_get_bool (empathy_conf_get (),
47       EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
48       &salut_created);
49
50   if (salut_created)
51     {
52       DEBUG ("Gconf says we already created a salut account once");
53       return FALSE;
54     }
55
56   accounts = tp_account_manager_get_valid_accounts (manager);
57
58   for (l = accounts; l != NULL;  l = g_list_next (l))
59     {
60       TpAccount *account = TP_ACCOUNT (l->data);
61
62       if (!tp_strdiff (tp_account_get_protocol (account), "local-xmpp"))
63         {
64           salut_created = TRUE;
65           break;
66         }
67     }
68
69   g_list_free (accounts);
70
71   if (salut_created)
72     {
73       DEBUG ("Existing salut account already exists, flagging so in gconf");
74       empathy_conf_set_bool (empathy_conf_get (),
75           EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
76           TRUE);
77     }
78
79   return !salut_created;
80 }
81
82 EmpathyAccountSettings *
83 create_salut_account_settings (void)
84 {
85   EmpathyAccountSettings  *settings;
86   EBook *book;
87   EContact *contact;
88   gchar *nickname = NULL;
89   gchar *first_name = NULL;
90   gchar *last_name = NULL;
91   gchar *email = NULL;
92   gchar *jid = NULL;
93   GError *error = NULL;
94
95   settings = empathy_account_settings_new ("salut", "local-xmpp",
96       _("People nearby"));
97
98   /* Get self EContact from EDS */
99   if (!e_book_get_self (&contact, &book, &error))
100     {
101       DEBUG ("Failed to get self econtact: %s",
102           error ? error->message : "No error given");
103       g_error_free (error);
104       return settings;
105     }
106
107   nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
108   first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
109   last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
110   email = e_contact_get (contact, E_CONTACT_EMAIL_1);
111   jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
112
113   if (!tp_strdiff (nickname, "nickname"))
114     {
115       g_free (nickname);
116       nickname = NULL;
117     }
118
119   DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
120      "last-name=%s\nemail=%s\njid=%s\n",
121      nickname, first_name, last_name, email, jid);
122
123   empathy_account_settings_set_string (settings,
124       "nickname", nickname ? nickname : "");
125   empathy_account_settings_set_string (settings,
126       "first-name", first_name ? first_name : "");
127   empathy_account_settings_set_string (settings,
128       "last-name", last_name ? last_name : "");
129   empathy_account_settings_set_string (settings, "email", email ? email : "");
130   empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
131
132   g_free (nickname);
133   g_free (first_name);
134   g_free (last_name);
135   g_free (email);
136   g_free (jid);
137   g_object_unref (contact);
138   g_object_unref (book);
139
140   return settings;
141 }