2 * Copyright (C) 2006-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
21 * Martyn Russell <martyn@imendio.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
31 #include <glib/gi18n-lib.h>
34 #include <mx-gtk/mx-gtk.h>
35 #endif /* HAVE_MEEGO */
37 #include <libempathy/empathy-utils.h>
39 #include <telepathy-glib/account.h>
40 #include <telepathy-glib/account-manager.h>
41 #include <telepathy-glib/connection-manager.h>
42 #include <telepathy-glib/util.h>
43 #include <dbus/dbus-protocol.h>
45 #include "empathy-account-widget.h"
46 #include "empathy-account-widget-private.h"
47 #include "empathy-account-widget-sip.h"
48 #include "empathy-account-widget-irc.h"
49 #include "empathy-ui-utils.h"
51 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
52 #include <libempathy/empathy-debug.h>
54 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT)
57 EmpathyAccountSettings *settings;
59 GtkWidget *table_common_settings;
60 GtkWidget *apply_button;
61 GtkWidget *cancel_button;
62 GtkWidget *entry_password;
63 GtkWidget *spinbutton_port;
64 GtkWidget *enabled_checkbox;
65 GtkWidget *radiobutton_reuse;
69 gboolean contains_pending_changes;
71 /* An EmpathyAccountWidget can be used to either create an account or
72 * modify it. When we are creating an account, this member is set to TRUE */
73 gboolean creating_account;
75 /* whether there are any other real accounts. Necessary so we know whether
76 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
77 * button should be sensitive) */
78 gboolean other_accounts_exist;
80 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
81 * embedded in this account widget can't be used any more
82 * workaround because some async callbacks can be called after the
83 * widget has been destroyed */
86 TpAccountManager *account_manager;
88 GtkWidget *param_account_widget;
89 GtkWidget *param_password_widget;
91 /* Used only for IRC accounts */
92 EmpathyIrcNetworkChooser *irc_network_chooser;
95 } EmpathyAccountWidgetPriv;
101 PROP_CREATING_ACCOUNT,
102 PROP_OTHER_ACCOUNTS_EXIST,
112 static void account_widget_apply_and_log_in (EmpathyAccountWidget *);
114 static guint signals[LAST_SIGNAL] = { 0 };
116 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
117 #define CHANGED_TIMEOUT 300
120 #define DIGITS "(["DIGIT"]+)"
121 #define ALPHA "a-zA-Z"
122 #define ALPHAS "(["ALPHA"]+)"
123 #define ALPHADIGIT ALPHA DIGIT
124 #define ALPHADIGITS "(["ALPHADIGIT"]+)"
125 #define ALPHADIGITDASH ALPHA DIGIT "-"
126 #define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
128 #define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
129 #define TOPLABEL ALPHAS"|(["ALPHA"]" ALPHADIGITDASHS "["ALPHADIGIT"])"
130 #define DOMAINLABEL ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
132 #define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
133 /* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
134 #define HOST "("HOSTNAME "|" HOSTNUMBER")"
135 /* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
136 #define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
138 /* UIN is digital according to the unofficial specification:
139 * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
140 * 5 digits minimun according to http://en.wikipedia.org/wiki/ICQ#UIN */
141 #define ICQ_USER_NAME "(["DIGIT"]{5,})"
142 /* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
143 #define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
144 #define IRC_USER_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
145 /* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
146 * We just exclude invalid characters to avoid ucschars and other redundant
148 #define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
149 /* ID is an email according to the unofficial specification:
150 * http://www.hypothetic.org/docs/msn/general/names.php */
151 #define MSN_USER_NAME EMAIL_LOCALPART
152 /* Based on the official help:
153 * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html */
154 #define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})"
156 #define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
157 #define ACCOUNT_REGEX_IRC "^"IRC_USER_NAME"$"
158 #define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@"HOST"$"
159 #define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
160 #define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
163 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
166 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
170 /* we hit this case because of the 'other-accounts-exist' property handler
171 * being called during init (before constructed()) */
172 if (priv->apply_button == NULL || priv->cancel_button == NULL)
175 gtk_widget_set_sensitive (priv->apply_button, sensitive);
176 gtk_widget_set_sensitive (priv->cancel_button,
177 (sensitive || priv->creating_account) && priv->other_accounts_exist);
182 account_widget_set_entry_highlighting (GtkEntry *entry, gboolean highlight)
187 g_return_if_fail (GTK_IS_ENTRY (entry));
189 style = gtk_widget_get_style (GTK_WIDGET (entry));
193 color = style->bg[GTK_STATE_SELECTED];
195 /* Here we take the current theme colour and add it to
196 * the colour for white and average the two. This
197 * gives a colour which is inline with the theme but
200 color.red = (color.red + (style->white).red) / 2;
201 color.green = (color.green + (style->white).green) / 2;
202 color.blue = (color.blue + (style->white).blue) / 2;
204 gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, &color);
207 gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
211 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
213 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
216 is_valid = empathy_account_settings_is_valid (priv->settings);
219 account_widget_set_control_buttons_sensitivity (self, is_valid);
221 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
225 account_widget_entry_changed_common (EmpathyAccountWidget *self,
226 GtkEntry *entry, gboolean focus)
229 const gchar *param_name;
230 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
231 gboolean prev_status;
232 gboolean curr_status;
234 str = gtk_entry_get_text (entry);
235 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
236 prev_status = empathy_account_settings_parameter_is_valid (priv->settings,
239 if (EMP_STR_EMPTY (str))
241 const gchar *value = NULL;
243 empathy_account_settings_unset (priv->settings, param_name);
247 value = empathy_account_settings_get_string (priv->settings,
249 DEBUG ("Unset %s and restore to %s", param_name, value);
250 gtk_entry_set_text (entry, value ? value : "");
255 DEBUG ("Setting %s to %s", param_name,
256 tp_strdiff (param_name, "password") ? str : "***");
257 empathy_account_settings_set_string (priv->settings, param_name, str);
260 curr_status = empathy_account_settings_parameter_is_valid (priv->settings,
262 if (curr_status != prev_status)
263 account_widget_set_entry_highlighting (entry, !curr_status);
267 account_widget_entry_changed_cb (GtkEditable *entry,
268 EmpathyAccountWidget *self)
270 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
271 empathy_account_widget_changed (self);
275 account_widget_entry_map_cb (GtkEntry *entry,
276 EmpathyAccountWidget *self)
278 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
279 const gchar *param_name;
282 /* need to initialize input highlighting */
283 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
284 is_valid = empathy_account_settings_parameter_is_valid (priv->settings,
286 account_widget_set_entry_highlighting (entry, !is_valid);
290 account_widget_int_changed_cb (GtkWidget *widget,
291 EmpathyAccountWidget *self)
293 const gchar *param_name;
295 const gchar *signature;
296 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
298 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
299 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
301 signature = empathy_account_settings_get_dbus_signature (priv->settings,
303 g_return_if_fail (signature != NULL);
305 DEBUG ("Setting %s to %d", param_name, value);
307 switch ((int)*signature)
309 case DBUS_TYPE_INT16:
310 case DBUS_TYPE_INT32:
311 empathy_account_settings_set_int32 (priv->settings, param_name, value);
313 case DBUS_TYPE_INT64:
314 empathy_account_settings_set_int64 (priv->settings, param_name, value);
316 case DBUS_TYPE_UINT16:
317 case DBUS_TYPE_UINT32:
318 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
320 case DBUS_TYPE_UINT64:
321 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
324 g_return_if_reached ();
327 empathy_account_widget_changed (self);
331 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
332 EmpathyAccountWidget *self)
335 gboolean default_value;
336 const gchar *param_name;
337 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
339 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
340 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
342 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
343 * always unset the param and set the value if different from the
345 empathy_account_settings_unset (priv->settings, param_name);
346 default_value = empathy_account_settings_get_boolean (priv->settings,
349 if (default_value == value)
351 DEBUG ("Unset %s and restore to %d", param_name, default_value);
355 DEBUG ("Setting %s to %d", param_name, value);
356 empathy_account_settings_set_boolean (priv->settings, param_name, value);
359 empathy_account_widget_changed (self);
363 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
364 EmpathyAccountWidget *self)
366 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
370 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
371 port = empathy_account_settings_get_uint32 (priv->settings, "port");
375 if (port == 5222 || port == 0)
380 if (port == 5223 || port == 0)
384 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
386 priv->contains_pending_changes = TRUE;
390 account_widget_combobox_changed_cb (GtkWidget *widget,
391 EmpathyAccountWidget *self)
397 const gchar *default_value = NULL;
398 const gchar *param_name;
399 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
401 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
404 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
405 /* the param value is stored in the first column */
406 gtk_tree_model_get (model, &iter, 0, &value, -1);
408 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
410 v = empathy_account_settings_get_default (priv->settings, param_name);
412 default_value = g_value_get_string (v);
414 if (!tp_strdiff (value, default_value))
416 DEBUG ("Unset %s and restore to %s", param_name, default_value);
417 empathy_account_settings_unset (priv->settings, param_name);
421 DEBUG ("Setting %s to %s", param_name, value);
422 empathy_account_settings_set_string (priv->settings, param_name, value);
425 empathy_account_widget_changed (self);
429 clear_icon_released_cb (GtkEntry *entry,
430 GtkEntryIconPosition icon_pos,
432 EmpathyAccountWidget *self)
434 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
435 const gchar *param_name;
437 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
439 DEBUG ("Unset %s", param_name);
440 empathy_account_settings_unset (priv->settings, param_name);
441 gtk_entry_set_text (entry, "");
443 empathy_account_widget_changed (self);
447 password_entry_changed_cb (GtkEditable *entry,
448 EmpathyAccountWidget *self)
452 str = gtk_entry_get_text (GTK_ENTRY (entry));
454 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
455 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
459 password_entry_activated_cb (GtkEntry *entry,
460 EmpathyAccountWidget *self)
462 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
464 if (gtk_widget_get_sensitive (priv->apply_button))
465 account_widget_apply_and_log_in (self);
469 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
471 const gchar *param_name)
473 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
475 g_object_set_data_full (G_OBJECT (widget), "param_name",
476 g_strdup (param_name), g_free);
478 if (GTK_IS_SPIN_BUTTON (widget))
481 const gchar *signature;
483 signature = empathy_account_settings_get_dbus_signature (priv->settings,
485 g_return_if_fail (signature != NULL);
487 switch ((int)*signature)
489 case DBUS_TYPE_INT16:
490 case DBUS_TYPE_INT32:
491 value = empathy_account_settings_get_int32 (priv->settings,
494 case DBUS_TYPE_INT64:
495 value = empathy_account_settings_get_int64 (priv->settings,
498 case DBUS_TYPE_UINT16:
499 case DBUS_TYPE_UINT32:
500 value = empathy_account_settings_get_uint32 (priv->settings,
503 case DBUS_TYPE_UINT64:
504 value = empathy_account_settings_get_uint64 (priv->settings,
508 g_return_if_reached ();
511 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
513 g_signal_connect (widget, "value-changed",
514 G_CALLBACK (account_widget_int_changed_cb),
517 else if (GTK_IS_ENTRY (widget))
519 const gchar *str = NULL;
521 str = empathy_account_settings_get_string (priv->settings, param_name);
522 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
524 if (!tp_strdiff (param_name, "account"))
525 priv->param_account_widget = widget;
526 else if (!tp_strdiff (param_name, "password"))
527 priv->param_password_widget = widget;
529 if (strstr (param_name, "password"))
531 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
533 /* Add 'clear' icon */
534 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
535 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
537 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
538 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
540 g_signal_connect (widget, "icon-release",
541 G_CALLBACK (clear_icon_released_cb), self);
542 g_signal_connect (widget, "changed",
543 G_CALLBACK (password_entry_changed_cb), self);
544 g_signal_connect (widget, "activate",
545 G_CALLBACK (password_entry_activated_cb), self);
548 g_signal_connect (widget, "changed",
549 G_CALLBACK (account_widget_entry_changed_cb), self);
550 g_signal_connect (widget, "map",
551 G_CALLBACK (account_widget_entry_map_cb), self);
553 else if (GTK_IS_TOGGLE_BUTTON (widget))
555 gboolean value = FALSE;
557 value = empathy_account_settings_get_boolean (priv->settings,
559 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
561 g_signal_connect (widget, "toggled",
562 G_CALLBACK (account_widget_checkbutton_toggled_cb),
565 else if (GTK_IS_COMBO_BOX (widget))
567 /* The combo box's model has to contain the param value in its first
568 * column (as a string) */
574 str = empathy_account_settings_get_string (priv->settings, param_name);
575 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
577 valid = gtk_tree_model_get_iter_first (model, &iter);
582 gtk_tree_model_get (model, &iter, 0, &name, -1);
583 if (!tp_strdiff (name, str))
585 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
590 valid = gtk_tree_model_iter_next (model, &iter);
596 g_signal_connect (widget, "changed",
597 G_CALLBACK (account_widget_combobox_changed_cb),
602 DEBUG ("Unknown type of widget for param %s", param_name);
607 build_translated_params (void)
611 hash = g_hash_table_new (g_str_hash, g_str_equal);
612 g_hash_table_insert (hash, "account", _("Account"));
613 g_hash_table_insert (hash, "password", _("Password"));
614 g_hash_table_insert (hash, "server", _("Server"));
615 g_hash_table_insert (hash, "port", _("Port"));
621 account_widget_generic_format_param_name (const gchar *param_name)
625 static GHashTable *translated_params = NULL;
627 if (G_UNLIKELY (translated_params == NULL))
628 translated_params = build_translated_params ();
630 /* Translate most common parameters */
631 str = g_hash_table_lookup (translated_params, param_name);
633 return g_strdup (str);
635 str = g_strdup (param_name);
637 if (str && g_ascii_isalpha (str[0]))
638 str[0] = g_ascii_toupper (str[0]);
640 while ((p = strchr (str, '-')) != NULL)
642 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
645 p[1] = g_ascii_toupper (p[1]);
655 accounts_widget_generic_setup (EmpathyAccountWidget *self,
656 GtkWidget *table_common_settings,
657 GtkWidget *table_advanced_settings)
659 TpConnectionManagerParam *params, *param;
660 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
662 params = empathy_account_settings_get_tp_params (priv->settings);
664 for (param = params; param != NULL && param->name != NULL; param++)
666 GtkWidget *table_settings;
668 GtkWidget *widget = NULL;
669 gchar *param_name_formatted;
671 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
672 table_settings = table_common_settings;
673 else if (priv->simple)
676 table_settings = table_advanced_settings;
678 param_name_formatted = account_widget_generic_format_param_name
680 g_object_get (table_settings, "n-rows", &n_rows, NULL);
681 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
683 if (param->dbus_signature[0] == 's')
687 str = g_strdup_printf (_("%s:"), param_name_formatted);
688 widget = gtk_label_new (str);
689 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
692 gtk_table_attach (GTK_TABLE (table_settings),
698 gtk_widget_show (widget);
700 widget = gtk_entry_new ();
701 if (strcmp (param->name, "account") == 0)
703 g_signal_connect (widget, "realize",
704 G_CALLBACK (gtk_widget_grab_focus),
707 gtk_table_attach (GTK_TABLE (table_settings),
711 GTK_FILL | GTK_EXPAND, 0,
713 gtk_widget_show (widget);
715 /* int types: ynqiuxt. double type is 'd' */
716 else if (param->dbus_signature[0] == 'y' ||
717 param->dbus_signature[0] == 'n' ||
718 param->dbus_signature[0] == 'q' ||
719 param->dbus_signature[0] == 'i' ||
720 param->dbus_signature[0] == 'u' ||
721 param->dbus_signature[0] == 'x' ||
722 param->dbus_signature[0] == 't' ||
723 param->dbus_signature[0] == 'd')
730 switch (param->dbus_signature[0])
732 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
733 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
734 case 'q': minint = 0; maxint = G_MAXUINT16; break;
735 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
736 case 'u': minint = 0; maxint = G_MAXUINT32; break;
737 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
738 case 't': minint = 0; maxint = G_MAXUINT64; break;
739 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
741 default: g_assert_not_reached ();
744 str = g_strdup_printf (_("%s:"), param_name_formatted);
745 widget = gtk_label_new (str);
746 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
749 gtk_table_attach (GTK_TABLE (table_settings),
755 gtk_widget_show (widget);
757 widget = gtk_spin_button_new_with_range (minint, maxint, step);
758 gtk_table_attach (GTK_TABLE (table_settings),
762 GTK_FILL | GTK_EXPAND, 0,
764 gtk_widget_show (widget);
766 else if (param->dbus_signature[0] == 'b')
768 widget = gtk_check_button_new_with_label (param_name_formatted);
769 gtk_table_attach (GTK_TABLE (table_settings),
773 GTK_FILL | GTK_EXPAND, 0,
775 gtk_widget_show (widget);
779 DEBUG ("Unknown signature for param %s: %s",
780 param_name_formatted, param->dbus_signature);
784 empathy_account_widget_setup_widget (self, widget, param->name);
786 g_free (param_name_formatted);
791 account_widget_handle_params_valist (EmpathyAccountWidget *self,
792 const gchar *first_widget,
798 for (name = first_widget; name; name = va_arg (args, const gchar *))
800 const gchar *param_name;
802 param_name = va_arg (args, const gchar *);
803 object = gtk_builder_get_object (self->ui_details->gui, name);
807 g_warning ("Builder is missing object '%s'.", name);
811 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
817 account_widget_cancel_clicked_cb (GtkWidget *button,
818 EmpathyAccountWidget *self)
820 g_signal_emit (self, signals[CANCELLED], 0);
824 account_widget_account_enabled_cb (GObject *source_object,
828 GError *error = NULL;
829 TpAccount *account = TP_ACCOUNT (source_object);
830 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
831 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
833 tp_account_set_enabled_finish (account, res, &error);
837 DEBUG ("Could not enable the account: %s", error->message);
838 g_error_free (error);
842 empathy_connect_new_account (account, priv->account_manager);
845 /* unref widget - part of the workaround */
846 g_object_unref (widget);
850 account_widget_applied_cb (GObject *source_object,
854 GError *error = NULL;
856 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
857 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
858 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
860 empathy_account_settings_apply_finish (settings, res, &error);
864 DEBUG ("Could not apply changes to account: %s", error->message);
865 g_error_free (error);
869 account = empathy_account_settings_get_account (priv->settings);
873 if (priv->creating_account)
875 /* By default, when an account is created, we enable it. */
877 /* workaround to keep widget alive during async call */
878 g_object_ref (widget);
880 tp_account_set_enabled_async (account, TRUE,
881 account_widget_account_enabled_cb, widget);
882 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
884 else if (priv->enabled_checkbox != NULL)
886 gboolean enabled_checked;
890 mx_gtk_light_switch_get_active (
891 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
893 gtk_toggle_button_get_active (
894 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
895 #endif /* HAVE_MEEGO */
897 if (tp_account_is_enabled (account) && enabled_checked)
899 /* After having applied changes to a user account, we
900 * automatically reconnect it. This is done so the new
901 * information entered by the user is validated on the server. */
902 tp_account_reconnect_async (account, NULL, NULL);
907 if (!priv->destroyed)
908 account_widget_set_control_buttons_sensitivity (widget, FALSE);
910 priv->contains_pending_changes = FALSE;
912 /* unref the widget - part of the workaround */
913 g_object_unref (widget);
917 account_widget_apply_and_log_in (EmpathyAccountWidget *self)
919 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
920 gboolean display_name_overridden;
922 if (priv->radiobutton_reuse != NULL)
924 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
925 priv->radiobutton_reuse));
927 DEBUG ("Set register param: %d", !reuse);
928 empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
931 g_object_get (priv->settings,
932 "display-name-overridden", &display_name_overridden, NULL);
934 if (priv->creating_account || !display_name_overridden)
938 /* set default display name for new accounts or update if user didn't
939 * manually override it. */
940 display_name = empathy_account_widget_get_default_display_name (self);
942 empathy_account_settings_set_display_name_async (priv->settings,
943 display_name, NULL, NULL);
945 g_free (display_name);
948 /* workaround to keep widget alive during async call */
950 empathy_account_settings_apply_async (priv->settings,
951 account_widget_applied_cb, self);
955 account_widget_apply_clicked_cb (GtkWidget *button,
956 EmpathyAccountWidget *self)
958 account_widget_apply_and_log_in (self);
962 account_widget_setup_generic (EmpathyAccountWidget *self)
964 GtkWidget *table_common_settings;
965 GtkWidget *table_advanced_settings;
967 table_common_settings = GTK_WIDGET (gtk_builder_get_object
968 (self->ui_details->gui, "table_common_settings"));
969 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
970 (self->ui_details->gui, "table_advanced_settings"));
972 accounts_widget_generic_setup (self, table_common_settings,
973 table_advanced_settings);
975 g_object_unref (self->ui_details->gui);
979 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
983 EmpathyAccountWidget *self = user_data;
984 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
986 if (empathy_account_settings_is_ready (priv->settings))
987 account_widget_setup_generic (self);
991 account_widget_build_generic (EmpathyAccountWidget *self,
992 const char *filename)
994 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
995 GtkWidget *expander_advanced;
997 self->ui_details->gui = empathy_builder_get_file (filename,
998 "table_common_settings", &priv->table_common_settings,
999 "vbox_generic_settings", &self->ui_details->widget,
1000 "expander_advanced_settings", &expander_advanced,
1004 gtk_widget_hide (expander_advanced);
1006 g_object_ref (self->ui_details->gui);
1008 if (empathy_account_settings_is_ready (priv->settings))
1009 account_widget_setup_generic (self);
1011 g_signal_connect (priv->settings, "notify::ready",
1012 G_CALLBACK (account_widget_settings_ready_cb), self);
1016 account_widget_build_salut (EmpathyAccountWidget *self,
1017 const char *filename)
1019 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1020 GtkWidget *expander_advanced;
1022 self->ui_details->gui = empathy_builder_get_file (filename,
1023 "table_common_settings", &priv->table_common_settings,
1024 "vbox_salut_settings", &self->ui_details->widget,
1025 "expander_advanced_settings", &expander_advanced,
1028 empathy_account_widget_handle_params (self,
1029 "entry_published", "published-name",
1030 "entry_nickname", "nickname",
1031 "entry_first_name", "first-name",
1032 "entry_last_name", "last-name",
1033 "entry_email", "email",
1038 gtk_widget_hide (expander_advanced);
1040 self->ui_details->default_focus = g_strdup ("entry_first_name");
1044 account_widget_build_irc (EmpathyAccountWidget *self,
1045 const char *filename)
1047 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1049 empathy_account_settings_set_regex (priv->settings, "account",
1054 priv->irc_network_chooser = empathy_account_widget_irc_build_simple (self,
1059 priv->irc_network_chooser = empathy_account_widget_irc_build (self,
1060 filename, &priv->table_common_settings);
1065 account_widget_build_sip (EmpathyAccountWidget *self,
1066 const char *filename)
1068 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1069 empathy_account_widget_sip_build (self, filename,
1070 &priv->table_common_settings);
1074 account_widget_build_msn (EmpathyAccountWidget *self,
1075 const char *filename)
1077 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1079 empathy_account_settings_set_regex (priv->settings, "account",
1084 self->ui_details->gui = empathy_builder_get_file (filename,
1085 "vbox_msn_simple", &self->ui_details->widget,
1088 empathy_account_widget_handle_params (self,
1089 "entry_id_simple", "account",
1090 "entry_password_simple", "password",
1093 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1097 self->ui_details->gui = empathy_builder_get_file (filename,
1098 "table_common_msn_settings", &priv->table_common_settings,
1099 "vbox_msn_settings", &self->ui_details->widget,
1102 empathy_account_widget_handle_params (self,
1103 "entry_id", "account",
1104 "entry_password", "password",
1105 "entry_server", "server",
1106 "spinbutton_port", "port",
1109 self->ui_details->default_focus = g_strdup ("entry_id");
1114 account_widget_is_gtalk (EmpathyAccountWidget *self)
1116 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1118 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
1123 account_widget_is_facebook (EmpathyAccountWidget *self)
1125 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1127 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
1131 #define FACEBOOK_SUFFIX "@chat.facebook.com"
1134 facebook_id_widget_changed_cb (GtkWidget *entry,
1135 EmpathyAccountWidget *self)
1137 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1138 const gchar *account;
1140 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1142 account = empathy_account_settings_get_string (priv->settings, "account");
1143 if (!EMP_STR_EMPTY (account) &&
1144 !g_str_has_suffix (account, FACEBOOK_SUFFIX))
1148 tmp = g_strdup_printf ("%s%s", account, FACEBOOK_SUFFIX);
1150 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1152 empathy_account_settings_set_string (priv->settings, "account", tmp);
1156 empathy_account_widget_changed (self);
1160 remove_facebook_suffix (const gchar *str)
1162 if (!g_str_has_suffix (str, FACEBOOK_SUFFIX))
1163 return g_strdup (str);
1165 return g_strndup (str, strlen (str) - strlen (FACEBOOK_SUFFIX));
1169 setup_facebook_id_widget (EmpathyAccountWidget *self,
1172 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1173 const gchar *str = NULL;
1175 g_object_set_data_full (G_OBJECT (widget), "param_name",
1176 g_strdup ("account"), g_free);
1178 str = empathy_account_settings_get_string (priv->settings, "account");
1183 tmp = remove_facebook_suffix (str);
1184 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1188 priv->param_account_widget = widget;
1190 g_signal_connect (widget, "changed",
1191 G_CALLBACK (facebook_id_widget_changed_cb), self);
1195 account_widget_build_jabber (EmpathyAccountWidget *self,
1196 const char *filename)
1198 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1199 GtkWidget *spinbutton_port;
1200 GtkWidget *checkbutton_ssl;
1201 GtkWidget *label_id, *label_password;
1202 GtkWidget *label_id_create, *label_password_create;
1203 GtkWidget *label_example_gtalk, *label_example_jabber, *label_example_fb;
1204 gboolean is_gtalk, is_facebook;
1205 GtkWidget *expander_advanced;
1206 GtkWidget *entry_id;
1208 is_gtalk = account_widget_is_gtalk (self);
1209 is_facebook = account_widget_is_facebook (self);
1211 empathy_account_settings_set_regex (priv->settings, "account",
1212 ACCOUNT_REGEX_JABBER);
1214 if (priv->simple && !is_gtalk && !is_facebook)
1216 /* Simple widget for XMPP */
1217 self->ui_details->gui = empathy_builder_get_file (filename,
1218 "vbox_jabber_simple", &self->ui_details->widget,
1219 "label_id_simple", &label_id,
1220 "label_id_create", &label_id_create,
1221 "label_password_simple", &label_password,
1222 "label_password_create", &label_password_create,
1225 if (empathy_account_settings_get_boolean (priv->settings, "register"))
1227 gtk_widget_hide (label_id);
1228 gtk_widget_hide (label_password);
1229 gtk_widget_show (label_id_create);
1230 gtk_widget_show (label_password_create);
1233 empathy_account_widget_handle_params (self,
1234 "entry_id_simple", "account",
1235 "entry_password_simple", "password",
1238 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1240 else if (priv->simple && is_gtalk)
1242 /* Simple widget for Google Talk */
1243 self->ui_details->gui = empathy_builder_get_file (filename,
1244 "vbox_gtalk_simple", &self->ui_details->widget,
1247 empathy_account_widget_handle_params (self,
1248 "entry_id_g_simple", "account",
1249 "entry_password_g_simple", "password",
1252 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1254 else if (priv->simple && is_facebook)
1256 /* Simple widget for Facebook */
1257 self->ui_details->gui = empathy_builder_get_file (filename,
1258 "vbox_fb_simple", &self->ui_details->widget,
1259 "entry_id_fb_simple", &entry_id,
1262 empathy_account_widget_handle_params (self,
1263 "entry_password_fb_simple", "password",
1266 setup_facebook_id_widget (self, entry_id);
1268 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1272 /* Full widget for XMPP, Google Talk and Facebook*/
1273 self->ui_details->gui = empathy_builder_get_file (filename,
1274 "table_common_settings", &priv->table_common_settings,
1275 "vbox_jabber_settings", &self->ui_details->widget,
1276 "spinbutton_port", &spinbutton_port,
1277 "checkbutton_ssl", &checkbutton_ssl,
1278 "label_username_example", &label_example_jabber,
1279 "label_username_g_example", &label_example_gtalk,
1280 "label_username_f_example", &label_example_fb,
1281 "expander_advanced", &expander_advanced,
1282 "entry_id", &entry_id,
1283 "label_id", &label_id,
1286 empathy_account_widget_handle_params (self,
1287 "entry_password", "password",
1288 "entry_resource", "resource",
1289 "entry_server", "server",
1290 "spinbutton_port", "port",
1291 "spinbutton_priority", "priority",
1292 "checkbutton_ssl", "old-ssl",
1293 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1294 "checkbutton_encryption", "require-encryption",
1299 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1301 /* Facebook special case the entry ID widget to hide the
1302 * "@chat.facebook.com" part */
1303 setup_facebook_id_widget (self, entry_id);
1307 empathy_account_widget_setup_widget (self, entry_id, "account");
1310 self->ui_details->default_focus = g_strdup ("entry_id");
1311 priv->spinbutton_port = spinbutton_port;
1313 g_signal_connect (checkbutton_ssl, "toggled",
1314 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1319 gtk_widget_hide (label_example_jabber);
1320 gtk_widget_show (label_example_gtalk);
1322 else if (is_facebook)
1324 gtk_widget_hide (label_example_jabber);
1325 gtk_widget_show (label_example_fb);
1326 gtk_widget_hide (expander_advanced);
1332 account_widget_build_icq (EmpathyAccountWidget *self,
1333 const char *filename)
1335 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1336 GtkWidget *spinbutton_port;
1338 empathy_account_settings_set_regex (priv->settings, "account",
1343 self->ui_details->gui = empathy_builder_get_file (filename,
1344 "vbox_icq_simple", &self->ui_details->widget,
1347 empathy_account_widget_handle_params (self,
1348 "entry_uin_simple", "account",
1349 "entry_password_simple", "password",
1352 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1356 self->ui_details->gui = empathy_builder_get_file (filename,
1357 "table_common_settings", &priv->table_common_settings,
1358 "vbox_icq_settings", &self->ui_details->widget,
1359 "spinbutton_port", &spinbutton_port,
1362 empathy_account_widget_handle_params (self,
1363 "entry_uin", "account",
1364 "entry_password", "password",
1365 "entry_server", "server",
1366 "spinbutton_port", "port",
1367 "entry_charset", "charset",
1370 self->ui_details->default_focus = g_strdup ("entry_uin");
1375 account_widget_build_aim (EmpathyAccountWidget *self,
1376 const char *filename)
1378 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1379 GtkWidget *spinbutton_port;
1383 self->ui_details->gui = empathy_builder_get_file (filename,
1384 "vbox_aim_simple", &self->ui_details->widget,
1387 empathy_account_widget_handle_params (self,
1388 "entry_screenname_simple", "account",
1389 "entry_password_simple", "password",
1392 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1396 self->ui_details->gui = empathy_builder_get_file (filename,
1397 "table_common_settings", &priv->table_common_settings,
1398 "vbox_aim_settings", &self->ui_details->widget,
1399 "spinbutton_port", &spinbutton_port,
1402 empathy_account_widget_handle_params (self,
1403 "entry_screenname", "account",
1404 "entry_password", "password",
1405 "entry_server", "server",
1406 "spinbutton_port", "port",
1409 self->ui_details->default_focus = g_strdup ("entry_screenname");
1414 account_widget_build_yahoo (EmpathyAccountWidget *self,
1415 const char *filename)
1417 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1419 empathy_account_settings_set_regex (priv->settings, "account",
1420 ACCOUNT_REGEX_YAHOO);
1424 self->ui_details->gui = empathy_builder_get_file (filename,
1425 "vbox_yahoo_simple", &self->ui_details->widget,
1428 empathy_account_widget_handle_params (self,
1429 "entry_id_simple", "account",
1430 "entry_password_simple", "password",
1433 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1437 self->ui_details->gui = empathy_builder_get_file (filename,
1438 "table_common_settings", &priv->table_common_settings,
1439 "vbox_yahoo_settings", &self->ui_details->widget,
1442 empathy_account_widget_handle_params (self,
1443 "entry_id", "account",
1444 "entry_password", "password",
1445 "entry_server", "server",
1446 "entry_locale", "room-list-locale",
1447 "entry_charset", "charset",
1448 "spinbutton_port", "port",
1449 "checkbutton_ignore_invites", "ignore-invites",
1452 self->ui_details->default_focus = g_strdup ("entry_id");
1457 account_widget_build_groupwise (EmpathyAccountWidget *self,
1458 const char *filename)
1460 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1464 self->ui_details->gui = empathy_builder_get_file (filename,
1465 "vbox_groupwise_simple", &self->ui_details->widget,
1468 empathy_account_widget_handle_params (self,
1469 "entry_id_simple", "account",
1470 "entry_password_simple", "password",
1473 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1477 self->ui_details->gui = empathy_builder_get_file (filename,
1478 "table_common_groupwise_settings", &priv->table_common_settings,
1479 "vbox_groupwise_settings", &self->ui_details->widget,
1482 empathy_account_widget_handle_params (self,
1483 "entry_id", "account",
1484 "entry_password", "password",
1485 "entry_server", "server",
1486 "spinbutton_port", "port",
1489 self->ui_details->default_focus = g_strdup ("entry_id");
1494 account_widget_destroy_cb (GtkWidget *widget,
1495 EmpathyAccountWidget *self)
1497 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1498 /* set the destroyed flag - workaround */
1499 priv->destroyed = TRUE;
1501 g_object_unref (self);
1505 empathy_account_widget_enabled_cb (TpAccount *account,
1509 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1510 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1511 gboolean enabled = tp_account_is_enabled (account);
1513 if (priv->enabled_checkbox != NULL)
1516 mx_gtk_light_switch_set_active (
1517 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1520 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1522 #endif /* HAVE_MEEGO */
1528 account_widget_switch_flipped_cb (MxGtkLightSwitch *sw,
1532 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1534 #endif /* HAVE_MEEGO */
1536 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1541 state = gtk_toggle_button_get_active (toggle_button);
1542 #endif /* HAVE_MEEGO */
1544 account = empathy_account_settings_get_account (priv->settings);
1546 /* Enable the account according to the value of the "Enabled" checkbox */
1547 /* workaround to keep widget alive during async call */
1548 g_object_ref (user_data);
1549 tp_account_set_enabled_async (account, state,
1550 account_widget_account_enabled_cb, user_data);
1554 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1555 gboolean others_exist)
1557 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1559 priv->other_accounts_exist = others_exist;
1561 if (priv->creating_account)
1562 account_widget_handle_control_buttons_sensitivity (self);
1566 do_set_property (GObject *object,
1568 const GValue *value,
1571 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1576 priv->settings = g_value_dup_object (value);
1579 priv->simple = g_value_get_boolean (value);
1581 case PROP_CREATING_ACCOUNT:
1582 priv->creating_account = g_value_get_boolean (value);
1584 case PROP_OTHER_ACCOUNTS_EXIST:
1585 empathy_account_widget_set_other_accounts_exist (
1586 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1589 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1594 do_get_property (GObject *object,
1599 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1604 g_value_set_string (value,
1605 empathy_account_settings_get_protocol (priv->settings));
1608 g_value_set_object (value, priv->settings);
1611 g_value_set_boolean (value, priv->simple);
1613 case PROP_CREATING_ACCOUNT:
1614 g_value_set_boolean (value, priv->creating_account);
1616 case PROP_OTHER_ACCOUNTS_EXIST:
1617 g_value_set_boolean (value, priv->other_accounts_exist);
1620 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1625 set_apply_button (EmpathyAccountWidget *self)
1627 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1630 /* We can't use the stock button as its accelerator ('A') clashes with the
1632 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1634 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("A_pply"));
1635 gtk_button_set_use_underline (GTK_BUTTON (priv->apply_button), TRUE);
1637 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1638 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1642 presence_changed_cb (TpAccountManager *manager,
1643 TpConnectionPresenceType state,
1644 const gchar *status,
1645 const gchar *message,
1646 EmpathyAccountWidget *self)
1648 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1650 if (priv->destroyed)
1653 if (priv->apply_button == NULL)
1654 /* This button doesn't exist in 'simple' mode */
1657 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1658 priv->creating_account)
1660 /* We are online and creating a new account, display a Login button */
1663 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1664 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1666 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1667 GTK_ICON_SIZE_BUTTON);
1668 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1672 /* We are offline or modifying an existing account, display
1674 set_apply_button (self);
1679 account_manager_ready_cb (GObject *source_object,
1680 GAsyncResult *result,
1683 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1684 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1685 GError *error = NULL;
1686 TpConnectionPresenceType state;
1688 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1690 DEBUG ("Failed to prepare account manager: %s", error->message);
1691 g_error_free (error);
1695 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1698 /* simulate a presence change so the apply button will be changed
1700 presence_changed_cb (account_manager, state, NULL, NULL, self);
1703 g_object_unref (self);
1706 #define WIDGET(cm, proto) \
1707 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1708 account_widget_build_##proto }
1711 add_enable_checkbox (EmpathyAccountWidget *self,
1714 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1718 GtkWidget *vbox = self->ui_details->widget;
1719 #endif /* HAVE_MEEGO */
1720 guint nb_rows, nb_columns;
1721 gboolean is_enabled;
1723 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1724 if (priv->creating_account || priv->table_common_settings == NULL)
1727 is_enabled = tp_account_is_enabled (account);
1730 w = gtk_label_new (_("Account:"));
1731 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1733 priv->enabled_checkbox = mx_gtk_light_switch_new ();
1735 mx_gtk_light_switch_set_active (
1736 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1738 gtk_widget_show (w);
1740 priv->enabled_checkbox =
1741 gtk_check_button_new_with_mnemonic (_("_Enabled"));
1743 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1745 #endif /* HAVE_MEEGO */
1747 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1748 "n-columns", &nb_columns, NULL);
1750 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1754 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1756 0, 1, nb_rows - 1, nb_rows,
1758 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1759 priv->enabled_checkbox,
1760 1, nb_columns, nb_rows - 1, nb_rows,
1761 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1763 gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
1764 gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
1765 #endif /* HAVE_MEEGO */
1767 gtk_widget_show (priv->enabled_checkbox);
1770 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1771 G_CALLBACK (account_widget_switch_flipped_cb), self);
1773 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
1774 G_CALLBACK (account_widget_enabled_toggled_cb), self);
1775 #endif /* HAVE_MEEGO */
1779 /* Meego doesn't support registration */
1781 add_register_buttons (EmpathyAccountWidget *self,
1784 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1785 const TpConnectionManagerProtocol *protocol;
1786 GtkWidget *radiobutton_register;
1787 GtkWidget *vbox = self->ui_details->widget;
1789 if (!priv->creating_account)
1792 protocol = empathy_account_settings_get_tp_protocol (priv->settings);
1793 if (protocol == NULL)
1796 if (!tp_connection_manager_protocol_can_register (protocol))
1799 if (account_widget_is_gtalk (self) || account_widget_is_facebook (self))
1805 priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1806 _("This account already exists on the server"));
1807 radiobutton_register = gtk_radio_button_new_with_label (
1808 gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
1809 _("Create a new account on the server"));
1811 gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
1812 gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
1813 gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
1814 gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
1815 gtk_widget_show (priv->radiobutton_reuse);
1816 gtk_widget_show (radiobutton_register);
1818 #endif /* HAVE_MEEGO */
1821 do_constructed (GObject *obj)
1823 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1824 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1826 const gchar *protocol, *cm_name;
1827 const gchar *display_name, *default_display_name;
1830 const gchar *cm_name;
1831 const gchar *protocol;
1833 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1835 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1836 account_widget_build_salut },
1837 WIDGET (gabble, jabber),
1838 WIDGET (butterfly, msn),
1841 WIDGET (haze, yahoo),
1842 WIDGET (haze, groupwise),
1844 WIDGET (sofiasip, sip),
1847 cm_name = empathy_account_settings_get_cm (priv->settings);
1848 protocol = empathy_account_settings_get_protocol (priv->settings);
1850 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1852 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1853 !tp_strdiff (widgets[i].protocol, protocol))
1857 filename = empathy_file_lookup (widgets[i].file,
1859 widgets[i].func (self, filename);
1866 if (i == G_N_ELEMENTS (widgets))
1868 gchar *filename = empathy_file_lookup (
1869 "empathy-account-widget-generic.ui", "libempathy-gtk");
1870 account_widget_build_generic (self, filename);
1874 /* handle default focus */
1875 if (self->ui_details->default_focus != NULL)
1877 GObject *default_focus_entry;
1879 default_focus_entry = gtk_builder_get_object
1880 (self->ui_details->gui, self->ui_details->default_focus);
1881 g_signal_connect (default_focus_entry, "realize",
1882 G_CALLBACK (gtk_widget_grab_focus),
1886 /* dup and init the account-manager */
1887 priv->account_manager = tp_account_manager_dup ();
1889 g_object_ref (self);
1890 tp_account_manager_prepare_async (priv->account_manager, NULL,
1891 account_manager_ready_cb, self);
1893 /* handle apply and cancel button */
1896 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1899 /* We can't use the stock button as its accelerator ('C') clashes with
1900 * the Close button. */
1901 priv->cancel_button = gtk_button_new ();
1902 gtk_button_set_label (GTK_BUTTON (priv->cancel_button), _("Ca_ncel"));
1903 gtk_button_set_use_underline (GTK_BUTTON (priv->cancel_button), TRUE);
1905 image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
1906 gtk_button_set_image (GTK_BUTTON (priv->cancel_button), image);
1908 priv->apply_button = gtk_button_new ();
1909 set_apply_button (self);
1911 /* We'll change this button to a "Log in" one if we are creating a new
1912 * account and are connected. */
1913 tp_g_signal_connect_object (priv->account_manager,
1914 "most-available-presence-changed",
1915 G_CALLBACK (presence_changed_cb), obj, 0);
1917 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1919 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1922 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1925 g_signal_connect (priv->cancel_button, "clicked",
1926 G_CALLBACK (account_widget_cancel_clicked_cb),
1928 g_signal_connect (priv->apply_button, "clicked",
1929 G_CALLBACK (account_widget_apply_clicked_cb),
1931 gtk_widget_show_all (hbox);
1933 if (priv->creating_account)
1934 /* When creating an account, the user might have nothing to enter.
1935 * That means that no control interaction might occur,
1936 * so we update the control button sensitivity manually.
1938 account_widget_handle_control_buttons_sensitivity (self);
1940 account_widget_set_control_buttons_sensitivity (self, FALSE);
1943 account = empathy_account_settings_get_account (priv->settings);
1945 if (account != NULL)
1947 g_signal_connect (account, "notify::enabled",
1948 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1952 add_register_buttons (self, account);
1953 #endif /* HAVE_MEEGO */
1954 add_enable_checkbox (self, account);
1956 /* hook up to widget destruction to unref ourselves */
1957 g_signal_connect (self->ui_details->widget, "destroy",
1958 G_CALLBACK (account_widget_destroy_cb), self);
1960 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1961 self->ui_details->widget);
1962 self->ui_details->gui = NULL;
1964 display_name = empathy_account_settings_get_display_name (priv->settings);
1965 default_display_name = empathy_account_widget_get_default_display_name (self);
1967 if (tp_strdiff (display_name, default_display_name) &&
1968 !priv->creating_account)
1970 /* The display name of the account is not the one that we'd assign by
1971 * default; assume that the user changed it manually */
1972 g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
1977 do_dispose (GObject *obj)
1979 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1980 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1982 if (priv->dispose_run)
1985 priv->dispose_run = TRUE;
1987 if (priv->settings != NULL)
1990 account = empathy_account_settings_get_account (priv->settings);
1992 if (account != NULL)
1994 g_signal_handlers_disconnect_by_func (account,
1995 empathy_account_widget_enabled_cb, self);
1998 g_object_unref (priv->settings);
1999 priv->settings = NULL;
2002 if (priv->account_manager != NULL)
2004 g_object_unref (priv->account_manager);
2005 priv->account_manager = NULL;
2008 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
2009 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
2013 do_finalize (GObject *obj)
2015 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2017 g_free (self->ui_details->default_focus);
2018 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
2020 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
2021 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
2025 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
2027 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2028 GParamSpec *param_spec;
2030 oclass->get_property = do_get_property;
2031 oclass->set_property = do_set_property;
2032 oclass->constructed = do_constructed;
2033 oclass->dispose = do_dispose;
2034 oclass->finalize = do_finalize;
2036 param_spec = g_param_spec_string ("protocol",
2037 "protocol", "The protocol of the account",
2039 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2040 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2042 param_spec = g_param_spec_object ("settings",
2043 "settings", "The settings of the account",
2044 EMPATHY_TYPE_ACCOUNT_SETTINGS,
2045 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2046 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2048 param_spec = g_param_spec_boolean ("simple",
2049 "simple", "Whether the account widget is a simple or an advanced one",
2051 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2052 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2054 param_spec = g_param_spec_boolean ("creating-account",
2056 "TRUE if we're creating an account, FALSE if we're modifying it",
2058 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2059 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2061 param_spec = g_param_spec_boolean ("other-accounts-exist",
2062 "other-accounts-exist",
2063 "TRUE if there are any other accounts (even if this isn't yet saved)",
2065 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2066 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2069 signals[HANDLE_APPLY] =
2070 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2071 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2072 g_cclosure_marshal_VOID__BOOLEAN,
2076 /* This signal is emitted when an account has been created and enabled. */
2077 signals[ACCOUNT_CREATED] =
2078 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2079 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2080 g_cclosure_marshal_VOID__OBJECT,
2084 signals[CANCELLED] =
2085 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2086 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2087 g_cclosure_marshal_VOID__VOID,
2091 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
2095 empathy_account_widget_init (EmpathyAccountWidget *self)
2097 EmpathyAccountWidgetPriv *priv =
2098 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
2099 EmpathyAccountWidgetPriv);
2102 priv->dispose_run = FALSE;
2104 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
2107 /* public methods */
2110 empathy_account_widget_discard_pending_changes
2111 (EmpathyAccountWidget *widget)
2113 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2115 empathy_account_settings_discard_changes (priv->settings);
2116 priv->contains_pending_changes = FALSE;
2120 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
2122 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2124 return priv->contains_pending_changes;
2128 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
2129 const gchar *first_widget,
2134 va_start (args, first_widget);
2135 account_widget_handle_params_valist (self, first_widget, args);
2140 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
2142 return widget->ui_details->widget;
2145 EmpathyAccountWidget *
2146 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
2149 EmpathyAccountWidget *self;
2151 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
2154 (EMPATHY_TYPE_ACCOUNT_WIDGET,
2155 "settings", settings, "simple", simple,
2157 empathy_account_settings_get_account (settings) == NULL,
2164 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
2166 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2167 const gchar *login_id;
2168 const gchar *protocol, *p;
2169 gchar *default_display_name;
2171 login_id = empathy_account_settings_get_string (priv->settings, "account");
2172 protocol = empathy_account_settings_get_protocol (priv->settings);
2174 if (login_id != NULL)
2176 /* TODO: this should be done in empathy-account-widget-irc */
2177 if (!tp_strdiff (protocol, "irc"))
2179 EmpathyIrcNetwork *network;
2181 network = empathy_irc_network_chooser_get_network (
2182 priv->irc_network_chooser);
2183 g_assert (network != NULL);
2185 /* To translators: The first parameter is the login id and the
2186 * second one is the network. The resulting string will be something
2187 * like: "MyUserName on freenode".
2188 * You should reverse the order of these arguments if the
2189 * server should come before the login id in your locale.*/
2190 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2191 login_id, empathy_irc_network_get_name (network));
2193 else if (account_widget_is_facebook (self))
2197 tmp = remove_facebook_suffix (login_id);
2198 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2203 default_display_name = g_strdup (login_id);
2206 return default_display_name;
2209 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2212 if (protocol != NULL)
2214 /* To translators: The parameter is the protocol name. The resulting
2215 * string will be something like: "Jabber Account" */
2216 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2220 default_display_name = g_strdup (_("New account"));
2223 return default_display_name;
2226 /* Used by subclass to indicate that widget contains pending changes */
2228 empathy_account_widget_changed (EmpathyAccountWidget *self)
2230 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2232 account_widget_handle_control_buttons_sensitivity (self);
2233 priv->contains_pending_changes = TRUE;
2237 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2238 const gchar *account)
2240 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2242 if (priv->param_account_widget == NULL)
2245 gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
2249 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2250 const gchar *account)
2252 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2254 if (priv->param_password_widget == NULL)
2257 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);