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;
60 account_prepare_cb (GObject *source_object,
64 TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data);
65 TpAccount *account = TP_ACCOUNT (source_object);
68 if (!tp_account_prepare_finish (account, result, &error))
70 DEBUG ("Failed to prepare account: %s", error->message);
76 empathy_accounts_show_accounts_ui (manager, account,
77 G_CALLBACK (gtk_main_quit));
81 maybe_show_accounts_ui (TpAccountManager *manager)
84 (only_if_needed && empathy_accounts_has_non_salut_accounts (manager)))
87 empathy_accounts_show_accounts_ui (manager, NULL, gtk_main_quit);
91 account_manager_ready_for_accounts_cb (GObject *source_object,
95 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
98 if (!tp_account_manager_prepare_finish (manager, result, &error))
100 DEBUG ("Failed to prepare account manager: %s", error->message);
101 g_clear_error (&error);
105 account_manager_prepared = TRUE;
107 if (selected_account_name != NULL)
110 TpAccount *account = NULL;
113 /* create and prep the corresponding TpAccount so it's fully ready by the
114 * time we try to select it in the accounts dialog */
115 account_path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE,
116 selected_account_name);
117 bus = tp_dbus_daemon_dup (NULL);
118 if ((account = tp_account_new (bus, account_path, &error)))
120 tp_account_prepare_async (account, NULL, account_prepare_cb, manager);
121 g_object_unref (bus);
126 DEBUG ("Failed to find account with path %s: %s", account_path,
128 g_clear_error (&error);
130 maybe_show_accounts_ui (manager);
133 g_object_unref (bus);
134 g_free (account_path);
138 maybe_show_accounts_ui (manager);
143 app_command_line_cb (GApplication *app,
144 GApplicationCommandLine *cmdline)
146 g_application_hold (app);
148 /* if the window is ready, present it; otherwise, it will be presented when
149 * the accounts manager is prepared */
150 if (account_manager_prepared)
152 TpAccountManager *account_manager;
154 account_manager = tp_account_manager_dup ();
155 empathy_accounts_show_accounts_ui (account_manager, NULL,
156 G_CALLBACK (gtk_main_quit));
158 g_object_unref (account_manager);
165 local_cmdline (GApplication *app,
172 gboolean retval = FALSE;
173 GError *error = NULL;
175 GOptionContext *optcontext;
176 GOptionEntry options[] = {
178 0, G_OPTION_ARG_NONE, &hidden,
179 N_("Don't display any dialogs; do any work (eg, importing) and exit"),
182 0, G_OPTION_ARG_NONE, &only_if_needed,
183 N_("Don't display any dialogs unless there are only \"People Nearby\" accounts"),
185 { "select-account", 's',
186 G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name,
187 N_("Initially select given account (eg, "
188 "gabble/jabber/foo_40example_2eorg0)"),
189 N_("<account-id>") },
194 optcontext = g_option_context_new (N_("- Empathy Accounts"));
195 g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
196 g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
199 for (i = 0; argv[i] != NULL; i++)
202 if (!g_option_context_parse (optcontext, &argc, &argv, &error))
204 g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
205 error->message, argv[0]);
206 g_warning ("Error in empathy init: %s", error->message);
208 *exit_status = EXIT_FAILURE;
212 g_option_context_free (optcontext);
217 #define COMMAND_ACCOUNTS_DIALOG 1
220 main (int argc, char *argv[])
222 TpAccountManager *account_manager;
224 GObjectClass *app_class;
227 g_thread_init (NULL);
230 gtk_init (&argc, &argv);
233 g_set_application_name (_("Empathy Accounts"));
235 /* Make empathy and empathy-accounts appear as the same app in gnome-shell */
236 gdk_set_program_class ("Empathy");
237 gtk_window_set_default_icon_name ("empathy");
238 textdomain (GETTEXT_PACKAGE);
240 app = gtk_application_new (EMPATHY_ACCOUNTS_DBUS_NAME,
241 G_APPLICATION_HANDLES_COMMAND_LINE);
242 app_class = G_OBJECT_GET_CLASS (app);
243 G_APPLICATION_CLASS (app_class)->local_command_line = local_cmdline;
245 account_manager = tp_account_manager_dup ();
247 tp_account_manager_prepare_async (account_manager, NULL,
248 account_manager_ready_for_accounts_cb, NULL);
250 g_signal_connect (app, "command-line", G_CALLBACK (app_command_line_cb),
253 retval = g_application_run (G_APPLICATION (app), argc, argv);
255 g_object_unref (account_manager);
256 g_object_unref (app);