2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2010 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
24 * Travis Reitter <travis.reitter@collabora.co.uk>
33 #include <glib/gi18n.h>
34 #include <unique/unique.h>
36 #include <telepathy-glib/account-manager.h>
37 #include <telepathy-glib/util.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-connection-managers.h>
41 #include <libempathy-gtk/empathy-ui-utils.h>
43 #include "empathy-accounts-common.h"
44 #include "empathy-accounts-dialog.h"
45 #include "empathy-account-assistant.h"
46 #include "empathy-import-mc4-accounts.h"
47 #include "empathy-auto-salut-account-helper.h"
49 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
50 #include <libempathy/empathy-debug.h>
53 empathy_accounts_has_non_salut_accounts (TpAccountManager *manager)
58 accounts = tp_account_manager_get_valid_accounts (manager);
60 for (l = accounts ; l != NULL; l = g_list_next (l))
62 if (tp_strdiff (tp_account_get_protocol (l->data), "local-xmpp"))
69 g_list_free (accounts);
74 /* Try to import accounts from MC4 and returns TRUE if we should display the
75 * accounts assistant. */
77 empathy_accounts_import (TpAccountManager *account_mgr,
78 EmpathyConnectionManagers *cm_mgr)
80 g_return_val_if_fail (tp_account_manager_is_prepared (account_mgr,
81 TP_ACCOUNT_MANAGER_FEATURE_CORE), FALSE);
82 g_return_val_if_fail (empathy_connection_managers_is_ready (cm_mgr), FALSE);
84 if (empathy_import_mc4_has_imported ())
87 if (empathy_import_mc4_accounts (cm_mgr))
90 if (empathy_accounts_has_non_salut_accounts (account_mgr))
93 if (!should_create_salut_account (account_mgr))
100 do_show_accounts_ui (TpAccountManager *manager,
102 GCallback window_destroyed_cb)
104 GtkWidget *accounts_window;
106 accounts_window = empathy_accounts_dialog_show (NULL, account);
108 if (window_destroyed_cb)
109 g_signal_connect (accounts_window, "destroy", window_destroyed_cb, NULL);
111 gtk_window_present (GTK_WINDOW (accounts_window));
115 show_account_assistant (EmpathyConnectionManagers *connection_mgrs,
116 GCallback assistant_destroy_cb)
118 GtkWidget *assistant;
120 assistant = empathy_account_assistant_show (NULL, connection_mgrs);
121 if (assistant_destroy_cb)
122 g_signal_connect (assistant, "destroy", assistant_destroy_cb, NULL);
128 connection_managers_prepare_cb (
129 EmpathyConnectionManagers *cm_mgr,
130 GAsyncResult *result,
133 GCallback assistant_destroy_cb = g_object_get_data (G_OBJECT (cm_mgr),
134 "assistant-destroy-callback");
135 TpAccountManager *account_mgr = g_object_get_data (G_OBJECT (cm_mgr),
137 gboolean hidden = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (cm_mgr),
140 if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
143 if (empathy_accounts_import (account_mgr, cm_mgr) &&
146 show_account_assistant (cm_mgr, assistant_destroy_cb);
148 else if (!empathy_accounts_has_non_salut_accounts (account_mgr))
150 show_account_assistant (cm_mgr, assistant_destroy_cb);
154 if (assistant_destroy_cb)
155 assistant_destroy_cb ();
159 g_object_unref (cm_mgr);
163 empathy_accounts_manager_ready_for_show_assistant (
164 TpAccountManager *account_mgr,
167 EmpathyConnectionManagers *cm_mgr;
169 cm_mgr = empathy_connection_managers_dup_singleton ();
171 g_object_set_data (G_OBJECT (cm_mgr), "assistant-destroy-callback",
172 g_object_get_data (G_OBJECT (account_mgr), "assistant-destroy-callback"));
173 g_object_set_data_full (G_OBJECT (cm_mgr), "account-manager",
174 g_object_ref (account_mgr), g_object_unref);
175 g_object_set_data (G_OBJECT (cm_mgr), "hidden", GUINT_TO_POINTER (hidden));
177 empathy_connection_managers_prepare_async (cm_mgr,
178 (GAsyncReadyCallback) connection_managers_prepare_cb, NULL);
182 connection_managers_prepare_for_accounts (GObject *source,
183 GAsyncResult *result,
186 EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source);
187 GCallback assistant_destroy_cb = G_CALLBACK (user_data);
189 if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
192 show_account_assistant (cm_mgr, assistant_destroy_cb);
193 g_debug ("would show the account assistant");
196 g_object_unref (cm_mgr);
200 empathy_accounts_show_accounts_ui (TpAccountManager *manager,
202 GCallback window_destroyed_cb)
204 g_return_if_fail (TP_IS_ACCOUNT_MANAGER (manager));
205 g_return_if_fail (!account || TP_IS_ACCOUNT (account));
207 if (empathy_accounts_has_non_salut_accounts (manager))
209 do_show_accounts_ui (manager, account, window_destroyed_cb);
213 EmpathyConnectionManagers *cm_mgr;
215 cm_mgr = empathy_connection_managers_dup_singleton ();
217 empathy_connection_managers_prepare_async (cm_mgr,
218 connection_managers_prepare_for_accounts, window_destroyed_cb);