diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-01-20 22:50:44 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-01-25 22:13:38 +0800 |
commit | 17ea62102f51a9d6e50a12f516fec4af60ce0c88 (patch) | |
tree | 2709c251b1a58f43b2349582ef4bc7f7fd678343 /src | |
parent | b7936254660d147c7fb683a477b2db728ea72723 (diff) | |
download | gsoc2013-empathy-17ea62102f51a9d6e50a12f516fec4af60ce0c88.tar gsoc2013-empathy-17ea62102f51a9d6e50a12f516fec4af60ce0c88.tar.gz gsoc2013-empathy-17ea62102f51a9d6e50a12f516fec4af60ce0c88.tar.bz2 gsoc2013-empathy-17ea62102f51a9d6e50a12f516fec4af60ce0c88.tar.lz gsoc2013-empathy-17ea62102f51a9d6e50a12f516fec4af60ce0c88.tar.xz gsoc2013-empathy-17ea62102f51a9d6e50a12f516fec4af60ce0c88.tar.zst gsoc2013-empathy-17ea62102f51a9d6e50a12f516fec4af60ce0c88.zip |
factor out and export create_salut_account_settings
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-auto-salut-account-helper.c | 113 | ||||
-rw-r--r-- | src/empathy-auto-salut-account-helper.h | 3 |
2 files changed, 68 insertions, 48 deletions
diff --git a/src/empathy-auto-salut-account-helper.c b/src/empathy-auto-salut-account-helper.c index 30842dd43..85ead8ef6 100644 --- a/src/empathy-auto-salut-account-helper.c +++ b/src/empathy-auto-salut-account-helper.c @@ -103,6 +103,67 @@ salut_account_created (GObject *source, TRUE); } +EmpathyAccountSettings * +create_salut_account_settings (void) +{ + EmpathyAccountSettings *settings; + EBook *book; + EContact *contact; + gchar *nickname = NULL; + gchar *first_name = NULL; + gchar *last_name = NULL; + gchar *email = NULL; + gchar *jid = NULL; + GError *error = NULL; + + settings = empathy_account_settings_new ("salut", "local-xmpp", + _("People nearby")); + + /* Get self EContact from EDS */ + if (!e_book_get_self (&contact, &book, &error)) + { + DEBUG ("Failed to get self econtact: %s", + error ? error->message : "No error given"); + g_error_free (error); + return settings; + } + + nickname = e_contact_get (contact, E_CONTACT_NICKNAME); + first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); + last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME); + email = e_contact_get (contact, E_CONTACT_EMAIL_1); + jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1); + + if (!tp_strdiff (nickname, "nickname")) + { + g_free (nickname); + nickname = NULL; + } + + DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n" + "last-name=%s\nemail=%s\njid=%s\n", + nickname, first_name, last_name, email, jid); + + empathy_account_settings_set_string (settings, + "nickname", nickname ? nickname : ""); + empathy_account_settings_set_string (settings, + "first-name", first_name ? first_name : ""); + empathy_account_settings_set_string (settings, + "last-name", last_name ? last_name : ""); + empathy_account_settings_set_string (settings, "email", email ? email : ""); + empathy_account_settings_set_string (settings, "jid", jid ? jid : ""); + + g_free (nickname); + g_free (first_name); + g_free (last_name); + g_free (email); + g_free (jid); + g_object_unref (contact); + g_object_unref (book); + + return settings; +} + static void create_salut_account_am_ready_cb (GObject *source_object, GAsyncResult *result, @@ -113,13 +174,6 @@ create_salut_account_am_ready_cb (GObject *source_object, EmpathyAccountSettings *settings; TpConnectionManager *manager; const TpConnectionManagerProtocol *protocol; - EBook *book; - EContact *contact; - gchar *nickname = NULL; - gchar *first_name = NULL; - gchar *last_name = NULL; - gchar *email = NULL; - gchar *jid = NULL; GError *error = NULL; if (!tp_account_manager_prepare_finish (account_manager, result, &error)) @@ -148,56 +202,19 @@ create_salut_account_am_ready_cb (GObject *source_object, DEBUG ("Trying to add a salut account..."); - /* Get self EContact from EDS */ - if (!e_book_get_self (&contact, &book, &error)) + settings = create_salut_account_settings (); + if (!empathy_account_settings_is_valid (settings)) { - DEBUG ("Failed to get self econtact: %s", - error ? error->message : "No error given"); - g_clear_error (&error); + g_object_unref (settings); goto out; } - settings = empathy_account_settings_new ("salut", "local-xmpp", - _("People nearby")); - - nickname = e_contact_get (contact, E_CONTACT_NICKNAME); - first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); - last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME); - email = e_contact_get (contact, E_CONTACT_EMAIL_1); - jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1); - - if (!tp_strdiff (nickname, "nickname")) - { - g_free (nickname); - nickname = NULL; - } - - DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n" - "last-name=%s\nemail=%s\njid=%s\n", - nickname, first_name, last_name, email, jid); - - empathy_account_settings_set_string (settings, - "nickname", nickname ? nickname : ""); - empathy_account_settings_set_string (settings, - "first-name", first_name ? first_name : ""); - empathy_account_settings_set_string (settings, - "last-name", last_name ? last_name : ""); - empathy_account_settings_set_string (settings, "email", email ? email : ""); - empathy_account_settings_set_string (settings, "jid", jid ? jid : ""); - empathy_account_settings_apply_async (settings, salut_account_created, NULL); - g_free (nickname); - g_free (first_name); - g_free (last_name); - g_free (email); - g_free (jid); g_object_unref (settings); - g_object_unref (contact); - g_object_unref (book); - out: +out: g_object_unref (managers); } diff --git a/src/empathy-auto-salut-account-helper.h b/src/empathy-auto-salut-account-helper.h index 8cec7b8ff..16e8905e7 100644 --- a/src/empathy-auto-salut-account-helper.h +++ b/src/empathy-auto-salut-account-helper.h @@ -27,9 +27,12 @@ #include <telepathy-glib/account-manager.h> #include <libempathy/empathy-connection-managers.h> +#include <libempathy/empathy-account-settings.h> void create_salut_account_if_needed (void); gboolean should_create_salut_account (TpAccountManager *manager); +EmpathyAccountSettings * create_salut_account_settings (void); + #endif |