aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/empathy-account-assistant.c481
-rw-r--r--src/empathy-account-assistant.h5
-rw-r--r--src/empathy-auto-salut-account-helper.c125
-rw-r--r--src/empathy-auto-salut-account-helper.h5
-rw-r--r--src/empathy.c129
5 files changed, 515 insertions, 230 deletions
diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c
index a80e47c92..be7babbd1 100644
--- a/src/empathy-account-assistant.c
+++ b/src/empathy-account-assistant.c
@@ -35,6 +35,10 @@
#include <libempathy-gtk/empathy-account-widget.h>
#include <libempathy-gtk/empathy-protocol-chooser.h>
#include <libempathy-gtk/empathy-ui-utils.h>
+#include <libempathy-gtk/empathy-conf.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
+#include <libempathy/empathy-debug.h>
G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant,
GTK_TYPE_ASSISTANT)
@@ -57,16 +61,20 @@ enum {
PAGE_INTRO = 0,
PAGE_IMPORT = 1,
PAGE_ENTER_CREATE = 2,
+ PAGE_SALUT = 3,
};
enum {
- PROP_PARENT = 1
+ PROP_PARENT = 1,
+ PROP_CONNECTION_MGRS,
};
typedef struct {
FirstPageResponse first_resp;
CreateEnterPageResponse create_enter_resp;
gboolean enter_create_forward;
+ TpAccountManager *account_mgr;
+ EmpathyConnectionManagers *connection_mgrs;
/* enter or create page */
GtkWidget *enter_or_create_page;
@@ -81,6 +89,14 @@ typedef struct {
/* import page */
EmpathyImportWidget *iw;
+ GtkWidget *import_page;
+
+ /* salut page */
+ GtkWidget *salut_page;
+ EmpathyAccountSettings *salut_settings;
+ GtkWidget *salut_account_widget;
+ gboolean create_salut_account;
+ gboolean display_salut_page;
GtkWindow *parent_window;
@@ -93,14 +109,14 @@ static void account_assistant_finish_enter_or_create_page (
EmpathyAccountAssistant *self,
gboolean is_enter);
+static void do_constructed (GObject *object);
+
static GtkWidget *
-account_assistant_build_error_page (EmpathyAccountAssistant *self,
- GError *error, gint page_num)
+build_error_vbox (const gchar *primary_message,
+ const gchar *secondary_message)
{
GtkWidget *main_vbox, *w, *hbox;
- const char *message;
PangoAttrList *list;
- EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
main_vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
@@ -115,18 +131,7 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self,
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
gtk_widget_show (w);
- if (page_num == PAGE_IMPORT)
- message = _("There was an error while importing the accounts.");
- else if (page_num >= PAGE_ENTER_CREATE &&
- priv->first_resp == RESPONSE_ENTER_ACCOUNT)
- message = _("There was an error while parsing the account details.");
- else if (page_num >= PAGE_ENTER_CREATE &&
- priv->first_resp == RESPONSE_CREATE_ACCOUNT)
- message = _("There was an error while creating the account.");
- else
- message = _("There was an error.");
-
- w = gtk_label_new (message);
+ w = gtk_label_new (primary_message);
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
list = pango_attr_list_new ();
pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_LARGE));
@@ -138,15 +143,41 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self,
pango_attr_list_unref (list);
- message = g_markup_printf_escaped
- (_("The error message was: <span style=\"italic\">%s</span>"),
- error->message);
- w = gtk_label_new (message);
+ w = gtk_label_new (secondary_message);
gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
gtk_widget_show (w);
+ return main_vbox;
+}
+
+static GtkWidget *
+account_assistant_build_error_page (EmpathyAccountAssistant *self,
+ GError *error, gint page_num)
+{
+ GtkWidget *main_vbox, *w;
+ const char *primary_message;
+ gchar *secondary_message, *markup;
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+
+ if (page_num == PAGE_IMPORT)
+ primary_message = _("There was an error while importing the accounts.");
+ else if (page_num >= PAGE_ENTER_CREATE &&
+ priv->first_resp == RESPONSE_ENTER_ACCOUNT)
+ primary_message = _("There was an error while parsing the account details.");
+ else if (page_num >= PAGE_ENTER_CREATE &&
+ priv->first_resp == RESPONSE_CREATE_ACCOUNT)
+ primary_message = _("There was an error while creating the account.");
+ else
+ primary_message = _("There was an error.");
+
+ markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>",
+ error->message);
+ secondary_message = g_strdup_printf (_("The error message was: %s"), markup);
+
+ main_vbox = build_error_vbox (primary_message, secondary_message);
+
w = gtk_label_new (_("You can either go back and try to enter your "
"accounts' details again or quit this assistant and add accounts "
"later from the Edit menu."));
@@ -155,6 +186,8 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self,
gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
gtk_widget_show (w);
+ g_free (markup);
+ g_free (secondary_message);
return main_vbox;
}
@@ -198,6 +231,22 @@ account_assistant_present_error_page (EmpathyAccountAssistant *self,
}
static void
+update_create_page_buttons (EmpathyAccountAssistant *self)
+{
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+ GtkAssistantPageType type;
+
+ if (priv->display_salut_page ||
+ priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
+ type = GTK_ASSISTANT_PAGE_CONTENT;
+ else
+ type = GTK_ASSISTANT_PAGE_CONFIRM;
+
+ gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->enter_or_create_page,
+ type);
+}
+
+static void
account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
{
EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
@@ -206,9 +255,8 @@ account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
page = account_assistant_build_enter_or_create_page (self);
idx = gtk_assistant_append_page (GTK_ASSISTANT (self), page);
- gtk_assistant_set_page_type (GTK_ASSISTANT (self), page,
- GTK_ASSISTANT_PAGE_CONFIRM);
priv->enter_or_create_page = page;
+ update_create_page_buttons (self);
gtk_assistant_set_current_page (GTK_ASSISTANT (self), idx);
@@ -225,9 +273,10 @@ account_assistant_account_enabled_cb (GObject *source,
GError *error = NULL;
EmpathyAccountAssistant *self = user_data;
EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+ const gchar *protocol;
+ TpAccount *account = TP_ACCOUNT (source);
- tp_account_set_enabled_finish (TP_ACCOUNT (source),
- result, &error);
+ tp_account_set_enabled_finish (account, result, &error);
if (error)
{
@@ -235,6 +284,16 @@ account_assistant_account_enabled_cb (GObject *source,
g_error_free (error);
}
+ protocol = tp_account_get_protocol (account);
+ if (!tp_strdiff (protocol, "local-xmpp"))
+ {
+ DEBUG ("Salut account has been created; update gconf key");
+
+ empathy_conf_set_bool (empathy_conf_get (),
+ EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
+ TRUE);
+ }
+
if (priv->create_enter_resp == RESPONSE_CREATE_STOP)
g_signal_emit_by_name (self, "close");
else
@@ -255,14 +314,17 @@ account_assistant_apply_account_cb (GObject *source,
empathy_account_settings_apply_finish (settings, result, &error);
- /* set default display name */
- display_name = empathy_account_widget_get_default_display_name (
- priv->current_widget_object);
+ if (empathy_account_settings_get_display_name (settings) == NULL)
+ {
+ /* set default display name */
+ display_name = empathy_account_widget_get_default_display_name (
+ priv->current_widget_object);
- empathy_account_settings_set_display_name_async (settings,
- display_name, NULL, NULL);
+ empathy_account_settings_set_display_name_async (settings,
+ display_name, NULL, NULL);
- g_free (display_name);
+ g_free (display_name);
+ }
priv->is_creating = FALSE;
@@ -281,16 +343,17 @@ account_assistant_apply_account_cb (GObject *source,
}
static void
-account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self)
+account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self,
+ EmpathyAccountSettings *settings)
{
EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
- if (priv->settings == NULL)
+ if (settings == NULL)
return;
priv->is_creating = TRUE;
- empathy_account_settings_apply_async (priv->settings,
+ empathy_account_settings_apply_async (settings,
account_assistant_apply_account_cb, self);
}
@@ -461,42 +524,56 @@ account_assistant_page_forward_func (gint current_page,
if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
priv->first_resp == RESPONSE_CREATE_ACCOUNT)
retval = PAGE_ENTER_CREATE;
- if (priv->first_resp == RESPONSE_IMPORT)
+ else if (priv->first_resp == RESPONSE_IMPORT)
retval = PAGE_IMPORT;
+ else if (priv->first_resp == RESPONSE_SALUT_ONLY)
+ retval = PAGE_SALUT;
}
-
- if (current_page == PAGE_IMPORT ||
- current_page >= PAGE_ENTER_CREATE)
- /* don't forward anymore */
- retval = -1;
-
- if (current_page >= PAGE_ENTER_CREATE &&
- priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
+ else if (current_page == PAGE_IMPORT)
+ {
+ if (priv->display_salut_page)
+ retval = PAGE_SALUT;
+ else
+ /* Don't go forward */
+ retval = -1;
+ }
+ else if (current_page == PAGE_SALUT)
+ {
+ /* Don't go forward */
+ retval = -1;
+ }
+ else if (current_page >= PAGE_ENTER_CREATE)
{
- priv->enter_create_forward = TRUE;
- retval = current_page;
+ if (priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
+ {
+ priv->enter_create_forward = TRUE;
+ retval = current_page;
+ }
+ else if (priv->display_salut_page)
+ {
+ retval = PAGE_SALUT;
+ }
+ else
+ {
+ /* Don't go forward */
+ retval = -1;
+ }
}
return retval;
}
static void
-account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
- EmpathyAccountAssistant *self)
+update_intro_page_buttons (EmpathyAccountAssistant *self)
{
- FirstPageResponse response;
EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
GtkWidget *intro_page;
- response = GPOINTER_TO_INT (g_object_get_data
- (G_OBJECT (button), "response"));
-
- priv->first_resp = response;
-
intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self),
PAGE_INTRO);
- if (response == RESPONSE_SALUT_ONLY)
+ if (priv->first_resp == RESPONSE_SALUT_ONLY &&
+ !priv->display_salut_page)
gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
GTK_ASSISTANT_PAGE_SUMMARY);
else
@@ -504,6 +581,21 @@ account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
GTK_ASSISTANT_PAGE_INTRO);
}
+static void
+account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
+ EmpathyAccountAssistant *self)
+{
+ FirstPageResponse response;
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+
+ response = GPOINTER_TO_INT (g_object_get_data
+ (G_OBJECT (button), "response"));
+
+ priv->first_resp = response;
+
+ update_intro_page_buttons (self);
+}
+
static GtkWidget *
account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
{
@@ -671,10 +763,7 @@ account_assistant_radio_create_again_clicked_cb (GtkButton *button,
priv->create_enter_resp = response;
- gtk_assistant_set_page_type (GTK_ASSISTANT (self),
- priv->enter_or_create_page,
- (response == RESPONSE_CREATE_AGAIN) ?
- GTK_ASSISTANT_PAGE_CONTENT : GTK_ASSISTANT_PAGE_CONFIRM);
+ update_create_page_buttons (self);
}
static GtkWidget *
@@ -756,8 +845,6 @@ account_assistant_close_cb (GtkAssistant *assistant,
if (priv->is_creating)
return;
- create_salut_account_if_needed ();
-
gtk_widget_destroy (GTK_WIDGET (assistant));
}
@@ -770,10 +857,16 @@ impl_signal_apply (GtkAssistant *assistant)
current_page = gtk_assistant_get_current_page (assistant);
- if (current_page >= PAGE_ENTER_CREATE)
- account_assistant_apply_account_and_finish (self);
+ if (current_page == PAGE_SALUT)
+ {
+ if (priv->create_salut_account)
+ account_assistant_apply_account_and_finish (self, priv->salut_settings);
+ return;
+ }
- if (current_page == PAGE_IMPORT)
+ if (current_page >= PAGE_ENTER_CREATE)
+ account_assistant_apply_account_and_finish (self, priv->settings);
+ else if (current_page == PAGE_IMPORT)
empathy_import_widget_add_selected_accounts (priv->iw);
}
@@ -793,7 +886,7 @@ impl_signal_prepare (GtkAssistant *assistant,
current_idx = gtk_assistant_get_current_page (assistant);
- if (current_idx >= PAGE_ENTER_CREATE)
+ if (current_idx >= PAGE_ENTER_CREATE && current_idx != PAGE_SALUT)
{
if (!priv->enter_create_forward)
{
@@ -804,7 +897,7 @@ impl_signal_prepare (GtkAssistant *assistant,
else
{
priv->enter_create_forward = FALSE;
- account_assistant_apply_account_and_finish (self);
+ account_assistant_apply_account_and_finish (self, priv->settings);
}
}
}
@@ -822,6 +915,9 @@ do_get_property (GObject *object,
case PROP_PARENT:
g_value_set_object (value, priv->parent_window);
break;
+ case PROP_CONNECTION_MGRS:
+ g_value_set_object (value, priv->connection_mgrs);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -840,26 +936,15 @@ do_set_property (GObject *object,
case PROP_PARENT:
priv->parent_window = g_value_get_object (value);
break;
+ case PROP_CONNECTION_MGRS:
+ priv->connection_mgrs = g_value_dup_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
-do_constructed (GObject *object)
-{
- EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
-
- /* set us as transient for the parent window if any */
- if (priv->parent_window)
- gtk_window_set_transient_for (GTK_WINDOW (object),
- priv->parent_window);
-
- /* set the dialog hint, so this will be centered over the parent window */
- gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
-}
-
-static void
do_dispose (GObject *obj)
{
EmpathyAccountAssistantPriv *priv = GET_PRIV (obj);
@@ -875,6 +960,12 @@ do_dispose (GObject *obj)
priv->settings = NULL;
}
+ g_object_unref (priv->account_mgr);
+ priv->account_mgr = NULL;
+
+ g_object_unref (priv->connection_mgrs);
+ priv->connection_mgrs = NULL;
+
if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL)
G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj);
}
@@ -901,20 +992,206 @@ empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (oclass, PROP_PARENT, param_spec);
+ param_spec = g_param_spec_object ("connection-managers",
+ "connection-managers", "A EmpathyConnectionManagers",
+ EMPATHY_TYPE_CONNECTION_MANAGERS,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property (oclass, PROP_CONNECTION_MGRS, param_spec);
+
g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
}
static void
+create_salut_check_box_toggled_cb (GtkWidget *widget,
+ EmpathyAccountAssistant *self)
+{
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+ gboolean sensitive;
+ gboolean page_valid;
+
+ sensitive = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+
+ gtk_widget_set_sensitive (priv->salut_account_widget, sensitive);
+
+ if (!sensitive)
+ {
+ page_valid = TRUE;
+ priv->create_salut_account = FALSE;
+ }
+ else
+ {
+ /* page is complete if the account is valid */
+ page_valid = empathy_account_settings_is_valid (priv->salut_settings);
+ priv->create_salut_account = TRUE;
+ }
+
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (self), priv->salut_page,
+ page_valid);
+}
+
+static void
+account_assistant_salut_handle_apply_cb (EmpathyAccountWidget *widget_object,
+ gboolean is_valid,
+ EmpathyAccountAssistant *self)
+{
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
+ priv->salut_page, is_valid);
+}
+
+static GtkWidget *
+account_assistant_build_salut_page (EmpathyAccountAssistant *self)
+{
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+ GtkWidget *main_vbox, *hbox_1, *w;
+ GdkPixbuf *pix;
+ EmpathyAccountSettings *settings;
+ GtkWidget *account_widget;
+ EmpathyAccountWidget *widget_object;
+ gchar *markup;
+
+ main_vbox = gtk_vbox_new (FALSE, 12);
+ gtk_widget_show (main_vbox);
+ gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
+
+ hbox_1 = gtk_hbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
+ gtk_widget_show (hbox_1);
+
+ w = gtk_label_new ("");
+ markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
+ _("Empathy can automatically discover and chat with the people "
+ "connected on the same network as you. "
+ "If you want to use this feature, please check that the "
+ "details below are correct. "
+ "You can easily change these details later or disable this feature "
+ "by using the 'Accounts' dialog"),
+ _("Edit->Accounts"));
+ gtk_label_set_markup (GTK_LABEL (w), markup);
+ g_free (markup);
+ gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+ gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
+ gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+
+ pix = empathy_pixbuf_from_icon_name_sized ("im-local-xmpp", 80);
+ w = gtk_image_new_from_pixbuf (pix);
+ gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
+ gtk_widget_show (w);
+
+ g_object_unref (pix);
+
+ w = gtk_check_button_new_with_label (
+ _("I don't want to enable this feature for now"));
+ gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
+ g_signal_connect (w, "toggled",
+ G_CALLBACK (create_salut_check_box_toggled_cb), self);
+ gtk_widget_show (w);
+
+ w = gtk_alignment_new (0, 0, 0, 0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
+ gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
+ gtk_widget_show (w);
+
+ settings = create_salut_account_settings ();
+
+ widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
+ account_widget = empathy_account_widget_get_widget (widget_object);
+
+ priv->salut_settings = settings;
+ priv->salut_account_widget = account_widget;
+
+ g_signal_connect (widget_object, "handle-apply",
+ G_CALLBACK (account_assistant_salut_handle_apply_cb), self);
+
+ gtk_box_pack_start (GTK_BOX (main_vbox), account_widget,
+ FALSE, FALSE, 0);
+ gtk_widget_show (account_widget);
+
+ return main_vbox;
+}
+
+static GtkWidget *
+account_assistant_build_salut_error_page (EmpathyAccountAssistant *self)
+{
+ GtkWidget *vbox;
+ gchar *markup;
+
+ markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
+ _("You won't be able to chat with people connected to your local "
+ "network, as telepathy-salut is not installed.\nIf you want to enable "
+ "this feature, please install the telepathy-salut package\nand create "
+ "a People Nearby account from the Accounts dialog "),
+ _("Edit->Accounts"));
+
+ vbox = build_error_vbox (_("telepathy-salut not installed"), markup);
+ g_free (markup);
+ return vbox;
+}
+
+static void
+account_mgr_prepare_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EmpathyAccountAssistant *self = user_data;
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+ TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
+ GError *error = NULL;
+
+ if (!tp_account_manager_prepare_finish (manager, result, &error))
+ {
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ if (!should_create_salut_account (manager))
+ {
+ DEBUG ("No need to create a Salut account");
+ priv->display_salut_page = FALSE;
+
+ update_intro_page_buttons (self);
+
+ gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->import_page,
+ GTK_ASSISTANT_PAGE_CONFIRM);
+
+ update_create_page_buttons (self);
+ }
+}
+
+static void
empathy_account_assistant_init (EmpathyAccountAssistant *self)
{
EmpathyAccountAssistantPriv *priv;
- GtkAssistant *assistant = GTK_ASSISTANT (self);
- GtkWidget *page;
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
EmpathyAccountAssistantPriv);
self->priv = priv;
+ priv->account_mgr = tp_account_manager_dup ();
+}
+
+static void
+do_constructed (GObject *object)
+{
+ GtkAssistant *assistant = GTK_ASSISTANT (object);
+ EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (object);
+ EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
+ GtkWidget *page;
+
+ /* set us as transient for the parent window if any */
+ if (priv->parent_window)
+ gtk_window_set_transient_for (GTK_WINDOW (object),
+ priv->parent_window);
+
+ /* set the dialog hint, so this will be centered over the parent window */
+ gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+ g_assert (priv->connection_mgrs != NULL);
+ g_assert (empathy_connection_managers_is_ready (priv->connection_mgrs));
+
g_signal_connect (self, "close",
G_CALLBACK (account_assistant_close_cb), NULL);
@@ -936,26 +1213,58 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self)
gtk_assistant_set_page_title (assistant, page,
_("Import your existing accounts"));
gtk_assistant_set_page_complete (assistant, page, TRUE);
- gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
+ gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
+ priv->import_page = page;
/* third page (enter account details) */
page = account_assistant_build_enter_or_create_page (self);
gtk_assistant_append_page (assistant, page);
- gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
+ gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
priv->enter_or_create_page = page;
+ /* fourth page (salut details) */
+ if (empathy_connection_managers_get_cm (priv->connection_mgrs, "salut")
+ != NULL)
+ {
+ page = account_assistant_build_salut_page (self);
+ gtk_assistant_append_page (assistant, page);
+ gtk_assistant_set_page_title (assistant, page,
+ _("Please enter personal details"));
+ gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
+
+ priv->create_salut_account = TRUE;
+ }
+ else
+ {
+ page = account_assistant_build_salut_error_page (self);
+ gtk_assistant_append_page (assistant, page);
+ gtk_assistant_set_page_title (assistant, page, _("An error occurred"));
+ gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_SUMMARY);
+
+ priv->create_salut_account = FALSE;
+ }
+
+ priv->salut_page = page;
+ priv->display_salut_page = TRUE;
+
+ tp_account_manager_prepare_async (priv->account_mgr, NULL,
+ account_mgr_prepare_cb, self);
+
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
}
GtkWidget *
-empathy_account_assistant_show (GtkWindow *window)
+empathy_account_assistant_show (GtkWindow *window,
+ EmpathyConnectionManagers *connection_mgrs)
{
static GtkWidget *dialog = NULL;
if (dialog == NULL)
{
- dialog = g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, "parent-window",
- window, NULL);
+ dialog = g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT,
+ "parent-window", window,
+ "connection-managers", connection_mgrs,
+ NULL);
g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &dialog);
}
diff --git a/src/empathy-account-assistant.h b/src/empathy-account-assistant.h
index ef91fa9da..d99475fe3 100644
--- a/src/empathy-account-assistant.h
+++ b/src/empathy-account-assistant.h
@@ -26,6 +26,8 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include <libempathy/empathy-connection-managers.h>
+
G_BEGIN_DECLS
#define EMPATHY_TYPE_ACCOUNT_ASSISTANT empathy_account_assistant_get_type()
@@ -56,7 +58,8 @@ typedef struct {
GType empathy_account_assistant_get_type (void);
-GtkWidget *empathy_account_assistant_show (GtkWindow *parent);
+GtkWidget *empathy_account_assistant_show (GtkWindow *parent,
+ EmpathyConnectionManagers *connection_mgrs);
G_END_DECLS
diff --git a/src/empathy-auto-salut-account-helper.c b/src/empathy-auto-salut-account-helper.c
index 30842dd43..ad4d6cbc0 100644
--- a/src/empathy-auto-salut-account-helper.c
+++ b/src/empathy-auto-salut-account-helper.c
@@ -79,87 +79,30 @@ should_create_salut_account (TpAccountManager *manager)
return !salut_created;
}
-static void
-salut_account_created (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
+EmpathyAccountSettings *
+create_salut_account_settings (void)
{
- EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
- TpAccount *account;
- GError *error = NULL;
-
- if (!empathy_account_settings_apply_finish (settings, result, &error))
- {
- DEBUG ("Failed to create salut account: %s", error->message);
- g_error_free (error);
- return;
- }
-
- account = empathy_account_settings_get_account (settings);
-
- tp_account_set_enabled_async (account, TRUE, NULL, NULL);
- empathy_conf_set_bool (empathy_conf_get (),
- EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
- TRUE);
-}
-
-static void
-create_salut_account_am_ready_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
- EmpathyConnectionManagers *managers = user_data;
EmpathyAccountSettings *settings;
- TpConnectionManager *manager;
- const TpConnectionManagerProtocol *protocol;
- EBook *book;
- EContact *contact;
- gchar *nickname = NULL;
- gchar *first_name = NULL;
- gchar *last_name = NULL;
- gchar *email = NULL;
- gchar *jid = NULL;
- GError *error = NULL;
-
- if (!tp_account_manager_prepare_finish (account_manager, result, &error))
- {
- DEBUG ("Failed to prepare account manager: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- if (!should_create_salut_account (account_manager))
- goto out;
-
- manager = empathy_connection_managers_get_cm (managers, "salut");
- if (manager == NULL)
- {
- DEBUG ("Salut not installed, not making a salut account");
- goto out;
- }
-
- protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
- if (protocol == NULL)
- {
- DEBUG ("Salut doesn't support local-xmpp!!");
- goto out;
- }
+ EBook *book;
+ EContact *contact;
+ gchar *nickname = NULL;
+ gchar *first_name = NULL;
+ gchar *last_name = NULL;
+ gchar *email = NULL;
+ gchar *jid = NULL;
+ GError *error = NULL;
- DEBUG ("Trying to add a salut account...");
+ settings = empathy_account_settings_new ("salut", "local-xmpp",
+ _("People nearby"));
/* Get self EContact from EDS */
if (!e_book_get_self (&contact, &book, &error))
{
- DEBUG ("Failed to get self econtact: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- goto out;
+ DEBUG ("Failed to get self econtact: %s", error->message);
+ g_error_free (error);
+ return settings;
}
- settings = empathy_account_settings_new ("salut", "local-xmpp",
- _("People nearby"));
-
nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
@@ -185,49 +128,13 @@ create_salut_account_am_ready_cb (GObject *source_object,
empathy_account_settings_set_string (settings, "email", email ? email : "");
empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
- empathy_account_settings_apply_async (settings,
- salut_account_created, NULL);
-
g_free (nickname);
g_free (first_name);
g_free (last_name);
g_free (email);
g_free (jid);
- g_object_unref (settings);
g_object_unref (contact);
g_object_unref (book);
- out:
- g_object_unref (managers);
-}
-
-static void
-create_salut_account_cms_ready_cb (EmpathyConnectionManagers *managers)
-{
- TpAccountManager *manager;
-
- manager = tp_account_manager_dup ();
-
- tp_account_manager_prepare_async (manager, NULL,
- create_salut_account_am_ready_cb, managers);
-
- g_object_unref (manager);
-}
-
-void
-create_salut_account_if_needed (void)
-{
- EmpathyConnectionManagers *managers;
-
- managers = empathy_connection_managers_dup_singleton ();
-
- if (empathy_connection_managers_is_ready (managers))
- {
- create_salut_account_cms_ready_cb (managers);
- }
- else
- {
- g_signal_connect (managers, "notify::ready",
- G_CALLBACK (create_salut_account_cms_ready_cb), NULL);
- }
+ return settings;
}
diff --git a/src/empathy-auto-salut-account-helper.h b/src/empathy-auto-salut-account-helper.h
index 8cec7b8ff..f0409d01d 100644
--- a/src/empathy-auto-salut-account-helper.h
+++ b/src/empathy-auto-salut-account-helper.h
@@ -27,9 +27,10 @@
#include <telepathy-glib/account-manager.h>
#include <libempathy/empathy-connection-managers.h>
-
-void create_salut_account_if_needed (void);
+#include <libempathy/empathy-account-settings.h>
gboolean should_create_salut_account (TpAccountManager *manager);
+EmpathyAccountSettings * create_salut_account_settings (void);
+
#endif
diff --git a/src/empathy.c b/src/empathy.c
index 7bdea3be9..f272ecfec 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -188,16 +188,32 @@ has_non_salut_accounts (TpAccountManager *manager)
return ret;
}
-static void
-maybe_show_account_assistant (void)
+/* Try to import accounts from MC4 and returns TRUE if we should display the
+ * accounts assistant. */
+static gboolean
+should_show_account_assistant (TpAccountManager *account_mgr,
+ EmpathyConnectionManagers *cm_mgr)
{
- TpAccountManager *manager;
- manager = tp_account_manager_dup ();
+ 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 (!has_non_salut_accounts (manager))
- empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()));
+ if (empathy_import_mc4_has_imported ())
+ return FALSE;
- g_object_unref (manager);
+ if (empathy_import_mc4_accounts (cm_mgr))
+ return FALSE;
+
+ if (start_hidden)
+ return FALSE;
+
+ if (has_non_salut_accounts (account_mgr))
+ return FALSE;
+
+ if (!should_create_salut_account (account_mgr))
+ return FALSE;
+
+ return TRUE;
}
static void
@@ -205,16 +221,51 @@ connection_managers_prepare_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
- EmpathyConnectionManagers *managers = EMPATHY_CONNECTION_MANAGERS (source);
+ EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source);
+ TpAccountManager *account_mgr = user_data;
- if (!empathy_connection_managers_prepare_finish (managers, result, NULL))
+ if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
goto out;
- if (!empathy_import_mc4_accounts (managers) && !start_hidden)
- maybe_show_account_assistant ();
+ if (should_show_account_assistant (account_mgr, cm_mgr))
+ empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()),
+ cm_mgr);
out:
- g_object_unref (managers);
+ g_object_unref (cm_mgr);
+ g_object_unref (account_mgr);
+}
+
+static void
+account_manager_ready_for_show_assistant (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccountManager *account_mgr = TP_ACCOUNT_MANAGER (source_object);
+ GError *error = NULL;
+ EmpathyConnectionManagers *cm_mgr;
+
+ if (!tp_account_manager_prepare_finish (account_mgr, result, &error))
+ {
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ g_object_unref (account_mgr);
+ return;
+ }
+
+ cm_mgr = empathy_connection_managers_dup_singleton ();
+
+ empathy_connection_managers_prepare_async (cm_mgr,
+ connection_managers_prepare_cb, account_mgr);
+}
+
+static void
+maybe_show_account_assistant (void)
+{
+ TpAccountManager *account_mgr = tp_account_manager_dup ();
+
+ tp_account_manager_prepare_async (account_mgr, NULL,
+ account_manager_ready_for_show_assistant, NULL);
}
static void
@@ -286,20 +337,46 @@ migrate_config_to_xdg_dir (void)
}
static void
+connection_managers_prepare_for_accounts (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source);
+ GtkWidget *ui;
+
+ if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
+ goto out;
+
+ ui = empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()),
+ cm_mgr);
+
+ if (account_dialog_only)
+ g_signal_connect (ui, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+
+out:
+ g_object_unref (cm_mgr);
+}
+
+static void
do_show_accounts_ui (GtkWindow *window,
TpAccountManager *manager)
{
+ if (has_non_salut_accounts (manager))
+ {
+ GtkWidget *ui;
- GtkWidget *ui;
+ ui = empathy_accounts_dialog_show (window, NULL);
- if (has_non_salut_accounts (manager))
- ui = empathy_accounts_dialog_show (window, NULL);
+ if (account_dialog_only)
+ g_signal_connect (ui, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+ }
else
- ui = empathy_account_assistant_show (window);
+ {
+ EmpathyConnectionManagers *cm_mgr;
- if (account_dialog_only)
- g_signal_connect (ui, "destroy",
- G_CALLBACK (gtk_main_quit), NULL);
+ empathy_connection_managers_prepare_async (cm_mgr,
+ connection_managers_prepare_for_accounts, NULL);
+ }
}
static void
@@ -484,19 +561,7 @@ 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);
- if (should_create_salut_account (manager)
- || !empathy_import_mc4_has_imported ())
- {
- EmpathyConnectionManagers *managers;
- managers = empathy_connection_managers_dup_singleton ();
-
- empathy_connection_managers_prepare_async (managers,
- connection_managers_prepare_cb, NULL);
- }
- else if (!start_hidden)
- {
- maybe_show_account_assistant ();
- }
+ maybe_show_account_assistant ();
g_object_unref (idle);
g_object_unref (connectivity);