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>
35 #include <telepathy-glib/account-manager.h>
36 #include <telepathy-glib/defs.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.h"
44 #include "empathy-accounts-common.h"
45 #include "empathy-accounts-dialog.h"
46 #include "empathy-account-assistant.h"
47 #include "empathy-auto-salut-account-helper.h"
49 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
50 #include <libempathy/empathy-debug.h>
52 #define EMPATHY_ACCOUNTS_DBUS_NAME "org.gnome.EmpathyAccounts"
54 static gboolean only_if_needed = FALSE;
55 static gboolean hidden = FALSE;
56 static gchar *selected_account_name = NULL;
57 static gboolean account_manager_prepared = FALSE;
58 static gboolean assistant = FALSE;
61 account_prepare_cb (GObject *source_object,
65 TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data);
66 TpAccount *account = TP_ACCOUNT (source_object);
69 if (!tp_proxy_prepare_finish (account, result, &error))
71 DEBUG ("Failed to prepare account: %s", error->message);
77 empathy_accounts_show_accounts_ui (manager, account, assistant,
78 G_CALLBACK (gtk_main_quit));
82 maybe_show_accounts_ui (TpAccountManager *manager)
85 (only_if_needed && empathy_accounts_has_non_salut_accounts (manager)))
88 empathy_accounts_show_accounts_ui (manager, NULL, assistant, gtk_main_quit);
92 account_manager_ready_for_accounts_cb (GObject *source_object,
96 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
99 if (!tp_proxy_prepare_finish (manager, result, &error))
101 DEBUG ("Failed to prepare account manager: %s", error->message);
102 g_clear_error (&error);
106 account_manager_prepared = TRUE;
108 if (selected_account_name != NULL)
111 TpAccount *account = NULL;
114 /* create and prep the corresponding TpAccount so it's fully ready by the
115 * time we try to select it in the accounts dialog */
116 if (g_str_has_prefix (selected_account_name, TP_ACCOUNT_OBJECT_PATH_BASE))
117 account_path = g_strdup (selected_account_name);
119 account_path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE,
120 selected_account_name);
122 bus = tp_dbus_daemon_dup (NULL);
123 if ((account = tp_account_new (bus, account_path, &error)))
125 tp_proxy_prepare_async (account, NULL, account_prepare_cb, manager);
126 g_object_unref (bus);
131 DEBUG ("Failed to find account with path %s: %s", account_path,
133 g_clear_error (&error);
135 maybe_show_accounts_ui (manager);
138 g_object_unref (bus);
139 g_free (account_path);
143 maybe_show_accounts_ui (manager);
148 app_command_line_cb (GApplication *app,
149 GApplicationCommandLine *cmdline)
151 g_application_hold (app);
153 /* if the window is ready, present it; otherwise, it will be presented when
154 * the accounts manager is prepared */
155 if (account_manager_prepared)
157 TpAccountManager *account_manager;
159 account_manager = tp_account_manager_dup ();
160 empathy_accounts_show_accounts_ui (account_manager, NULL, assistant,
161 G_CALLBACK (gtk_main_quit));
163 g_object_unref (account_manager);
170 local_cmdline (GApplication *app,
177 gboolean retval = FALSE;
178 GError *error = NULL;
180 GOptionContext *optcontext;
181 GOptionEntry options[] = {
183 0, G_OPTION_ARG_NONE, &hidden,
184 N_("Don't display any dialogs; do any work (eg, importing) and exit"),
187 0, G_OPTION_ARG_NONE, &only_if_needed,
188 N_("Don't display any dialogs unless there are only \"People Nearby\" accounts"),
190 { "select-account", 's',
191 G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name,
192 N_("Initially select given account (eg, "
193 "gabble/jabber/foo_40example_2eorg0)"),
194 N_("<account-id>") },
196 0, G_OPTION_ARG_NONE, &assistant,
197 N_("Show account assistant"),
203 optcontext = g_option_context_new (N_("- Empathy Accounts"));
204 g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
205 g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
208 for (i = 0; argv[i] != NULL; i++)
211 if (!g_option_context_parse (optcontext, &argc, &argv, &error))
213 g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
214 error->message, argv[0]);
215 g_warning ("Error in empathy init: %s", error->message);
217 *exit_status = EXIT_FAILURE;
221 g_option_context_free (optcontext);
226 #define COMMAND_ACCOUNTS_DIALOG 1
229 main (int argc, char *argv[])
231 TpAccountManager *account_manager;
233 GObjectClass *app_class;
236 g_thread_init (NULL);
239 gtk_init (&argc, &argv);
242 g_set_application_name (_("Empathy Accounts"));
244 /* Make empathy and empathy-accounts appear as the same app in gnome-shell */
245 gdk_set_program_class ("Empathy");
246 gtk_window_set_default_icon_name ("empathy");
247 textdomain (GETTEXT_PACKAGE);
249 app = gtk_application_new (EMPATHY_ACCOUNTS_DBUS_NAME,
250 G_APPLICATION_HANDLES_COMMAND_LINE);
251 app_class = G_OBJECT_GET_CLASS (app);
252 G_APPLICATION_CLASS (app_class)->local_command_line = local_cmdline;
254 account_manager = tp_account_manager_dup ();
256 tp_proxy_prepare_async (account_manager, NULL,
257 account_manager_ready_for_accounts_cb, NULL);
259 g_signal_connect (app, "command-line", G_CALLBACK (app_command_line_cb),
262 retval = g_application_run (G_APPLICATION (app), argc, argv);
264 g_object_unref (account_manager);
265 g_object_unref (app);