2 * Copyright (C) 2007-2010 Collabora Ltd.
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.
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.
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
18 * Authors: Xavier Claessens <xclaesse@gmail.com>
19 * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
23 #include <glib/gi18n.h>
25 #include <telepathy-glib/account-manager.h>
26 #include <telepathy-glib/util.h>
27 #include <libebook/e-book.h>
29 #include <libempathy/empathy-account-settings.h>
30 #include <libempathy-gtk/empathy-conf.h>
32 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
33 #include <libempathy/empathy-debug.h>
35 #include "empathy-auto-salut-account-helper.h"
37 /* Salut account creation. The TpAccountManager first argument
38 * must already be prepared when calling this function. */
40 should_create_salut_account (TpAccountManager *manager)
42 gboolean salut_created = FALSE;
45 accounts = tp_account_manager_get_valid_accounts (manager);
47 for (l = accounts; l != NULL; l = g_list_next (l))
49 TpAccount *account = TP_ACCOUNT (l->data);
51 if (!tp_strdiff (tp_account_get_protocol (account), "local-xmpp"))
58 g_list_free (accounts);
60 return !salut_created;
63 EmpathyAccountSettings *
64 create_salut_account_settings (void)
66 EmpathyAccountSettings *settings;
69 gchar *nickname = NULL;
70 gchar *first_name = NULL;
71 gchar *last_name = NULL;
76 settings = empathy_account_settings_new ("salut", "local-xmpp",
79 /* Get self EContact from EDS */
80 if (!e_book_get_self (&contact, &book, &error))
82 DEBUG ("Failed to get self econtact: %s", error->message);
87 nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
88 first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
89 last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
90 email = e_contact_get (contact, E_CONTACT_EMAIL_1);
91 jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
93 if (!tp_strdiff (nickname, "nickname"))
99 DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
100 "last-name=%s\nemail=%s\njid=%s\n",
101 nickname, first_name, last_name, email, jid);
103 empathy_account_settings_set_string (settings,
104 "nickname", nickname ? nickname : "");
105 empathy_account_settings_set_string (settings,
106 "first-name", first_name ? first_name : "");
107 empathy_account_settings_set_string (settings,
108 "last-name", last_name ? last_name : "");
109 empathy_account_settings_set_string (settings, "email", email ? email : "");
110 empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
117 g_object_unref (contact);
118 g_object_unref (book);