aboutsummaryrefslogtreecommitdiffstats
path: root/src/empathy-accounts-dialog.c
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2009-07-23 18:32:23 +0800
committerCosimo Cecchi <cosimoc@gnome.org>2009-07-30 06:13:19 +0800
commit010828ac98b604438cd0edace9263cd120f4ad10 (patch)
treeebcfc63e9e6d16b6606f1424e9fe64a111bcd756 /src/empathy-accounts-dialog.c
parent9dfae3e6a3b7ca4751c2249590eca8317768e9b9 (diff)
downloadgsoc2013-empathy-010828ac98b604438cd0edace9263cd120f4ad10.tar
gsoc2013-empathy-010828ac98b604438cd0edace9263cd120f4ad10.tar.gz
gsoc2013-empathy-010828ac98b604438cd0edace9263cd120f4ad10.tar.bz2
gsoc2013-empathy-010828ac98b604438cd0edace9263cd120f4ad10.tar.lz
gsoc2013-empathy-010828ac98b604438cd0edace9263cd120f4ad10.tar.xz
gsoc2013-empathy-010828ac98b604438cd0edace9263cd120f4ad10.tar.zst
gsoc2013-empathy-010828ac98b604438cd0edace9263cd120f4ad10.zip
GObject-ify and clean-up the code; still WIP
Diffstat (limited to 'src/empathy-accounts-dialog.c')
-rw-r--r--src/empathy-accounts-dialog.c545
1 files changed, 362 insertions, 183 deletions
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index 010493ff2..bad15b974 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -35,6 +35,7 @@
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-account-manager.h>
+#include <libempathy/empathy-connection-managers.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include <libempathy-gtk/empathy-protocol-chooser.h>
#include <libempathy-gtk/empathy-account-widget.h>
@@ -54,6 +55,11 @@
/* Flashing delay for icons (milliseconds). */
#define FLASH_TIMEOUT 500
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
+G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
+
+static EmpathyAccountsDialog *dialog_singleton = NULL;
+
typedef struct {
GtkWidget *window;
@@ -88,7 +94,11 @@ typedef struct {
EmpathyAccountSettings *settings_ready;
EmpathyAccountManager *account_manager;
-} EmpathyAccountsDialog;
+ EmpathyConnectionManagers *cms;
+
+ EmpathyAccount *selected_account;
+ GtkWindow *parent_window;
+} EmpathyAccountsDialogPriv;
enum {
COL_ENABLED,
@@ -99,6 +109,11 @@ enum {
COL_COUNT
};
+enum {
+ PROP_SELECTED_ACCOUNT = 1,
+ PROP_PARENT
+};
+
static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
EmpathyAccountSettings *settings);
static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
@@ -153,18 +168,17 @@ static void accounts_dialog_button_import_clicked_cb (GtkWidget
static void accounts_dialog_response_cb (GtkWidget *widget,
gint response,
EmpathyAccountsDialog *dialog);
-static void accounts_dialog_destroy_cb (GtkWidget *widget,
- EmpathyAccountsDialog *dialog);
static void
accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
EmpathyAccountSettings *settings)
{
gchar *text;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
text = g_markup_printf_escaped ("<big><b>%s</b></big>",
empathy_account_settings_get_display_name (settings));
- gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
+ gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
g_free (text);
}
@@ -208,17 +222,19 @@ static void
account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
EmpathyAccountSettings *settings)
{
- dialog->settings_widget = get_account_setup_widget (settings);
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+
+ priv->settings_widget = get_account_setup_widget (settings);
- gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
- dialog->settings_widget);
- gtk_widget_show (dialog->settings_widget);
+ gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
+ priv->settings_widget);
+ gtk_widget_show (priv->settings_widget);
- gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
+ gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
empathy_account_settings_get_icon_name (settings),
GTK_ICON_SIZE_DIALOG);
- gtk_widget_set_tooltip_text (dialog->image_type,
+ gtk_widget_set_tooltip_text (priv->image_type,
empathy_account_settings_get_protocol (settings));
accounts_dialog_update_name_label (dialog, settings);
@@ -236,18 +252,20 @@ static void
accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
EmpathyAccountSettings *settings)
{
- if (dialog->settings_ready != NULL) {
- g_signal_handler_disconnect (dialog->settings_ready,
- dialog->settings_ready_id);
- dialog->settings_ready = NULL;
- dialog->settings_ready_id = 0;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+
+ if (priv->settings_ready != NULL) {
+ g_signal_handler_disconnect (priv->settings_ready,
+ priv->settings_ready_id);
+ priv->settings_ready = NULL;
+ priv->settings_ready_id = 0;
}
if (!settings) {
GtkTreeView *view;
GtkTreeModel *model;
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
model = gtk_tree_view_get_model (view);
if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
@@ -255,36 +273,35 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
accounts_dialog_model_select_first (dialog);
return;
}
- if (empathy_protocol_chooser_n_protocols (
- EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) {
+ if (empathy_connection_managers_get_cms_num (priv->cms) > 0) {
/* We have no account configured but we have some
* profiles instsalled. The user obviously wants to add
* an account. Click on the Add button for him. */
- accounts_dialog_button_add_clicked_cb (dialog->button_add,
+ accounts_dialog_button_add_clicked_cb (priv->button_add,
dialog);
return;
}
/* No account and no profile, warn the user */
- gtk_widget_hide (dialog->vbox_details);
- gtk_widget_hide (dialog->frame_new_account);
- gtk_widget_show (dialog->frame_no_protocol);
- gtk_widget_set_sensitive (dialog->button_add, FALSE);
- gtk_widget_set_sensitive (dialog->button_remove, FALSE);
+ gtk_widget_hide (priv->vbox_details);
+ gtk_widget_hide (priv->frame_new_account);
+ gtk_widget_show (priv->frame_no_protocol);
+ gtk_widget_set_sensitive (priv->button_add, FALSE);
+ gtk_widget_set_sensitive (priv->button_remove, FALSE);
return;
}
/* We have an account selected, destroy old settings and create a new
* one for the account selected */
- gtk_widget_hide (dialog->frame_new_account);
- gtk_widget_hide (dialog->frame_no_protocol);
- gtk_widget_show (dialog->vbox_details);
- gtk_widget_set_sensitive (dialog->button_add, TRUE);
- gtk_widget_set_sensitive (dialog->button_remove, TRUE);
-
- if (dialog->settings_widget) {
- gtk_widget_destroy (dialog->settings_widget);
- dialog->settings_widget = NULL;
+ gtk_widget_hide (priv->frame_new_account);
+ gtk_widget_hide (priv->frame_no_protocol);
+ gtk_widget_show (priv->vbox_details);
+ gtk_widget_set_sensitive (priv->button_add, TRUE);
+ gtk_widget_set_sensitive (priv->button_remove, TRUE);
+
+ if (priv->settings_widget) {
+ gtk_widget_destroy (priv->settings_widget);
+ priv->settings_widget = NULL;
}
if (empathy_account_settings_is_ready (settings))
@@ -293,8 +310,8 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
}
else
{
- dialog->settings_ready = settings;
- dialog->settings_ready_id =
+ priv->settings_ready = settings;
+ priv->settings_ready_id =
g_signal_connect (settings, "notify::ready",
G_CALLBACK (account_dialog_settings_ready_cb), dialog);
}
@@ -306,6 +323,7 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
{
GtkListStore *store;
GtkTreeSelection *selection;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
store = gtk_list_store_new (COL_COUNT,
G_TYPE_BOOLEAN, /* enabled */
@@ -314,10 +332,10 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
EMPATHY_TYPE_ACCOUNT, /* account */
EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
- gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
+ gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
GTK_TREE_MODEL (store));
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
g_signal_connect (selection, "changed",
@@ -342,14 +360,15 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
GtkTreeModel *model;
GtkTreePath *treepath;
GtkTreeIter iter;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
- dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
+ if (empathy_account_manager_get_connecting_accounts (priv->account_manager) > 0) {
+ priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
(GSourceFunc) accounts_dialog_flash_connecting_cb,
dialog);
}
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
treepath = gtk_tree_path_new_from_string (path);
gtk_tree_model_get_iter (model, &iter, treepath);
gtk_tree_model_get (model, &iter,
@@ -375,8 +394,9 @@ accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
GtkTreePath *treepath;
GtkTreeIter iter;
gboolean enabled;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
treepath = gtk_tree_path_new_from_string (path);
gtk_tree_model_get_iter (model, &iter, treepath);
gtk_tree_model_get (model, &iter,
@@ -402,8 +422,10 @@ accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
gchar *path,
EmpathyAccountsDialog *dialog)
{
- if (dialog->connecting_id) {
- g_source_remove (dialog->connecting_id);
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+
+ if (priv->connecting_id) {
+ g_source_remove (priv->connecting_id);
}
DEBUG ("Editing account name started; stopping flashing");
}
@@ -414,8 +436,9 @@ accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
GtkTreeView *view;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
gtk_tree_view_set_headers_visible (view, TRUE);
/* Enabled column */
@@ -468,9 +491,10 @@ accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
/* select first */
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
model = gtk_tree_view_get_model (view);
if (gtk_tree_model_get_iter_first (model, &iter)) {
@@ -492,6 +516,7 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
const gchar *icon_name;
GdkPixbuf *pixbuf;
TpConnectionStatus status;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
gtk_tree_model_get (model, iter,
COL_STATUS, &status,
@@ -504,7 +529,7 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
if (pixbuf) {
if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
(status == TP_CONNECTION_STATUS_CONNECTING &&
- !dialog->connecting_show)) {
+ !priv->connecting_show)) {
GdkPixbuf *modded_pixbuf;
modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
@@ -542,9 +567,10 @@ accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
GtkTreeSelection *selection;
GtkTreeModel *model;
gboolean ok;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
/* Update the status in the model */
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
selection = gtk_tree_view_get_selection (view);
model = gtk_tree_view_get_model (view);
@@ -578,9 +604,10 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
GtkTreeSelection *selection;
GtkTreeModel *model;
gboolean ok;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
/* Update the status in the model */
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
selection = gtk_tree_view_get_selection (view);
model = gtk_tree_view_get_model (view);
@@ -613,8 +640,9 @@ accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
GtkTreeSelection *selection;
GtkTreeIter iter;
EmpathyAccountSettings *settings;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
selection = gtk_tree_view_get_selection (view);
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -636,8 +664,9 @@ accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog)
GtkTreeSelection *selection;
GtkTreeIter iter;
EmpathyAccount *account;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
selection = gtk_tree_view_get_selection (view);
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -655,8 +684,9 @@ accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
{
GtkTreeSelection *selection;
GtkTreeIter iter;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) {
gtk_tree_selection_select_iter (selection, &iter);
}
@@ -670,8 +700,9 @@ accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
GtkTreeSelection *selection;
GtkTreeIter iter;
EmpathyAccount *account;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
selection = gtk_tree_view_get_selection (view);
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -714,8 +745,9 @@ accounts_dialog_add (EmpathyAccountsDialog *dialog,
GtkTreeModel *model;
GtkTreeIter iter;
const gchar *name;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ 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);
@@ -739,8 +771,9 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
TpConnectionStatus status;
const gchar *name;
gboolean enabled;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
g_object_get (account, "status", &status, NULL);
name = empathy_account_get_display_name (account);
enabled = empathy_account_is_enabled (account);
@@ -757,7 +790,7 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
COL_ACCOUNT_SETTINGS_POINTER, settings,
-1);
- accounts_dialog_connection_changed_cb (dialog->account_manager,
+ accounts_dialog_connection_changed_cb (priv->account_manager,
account,
TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
status,
@@ -777,8 +810,9 @@ accounts_dialog_update (EmpathyAccountsDialog *dialog,
const gchar *name;
gboolean enabled = FALSE;
EmpathyAccount *account;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
name = empathy_account_settings_get_display_name (settings);
account = empathy_account_settings_get_account (settings);
@@ -813,10 +847,11 @@ accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
EmpathyAccountsDialog *dialog)
{
GtkTreeIter iter;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
if (accounts_dialog_get_account_iter (dialog, account, &iter))
gtk_list_store_remove (GTK_LIST_STORE (
- gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview))), &iter);
+ gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
}
static gboolean
@@ -835,10 +870,11 @@ accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
{
GtkTreeView *view;
GtkTreeModel *model;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- dialog->connecting_show = !dialog->connecting_show;
+ priv->connecting_show = !priv->connecting_show;
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
model = gtk_tree_view_get_model (view);
gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
@@ -857,9 +893,10 @@ accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
GtkTreeModel *model;
GtkTreeIter iter;
gboolean found;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
/* Update the status in the model */
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
GtkTreePath *path;
@@ -875,13 +912,13 @@ accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
- if (!found && dialog->connecting_id) {
- g_source_remove (dialog->connecting_id);
- dialog->connecting_id = 0;
+ if (!found && priv->connecting_id) {
+ g_source_remove (priv->connecting_id);
+ priv->connecting_id = 0;
}
- if (found && !dialog->connecting_id) {
- dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
+ if (found && !priv->connecting_id) {
+ priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
(GSourceFunc) accounts_dialog_flash_connecting_cb,
dialog);
}
@@ -894,9 +931,10 @@ enable_or_disable_account (EmpathyAccountsDialog *dialog,
{
GtkTreeModel *model;
GtkTreeIter iter;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
/* Update the status in the model */
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
DEBUG ("Account %s is now %s",
empathy_account_get_display_name (account),
@@ -933,8 +971,9 @@ accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
EmpathyAccountSettings *settings, *selected_settings;
GtkTreeModel *model;
GtkTreeIter iter;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
if (!accounts_dialog_get_account_iter (dialog, account, &iter))
return;
@@ -958,9 +997,10 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button,
gchar *str;
TpConnectionManager *cm;
TpConnectionManagerProtocol *proto;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
cm = empathy_protocol_chooser_dup_selected (
- EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
+ EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
/* Create account */
/* To translator: %s is the protocol name */
@@ -973,7 +1013,7 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button,
if (tp_connection_manager_protocol_can_register (proto)) {
gboolean active;
- active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
+ active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
if (active) {
empathy_account_settings_set_boolean (settings, "register", TRUE);
}
@@ -1002,16 +1042,17 @@ accounts_dialog_protocol_changed_cb (GtkWidget *widget,
{
TpConnectionManager *cm;
TpConnectionManagerProtocol *proto;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
cm = empathy_protocol_chooser_dup_selected (
- EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
+ EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
if (tp_connection_manager_protocol_can_register (proto)) {
- gtk_widget_show (dialog->radiobutton_register);
- gtk_widget_show (dialog->radiobutton_reuse);
+ gtk_widget_show (priv->radiobutton_register);
+ gtk_widget_show (priv->radiobutton_reuse);
} else {
- gtk_widget_hide (dialog->radiobutton_register);
- gtk_widget_hide (dialog->radiobutton_reuse);
+ gtk_widget_hide (priv->radiobutton_register);
+ gtk_widget_hide (priv->radiobutton_reuse);
}
g_object_unref (cm);
}
@@ -1023,30 +1064,31 @@ accounts_dialog_button_add_clicked_cb (GtkWidget *button,
GtkTreeView *view;
GtkTreeSelection *selection;
GtkTreeModel *model;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
- view = GTK_TREE_VIEW (dialog->treeview);
+ view = GTK_TREE_VIEW (priv->treeview);
model = gtk_tree_view_get_model (view);
selection = gtk_tree_view_get_selection (view);
gtk_tree_selection_unselect_all (selection);
- gtk_widget_set_sensitive (dialog->button_add, FALSE);
- gtk_widget_set_sensitive (dialog->button_remove, FALSE);
- gtk_widget_hide (dialog->vbox_details);
- gtk_widget_hide (dialog->frame_no_protocol);
- gtk_widget_show (dialog->frame_new_account);
+ gtk_widget_set_sensitive (priv->button_add, FALSE);
+ gtk_widget_set_sensitive (priv->button_remove, FALSE);
+ gtk_widget_hide (priv->vbox_details);
+ gtk_widget_hide (priv->frame_no_protocol);
+ gtk_widget_show (priv->frame_new_account);
/* If we have no account, no need of a back button */
if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
- gtk_widget_show (dialog->button_back);
+ gtk_widget_show (priv->button_back);
} else {
- gtk_widget_hide (dialog->button_back);
+ gtk_widget_hide (priv->button_back);
}
- accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
+ accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
TRUE);
- gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
- gtk_widget_grab_focus (dialog->combobox_protocol);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
+ gtk_widget_grab_focus (priv->combobox_protocol);
}
static void
@@ -1063,6 +1105,7 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
EmpathyAccount *account;
GtkWidget *message_dialog;
gint res;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
account = accounts_dialog_model_get_selected_account (dialog);
@@ -1072,7 +1115,7 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
return;
}
message_dialog = gtk_message_dialog_new
- (GTK_WINDOW (dialog->window),
+ (GTK_WINDOW (priv->window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
@@ -1099,7 +1142,7 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
res = gtk_dialog_run (GTK_DIALOG (message_dialog));
if (res == GTK_RESPONSE_YES) {
- empathy_account_manager_remove (dialog->account_manager, account);
+ empathy_account_manager_remove (priv->account_manager, account);
accounts_dialog_model_select_first (dialog);
}
gtk_widget_destroy (message_dialog);
@@ -1111,7 +1154,9 @@ static void
accounts_dialog_button_import_clicked_cb (GtkWidget *button,
EmpathyAccountsDialog *dialog)
{
- empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+
+ empathy_import_dialog_show (GTK_WINDOW (priv->window), TRUE);
}
#endif
@@ -1126,33 +1171,109 @@ accounts_dialog_response_cb (GtkWidget *widget,
}
static void
-accounts_dialog_destroy_cb (GtkWidget *widget,
- EmpathyAccountsDialog *dialog)
+accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
+ GParamSpec *pspec,
+ EmpathyAccountsDialog *dialog)
+{
+ if (empathy_connection_managers_is_ready (cms)) {
+ accounts_dialog_update_settings (dialog, NULL);
+ }
+}
+
+static void
+accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
+{
+ GtkBuilder *gui;
+ gchar *filename;
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+
+ filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
+
+ gui = empathy_builder_get_file (filename,
+ "accounts_dialog", &priv->window,
+ "vbox_details", &priv->vbox_details,
+ "frame_no_protocol", &priv->frame_no_protocol,
+ "alignment_settings", &priv->alignment_settings,
+ "treeview", &priv->treeview,
+ "frame_new_account", &priv->frame_new_account,
+ "hbox_type", &priv->hbox_type,
+ "button_create", &priv->button_create,
+ "button_back", &priv->button_back,
+ "radiobutton_reuse", &priv->radiobutton_reuse,
+ "radiobutton_register", &priv->radiobutton_register,
+ "image_type", &priv->image_type,
+ "label_name", &priv->label_name,
+ "button_add", &priv->button_add,
+ "button_remove", &priv->button_remove,
+ "button_import", &priv->button_import,
+ NULL);
+ g_free (filename);
+
+ empathy_builder_connect (gui, dialog,
+ "accounts_dialog", "response", accounts_dialog_response_cb,
+ "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
+ "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
+ "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
+ "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
+#if 0
+/* FIXME MC-5 */
+ "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
+#endif
+ "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
+ NULL);
+
+ g_object_unref (gui);
+
+ priv->combobox_protocol = empathy_protocol_chooser_new ();
+ gtk_box_pack_end (GTK_BOX (priv->hbox_type),
+ priv->combobox_protocol,
+ TRUE, TRUE, 0);
+ gtk_widget_show (priv->combobox_protocol);
+ 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 (priv->window),
+ priv->parent_window);
+ }
+}
+
+static void
+do_finalize (GObject *obj)
+{
+
+}
+
+static void
+do_dispose (GObject *obj)
{
+ EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
GList *accounts, *l;
/* Disconnect signals */
- g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
accounts_dialog_account_added_cb,
dialog);
- g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
accounts_dialog_account_removed_cb,
dialog);
- g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
accounts_dialog_account_enabled_cb,
dialog);
- g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
accounts_dialog_account_disabled_cb,
dialog);
- g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
accounts_dialog_account_changed_cb,
dialog);
- g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
accounts_dialog_connection_changed_cb,
dialog);
/* Delete incomplete accounts */
- accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
+ accounts = empathy_account_manager_dup_accounts (priv->account_manager);
for (l = accounts; l; l = l->next) {
EmpathyAccount *account;
@@ -1160,140 +1281,142 @@ accounts_dialog_destroy_cb (GtkWidget *widget,
if (!empathy_account_is_valid (account)) {
/* FIXME: Warn the user the account is not complete
* and is going to be removed. */
- empathy_account_manager_remove (dialog->account_manager, account);
+ empathy_account_manager_remove (priv->account_manager, account);
}
g_object_unref (account);
}
g_list_free (accounts);
- if (dialog->connecting_id) {
- g_source_remove (dialog->connecting_id);
+ if (priv->connecting_id) {
+ g_source_remove (priv->connecting_id);
}
- g_object_unref (dialog->account_manager);
-
- g_free (dialog);
+ g_object_unref (priv->account_manager);
}
-GtkWidget *
-empathy_accounts_dialog_show (GtkWindow *parent,
- EmpathyAccount *selected_account)
+static GObject *
+do_constructor (GType type,
+ guint n_props,
+ GObjectConstructParam *props)
{
- static EmpathyAccountsDialog *dialog = NULL;
- GtkBuilder *gui;
- gchar *filename;
- GList *accounts, *l;
- gboolean import_asked;
+ GObject *retval;
- if (dialog) {
- gtk_window_present (GTK_WINDOW (dialog->window));
- return dialog->window;
- }
+ if (dialog_singleton) {
+ retval = G_OBJECT (dialog_singleton);
+ } else {
+ retval = G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
+ (type, n_props, props);
- dialog = g_new0 (EmpathyAccountsDialog, 1);
+ dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
+ g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
+ }
- filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
- "src");
- gui = empathy_builder_get_file (filename,
- "accounts_dialog", &dialog->window,
- "vbox_details", &dialog->vbox_details,
- "frame_no_protocol", &dialog->frame_no_protocol,
- "alignment_settings", &dialog->alignment_settings,
- "treeview", &dialog->treeview,
- "frame_new_account", &dialog->frame_new_account,
- "hbox_type", &dialog->hbox_type,
- "button_create", &dialog->button_create,
- "button_back", &dialog->button_back,
- "radiobutton_reuse", &dialog->radiobutton_reuse,
- "radiobutton_register", &dialog->radiobutton_register,
- "image_type", &dialog->image_type,
- "label_name", &dialog->label_name,
- "button_add", &dialog->button_add,
- "button_remove", &dialog->button_remove,
- "button_import", &dialog->button_import,
- NULL);
- g_free (filename);
+ return retval;
+}
- empathy_builder_connect (gui, dialog,
- "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
- "accounts_dialog", "response", accounts_dialog_response_cb,
- "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
- "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
- "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
- "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
-#if 0
-/* FIXME MC-5 */
- "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
-#endif
- "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
- NULL);
+static void
+do_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
+
+ switch (property_id) {
+ case PROP_PARENT:
+ g_value_set_object (value, priv->parent_window);
+ break;
+ case PROP_SELECTED_ACCOUNT:
+ g_value_set_object (value, priv->selected_account);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
- g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
+static void
+do_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
+
+ switch (property_id) {
+ case PROP_PARENT:
+ priv->parent_window = g_value_get_object (value);
+ break;
+ case PROP_SELECTED_ACCOUNT:
+ priv->selected_account = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
- g_object_unref (gui);
+static void
+do_constructed (GObject *object)
+{
+ EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
+ EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+ GList *accounts, *l;
+ gboolean import_asked;
- /* Create protocol chooser */
- dialog->combobox_protocol = empathy_protocol_chooser_new ();
- gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
- dialog->combobox_protocol,
- TRUE, TRUE, 0);
- gtk_widget_show (dialog->combobox_protocol);
- g_signal_connect (dialog->combobox_protocol, "changed",
- G_CALLBACK (accounts_dialog_protocol_changed_cb),
- dialog);
+ accounts_dialog_build_ui (dialog);
/* Set up signalling */
- dialog->account_manager = empathy_account_manager_dup_singleton ();
+ priv->account_manager = empathy_account_manager_dup_singleton ();
- g_signal_connect (dialog->account_manager, "account-created",
+ g_signal_connect (priv->account_manager, "account-created",
G_CALLBACK (accounts_dialog_account_added_cb),
dialog);
- g_signal_connect (dialog->account_manager, "account-deleted",
+ g_signal_connect (priv->account_manager, "account-deleted",
G_CALLBACK (accounts_dialog_account_removed_cb),
dialog);
- g_signal_connect (dialog->account_manager, "account-enabled",
+ g_signal_connect (priv->account_manager, "account-enabled",
G_CALLBACK (accounts_dialog_account_enabled_cb),
dialog);
- g_signal_connect (dialog->account_manager, "account-disabled",
+ g_signal_connect (priv->account_manager, "account-disabled",
G_CALLBACK (accounts_dialog_account_disabled_cb),
dialog);
- g_signal_connect (dialog->account_manager, "account-changed",
+ g_signal_connect (priv->account_manager, "account-changed",
G_CALLBACK (accounts_dialog_account_changed_cb),
dialog);
- g_signal_connect (dialog->account_manager, "account-connection-changed",
+ g_signal_connect (priv->account_manager, "account-connection-changed",
G_CALLBACK (accounts_dialog_connection_changed_cb),
dialog);
accounts_dialog_model_setup (dialog);
/* Add existing accounts */
- accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
+ accounts = empathy_account_manager_dup_accounts (priv->account_manager);
for (l = accounts; l; l = l->next) {
accounts_dialog_add_account (dialog, l->data);
g_object_unref (l->data);
}
g_list_free (accounts);
- if (selected_account) {
+ priv->cms = empathy_connection_managers_dup_singleton ();
+ if (!empathy_connection_managers_is_ready (priv->cms)) {
+ g_signal_connect (priv->cms, "notify::ready",
+ G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
+ }
+
+ if (priv->selected_account) {
GtkTreeSelection *selection;
GtkTreeIter iter;
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
- if (accounts_dialog_get_account_iter (dialog, selected_account, &iter)) {
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
+ if (accounts_dialog_get_account_iter (dialog, priv->selected_account, &iter)) {
gtk_tree_selection_select_iter (selection, &iter);
}
+
+ priv->selected_account = NULL;
} else {
accounts_dialog_model_select_first (dialog);
}
- if (parent) {
- gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
- GTK_WINDOW (parent));
- }
-
- gtk_widget_show (dialog->window);
-
empathy_conf_get_bool (empathy_conf_get (),
EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
@@ -1305,14 +1428,70 @@ empathy_accounts_dialog_show (GtkWindow *parent,
if (!import_asked) {
empathy_conf_set_bool (empathy_conf_get (),
EMPATHY_PREFS_IMPORT_ASKED, TRUE);
- empathy_import_dialog_show (GTK_WINDOW (dialog->window),
+ empathy_import_dialog_show (GTK_WINDOW (priv->window),
FALSE);
}
} else {
- gtk_widget_set_sensitive (dialog->button_import, FALSE);
+ gtk_widget_set_sensitive (priv->button_import, FALSE);
}
#endif
+}
- return dialog->window;
+static void
+empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GParamSpec *param_spec;
+
+ oclass->constructor = do_constructor;
+ oclass->finalize = do_finalize;
+ oclass->dispose = do_dispose;
+ oclass->constructed = do_constructed;
+ oclass->set_property = do_set_property;
+ oclass->get_property = do_get_property;
+
+ param_spec = g_param_spec_object ("parent",
+ "parent", "The parent window",
+ GTK_TYPE_WINDOW,
+ 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 ("selected-account",
+ "selected-account", "The account selected by default",
+ EMPATHY_TYPE_ACCOUNT,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property (oclass, PROP_SELECTED_ACCOUNT, param_spec);
+
+
+ g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
}
+static void
+empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
+{
+ EmpathyAccountsDialogPriv *priv;
+
+ priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
+ EMPATHY_TYPE_ACCOUNTS_DIALOG,
+ EmpathyAccountsDialogPriv);
+ dialog->priv = priv;
+}
+
+/* public methods */
+
+GtkWidget *
+empathy_accounts_dialog_show (GtkWindow *parent,
+ EmpathyAccount *selected_account)
+{
+ EmpathyAccountsDialog *dialog;
+ EmpathyAccountsDialogPriv *priv;
+
+ dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
+ "parent", parent, "selected-account", selected_account, NULL);
+
+ priv = GET_PRIV (dialog);
+
+ gtk_window_present (GTK_WINDOW (priv->window));
+
+ return priv->window;
+}