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>
25 #include <glib/gi18n-lib.h>
27 #include <telepathy-glib/account-manager.h>
28 #include <telepathy-glib/util.h>
31 #include <libebook/e-book.h>
34 #include <libempathy/empathy-account-settings.h>
36 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
37 #include <libempathy/empathy-debug.h>
39 #include "empathy-auto-salut-account-helper.h"
41 /* Salut account creation. The TpAccountManager first argument
42 * must already be prepared when calling this function. */
44 should_create_salut_account (TpAccountManager
*manager
)
46 gboolean salut_created
= FALSE
;
49 accounts
= tp_account_manager_get_valid_accounts (manager
);
51 for (l
= accounts
; l
!= NULL
; l
= g_list_next (l
))
53 TpAccount
*account
= TP_ACCOUNT (l
->data
);
55 if (!tp_strdiff (tp_account_get_protocol (account
), "local-xmpp"))
62 g_list_free (accounts
);
64 return !salut_created
;
67 EmpathyAccountSettings
*
68 create_salut_account_settings (void)
70 EmpathyAccountSettings
*settings
;
74 gchar
*nickname
= NULL
;
75 gchar
*first_name
= NULL
;
76 gchar
*last_name
= NULL
;
82 settings
= empathy_account_settings_new ("salut", "local-xmpp", NULL
,
86 /* Get self EContact from EDS */
87 if (!e_book_get_self (&contact
, &book
, &error
))
89 DEBUG ("Failed to get self econtact: %s", error
->message
);
94 nickname
= e_contact_get (contact
, E_CONTACT_NICKNAME
);
95 first_name
= e_contact_get (contact
, E_CONTACT_GIVEN_NAME
);
96 last_name
= e_contact_get (contact
, E_CONTACT_FAMILY_NAME
);
97 email
= e_contact_get (contact
, E_CONTACT_EMAIL_1
);
98 jid
= e_contact_get (contact
, E_CONTACT_IM_JABBER_HOME_1
);
100 if (!tp_strdiff (nickname
, "nickname"))
106 DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
107 "last-name=%s\nemail=%s\njid=%s\n",
108 nickname
, first_name
, last_name
, email
, jid
);
110 empathy_account_settings_set_string (settings
,
111 "nickname", nickname
? nickname
: "");
112 empathy_account_settings_set_string (settings
,
113 "first-name", first_name
? first_name
: "");
114 empathy_account_settings_set_string (settings
,
115 "last-name", last_name
? last_name
: "");
116 empathy_account_settings_set_string (settings
, "email", email
? email
: "");
117 empathy_account_settings_set_string (settings
, "jid", jid
? jid
: "");
124 g_object_unref (contact
);
125 g_object_unref (book
);