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 /* We can't grab default if the widget hasn't be packed in a
190 window = gtk_widget_get_toplevel (priv->apply_button);
191 if (window != NULL &&
192 gtk_widget_is_toplevel (window))
194 gtk_widget_set_can_default (priv->apply_button, TRUE);
195 gtk_widget_grab_default (priv->apply_button);
202 account_widget_set_entry_highlighting (GtkEntry *entry, gboolean highlight)
207 g_return_if_fail (GTK_IS_ENTRY (entry));
209 style = gtk_widget_get_style (GTK_WIDGET (entry));
213 color = style->bg[GTK_STATE_SELECTED];
215 /* Here we take the current theme colour and add it to
216 * the colour for white and average the two. This
217 * gives a colour which is inline with the theme but
220 color.red = (color.red + (style->white).red) / 2;
221 color.green = (color.green + (style->white).green) / 2;
222 color.blue = (color.blue + (style->white).blue) / 2;
224 gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, &color);
227 gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
231 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
233 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
236 is_valid = empathy_account_settings_is_valid (priv->settings);
239 account_widget_set_control_buttons_sensitivity (self, is_valid);
241 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
245 account_widget_entry_changed_common (EmpathyAccountWidget *self,
246 GtkEntry *entry, gboolean focus)
249 const gchar *param_name;
250 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
251 gboolean prev_status;
252 gboolean curr_status;
254 str = gtk_entry_get_text (entry);
255 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
256 prev_status = empathy_account_settings_parameter_is_valid (priv->settings,
259 if (EMP_STR_EMPTY (str))
261 const gchar *value = NULL;
263 empathy_account_settings_unset (priv->settings, param_name);
267 value = empathy_account_settings_get_string (priv->settings,
269 DEBUG ("Unset %s and restore to %s", param_name, value);
270 gtk_entry_set_text (entry, value ? value : "");
275 DEBUG ("Setting %s to %s", param_name,
276 tp_strdiff (param_name, "password") ? str : "***");
277 empathy_account_settings_set_string (priv->settings, param_name, str);
280 curr_status = empathy_account_settings_parameter_is_valid (priv->settings,
282 if (curr_status != prev_status)
283 account_widget_set_entry_highlighting (entry, !curr_status);
287 account_widget_entry_changed_cb (GtkEditable *entry,
288 EmpathyAccountWidget *self)
290 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
291 empathy_account_widget_changed (self);
295 account_widget_entry_map_cb (GtkEntry *entry,
296 EmpathyAccountWidget *self)
298 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
299 const gchar *param_name;
302 /* need to initialize input highlighting */
303 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
304 is_valid = empathy_account_settings_parameter_is_valid (priv->settings,
306 account_widget_set_entry_highlighting (entry, !is_valid);
310 account_widget_int_changed_cb (GtkWidget *widget,
311 EmpathyAccountWidget *self)
313 const gchar *param_name;
315 const gchar *signature;
316 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
318 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
319 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
321 signature = empathy_account_settings_get_dbus_signature (priv->settings,
323 g_return_if_fail (signature != NULL);
325 DEBUG ("Setting %s to %d", param_name, value);
327 switch ((int)*signature)
329 case DBUS_TYPE_INT16:
330 case DBUS_TYPE_INT32:
331 empathy_account_settings_set_int32 (priv->settings, param_name, value);
333 case DBUS_TYPE_INT64:
334 empathy_account_settings_set_int64 (priv->settings, param_name, value);
336 case DBUS_TYPE_UINT16:
337 case DBUS_TYPE_UINT32:
338 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
340 case DBUS_TYPE_UINT64:
341 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
344 g_return_if_reached ();
347 empathy_account_widget_changed (self);
351 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
352 EmpathyAccountWidget *self)
355 gboolean default_value;
356 const gchar *param_name;
357 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
359 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
360 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
362 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
363 * always unset the param and set the value if different from the
365 empathy_account_settings_unset (priv->settings, param_name);
366 default_value = empathy_account_settings_get_boolean (priv->settings,
369 if (default_value == value)
371 DEBUG ("Unset %s and restore to %d", param_name, default_value);
375 DEBUG ("Setting %s to %d", param_name, value);
376 empathy_account_settings_set_boolean (priv->settings, param_name, value);
379 empathy_account_widget_changed (self);
383 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
384 EmpathyAccountWidget *self)
386 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
390 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
391 port = empathy_account_settings_get_uint32 (priv->settings, "port");
395 if (port == 5222 || port == 0)
400 if (port == 5223 || port == 0)
404 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
406 priv->contains_pending_changes = TRUE;
410 account_widget_combobox_changed_cb (GtkWidget *widget,
411 EmpathyAccountWidget *self)
417 const gchar *default_value = NULL;
418 const gchar *param_name;
419 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
421 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
424 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
425 /* the param value is stored in the first column */
426 gtk_tree_model_get (model, &iter, 0, &value, -1);
428 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
430 v = empathy_account_settings_get_default (priv->settings, param_name);
432 default_value = g_value_get_string (v);
434 if (!tp_strdiff (value, default_value))
436 DEBUG ("Unset %s and restore to %s", param_name, default_value);
437 empathy_account_settings_unset (priv->settings, param_name);
441 DEBUG ("Setting %s to %s", param_name, value);
442 empathy_account_settings_set_string (priv->settings, param_name, value);
445 empathy_account_widget_changed (self);
449 clear_icon_released_cb (GtkEntry *entry,
450 GtkEntryIconPosition icon_pos,
452 EmpathyAccountWidget *self)
454 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
455 const gchar *param_name;
457 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
459 DEBUG ("Unset %s", param_name);
460 empathy_account_settings_unset (priv->settings, param_name);
461 gtk_entry_set_text (entry, "");
463 empathy_account_widget_changed (self);
467 password_entry_changed_cb (GtkEditable *entry,
468 EmpathyAccountWidget *self)
472 str = gtk_entry_get_text (GTK_ENTRY (entry));
474 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
475 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
479 password_entry_activated_cb (GtkEntry *entry,
480 EmpathyAccountWidget *self)
482 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
484 if (gtk_widget_get_sensitive (priv->apply_button))
485 account_widget_apply_and_log_in (self);
489 account_entry_activated_cb (GtkEntry *entry,
490 EmpathyAccountWidget *self)
492 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
494 if (gtk_widget_get_sensitive (priv->apply_button))
495 account_widget_apply_and_log_in (self);
499 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
501 const gchar *param_name)
503 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
505 g_object_set_data_full (G_OBJECT (widget), "param_name",
506 g_strdup (param_name), g_free);
508 if (GTK_IS_SPIN_BUTTON (widget))
511 const gchar *signature;
513 signature = empathy_account_settings_get_dbus_signature (priv->settings,
515 g_return_if_fail (signature != NULL);
517 switch ((int)*signature)
519 case DBUS_TYPE_INT16:
520 case DBUS_TYPE_INT32:
521 value = empathy_account_settings_get_int32 (priv->settings,
524 case DBUS_TYPE_INT64:
525 value = empathy_account_settings_get_int64 (priv->settings,
528 case DBUS_TYPE_UINT16:
529 case DBUS_TYPE_UINT32:
530 value = empathy_account_settings_get_uint32 (priv->settings,
533 case DBUS_TYPE_UINT64:
534 value = empathy_account_settings_get_uint64 (priv->settings,
538 g_return_if_reached ();
541 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
543 g_signal_connect (widget, "value-changed",
544 G_CALLBACK (account_widget_int_changed_cb),
547 else if (GTK_IS_ENTRY (widget))
549 const gchar *str = NULL;
551 str = empathy_account_settings_get_string (priv->settings, param_name);
552 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
554 if (!tp_strdiff (param_name, "account"))
555 priv->param_account_widget = widget;
556 else if (!tp_strdiff (param_name, "password"))
557 priv->param_password_widget = widget;
559 if (strstr (param_name, "password"))
561 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
563 /* Add 'clear' icon */
564 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
565 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
567 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
568 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
570 g_signal_connect (widget, "icon-release",
571 G_CALLBACK (clear_icon_released_cb), self);
572 g_signal_connect (widget, "changed",
573 G_CALLBACK (password_entry_changed_cb), self);
574 g_signal_connect (widget, "activate",
575 G_CALLBACK (password_entry_activated_cb), self);
577 else if (strstr (param_name, "account"))
578 g_signal_connect (widget, "activate",
579 G_CALLBACK (account_entry_activated_cb), self);
582 g_signal_connect (widget, "changed",
583 G_CALLBACK (account_widget_entry_changed_cb), self);
584 g_signal_connect (widget, "map",
585 G_CALLBACK (account_widget_entry_map_cb), self);
587 else if (GTK_IS_TOGGLE_BUTTON (widget))
589 gboolean value = FALSE;
591 value = empathy_account_settings_get_boolean (priv->settings,
593 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
595 g_signal_connect (widget, "toggled",
596 G_CALLBACK (account_widget_checkbutton_toggled_cb),
599 else if (GTK_IS_COMBO_BOX (widget))
601 /* The combo box's model has to contain the param value in its first
602 * column (as a string) */
608 str = empathy_account_settings_get_string (priv->settings, param_name);
609 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
611 valid = gtk_tree_model_get_iter_first (model, &iter);
616 gtk_tree_model_get (model, &iter, 0, &name, -1);
617 if (!tp_strdiff (name, str))
619 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
624 valid = gtk_tree_model_iter_next (model, &iter);
630 g_signal_connect (widget, "changed",
631 G_CALLBACK (account_widget_combobox_changed_cb),
636 DEBUG ("Unknown type of widget for param %s", param_name);
641 build_translated_params (void)
645 hash = g_hash_table_new (g_str_hash, g_str_equal);
646 g_hash_table_insert (hash, "account", _("Account"));
647 g_hash_table_insert (hash, "password", _("Password"));
648 g_hash_table_insert (hash, "server", _("Server"));
649 g_hash_table_insert (hash, "port", _("Port"));
655 account_widget_generic_format_param_name (const gchar *param_name)
659 static GHashTable *translated_params = NULL;
661 if (G_UNLIKELY (translated_params == NULL))
662 translated_params = build_translated_params ();
664 /* Translate most common parameters */
665 str = g_hash_table_lookup (translated_params, param_name);
667 return g_strdup (str);
669 str = g_strdup (param_name);
671 if (str && g_ascii_isalpha (str[0]))
672 str[0] = g_ascii_toupper (str[0]);
674 while ((p = strchr (str, '-')) != NULL)
676 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
679 p[1] = g_ascii_toupper (p[1]);
689 accounts_widget_generic_setup (EmpathyAccountWidget *self,
690 GtkWidget *table_common_settings,
691 GtkWidget *table_advanced_settings)
693 TpConnectionManagerParam *params, *param;
694 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
696 params = empathy_account_settings_get_tp_params (priv->settings);
698 for (param = params; param != NULL && param->name != NULL; param++)
700 GtkWidget *table_settings;
702 GtkWidget *widget = NULL;
703 gchar *param_name_formatted;
705 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
706 table_settings = table_common_settings;
707 else if (priv->simple)
710 table_settings = table_advanced_settings;
712 param_name_formatted = account_widget_generic_format_param_name
714 g_object_get (table_settings, "n-rows", &n_rows, NULL);
715 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
717 if (param->dbus_signature[0] == 's')
721 str = g_strdup_printf (_("%s:"), param_name_formatted);
722 widget = gtk_label_new (str);
723 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
726 gtk_table_attach (GTK_TABLE (table_settings),
732 gtk_widget_show (widget);
734 widget = gtk_entry_new ();
735 if (strcmp (param->name, "account") == 0)
737 g_signal_connect (widget, "realize",
738 G_CALLBACK (gtk_widget_grab_focus),
741 gtk_table_attach (GTK_TABLE (table_settings),
745 GTK_FILL | GTK_EXPAND, 0,
747 gtk_widget_show (widget);
749 /* int types: ynqiuxt. double type is 'd' */
750 else if (param->dbus_signature[0] == 'y' ||
751 param->dbus_signature[0] == 'n' ||
752 param->dbus_signature[0] == 'q' ||
753 param->dbus_signature[0] == 'i' ||
754 param->dbus_signature[0] == 'u' ||
755 param->dbus_signature[0] == 'x' ||
756 param->dbus_signature[0] == 't' ||
757 param->dbus_signature[0] == 'd')
764 switch (param->dbus_signature[0])
766 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
767 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
768 case 'q': minint = 0; maxint = G_MAXUINT16; break;
769 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
770 case 'u': minint = 0; maxint = G_MAXUINT32; break;
771 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
772 case 't': minint = 0; maxint = G_MAXUINT64; break;
773 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
775 default: g_assert_not_reached ();
778 str = g_strdup_printf (_("%s:"), param_name_formatted);
779 widget = gtk_label_new (str);
780 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
783 gtk_table_attach (GTK_TABLE (table_settings),
789 gtk_widget_show (widget);
791 widget = gtk_spin_button_new_with_range (minint, maxint, step);
792 gtk_table_attach (GTK_TABLE (table_settings),
796 GTK_FILL | GTK_EXPAND, 0,
798 gtk_widget_show (widget);
800 else if (param->dbus_signature[0] == 'b')
802 widget = gtk_check_button_new_with_label (param_name_formatted);
803 gtk_table_attach (GTK_TABLE (table_settings),
807 GTK_FILL | GTK_EXPAND, 0,
809 gtk_widget_show (widget);
813 DEBUG ("Unknown signature for param %s: %s",
814 param_name_formatted, param->dbus_signature);
818 empathy_account_widget_setup_widget (self, widget, param->name);
820 g_free (param_name_formatted);
825 account_widget_handle_params_valist (EmpathyAccountWidget *self,
826 const gchar *first_widget,
832 for (name = first_widget; name; name = va_arg (args, const gchar *))
834 const gchar *param_name;
836 param_name = va_arg (args, const gchar *);
837 object = gtk_builder_get_object (self->ui_details->gui, name);
841 g_warning ("Builder is missing object '%s'.", name);
845 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
851 account_widget_cancel_clicked_cb (GtkWidget *button,
852 EmpathyAccountWidget *self)
854 g_signal_emit (self, signals[CANCELLED], 0);
858 account_widget_account_enabled_cb (GObject *source_object,
862 GError *error = NULL;
863 TpAccount *account = TP_ACCOUNT (source_object);
864 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
865 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
867 tp_account_set_enabled_finish (account, res, &error);
871 DEBUG ("Could not enable the account: %s", error->message);
872 g_error_free (error);
876 empathy_connect_new_account (account, priv->account_manager);
879 /* unref widget - part of the workaround */
880 g_object_unref (widget);
884 account_widget_applied_cb (GObject *source_object,
888 GError *error = NULL;
890 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
891 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
892 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
894 empathy_account_settings_apply_finish (settings, res, &error);
898 DEBUG ("Could not apply changes to account: %s", error->message);
899 g_error_free (error);
903 account = empathy_account_settings_get_account (priv->settings);
907 if (priv->creating_account)
909 /* By default, when an account is created, we enable it. */
911 /* workaround to keep widget alive during async call */
912 g_object_ref (widget);
914 tp_account_set_enabled_async (account, TRUE,
915 account_widget_account_enabled_cb, widget);
916 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
918 else if (priv->enabled_checkbox != NULL)
920 gboolean enabled_checked;
924 mx_gtk_light_switch_get_active (
925 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
927 gtk_toggle_button_get_active (
928 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
929 #endif /* HAVE_MEEGO */
931 if (tp_account_is_enabled (account) && enabled_checked)
933 /* After having applied changes to a user account, we
934 * automatically reconnect it. This is done so the new
935 * information entered by the user is validated on the server. */
936 tp_account_reconnect_async (account, NULL, NULL);
941 if (!priv->destroyed)
942 account_widget_set_control_buttons_sensitivity (widget, FALSE);
944 priv->contains_pending_changes = FALSE;
946 /* unref the widget - part of the workaround */
947 g_object_unref (widget);
951 account_widget_apply_and_log_in (EmpathyAccountWidget *self)
953 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
954 gboolean display_name_overridden;
956 if (priv->radiobutton_reuse != NULL)
958 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
959 priv->radiobutton_reuse));
961 DEBUG ("Set register param: %d", !reuse);
962 empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
965 g_object_get (priv->settings,
966 "display-name-overridden", &display_name_overridden, NULL);
968 if (priv->creating_account || !display_name_overridden)
972 /* set default display name for new accounts or update if user didn't
973 * manually override it. */
974 display_name = empathy_account_widget_get_default_display_name (self);
976 empathy_account_settings_set_display_name_async (priv->settings,
977 display_name, NULL, NULL);
979 g_free (display_name);
982 /* workaround to keep widget alive during async call */
984 empathy_account_settings_apply_async (priv->settings,
985 account_widget_applied_cb, self);
989 account_widget_apply_clicked_cb (GtkWidget *button,
990 EmpathyAccountWidget *self)
992 account_widget_apply_and_log_in (self);
996 account_widget_setup_generic (EmpathyAccountWidget *self)
998 GtkWidget *table_common_settings;
999 GtkWidget *table_advanced_settings;
1001 table_common_settings = GTK_WIDGET (gtk_builder_get_object
1002 (self->ui_details->gui, "table_common_settings"));
1003 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
1004 (self->ui_details->gui, "table_advanced_settings"));
1006 accounts_widget_generic_setup (self, table_common_settings,
1007 table_advanced_settings);
1009 g_object_unref (self->ui_details->gui);
1013 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
1017 EmpathyAccountWidget *self = user_data;
1018 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1020 if (empathy_account_settings_is_ready (priv->settings))
1021 account_widget_setup_generic (self);
1025 account_widget_build_generic (EmpathyAccountWidget *self,
1026 const char *filename)
1028 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1029 GtkWidget *expander_advanced;
1031 self->ui_details->gui = empathy_builder_get_file (filename,
1032 "table_common_settings", &priv->table_common_settings,
1033 "vbox_generic_settings", &self->ui_details->widget,
1034 "expander_advanced_settings", &expander_advanced,
1038 gtk_widget_hide (expander_advanced);
1040 g_object_ref (self->ui_details->gui);
1042 if (empathy_account_settings_is_ready (priv->settings))
1043 account_widget_setup_generic (self);
1045 g_signal_connect (priv->settings, "notify::ready",
1046 G_CALLBACK (account_widget_settings_ready_cb), self);
1050 account_widget_launch_external_clicked (GtkWidget *button,
1053 if (!tp_strdiff (tp_account_get_storage_provider (account),
1054 "com.meego.libsocialweb"))
1056 /* we know how to handle this external provider */
1057 GDesktopAppInfo *app_info;
1058 const gchar *args[3] = { NULL, };
1059 GError *error = NULL;
1061 app_info = g_desktop_app_info_new ("gnome-control-center.desktop");
1063 if (app_info == NULL)
1065 g_critical ("Could not locate 'gnome-control-center.desktop'");
1069 args[0] = g_app_info_get_commandline (G_APP_INFO (app_info));
1070 args[1] = "bisho.desktop";
1073 gdk_spawn_on_screen (gtk_widget_get_screen (button),
1074 NULL, (gchar **) args, NULL,
1075 G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
1078 g_critical ("Failed to launch editor: %s", error->message);
1079 g_clear_error (&error);
1082 g_object_unref (app_info);
1087 account_widget_build_external (EmpathyAccountWidget *self,
1088 EmpathyAccountSettings *settings)
1090 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1091 TpAccount *account = empathy_account_settings_get_account (settings);
1092 GtkWidget *bar, *widget;
1095 self->ui_details->widget = gtk_vbox_new (FALSE, 6);
1096 priv->table_common_settings = gtk_table_new (1, 2, FALSE);
1098 if (!tp_strdiff (tp_account_get_storage_provider (account),
1099 "com.meego.libsocialweb"))
1101 /* we know how to handle this external provider */
1102 str = g_strdup_printf (
1103 _("The account %s is edited via My Web Accounts."),
1104 empathy_account_settings_get_display_name (settings));
1108 str = g_strdup_printf (
1109 _("The account %s cannot be edited in Empathy."),
1110 empathy_account_settings_get_display_name (settings));
1113 widget = gtk_label_new (str);
1114 gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
1117 bar = gtk_info_bar_new ();
1118 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
1120 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))),
1122 gtk_container_set_border_width (GTK_CONTAINER (bar), 6);
1124 if (!tp_strdiff (tp_account_get_storage_provider (account),
1125 "com.meego.libsocialweb"))
1127 /* we know how to handle this external provider */
1128 widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
1129 _("Launch My Web Accounts"), RESPONSE_LAUNCH);
1131 g_signal_connect (widget, "clicked",
1132 G_CALLBACK (account_widget_launch_external_clicked), account);
1135 gtk_box_pack_start (GTK_BOX (self->ui_details->widget), bar,
1137 gtk_box_pack_start (GTK_BOX (self->ui_details->widget),
1138 priv->table_common_settings, FALSE, TRUE, 0);
1140 gtk_widget_show_all (self->ui_details->widget);
1144 account_widget_build_salut (EmpathyAccountWidget *self,
1145 const char *filename)
1147 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1148 GtkWidget *expander_advanced;
1150 self->ui_details->gui = empathy_builder_get_file (filename,
1151 "table_common_settings", &priv->table_common_settings,
1152 "vbox_salut_settings", &self->ui_details->widget,
1153 "expander_advanced_settings", &expander_advanced,
1156 empathy_account_widget_handle_params (self,
1157 "entry_published", "published-name",
1158 "entry_nickname", "nickname",
1159 "entry_first_name", "first-name",
1160 "entry_last_name", "last-name",
1161 "entry_email", "email",
1166 gtk_widget_hide (expander_advanced);
1168 self->ui_details->default_focus = g_strdup ("entry_first_name");
1172 account_widget_build_irc (EmpathyAccountWidget *self,
1173 const char *filename)
1175 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1177 empathy_account_settings_set_regex (priv->settings, "account",
1182 priv->irc_network_chooser = empathy_account_widget_irc_build_simple (self,
1187 priv->irc_network_chooser = empathy_account_widget_irc_build (self,
1188 filename, &priv->table_common_settings);
1193 account_widget_build_sip (EmpathyAccountWidget *self,
1194 const char *filename)
1196 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1197 empathy_account_widget_sip_build (self, filename,
1198 &priv->table_common_settings);
1202 account_widget_build_msn (EmpathyAccountWidget *self,
1203 const char *filename)
1205 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1207 empathy_account_settings_set_regex (priv->settings, "account",
1212 self->ui_details->gui = empathy_builder_get_file (filename,
1213 "vbox_msn_simple", &self->ui_details->widget,
1216 empathy_account_widget_handle_params (self,
1217 "entry_id_simple", "account",
1218 "entry_password_simple", "password",
1221 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1225 self->ui_details->gui = empathy_builder_get_file (filename,
1226 "table_common_msn_settings", &priv->table_common_settings,
1227 "vbox_msn_settings", &self->ui_details->widget,
1230 empathy_account_widget_handle_params (self,
1231 "entry_id", "account",
1232 "entry_password", "password",
1233 "entry_server", "server",
1234 "spinbutton_port", "port",
1237 self->ui_details->default_focus = g_strdup ("entry_id");
1242 account_widget_is_gtalk (EmpathyAccountWidget *self)
1244 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1246 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
1251 account_widget_is_facebook (EmpathyAccountWidget *self)
1253 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1255 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
1259 #define FACEBOOK_SUFFIX "@chat.facebook.com"
1262 facebook_id_widget_changed_cb (GtkWidget *entry,
1263 EmpathyAccountWidget *self)
1265 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1266 const gchar *account;
1268 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1270 account = empathy_account_settings_get_string (priv->settings, "account");
1271 if (!EMP_STR_EMPTY (account) &&
1272 !g_str_has_suffix (account, FACEBOOK_SUFFIX))
1276 tmp = g_strdup_printf ("%s%s", account, FACEBOOK_SUFFIX);
1278 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1280 empathy_account_settings_set_string (priv->settings, "account", tmp);
1284 empathy_account_widget_changed (self);
1288 remove_facebook_suffix (const gchar *str)
1290 if (!g_str_has_suffix (str, FACEBOOK_SUFFIX))
1291 return g_strdup (str);
1293 return g_strndup (str, strlen (str) - strlen (FACEBOOK_SUFFIX));
1297 setup_facebook_id_widget (EmpathyAccountWidget *self,
1300 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1301 const gchar *str = NULL;
1303 g_object_set_data_full (G_OBJECT (widget), "param_name",
1304 g_strdup ("account"), g_free);
1306 str = empathy_account_settings_get_string (priv->settings, "account");
1311 tmp = remove_facebook_suffix (str);
1312 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1316 priv->param_account_widget = widget;
1318 g_signal_connect (widget, "changed",
1319 G_CALLBACK (facebook_id_widget_changed_cb), self);
1323 account_widget_build_jabber (EmpathyAccountWidget *self,
1324 const char *filename)
1326 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1327 GtkWidget *spinbutton_port;
1328 GtkWidget *checkbutton_ssl;
1329 GtkWidget *label_id, *label_password;
1330 GtkWidget *label_id_create, *label_password_create;
1331 GtkWidget *label_example_gtalk, *label_example_jabber, *label_example_fb;
1332 gboolean is_gtalk, is_facebook;
1333 GtkWidget *expander_advanced;
1334 GtkWidget *entry_id;
1336 is_gtalk = account_widget_is_gtalk (self);
1337 is_facebook = account_widget_is_facebook (self);
1339 empathy_account_settings_set_regex (priv->settings, "account",
1340 ACCOUNT_REGEX_JABBER);
1342 if (priv->simple && !is_gtalk && !is_facebook)
1344 /* Simple widget for XMPP */
1345 self->ui_details->gui = empathy_builder_get_file (filename,
1346 "vbox_jabber_simple", &self->ui_details->widget,
1347 "label_id_simple", &label_id,
1348 "label_id_create", &label_id_create,
1349 "label_password_simple", &label_password,
1350 "label_password_create", &label_password_create,
1353 if (empathy_account_settings_get_boolean (priv->settings, "register"))
1355 gtk_widget_hide (label_id);
1356 gtk_widget_hide (label_password);
1357 gtk_widget_show (label_id_create);
1358 gtk_widget_show (label_password_create);
1361 empathy_account_widget_handle_params (self,
1362 "entry_id_simple", "account",
1363 "entry_password_simple", "password",
1366 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1368 else if (priv->simple && is_gtalk)
1370 /* Simple widget for Google Talk */
1371 self->ui_details->gui = empathy_builder_get_file (filename,
1372 "vbox_gtalk_simple", &self->ui_details->widget,
1375 empathy_account_widget_handle_params (self,
1376 "entry_id_g_simple", "account",
1377 "entry_password_g_simple", "password",
1380 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1382 else if (priv->simple && is_facebook)
1384 /* Simple widget for Facebook */
1385 self->ui_details->gui = empathy_builder_get_file (filename,
1386 "vbox_fb_simple", &self->ui_details->widget,
1387 "entry_id_fb_simple", &entry_id,
1390 empathy_account_widget_handle_params (self,
1391 "entry_password_fb_simple", "password",
1394 setup_facebook_id_widget (self, entry_id);
1396 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1400 /* Full widget for XMPP, Google Talk and Facebook*/
1401 self->ui_details->gui = empathy_builder_get_file (filename,
1402 "table_common_settings", &priv->table_common_settings,
1403 "vbox_jabber_settings", &self->ui_details->widget,
1404 "spinbutton_port", &spinbutton_port,
1405 "checkbutton_ssl", &checkbutton_ssl,
1406 "label_username_example", &label_example_jabber,
1407 "label_username_g_example", &label_example_gtalk,
1408 "label_username_f_example", &label_example_fb,
1409 "expander_advanced", &expander_advanced,
1410 "entry_id", &entry_id,
1411 "label_id", &label_id,
1414 empathy_account_widget_handle_params (self,
1415 "entry_password", "password",
1416 "entry_resource", "resource",
1417 "entry_server", "server",
1418 "spinbutton_port", "port",
1419 "spinbutton_priority", "priority",
1420 "checkbutton_ssl", "old-ssl",
1421 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1422 "checkbutton_encryption", "require-encryption",
1427 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1429 /* Facebook special case the entry ID widget to hide the
1430 * "@chat.facebook.com" part */
1431 setup_facebook_id_widget (self, entry_id);
1435 empathy_account_widget_setup_widget (self, entry_id, "account");
1438 self->ui_details->default_focus = g_strdup ("entry_id");
1439 priv->spinbutton_port = spinbutton_port;
1441 g_signal_connect (checkbutton_ssl, "toggled",
1442 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1447 gtk_widget_hide (label_example_jabber);
1448 gtk_widget_show (label_example_gtalk);
1450 else if (is_facebook)
1452 GtkContainer *parent;
1455 gtk_widget_hide (label_example_jabber);
1457 /* Removing the label from list of focusable widgets */
1458 parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
1459 children = gtk_container_get_children (parent);
1460 children = g_list_remove (children, label_example_fb);
1461 gtk_container_set_focus_chain (parent, children);
1462 g_list_free (children);
1464 gtk_widget_show (label_example_fb);
1465 gtk_widget_hide (expander_advanced);
1471 account_widget_build_icq (EmpathyAccountWidget *self,
1472 const char *filename)
1474 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1475 GtkWidget *spinbutton_port;
1477 empathy_account_settings_set_regex (priv->settings, "account",
1482 self->ui_details->gui = empathy_builder_get_file (filename,
1483 "vbox_icq_simple", &self->ui_details->widget,
1486 empathy_account_widget_handle_params (self,
1487 "entry_uin_simple", "account",
1488 "entry_password_simple", "password",
1491 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1495 self->ui_details->gui = empathy_builder_get_file (filename,
1496 "table_common_settings", &priv->table_common_settings,
1497 "vbox_icq_settings", &self->ui_details->widget,
1498 "spinbutton_port", &spinbutton_port,
1501 empathy_account_widget_handle_params (self,
1502 "entry_uin", "account",
1503 "entry_password", "password",
1504 "entry_server", "server",
1505 "spinbutton_port", "port",
1506 "entry_charset", "charset",
1509 self->ui_details->default_focus = g_strdup ("entry_uin");
1514 account_widget_build_aim (EmpathyAccountWidget *self,
1515 const char *filename)
1517 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1518 GtkWidget *spinbutton_port;
1522 self->ui_details->gui = empathy_builder_get_file (filename,
1523 "vbox_aim_simple", &self->ui_details->widget,
1526 empathy_account_widget_handle_params (self,
1527 "entry_screenname_simple", "account",
1528 "entry_password_simple", "password",
1531 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1535 self->ui_details->gui = empathy_builder_get_file (filename,
1536 "table_common_settings", &priv->table_common_settings,
1537 "vbox_aim_settings", &self->ui_details->widget,
1538 "spinbutton_port", &spinbutton_port,
1541 empathy_account_widget_handle_params (self,
1542 "entry_screenname", "account",
1543 "entry_password", "password",
1544 "entry_server", "server",
1545 "spinbutton_port", "port",
1548 self->ui_details->default_focus = g_strdup ("entry_screenname");
1553 account_widget_build_yahoo (EmpathyAccountWidget *self,
1554 const char *filename)
1556 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1558 empathy_account_settings_set_regex (priv->settings, "account",
1559 ACCOUNT_REGEX_YAHOO);
1563 self->ui_details->gui = empathy_builder_get_file (filename,
1564 "vbox_yahoo_simple", &self->ui_details->widget,
1567 empathy_account_widget_handle_params (self,
1568 "entry_id_simple", "account",
1569 "entry_password_simple", "password",
1572 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1576 self->ui_details->gui = empathy_builder_get_file (filename,
1577 "table_common_settings", &priv->table_common_settings,
1578 "vbox_yahoo_settings", &self->ui_details->widget,
1581 empathy_account_widget_handle_params (self,
1582 "entry_id", "account",
1583 "entry_password", "password",
1584 "entry_server", "server",
1585 "entry_locale", "room-list-locale",
1586 "entry_charset", "charset",
1587 "spinbutton_port", "port",
1588 "checkbutton_ignore_invites", "ignore-invites",
1591 self->ui_details->default_focus = g_strdup ("entry_id");
1596 account_widget_build_groupwise (EmpathyAccountWidget *self,
1597 const char *filename)
1599 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1603 self->ui_details->gui = empathy_builder_get_file (filename,
1604 "vbox_groupwise_simple", &self->ui_details->widget,
1607 empathy_account_widget_handle_params (self,
1608 "entry_id_simple", "account",
1609 "entry_password_simple", "password",
1612 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1616 self->ui_details->gui = empathy_builder_get_file (filename,
1617 "table_common_groupwise_settings", &priv->table_common_settings,
1618 "vbox_groupwise_settings", &self->ui_details->widget,
1621 empathy_account_widget_handle_params (self,
1622 "entry_id", "account",
1623 "entry_password", "password",
1624 "entry_server", "server",
1625 "spinbutton_port", "port",
1628 self->ui_details->default_focus = g_strdup ("entry_id");
1633 account_widget_destroy_cb (GtkWidget *widget,
1634 EmpathyAccountWidget *self)
1636 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1637 /* set the destroyed flag - workaround */
1638 priv->destroyed = TRUE;
1640 g_object_unref (self);
1644 empathy_account_widget_enabled_cb (TpAccount *account,
1648 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1649 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1650 gboolean enabled = tp_account_is_enabled (account);
1652 if (priv->enabled_checkbox != NULL)
1655 mx_gtk_light_switch_set_active (
1656 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1659 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1661 #endif /* HAVE_MEEGO */
1667 account_widget_switch_flipped_cb (MxGtkLightSwitch *sw,
1671 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1673 #endif /* HAVE_MEEGO */
1675 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1680 state = gtk_toggle_button_get_active (toggle_button);
1681 #endif /* HAVE_MEEGO */
1683 account = empathy_account_settings_get_account (priv->settings);
1685 /* Enable the account according to the value of the "Enabled" checkbox */
1686 /* workaround to keep widget alive during async call */
1687 g_object_ref (user_data);
1688 tp_account_set_enabled_async (account, state,
1689 account_widget_account_enabled_cb, user_data);
1693 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1694 gboolean others_exist)
1696 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1698 priv->other_accounts_exist = others_exist;
1700 if (priv->creating_account)
1701 account_widget_handle_control_buttons_sensitivity (self);
1705 do_set_property (GObject *object,
1707 const GValue *value,
1710 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1715 priv->settings = g_value_dup_object (value);
1718 priv->simple = g_value_get_boolean (value);
1720 case PROP_CREATING_ACCOUNT:
1721 priv->creating_account = g_value_get_boolean (value);
1723 case PROP_OTHER_ACCOUNTS_EXIST:
1724 empathy_account_widget_set_other_accounts_exist (
1725 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1728 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1733 do_get_property (GObject *object,
1738 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1743 g_value_set_string (value,
1744 empathy_account_settings_get_protocol (priv->settings));
1747 g_value_set_object (value, priv->settings);
1750 g_value_set_boolean (value, priv->simple);
1752 case PROP_CREATING_ACCOUNT:
1753 g_value_set_boolean (value, priv->creating_account);
1755 case PROP_OTHER_ACCOUNTS_EXIST:
1756 g_value_set_boolean (value, priv->other_accounts_exist);
1759 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1764 set_apply_button (EmpathyAccountWidget *self)
1766 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1769 /* We can't use the stock button as its accelerator ('A') clashes with the
1771 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1773 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("A_pply"));
1774 gtk_button_set_use_underline (GTK_BUTTON (priv->apply_button), TRUE);
1776 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1777 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1781 presence_changed_cb (TpAccountManager *manager,
1782 TpConnectionPresenceType state,
1783 const gchar *status,
1784 const gchar *message,
1785 EmpathyAccountWidget *self)
1787 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1789 if (priv->destroyed)
1792 if (priv->apply_button == NULL)
1793 /* This button doesn't exist in 'simple' mode */
1796 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1797 priv->creating_account)
1799 /* We are online and creating a new account, display a Login button */
1802 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1803 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1805 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1806 GTK_ICON_SIZE_BUTTON);
1807 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1811 /* We are offline or modifying an existing account, display
1813 set_apply_button (self);
1818 account_manager_ready_cb (GObject *source_object,
1819 GAsyncResult *result,
1822 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1823 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1824 GError *error = NULL;
1825 TpConnectionPresenceType state;
1827 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1829 DEBUG ("Failed to prepare account manager: %s", error->message);
1830 g_error_free (error);
1834 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1837 /* simulate a presence change so the apply button will be changed
1839 presence_changed_cb (account_manager, state, NULL, NULL, self);
1842 g_object_unref (self);
1845 #define WIDGET(cm, proto) \
1846 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1847 account_widget_build_##proto }
1850 add_enable_checkbox (EmpathyAccountWidget *self,
1853 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1857 GtkWidget *vbox = self->ui_details->widget;
1858 #endif /* HAVE_MEEGO */
1859 guint nb_rows, nb_columns;
1860 gboolean is_enabled;
1862 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1863 if (priv->creating_account || priv->table_common_settings == NULL)
1866 is_enabled = tp_account_is_enabled (account);
1869 w = gtk_label_new (_("Account:"));
1870 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1872 priv->enabled_checkbox = mx_gtk_light_switch_new ();
1874 mx_gtk_light_switch_set_active (
1875 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1877 gtk_widget_show (w);
1879 priv->enabled_checkbox =
1880 gtk_check_button_new_with_mnemonic (_("_Enabled"));
1882 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1884 #endif /* HAVE_MEEGO */
1886 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1887 "n-columns", &nb_columns, NULL);
1889 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1893 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1895 0, 1, nb_rows - 1, nb_rows,
1897 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1898 priv->enabled_checkbox,
1899 1, nb_columns, nb_rows - 1, nb_rows,
1900 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1902 gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
1903 gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
1904 #endif /* HAVE_MEEGO */
1906 gtk_widget_show (priv->enabled_checkbox);
1909 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1910 G_CALLBACK (account_widget_switch_flipped_cb), self);
1912 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
1913 G_CALLBACK (account_widget_enabled_toggled_cb), self);
1914 #endif /* HAVE_MEEGO */
1918 /* Meego doesn't support registration */
1920 add_register_buttons (EmpathyAccountWidget *self,
1923 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1924 const TpConnectionManagerProtocol *protocol;
1925 GtkWidget *radiobutton_register;
1926 GtkWidget *vbox = self->ui_details->widget;
1928 if (!priv->creating_account)
1931 protocol = empathy_account_settings_get_tp_protocol (priv->settings);
1932 if (protocol == NULL)
1935 if (!tp_connection_manager_protocol_can_register (protocol))
1938 if (account_widget_is_gtalk (self) || account_widget_is_facebook (self))
1944 priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1945 _("This account already exists on the server"));
1946 radiobutton_register = gtk_radio_button_new_with_label (
1947 gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
1948 _("Create a new account on the server"));
1950 gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
1951 gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
1952 gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
1953 gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
1954 gtk_widget_show (priv->radiobutton_reuse);
1955 gtk_widget_show (radiobutton_register);
1957 #endif /* HAVE_MEEGO */
1960 do_constructed (GObject *obj)
1962 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1963 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1965 TpStorageRestrictionFlags storage_restrictions;
1966 const gchar *display_name, *default_display_name;
1969 const gchar *cm_name;
1970 const gchar *protocol;
1972 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1974 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1975 account_widget_build_salut },
1976 WIDGET (gabble, jabber),
1977 WIDGET (butterfly, msn),
1980 WIDGET (haze, yahoo),
1981 WIDGET (haze, groupwise),
1983 WIDGET (sofiasip, sip),
1986 account = empathy_account_settings_get_account (priv->settings);
1988 if (account != NULL)
1989 storage_restrictions = tp_account_get_storage_restrictions (account);
1991 storage_restrictions = 0;
1993 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
1994 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
1996 DEBUG ("Account is provided by an external storage provider");
1998 account_widget_build_external (self, priv->settings);
2002 const gchar *protocol, *cm_name;
2004 cm_name = empathy_account_settings_get_cm (priv->settings);
2005 protocol = empathy_account_settings_get_protocol (priv->settings);
2007 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
2009 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
2010 !tp_strdiff (widgets[i].protocol, protocol))
2014 filename = empathy_file_lookup (widgets[i].file,
2016 widgets[i].func (self, filename);
2023 if (i == G_N_ELEMENTS (widgets))
2025 gchar *filename = empathy_file_lookup (
2026 "empathy-account-widget-generic.ui", "libempathy-gtk");
2027 account_widget_build_generic (self, filename);
2032 /* handle default focus */
2033 if (self->ui_details->default_focus != NULL)
2035 GObject *default_focus_entry;
2037 default_focus_entry = gtk_builder_get_object
2038 (self->ui_details->gui, self->ui_details->default_focus);
2039 g_signal_connect (default_focus_entry, "realize",
2040 G_CALLBACK (gtk_widget_grab_focus),
2044 /* dup and init the account-manager */
2045 priv->account_manager = tp_account_manager_dup ();
2047 g_object_ref (self);
2048 tp_account_manager_prepare_async (priv->account_manager, NULL,
2049 account_manager_ready_cb, self);
2051 /* handle apply and cancel button */
2052 if (!priv->simple &&
2053 !(storage_restrictions &
2054 TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS))
2056 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
2059 /* We can't use the stock button as its accelerator ('C') clashes with
2060 * the Close button. */
2061 priv->cancel_button = gtk_button_new ();
2062 gtk_button_set_label (GTK_BUTTON (priv->cancel_button), _("Ca_ncel"));
2063 gtk_button_set_use_underline (GTK_BUTTON (priv->cancel_button), TRUE);
2065 image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
2066 gtk_button_set_image (GTK_BUTTON (priv->cancel_button), image);
2068 priv->apply_button = gtk_button_new ();
2069 set_apply_button (self);
2071 /* We'll change this button to a "Log in" one if we are creating a new
2072 * account and are connected. */
2073 tp_g_signal_connect_object (priv->account_manager,
2074 "most-available-presence-changed",
2075 G_CALLBACK (presence_changed_cb), obj, 0);
2077 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
2079 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
2082 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
2085 g_signal_connect (priv->cancel_button, "clicked",
2086 G_CALLBACK (account_widget_cancel_clicked_cb),
2088 g_signal_connect (priv->apply_button, "clicked",
2089 G_CALLBACK (account_widget_apply_clicked_cb),
2091 gtk_widget_show_all (hbox);
2093 if (priv->creating_account)
2094 /* When creating an account, the user might have nothing to enter.
2095 * That means that no control interaction might occur,
2096 * so we update the control button sensitivity manually.
2098 account_widget_handle_control_buttons_sensitivity (self);
2100 account_widget_set_control_buttons_sensitivity (self, FALSE);
2103 if (account != NULL)
2105 g_signal_connect (account, "notify::enabled",
2106 G_CALLBACK (empathy_account_widget_enabled_cb), self);
2110 add_register_buttons (self, account);
2111 #endif /* HAVE_MEEGO */
2113 /* add the Enable checkbox to accounts that support it */
2114 if (!(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED))
2115 add_enable_checkbox (self, account);
2117 /* hook up to widget destruction to unref ourselves */
2118 g_signal_connect (self->ui_details->widget, "destroy",
2119 G_CALLBACK (account_widget_destroy_cb), self);
2121 if (self->ui_details->gui != NULL)
2123 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
2124 self->ui_details->widget);
2125 self->ui_details->gui = NULL;
2128 display_name = empathy_account_settings_get_display_name (priv->settings);
2129 default_display_name = empathy_account_widget_get_default_display_name (self);
2131 if (tp_strdiff (display_name, default_display_name) &&
2132 !priv->creating_account)
2134 /* The display name of the account is not the one that we'd assign by
2135 * default; assume that the user changed it manually */
2136 g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
2141 do_dispose (GObject *obj)
2143 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2144 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2146 if (priv->dispose_run)
2149 priv->dispose_run = TRUE;
2151 if (priv->settings != NULL)
2154 account = empathy_account_settings_get_account (priv->settings);
2156 if (account != NULL)
2158 g_signal_handlers_disconnect_by_func (account,
2159 empathy_account_widget_enabled_cb, self);
2162 g_object_unref (priv->settings);
2163 priv->settings = NULL;
2166 if (priv->account_manager != NULL)
2168 g_object_unref (priv->account_manager);
2169 priv->account_manager = NULL;
2172 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
2173 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
2177 do_finalize (GObject *obj)
2179 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2181 g_free (self->ui_details->default_focus);
2182 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
2184 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
2185 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
2189 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
2191 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2192 GParamSpec *param_spec;
2194 oclass->get_property = do_get_property;
2195 oclass->set_property = do_set_property;
2196 oclass->constructed = do_constructed;
2197 oclass->dispose = do_dispose;
2198 oclass->finalize = do_finalize;
2200 param_spec = g_param_spec_string ("protocol",
2201 "protocol", "The protocol of the account",
2203 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2204 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2206 param_spec = g_param_spec_object ("settings",
2207 "settings", "The settings of the account",
2208 EMPATHY_TYPE_ACCOUNT_SETTINGS,
2209 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2210 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2212 param_spec = g_param_spec_boolean ("simple",
2213 "simple", "Whether the account widget is a simple or an advanced one",
2215 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2216 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2218 param_spec = g_param_spec_boolean ("creating-account",
2220 "TRUE if we're creating an account, FALSE if we're modifying it",
2222 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2223 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2225 param_spec = g_param_spec_boolean ("other-accounts-exist",
2226 "other-accounts-exist",
2227 "TRUE if there are any other accounts (even if this isn't yet saved)",
2229 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2230 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2233 signals[HANDLE_APPLY] =
2234 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2235 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2236 g_cclosure_marshal_VOID__BOOLEAN,
2240 /* This signal is emitted when an account has been created and enabled. */
2241 signals[ACCOUNT_CREATED] =
2242 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2243 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2244 g_cclosure_marshal_VOID__OBJECT,
2248 signals[CANCELLED] =
2249 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2250 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2251 g_cclosure_marshal_VOID__VOID,
2255 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
2259 empathy_account_widget_init (EmpathyAccountWidget *self)
2261 EmpathyAccountWidgetPriv *priv =
2262 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
2263 EmpathyAccountWidgetPriv);
2266 priv->dispose_run = FALSE;
2268 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
2271 /* public methods */
2274 empathy_account_widget_discard_pending_changes
2275 (EmpathyAccountWidget *widget)
2277 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2279 empathy_account_settings_discard_changes (priv->settings);
2280 priv->contains_pending_changes = FALSE;
2284 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
2286 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2288 return priv->contains_pending_changes;
2292 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
2293 const gchar *first_widget,
2298 va_start (args, first_widget);
2299 account_widget_handle_params_valist (self, first_widget, args);
2304 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
2306 return widget->ui_details->widget;
2309 EmpathyAccountWidget *
2310 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
2313 EmpathyAccountWidget *self;
2315 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
2318 (EMPATHY_TYPE_ACCOUNT_WIDGET,
2319 "settings", settings, "simple", simple,
2321 empathy_account_settings_get_account (settings) == NULL,
2328 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
2330 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2331 const gchar *login_id;
2332 const gchar *protocol, *p;
2333 gchar *default_display_name;
2335 login_id = empathy_account_settings_get_string (priv->settings, "account");
2336 protocol = empathy_account_settings_get_protocol (priv->settings);
2338 if (login_id != NULL)
2340 /* TODO: this should be done in empathy-account-widget-irc */
2341 if (!tp_strdiff (protocol, "irc"))
2343 EmpathyIrcNetwork *network;
2345 network = empathy_irc_network_chooser_get_network (
2346 priv->irc_network_chooser);
2347 g_assert (network != NULL);
2349 /* To translators: The first parameter is the login id and the
2350 * second one is the network. The resulting string will be something
2351 * like: "MyUserName on freenode".
2352 * You should reverse the order of these arguments if the
2353 * server should come before the login id in your locale.*/
2354 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2355 login_id, empathy_irc_network_get_name (network));
2357 else if (account_widget_is_facebook (self))
2361 tmp = remove_facebook_suffix (login_id);
2362 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2367 default_display_name = g_strdup (login_id);
2370 return default_display_name;
2373 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2376 if (protocol != NULL)
2378 /* To translators: The parameter is the protocol name. The resulting
2379 * string will be something like: "Jabber Account" */
2380 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2384 default_display_name = g_strdup (_("New account"));
2387 return default_display_name;
2390 /* Used by subclass to indicate that widget contains pending changes */
2392 empathy_account_widget_changed (EmpathyAccountWidget *self)
2394 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2396 account_widget_handle_control_buttons_sensitivity (self);
2397 priv->contains_pending_changes = TRUE;
2401 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2402 const gchar *account)
2404 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2406 if (priv->param_account_widget == NULL)
2409 gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
2413 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2414 const gchar *account)
2416 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2418 if (priv->param_password_widget == NULL)
2421 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);