#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-new-account-dialog.h>
#include "empathy-accounts-dialog.h"
#include "empathy-import-dialog.h"
GtkWidget *button_remove;
GtkWidget *button_import;
- GtkWidget *combobox_protocol;
GtkWidget *hbox_protocol;
GtkWidget *image_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,
empathy_account_dialog_cancel (dialog);
}
-static void
-empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
- TpAccount *account,
- EmpathyAccountsDialog *dialog)
-{
- EmpathyAccountSettings *settings =
- accounts_dialog_model_get_selected_settings (dialog);
- EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-
- accounts_dialog_update_settings (dialog, settings);
- accounts_dialog_update_status_infobar (dialog,
- empathy_account_settings_get_account (settings));
-
- gtk_widget_set_sensitive (priv->treeview, TRUE);
- gtk_widget_set_sensitive (priv->button_add, TRUE);
- gtk_widget_set_sensitive (priv->button_remove, TRUE);
- gtk_widget_set_sensitive (priv->button_import, TRUE);
-
- if (settings)
- g_object_unref (settings);
-}
-
static gboolean
accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
{
content = empathy_account_widget_get_widget (priv->setting_widget_object);
- g_signal_connect (priv->setting_widget_object, "account-created",
- G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
g_signal_connect (priv->setting_widget_object, "cancelled",
G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
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,
static void
accounts_dialog_button_add_clicked_cb (GtkWidget *button,
- EmpathyAccountsDialog *dialog)
+ EmpathyAccountsDialog *self)
{
- accounts_dialog_setup_ui_to_add_account (dialog);
- account_dialog_create_edit_params_dialog (dialog);
+ GtkWidget *dialog;
+ gint response;
+
+ dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (response == GTK_RESPONSE_OK)
+ {
+ EmpathyAccountSettings *settings;
+ TpAccount *account;
+
+ settings = empathy_new_account_dialog_get_settings (
+ EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
+
+ /* 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);
}
static void
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,
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
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);