2 * Copyright (C) 2006-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
21 * Martyn Russell <martyn@imendio.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
31 #include <glib/gi18n-lib.h>
34 #include <mx-gtk/mx-gtk.h>
35 #endif /* HAVE_MEEGO */
36 #include <gio/gdesktopappinfo.h>
38 #include <libempathy/empathy-utils.h>
40 #include <telepathy-glib/account.h>
41 #include <telepathy-glib/account-manager.h>
42 #include <telepathy-glib/connection-manager.h>
43 #include <telepathy-glib/util.h>
44 #include <dbus/dbus-protocol.h>
46 #include "empathy-account-widget.h"
47 #include "empathy-account-widget-private.h"
48 #include "empathy-account-widget-sip.h"
49 #include "empathy-account-widget-irc.h"
50 #include "empathy-ui-utils.h"
52 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
53 #include <libempathy/empathy-debug.h>
55 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT)
58 EmpathyAccountSettings *settings;
60 GtkWidget *table_common_settings;
61 GtkWidget *apply_button;
62 GtkWidget *cancel_button;
63 GtkWidget *entry_password;
64 GtkWidget *spinbutton_port;
65 GtkWidget *enabled_checkbox;
66 GtkWidget *radiobutton_reuse;
70 gboolean contains_pending_changes;
72 /* An EmpathyAccountWidget can be used to either create an account or
73 * modify it. When we are creating an account, this member is set to TRUE */
74 gboolean creating_account;
76 /* whether there are any other real accounts. Necessary so we know whether
77 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
78 * button should be sensitive) */
79 gboolean other_accounts_exist;
81 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
82 * embedded in this account widget can't be used any more
83 * workaround because some async callbacks can be called after the
84 * widget has been destroyed */
87 TpAccountManager *account_manager;
89 GtkWidget *param_account_widget;
90 GtkWidget *param_password_widget;
92 /* Used only for IRC accounts */
93 EmpathyIrcNetworkChooser *irc_network_chooser;
96 } EmpathyAccountWidgetPriv;
102 PROP_CREATING_ACCOUNT,
103 PROP_OTHER_ACCOUNTS_EXIST,
113 static void account_widget_apply_and_log_in (EmpathyAccountWidget *);
119 static guint signals[LAST_SIGNAL] = { 0 };
121 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
122 #define CHANGED_TIMEOUT 300
125 #define DIGITS "(["DIGIT"]+)"
126 #define ALPHA "a-zA-Z"
127 #define ALPHAS "(["ALPHA"]+)"
128 #define ALPHADIGIT ALPHA DIGIT
129 #define ALPHADIGITS "(["ALPHADIGIT"]+)"
130 #define ALPHADIGITDASH ALPHA DIGIT "-"
131 #define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
133 #define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
134 #define TOPLABEL ALPHAS"|(["ALPHA"]" ALPHADIGITDASHS "["ALPHADIGIT"])"
135 #define DOMAINLABEL ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
137 #define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
138 /* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
139 #define HOST "("HOSTNAME "|" HOSTNUMBER")"
140 /* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
141 #define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
143 /* UIN is digital according to the unofficial specification:
144 * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
145 * 5 digits minimun according to http://en.wikipedia.org/wiki/ICQ#UIN */
146 #define ICQ_USER_NAME "(["DIGIT"]{5,})"
147 /* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
148 #define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
149 #define IRC_USER_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
150 /* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
151 * We just exclude invalid characters to avoid ucschars and other redundant
153 #define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
154 /* ID is an email according to the unofficial specification:
155 * http://www.hypothetic.org/docs/msn/general/names.php */
156 #define MSN_USER_NAME EMAIL_LOCALPART
157 /* Based on the official help:
158 * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html */
159 #define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})"
161 #define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
162 #define ACCOUNT_REGEX_IRC "^"IRC_USER_NAME"$"
163 #define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@"HOST"$"
164 #define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
165 #define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
168 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
171 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
175 /* we hit this case because of the 'other-accounts-exist' property handler
176 * being called during init (before constructed()) */
177 if (priv->apply_button == NULL || priv->cancel_button == NULL)
180 gtk_widget_set_sensitive (priv->apply_button, sensitive);
181 gtk_widget_set_sensitive (priv->cancel_button,
182 (sensitive || priv->creating_account) && priv->other_accounts_exist);
186 gtk_widget_set_can_default (priv->apply_button, TRUE);
187 gtk_widget_grab_default (priv->apply_button);
193 account_widget_set_entry_highlighting (GtkEntry *entry, gboolean highlight)
198 g_return_if_fail (GTK_IS_ENTRY (entry));
200 style = gtk_widget_get_style (GTK_WIDGET (entry));
204 color = style->bg[GTK_STATE_SELECTED];
206 /* Here we take the current theme colour and add it to
207 * the colour for white and average the two. This
208 * gives a colour which is inline with the theme but
211 color.red = (color.red + (style->white).red) / 2;
212 color.green = (color.green + (style->white).green) / 2;
213 color.blue = (color.blue + (style->white).blue) / 2;
215 gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, &color);
218 gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
222 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
224 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
227 is_valid = empathy_account_settings_is_valid (priv->settings);
230 account_widget_set_control_buttons_sensitivity (self, is_valid);
232 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
236 account_widget_entry_changed_common (EmpathyAccountWidget *self,
237 GtkEntry *entry, gboolean focus)
240 const gchar *param_name;
241 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
242 gboolean prev_status;
243 gboolean curr_status;
245 str = gtk_entry_get_text (entry);
246 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
247 prev_status = empathy_account_settings_parameter_is_valid (priv->settings,
250 if (EMP_STR_EMPTY (str))
252 const gchar *value = NULL;
254 empathy_account_settings_unset (priv->settings, param_name);
258 value = empathy_account_settings_get_string (priv->settings,
260 DEBUG ("Unset %s and restore to %s", param_name, value);
261 gtk_entry_set_text (entry, value ? value : "");
266 DEBUG ("Setting %s to %s", param_name,
267 tp_strdiff (param_name, "password") ? str : "***");
268 empathy_account_settings_set_string (priv->settings, param_name, str);
271 curr_status = empathy_account_settings_parameter_is_valid (priv->settings,
273 if (curr_status != prev_status)
274 account_widget_set_entry_highlighting (entry, !curr_status);
278 account_widget_entry_changed_cb (GtkEditable *entry,
279 EmpathyAccountWidget *self)
281 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
282 empathy_account_widget_changed (self);
286 account_widget_entry_map_cb (GtkEntry *entry,
287 EmpathyAccountWidget *self)
289 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
290 const gchar *param_name;
293 /* need to initialize input highlighting */
294 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
295 is_valid = empathy_account_settings_parameter_is_valid (priv->settings,
297 account_widget_set_entry_highlighting (entry, !is_valid);
301 account_widget_int_changed_cb (GtkWidget *widget,
302 EmpathyAccountWidget *self)
304 const gchar *param_name;
306 const gchar *signature;
307 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
309 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
310 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
312 signature = empathy_account_settings_get_dbus_signature (priv->settings,
314 g_return_if_fail (signature != NULL);
316 DEBUG ("Setting %s to %d", param_name, value);
318 switch ((int)*signature)
320 case DBUS_TYPE_INT16:
321 case DBUS_TYPE_INT32:
322 empathy_account_settings_set_int32 (priv->settings, param_name, value);
324 case DBUS_TYPE_INT64:
325 empathy_account_settings_set_int64 (priv->settings, param_name, value);
327 case DBUS_TYPE_UINT16:
328 case DBUS_TYPE_UINT32:
329 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
331 case DBUS_TYPE_UINT64:
332 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
335 g_return_if_reached ();
338 empathy_account_widget_changed (self);
342 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
343 EmpathyAccountWidget *self)
346 gboolean default_value;
347 const gchar *param_name;
348 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
350 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
351 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
353 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
354 * always unset the param and set the value if different from the
356 empathy_account_settings_unset (priv->settings, param_name);
357 default_value = empathy_account_settings_get_boolean (priv->settings,
360 if (default_value == value)
362 DEBUG ("Unset %s and restore to %d", param_name, default_value);
366 DEBUG ("Setting %s to %d", param_name, value);
367 empathy_account_settings_set_boolean (priv->settings, param_name, value);
370 empathy_account_widget_changed (self);
374 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
375 EmpathyAccountWidget *self)
377 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
381 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
382 port = empathy_account_settings_get_uint32 (priv->settings, "port");
386 if (port == 5222 || port == 0)
391 if (port == 5223 || port == 0)
395 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
397 priv->contains_pending_changes = TRUE;
401 account_widget_combobox_changed_cb (GtkWidget *widget,
402 EmpathyAccountWidget *self)
408 const gchar *default_value = NULL;
409 const gchar *param_name;
410 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
412 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
415 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
416 /* the param value is stored in the first column */
417 gtk_tree_model_get (model, &iter, 0, &value, -1);
419 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
421 v = empathy_account_settings_get_default (priv->settings, param_name);
423 default_value = g_value_get_string (v);
425 if (!tp_strdiff (value, default_value))
427 DEBUG ("Unset %s and restore to %s", param_name, default_value);
428 empathy_account_settings_unset (priv->settings, param_name);
432 DEBUG ("Setting %s to %s", param_name, value);
433 empathy_account_settings_set_string (priv->settings, param_name, value);
436 empathy_account_widget_changed (self);
440 clear_icon_released_cb (GtkEntry *entry,
441 GtkEntryIconPosition icon_pos,
443 EmpathyAccountWidget *self)
445 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
446 const gchar *param_name;
448 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
450 DEBUG ("Unset %s", param_name);
451 empathy_account_settings_unset (priv->settings, param_name);
452 gtk_entry_set_text (entry, "");
454 empathy_account_widget_changed (self);
458 password_entry_changed_cb (GtkEditable *entry,
459 EmpathyAccountWidget *self)
463 str = gtk_entry_get_text (GTK_ENTRY (entry));
465 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
466 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
470 password_entry_activated_cb (GtkEntry *entry,
471 EmpathyAccountWidget *self)
473 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
475 if (gtk_widget_get_sensitive (priv->apply_button))
476 account_widget_apply_and_log_in (self);
480 account_entry_activated_cb (GtkEntry *entry,
481 EmpathyAccountWidget *self)
483 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
485 if (gtk_widget_get_sensitive (priv->apply_button))
486 account_widget_apply_and_log_in (self);
490 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
492 const gchar *param_name)
494 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
496 g_object_set_data_full (G_OBJECT (widget), "param_name",
497 g_strdup (param_name), g_free);
499 if (GTK_IS_SPIN_BUTTON (widget))
502 const gchar *signature;
504 signature = empathy_account_settings_get_dbus_signature (priv->settings,
506 g_return_if_fail (signature != NULL);
508 switch ((int)*signature)
510 case DBUS_TYPE_INT16:
511 case DBUS_TYPE_INT32:
512 value = empathy_account_settings_get_int32 (priv->settings,
515 case DBUS_TYPE_INT64:
516 value = empathy_account_settings_get_int64 (priv->settings,
519 case DBUS_TYPE_UINT16:
520 case DBUS_TYPE_UINT32:
521 value = empathy_account_settings_get_uint32 (priv->settings,
524 case DBUS_TYPE_UINT64:
525 value = empathy_account_settings_get_uint64 (priv->settings,
529 g_return_if_reached ();
532 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
534 g_signal_connect (widget, "value-changed",
535 G_CALLBACK (account_widget_int_changed_cb),
538 else if (GTK_IS_ENTRY (widget))
540 const gchar *str = NULL;
542 str = empathy_account_settings_get_string (priv->settings, param_name);
543 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
545 if (!tp_strdiff (param_name, "account"))
546 priv->param_account_widget = widget;
547 else if (!tp_strdiff (param_name, "password"))
548 priv->param_password_widget = widget;
550 if (strstr (param_name, "password"))
552 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
554 /* Add 'clear' icon */
555 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
556 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
558 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
559 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
561 g_signal_connect (widget, "icon-release",
562 G_CALLBACK (clear_icon_released_cb), self);
563 g_signal_connect (widget, "changed",
564 G_CALLBACK (password_entry_changed_cb), self);
565 g_signal_connect (widget, "activate",
566 G_CALLBACK (password_entry_activated_cb), self);
568 else if (strstr (param_name, "account"))
569 g_signal_connect (widget, "activate",
570 G_CALLBACK (account_entry_activated_cb), self);
573 g_signal_connect (widget, "changed",
574 G_CALLBACK (account_widget_entry_changed_cb), self);
575 g_signal_connect (widget, "map",
576 G_CALLBACK (account_widget_entry_map_cb), self);
578 else if (GTK_IS_TOGGLE_BUTTON (widget))
580 gboolean value = FALSE;
582 value = empathy_account_settings_get_boolean (priv->settings,
584 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
586 g_signal_connect (widget, "toggled",
587 G_CALLBACK (account_widget_checkbutton_toggled_cb),
590 else if (GTK_IS_COMBO_BOX (widget))
592 /* The combo box's model has to contain the param value in its first
593 * column (as a string) */
599 str = empathy_account_settings_get_string (priv->settings, param_name);
600 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
602 valid = gtk_tree_model_get_iter_first (model, &iter);
607 gtk_tree_model_get (model, &iter, 0, &name, -1);
608 if (!tp_strdiff (name, str))
610 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
615 valid = gtk_tree_model_iter_next (model, &iter);
621 g_signal_connect (widget, "changed",
622 G_CALLBACK (account_widget_combobox_changed_cb),
627 DEBUG ("Unknown type of widget for param %s", param_name);
632 build_translated_params (void)
636 hash = g_hash_table_new (g_str_hash, g_str_equal);
637 g_hash_table_insert (hash, "account", _("Account"));
638 g_hash_table_insert (hash, "password", _("Password"));
639 g_hash_table_insert (hash, "server", _("Server"));
640 g_hash_table_insert (hash, "port", _("Port"));
646 account_widget_generic_format_param_name (const gchar *param_name)
650 static GHashTable *translated_params = NULL;
652 if (G_UNLIKELY (translated_params == NULL))
653 translated_params = build_translated_params ();
655 /* Translate most common parameters */
656 str = g_hash_table_lookup (translated_params, param_name);
658 return g_strdup (str);
660 str = g_strdup (param_name);
662 if (str && g_ascii_isalpha (str[0]))
663 str[0] = g_ascii_toupper (str[0]);
665 while ((p = strchr (str, '-')) != NULL)
667 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
670 p[1] = g_ascii_toupper (p[1]);
680 accounts_widget_generic_setup (EmpathyAccountWidget *self,
681 GtkWidget *table_common_settings,
682 GtkWidget *table_advanced_settings)
684 TpConnectionManagerParam *params, *param;
685 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
687 params = empathy_account_settings_get_tp_params (priv->settings);
689 for (param = params; param != NULL && param->name != NULL; param++)
691 GtkWidget *table_settings;
693 GtkWidget *widget = NULL;
694 gchar *param_name_formatted;
696 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
697 table_settings = table_common_settings;
698 else if (priv->simple)
701 table_settings = table_advanced_settings;
703 param_name_formatted = account_widget_generic_format_param_name
705 g_object_get (table_settings, "n-rows", &n_rows, NULL);
706 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
708 if (param->dbus_signature[0] == 's')
712 str = g_strdup_printf (_("%s:"), param_name_formatted);
713 widget = gtk_label_new (str);
714 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
717 gtk_table_attach (GTK_TABLE (table_settings),
723 gtk_widget_show (widget);
725 widget = gtk_entry_new ();
726 if (strcmp (param->name, "account") == 0)
728 g_signal_connect (widget, "realize",
729 G_CALLBACK (gtk_widget_grab_focus),
732 gtk_table_attach (GTK_TABLE (table_settings),
736 GTK_FILL | GTK_EXPAND, 0,
738 gtk_widget_show (widget);
740 /* int types: ynqiuxt. double type is 'd' */
741 else if (param->dbus_signature[0] == 'y' ||
742 param->dbus_signature[0] == 'n' ||
743 param->dbus_signature[0] == 'q' ||
744 param->dbus_signature[0] == 'i' ||
745 param->dbus_signature[0] == 'u' ||
746 param->dbus_signature[0] == 'x' ||
747 param->dbus_signature[0] == 't' ||
748 param->dbus_signature[0] == 'd')
755 switch (param->dbus_signature[0])
757 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
758 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
759 case 'q': minint = 0; maxint = G_MAXUINT16; break;
760 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
761 case 'u': minint = 0; maxint = G_MAXUINT32; break;
762 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
763 case 't': minint = 0; maxint = G_MAXUINT64; break;
764 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
766 default: g_assert_not_reached ();
769 str = g_strdup_printf (_("%s:"), param_name_formatted);
770 widget = gtk_label_new (str);
771 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
774 gtk_table_attach (GTK_TABLE (table_settings),
780 gtk_widget_show (widget);
782 widget = gtk_spin_button_new_with_range (minint, maxint, step);
783 gtk_table_attach (GTK_TABLE (table_settings),
787 GTK_FILL | GTK_EXPAND, 0,
789 gtk_widget_show (widget);
791 else if (param->dbus_signature[0] == 'b')
793 widget = gtk_check_button_new_with_label (param_name_formatted);
794 gtk_table_attach (GTK_TABLE (table_settings),
798 GTK_FILL | GTK_EXPAND, 0,
800 gtk_widget_show (widget);
804 DEBUG ("Unknown signature for param %s: %s",
805 param_name_formatted, param->dbus_signature);
809 empathy_account_widget_setup_widget (self, widget, param->name);
811 g_free (param_name_formatted);
816 account_widget_handle_params_valist (EmpathyAccountWidget *self,
817 const gchar *first_widget,
823 for (name = first_widget; name; name = va_arg (args, const gchar *))
825 const gchar *param_name;
827 param_name = va_arg (args, const gchar *);
828 object = gtk_builder_get_object (self->ui_details->gui, name);
832 g_warning ("Builder is missing object '%s'.", name);
836 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
842 account_widget_cancel_clicked_cb (GtkWidget *button,
843 EmpathyAccountWidget *self)
845 g_signal_emit (self, signals[CANCELLED], 0);
849 account_widget_account_enabled_cb (GObject *source_object,
853 GError *error = NULL;
854 TpAccount *account = TP_ACCOUNT (source_object);
855 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
856 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
858 tp_account_set_enabled_finish (account, res, &error);
862 DEBUG ("Could not enable the account: %s", error->message);
863 g_error_free (error);
867 empathy_connect_new_account (account, priv->account_manager);
870 /* unref widget - part of the workaround */
871 g_object_unref (widget);
875 account_widget_applied_cb (GObject *source_object,
879 GError *error = NULL;
881 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
882 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
883 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
885 empathy_account_settings_apply_finish (settings, res, &error);
889 DEBUG ("Could not apply changes to account: %s", error->message);
890 g_error_free (error);
894 account = empathy_account_settings_get_account (priv->settings);
898 if (priv->creating_account)
900 /* By default, when an account is created, we enable it. */
902 /* workaround to keep widget alive during async call */
903 g_object_ref (widget);
905 tp_account_set_enabled_async (account, TRUE,
906 account_widget_account_enabled_cb, widget);
907 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
909 else if (priv->enabled_checkbox != NULL)
911 gboolean enabled_checked;
915 mx_gtk_light_switch_get_active (
916 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
918 gtk_toggle_button_get_active (
919 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
920 #endif /* HAVE_MEEGO */
922 if (tp_account_is_enabled (account) && enabled_checked)
924 /* After having applied changes to a user account, we
925 * automatically reconnect it. This is done so the new
926 * information entered by the user is validated on the server. */
927 tp_account_reconnect_async (account, NULL, NULL);
932 if (!priv->destroyed)
933 account_widget_set_control_buttons_sensitivity (widget, FALSE);
935 priv->contains_pending_changes = FALSE;
937 /* unref the widget - part of the workaround */
938 g_object_unref (widget);
942 account_widget_apply_and_log_in (EmpathyAccountWidget *self)
944 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
945 gboolean display_name_overridden;
947 if (priv->radiobutton_reuse != NULL)
949 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
950 priv->radiobutton_reuse));
952 DEBUG ("Set register param: %d", !reuse);
953 empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
956 g_object_get (priv->settings,
957 "display-name-overridden", &display_name_overridden, NULL);
959 if (priv->creating_account || !display_name_overridden)
963 /* set default display name for new accounts or update if user didn't
964 * manually override it. */
965 display_name = empathy_account_widget_get_default_display_name (self);
967 empathy_account_settings_set_display_name_async (priv->settings,
968 display_name, NULL, NULL);
970 g_free (display_name);
973 /* workaround to keep widget alive during async call */
975 empathy_account_settings_apply_async (priv->settings,
976 account_widget_applied_cb, self);
980 account_widget_apply_clicked_cb (GtkWidget *button,
981 EmpathyAccountWidget *self)
983 account_widget_apply_and_log_in (self);
987 account_widget_setup_generic (EmpathyAccountWidget *self)
989 GtkWidget *table_common_settings;
990 GtkWidget *table_advanced_settings;
992 table_common_settings = GTK_WIDGET (gtk_builder_get_object
993 (self->ui_details->gui, "table_common_settings"));
994 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
995 (self->ui_details->gui, "table_advanced_settings"));
997 accounts_widget_generic_setup (self, table_common_settings,
998 table_advanced_settings);
1000 g_object_unref (self->ui_details->gui);
1004 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
1008 EmpathyAccountWidget *self = user_data;
1009 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1011 if (empathy_account_settings_is_ready (priv->settings))
1012 account_widget_setup_generic (self);
1016 account_widget_build_generic (EmpathyAccountWidget *self,
1017 const char *filename)
1019 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1020 GtkWidget *expander_advanced;
1022 self->ui_details->gui = empathy_builder_get_file (filename,
1023 "table_common_settings", &priv->table_common_settings,
1024 "vbox_generic_settings", &self->ui_details->widget,
1025 "expander_advanced_settings", &expander_advanced,
1029 gtk_widget_hide (expander_advanced);
1031 g_object_ref (self->ui_details->gui);
1033 if (empathy_account_settings_is_ready (priv->settings))
1034 account_widget_setup_generic (self);
1036 g_signal_connect (priv->settings, "notify::ready",
1037 G_CALLBACK (account_widget_settings_ready_cb), self);
1041 account_widget_launch_external_clicked (GtkWidget *button,
1044 if (!tp_strdiff (tp_account_get_storage_provider (account),
1045 "com.meego.libsocialweb"))
1047 /* we know how to handle this external provider */
1048 GDesktopAppInfo *app_info;
1049 const gchar *args[3] = { NULL, };
1050 GError *error = NULL;
1052 app_info = g_desktop_app_info_new ("gnome-control-center.desktop");
1054 if (app_info == NULL)
1056 g_critical ("Could not locate 'gnome-control-center.desktop'");
1060 args[0] = g_app_info_get_commandline (G_APP_INFO (app_info));
1061 args[1] = "bisho.desktop";
1064 gdk_spawn_on_screen (gtk_widget_get_screen (button),
1065 NULL, (gchar **) args, NULL,
1066 G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
1069 g_critical ("Failed to launch editor: %s", error->message);
1070 g_clear_error (&error);
1073 g_object_unref (app_info);
1078 account_widget_build_external (EmpathyAccountWidget *self,
1079 EmpathyAccountSettings *settings)
1081 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1082 TpAccount *account = empathy_account_settings_get_account (settings);
1083 GtkWidget *bar, *widget;
1086 self->ui_details->widget = gtk_vbox_new (FALSE, 6);
1087 priv->table_common_settings = gtk_table_new (1, 2, FALSE);
1089 if (!tp_strdiff (tp_account_get_storage_provider (account),
1090 "com.meego.libsocialweb"))
1092 /* we know how to handle this external provider */
1093 str = g_strdup_printf (
1094 _("The account %s is edited via My Web Accounts."),
1095 empathy_account_settings_get_display_name (settings));
1099 str = g_strdup_printf (
1100 _("The account %s cannot be edited in Empathy."),
1101 empathy_account_settings_get_display_name (settings));
1104 widget = gtk_label_new (str);
1105 gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
1108 bar = gtk_info_bar_new ();
1109 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
1111 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))),
1113 gtk_container_set_border_width (GTK_CONTAINER (bar), 6);
1115 if (!tp_strdiff (tp_account_get_storage_provider (account),
1116 "com.meego.libsocialweb"))
1118 /* we know how to handle this external provider */
1119 widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
1120 _("Launch My Web Accounts"), RESPONSE_LAUNCH);
1122 g_signal_connect (widget, "clicked",
1123 G_CALLBACK (account_widget_launch_external_clicked), account);
1126 gtk_box_pack_start (GTK_BOX (self->ui_details->widget), bar,
1128 gtk_box_pack_start (GTK_BOX (self->ui_details->widget),
1129 priv->table_common_settings, FALSE, TRUE, 0);
1131 gtk_widget_show_all (self->ui_details->widget);
1135 account_widget_build_salut (EmpathyAccountWidget *self,
1136 const char *filename)
1138 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1139 GtkWidget *expander_advanced;
1141 self->ui_details->gui = empathy_builder_get_file (filename,
1142 "table_common_settings", &priv->table_common_settings,
1143 "vbox_salut_settings", &self->ui_details->widget,
1144 "expander_advanced_settings", &expander_advanced,
1147 empathy_account_widget_handle_params (self,
1148 "entry_published", "published-name",
1149 "entry_nickname", "nickname",
1150 "entry_first_name", "first-name",
1151 "entry_last_name", "last-name",
1152 "entry_email", "email",
1157 gtk_widget_hide (expander_advanced);
1159 self->ui_details->default_focus = g_strdup ("entry_first_name");
1163 account_widget_build_irc (EmpathyAccountWidget *self,
1164 const char *filename)
1166 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1168 empathy_account_settings_set_regex (priv->settings, "account",
1173 priv->irc_network_chooser = empathy_account_widget_irc_build_simple (self,
1178 priv->irc_network_chooser = empathy_account_widget_irc_build (self,
1179 filename, &priv->table_common_settings);
1184 account_widget_build_sip (EmpathyAccountWidget *self,
1185 const char *filename)
1187 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1188 empathy_account_widget_sip_build (self, filename,
1189 &priv->table_common_settings);
1193 account_widget_build_msn (EmpathyAccountWidget *self,
1194 const char *filename)
1196 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1198 empathy_account_settings_set_regex (priv->settings, "account",
1203 self->ui_details->gui = empathy_builder_get_file (filename,
1204 "vbox_msn_simple", &self->ui_details->widget,
1207 empathy_account_widget_handle_params (self,
1208 "entry_id_simple", "account",
1209 "entry_password_simple", "password",
1212 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1216 self->ui_details->gui = empathy_builder_get_file (filename,
1217 "table_common_msn_settings", &priv->table_common_settings,
1218 "vbox_msn_settings", &self->ui_details->widget,
1221 empathy_account_widget_handle_params (self,
1222 "entry_id", "account",
1223 "entry_password", "password",
1224 "entry_server", "server",
1225 "spinbutton_port", "port",
1228 self->ui_details->default_focus = g_strdup ("entry_id");
1233 account_widget_is_gtalk (EmpathyAccountWidget *self)
1235 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1237 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
1242 account_widget_is_facebook (EmpathyAccountWidget *self)
1244 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1246 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
1250 #define FACEBOOK_SUFFIX "@chat.facebook.com"
1253 facebook_id_widget_changed_cb (GtkWidget *entry,
1254 EmpathyAccountWidget *self)
1256 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1257 const gchar *account;
1259 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1261 account = empathy_account_settings_get_string (priv->settings, "account");
1262 if (!EMP_STR_EMPTY (account) &&
1263 !g_str_has_suffix (account, FACEBOOK_SUFFIX))
1267 tmp = g_strdup_printf ("%s%s", account, FACEBOOK_SUFFIX);
1269 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1271 empathy_account_settings_set_string (priv->settings, "account", tmp);
1275 empathy_account_widget_changed (self);
1279 remove_facebook_suffix (const gchar *str)
1281 if (!g_str_has_suffix (str, FACEBOOK_SUFFIX))
1282 return g_strdup (str);
1284 return g_strndup (str, strlen (str) - strlen (FACEBOOK_SUFFIX));
1288 setup_facebook_id_widget (EmpathyAccountWidget *self,
1291 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1292 const gchar *str = NULL;
1294 g_object_set_data_full (G_OBJECT (widget), "param_name",
1295 g_strdup ("account"), g_free);
1297 str = empathy_account_settings_get_string (priv->settings, "account");
1302 tmp = remove_facebook_suffix (str);
1303 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1307 priv->param_account_widget = widget;
1309 g_signal_connect (widget, "changed",
1310 G_CALLBACK (facebook_id_widget_changed_cb), self);
1314 account_widget_build_jabber (EmpathyAccountWidget *self,
1315 const char *filename)
1317 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1318 GtkWidget *spinbutton_port;
1319 GtkWidget *checkbutton_ssl;
1320 GtkWidget *label_id, *label_password;
1321 GtkWidget *label_id_create, *label_password_create;
1322 GtkWidget *label_example_gtalk, *label_example_jabber, *label_example_fb;
1323 gboolean is_gtalk, is_facebook;
1324 GtkWidget *expander_advanced;
1325 GtkWidget *entry_id;
1327 is_gtalk = account_widget_is_gtalk (self);
1328 is_facebook = account_widget_is_facebook (self);
1330 empathy_account_settings_set_regex (priv->settings, "account",
1331 ACCOUNT_REGEX_JABBER);
1333 if (priv->simple && !is_gtalk && !is_facebook)
1335 /* Simple widget for XMPP */
1336 self->ui_details->gui = empathy_builder_get_file (filename,
1337 "vbox_jabber_simple", &self->ui_details->widget,
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 (priv->settings, "register"))
1346 gtk_widget_hide (label_id);
1347 gtk_widget_hide (label_password);
1348 gtk_widget_show (label_id_create);
1349 gtk_widget_show (label_password_create);
1352 empathy_account_widget_handle_params (self,
1353 "entry_id_simple", "account",
1354 "entry_password_simple", "password",
1357 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1359 else if (priv->simple && is_gtalk)
1361 /* Simple widget for Google Talk */
1362 self->ui_details->gui = empathy_builder_get_file (filename,
1363 "vbox_gtalk_simple", &self->ui_details->widget,
1366 empathy_account_widget_handle_params (self,
1367 "entry_id_g_simple", "account",
1368 "entry_password_g_simple", "password",
1371 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1373 else if (priv->simple && is_facebook)
1375 /* Simple widget for Facebook */
1376 self->ui_details->gui = empathy_builder_get_file (filename,
1377 "vbox_fb_simple", &self->ui_details->widget,
1378 "entry_id_fb_simple", &entry_id,
1381 empathy_account_widget_handle_params (self,
1382 "entry_password_fb_simple", "password",
1385 setup_facebook_id_widget (self, entry_id);
1387 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1391 /* Full widget for XMPP, Google Talk and Facebook*/
1392 self->ui_details->gui = empathy_builder_get_file (filename,
1393 "table_common_settings", &priv->table_common_settings,
1394 "vbox_jabber_settings", &self->ui_details->widget,
1395 "spinbutton_port", &spinbutton_port,
1396 "checkbutton_ssl", &checkbutton_ssl,
1397 "label_username_example", &label_example_jabber,
1398 "label_username_g_example", &label_example_gtalk,
1399 "label_username_f_example", &label_example_fb,
1400 "expander_advanced", &expander_advanced,
1401 "entry_id", &entry_id,
1402 "label_id", &label_id,
1405 empathy_account_widget_handle_params (self,
1406 "entry_password", "password",
1407 "entry_resource", "resource",
1408 "entry_server", "server",
1409 "spinbutton_port", "port",
1410 "spinbutton_priority", "priority",
1411 "checkbutton_ssl", "old-ssl",
1412 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1413 "checkbutton_encryption", "require-encryption",
1418 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1420 /* Facebook special case the entry ID widget to hide the
1421 * "@chat.facebook.com" part */
1422 setup_facebook_id_widget (self, entry_id);
1426 empathy_account_widget_setup_widget (self, entry_id, "account");
1429 self->ui_details->default_focus = g_strdup ("entry_id");
1430 priv->spinbutton_port = spinbutton_port;
1432 g_signal_connect (checkbutton_ssl, "toggled",
1433 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1438 gtk_widget_hide (label_example_jabber);
1439 gtk_widget_show (label_example_gtalk);
1441 else if (is_facebook)
1443 GtkContainer *parent;
1446 gtk_widget_hide (label_example_jabber);
1448 /* Removing the label from list of focusable widgets */
1449 parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
1450 children = gtk_container_get_children (parent);
1451 children = g_list_remove (children, label_example_fb);
1452 gtk_container_set_focus_chain (parent, children);
1453 g_list_free (children);
1455 gtk_widget_show (label_example_fb);
1456 gtk_widget_hide (expander_advanced);
1462 account_widget_build_icq (EmpathyAccountWidget *self,
1463 const char *filename)
1465 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1466 GtkWidget *spinbutton_port;
1468 empathy_account_settings_set_regex (priv->settings, "account",
1473 self->ui_details->gui = empathy_builder_get_file (filename,
1474 "vbox_icq_simple", &self->ui_details->widget,
1477 empathy_account_widget_handle_params (self,
1478 "entry_uin_simple", "account",
1479 "entry_password_simple", "password",
1482 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1486 self->ui_details->gui = empathy_builder_get_file (filename,
1487 "table_common_settings", &priv->table_common_settings,
1488 "vbox_icq_settings", &self->ui_details->widget,
1489 "spinbutton_port", &spinbutton_port,
1492 empathy_account_widget_handle_params (self,
1493 "entry_uin", "account",
1494 "entry_password", "password",
1495 "entry_server", "server",
1496 "spinbutton_port", "port",
1497 "entry_charset", "charset",
1500 self->ui_details->default_focus = g_strdup ("entry_uin");
1505 account_widget_build_aim (EmpathyAccountWidget *self,
1506 const char *filename)
1508 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1509 GtkWidget *spinbutton_port;
1513 self->ui_details->gui = empathy_builder_get_file (filename,
1514 "vbox_aim_simple", &self->ui_details->widget,
1517 empathy_account_widget_handle_params (self,
1518 "entry_screenname_simple", "account",
1519 "entry_password_simple", "password",
1522 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1526 self->ui_details->gui = empathy_builder_get_file (filename,
1527 "table_common_settings", &priv->table_common_settings,
1528 "vbox_aim_settings", &self->ui_details->widget,
1529 "spinbutton_port", &spinbutton_port,
1532 empathy_account_widget_handle_params (self,
1533 "entry_screenname", "account",
1534 "entry_password", "password",
1535 "entry_server", "server",
1536 "spinbutton_port", "port",
1539 self->ui_details->default_focus = g_strdup ("entry_screenname");
1544 account_widget_build_yahoo (EmpathyAccountWidget *self,
1545 const char *filename)
1547 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1549 empathy_account_settings_set_regex (priv->settings, "account",
1550 ACCOUNT_REGEX_YAHOO);
1554 self->ui_details->gui = empathy_builder_get_file (filename,
1555 "vbox_yahoo_simple", &self->ui_details->widget,
1558 empathy_account_widget_handle_params (self,
1559 "entry_id_simple", "account",
1560 "entry_password_simple", "password",
1563 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1567 self->ui_details->gui = empathy_builder_get_file (filename,
1568 "table_common_settings", &priv->table_common_settings,
1569 "vbox_yahoo_settings", &self->ui_details->widget,
1572 empathy_account_widget_handle_params (self,
1573 "entry_id", "account",
1574 "entry_password", "password",
1575 "entry_server", "server",
1576 "entry_locale", "room-list-locale",
1577 "entry_charset", "charset",
1578 "spinbutton_port", "port",
1579 "checkbutton_ignore_invites", "ignore-invites",
1582 self->ui_details->default_focus = g_strdup ("entry_id");
1587 account_widget_build_groupwise (EmpathyAccountWidget *self,
1588 const char *filename)
1590 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1594 self->ui_details->gui = empathy_builder_get_file (filename,
1595 "vbox_groupwise_simple", &self->ui_details->widget,
1598 empathy_account_widget_handle_params (self,
1599 "entry_id_simple", "account",
1600 "entry_password_simple", "password",
1603 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1607 self->ui_details->gui = empathy_builder_get_file (filename,
1608 "table_common_groupwise_settings", &priv->table_common_settings,
1609 "vbox_groupwise_settings", &self->ui_details->widget,
1612 empathy_account_widget_handle_params (self,
1613 "entry_id", "account",
1614 "entry_password", "password",
1615 "entry_server", "server",
1616 "spinbutton_port", "port",
1619 self->ui_details->default_focus = g_strdup ("entry_id");
1624 account_widget_destroy_cb (GtkWidget *widget,
1625 EmpathyAccountWidget *self)
1627 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1628 /* set the destroyed flag - workaround */
1629 priv->destroyed = TRUE;
1631 g_object_unref (self);
1635 empathy_account_widget_enabled_cb (TpAccount *account,
1639 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1640 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1641 gboolean enabled = tp_account_is_enabled (account);
1643 if (priv->enabled_checkbox != NULL)
1646 mx_gtk_light_switch_set_active (
1647 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1650 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1652 #endif /* HAVE_MEEGO */
1658 account_widget_switch_flipped_cb (MxGtkLightSwitch *sw,
1662 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1664 #endif /* HAVE_MEEGO */
1666 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1671 state = gtk_toggle_button_get_active (toggle_button);
1672 #endif /* HAVE_MEEGO */
1674 account = empathy_account_settings_get_account (priv->settings);
1676 /* Enable the account according to the value of the "Enabled" checkbox */
1677 /* workaround to keep widget alive during async call */
1678 g_object_ref (user_data);
1679 tp_account_set_enabled_async (account, state,
1680 account_widget_account_enabled_cb, user_data);
1684 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1685 gboolean others_exist)
1687 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1689 priv->other_accounts_exist = others_exist;
1691 if (priv->creating_account)
1692 account_widget_handle_control_buttons_sensitivity (self);
1696 do_set_property (GObject *object,
1698 const GValue *value,
1701 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1706 priv->settings = g_value_dup_object (value);
1709 priv->simple = g_value_get_boolean (value);
1711 case PROP_CREATING_ACCOUNT:
1712 priv->creating_account = g_value_get_boolean (value);
1714 case PROP_OTHER_ACCOUNTS_EXIST:
1715 empathy_account_widget_set_other_accounts_exist (
1716 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1719 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1724 do_get_property (GObject *object,
1729 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1734 g_value_set_string (value,
1735 empathy_account_settings_get_protocol (priv->settings));
1738 g_value_set_object (value, priv->settings);
1741 g_value_set_boolean (value, priv->simple);
1743 case PROP_CREATING_ACCOUNT:
1744 g_value_set_boolean (value, priv->creating_account);
1746 case PROP_OTHER_ACCOUNTS_EXIST:
1747 g_value_set_boolean (value, priv->other_accounts_exist);
1750 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1755 set_apply_button (EmpathyAccountWidget *self)
1757 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1760 /* We can't use the stock button as its accelerator ('A') clashes with the
1762 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1764 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("A_pply"));
1765 gtk_button_set_use_underline (GTK_BUTTON (priv->apply_button), TRUE);
1767 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1768 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1772 presence_changed_cb (TpAccountManager *manager,
1773 TpConnectionPresenceType state,
1774 const gchar *status,
1775 const gchar *message,
1776 EmpathyAccountWidget *self)
1778 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1780 if (priv->destroyed)
1783 if (priv->apply_button == NULL)
1784 /* This button doesn't exist in 'simple' mode */
1787 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1788 priv->creating_account)
1790 /* We are online and creating a new account, display a Login button */
1793 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1794 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1796 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1797 GTK_ICON_SIZE_BUTTON);
1798 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1802 /* We are offline or modifying an existing account, display
1804 set_apply_button (self);
1809 account_manager_ready_cb (GObject *source_object,
1810 GAsyncResult *result,
1813 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1814 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1815 GError *error = NULL;
1816 TpConnectionPresenceType state;
1818 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1820 DEBUG ("Failed to prepare account manager: %s", error->message);
1821 g_error_free (error);
1825 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1828 /* simulate a presence change so the apply button will be changed
1830 presence_changed_cb (account_manager, state, NULL, NULL, self);
1833 g_object_unref (self);
1836 #define WIDGET(cm, proto) \
1837 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1838 account_widget_build_##proto }
1841 add_enable_checkbox (EmpathyAccountWidget *self,
1844 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1848 GtkWidget *vbox = self->ui_details->widget;
1849 #endif /* HAVE_MEEGO */
1850 guint nb_rows, nb_columns;
1851 gboolean is_enabled;
1853 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1854 if (priv->creating_account || priv->table_common_settings == NULL)
1857 is_enabled = tp_account_is_enabled (account);
1860 w = gtk_label_new (_("Account:"));
1861 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1863 priv->enabled_checkbox = mx_gtk_light_switch_new ();
1865 mx_gtk_light_switch_set_active (
1866 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1868 gtk_widget_show (w);
1870 priv->enabled_checkbox =
1871 gtk_check_button_new_with_mnemonic (_("_Enabled"));
1873 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1875 #endif /* HAVE_MEEGO */
1877 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1878 "n-columns", &nb_columns, NULL);
1880 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1884 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1886 0, 1, nb_rows - 1, nb_rows,
1888 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1889 priv->enabled_checkbox,
1890 1, nb_columns, nb_rows - 1, nb_rows,
1891 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1893 gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
1894 gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
1895 #endif /* HAVE_MEEGO */
1897 gtk_widget_show (priv->enabled_checkbox);
1900 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1901 G_CALLBACK (account_widget_switch_flipped_cb), self);
1903 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
1904 G_CALLBACK (account_widget_enabled_toggled_cb), self);
1905 #endif /* HAVE_MEEGO */
1909 /* Meego doesn't support registration */
1911 add_register_buttons (EmpathyAccountWidget *self,
1914 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1915 const TpConnectionManagerProtocol *protocol;
1916 GtkWidget *radiobutton_register;
1917 GtkWidget *vbox = self->ui_details->widget;
1919 if (!priv->creating_account)
1922 protocol = empathy_account_settings_get_tp_protocol (priv->settings);
1923 if (protocol == NULL)
1926 if (!tp_connection_manager_protocol_can_register (protocol))
1929 if (account_widget_is_gtalk (self) || account_widget_is_facebook (self))
1935 priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1936 _("This account already exists on the server"));
1937 radiobutton_register = gtk_radio_button_new_with_label (
1938 gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
1939 _("Create a new account on the server"));
1941 gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
1942 gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
1943 gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
1944 gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
1945 gtk_widget_show (priv->radiobutton_reuse);
1946 gtk_widget_show (radiobutton_register);
1948 #endif /* HAVE_MEEGO */
1951 do_constructed (GObject *obj)
1953 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1954 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1956 TpStorageRestrictionFlags storage_restrictions;
1957 const gchar *display_name, *default_display_name;
1960 const gchar *cm_name;
1961 const gchar *protocol;
1963 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1965 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1966 account_widget_build_salut },
1967 WIDGET (gabble, jabber),
1968 WIDGET (butterfly, msn),
1971 WIDGET (haze, yahoo),
1972 WIDGET (haze, groupwise),
1974 WIDGET (sofiasip, sip),
1977 account = empathy_account_settings_get_account (priv->settings);
1979 if (account != NULL)
1980 storage_restrictions = tp_account_get_storage_restrictions (account);
1982 storage_restrictions = 0;
1984 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
1985 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
1987 DEBUG ("Account is provided by an external storage provider");
1989 account_widget_build_external (self, priv->settings);
1993 const gchar *protocol, *cm_name;
1995 cm_name = empathy_account_settings_get_cm (priv->settings);
1996 protocol = empathy_account_settings_get_protocol (priv->settings);
1998 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
2000 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
2001 !tp_strdiff (widgets[i].protocol, protocol))
2005 filename = empathy_file_lookup (widgets[i].file,
2007 widgets[i].func (self, filename);
2014 if (i == G_N_ELEMENTS (widgets))
2016 gchar *filename = empathy_file_lookup (
2017 "empathy-account-widget-generic.ui", "libempathy-gtk");
2018 account_widget_build_generic (self, filename);
2023 /* handle default focus */
2024 if (self->ui_details->default_focus != NULL)
2026 GObject *default_focus_entry;
2028 default_focus_entry = gtk_builder_get_object
2029 (self->ui_details->gui, self->ui_details->default_focus);
2030 g_signal_connect (default_focus_entry, "realize",
2031 G_CALLBACK (gtk_widget_grab_focus),
2035 /* dup and init the account-manager */
2036 priv->account_manager = tp_account_manager_dup ();
2038 g_object_ref (self);
2039 tp_account_manager_prepare_async (priv->account_manager, NULL,
2040 account_manager_ready_cb, self);
2042 /* handle apply and cancel button */
2043 if (!priv->simple &&
2044 !(storage_restrictions &
2045 TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS))
2047 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
2050 /* We can't use the stock button as its accelerator ('C') clashes with
2051 * the Close button. */
2052 priv->cancel_button = gtk_button_new ();
2053 gtk_button_set_label (GTK_BUTTON (priv->cancel_button), _("Ca_ncel"));
2054 gtk_button_set_use_underline (GTK_BUTTON (priv->cancel_button), TRUE);
2056 image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
2057 gtk_button_set_image (GTK_BUTTON (priv->cancel_button), image);
2059 priv->apply_button = gtk_button_new ();
2060 set_apply_button (self);
2062 /* We'll change this button to a "Log in" one if we are creating a new
2063 * account and are connected. */
2064 tp_g_signal_connect_object (priv->account_manager,
2065 "most-available-presence-changed",
2066 G_CALLBACK (presence_changed_cb), obj, 0);
2068 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
2070 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
2073 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
2076 g_signal_connect (priv->cancel_button, "clicked",
2077 G_CALLBACK (account_widget_cancel_clicked_cb),
2079 g_signal_connect (priv->apply_button, "clicked",
2080 G_CALLBACK (account_widget_apply_clicked_cb),
2082 gtk_widget_show_all (hbox);
2084 if (priv->creating_account)
2085 /* When creating an account, the user might have nothing to enter.
2086 * That means that no control interaction might occur,
2087 * so we update the control button sensitivity manually.
2089 account_widget_handle_control_buttons_sensitivity (self);
2091 account_widget_set_control_buttons_sensitivity (self, FALSE);
2094 if (account != NULL)
2096 g_signal_connect (account, "notify::enabled",
2097 G_CALLBACK (empathy_account_widget_enabled_cb), self);
2101 add_register_buttons (self, account);
2102 #endif /* HAVE_MEEGO */
2104 /* add the Enable checkbox to accounts that support it */
2105 if (!(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED))
2106 add_enable_checkbox (self, account);
2108 /* hook up to widget destruction to unref ourselves */
2109 g_signal_connect (self->ui_details->widget, "destroy",
2110 G_CALLBACK (account_widget_destroy_cb), self);
2112 if (self->ui_details->gui != NULL)
2114 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
2115 self->ui_details->widget);
2116 self->ui_details->gui = NULL;
2119 display_name = empathy_account_settings_get_display_name (priv->settings);
2120 default_display_name = empathy_account_widget_get_default_display_name (self);
2122 if (tp_strdiff (display_name, default_display_name) &&
2123 !priv->creating_account)
2125 /* The display name of the account is not the one that we'd assign by
2126 * default; assume that the user changed it manually */
2127 g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
2132 do_dispose (GObject *obj)
2134 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2135 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2137 if (priv->dispose_run)
2140 priv->dispose_run = TRUE;
2142 if (priv->settings != NULL)
2145 account = empathy_account_settings_get_account (priv->settings);
2147 if (account != NULL)
2149 g_signal_handlers_disconnect_by_func (account,
2150 empathy_account_widget_enabled_cb, self);
2153 g_object_unref (priv->settings);
2154 priv->settings = NULL;
2157 if (priv->account_manager != NULL)
2159 g_object_unref (priv->account_manager);
2160 priv->account_manager = NULL;
2163 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
2164 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
2168 do_finalize (GObject *obj)
2170 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2172 g_free (self->ui_details->default_focus);
2173 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
2175 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
2176 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
2180 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
2182 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2183 GParamSpec *param_spec;
2185 oclass->get_property = do_get_property;
2186 oclass->set_property = do_set_property;
2187 oclass->constructed = do_constructed;
2188 oclass->dispose = do_dispose;
2189 oclass->finalize = do_finalize;
2191 param_spec = g_param_spec_string ("protocol",
2192 "protocol", "The protocol of the account",
2194 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2195 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2197 param_spec = g_param_spec_object ("settings",
2198 "settings", "The settings of the account",
2199 EMPATHY_TYPE_ACCOUNT_SETTINGS,
2200 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2201 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2203 param_spec = g_param_spec_boolean ("simple",
2204 "simple", "Whether the account widget is a simple or an advanced one",
2206 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2207 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2209 param_spec = g_param_spec_boolean ("creating-account",
2211 "TRUE if we're creating an account, FALSE if we're modifying it",
2213 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2214 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2216 param_spec = g_param_spec_boolean ("other-accounts-exist",
2217 "other-accounts-exist",
2218 "TRUE if there are any other accounts (even if this isn't yet saved)",
2220 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2221 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2224 signals[HANDLE_APPLY] =
2225 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2226 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2227 g_cclosure_marshal_VOID__BOOLEAN,
2231 /* This signal is emitted when an account has been created and enabled. */
2232 signals[ACCOUNT_CREATED] =
2233 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2234 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2235 g_cclosure_marshal_VOID__OBJECT,
2239 signals[CANCELLED] =
2240 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2241 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2242 g_cclosure_marshal_VOID__VOID,
2246 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
2250 empathy_account_widget_init (EmpathyAccountWidget *self)
2252 EmpathyAccountWidgetPriv *priv =
2253 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
2254 EmpathyAccountWidgetPriv);
2257 priv->dispose_run = FALSE;
2259 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
2262 /* public methods */
2265 empathy_account_widget_discard_pending_changes
2266 (EmpathyAccountWidget *widget)
2268 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2270 empathy_account_settings_discard_changes (priv->settings);
2271 priv->contains_pending_changes = FALSE;
2275 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
2277 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2279 return priv->contains_pending_changes;
2283 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
2284 const gchar *first_widget,
2289 va_start (args, first_widget);
2290 account_widget_handle_params_valist (self, first_widget, args);
2295 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
2297 return widget->ui_details->widget;
2300 EmpathyAccountWidget *
2301 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
2304 EmpathyAccountWidget *self;
2306 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
2309 (EMPATHY_TYPE_ACCOUNT_WIDGET,
2310 "settings", settings, "simple", simple,
2312 empathy_account_settings_get_account (settings) == NULL,
2319 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
2321 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2322 const gchar *login_id;
2323 const gchar *protocol, *p;
2324 gchar *default_display_name;
2326 login_id = empathy_account_settings_get_string (priv->settings, "account");
2327 protocol = empathy_account_settings_get_protocol (priv->settings);
2329 if (login_id != NULL)
2331 /* TODO: this should be done in empathy-account-widget-irc */
2332 if (!tp_strdiff (protocol, "irc"))
2334 EmpathyIrcNetwork *network;
2336 network = empathy_irc_network_chooser_get_network (
2337 priv->irc_network_chooser);
2338 g_assert (network != NULL);
2340 /* To translators: The first parameter is the login id and the
2341 * second one is the network. The resulting string will be something
2342 * like: "MyUserName on freenode".
2343 * You should reverse the order of these arguments if the
2344 * server should come before the login id in your locale.*/
2345 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2346 login_id, empathy_irc_network_get_name (network));
2348 else if (account_widget_is_facebook (self))
2352 tmp = remove_facebook_suffix (login_id);
2353 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2358 default_display_name = g_strdup (login_id);
2361 return default_display_name;
2364 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2367 if (protocol != NULL)
2369 /* To translators: The parameter is the protocol name. The resulting
2370 * string will be something like: "Jabber Account" */
2371 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2375 default_display_name = g_strdup (_("New account"));
2378 return default_display_name;
2381 /* Used by subclass to indicate that widget contains pending changes */
2383 empathy_account_widget_changed (EmpathyAccountWidget *self)
2385 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2387 account_widget_handle_control_buttons_sensitivity (self);
2388 priv->contains_pending_changes = TRUE;
2392 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2393 const gchar *account)
2395 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2397 if (priv->param_account_widget == NULL)
2400 gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
2404 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2405 const gchar *account)
2407 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2409 if (priv->param_password_widget == NULL)
2412 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);