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>
24 * Danielle Madeley <danielle.madeley@collabora.co.uk>
32 #include <glib/gi18n-lib.h>
34 #include <gio/gdesktopappinfo.h>
36 #include <libempathy/empathy-utils.h>
38 #include <telepathy-glib/telepathy-glib.h>
39 #include <dbus/dbus-protocol.h>
41 #include "empathy-account-widget.h"
42 #include "empathy-account-widget-private.h"
43 #include "empathy-account-widget-sip.h"
44 #include "empathy-account-widget-irc.h"
45 #include "empathy-ui-utils.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
48 #include <libempathy/empathy-debug.h>
50 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, GTK_TYPE_BOX)
62 const gchar *label_username_example;
63 gboolean show_advanced;
66 static ServiceInfo services_infos[N_SERVICES] = {
67 { "label_username_example", TRUE },
68 { "label_username_g_example", FALSE },
69 { "label_username_f_example", FALSE },
72 struct _EmpathyAccountWidgetPriv {
73 EmpathyAccountSettings *settings;
75 GtkWidget *grid_common_settings;
76 GtkWidget *apply_button;
77 GtkWidget *cancel_button;
78 GtkWidget *entry_password;
79 GtkWidget *spinbutton_port;
80 GtkWidget *radiobutton_reuse;
81 GtkWidget *hbox_buttons;
85 gboolean contains_pending_changes;
87 /* An EmpathyAccountWidget can be used to either create an account or
88 * modify it. When we are creating an account, this member is set to TRUE */
89 gboolean creating_account;
91 /* whether there are any other real accounts. Necessary so we know whether
92 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
93 * button should be sensitive) */
94 gboolean other_accounts_exist;
96 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
97 * embedded in this account widget can't be used any more
98 * workaround because some async callbacks can be called after the
99 * widget has been destroyed */
102 TpAccountManager *account_manager;
104 GtkWidget *param_account_widget;
105 GtkWidget *param_password_widget;
107 gboolean automatic_change;
108 GtkWidget *remember_password_widget;
110 /* Used only for IRC accounts */
111 EmpathyIrcNetworkChooser *irc_network_chooser;
113 /* Used for 'special' XMPP account having a service associated ensuring that
114 * JIDs have a specific suffix; such as Facebook for example */
122 PROP_CREATING_ACCOUNT,
123 PROP_OTHER_ACCOUNTS_EXIST,
138 static guint signals[LAST_SIGNAL] = { 0 };
140 #define CHANGED_TIMEOUT 300
143 #define DIGITS "(["DIGIT"]+)"
144 #define ALPHA "a-zA-Z"
145 #define ALPHAS "(["ALPHA"]+)"
146 #define ALPHADIGIT ALPHA DIGIT
147 #define ALPHADIGITS "(["ALPHADIGIT"]+)"
148 #define ALPHADIGITDASH ALPHA DIGIT "-"
149 #define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
151 #define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
152 #define TOPLABEL "("ALPHAS \
153 "| (["ALPHA"]"ALPHADIGITDASHS "["ALPHADIGIT"]))"
154 #define DOMAINLABEL "("ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
156 #define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
157 /* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
158 #define HOST "("HOSTNAME "|" HOSTNUMBER")"
159 /* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
160 #define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
162 /* UIN is digital according to the unofficial specification:
163 * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
164 * 5 digits minimum according to http://en.wikipedia.org/wiki/ICQ#UIN
165 * According to an user, we can also provide an email address instead of the
167 #define ICQ_USER_NAME "((["DIGIT"]{5,})|"EMAIL_LOCALPART"@"HOST")"
169 /* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
170 #define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
171 #define IRC_NICK_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
173 /* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
174 * We just exclude invalid characters to avoid ucschars and other redundant
176 #define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
177 /* ID is an email according to the unofficial specification:
178 * http://www.hypothetic.org/docs/msn/general/names.php */
179 #define MSN_USER_NAME EMAIL_LOCALPART
180 /* Based on the official help:
181 * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html
182 * Looks like an email address can be used as well (bgo #655959)
184 #define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})|("EMAIL_LOCALPART"@"HOST")"
186 #define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
187 #define ACCOUNT_REGEX_IRC "^"IRC_NICK_NAME"$"
188 #define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@[^@/]+"
189 #define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
190 #define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
193 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
196 /* we hit this case because of the 'other-accounts-exist' property handler
197 * being called during init (before constructed()) */
198 if (self->priv->apply_button == NULL || self->priv->cancel_button == NULL)
201 gtk_widget_set_sensitive (self->priv->apply_button, sensitive);
205 /* We can't grab default if the widget hasn't be packed in a
209 window = gtk_widget_get_toplevel (self->priv->apply_button);
210 if (window != NULL &&
211 gtk_widget_is_toplevel (window))
213 gtk_widget_set_can_default (self->priv->apply_button, TRUE);
214 gtk_widget_grab_default (self->priv->apply_button);
220 account_widget_set_entry_highlighting (GtkEntry *entry,
223 g_return_if_fail (GTK_IS_ENTRY (entry));
227 GtkStyleContext *style;
230 style = gtk_widget_get_style_context (GTK_WIDGET (entry));
231 gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
234 /* Here we take the current theme colour and add it to
235 * the colour for white and average the two. This
236 * gives a colour which is inline with the theme but
239 empathy_make_color_whiter (&color);
241 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, &color);
245 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, NULL);
250 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
254 is_valid = empathy_account_settings_is_valid (self->priv->settings);
256 account_widget_set_control_buttons_sensitivity (self, is_valid);
258 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
262 account_widget_entry_changed_common (EmpathyAccountWidget *self,
263 GtkEntry *entry, gboolean focus)
266 const gchar *param_name;
267 gboolean prev_status;
268 gboolean curr_status;
270 str = gtk_entry_get_text (entry);
271 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
272 prev_status = empathy_account_settings_parameter_is_valid (
273 self->priv->settings, param_name);
275 if (EMP_STR_EMPTY (str))
277 empathy_account_settings_unset (self->priv->settings, param_name);
283 value = empathy_account_settings_dup_string (self->priv->settings,
286 DEBUG ("Unset %s and restore to %s", param_name, value);
287 gtk_entry_set_text (entry, value ? value : "");
293 DEBUG ("Setting %s to %s", param_name,
294 tp_strdiff (param_name, "password") ? str : "***");
295 empathy_account_settings_set (self->priv->settings, param_name,
296 g_variant_new_string (str));
299 curr_status = empathy_account_settings_parameter_is_valid (
300 self->priv->settings, param_name);
302 if (curr_status != prev_status)
303 account_widget_set_entry_highlighting (entry, !curr_status);
307 account_widget_entry_changed_cb (GtkEditable *entry,
308 EmpathyAccountWidget *self)
310 if (self->priv->automatic_change)
313 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
314 empathy_account_widget_changed (self);
318 account_widget_entry_map_cb (GtkEntry *entry,
319 EmpathyAccountWidget *self)
321 const gchar *param_name;
324 /* need to initialize input highlighting */
325 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
326 is_valid = empathy_account_settings_parameter_is_valid (self->priv->settings,
328 account_widget_set_entry_highlighting (entry, !is_valid);
332 account_widget_int_changed_cb (GtkWidget *widget,
333 EmpathyAccountWidget *self)
335 const gchar *param_name;
337 const gchar *signature;
339 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
340 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
342 signature = empathy_account_settings_get_dbus_signature (self->priv->settings,
344 g_return_if_fail (signature != NULL);
346 DEBUG ("Setting %s to %d", param_name, value);
348 switch ((int)*signature)
350 case DBUS_TYPE_INT16:
351 case DBUS_TYPE_INT32:
352 empathy_account_settings_set (self->priv->settings, param_name,
353 g_variant_new_int32 (value));
355 case DBUS_TYPE_INT64:
356 empathy_account_settings_set (self->priv->settings, param_name,
357 g_variant_new_int64 (value));
359 case DBUS_TYPE_UINT16:
360 case DBUS_TYPE_UINT32:
361 empathy_account_settings_set (self->priv->settings, param_name,
362 g_variant_new_uint32 (value));
364 case DBUS_TYPE_UINT64:
365 empathy_account_settings_set (self->priv->settings, param_name,
366 g_variant_new_uint64 (value));
369 g_return_if_reached ();
372 empathy_account_widget_changed (self);
376 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
377 EmpathyAccountWidget *self)
380 gboolean default_value;
381 const gchar *param_name;
383 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
384 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
386 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
387 * always unset the param and set the value if different from the
389 empathy_account_settings_unset (self->priv->settings, param_name);
390 default_value = empathy_account_settings_get_boolean (self->priv->settings,
393 if (default_value == value)
395 DEBUG ("Unset %s and restore to %d", param_name, default_value);
399 DEBUG ("Setting %s to %d", param_name, value);
400 empathy_account_settings_set (self->priv->settings, param_name,
401 g_variant_new_boolean (value));
404 empathy_account_widget_changed (self);
408 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
409 EmpathyAccountWidget *self)
414 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
415 port = empathy_account_settings_get_uint32 (self->priv->settings, "port");
419 if (port == 5222 || port == 0)
424 if (port == 5223 || port == 0)
428 gtk_spin_button_set_value (GTK_SPIN_BUTTON (self->priv->spinbutton_port),
431 self->priv->contains_pending_changes = TRUE;
435 account_widget_combobox_changed_cb (GtkWidget *widget,
436 EmpathyAccountWidget *self)
442 const gchar *default_value = NULL;
443 const gchar *param_name;
445 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
448 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
449 /* the param value is stored in the first column */
450 gtk_tree_model_get (model, &iter, 0, &value, -1);
452 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
454 v = empathy_account_settings_dup_default (self->priv->settings, param_name);
455 if (v != NULL && g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
456 default_value = g_variant_get_string (v, NULL);
458 if (!tp_strdiff (value, default_value))
460 DEBUG ("Unset %s and restore to %s", param_name, default_value);
461 empathy_account_settings_unset (self->priv->settings, param_name);
465 DEBUG ("Setting %s to %s", param_name, value);
466 empathy_account_settings_set (self->priv->settings, param_name,
467 g_variant_new_string (value));
470 empathy_account_widget_changed (self);
472 tp_clear_pointer (&v, g_variant_unref);
476 clear_icon_released_cb (GtkEntry *entry,
477 GtkEntryIconPosition icon_pos,
479 EmpathyAccountWidget *self)
481 const gchar *param_name;
483 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
485 DEBUG ("Unset %s", param_name);
486 empathy_account_settings_unset (self->priv->settings, param_name);
487 gtk_entry_set_text (entry, "");
489 empathy_account_widget_changed (self);
493 password_entry_changed_cb (GtkEditable *entry,
494 EmpathyAccountWidget *self)
498 str = gtk_entry_get_text (GTK_ENTRY (entry));
500 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
501 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
505 password_entry_activated_cb (GtkEntry *entry,
506 EmpathyAccountWidget *self)
508 if (gtk_widget_get_sensitive (self->priv->apply_button))
509 empathy_account_widget_apply_and_log_in (self);
513 account_entry_activated_cb (GtkEntry *entry,
514 EmpathyAccountWidget *self)
516 if (gtk_widget_get_sensitive (self->priv->apply_button))
517 empathy_account_widget_apply_and_log_in (self);
521 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
523 const gchar *param_name)
525 g_object_set_data_full (G_OBJECT (widget), "param_name",
526 g_strdup (param_name), g_free);
528 if (GTK_IS_SPIN_BUTTON (widget))
531 const gchar *signature;
533 signature = empathy_account_settings_get_dbus_signature (
534 self->priv->settings, param_name);
535 g_return_if_fail (signature != NULL);
537 switch ((int)*signature)
539 case DBUS_TYPE_INT16:
540 case DBUS_TYPE_INT32:
541 value = empathy_account_settings_get_int32 (self->priv->settings,
544 case DBUS_TYPE_INT64:
545 value = empathy_account_settings_get_int64 (self->priv->settings,
548 case DBUS_TYPE_UINT16:
549 case DBUS_TYPE_UINT32:
550 value = empathy_account_settings_get_uint32 (self->priv->settings,
553 case DBUS_TYPE_UINT64:
554 value = empathy_account_settings_get_uint64 (self->priv->settings,
558 g_return_if_reached ();
561 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
563 g_signal_connect (widget, "value-changed",
564 G_CALLBACK (account_widget_int_changed_cb),
567 else if (GTK_IS_ENTRY (widget))
571 str = empathy_account_settings_dup_string (self->priv->settings,
573 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
575 if (!tp_strdiff (param_name, "account"))
576 self->priv->param_account_widget = widget;
577 else if (!tp_strdiff (param_name, "password"))
578 self->priv->param_password_widget = widget;
580 if (strstr (param_name, "password"))
582 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
584 /* Add 'clear' icon */
585 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
586 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
588 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
589 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
591 g_signal_connect (widget, "icon-release",
592 G_CALLBACK (clear_icon_released_cb), self);
593 g_signal_connect (widget, "changed",
594 G_CALLBACK (password_entry_changed_cb), self);
595 g_signal_connect (widget, "activate",
596 G_CALLBACK (password_entry_activated_cb), self);
598 else if (strstr (param_name, "account"))
599 g_signal_connect (widget, "activate",
600 G_CALLBACK (account_entry_activated_cb), self);
602 g_signal_connect (widget, "changed",
603 G_CALLBACK (account_widget_entry_changed_cb), self);
604 g_signal_connect (widget, "map",
605 G_CALLBACK (account_widget_entry_map_cb), self);
609 else if (GTK_IS_TOGGLE_BUTTON (widget))
611 gboolean value = FALSE;
613 value = empathy_account_settings_get_boolean (self->priv->settings,
615 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
617 g_signal_connect (widget, "toggled",
618 G_CALLBACK (account_widget_checkbutton_toggled_cb),
621 else if (GTK_IS_COMBO_BOX (widget))
623 /* The combo box's model has to contain the param value in its first
624 * column (as a string) */
630 str = empathy_account_settings_dup_string (self->priv->settings,
632 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
634 valid = gtk_tree_model_get_iter_first (model, &iter);
639 gtk_tree_model_get (model, &iter, 0, &name, -1);
640 if (!tp_strdiff (name, str))
642 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
647 valid = gtk_tree_model_iter_next (model, &iter);
655 g_signal_connect (widget, "changed",
656 G_CALLBACK (account_widget_combobox_changed_cb),
661 DEBUG ("Unknown type of widget for param %s", param_name);
664 gtk_widget_set_sensitive (widget,
665 empathy_account_settings_param_is_supported (self->priv->settings,
670 build_translated_params (void)
674 hash = g_hash_table_new (g_str_hash, g_str_equal);
675 g_hash_table_insert (hash, "account", _("Account"));
676 g_hash_table_insert (hash, "password", _("Password"));
677 g_hash_table_insert (hash, "server", _("Server"));
678 g_hash_table_insert (hash, "port", _("Port"));
684 account_widget_generic_format_param_name (const gchar *param_name)
688 static GHashTable *translated_params = NULL;
690 g_return_val_if_fail (param_name != NULL, NULL);
692 if (G_UNLIKELY (translated_params == NULL))
693 translated_params = build_translated_params ();
695 /* Translate most common parameters */
696 str = g_hash_table_lookup (translated_params, param_name);
698 return g_strdup (str);
700 str = g_strdup (param_name);
702 if (str && g_ascii_isalpha (str[0]))
703 str[0] = g_ascii_toupper (str[0]);
705 while ((p = strchr (str, '-')) != NULL)
707 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
710 p[1] = g_ascii_toupper (p[1]);
720 accounts_widget_generic_setup (EmpathyAccountWidget *self,
721 GtkWidget *grid_common_settings,
722 GtkWidget *grid_advanced_settings)
725 guint row_common = 0, row_advanced = 0;
727 params = empathy_account_settings_dup_tp_params (self->priv->settings);
729 for (l = params; l != NULL; l = g_list_next (l))
731 TpConnectionManagerParam *param = l->data;
732 GtkWidget *grid_settings;
734 GtkWidget *widget = NULL;
735 gchar *param_name_formatted;
736 const gchar *dbus_signature;
738 if (tp_connection_manager_param_is_required (param))
740 grid_settings = grid_common_settings;
743 else if (self->priv->simple)
749 grid_settings = grid_advanced_settings;
750 row = row_advanced++;
753 param_name_formatted = account_widget_generic_format_param_name (
754 tp_connection_manager_param_get_name (param));
756 dbus_signature = tp_connection_manager_param_get_dbus_signature (param);
758 if (dbus_signature[0] == 's')
762 str = g_strdup_printf (_("%s"), param_name_formatted);
763 widget = gtk_label_new (str);
764 gtk_misc_set_alignment (GTK_MISC (widget), 1., 0.5);
765 gtk_style_context_add_class (gtk_widget_get_style_context (widget),
766 GTK_STYLE_CLASS_DIM_LABEL);
769 gtk_grid_attach (GTK_GRID (grid_settings),
770 widget, 0, row, 1, 1);
772 gtk_widget_show (widget);
774 widget = gtk_entry_new ();
775 if (strcmp (tp_connection_manager_param_get_name (param),
778 g_signal_connect (widget, "realize",
779 G_CALLBACK (gtk_widget_grab_focus),
783 gtk_grid_attach (GTK_GRID (grid_settings),
784 widget, 1, row, 1, 1);
786 gtk_widget_show (widget);
788 /* int types: ynqiuxt. double type is 'd' */
789 else if (dbus_signature[0] == 'y' ||
790 dbus_signature[0] == 'n' ||
791 dbus_signature[0] == 'q' ||
792 dbus_signature[0] == 'i' ||
793 dbus_signature[0] == 'u' ||
794 dbus_signature[0] == 'x' ||
795 dbus_signature[0] == 't' ||
796 dbus_signature[0] == 'd')
803 switch (dbus_signature[0])
805 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
806 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
807 case 'q': minint = 0; maxint = G_MAXUINT16; break;
808 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
809 case 'u': minint = 0; maxint = G_MAXUINT32; break;
810 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
811 case 't': minint = 0; maxint = G_MAXUINT64; break;
812 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
814 default: g_assert_not_reached ();
817 str = g_strdup_printf (_("%s:"), param_name_formatted);
818 widget = gtk_label_new (str);
819 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
822 gtk_grid_attach (GTK_GRID (grid_settings),
823 widget, 0, row, 1, 1);
824 gtk_widget_show (widget);
826 widget = gtk_spin_button_new_with_range (minint, maxint, step);
827 gtk_grid_attach (GTK_GRID (grid_settings),
828 widget, 1, row, 1, 1);
829 gtk_widget_show (widget);
831 else if (dbus_signature[0] == 'b')
833 widget = gtk_check_button_new_with_label (param_name_formatted);
834 gtk_grid_attach (GTK_GRID (grid_settings),
835 widget, 0, row, 2, 1);
836 gtk_widget_show (widget);
840 DEBUG ("Unknown signature for param %s: %s",
841 param_name_formatted, dbus_signature);
845 empathy_account_widget_setup_widget (self, widget,
846 tp_connection_manager_param_get_name (param));
848 g_free (param_name_formatted);
851 g_list_free_full (params, (GDestroyNotify) tp_connection_manager_param_free);
855 account_widget_handle_params_valist (EmpathyAccountWidget *self,
856 const gchar *first_widget,
862 for (name = first_widget; name; name = va_arg (args, const gchar *))
864 const gchar *param_name;
866 param_name = va_arg (args, const gchar *);
867 object = gtk_builder_get_object (self->ui_details->gui, name);
871 g_warning ("Builder is missing object '%s'.", name);
875 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
881 account_widget_cancel_clicked_cb (GtkWidget *button,
882 EmpathyAccountWidget *self)
884 g_signal_emit (self, signals[CANCELLED], 0);
885 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_CANCEL);
889 account_widget_account_enabled_cb (GObject *source_object,
893 GError *error = NULL;
894 TpAccount *account = TP_ACCOUNT (source_object);
895 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
897 tp_account_set_enabled_finish (account, res, &error);
901 DEBUG ("Could not enable the account: %s", error->message);
902 g_error_free (error);
906 empathy_connect_new_account (account, self->priv->account_manager);
909 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY);
911 /* unref self - part of the workaround */
912 g_object_unref (self);
916 account_widget_applied_cb (GObject *source_object,
920 GError *error = NULL;
922 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
923 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
924 gboolean reconnect_required;
925 gboolean fire_close = TRUE;
927 empathy_account_settings_apply_finish (settings, res, &reconnect_required,
932 DEBUG ("Could not apply changes to account: %s", error->message);
933 g_error_free (error);
937 account = empathy_account_settings_get_account (self->priv->settings);
941 if (self->priv->creating_account)
943 /* By default, when an account is created, we enable it. */
945 /* workaround to keep self alive during async call */
948 tp_account_set_enabled_async (account, TRUE,
949 account_widget_account_enabled_cb, self);
950 g_signal_emit (self, signals[ACCOUNT_CREATED], 0, account);
952 /* Will be fired in account_widget_account_enabled_cb */
957 /* If the account was offline, we always want to try reconnecting,
958 * to give it a chance to connect if the previous params were wrong.
959 * tp_account_reconnect_async() won't do anything if the requested
960 * presence is offline anyway. */
961 if (tp_account_get_connection_status (account, NULL) ==
962 TP_CONNECTION_STATUS_DISCONNECTED)
963 reconnect_required = TRUE;
965 if (reconnect_required && tp_account_is_enabled (account)
966 && tp_account_is_enabled (account))
968 /* After having applied changes to a user account, we
969 * reconnect it if needed. This is done so the new
970 * information entered by the user is validated on the server. */
971 tp_account_reconnect_async (account, NULL, NULL);
976 if (!self->priv->destroyed)
977 account_widget_set_control_buttons_sensitivity (self, FALSE);
979 self->priv->contains_pending_changes = FALSE;
983 /* announce the widget can be closed */
984 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY);
987 /* unref the widget - part of the workaround */
988 g_object_unref (self);
992 empathy_account_widget_apply_and_log_in (EmpathyAccountWidget *self)
994 gboolean display_name_overridden;
996 if (self->priv->radiobutton_reuse != NULL)
998 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
999 self->priv->radiobutton_reuse));
1001 DEBUG ("Set register param: %d", !reuse);
1002 empathy_account_settings_set (self->priv->settings, "register",
1003 g_variant_new_boolean (!reuse));
1006 g_object_get (self->priv->settings,
1007 "display-name-overridden", &display_name_overridden, NULL);
1009 if (self->priv->creating_account || !display_name_overridden)
1011 gchar *display_name;
1013 /* set default display name for new accounts or update if user didn't
1014 * manually override it. */
1015 display_name = empathy_account_widget_get_default_display_name (self);
1017 empathy_account_settings_set_display_name_async (self->priv->settings,
1018 display_name, NULL, NULL);
1020 g_free (display_name);
1023 /* workaround to keep widget alive during async call */
1024 g_object_ref (self);
1025 empathy_account_settings_apply_async (self->priv->settings,
1026 account_widget_applied_cb, self);
1030 account_widget_apply_clicked_cb (GtkWidget *button,
1031 EmpathyAccountWidget *self)
1033 empathy_account_widget_apply_and_log_in (self);
1037 account_widget_setup_generic (EmpathyAccountWidget *self)
1039 GtkWidget *grid_common_settings;
1040 GtkWidget *grid_advanced_settings;
1042 grid_common_settings = GTK_WIDGET (gtk_builder_get_object
1043 (self->ui_details->gui, "grid_common_settings"));
1044 grid_advanced_settings = GTK_WIDGET (gtk_builder_get_object
1045 (self->ui_details->gui, "grid_advanced_settings"));
1047 accounts_widget_generic_setup (self, grid_common_settings,
1048 grid_advanced_settings);
1050 g_object_unref (self->ui_details->gui);
1054 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
1058 EmpathyAccountWidget *self = user_data;
1060 if (empathy_account_settings_is_ready (self->priv->settings))
1061 account_widget_setup_generic (self);
1065 account_widget_build_generic (EmpathyAccountWidget *self,
1066 const char *filename)
1068 GtkWidget *expander_advanced, *box;
1070 self->ui_details->gui = empathy_builder_get_file (filename,
1071 "grid_common_settings", &self->priv->grid_common_settings,
1072 "vbox_generic_settings", &box,
1073 "expander_advanced_settings", &expander_advanced,
1076 if (self->priv->simple)
1077 gtk_widget_hide (expander_advanced);
1079 g_object_ref (self->ui_details->gui);
1081 if (empathy_account_settings_is_ready (self->priv->settings))
1082 account_widget_setup_generic (self);
1084 g_signal_connect (self->priv->settings, "notify::ready",
1085 G_CALLBACK (account_widget_settings_ready_cb), self);
1091 account_widget_build_salut (EmpathyAccountWidget *self,
1092 const char *filename)
1094 GtkWidget *expander_advanced, *box;
1096 self->ui_details->gui = empathy_builder_get_file (filename,
1097 "grid_common_settings", &self->priv->grid_common_settings,
1098 "vbox_salut_settings", &box,
1099 "expander_advanced_settings", &expander_advanced,
1102 empathy_account_widget_handle_params (self,
1103 "entry_published", "published-name",
1104 "entry_nickname", "nickname",
1105 "entry_first_name", "first-name",
1106 "entry_last_name", "last-name",
1107 "entry_email", "email",
1111 if (self->priv->simple)
1112 gtk_widget_hide (expander_advanced);
1114 self->ui_details->default_focus = g_strdup ("entry_first_name");
1120 account_widget_build_irc (EmpathyAccountWidget *self,
1121 const char *filename)
1125 empathy_account_settings_set_regex (self->priv->settings, "account",
1128 if (self->priv->simple)
1130 self->priv->irc_network_chooser = empathy_account_widget_irc_build_simple
1131 (self, filename, &box);
1135 self->priv->irc_network_chooser = empathy_account_widget_irc_build (self,
1136 filename, &self->priv->grid_common_settings, &box);
1143 account_widget_build_sip (EmpathyAccountWidget *self,
1144 const char *filename)
1148 box = empathy_account_widget_sip_build (self, filename,
1149 &self->priv->grid_common_settings);
1151 if (self->priv->simple)
1153 self->priv->remember_password_widget = GTK_WIDGET (
1154 gtk_builder_get_object (self->ui_details->gui,
1155 "remember_password_simple"));
1159 self->priv->remember_password_widget = GTK_WIDGET (
1160 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1167 account_widget_build_msn (EmpathyAccountWidget *self,
1168 const char *filename)
1172 empathy_account_settings_set_regex (self->priv->settings, "account",
1175 if (self->priv->simple)
1177 self->ui_details->gui = empathy_builder_get_file (filename,
1178 "vbox_msn_simple", &box,
1181 empathy_account_widget_handle_params (self,
1182 "entry_id_simple", "account",
1183 "entry_password_simple", "password",
1186 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1188 self->priv->remember_password_widget = GTK_WIDGET (
1189 gtk_builder_get_object (self->ui_details->gui,
1190 "remember_password_simple"));
1194 self->ui_details->gui = empathy_builder_get_file (filename,
1195 "grid_common_msn_settings", &self->priv->grid_common_settings,
1196 "vbox_msn_settings", &box,
1199 empathy_account_widget_handle_params (self,
1200 "entry_id", "account",
1201 "entry_password", "password",
1202 "entry_server", "server",
1203 "spinbutton_port", "port",
1206 self->ui_details->default_focus = g_strdup ("entry_id");
1208 self->priv->remember_password_widget = GTK_WIDGET (
1209 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1216 suffix_id_widget_changed_cb (GtkWidget *entry,
1217 EmpathyAccountWidget *self)
1221 g_assert (self->priv->jid_suffix != NULL);
1223 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1225 account = empathy_account_settings_dup_string (self->priv->settings,
1228 if (!EMP_STR_EMPTY (account) &&
1229 !g_str_has_suffix (account, self->priv->jid_suffix))
1233 tmp = g_strdup_printf ("%s%s", account, self->priv->jid_suffix);
1235 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1237 empathy_account_settings_set (self->priv->settings, "account",
1238 g_variant_new_string (tmp));
1242 empathy_account_widget_changed (self);
1248 remove_jid_suffix (EmpathyAccountWidget *self,
1251 g_assert (self->priv->jid_suffix != NULL);
1253 if (!g_str_has_suffix (str, self->priv->jid_suffix))
1254 return g_strdup (str);
1256 return g_strndup (str, strlen (str) - strlen (self->priv->jid_suffix));
1260 setup_id_widget_with_suffix (EmpathyAccountWidget *self,
1262 const gchar *suffix)
1266 g_object_set_data_full (G_OBJECT (widget), "param_name",
1267 g_strdup ("account"), g_free);
1269 g_assert (self->priv->jid_suffix == NULL);
1270 self->priv->jid_suffix = g_strdup (suffix);
1272 str = empathy_account_settings_dup_string (self->priv->settings, "account");
1277 tmp = remove_jid_suffix (self, str);
1278 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1283 self->priv->param_account_widget = widget;
1285 g_signal_connect (widget, "changed",
1286 G_CALLBACK (suffix_id_widget_changed_cb), self);
1290 account_widget_get_service (EmpathyAccountWidget *self)
1292 const gchar *icon_name, *service;
1294 icon_name = empathy_account_settings_get_icon_name (self->priv->settings);
1295 service = empathy_account_settings_get_service (self->priv->settings);
1297 /* Previous versions of Empathy didn't set the Service property on Facebook
1298 * and gtalk accounts, so we check using the icon name as well. */
1299 if (!tp_strdiff (icon_name, "im-google-talk") ||
1300 !tp_strdiff (service, "google-talk"))
1301 return GTALK_SERVICE;
1303 if (!tp_strdiff (icon_name, "im-facebook") ||
1304 !tp_strdiff (service, "facebook"))
1305 return FACEBOOK_SERVICE;
1311 account_widget_build_jabber (EmpathyAccountWidget *self,
1312 const char *filename)
1314 GtkWidget *spinbutton_port;
1315 GtkWidget *checkbutton_ssl;
1316 GtkWidget *label_id, *label_password;
1317 GtkWidget *label_id_create, *label_password_create;
1318 GtkWidget *label_example_fb;
1319 GtkWidget *label_example;
1320 GtkWidget *expander_advanced;
1321 GtkWidget *entry_id;
1325 service = account_widget_get_service (self);
1327 empathy_account_settings_set_regex (self->priv->settings, "account",
1328 ACCOUNT_REGEX_JABBER);
1330 if (self->priv->simple && service == NO_SERVICE)
1332 /* Simple widget for XMPP */
1333 self->ui_details->gui = empathy_builder_get_file (filename,
1334 "vbox_jabber_simple", &box,
1335 "label_id_simple", &label_id,
1336 "label_id_create", &label_id_create,
1337 "label_password_simple", &label_password,
1338 "label_password_create", &label_password_create,
1341 if (empathy_account_settings_get_boolean (self->priv->settings,
1344 gtk_widget_hide (label_id);
1345 gtk_widget_hide (label_password);
1346 gtk_widget_show (label_id_create);
1347 gtk_widget_show (label_password_create);
1350 empathy_account_widget_handle_params (self,
1351 "entry_id_simple", "account",
1352 "entry_password_simple", "password",
1355 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1357 self->priv->remember_password_widget = GTK_WIDGET (
1358 gtk_builder_get_object (self->ui_details->gui,
1359 "remember_password_simple"));
1361 else if (self->priv->simple && service == GTALK_SERVICE)
1363 /* Simple widget for Google Talk */
1364 self->ui_details->gui = empathy_builder_get_file (filename,
1365 "vbox_gtalk_simple", &box,
1368 empathy_account_widget_handle_params (self,
1369 "entry_id_g_simple", "account",
1370 "entry_password_g_simple", "password",
1373 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1375 self->priv->remember_password_widget = GTK_WIDGET (
1376 gtk_builder_get_object (self->ui_details->gui,
1377 "remember_password_g_simple"));
1379 else if (self->priv->simple && service == FACEBOOK_SERVICE)
1381 /* Simple widget for Facebook */
1382 self->ui_details->gui = empathy_builder_get_file (filename,
1383 "vbox_fb_simple", &box,
1384 "entry_id_fb_simple", &entry_id,
1387 empathy_account_widget_handle_params (self,
1388 "entry_password_fb_simple", "password",
1391 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1393 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1395 self->priv->remember_password_widget = GTK_WIDGET (
1396 gtk_builder_get_object (self->ui_details->gui,
1397 "remember_password_fb_simple"));
1401 ServiceInfo info = services_infos[service];
1403 /* Full widget for XMPP, Google Talk and Facebook*/
1404 self->ui_details->gui = empathy_builder_get_file (filename,
1405 "grid_common_settings", &self->priv->grid_common_settings,
1406 "vbox_jabber_settings", &box,
1407 "spinbutton_port", &spinbutton_port,
1408 "checkbutton_ssl", &checkbutton_ssl,
1409 "label_username_f_example", &label_example_fb,
1410 info.label_username_example, &label_example,
1411 "expander_advanced", &expander_advanced,
1412 "entry_id", &entry_id,
1413 "label_id", &label_id,
1416 empathy_account_widget_handle_params (self,
1417 "entry_password", "password",
1418 "entry_resource", "resource",
1419 "entry_server", "server",
1420 "spinbutton_port", "port",
1421 "spinbutton_priority", "priority",
1422 "checkbutton_ssl", "old-ssl",
1423 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1424 "checkbutton_encryption", "require-encryption",
1427 if (service == FACEBOOK_SERVICE)
1429 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1431 /* Facebook special case the entry ID widget to hide the
1432 * "@chat.facebook.com" part */
1433 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1437 empathy_account_widget_setup_widget (self, entry_id, "account");
1440 self->ui_details->default_focus = g_strdup ("entry_id");
1441 self->priv->spinbutton_port = spinbutton_port;
1443 self->priv->remember_password_widget = GTK_WIDGET (
1444 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1446 g_signal_connect (checkbutton_ssl, "toggled",
1447 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1450 if (service == FACEBOOK_SERVICE)
1452 GtkContainer *parent;
1455 /* Removing the label from list of focusable widgets */
1456 parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
1457 children = gtk_container_get_children (parent);
1458 children = g_list_remove (children, label_example_fb);
1459 gtk_container_set_focus_chain (parent, children);
1460 g_list_free (children);
1463 gtk_widget_show (label_example);
1465 if (!info.show_advanced)
1466 gtk_widget_hide (expander_advanced);
1473 account_widget_build_icq (EmpathyAccountWidget *self,
1474 const char *filename)
1476 GtkWidget *spinbutton_port;
1479 empathy_account_settings_set_regex (self->priv->settings, "account",
1482 if (self->priv->simple)
1484 self->ui_details->gui = empathy_builder_get_file (filename,
1485 "vbox_icq_simple", &box,
1488 empathy_account_widget_handle_params (self,
1489 "entry_uin_simple", "account",
1490 "entry_password_simple", "password",
1493 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1495 self->priv->remember_password_widget = GTK_WIDGET (
1496 gtk_builder_get_object (self->ui_details->gui,
1497 "remember_password_simple"));
1501 self->ui_details->gui = empathy_builder_get_file (filename,
1502 "grid_common_settings", &self->priv->grid_common_settings,
1503 "vbox_icq_settings", &box,
1504 "spinbutton_port", &spinbutton_port,
1507 empathy_account_widget_handle_params (self,
1508 "entry_uin", "account",
1509 "entry_password", "password",
1510 "entry_server", "server",
1511 "spinbutton_port", "port",
1512 "entry_charset", "charset",
1515 self->ui_details->default_focus = g_strdup ("entry_uin");
1517 self->priv->remember_password_widget = GTK_WIDGET (
1518 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1525 account_widget_build_aim (EmpathyAccountWidget *self,
1526 const char *filename)
1528 GtkWidget *spinbutton_port, *box;
1530 if (self->priv->simple)
1532 self->ui_details->gui = empathy_builder_get_file (filename,
1533 "vbox_aim_simple", &box,
1536 empathy_account_widget_handle_params (self,
1537 "entry_screenname_simple", "account",
1538 "entry_password_simple", "password",
1541 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1543 self->priv->remember_password_widget = GTK_WIDGET (
1544 gtk_builder_get_object (self->ui_details->gui,
1545 "remember_password_simple"));
1549 self->ui_details->gui = empathy_builder_get_file (filename,
1550 "grid_common_settings", &self->priv->grid_common_settings,
1551 "vbox_aim_settings", &box,
1552 "spinbutton_port", &spinbutton_port,
1555 empathy_account_widget_handle_params (self,
1556 "entry_screenname", "account",
1557 "entry_password", "password",
1558 "entry_server", "server",
1559 "spinbutton_port", "port",
1562 self->ui_details->default_focus = g_strdup ("entry_screenname");
1564 self->priv->remember_password_widget = GTK_WIDGET (
1565 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1572 account_widget_build_yahoo (EmpathyAccountWidget *self,
1573 const char *filename)
1577 empathy_account_settings_set_regex (self->priv->settings, "account",
1578 ACCOUNT_REGEX_YAHOO);
1580 if (self->priv->simple)
1582 self->ui_details->gui = empathy_builder_get_file (filename,
1583 "vbox_yahoo_simple", &box,
1586 empathy_account_widget_handle_params (self,
1587 "entry_id_simple", "account",
1588 "entry_password_simple", "password",
1591 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1593 self->priv->remember_password_widget = GTK_WIDGET (
1594 gtk_builder_get_object (self->ui_details->gui,
1595 "remember_password_simple"));
1599 self->ui_details->gui = empathy_builder_get_file (filename,
1600 "grid_common_settings", &self->priv->grid_common_settings,
1601 "vbox_yahoo_settings", &box,
1604 empathy_account_widget_handle_params (self,
1605 "entry_id", "account",
1606 "entry_password", "password",
1607 "entry_locale", "room-list-locale",
1608 "entry_charset", "charset",
1609 "spinbutton_port", "port",
1610 "checkbutton_ignore_invites", "ignore-invites",
1613 self->ui_details->default_focus = g_strdup ("entry_id");
1615 self->priv->remember_password_widget = GTK_WIDGET (
1616 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1623 account_widget_build_groupwise (EmpathyAccountWidget *self,
1624 const char *filename)
1628 if (self->priv->simple)
1630 self->ui_details->gui = empathy_builder_get_file (filename,
1631 "vbox_groupwise_simple", &box,
1634 empathy_account_widget_handle_params (self,
1635 "entry_id_simple", "account",
1636 "entry_password_simple", "password",
1639 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1641 self->priv->remember_password_widget = GTK_WIDGET (
1642 gtk_builder_get_object (self->ui_details->gui,
1643 "remember_password_simple"));
1647 self->ui_details->gui = empathy_builder_get_file (filename,
1648 "grid_common_groupwise_settings", &self->priv->grid_common_settings,
1649 "vbox_groupwise_settings", &box,
1652 empathy_account_widget_handle_params (self,
1653 "entry_id", "account",
1654 "entry_password", "password",
1655 "entry_server", "server",
1656 "spinbutton_port", "port",
1659 self->ui_details->default_focus = g_strdup ("entry_id");
1661 self->priv->remember_password_widget = GTK_WIDGET (
1662 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1669 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1670 gboolean others_exist)
1672 self->priv->other_accounts_exist = others_exist;
1674 if (self->priv->creating_account)
1675 account_widget_handle_control_buttons_sensitivity (self);
1679 do_set_property (GObject *object,
1681 const GValue *value,
1684 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object);
1689 self->priv->settings = g_value_dup_object (value);
1692 self->priv->simple = g_value_get_boolean (value);
1694 case PROP_CREATING_ACCOUNT:
1695 self->priv->creating_account = g_value_get_boolean (value);
1697 case PROP_OTHER_ACCOUNTS_EXIST:
1698 empathy_account_widget_set_other_accounts_exist (
1699 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1702 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1707 do_get_property (GObject *object,
1712 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object);
1717 g_value_set_string (value,
1718 empathy_account_settings_get_protocol (self->priv->settings));
1721 g_value_set_object (value, self->priv->settings);
1724 g_value_set_boolean (value, self->priv->simple);
1726 case PROP_CREATING_ACCOUNT:
1727 g_value_set_boolean (value, self->priv->creating_account);
1729 case PROP_OTHER_ACCOUNTS_EXIST:
1730 g_value_set_boolean (value, self->priv->other_accounts_exist);
1733 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1738 set_apply_button (EmpathyAccountWidget *self)
1742 /* We can't use the stock button as its accelerator ('A') clashes with the
1744 gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE);
1746 gtk_button_set_label (GTK_BUTTON (self->priv->apply_button), _("A_pply"));
1747 gtk_button_set_use_underline (GTK_BUTTON (self->priv->apply_button), TRUE);
1749 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1750 gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image);
1754 presence_changed_cb (TpAccountManager *manager,
1755 TpConnectionPresenceType state,
1756 const gchar *status,
1757 const gchar *message,
1758 EmpathyAccountWidget *self)
1760 if (self->priv->destroyed)
1763 if (self->priv->apply_button == NULL)
1764 /* This button doesn't exist in 'simple' mode */
1767 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1768 self->priv->creating_account)
1770 /* We are online and creating a new account, display a Login button */
1773 gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE);
1774 gtk_button_set_label (GTK_BUTTON (self->priv->apply_button),
1777 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1778 GTK_ICON_SIZE_BUTTON);
1779 gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image);
1783 /* We are offline or modifying an existing account, display
1785 set_apply_button (self);
1790 account_manager_ready_cb (GObject *source_object,
1791 GAsyncResult *result,
1794 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1795 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1796 GError *error = NULL;
1797 TpConnectionPresenceType state;
1799 if (!tp_proxy_prepare_finish (account_manager, result, &error))
1801 DEBUG ("Failed to prepare account manager: %s", error->message);
1802 g_error_free (error);
1806 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1809 /* simulate a presence change so the apply button will be changed
1811 presence_changed_cb (account_manager, state, NULL, NULL, self);
1814 g_object_unref (self);
1817 #define WIDGET(cm, proto) \
1818 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1819 account_widget_build_##proto }
1822 add_register_buttons (EmpathyAccountWidget *self,
1825 TpProtocol *protocol;
1826 GtkWidget *radiobutton_register;
1828 if (!self->priv->creating_account)
1831 protocol = empathy_account_settings_get_tp_protocol (self->priv->settings);
1832 if (protocol == NULL)
1835 if (!tp_protocol_can_register (protocol))
1838 if (account_widget_get_service (self) != NO_SERVICE)
1841 if (self->priv->simple)
1844 self->priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1845 _("This account already exists on the server"));
1846 radiobutton_register = gtk_radio_button_new_with_label (
1847 gtk_radio_button_get_group (
1848 GTK_RADIO_BUTTON (self->priv->radiobutton_reuse)),
1849 _("Create a new account on the server"));
1851 gtk_box_pack_start (GTK_BOX (self), self->priv->radiobutton_reuse, FALSE,
1853 gtk_box_pack_start (GTK_BOX (self), radiobutton_register, FALSE, FALSE, 0);
1854 gtk_box_reorder_child (GTK_BOX (self), self->priv->radiobutton_reuse, 0);
1855 gtk_box_reorder_child (GTK_BOX (self), radiobutton_register, 1);
1856 gtk_widget_show (self->priv->radiobutton_reuse);
1857 gtk_widget_show (radiobutton_register);
1861 remember_password_toggled_cb (GtkToggleButton *button,
1862 EmpathyAccountWidget *self)
1864 empathy_account_settings_set_remember_password (self->priv->settings,
1865 gtk_toggle_button_get_active (button));
1867 if (!self->priv->automatic_change)
1868 empathy_account_widget_changed (self);
1872 account_settings_password_retrieved_cb (GObject *object,
1875 EmpathyAccountWidget *self = user_data;
1878 password = empathy_account_settings_dup_string (
1879 self->priv->settings, "password");
1881 /* We have to do this so that when we call gtk_entry_set_text,
1882 * the ::changed callback doesn't think the user made the
1883 * change. This is also used in remember_password_toggled_cb. */
1884 self->priv->automatic_change = TRUE;
1886 if (password != NULL)
1888 gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget),
1892 gtk_toggle_button_set_active (
1893 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget),
1894 !EMP_STR_EMPTY (password));
1896 self->priv->automatic_change = FALSE;
1902 do_constructed (GObject *obj)
1904 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1906 const gchar *display_name, *default_display_name;
1909 const gchar *cm_name;
1910 const gchar *protocol;
1912 GtkWidget * (*func)(EmpathyAccountWidget *self, const gchar *filename);
1914 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1915 account_widget_build_salut },
1916 WIDGET (gabble, jabber),
1920 WIDGET (haze, yahoo),
1921 WIDGET (haze, groupwise),
1923 WIDGET (sofiasip, sip),
1925 const gchar *protocol, *cm_name;
1928 account = empathy_account_settings_get_account (self->priv->settings);
1930 cm_name = empathy_account_settings_get_cm (self->priv->settings);
1931 protocol = empathy_account_settings_get_protocol (self->priv->settings);
1933 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1935 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1936 !tp_strdiff (widgets[i].protocol, protocol))
1940 filename = empathy_file_lookup (widgets[i].file,
1942 box = widgets[i].func (self, filename);
1949 if (i == G_N_ELEMENTS (widgets))
1951 gchar *filename = empathy_file_lookup (
1952 "empathy-account-widget-generic.ui", "libempathy-gtk");
1953 box = account_widget_build_generic (self, filename);
1957 gtk_container_add (GTK_CONTAINER (self), box);
1959 /* handle default focus */
1960 if (self->ui_details->default_focus != NULL)
1962 GObject *default_focus_entry;
1964 default_focus_entry = gtk_builder_get_object
1965 (self->ui_details->gui, self->ui_details->default_focus);
1966 g_signal_connect (default_focus_entry, "realize",
1967 G_CALLBACK (gtk_widget_grab_focus),
1971 /* remember password */
1972 if (self->priv->param_password_widget != NULL
1973 && self->priv->remember_password_widget != NULL
1974 && empathy_account_settings_supports_sasl (self->priv->settings))
1976 if (self->priv->simple)
1978 gtk_toggle_button_set_active (
1979 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), TRUE);
1985 password = empathy_account_settings_dup_string (self->priv->settings,
1988 /* FIXME: we should enable this checkbox only if the password is
1989 * stored for good in the password storage, not only for the session
1991 gtk_toggle_button_set_active (
1992 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget),
1993 !EMP_STR_EMPTY (password));
1995 /* The password might not have been retrieved from the
1996 * keyring yet. We should update the remember password
1997 * toggle button and the password entry when/if it is. */
1998 tp_g_signal_connect_object (self->priv->settings,
1999 "password-retrieved",
2000 G_CALLBACK (account_settings_password_retrieved_cb), self, 0);
2005 g_signal_connect (self->priv->remember_password_widget, "toggled",
2006 G_CALLBACK (remember_password_toggled_cb), self);
2008 self->priv->automatic_change = TRUE;
2009 remember_password_toggled_cb (
2010 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), self);
2011 self->priv->automatic_change = FALSE;
2013 else if (self->priv->remember_password_widget != NULL
2014 && !empathy_account_settings_supports_sasl (self->priv->settings))
2016 gtk_widget_set_visible (self->priv->remember_password_widget, FALSE);
2017 empathy_account_settings_set_remember_password (self->priv->settings,
2021 /* dup and init the account-manager */
2022 self->priv->account_manager = tp_account_manager_dup ();
2024 g_object_ref (self);
2025 tp_proxy_prepare_async (self->priv->account_manager, NULL,
2026 account_manager_ready_cb, self);
2028 /* handle apply and cancel button */
2029 self->priv->hbox_buttons = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2031 gtk_box_set_homogeneous (GTK_BOX (self->priv->hbox_buttons), TRUE);
2033 self->priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
2035 self->priv->apply_button = gtk_button_new ();
2036 set_apply_button (self);
2038 /* We'll change this button to a "Log in" one if we are creating a new
2039 * account and are connected. */
2040 tp_g_signal_connect_object (self->priv->account_manager,
2041 "most-available-presence-changed",
2042 G_CALLBACK (presence_changed_cb), obj, 0);
2044 gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons),
2045 self->priv->apply_button, TRUE, TRUE, 3);
2046 gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons),
2047 self->priv->cancel_button, TRUE, TRUE, 3);
2049 gtk_box_pack_end (GTK_BOX (self), self->priv->hbox_buttons, FALSE,
2052 g_signal_connect (self->priv->cancel_button, "clicked",
2053 G_CALLBACK (account_widget_cancel_clicked_cb),
2055 g_signal_connect (self->priv->apply_button, "clicked",
2056 G_CALLBACK (account_widget_apply_clicked_cb),
2058 gtk_widget_show_all (self->priv->hbox_buttons);
2060 if (self->priv->creating_account)
2061 /* When creating an account, the user might have nothing to enter.
2062 * That means that no control interaction might occur,
2063 * so we update the control button sensitivity manually.
2065 account_widget_handle_control_buttons_sensitivity (self);
2067 account_widget_set_control_buttons_sensitivity (self, FALSE);
2069 add_register_buttons (self, account);
2071 g_clear_object (&self->ui_details->gui);
2073 display_name = empathy_account_settings_get_display_name (
2074 self->priv->settings);
2075 default_display_name = empathy_account_widget_get_default_display_name (self);
2077 if (tp_strdiff (display_name, default_display_name) &&
2078 !self->priv->creating_account)
2080 /* The display name of the account is not the one that we'd assign by
2081 * default; assume that the user changed it manually */
2082 g_object_set (self->priv->settings, "display-name-overridden", TRUE,
2088 do_dispose (GObject *obj)
2090 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2092 g_clear_object (&self->priv->settings);
2093 g_clear_object (&self->priv->account_manager);
2095 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
2096 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
2100 do_finalize (GObject *obj)
2102 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2104 g_free (self->ui_details->default_focus);
2105 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
2107 g_free (self->priv->jid_suffix);
2109 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
2110 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
2114 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
2116 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2117 GParamSpec *param_spec;
2119 oclass->get_property = do_get_property;
2120 oclass->set_property = do_set_property;
2121 oclass->constructed = do_constructed;
2122 oclass->dispose = do_dispose;
2123 oclass->finalize = do_finalize;
2125 param_spec = g_param_spec_string ("protocol",
2126 "protocol", "The protocol of the account",
2128 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2129 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2131 param_spec = g_param_spec_object ("settings",
2132 "settings", "The settings of the account",
2133 EMPATHY_TYPE_ACCOUNT_SETTINGS,
2134 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2135 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2137 param_spec = g_param_spec_boolean ("simple",
2138 "simple", "Whether the account widget is a simple or an advanced one",
2140 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2141 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2143 param_spec = g_param_spec_boolean ("creating-account",
2145 "TRUE if we're creating an account, FALSE if we're modifying it",
2147 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2148 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2150 param_spec = g_param_spec_boolean ("other-accounts-exist",
2151 "other-accounts-exist",
2152 "TRUE if there are any other accounts (even if this isn't yet saved)",
2154 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2155 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2158 signals[HANDLE_APPLY] =
2159 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2160 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2161 g_cclosure_marshal_generic,
2165 /* This signal is emitted when an account has been created and enabled. */
2166 signals[ACCOUNT_CREATED] =
2167 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2168 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2169 g_cclosure_marshal_generic,
2173 signals[CANCELLED] =
2174 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2175 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2176 g_cclosure_marshal_generic,
2181 g_signal_new ("close", G_TYPE_FROM_CLASS (klass),
2182 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2183 g_cclosure_marshal_VOID__INT,
2187 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
2191 empathy_account_widget_init (EmpathyAccountWidget *self)
2193 self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
2194 EmpathyAccountWidgetPriv);
2196 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
2199 /* public methods */
2202 empathy_account_widget_discard_pending_changes (EmpathyAccountWidget *self)
2204 empathy_account_settings_discard_changes (self->priv->settings);
2205 self->priv->contains_pending_changes = FALSE;
2209 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *self)
2211 return self->priv->contains_pending_changes;
2215 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
2216 const gchar *first_widget,
2221 va_start (args, first_widget);
2222 account_widget_handle_params_valist (self, first_widget, args);
2226 EmpathyAccountWidget *
2227 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
2230 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
2232 return g_object_new (EMPATHY_TYPE_ACCOUNT_WIDGET,
2233 "orientation", GTK_ORIENTATION_VERTICAL,
2234 "settings", settings,
2237 empathy_account_settings_get_account (settings) == NULL,
2242 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
2245 const gchar *protocol, *p;
2246 gchar *default_display_name;
2249 login_id = empathy_account_settings_dup_string (self->priv->settings,
2251 protocol = empathy_account_settings_get_protocol (self->priv->settings);
2252 service = account_widget_get_service (self);
2254 if (login_id != NULL)
2256 /* TODO: this should be done in empathy-account-widget-irc */
2257 if (!tp_strdiff (protocol, "irc"))
2259 EmpathyIrcNetwork *network;
2261 network = empathy_irc_network_chooser_get_network (
2262 self->priv->irc_network_chooser);
2263 g_assert (network != NULL);
2265 /* To translators: The first parameter is the login id and the
2266 * second one is the network. The resulting string will be something
2267 * like: "MyUserName on freenode".
2268 * You should reverse the order of these arguments if the
2269 * server should come before the login id in your locale.*/
2270 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2271 login_id, empathy_irc_network_get_name (network));
2273 else if (service == FACEBOOK_SERVICE && self->priv->jid_suffix != NULL)
2277 tmp = remove_jid_suffix (self, login_id);
2278 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2283 default_display_name = g_strdup (login_id);
2286 return default_display_name;
2289 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2292 if (protocol != NULL)
2294 /* To translators: The parameter is the protocol name. The resulting
2295 * string will be something like: "Jabber Account" */
2296 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2300 default_display_name = g_strdup (_("New account"));
2305 return default_display_name;
2308 /* Used by subclass to indicate that widget contains pending changes */
2310 empathy_account_widget_changed (EmpathyAccountWidget *self)
2312 account_widget_handle_control_buttons_sensitivity (self);
2313 self->priv->contains_pending_changes = TRUE;
2317 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2318 const gchar *account)
2320 if (self->priv->param_account_widget == NULL)
2323 gtk_entry_set_text (GTK_ENTRY (self->priv->param_account_widget), account);
2327 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2328 const gchar *account)
2330 if (self->priv->param_password_widget == NULL)
2333 gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), account);
2336 EmpathyAccountSettings *
2337 empathy_account_widget_get_settings (EmpathyAccountWidget *self)
2339 return self->priv->settings;
2343 empathy_account_widget_hide_buttons (EmpathyAccountWidget *self)
2345 gtk_widget_hide (self->priv->hbox_buttons);