aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2010-03-02 19:39:14 +0800
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>2010-03-02 19:39:14 +0800
commit41ca7cb4fea39f928976b7b69466a61c78a5f7ed (patch)
tree6fb60beb6cf57f68bf94ba5b134bdffc04b1c01b
parent74b2a167ce29bbda607b1b1a0ac8ef96c51a924c (diff)
parent3c8e671463630b94f8238ea8caaf6a03b2165278 (diff)
downloadgsoc2013-empathy-41ca7cb4fea39f928976b7b69466a61c78a5f7ed.tar
gsoc2013-empathy-41ca7cb4fea39f928976b7b69466a61c78a5f7ed.tar.gz
gsoc2013-empathy-41ca7cb4fea39f928976b7b69466a61c78a5f7ed.tar.bz2
gsoc2013-empathy-41ca7cb4fea39f928976b7b69466a61c78a5f7ed.tar.lz
gsoc2013-empathy-41ca7cb4fea39f928976b7b69466a61c78a5f7ed.tar.xz
gsoc2013-empathy-41ca7cb4fea39f928976b7b69466a61c78a5f7ed.tar.zst
gsoc2013-empathy-41ca7cb4fea39f928976b7b69466a61c78a5f7ed.zip
Merge branch 'accounts-wizard'
-rw-r--r--src/cc-empathy-accounts-page.c4
-rw-r--r--src/empathy-accounts-common.c83
-rw-r--r--src/empathy-accounts-common.h6
-rw-r--r--src/empathy-accounts-dialog.c11
-rw-r--r--src/empathy-accounts-dialog.h2
-rw-r--r--src/empathy-accounts.c105
-rw-r--r--src/empathy.c22
7 files changed, 87 insertions, 146 deletions
diff --git a/src/cc-empathy-accounts-page.c b/src/cc-empathy-accounts-page.c
index 15c7e5689..bf4d46af7 100644
--- a/src/cc-empathy-accounts-page.c
+++ b/src/cc-empathy-accounts-page.c
@@ -89,7 +89,9 @@ connection_managers_prepare (GObject *source,
page_pack_with_accounts_dialog (page);
- if (empathy_accounts_import (account_mgr, cm_mgr))
+ empathy_accounts_import (account_mgr, cm_mgr);
+
+ if (!empathy_accounts_has_non_salut_accounts (account_mgr))
empathy_account_assistant_show (NULL, cm_mgr);
out:
diff --git a/src/empathy-accounts-common.c b/src/empathy-accounts-common.c
index cf730fab2..334f3cba8 100644
--- a/src/empathy-accounts-common.c
+++ b/src/empathy-accounts-common.c
@@ -71,29 +71,16 @@ empathy_accounts_has_non_salut_accounts (TpAccountManager *manager)
return ret;
}
-/* Try to import accounts from MC4 and returns TRUE if we should display the
- * accounts assistant. */
-gboolean
+void
empathy_accounts_import (TpAccountManager *account_mgr,
EmpathyConnectionManagers *cm_mgr)
{
- g_return_val_if_fail (tp_account_manager_is_prepared (account_mgr,
- TP_ACCOUNT_MANAGER_FEATURE_CORE), FALSE);
- g_return_val_if_fail (empathy_connection_managers_is_ready (cm_mgr), FALSE);
-
- if (empathy_import_mc4_has_imported ())
- return FALSE;
-
- if (empathy_import_mc4_accounts (cm_mgr))
- return FALSE;
-
- if (empathy_accounts_has_non_salut_accounts (account_mgr))
- return FALSE;
+ g_return_if_fail (tp_account_manager_is_prepared (account_mgr,
+ TP_ACCOUNT_MANAGER_FEATURE_CORE));
+ g_return_if_fail (empathy_connection_managers_is_ready (cm_mgr));
- if (!should_create_salut_account (account_mgr))
- return FALSE;
-
- return TRUE;
+ if (!empathy_import_mc4_has_imported ())
+ empathy_import_mc4_accounts (cm_mgr);
}
static void
@@ -111,7 +98,7 @@ do_show_accounts_ui (TpAccountManager *manager,
gtk_window_present (GTK_WINDOW (accounts_window));
}
-static GtkWidget*
+static GtkWidget *
show_account_assistant (EmpathyConnectionManagers *connection_mgrs,
GCallback assistant_destroy_cb)
{
@@ -125,60 +112,6 @@ show_account_assistant (EmpathyConnectionManagers *connection_mgrs,
}
static void
-connection_managers_prepare_cb (
- EmpathyConnectionManagers *cm_mgr,
- GAsyncResult *result,
- gpointer user_data)
-{
- GCallback assistant_destroy_cb = g_object_get_data (G_OBJECT (cm_mgr),
- "assistant-destroy-callback");
- TpAccountManager *account_mgr = g_object_get_data (G_OBJECT (cm_mgr),
- "account-manager");
- gboolean hidden = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (cm_mgr),
- "hidden"));
-
- if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
- goto out;
-
- if (empathy_accounts_import (account_mgr, cm_mgr) &&
- !hidden)
- {
- show_account_assistant (cm_mgr, assistant_destroy_cb);
- }
- else if (!empathy_accounts_has_non_salut_accounts (account_mgr))
- {
- show_account_assistant (cm_mgr, assistant_destroy_cb);
- }
- else
- {
- if (assistant_destroy_cb)
- assistant_destroy_cb ();
- }
-
-out:
- g_object_unref (cm_mgr);
-}
-
-void
-empathy_accounts_manager_ready_for_show_assistant (
- TpAccountManager *account_mgr,
- gboolean hidden)
-{
- EmpathyConnectionManagers *cm_mgr;
-
- cm_mgr = empathy_connection_managers_dup_singleton ();
-
- g_object_set_data (G_OBJECT (cm_mgr), "assistant-destroy-callback",
- g_object_get_data (G_OBJECT (account_mgr), "assistant-destroy-callback"));
- g_object_set_data_full (G_OBJECT (cm_mgr), "account-manager",
- g_object_ref (account_mgr), g_object_unref);
- g_object_set_data (G_OBJECT (cm_mgr), "hidden", GUINT_TO_POINTER (hidden));
-
- empathy_connection_managers_prepare_async (cm_mgr,
- (GAsyncReadyCallback) connection_managers_prepare_cb, NULL);
-}
-
-static void
connection_managers_prepare_for_accounts (GObject *source,
GAsyncResult *result,
gpointer user_data)
@@ -190,7 +123,7 @@ connection_managers_prepare_for_accounts (GObject *source,
goto out;
show_account_assistant (cm_mgr, assistant_destroy_cb);
- g_debug ("would show the account assistant");
+ DEBUG ("would show the account assistant");
out:
g_object_unref (cm_mgr);
diff --git a/src/empathy-accounts-common.h b/src/empathy-accounts-common.h
index 6782d77e2..2bd51bf0d 100644
--- a/src/empathy-accounts-common.h
+++ b/src/empathy-accounts-common.h
@@ -28,11 +28,7 @@ void empathy_accounts_show_accounts_ui (TpAccountManager *manager,
TpAccount *account,
GCallback window_destroyed_cb);
-void empathy_accounts_manager_ready_for_show_assistant (
- TpAccountManager *account_mgr,
- gboolean hidden);
-
-gboolean empathy_accounts_import (TpAccountManager *account_mgr,
+void empathy_accounts_import (TpAccountManager *account_mgr,
EmpathyConnectionManagers *cm_mgr);
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index 1256a1758..b2e21dc8d 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -2229,7 +2229,7 @@ empathy_accounts_dialog_show_application (GdkScreen *screen,
GChildWatchFunc application_exit_cb,
gpointer user_data,
TpAccount *selected_account,
- gboolean try_import,
+ gboolean if_needed,
gboolean hidden)
{
gint command_pid;
@@ -2265,12 +2265,17 @@ empathy_accounts_dialog_show_application (GdkScreen *screen,
argv[i++] = account_option;
}
- if (try_import)
- argv[i++] = "--import";
+ if (if_needed)
+ argv[i++] = "--if-needed";
if (hidden)
argv[i++] = "--hidden";
+ DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
+ if_needed, hidden,
+ selected_account == NULL ? "<none selected>" :
+ tp_proxy_get_object_path (TP_PROXY (selected_account)));
+
gdk_spawn_on_screen (screen, NULL, argv, NULL,
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL,
&command_pid, &error);
diff --git a/src/empathy-accounts-dialog.h b/src/empathy-accounts-dialog.h
index dd9cd7d55..c171e3d24 100644
--- a/src/empathy-accounts-dialog.h
+++ b/src/empathy-accounts-dialog.h
@@ -60,7 +60,7 @@ void empathy_accounts_dialog_show_application (GdkScreen *screen,
GChildWatchFunc application_exit_cb,
gpointer user_data,
TpAccount *selected_account,
- gboolean try_import,
+ gboolean if_needed,
gboolean hidden);
G_END_DECLS
diff --git a/src/empathy-accounts.c b/src/empathy-accounts.c
index 942f6a475..b97bc4533 100644
--- a/src/empathy-accounts.c
+++ b/src/empathy-accounts.c
@@ -53,50 +53,58 @@
#define EMPATHY_ACCOUNTS_DBUS_NAME "org.gnome.EmpathyAccounts"
-static gboolean try_import = FALSE;
+static gboolean only_if_needed = FALSE;
static gboolean hidden = FALSE;
static gchar *selected_account_name = NULL;
static void
-account_manager_ready_for_assistant_cb (GObject *source_object,
+account_prepare_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
- TpAccountManager *account_mgr = TP_ACCOUNT_MANAGER (source_object);
+ TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data);
+ TpAccount *account = TP_ACCOUNT (source_object);
GError *error = NULL;
- if (!tp_account_manager_prepare_finish (account_mgr, result, &error))
+ if (!tp_account_prepare_finish (account, result, &error))
{
- DEBUG ("Failed to prepare account manager: %s", error->message);
+ DEBUG ("Failed to prepare account: %s", error->message);
g_error_free (error);
- return;
+
+ account = NULL;
}
- g_object_set_data (G_OBJECT (account_mgr), "assistant-destroy-callback",
+ empathy_accounts_show_accounts_ui (manager, account,
G_CALLBACK (gtk_main_quit));
+}
- empathy_accounts_manager_ready_for_show_assistant (account_mgr, hidden);
+static void
+maybe_show_accounts_ui (TpAccountManager *manager)
+{
+ if (hidden ||
+ (only_if_needed && empathy_accounts_has_non_salut_accounts (manager)))
+ gtk_main_quit ();
+ else
+ empathy_accounts_show_accounts_ui (manager, NULL, gtk_main_quit);
}
static void
-account_prepare_cb (GObject *source_object,
+cm_manager_prepared_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
- TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data);
- TpAccount *account = TP_ACCOUNT (source_object);
- GError *error = NULL;
-
- if (!tp_account_prepare_finish (account, result, &error))
+ if (!empathy_connection_managers_prepare_finish (
+ EMPATHY_CONNECTION_MANAGERS (source), result, NULL))
{
- DEBUG ("Failed to prepare account: %s", error->message);
- g_error_free (error);
-
- account = NULL;
+ g_warning ("Failed to prepare connection managers singleton");
+ gtk_main_quit ();
+ return;
}
- empathy_accounts_show_accounts_ui (manager, account,
- G_CALLBACK (gtk_main_quit));
+ empathy_accounts_import (TP_ACCOUNT_MANAGER (user_data),
+ EMPATHY_CONNECTION_MANAGERS (source));
+
+ maybe_show_accounts_ui (TP_ACCOUNT_MANAGER (user_data));
}
static void
@@ -115,7 +123,7 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
return;
}
- if (account_id)
+ if (account_id != NULL)
{
gchar *account_path;
TpAccount *account = NULL;
@@ -143,8 +151,18 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
}
else
{
- empathy_accounts_show_accounts_ui (manager, NULL,
- G_CALLBACK (gtk_main_quit));
+ if (empathy_import_mc4_has_imported ())
+ {
+ maybe_show_accounts_ui (manager);
+ }
+ else
+ {
+ EmpathyConnectionManagers *cm_mgr =
+ empathy_connection_managers_dup_singleton ();
+
+ empathy_connection_managers_prepare_async (
+ cm_mgr, cm_manager_prepared_cb, manager);
+ }
}
}
@@ -191,15 +209,14 @@ main (int argc, char *argv[])
GOptionContext *optcontext;
GOptionEntry options[] = {
- { "import", 'i',
- G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &try_import,
- N_("Try to import any recognized accounts and display an assistant if "
- "that fails"),
- NULL },
{ "hidden", 'h',
0, G_OPTION_ARG_NONE, &hidden,
N_("Don't display any dialogs; do any work (eg, importing) and exit"),
NULL },
+ { "if-needed", 'n',
+ 0, G_OPTION_ARG_NONE, &only_if_needed,
+ N_("Don't display any dialogs if there are any non-salut accounts"),
+ NULL },
{ "select-account", 's',
G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name,
N_("Initially select given account (eg, "
@@ -242,38 +259,10 @@ main (int argc, char *argv[])
return EXIT_SUCCESS;
}
- /* Take well-known name */
- dbus_daemon = tp_dbus_daemon_dup (&error);
- if (error == NULL)
- {
- if (!tp_dbus_daemon_request_name (dbus_daemon,
- EMPATHY_ACCOUNTS_DBUS_NAME, TRUE, &error))
- {
- DEBUG ("Failed to request well-known name: %s",
- error ? error->message : "no message");
- g_clear_error (&error);
- }
- g_object_unref (dbus_daemon);
- }
- else
- {
- DEBUG ("Failed to dup dbus daemon: %s",
- error ? error->message : "no message");
- g_clear_error (&error);
- }
-
account_manager = tp_account_manager_dup ();
- if (try_import)
- {
- tp_account_manager_prepare_async (account_manager, NULL,
- account_manager_ready_for_assistant_cb, NULL);
- }
- else
- {
- tp_account_manager_prepare_async (account_manager, NULL,
- account_manager_ready_for_accounts_cb, selected_account_name);
- }
+ tp_account_manager_prepare_async (account_manager, NULL,
+ account_manager_ready_for_accounts_cb, selected_account_name);
g_signal_connect (unique_app, "message-received",
G_CALLBACK (unique_app_message_cb), NULL);
diff --git a/src/empathy.c b/src/empathy.c
index 2cc5a9f28..2dc62943e 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -69,6 +69,8 @@
#include <libempathy-gtk/empathy-location-manager.h>
#include "empathy-main-window.h"
+#include "empathy-import-mc4-accounts.h"
+#include "empathy-accounts-common.h"
#include "empathy-accounts-dialog.h"
#include "empathy-status-icon.h"
#include "empathy-call-window.h"
@@ -85,6 +87,10 @@
static gboolean start_hidden = FALSE;
static gboolean no_connect = FALSE;
+static void account_manager_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data);
+
static void
dispatch_cb (EmpathyDispatcher *dispatcher,
EmpathyDispatchOperation *operation,
@@ -248,10 +254,10 @@ accounts_application_exited_cb (GPid pid,
static void
show_accounts_ui (GdkScreen *screen,
- gboolean try_import)
+ gboolean if_needed)
{
empathy_accounts_dialog_show_application (screen,
- accounts_application_exited_cb, NULL, NULL, try_import, start_hidden);
+ accounts_application_exited_cb, NULL, NULL, if_needed, start_hidden);
}
static UniqueResponse
@@ -262,6 +268,7 @@ unique_app_message_cb (UniqueApp *unique_app,
gpointer user_data)
{
GtkWindow *window = user_data;
+ TpAccountManager *account_manager;
DEBUG ("Other instance launched, presenting the main window. "
"Command=%d, timestamp %u", command, timestamp);
@@ -281,6 +288,11 @@ unique_app_message_cb (UniqueApp *unique_app,
gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
gtk_window_set_skip_taskbar_hint (window, FALSE);
+ account_manager = tp_account_manager_dup ();
+ tp_account_manager_prepare_async (account_manager, NULL,
+ account_manager_ready_cb, NULL);
+ g_object_unref (account_manager);
+
return UNIQUE_RESPONSE_OK;
}
@@ -370,7 +382,11 @@ account_manager_ready_cb (GObject *source_object,
/* if current state is Offline, then put it online */
empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
- show_accounts_ui (gdk_screen_get_default (), TRUE);
+ /* Pop up the accounts dialog if it's needed (either when we don't have any
+ * non-salut accounts yet or when we haven't imported mc4 accounts yet */
+ if (!empathy_accounts_has_non_salut_accounts (manager)
+ || !empathy_import_mc4_has_imported ())
+ show_accounts_ui (gdk_screen_get_default (), TRUE);
g_object_unref (idle);
g_object_unref (connectivity);