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/account.h>
39 #include <telepathy-glib/account-manager.h>
40 #include <telepathy-glib/connection-manager.h>
41 #include <telepathy-glib/util.h>
42 #include <dbus/dbus-protocol.h>
44 #include "empathy-account-widget.h"
45 #include "empathy-account-widget-private.h"
46 #include "empathy-account-widget-sip.h"
47 #include "empathy-account-widget-irc.h"
48 #include "empathy-ui-utils.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
51 #include <libempathy/empathy-debug.h>
53 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, GTK_TYPE_BOX)
65 const gchar *label_username_example;
66 gboolean show_advanced;
69 static ServiceInfo services_infos[N_SERVICES] = {
70 { "label_username_example", TRUE },
71 { "label_username_g_example", FALSE },
72 { "label_username_f_example", FALSE },
75 struct _EmpathyAccountWidgetPriv {
76 EmpathyAccountSettings *settings;
78 GtkWidget *grid_common_settings;
79 GtkWidget *apply_button;
80 GtkWidget *cancel_button;
81 GtkWidget *entry_password;
82 GtkWidget *spinbutton_port;
83 GtkWidget *radiobutton_reuse;
84 GtkWidget *hbox_buttons;
88 gboolean contains_pending_changes;
90 /* An EmpathyAccountWidget can be used to either create an account or
91 * modify it. When we are creating an account, this member is set to TRUE */
92 gboolean creating_account;
94 /* whether there are any other real accounts. Necessary so we know whether
95 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
96 * button should be sensitive) */
97 gboolean other_accounts_exist;
99 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
100 * embedded in this account widget can't be used any more
101 * workaround because some async callbacks can be called after the
102 * widget has been destroyed */
105 TpAccountManager *account_manager;
107 GtkWidget *param_account_widget;
108 GtkWidget *param_password_widget;
110 gboolean automatic_change;
111 GtkWidget *remember_password_widget;
113 /* Used only for IRC accounts */
114 EmpathyIrcNetworkChooser *irc_network_chooser;
116 /* Used for 'special' XMPP account having a service associated ensuring that
117 * JIDs have a specific suffix; such as Facebook for example */
125 PROP_CREATING_ACCOUNT,
126 PROP_OTHER_ACCOUNTS_EXIST,
141 static guint signals[LAST_SIGNAL] = { 0 };
143 #define CHANGED_TIMEOUT 300
146 #define DIGITS "(["DIGIT"]+)"
147 #define ALPHA "a-zA-Z"
148 #define ALPHAS "(["ALPHA"]+)"
149 #define ALPHADIGIT ALPHA DIGIT
150 #define ALPHADIGITS "(["ALPHADIGIT"]+)"
151 #define ALPHADIGITDASH ALPHA DIGIT "-"
152 #define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
154 #define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
155 #define TOPLABEL "("ALPHAS \
156 "| (["ALPHA"]"ALPHADIGITDASHS "["ALPHADIGIT"]))"
157 #define DOMAINLABEL "("ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
159 #define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
160 /* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
161 #define HOST "("HOSTNAME "|" HOSTNUMBER")"
162 /* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
163 #define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
165 /* UIN is digital according to the unofficial specification:
166 * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
167 * 5 digits minimum according to http://en.wikipedia.org/wiki/ICQ#UIN
168 * According to an user, we can also provide an email address instead of the
170 #define ICQ_USER_NAME "((["DIGIT"]{5,})|"EMAIL_LOCALPART"@"HOST")"
172 /* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
173 #define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
174 #define IRC_NICK_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
176 /* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
177 * We just exclude invalid characters to avoid ucschars and other redundant
179 #define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
180 /* ID is an email according to the unofficial specification:
181 * http://www.hypothetic.org/docs/msn/general/names.php */
182 #define MSN_USER_NAME EMAIL_LOCALPART
183 /* Based on the official help:
184 * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html
185 * Looks like an email address can be used as well (bgo #655959)
187 #define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})|("EMAIL_LOCALPART"@"HOST")"
189 #define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
190 #define ACCOUNT_REGEX_IRC "^"IRC_NICK_NAME"$"
191 #define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@[^@/]+"
192 #define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
193 #define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
196 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
199 /* we hit this case because of the 'other-accounts-exist' property handler
200 * being called during init (before constructed()) */
201 if (self->priv->apply_button == NULL || self->priv->cancel_button == NULL)
204 gtk_widget_set_sensitive (self->priv->apply_button, sensitive);
208 /* We can't grab default if the widget hasn't be packed in a
212 window = gtk_widget_get_toplevel (self->priv->apply_button);
213 if (window != NULL &&
214 gtk_widget_is_toplevel (window))
216 gtk_widget_set_can_default (self->priv->apply_button, TRUE);
217 gtk_widget_grab_default (self->priv->apply_button);
223 account_widget_set_entry_highlighting (GtkEntry *entry,
226 g_return_if_fail (GTK_IS_ENTRY (entry));
230 GtkStyleContext *style;
233 style = gtk_widget_get_style_context (GTK_WIDGET (entry));
234 gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
237 /* Here we take the current theme colour and add it to
238 * the colour for white and average the two. This
239 * gives a colour which is inline with the theme but
242 empathy_make_color_whiter (&color);
244 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, &color);
248 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, NULL);
253 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
257 is_valid = empathy_account_settings_is_valid (self->priv->settings);
259 account_widget_set_control_buttons_sensitivity (self, is_valid);
261 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
265 account_widget_entry_changed_common (EmpathyAccountWidget *self,
266 GtkEntry *entry, gboolean focus)
269 const gchar *param_name;
270 gboolean prev_status;
271 gboolean curr_status;
273 str = gtk_entry_get_text (entry);
274 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
275 prev_status = empathy_account_settings_parameter_is_valid (
276 self->priv->settings, param_name);
278 if (EMP_STR_EMPTY (str))
280 empathy_account_settings_unset (self->priv->settings, param_name);
286 value = empathy_account_settings_dup_string (self->priv->settings,
289 DEBUG ("Unset %s and restore to %s", param_name, value);
290 gtk_entry_set_text (entry, value ? value : "");
296 DEBUG ("Setting %s to %s", param_name,
297 tp_strdiff (param_name, "password") ? str : "***");
298 empathy_account_settings_set (self->priv->settings, param_name,
299 g_variant_new_string (str));
302 curr_status = empathy_account_settings_parameter_is_valid (
303 self->priv->settings, param_name);
305 if (curr_status != prev_status)
306 account_widget_set_entry_highlighting (entry, !curr_status);
310 account_widget_entry_changed_cb (GtkEditable *entry,
311 EmpathyAccountWidget *self)
313 if (self->priv->automatic_change)
316 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
317 empathy_account_widget_changed (self);
321 account_widget_entry_map_cb (GtkEntry *entry,
322 EmpathyAccountWidget *self)
324 const gchar *param_name;
327 /* need to initialize input highlighting */
328 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
329 is_valid = empathy_account_settings_parameter_is_valid (self->priv->settings,
331 account_widget_set_entry_highlighting (entry, !is_valid);
335 account_widget_int_changed_cb (GtkWidget *widget,
336 EmpathyAccountWidget *self)
338 const gchar *param_name;
340 const gchar *signature;
342 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
343 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
345 signature = empathy_account_settings_get_dbus_signature (self->priv->settings,
347 g_return_if_fail (signature != NULL);
349 DEBUG ("Setting %s to %d", param_name, value);
351 switch ((int)*signature)
353 case DBUS_TYPE_INT16:
354 case DBUS_TYPE_INT32:
355 empathy_account_settings_set (self->priv->settings, param_name,
356 g_variant_new_int32 (value));
358 case DBUS_TYPE_INT64:
359 empathy_account_settings_set (self->priv->settings, param_name,
360 g_variant_new_int64 (value));
362 case DBUS_TYPE_UINT16:
363 case DBUS_TYPE_UINT32:
364 empathy_account_settings_set (self->priv->settings, param_name,
365 g_variant_new_uint32 (value));
367 case DBUS_TYPE_UINT64:
368 empathy_account_settings_set (self->priv->settings, param_name,
369 g_variant_new_uint64 (value));
372 g_return_if_reached ();
375 empathy_account_widget_changed (self);
379 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
380 EmpathyAccountWidget *self)
383 gboolean default_value;
384 const gchar *param_name;
386 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
387 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
389 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
390 * always unset the param and set the value if different from the
392 empathy_account_settings_unset (self->priv->settings, param_name);
393 default_value = empathy_account_settings_get_boolean (self->priv->settings,
396 if (default_value == value)
398 DEBUG ("Unset %s and restore to %d", param_name, default_value);
402 DEBUG ("Setting %s to %d", param_name, value);
403 empathy_account_settings_set (self->priv->settings, param_name,
404 g_variant_new_boolean (value));
407 empathy_account_widget_changed (self);
411 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
412 EmpathyAccountWidget *self)
417 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
418 port = empathy_account_settings_get_uint32 (self->priv->settings, "port");
422 if (port == 5222 || port == 0)
427 if (port == 5223 || port == 0)
431 gtk_spin_button_set_value (GTK_SPIN_BUTTON (self->priv->spinbutton_port),
434 self->priv->contains_pending_changes = TRUE;
438 account_widget_combobox_changed_cb (GtkWidget *widget,
439 EmpathyAccountWidget *self)
445 const gchar *default_value = NULL;
446 const gchar *param_name;
448 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
451 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
452 /* the param value is stored in the first column */
453 gtk_tree_model_get (model, &iter, 0, &value, -1);
455 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
457 v = empathy_account_settings_dup_default (self->priv->settings, param_name);
458 if (v != NULL && g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
459 default_value = g_variant_get_string (v, NULL);
461 if (!tp_strdiff (value, default_value))
463 DEBUG ("Unset %s and restore to %s", param_name, default_value);
464 empathy_account_settings_unset (self->priv->settings, param_name);
468 DEBUG ("Setting %s to %s", param_name, value);
469 empathy_account_settings_set (self->priv->settings, param_name,
470 g_variant_new_string (value));
473 empathy_account_widget_changed (self);
475 tp_clear_pointer (&v, g_variant_unref);
479 clear_icon_released_cb (GtkEntry *entry,
480 GtkEntryIconPosition icon_pos,
482 EmpathyAccountWidget *self)
484 const gchar *param_name;
486 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
488 DEBUG ("Unset %s", param_name);
489 empathy_account_settings_unset (self->priv->settings, param_name);
490 gtk_entry_set_text (entry, "");
492 empathy_account_widget_changed (self);
496 password_entry_changed_cb (GtkEditable *entry,
497 EmpathyAccountWidget *self)
501 str = gtk_entry_get_text (GTK_ENTRY (entry));
503 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
504 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
508 password_entry_activated_cb (GtkEntry *entry,
509 EmpathyAccountWidget *self)
511 if (gtk_widget_get_sensitive (self->priv->apply_button))
512 empathy_account_widget_apply_and_log_in (self);
516 account_entry_activated_cb (GtkEntry *entry,
517 EmpathyAccountWidget *self)
519 if (gtk_widget_get_sensitive (self->priv->apply_button))
520 empathy_account_widget_apply_and_log_in (self);
524 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
526 const gchar *param_name)
528 g_object_set_data_full (G_OBJECT (widget), "param_name",
529 g_strdup (param_name), g_free);
531 if (GTK_IS_SPIN_BUTTON (widget))
534 const gchar *signature;
536 signature = empathy_account_settings_get_dbus_signature (
537 self->priv->settings, param_name);
538 g_return_if_fail (signature != NULL);
540 switch ((int)*signature)
542 case DBUS_TYPE_INT16:
543 case DBUS_TYPE_INT32:
544 value = empathy_account_settings_get_int32 (self->priv->settings,
547 case DBUS_TYPE_INT64:
548 value = empathy_account_settings_get_int64 (self->priv->settings,
551 case DBUS_TYPE_UINT16:
552 case DBUS_TYPE_UINT32:
553 value = empathy_account_settings_get_uint32 (self->priv->settings,
556 case DBUS_TYPE_UINT64:
557 value = empathy_account_settings_get_uint64 (self->priv->settings,
561 g_return_if_reached ();
564 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
566 g_signal_connect (widget, "value-changed",
567 G_CALLBACK (account_widget_int_changed_cb),
570 else if (GTK_IS_ENTRY (widget))
574 str = empathy_account_settings_dup_string (self->priv->settings,
576 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
578 if (!tp_strdiff (param_name, "account"))
579 self->priv->param_account_widget = widget;
580 else if (!tp_strdiff (param_name, "password"))
581 self->priv->param_password_widget = widget;
583 if (strstr (param_name, "password"))
585 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
587 /* Add 'clear' icon */
588 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
589 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
591 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
592 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
594 g_signal_connect (widget, "icon-release",
595 G_CALLBACK (clear_icon_released_cb), self);
596 g_signal_connect (widget, "changed",
597 G_CALLBACK (password_entry_changed_cb), self);
598 g_signal_connect (widget, "activate",
599 G_CALLBACK (password_entry_activated_cb), self);
601 else if (strstr (param_name, "account"))
602 g_signal_connect (widget, "activate",
603 G_CALLBACK (account_entry_activated_cb), self);
605 g_signal_connect (widget, "changed",
606 G_CALLBACK (account_widget_entry_changed_cb), self);
607 g_signal_connect (widget, "map",
608 G_CALLBACK (account_widget_entry_map_cb), self);
612 else if (GTK_IS_TOGGLE_BUTTON (widget))
614 gboolean value = FALSE;
616 value = empathy_account_settings_get_boolean (self->priv->settings,
618 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
620 g_signal_connect (widget, "toggled",
621 G_CALLBACK (account_widget_checkbutton_toggled_cb),
624 else if (GTK_IS_COMBO_BOX (widget))
626 /* The combo box's model has to contain the param value in its first
627 * column (as a string) */
633 str = empathy_account_settings_dup_string (self->priv->settings,
635 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
637 valid = gtk_tree_model_get_iter_first (model, &iter);
642 gtk_tree_model_get (model, &iter, 0, &name, -1);
643 if (!tp_strdiff (name, str))
645 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
650 valid = gtk_tree_model_iter_next (model, &iter);
658 g_signal_connect (widget, "changed",
659 G_CALLBACK (account_widget_combobox_changed_cb),
664 DEBUG ("Unknown type of widget for param %s", param_name);
667 gtk_widget_set_sensitive (widget,
668 empathy_account_settings_param_is_supported (self->priv->settings,
673 build_translated_params (void)
677 hash = g_hash_table_new (g_str_hash, g_str_equal);
678 g_hash_table_insert (hash, "account", _("Account"));
679 g_hash_table_insert (hash, "password", _("Password"));
680 g_hash_table_insert (hash, "server", _("Server"));
681 g_hash_table_insert (hash, "port", _("Port"));
687 account_widget_generic_format_param_name (const gchar *param_name)
691 static GHashTable *translated_params = NULL;
693 g_return_val_if_fail (param_name != NULL, NULL);
695 if (G_UNLIKELY (translated_params == NULL))
696 translated_params = build_translated_params ();
698 /* Translate most common parameters */
699 str = g_hash_table_lookup (translated_params, param_name);
701 return g_strdup (str);
703 str = g_strdup (param_name);
705 if (str && g_ascii_isalpha (str[0]))
706 str[0] = g_ascii_toupper (str[0]);
708 while ((p = strchr (str, '-')) != NULL)
710 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
713 p[1] = g_ascii_toupper (p[1]);
723 accounts_widget_generic_setup (EmpathyAccountWidget *self,
724 GtkWidget *grid_common_settings,
725 GtkWidget *grid_advanced_settings)
728 guint row_common = 0, row_advanced = 0;
730 params = empathy_account_settings_dup_tp_params (self->priv->settings);
732 for (l = params; l != NULL; l = g_list_next (l))
734 TpConnectionManagerParam *param = l->data;
735 GtkWidget *grid_settings;
737 GtkWidget *widget = NULL;
738 gchar *param_name_formatted;
739 const gchar *dbus_signature;
741 if (tp_connection_manager_param_is_required (param))
743 grid_settings = grid_common_settings;
746 else if (self->priv->simple)
752 grid_settings = grid_advanced_settings;
753 row = row_advanced++;
756 param_name_formatted = account_widget_generic_format_param_name (
757 tp_connection_manager_param_get_name (param));
759 dbus_signature = tp_connection_manager_param_get_dbus_signature (param);
761 if (dbus_signature[0] == 's')
765 str = g_strdup_printf (_("%s"), param_name_formatted);
766 widget = gtk_label_new (str);
767 gtk_misc_set_alignment (GTK_MISC (widget), 1., 0.5);
768 gtk_style_context_add_class (gtk_widget_get_style_context (widget),
769 GTK_STYLE_CLASS_DIM_LABEL);
772 gtk_grid_attach (GTK_GRID (grid_settings),
773 widget, 0, row, 1, 1);
775 gtk_widget_show (widget);
777 widget = gtk_entry_new ();
778 if (strcmp (tp_connection_manager_param_get_name (param),
781 g_signal_connect (widget, "realize",
782 G_CALLBACK (gtk_widget_grab_focus),
786 gtk_grid_attach (GTK_GRID (grid_settings),
787 widget, 1, row, 1, 1);
789 gtk_widget_show (widget);
791 /* int types: ynqiuxt. double type is 'd' */
792 else if (dbus_signature[0] == 'y' ||
793 dbus_signature[0] == 'n' ||
794 dbus_signature[0] == 'q' ||
795 dbus_signature[0] == 'i' ||
796 dbus_signature[0] == 'u' ||
797 dbus_signature[0] == 'x' ||
798 dbus_signature[0] == 't' ||
799 dbus_signature[0] == 'd')
806 switch (dbus_signature[0])
808 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
809 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
810 case 'q': minint = 0; maxint = G_MAXUINT16; break;
811 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
812 case 'u': minint = 0; maxint = G_MAXUINT32; break;
813 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
814 case 't': minint = 0; maxint = G_MAXUINT64; break;
815 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
817 default: g_assert_not_reached ();
820 str = g_strdup_printf (_("%s:"), param_name_formatted);
821 widget = gtk_label_new (str);
822 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
825 gtk_grid_attach (GTK_GRID (grid_settings),
826 widget, 0, row, 1, 1);
827 gtk_widget_show (widget);
829 widget = gtk_spin_button_new_with_range (minint, maxint, step);
830 gtk_grid_attach (GTK_GRID (grid_settings),
831 widget, 1, row, 1, 1);
832 gtk_widget_show (widget);
834 else if (dbus_signature[0] == 'b')
836 widget = gtk_check_button_new_with_label (param_name_formatted);
837 gtk_grid_attach (GTK_GRID (grid_settings),
838 widget, 0, row, 2, 1);
839 gtk_widget_show (widget);
843 DEBUG ("Unknown signature for param %s: %s",
844 param_name_formatted, dbus_signature);
848 empathy_account_widget_setup_widget (self, widget,
849 tp_connection_manager_param_get_name (param));
851 g_free (param_name_formatted);
854 g_list_free_full (params, (GDestroyNotify) tp_connection_manager_param_free);
858 account_widget_handle_params_valist (EmpathyAccountWidget *self,
859 const gchar *first_widget,
865 for (name = first_widget; name; name = va_arg (args, const gchar *))
867 const gchar *param_name;
869 param_name = va_arg (args, const gchar *);
870 object = gtk_builder_get_object (self->ui_details->gui, name);
874 g_warning ("Builder is missing object '%s'.", name);
878 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
884 account_widget_cancel_clicked_cb (GtkWidget *button,
885 EmpathyAccountWidget *self)
887 g_signal_emit (self, signals[CANCELLED], 0);
888 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_CANCEL);
892 account_widget_account_enabled_cb (GObject *source_object,
896 GError *error = NULL;
897 TpAccount *account = TP_ACCOUNT (source_object);
898 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
900 tp_account_set_enabled_finish (account, res, &error);
904 DEBUG ("Could not enable the account: %s", error->message);
905 g_error_free (error);
909 empathy_connect_new_account (account, self->priv->account_manager);
912 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY);
914 /* unref self - part of the workaround */
915 g_object_unref (self);
919 account_widget_applied_cb (GObject *source_object,
923 GError *error = NULL;
925 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
926 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
927 gboolean reconnect_required;
928 gboolean fire_close = TRUE;
930 empathy_account_settings_apply_finish (settings, res, &reconnect_required,
935 DEBUG ("Could not apply changes to account: %s", error->message);
936 g_error_free (error);
940 account = empathy_account_settings_get_account (self->priv->settings);
944 if (self->priv->creating_account)
946 /* By default, when an account is created, we enable it. */
948 /* workaround to keep self alive during async call */
951 tp_account_set_enabled_async (account, TRUE,
952 account_widget_account_enabled_cb, self);
953 g_signal_emit (self, signals[ACCOUNT_CREATED], 0, account);
955 /* Will be fired in account_widget_account_enabled_cb */
960 /* If the account was offline, we always want to try reconnecting,
961 * to give it a chance to connect if the previous params were wrong.
962 * tp_account_reconnect_async() won't do anything if the requested
963 * presence is offline anyway. */
964 if (tp_account_get_connection_status (account, NULL) ==
965 TP_CONNECTION_STATUS_DISCONNECTED)
966 reconnect_required = TRUE;
968 if (reconnect_required && tp_account_is_enabled (account)
969 && tp_account_is_enabled (account))
971 /* After having applied changes to a user account, we
972 * reconnect it if needed. This is done so the new
973 * information entered by the user is validated on the server. */
974 tp_account_reconnect_async (account, NULL, NULL);
979 if (!self->priv->destroyed)
980 account_widget_set_control_buttons_sensitivity (self, FALSE);
982 self->priv->contains_pending_changes = FALSE;
986 /* announce the widget can be closed */
987 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY);
990 /* unref the widget - part of the workaround */
991 g_object_unref (self);
995 empathy_account_widget_apply_and_log_in (EmpathyAccountWidget *self)
997 gboolean display_name_overridden;
999 if (self->priv->radiobutton_reuse != NULL)
1001 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
1002 self->priv->radiobutton_reuse));
1004 DEBUG ("Set register param: %d", !reuse);
1005 empathy_account_settings_set (self->priv->settings, "register",
1006 g_variant_new_boolean (!reuse));
1009 g_object_get (self->priv->settings,
1010 "display-name-overridden", &display_name_overridden, NULL);
1012 if (self->priv->creating_account || !display_name_overridden)
1014 gchar *display_name;
1016 /* set default display name for new accounts or update if user didn't
1017 * manually override it. */
1018 display_name = empathy_account_widget_get_default_display_name (self);
1020 empathy_account_settings_set_display_name_async (self->priv->settings,
1021 display_name, NULL, NULL);
1023 g_free (display_name);
1026 /* workaround to keep widget alive during async call */
1027 g_object_ref (self);
1028 empathy_account_settings_apply_async (self->priv->settings,
1029 account_widget_applied_cb, self);
1033 account_widget_apply_clicked_cb (GtkWidget *button,
1034 EmpathyAccountWidget *self)
1036 empathy_account_widget_apply_and_log_in (self);
1040 account_widget_setup_generic (EmpathyAccountWidget *self)
1042 GtkWidget *grid_common_settings;
1043 GtkWidget *grid_advanced_settings;
1045 grid_common_settings = GTK_WIDGET (gtk_builder_get_object
1046 (self->ui_details->gui, "grid_common_settings"));
1047 grid_advanced_settings = GTK_WIDGET (gtk_builder_get_object
1048 (self->ui_details->gui, "grid_advanced_settings"));
1050 accounts_widget_generic_setup (self, grid_common_settings,
1051 grid_advanced_settings);
1053 g_object_unref (self->ui_details->gui);
1057 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
1061 EmpathyAccountWidget *self = user_data;
1063 if (empathy_account_settings_is_ready (self->priv->settings))
1064 account_widget_setup_generic (self);
1068 account_widget_build_generic (EmpathyAccountWidget *self,
1069 const char *filename)
1071 GtkWidget *expander_advanced, *box;
1073 self->ui_details->gui = empathy_builder_get_file (filename,
1074 "grid_common_settings", &self->priv->grid_common_settings,
1075 "vbox_generic_settings", &box,
1076 "expander_advanced_settings", &expander_advanced,
1079 if (self->priv->simple)
1080 gtk_widget_hide (expander_advanced);
1082 g_object_ref (self->ui_details->gui);
1084 if (empathy_account_settings_is_ready (self->priv->settings))
1085 account_widget_setup_generic (self);
1087 g_signal_connect (self->priv->settings, "notify::ready",
1088 G_CALLBACK (account_widget_settings_ready_cb), self);
1094 account_widget_build_salut (EmpathyAccountWidget *self,
1095 const char *filename)
1097 GtkWidget *expander_advanced, *box;
1099 self->ui_details->gui = empathy_builder_get_file (filename,
1100 "grid_common_settings", &self->priv->grid_common_settings,
1101 "vbox_salut_settings", &box,
1102 "expander_advanced_settings", &expander_advanced,
1105 empathy_account_widget_handle_params (self,
1106 "entry_published", "published-name",
1107 "entry_nickname", "nickname",
1108 "entry_first_name", "first-name",
1109 "entry_last_name", "last-name",
1110 "entry_email", "email",
1114 if (self->priv->simple)
1115 gtk_widget_hide (expander_advanced);
1117 self->ui_details->default_focus = g_strdup ("entry_first_name");
1123 account_widget_build_irc (EmpathyAccountWidget *self,
1124 const char *filename)
1128 empathy_account_settings_set_regex (self->priv->settings, "account",
1131 if (self->priv->simple)
1133 self->priv->irc_network_chooser = empathy_account_widget_irc_build_simple
1134 (self, filename, &box);
1138 self->priv->irc_network_chooser = empathy_account_widget_irc_build (self,
1139 filename, &self->priv->grid_common_settings, &box);
1146 account_widget_build_sip (EmpathyAccountWidget *self,
1147 const char *filename)
1151 box = empathy_account_widget_sip_build (self, filename,
1152 &self->priv->grid_common_settings);
1154 if (self->priv->simple)
1156 self->priv->remember_password_widget = GTK_WIDGET (
1157 gtk_builder_get_object (self->ui_details->gui,
1158 "remember_password_simple"));
1162 self->priv->remember_password_widget = GTK_WIDGET (
1163 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1170 account_widget_build_msn (EmpathyAccountWidget *self,
1171 const char *filename)
1175 empathy_account_settings_set_regex (self->priv->settings, "account",
1178 if (self->priv->simple)
1180 self->ui_details->gui = empathy_builder_get_file (filename,
1181 "vbox_msn_simple", &box,
1184 empathy_account_widget_handle_params (self,
1185 "entry_id_simple", "account",
1186 "entry_password_simple", "password",
1189 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1191 self->priv->remember_password_widget = GTK_WIDGET (
1192 gtk_builder_get_object (self->ui_details->gui,
1193 "remember_password_simple"));
1197 self->ui_details->gui = empathy_builder_get_file (filename,
1198 "grid_common_msn_settings", &self->priv->grid_common_settings,
1199 "vbox_msn_settings", &box,
1202 empathy_account_widget_handle_params (self,
1203 "entry_id", "account",
1204 "entry_password", "password",
1205 "entry_server", "server",
1206 "spinbutton_port", "port",
1209 self->ui_details->default_focus = g_strdup ("entry_id");
1211 self->priv->remember_password_widget = GTK_WIDGET (
1212 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1219 suffix_id_widget_changed_cb (GtkWidget *entry,
1220 EmpathyAccountWidget *self)
1224 g_assert (self->priv->jid_suffix != NULL);
1226 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1228 account = empathy_account_settings_dup_string (self->priv->settings,
1231 if (!EMP_STR_EMPTY (account) &&
1232 !g_str_has_suffix (account, self->priv->jid_suffix))
1236 tmp = g_strdup_printf ("%s%s", account, self->priv->jid_suffix);
1238 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1240 empathy_account_settings_set (self->priv->settings, "account",
1241 g_variant_new_string (tmp));
1245 empathy_account_widget_changed (self);
1251 remove_jid_suffix (EmpathyAccountWidget *self,
1254 g_assert (self->priv->jid_suffix != NULL);
1256 if (!g_str_has_suffix (str, self->priv->jid_suffix))
1257 return g_strdup (str);
1259 return g_strndup (str, strlen (str) - strlen (self->priv->jid_suffix));
1263 setup_id_widget_with_suffix (EmpathyAccountWidget *self,
1265 const gchar *suffix)
1269 g_object_set_data_full (G_OBJECT (widget), "param_name",
1270 g_strdup ("account"), g_free);
1272 g_assert (self->priv->jid_suffix == NULL);
1273 self->priv->jid_suffix = g_strdup (suffix);
1275 str = empathy_account_settings_dup_string (self->priv->settings, "account");
1280 tmp = remove_jid_suffix (self, str);
1281 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1286 self->priv->param_account_widget = widget;
1288 g_signal_connect (widget, "changed",
1289 G_CALLBACK (suffix_id_widget_changed_cb), self);
1293 account_widget_get_service (EmpathyAccountWidget *self)
1295 const gchar *icon_name, *service;
1297 icon_name = empathy_account_settings_get_icon_name (self->priv->settings);
1298 service = empathy_account_settings_get_service (self->priv->settings);
1300 /* Previous versions of Empathy didn't set the Service property on Facebook
1301 * and gtalk accounts, so we check using the icon name as well. */
1302 if (!tp_strdiff (icon_name, "im-google-talk") ||
1303 !tp_strdiff (service, "google-talk"))
1304 return GTALK_SERVICE;
1306 if (!tp_strdiff (icon_name, "im-facebook") ||
1307 !tp_strdiff (service, "facebook"))
1308 return FACEBOOK_SERVICE;
1314 account_widget_build_jabber (EmpathyAccountWidget *self,
1315 const char *filename)
1317 GtkWidget *spinbutton_port;
1318 GtkWidget *checkbutton_ssl;
1319 GtkWidget *label_id, *label_password;
1320 GtkWidget *label_id_create, *label_password_create;
1321 GtkWidget *label_example_fb;
1322 GtkWidget *label_example;
1323 GtkWidget *expander_advanced;
1324 GtkWidget *entry_id;
1328 service = account_widget_get_service (self);
1330 empathy_account_settings_set_regex (self->priv->settings, "account",
1331 ACCOUNT_REGEX_JABBER);
1333 if (self->priv->simple && service == NO_SERVICE)
1335 /* Simple widget for XMPP */
1336 self->ui_details->gui = empathy_builder_get_file (filename,
1337 "vbox_jabber_simple", &box,
1338 "label_id_simple", &label_id,
1339 "label_id_create", &label_id_create,
1340 "label_password_simple", &label_password,
1341 "label_password_create", &label_password_create,
1344 if (empathy_account_settings_get_boolean (self->priv->settings,
1347 gtk_widget_hide (label_id);
1348 gtk_widget_hide (label_password);
1349 gtk_widget_show (label_id_create);
1350 gtk_widget_show (label_password_create);
1353 empathy_account_widget_handle_params (self,
1354 "entry_id_simple", "account",
1355 "entry_password_simple", "password",
1358 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1360 self->priv->remember_password_widget = GTK_WIDGET (
1361 gtk_builder_get_object (self->ui_details->gui,
1362 "remember_password_simple"));
1364 else if (self->priv->simple && service == GTALK_SERVICE)
1366 /* Simple widget for Google Talk */
1367 self->ui_details->gui = empathy_builder_get_file (filename,
1368 "vbox_gtalk_simple", &box,
1371 empathy_account_widget_handle_params (self,
1372 "entry_id_g_simple", "account",
1373 "entry_password_g_simple", "password",
1376 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1378 self->priv->remember_password_widget = GTK_WIDGET (
1379 gtk_builder_get_object (self->ui_details->gui,
1380 "remember_password_g_simple"));
1382 else if (self->priv->simple && service == FACEBOOK_SERVICE)
1384 /* Simple widget for Facebook */
1385 self->ui_details->gui = empathy_builder_get_file (filename,
1386 "vbox_fb_simple", &box,
1387 "entry_id_fb_simple", &entry_id,
1390 empathy_account_widget_handle_params (self,
1391 "entry_password_fb_simple", "password",
1394 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1396 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1398 self->priv->remember_password_widget = GTK_WIDGET (
1399 gtk_builder_get_object (self->ui_details->gui,
1400 "remember_password_fb_simple"));
1404 ServiceInfo info = services_infos[service];
1406 /* Full widget for XMPP, Google Talk and Facebook*/
1407 self->ui_details->gui = empathy_builder_get_file (filename,
1408 "grid_common_settings", &self->priv->grid_common_settings,
1409 "vbox_jabber_settings", &box,
1410 "spinbutton_port", &spinbutton_port,
1411 "checkbutton_ssl", &checkbutton_ssl,
1412 "label_username_f_example", &label_example_fb,
1413 info.label_username_example, &label_example,
1414 "expander_advanced", &expander_advanced,
1415 "entry_id", &entry_id,
1416 "label_id", &label_id,
1419 empathy_account_widget_handle_params (self,
1420 "entry_password", "password",
1421 "entry_resource", "resource",
1422 "entry_server", "server",
1423 "spinbutton_port", "port",
1424 "spinbutton_priority", "priority",
1425 "checkbutton_ssl", "old-ssl",
1426 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1427 "checkbutton_encryption", "require-encryption",
1430 if (service == FACEBOOK_SERVICE)
1432 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1434 /* Facebook special case the entry ID widget to hide the
1435 * "@chat.facebook.com" part */
1436 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1440 empathy_account_widget_setup_widget (self, entry_id, "account");
1443 self->ui_details->default_focus = g_strdup ("entry_id");
1444 self->priv->spinbutton_port = spinbutton_port;
1446 self->priv->remember_password_widget = GTK_WIDGET (
1447 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1449 g_signal_connect (checkbutton_ssl, "toggled",
1450 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1453 if (service == FACEBOOK_SERVICE)
1455 GtkContainer *parent;
1458 /* Removing the label from list of focusable widgets */
1459 parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
1460 children = gtk_container_get_children (parent);
1461 children = g_list_remove (children, label_example_fb);
1462 gtk_container_set_focus_chain (parent, children);
1463 g_list_free (children);
1466 gtk_widget_show (label_example);
1468 if (!info.show_advanced)
1469 gtk_widget_hide (expander_advanced);
1476 account_widget_build_icq (EmpathyAccountWidget *self,
1477 const char *filename)
1479 GtkWidget *spinbutton_port;
1482 empathy_account_settings_set_regex (self->priv->settings, "account",
1485 if (self->priv->simple)
1487 self->ui_details->gui = empathy_builder_get_file (filename,
1488 "vbox_icq_simple", &box,
1491 empathy_account_widget_handle_params (self,
1492 "entry_uin_simple", "account",
1493 "entry_password_simple", "password",
1496 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1498 self->priv->remember_password_widget = GTK_WIDGET (
1499 gtk_builder_get_object (self->ui_details->gui,
1500 "remember_password_simple"));
1504 self->ui_details->gui = empathy_builder_get_file (filename,
1505 "grid_common_settings", &self->priv->grid_common_settings,
1506 "vbox_icq_settings", &box,
1507 "spinbutton_port", &spinbutton_port,
1510 empathy_account_widget_handle_params (self,
1511 "entry_uin", "account",
1512 "entry_password", "password",
1513 "entry_server", "server",
1514 "spinbutton_port", "port",
1515 "entry_charset", "charset",
1518 self->ui_details->default_focus = g_strdup ("entry_uin");
1520 self->priv->remember_password_widget = GTK_WIDGET (
1521 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1528 account_widget_build_aim (EmpathyAccountWidget *self,
1529 const char *filename)
1531 GtkWidget *spinbutton_port, *box;
1533 if (self->priv->simple)
1535 self->ui_details->gui = empathy_builder_get_file (filename,
1536 "vbox_aim_simple", &box,
1539 empathy_account_widget_handle_params (self,
1540 "entry_screenname_simple", "account",
1541 "entry_password_simple", "password",
1544 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1546 self->priv->remember_password_widget = GTK_WIDGET (
1547 gtk_builder_get_object (self->ui_details->gui,
1548 "remember_password_simple"));
1552 self->ui_details->gui = empathy_builder_get_file (filename,
1553 "grid_common_settings", &self->priv->grid_common_settings,
1554 "vbox_aim_settings", &box,
1555 "spinbutton_port", &spinbutton_port,
1558 empathy_account_widget_handle_params (self,
1559 "entry_screenname", "account",
1560 "entry_password", "password",
1561 "entry_server", "server",
1562 "spinbutton_port", "port",
1565 self->ui_details->default_focus = g_strdup ("entry_screenname");
1567 self->priv->remember_password_widget = GTK_WIDGET (
1568 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1575 account_widget_build_yahoo (EmpathyAccountWidget *self,
1576 const char *filename)
1580 empathy_account_settings_set_regex (self->priv->settings, "account",
1581 ACCOUNT_REGEX_YAHOO);
1583 if (self->priv->simple)
1585 self->ui_details->gui = empathy_builder_get_file (filename,
1586 "vbox_yahoo_simple", &box,
1589 empathy_account_widget_handle_params (self,
1590 "entry_id_simple", "account",
1591 "entry_password_simple", "password",
1594 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1596 self->priv->remember_password_widget = GTK_WIDGET (
1597 gtk_builder_get_object (self->ui_details->gui,
1598 "remember_password_simple"));
1602 self->ui_details->gui = empathy_builder_get_file (filename,
1603 "grid_common_settings", &self->priv->grid_common_settings,
1604 "vbox_yahoo_settings", &box,
1607 empathy_account_widget_handle_params (self,
1608 "entry_id", "account",
1609 "entry_password", "password",
1610 "entry_locale", "room-list-locale",
1611 "entry_charset", "charset",
1612 "spinbutton_port", "port",
1613 "checkbutton_ignore_invites", "ignore-invites",
1616 self->ui_details->default_focus = g_strdup ("entry_id");
1618 self->priv->remember_password_widget = GTK_WIDGET (
1619 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1626 account_widget_build_groupwise (EmpathyAccountWidget *self,
1627 const char *filename)
1631 if (self->priv->simple)
1633 self->ui_details->gui = empathy_builder_get_file (filename,
1634 "vbox_groupwise_simple", &box,
1637 empathy_account_widget_handle_params (self,
1638 "entry_id_simple", "account",
1639 "entry_password_simple", "password",
1642 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1644 self->priv->remember_password_widget = GTK_WIDGET (
1645 gtk_builder_get_object (self->ui_details->gui,
1646 "remember_password_simple"));
1650 self->ui_details->gui = empathy_builder_get_file (filename,
1651 "grid_common_groupwise_settings", &self->priv->grid_common_settings,
1652 "vbox_groupwise_settings", &box,
1655 empathy_account_widget_handle_params (self,
1656 "entry_id", "account",
1657 "entry_password", "password",
1658 "entry_server", "server",
1659 "spinbutton_port", "port",
1662 self->ui_details->default_focus = g_strdup ("entry_id");
1664 self->priv->remember_password_widget = GTK_WIDGET (
1665 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1672 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1673 gboolean others_exist)
1675 self->priv->other_accounts_exist = others_exist;
1677 if (self->priv->creating_account)
1678 account_widget_handle_control_buttons_sensitivity (self);
1682 do_set_property (GObject *object,
1684 const GValue *value,
1687 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object);
1692 self->priv->settings = g_value_dup_object (value);
1695 self->priv->simple = g_value_get_boolean (value);
1697 case PROP_CREATING_ACCOUNT:
1698 self->priv->creating_account = g_value_get_boolean (value);
1700 case PROP_OTHER_ACCOUNTS_EXIST:
1701 empathy_account_widget_set_other_accounts_exist (
1702 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1705 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1710 do_get_property (GObject *object,
1715 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (object);
1720 g_value_set_string (value,
1721 empathy_account_settings_get_protocol (self->priv->settings));
1724 g_value_set_object (value, self->priv->settings);
1727 g_value_set_boolean (value, self->priv->simple);
1729 case PROP_CREATING_ACCOUNT:
1730 g_value_set_boolean (value, self->priv->creating_account);
1732 case PROP_OTHER_ACCOUNTS_EXIST:
1733 g_value_set_boolean (value, self->priv->other_accounts_exist);
1736 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1741 set_apply_button (EmpathyAccountWidget *self)
1745 /* We can't use the stock button as its accelerator ('A') clashes with the
1747 gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE);
1749 gtk_button_set_label (GTK_BUTTON (self->priv->apply_button), _("A_pply"));
1750 gtk_button_set_use_underline (GTK_BUTTON (self->priv->apply_button), TRUE);
1752 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1753 gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image);
1757 presence_changed_cb (TpAccountManager *manager,
1758 TpConnectionPresenceType state,
1759 const gchar *status,
1760 const gchar *message,
1761 EmpathyAccountWidget *self)
1763 if (self->priv->destroyed)
1766 if (self->priv->apply_button == NULL)
1767 /* This button doesn't exist in 'simple' mode */
1770 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1771 self->priv->creating_account)
1773 /* We are online and creating a new account, display a Login button */
1776 gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE);
1777 gtk_button_set_label (GTK_BUTTON (self->priv->apply_button),
1780 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1781 GTK_ICON_SIZE_BUTTON);
1782 gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image);
1786 /* We are offline or modifying an existing account, display
1788 set_apply_button (self);
1793 account_manager_ready_cb (GObject *source_object,
1794 GAsyncResult *result,
1797 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1798 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1799 GError *error = NULL;
1800 TpConnectionPresenceType state;
1802 if (!tp_proxy_prepare_finish (account_manager, result, &error))
1804 DEBUG ("Failed to prepare account manager: %s", error->message);
1805 g_error_free (error);
1809 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1812 /* simulate a presence change so the apply button will be changed
1814 presence_changed_cb (account_manager, state, NULL, NULL, self);
1817 g_object_unref (self);
1820 #define WIDGET(cm, proto) \
1821 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1822 account_widget_build_##proto }
1825 add_register_buttons (EmpathyAccountWidget *self,
1828 TpProtocol *protocol;
1829 GtkWidget *radiobutton_register;
1831 if (!self->priv->creating_account)
1834 protocol = empathy_account_settings_get_tp_protocol (self->priv->settings);
1835 if (protocol == NULL)
1838 if (!tp_protocol_can_register (protocol))
1841 if (account_widget_get_service (self) != NO_SERVICE)
1844 if (self->priv->simple)
1847 self->priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1848 _("This account already exists on the server"));
1849 radiobutton_register = gtk_radio_button_new_with_label (
1850 gtk_radio_button_get_group (
1851 GTK_RADIO_BUTTON (self->priv->radiobutton_reuse)),
1852 _("Create a new account on the server"));
1854 gtk_box_pack_start (GTK_BOX (self), self->priv->radiobutton_reuse, FALSE,
1856 gtk_box_pack_start (GTK_BOX (self), radiobutton_register, FALSE, FALSE, 0);
1857 gtk_box_reorder_child (GTK_BOX (self), self->priv->radiobutton_reuse, 0);
1858 gtk_box_reorder_child (GTK_BOX (self), radiobutton_register, 1);
1859 gtk_widget_show (self->priv->radiobutton_reuse);
1860 gtk_widget_show (radiobutton_register);
1864 remember_password_toggled_cb (GtkToggleButton *button,
1865 EmpathyAccountWidget *self)
1867 empathy_account_settings_set_remember_password (self->priv->settings,
1868 gtk_toggle_button_get_active (button));
1870 if (!self->priv->automatic_change)
1871 empathy_account_widget_changed (self);
1875 account_settings_password_retrieved_cb (GObject *object,
1878 EmpathyAccountWidget *self = user_data;
1881 password = empathy_account_settings_dup_string (
1882 self->priv->settings, "password");
1884 /* We have to do this so that when we call gtk_entry_set_text,
1885 * the ::changed callback doesn't think the user made the
1886 * change. This is also used in remember_password_toggled_cb. */
1887 self->priv->automatic_change = TRUE;
1889 if (password != NULL)
1891 gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget),
1895 gtk_toggle_button_set_active (
1896 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget),
1897 !EMP_STR_EMPTY (password));
1899 self->priv->automatic_change = FALSE;
1905 do_constructed (GObject *obj)
1907 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1909 const gchar *display_name, *default_display_name;
1912 const gchar *cm_name;
1913 const gchar *protocol;
1915 GtkWidget * (*func)(EmpathyAccountWidget *self, const gchar *filename);
1917 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1918 account_widget_build_salut },
1919 WIDGET (gabble, jabber),
1923 WIDGET (haze, yahoo),
1924 WIDGET (haze, groupwise),
1926 WIDGET (sofiasip, sip),
1928 const gchar *protocol, *cm_name;
1931 account = empathy_account_settings_get_account (self->priv->settings);
1933 cm_name = empathy_account_settings_get_cm (self->priv->settings);
1934 protocol = empathy_account_settings_get_protocol (self->priv->settings);
1936 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1938 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1939 !tp_strdiff (widgets[i].protocol, protocol))
1943 filename = empathy_file_lookup (widgets[i].file,
1945 box = widgets[i].func (self, filename);
1952 if (i == G_N_ELEMENTS (widgets))
1954 gchar *filename = empathy_file_lookup (
1955 "empathy-account-widget-generic.ui", "libempathy-gtk");
1956 box = account_widget_build_generic (self, filename);
1960 gtk_container_add (GTK_CONTAINER (self), box);
1962 /* handle default focus */
1963 if (self->ui_details->default_focus != NULL)
1965 GObject *default_focus_entry;
1967 default_focus_entry = gtk_builder_get_object
1968 (self->ui_details->gui, self->ui_details->default_focus);
1969 g_signal_connect (default_focus_entry, "realize",
1970 G_CALLBACK (gtk_widget_grab_focus),
1974 /* remember password */
1975 if (self->priv->param_password_widget != NULL
1976 && self->priv->remember_password_widget != NULL
1977 && empathy_account_settings_supports_sasl (self->priv->settings))
1979 if (self->priv->simple)
1981 gtk_toggle_button_set_active (
1982 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), TRUE);
1988 password = empathy_account_settings_dup_string (self->priv->settings,
1991 /* FIXME: we should enable this checkbox only if the password is
1992 * stored for good in the password storage, not only for the session
1994 gtk_toggle_button_set_active (
1995 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget),
1996 !EMP_STR_EMPTY (password));
1998 /* The password might not have been retrieved from the
1999 * keyring yet. We should update the remember password
2000 * toggle button and the password entry when/if it is. */
2001 tp_g_signal_connect_object (self->priv->settings,
2002 "password-retrieved",
2003 G_CALLBACK (account_settings_password_retrieved_cb), self, 0);
2008 g_signal_connect (self->priv->remember_password_widget, "toggled",
2009 G_CALLBACK (remember_password_toggled_cb), self);
2011 self->priv->automatic_change = TRUE;
2012 remember_password_toggled_cb (
2013 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), self);
2014 self->priv->automatic_change = FALSE;
2016 else if (self->priv->remember_password_widget != NULL
2017 && !empathy_account_settings_supports_sasl (self->priv->settings))
2019 gtk_widget_set_visible (self->priv->remember_password_widget, FALSE);
2020 empathy_account_settings_set_remember_password (self->priv->settings,
2024 /* dup and init the account-manager */
2025 self->priv->account_manager = tp_account_manager_dup ();
2027 g_object_ref (self);
2028 tp_proxy_prepare_async (self->priv->account_manager, NULL,
2029 account_manager_ready_cb, self);
2031 /* handle apply and cancel button */
2032 self->priv->hbox_buttons = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2034 gtk_box_set_homogeneous (GTK_BOX (self->priv->hbox_buttons), TRUE);
2036 self->priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
2038 self->priv->apply_button = gtk_button_new ();
2039 set_apply_button (self);
2041 /* We'll change this button to a "Log in" one if we are creating a new
2042 * account and are connected. */
2043 tp_g_signal_connect_object (self->priv->account_manager,
2044 "most-available-presence-changed",
2045 G_CALLBACK (presence_changed_cb), obj, 0);
2047 gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons),
2048 self->priv->apply_button, TRUE, TRUE, 3);
2049 gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons),
2050 self->priv->cancel_button, TRUE, TRUE, 3);
2052 gtk_box_pack_end (GTK_BOX (self), self->priv->hbox_buttons, FALSE,
2055 g_signal_connect (self->priv->cancel_button, "clicked",
2056 G_CALLBACK (account_widget_cancel_clicked_cb),
2058 g_signal_connect (self->priv->apply_button, "clicked",
2059 G_CALLBACK (account_widget_apply_clicked_cb),
2061 gtk_widget_show_all (self->priv->hbox_buttons);
2063 if (self->priv->creating_account)
2064 /* When creating an account, the user might have nothing to enter.
2065 * That means that no control interaction might occur,
2066 * so we update the control button sensitivity manually.
2068 account_widget_handle_control_buttons_sensitivity (self);
2070 account_widget_set_control_buttons_sensitivity (self, FALSE);
2072 add_register_buttons (self, account);
2074 g_clear_object (&self->ui_details->gui);
2076 display_name = empathy_account_settings_get_display_name (
2077 self->priv->settings);
2078 default_display_name = empathy_account_widget_get_default_display_name (self);
2080 if (tp_strdiff (display_name, default_display_name) &&
2081 !self->priv->creating_account)
2083 /* The display name of the account is not the one that we'd assign by
2084 * default; assume that the user changed it manually */
2085 g_object_set (self->priv->settings, "display-name-overridden", TRUE,
2091 do_dispose (GObject *obj)
2093 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2095 g_clear_object (&self->priv->settings);
2096 g_clear_object (&self->priv->account_manager);
2098 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
2099 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
2103 do_finalize (GObject *obj)
2105 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2107 g_free (self->ui_details->default_focus);
2108 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
2110 g_free (self->priv->jid_suffix);
2112 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
2113 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
2117 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
2119 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2120 GParamSpec *param_spec;
2122 oclass->get_property = do_get_property;
2123 oclass->set_property = do_set_property;
2124 oclass->constructed = do_constructed;
2125 oclass->dispose = do_dispose;
2126 oclass->finalize = do_finalize;
2128 param_spec = g_param_spec_string ("protocol",
2129 "protocol", "The protocol of the account",
2131 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2132 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2134 param_spec = g_param_spec_object ("settings",
2135 "settings", "The settings of the account",
2136 EMPATHY_TYPE_ACCOUNT_SETTINGS,
2137 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2138 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2140 param_spec = g_param_spec_boolean ("simple",
2141 "simple", "Whether the account widget is a simple or an advanced one",
2143 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2144 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2146 param_spec = g_param_spec_boolean ("creating-account",
2148 "TRUE if we're creating an account, FALSE if we're modifying it",
2150 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2151 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2153 param_spec = g_param_spec_boolean ("other-accounts-exist",
2154 "other-accounts-exist",
2155 "TRUE if there are any other accounts (even if this isn't yet saved)",
2157 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2158 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2161 signals[HANDLE_APPLY] =
2162 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2163 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2164 g_cclosure_marshal_generic,
2168 /* This signal is emitted when an account has been created and enabled. */
2169 signals[ACCOUNT_CREATED] =
2170 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2171 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2172 g_cclosure_marshal_generic,
2176 signals[CANCELLED] =
2177 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2178 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2179 g_cclosure_marshal_generic,
2184 g_signal_new ("close", G_TYPE_FROM_CLASS (klass),
2185 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2186 g_cclosure_marshal_VOID__INT,
2190 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
2194 empathy_account_widget_init (EmpathyAccountWidget *self)
2196 self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
2197 EmpathyAccountWidgetPriv);
2199 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
2202 /* public methods */
2205 empathy_account_widget_discard_pending_changes (EmpathyAccountWidget *self)
2207 empathy_account_settings_discard_changes (self->priv->settings);
2208 self->priv->contains_pending_changes = FALSE;
2212 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *self)
2214 return self->priv->contains_pending_changes;
2218 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
2219 const gchar *first_widget,
2224 va_start (args, first_widget);
2225 account_widget_handle_params_valist (self, first_widget, args);
2229 EmpathyAccountWidget *
2230 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
2233 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
2235 return g_object_new (EMPATHY_TYPE_ACCOUNT_WIDGET,
2236 "orientation", GTK_ORIENTATION_VERTICAL,
2237 "settings", settings,
2240 empathy_account_settings_get_account (settings) == NULL,
2245 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
2248 const gchar *protocol, *p;
2249 gchar *default_display_name;
2252 login_id = empathy_account_settings_dup_string (self->priv->settings,
2254 protocol = empathy_account_settings_get_protocol (self->priv->settings);
2255 service = account_widget_get_service (self);
2257 if (login_id != NULL)
2259 /* TODO: this should be done in empathy-account-widget-irc */
2260 if (!tp_strdiff (protocol, "irc"))
2262 EmpathyIrcNetwork *network;
2264 network = empathy_irc_network_chooser_get_network (
2265 self->priv->irc_network_chooser);
2266 g_assert (network != NULL);
2268 /* To translators: The first parameter is the login id and the
2269 * second one is the network. The resulting string will be something
2270 * like: "MyUserName on freenode".
2271 * You should reverse the order of these arguments if the
2272 * server should come before the login id in your locale.*/
2273 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2274 login_id, empathy_irc_network_get_name (network));
2276 else if (service == FACEBOOK_SERVICE && self->priv->jid_suffix != NULL)
2280 tmp = remove_jid_suffix (self, login_id);
2281 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2286 default_display_name = g_strdup (login_id);
2289 return default_display_name;
2292 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2295 if (protocol != NULL)
2297 /* To translators: The parameter is the protocol name. The resulting
2298 * string will be something like: "Jabber Account" */
2299 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2303 default_display_name = g_strdup (_("New account"));
2308 return default_display_name;
2311 /* Used by subclass to indicate that widget contains pending changes */
2313 empathy_account_widget_changed (EmpathyAccountWidget *self)
2315 account_widget_handle_control_buttons_sensitivity (self);
2316 self->priv->contains_pending_changes = TRUE;
2320 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2321 const gchar *account)
2323 if (self->priv->param_account_widget == NULL)
2326 gtk_entry_set_text (GTK_ENTRY (self->priv->param_account_widget), account);
2330 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2331 const gchar *account)
2333 if (self->priv->param_password_widget == NULL)
2336 gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), account);
2339 EmpathyAccountSettings *
2340 empathy_account_widget_get_settings (EmpathyAccountWidget *self)
2342 return self->priv->settings;
2346 empathy_account_widget_hide_buttons (EmpathyAccountWidget *self)
2348 gtk_widget_hide (self->priv->hbox_buttons);