Updated Norwegian bokmål translation
[empathy-mirror.git] / src / empathy-accounts-common.c
bloba14a95c59a2761e6842c1a42f2620a4a84180771
1 /*
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>
27 #include <config.h>
29 #include <string.h>
30 #include <stdlib.h>
32 #include <gtk/gtk.h>
33 #include <glib/gi18n-lib.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-auto-salut-account-helper.h"
48 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
49 #include <libempathy/empathy-debug.h>
51 gboolean
52 empathy_accounts_has_non_salut_accounts (TpAccountManager *manager)
54 gboolean ret = FALSE;
55 GList *accounts, *l;
57 accounts = tp_account_manager_get_valid_accounts (manager);
59 for (l = accounts ; l != NULL; l = g_list_next (l))
61 if (tp_strdiff (tp_account_get_protocol (l->data), "local-xmpp"))
63 ret = TRUE;
64 break;
68 g_list_free (accounts);
70 return ret;
73 gboolean
74 empathy_accounts_has_accounts (TpAccountManager *manager)
76 GList *accounts;
77 gboolean has_accounts;
79 accounts = tp_account_manager_get_valid_accounts (manager);
80 has_accounts = (accounts != NULL);
81 g_list_free (accounts);
83 return has_accounts;
86 static void
87 do_show_accounts_ui (TpAccountManager *manager,
88 TpAccount *account,
89 GCallback window_destroyed_cb)
91 static GtkWidget *accounts_window = NULL;
93 if (accounts_window == NULL)
94 accounts_window = empathy_accounts_dialog_show (NULL, account);
96 if (window_destroyed_cb)
97 g_signal_connect (accounts_window, "destroy", window_destroyed_cb, NULL);
99 gtk_window_present (GTK_WINDOW (accounts_window));
102 static GtkWidget *
103 show_account_assistant (EmpathyConnectionManagers *connection_mgrs,
104 GCallback assistant_destroy_cb)
106 GtkWidget *assistant;
108 assistant = empathy_account_assistant_show (NULL, connection_mgrs);
109 if (assistant_destroy_cb)
110 g_signal_connect (assistant, "destroy", assistant_destroy_cb, NULL);
112 return assistant;
115 static void
116 connection_managers_prepare_for_accounts (GObject *source,
117 GAsyncResult *result,
118 gpointer user_data)
120 EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source);
121 GCallback assistant_destroy_cb = G_CALLBACK (user_data);
123 if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
124 goto out;
126 show_account_assistant (cm_mgr, assistant_destroy_cb);
127 DEBUG ("would show the account assistant");
129 out:
130 g_object_unref (cm_mgr);
133 void
134 empathy_accounts_show_accounts_ui (TpAccountManager *manager,
135 TpAccount *account,
136 GCallback window_destroyed_cb)
138 g_return_if_fail (TP_IS_ACCOUNT_MANAGER (manager));
139 g_return_if_fail (!account || TP_IS_ACCOUNT (account));
141 if (empathy_accounts_has_non_salut_accounts (manager))
143 do_show_accounts_ui (manager, account, window_destroyed_cb);
145 else
147 EmpathyConnectionManagers *cm_mgr;
149 cm_mgr = empathy_connection_managers_dup_singleton ();
151 empathy_connection_managers_prepare_async (cm_mgr,
152 connection_managers_prepare_for_accounts, window_destroyed_cb);