#include <libempathy-gtk/empathy-cell-renderer-activatable.h>
#include <libempathy-gtk/empathy-contact-widget.h>
#include <libempathy-gtk/empathy-images.h>
+#include <libempathy-gtk/empathy-local-xmpp-assistant-widget.h>
#include <libempathy-gtk/empathy-new-account-dialog.h>
+#include "empathy-accounts-common.h"
#include "empathy-accounts-dialog.h"
#include "empathy-import-dialog.h"
#include "empathy-import-utils.h"
enum
{
NOTEBOOK_PAGE_ACCOUNT = 0,
- NOTEBOOK_PAGE_LOADING
+ NOTEBOOK_PAGE_LOADING,
+ NOTEBOOK_PAGE_NO_PROTOCOL
};
typedef struct {
GtkWidget *image_status;
GtkWidget *throbber;
GtkWidget *enabled_switch;
- GtkWidget *frame_no_protocol;
GtkWidget *treeview;
GtkWidget *button_remove;
GtkWidget *button_import;
- GtkWidget *combobox_protocol;
- GtkWidget *hbox_protocol;
-
GtkWidget *image_type;
GtkWidget *label_name;
GtkWidget *label_type;
static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
EmpathyAccountsDialog *dialog);
-static gboolean accounts_dialog_get_settings_iter (
- EmpathyAccountsDialog *dialog,
- EmpathyAccountSettings *settings,
- GtkTreeIter *iter);
-
static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
EmpathyAccountSettings *settings);
-static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
- EmpathyAccountSettings *settings);
-
static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
- EmpathyAccountSettings *settings);
+ TpAccount *account);
static void accounts_dialog_connection_changed_cb (TpAccount *account,
guint old_status,
message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
+
+ gtk_widget_set_tooltip_text (priv->label_status, message);
+
g_free (message_markup);
}
priv->setting_widget_object);
}
-static void
-accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
-{
- EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- EmpathyAccountSettings *settings;
-
- settings = empathy_protocol_chooser_create_account_settings (
- EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol));
- if (settings == NULL)
- return;
-
- accounts_dialog_add (dialog, settings);
- accounts_dialog_model_set_selected (dialog, settings);
-
- gtk_widget_show_all (priv->hbox_protocol);
-
- g_object_unref (settings);
-}
-
-static void
-accounts_dialog_protocol_changed_cb (GtkWidget *widget,
- EmpathyAccountsDialog *dialog)
-{
- EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- gboolean creating;
- EmpathyAccountSettings *settings;
- gchar *account = NULL, *password = NULL;
-
- /* The "changed" signal is fired during the initiation of the
- * EmpathyProtocolChooser while populating the widget. Such signals should
- * be ignored so we check if we are actually creating a new account. */
- if (priv->setting_widget_object == NULL)
- return;
-
- g_object_get (priv->setting_widget_object,
- "creating-account", &creating, NULL);
- if (!creating)
- return;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
-
- if (!gtk_tree_selection_get_selected (selection, &model, &iter))
- return;
-
- /* Save "account" and "password" parameters */
- g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
-
- if (settings != NULL)
- {
- account = g_strdup (empathy_account_settings_get_string (settings,
- "account"));
- password = g_strdup (empathy_account_settings_get_string (settings,
- "password"));
- g_object_unref (settings);
- }
-
- /* We are creating a new widget to replace the current one, don't ask
- * confirmation to the user. */
- priv->force_change_row = TRUE;
-
- /* We'll update the selection after we create the new account widgets;
- * updating it right now causes problems for the # of accounts = zero case */
- g_signal_handlers_block_by_func (selection,
- accounts_dialog_model_selection_changed, dialog);
-
- gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-
- g_signal_handlers_unblock_by_func (selection,
- accounts_dialog_model_selection_changed, dialog);
-
- accounts_dialog_setup_ui_to_add_account (dialog);
-
- /* Restore "account" and "password" parameters in the new widget */
- if (account != NULL)
- {
- empathy_account_widget_set_account_param (priv->setting_widget_object,
- account);
- g_free (account);
- }
-
- if (password != NULL)
- {
- empathy_account_widget_set_password_param (priv->setting_widget_object,
- password);
- g_free (password);
- }
-}
-
static void
accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
const gchar *primary_text,
if (response == GTK_RESPONSE_OK)
{
EmpathyAccountSettings *settings;
+ TpAccount *account;
settings = empathy_new_account_dialog_get_settings (
EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
- accounts_dialog_add (self, settings);
- accounts_dialog_model_set_selected (self, settings);
+ /* The newly created account has already been added by
+ * accounts_dialog_account_validity_changed_cb so we just
+ * have to select it. */
+ account = empathy_account_settings_get_account (settings);
+ accounts_dialog_model_set_selected (self, account);
}
gtk_widget_destroy (dialog);
return;
}
- if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
- {
- /* We have no account configured but we have some
- * profiles installed. The user obviously wants to add
- * an account. Click on the Add button for him. */
- accounts_dialog_button_add_clicked_cb (priv->button_add,
- dialog);
- return;
- }
/* No account and no profile, warn the user */
gtk_widget_hide (priv->vbox_details);
- gtk_widget_show (priv->frame_no_protocol);
gtk_widget_set_sensitive (priv->button_add, FALSE);
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
+ NOTEBOOK_PAGE_NO_PROTOCOL);
return;
}
/* We have an account selected, destroy old settings and create a new
* one for the account selected */
- gtk_widget_hide (priv->frame_no_protocol);
gtk_widget_show (priv->vbox_details);
- gtk_widget_hide (priv->hbox_protocol);
if (priv->dialog_content)
{
g_object_unref (store);
}
-static gboolean
-accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
- EmpathyAccountSettings *settings,
- GtkTreeIter *iter)
-{
- GtkTreeView *view;
- GtkTreeModel *model;
- gboolean ok;
- EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-
- /* Update the status in the model */
- view = GTK_TREE_VIEW (priv->treeview);
- model = gtk_tree_view_get_model (view);
-
- for (ok = gtk_tree_model_get_iter_first (model, iter);
- ok;
- ok = gtk_tree_model_iter_next (model, iter))
- {
- EmpathyAccountSettings *this_settings;
- gboolean equal;
-
- gtk_tree_model_get (model, iter,
- COL_ACCOUNT_SETTINGS, &this_settings,
- -1);
-
- equal = (this_settings == settings);
- g_object_unref (this_settings);
-
- if (equal)
- return TRUE;
- }
-
- return FALSE;
-}
-
static gboolean
accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
TpAccount *account,
ok;
ok = gtk_tree_model_iter_next (model, iter))
{
- EmpathyAccountSettings *settings;
+ TpAccount *this_account;
gboolean equal;
gtk_tree_model_get (model, iter,
- COL_ACCOUNT_SETTINGS, &settings,
+ COL_ACCOUNT, &this_account,
-1);
- equal = empathy_account_settings_has_account (settings, account);
- g_object_unref (settings);
+ equal = (this_account == account);
+ g_object_unref (this_account);
if (equal)
return TRUE;
static void
accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
- EmpathyAccountSettings *settings)
+ TpAccount *account)
{
GtkTreeIter iter;
- if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
+ if (accounts_dialog_get_account_iter (dialog, account, &iter))
select_and_scroll_to_iter (dialog, &iter);
}
return FALSE;
}
-static void
-accounts_dialog_add (EmpathyAccountsDialog *dialog,
- EmpathyAccountSettings *settings)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- const gchar *name;
- EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
- name = empathy_account_settings_get_display_name (settings);
-
- gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-
- gtk_list_store_set (GTK_LIST_STORE (model), &iter,
- COL_NAME, name,
- COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
- COL_ACCOUNT_SETTINGS, settings,
- -1);
-}
-
static void
accounts_dialog_connection_changed_cb (TpAccount *account,
guint old_status,
const gchar *name;
EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
gboolean selected = FALSE;
+ GtkTreeSelection *selection;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
status = tp_account_get_connection_status (account, NULL);
settings = empathy_account_settings_new_for_account (account);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
+
if (!accounts_dialog_get_account_iter (dialog, account, &iter))
{
+ /* Select the account if it's the first added */
+ if (gtk_tree_selection_count_selected_rows (selection) == 0)
+ selected = TRUE;
+
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
}
else
{
- GtkTreeSelection *selection;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
selected = gtk_tree_selection_iter_is_selected (selection, &iter);
}
g_object_unref (settings);
}
-static void
-account_prepare_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
- TpAccount *account = TP_ACCOUNT (source_object);
- GError *error = NULL;
-
- if (!tp_proxy_prepare_finish (account, result, &error))
- {
- DEBUG ("Failed to prepare account: %s", error->message);
- g_error_free (error);
- return;
- }
-
- accounts_dialog_add_account (dialog, account);
-}
-
static void
accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
TpAccount *account,
gboolean valid,
EmpathyAccountsDialog *dialog)
{
- tp_proxy_prepare_async (account, NULL, account_prepare_cb, dialog);
+ accounts_dialog_add_account (dialog, account);
}
static void
enable_or_disable_account (dialog, account, TRUE);
}
-static void
-accounts_dialog_button_import_clicked_cb (GtkWidget *button,
- EmpathyAccountsDialog *dialog)
+static GtkWidget *
+display_import_dialog (EmpathyAccountsDialog *dialog)
{
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
GtkWidget *import_dialog;
import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
- FALSE);
+ FALSE, priv->cms);
gtk_widget_show (import_dialog);
+
+ return import_dialog;
+}
+
+static void
+accounts_dialog_button_import_clicked_cb (GtkWidget *button,
+ EmpathyAccountsDialog *dialog)
+{
+ display_import_dialog (dialog);
}
static void
select_and_scroll_to_iter (dialog, &iter);
}
+static void
+salut_valid_cb (GtkWidget *widget,
+ gboolean valid,
+ GtkWidget *button)
+{
+ gtk_widget_set_sensitive (button, valid);
+}
+
+static void
+maybe_show_salut_dialog (EmpathyAccountsDialog *self)
+{
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
+ GtkWidget *dialog, *widget, *content, *button;
+ gint response;
+
+ if (!empathy_local_xmpp_assistant_widget_should_create_account (
+ priv->account_manager))
+ return;
+
+ widget = empathy_local_xmpp_assistant_widget_new ();
+ gtk_widget_show (widget);
+
+ dialog = gtk_dialog_new ();
+
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
+ GTK_RESPONSE_NO);
+
+ button = gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("_Connect"), GTK_RESPONSE_YES);
+ gtk_widget_set_sensitive (button, FALSE);
+
+ g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
+ button);
+
+ content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (response == GTK_RESPONSE_YES)
+ {
+ empathy_local_xmpp_assistant_widget_create_account (
+ EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
+static void
+import_dialog_response_cb (GtkDialog *dialog,
+ gint response_id,
+ EmpathyAccountsDialog *self)
+{
+ maybe_show_salut_dialog (self);
+}
+
+static void
+maybe_show_import_dialog (EmpathyAccountsDialog *self)
+{
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
+ GtkWidget *dialog;
+
+ if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
+ return;
+
+ if (!empathy_import_accounts_to_import ())
+ {
+ maybe_show_salut_dialog (self);
+ return;
+ }
+
+ dialog = display_import_dialog (self);
+
+ tp_g_signal_connect_object (dialog, "response",
+ G_CALLBACK (import_dialog_response_cb), self, 0);
+}
+
static void
finished_loading (EmpathyAccountsDialog *self)
{
gtk_spinner_stop (GTK_SPINNER (priv->spinner));
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
NOTEBOOK_PAGE_ACCOUNT);
+
+ maybe_show_import_dialog (self);
}
static void
gui = empathy_builder_get_file (filename,
"accounts_dialog_hbox", &top_hbox,
"vbox_details", &priv->vbox_details,
- "frame_no_protocol", &priv->frame_no_protocol,
"alignment_settings", &priv->alignment_settings,
"alignment_infobar", &priv->alignment_infobar,
"treeview", &priv->treeview,
"button_add", &priv->button_add,
"button_remove", &priv->button_remove,
"button_import", &priv->button_import,
- "hbox_protocol", &priv->hbox_protocol,
"notebook_account", &priv->notebook_account,
"alignment_loading", &alig,
"accounts_sw", &sw,
NULL);
g_free (filename);
- gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
-
empathy_builder_connect (gui, dialog,
"button_add", "clicked", accounts_dialog_button_add_clicked_cb,
"button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
gtk_widget_set_sensitive (priv->button_import, FALSE);
gtk_widget_set_sensitive (priv->treeview, FALSE);
- priv->combobox_protocol = empathy_protocol_chooser_new ();
- gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
- TRUE, TRUE, 0);
- g_signal_connect (priv->combobox_protocol, "changed",
- G_CALLBACK (accounts_dialog_protocol_changed_cb),
- dialog);
-
if (priv->parent_window)
gtk_window_set_transient_for (GTK_WINDOW (dialog),
priv->parent_window);
TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
priv->label_status = gtk_label_new (NULL);
- gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
+ gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);