Merge branch 'more-contact-info'
[empathy-mirror.git] / src / empathy-auto-salut-account-helper.c
blob409b6936c66ef741385226b1d4c49dc98b8849f1
1 /*
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>
22 #include <config.h>
24 #include <glib.h>
25 #include <glib/gi18n-lib.h>
27 #include <telepathy-glib/account-manager.h>
28 #include <telepathy-glib/util.h>
30 #if HAVE_EDS
31 #include <libebook/e-book.h>
32 #endif
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. */
43 gboolean
44 should_create_salut_account (TpAccountManager *manager)
46 gboolean salut_created = FALSE;
47 GList *accounts, *l;
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"))
57 salut_created = TRUE;
58 break;
62 g_list_free (accounts);
64 return !salut_created;
67 EmpathyAccountSettings *
68 create_salut_account_settings (void)
70 EmpathyAccountSettings *settings;
71 #if HAVE_EDS
72 EBook *book;
73 EContact *contact;
74 gchar *nickname = NULL;
75 gchar *first_name = NULL;
76 gchar *last_name = NULL;
77 gchar *email = NULL;
78 gchar *jid = NULL;
79 GError *error = NULL;
80 #endif
82 settings = empathy_account_settings_new ("salut", "local-xmpp", NULL,
83 _("People nearby"));
85 #if HAVE_EDS
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);
90 g_error_free (error);
91 return settings;
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"))
102 g_free (nickname);
103 nickname = NULL;
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 : "");
119 g_free (nickname);
120 g_free (first_name);
121 g_free (last_name);
122 g_free (email);
123 g_free (jid);
124 g_object_unref (contact);
125 g_object_unref (book);
126 #endif
128 return settings;