aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-01-19 22:40:57 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-01-20 00:11:11 +0800
commit452df1568e0a3e74a49c92c00840e15c788215ce (patch)
tree148946799418b52570340e6d94a5be394976379a /src
parentc4f65286eb3b7f82d25afa63c5204a98bd85408a (diff)
downloadgsoc2013-empathy-452df1568e0a3e74a49c92c00840e15c788215ce.tar
gsoc2013-empathy-452df1568e0a3e74a49c92c00840e15c788215ce.tar.gz
gsoc2013-empathy-452df1568e0a3e74a49c92c00840e15c788215ce.tar.bz2
gsoc2013-empathy-452df1568e0a3e74a49c92c00840e15c788215ce.tar.lz
gsoc2013-empathy-452df1568e0a3e74a49c92c00840e15c788215ce.tar.xz
gsoc2013-empathy-452df1568e0a3e74a49c92c00840e15c788215ce.tar.zst
gsoc2013-empathy-452df1568e0a3e74a49c92c00840e15c788215ce.zip
move create_salut_account_if_needed and should_create_salut_account to a new file
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/empathy-auto-salut-account-helper.c215
-rw-r--r--src/empathy-auto-salut-account-helper.h35
-rw-r--r--src/empathy.c182
4 files changed, 252 insertions, 181 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 6360dee09..24ba7b405 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,6 +29,7 @@ empathy_handwritten_source = \
empathy-about-dialog.c empathy-about-dialog.h \
empathy-account-assistant.c empathy-account-assistant.h \
empathy-accounts-dialog.c empathy-accounts-dialog.h \
+ empathy-auto-salut-account-helper.c empathy-auto-salut-account-helper.h \
empathy-call-window-fullscreen.c empathy-call-window-fullscreen.h \
empathy-call-window.c empathy-call-window.h \
empathy-chat-window.c empathy-chat-window.h \
diff --git a/src/empathy-auto-salut-account-helper.c b/src/empathy-auto-salut-account-helper.c
new file mode 100644
index 000000000..a6bbf88d9
--- /dev/null
+++ b/src/empathy-auto-salut-account-helper.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2007-2010 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
+ * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include <telepathy-glib/account-manager.h>
+#include <telepathy-glib/util.h>
+#include <libebook/e-book.h>
+
+#include <libempathy/empathy-account-settings.h>
+#include <libempathy-gtk/empathy-conf.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
+#include <libempathy/empathy-debug.h>
+
+#include "empathy-auto-salut-account-helper.h"
+
+/* Salut account creation. The TpAccountManager first argument
+ * must already be prepared when calling this function. */
+gboolean
+should_create_salut_account (TpAccountManager *manager)
+{
+ gboolean salut_created = FALSE;
+ GList *accounts, *l;
+
+ /* Check if we already created a salut account */
+ empathy_conf_get_bool (empathy_conf_get (),
+ EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
+ &salut_created);
+
+ if (salut_created)
+ {
+ DEBUG ("Gconf says we already created a salut account once");
+ return FALSE;
+ }
+
+ accounts = tp_account_manager_get_valid_accounts (manager);
+
+ for (l = accounts; l != NULL; l = g_list_next (l))
+ {
+ TpAccount *account = TP_ACCOUNT (l->data);
+
+ if (!tp_strdiff (tp_account_get_protocol (account), "local-xmpp"))
+ {
+ salut_created = TRUE;
+ break;
+ }
+ }
+
+ g_list_free (accounts);
+
+ if (salut_created)
+ {
+ DEBUG ("Existing salut account already exists, flagging so in gconf");
+ empathy_conf_set_bool (empathy_conf_get (),
+ EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
+ TRUE);
+ }
+
+ return !salut_created;
+}
+
+static void
+salut_account_created (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
+ TpAccount *account;
+ GError *error = NULL;
+
+ if (!empathy_account_settings_apply_finish (settings, result, &error))
+ {
+ DEBUG ("Failed to create salut account: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ account = empathy_account_settings_get_account (settings);
+
+ tp_account_set_enabled_async (account, TRUE, NULL, NULL);
+ empathy_conf_set_bool (empathy_conf_get (),
+ EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
+ TRUE);
+}
+
+static void
+create_salut_account_am_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
+ EmpathyConnectionManagers *managers = user_data;
+ 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))
+ {
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ if (!should_create_salut_account (account_manager))
+ goto out;
+
+ manager = empathy_connection_managers_get_cm (managers, "salut");
+ if (manager == NULL)
+ {
+ DEBUG ("Salut not installed, not making a salut account");
+ goto out;
+ }
+
+ protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
+ if (protocol == NULL)
+ {
+ DEBUG ("Salut doesn't support local-xmpp!!");
+ goto out;
+ }
+
+ DEBUG ("Trying to add a salut account...");
+
+ /* 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_clear_error (&error);
+ 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:
+ g_object_unref (managers);
+}
+
+void
+create_salut_account_if_needed (EmpathyConnectionManagers *managers)
+{
+ TpAccountManager *manager;
+
+ manager = tp_account_manager_dup ();
+
+ tp_account_manager_prepare_async (manager, NULL,
+ create_salut_account_am_ready_cb, g_object_ref (managers));
+
+ g_object_unref (manager);
+}
diff --git a/src/empathy-auto-salut-account-helper.h b/src/empathy-auto-salut-account-helper.h
new file mode 100644
index 000000000..6e934500b
--- /dev/null
+++ b/src/empathy-auto-salut-account-helper.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2007-2010 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
+ * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
+ */
+
+/* Helper functions to automatically create a Salut account */
+
+#ifndef __AUTO_SALUT_ACCOUNT_HELPER_H__
+#define __AUTO_SALUT_ACCOUNT_HELPER_H__
+
+#include <telepathy-glib/account-manager.h>
+
+#include <libempathy/empathy-connection-managers.h>
+
+void create_salut_account_if_needed (EmpathyConnectionManagers *managers);
+
+gboolean should_create_salut_account (TpAccountManager *manager);
+
+#endif
diff --git a/src/empathy.c b/src/empathy.c
index e54274b4b..60ff6c0cd 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -35,7 +35,6 @@
#include <clutter-gtk/clutter-gtk.h>
#endif
-#include <libebook/e-book.h>
#include <libnotify/notify.h>
#include <telepathy-glib/account-manager.h>
@@ -71,6 +70,7 @@
#include "empathy-chat-window.h"
#include "empathy-ft-manager.h"
#include "empathy-import-mc4-accounts.h"
+#include "empathy-auto-salut-account-helper.h"
#include "extensions/extensions.h"
@@ -152,75 +152,6 @@ dispatch_cb (EmpathyDispatcher *dispatcher,
}
}
-/* Salut account creation. The TpAccountManager first argument
- * must already be prepared when calling this function. */
-static gboolean
-should_create_salut_account (TpAccountManager *manager)
-{
- gboolean salut_created = FALSE;
- GList *accounts, *l;
-
- /* Check if we already created a salut account */
- empathy_conf_get_bool (empathy_conf_get (),
- EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
- &salut_created);
-
- if (salut_created)
- {
- DEBUG ("Gconf says we already created a salut account once");
- return FALSE;
- }
-
- accounts = tp_account_manager_get_valid_accounts (manager);
-
- for (l = accounts; l != NULL; l = g_list_next (l))
- {
- TpAccount *account = TP_ACCOUNT (l->data);
-
- if (!tp_strdiff (tp_account_get_protocol (account), "local-xmpp"))
- {
- salut_created = TRUE;
- break;
- }
- }
-
- g_list_free (accounts);
-
- if (salut_created)
- {
- DEBUG ("Existing salut account already exists, flagging so in gconf");
- empathy_conf_set_bool (empathy_conf_get (),
- EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
- TRUE);
- }
-
- return !salut_created;
-}
-
-static void
-salut_account_created (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
- TpAccount *account;
- GError *error = NULL;
-
- if (!empathy_account_settings_apply_finish (settings, result, &error))
- {
- DEBUG ("Failed to create salut account: %s", error->message);
- g_error_free (error);
- return;
- }
-
- account = empathy_account_settings_get_account (settings);
-
- tp_account_set_enabled_async (account, TRUE, NULL, NULL);
- empathy_conf_set_bool (empathy_conf_get (),
- EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
- TRUE);
-}
-
static void
use_conn_notify_cb (EmpathyConf *conf,
const gchar *key,
@@ -235,117 +166,6 @@ use_conn_notify_cb (EmpathyConf *conf,
}
}
-static void
-create_salut_account_am_ready_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
- EmpathyConnectionManagers *managers = user_data;
- 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))
- {
- DEBUG ("Failed to prepare account manager: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- if (!should_create_salut_account (account_manager))
- goto out;
-
- manager = empathy_connection_managers_get_cm (managers, "salut");
- if (manager == NULL)
- {
- DEBUG ("Salut not installed, not making a salut account");
- goto out;
- }
-
- protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
- if (protocol == NULL)
- {
- DEBUG ("Salut doesn't support local-xmpp!!");
- goto out;
- }
-
- DEBUG ("Trying to add a salut account...");
-
- /* 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_clear_error (&error);
- 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:
- g_object_unref (managers);
-}
-
-static void
-create_salut_account_if_needed (EmpathyConnectionManagers *managers)
-{
- TpAccountManager *manager;
-
- manager = tp_account_manager_dup ();
-
- tp_account_manager_prepare_async (manager, NULL,
- create_salut_account_am_ready_cb, g_object_ref (managers));
-
- g_object_unref (manager);
-}
-
static gboolean
has_non_salut_accounts (TpAccountManager *manager)
{