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>
33 #include <gio/gdesktopappinfo.h>
35 #include <libempathy/empathy-utils.h>
37 #include <telepathy-glib/account.h>
38 #include <telepathy-glib/account-manager.h>
39 #include <telepathy-glib/connection-manager.h>
40 #include <telepathy-glib/util.h>
41 #include <dbus/dbus-protocol.h>
43 #include "empathy-account-widget.h"
44 #include "empathy-account-widget-private.h"
45 #include "empathy-account-widget-sip.h"
46 #include "empathy-account-widget-irc.h"
47 #include "empathy-ui-utils.h"
49 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
50 #include <libempathy/empathy-debug.h>
52 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT)
64 const gchar *label_username_example;
65 gboolean show_advanced;
68 static ServiceInfo services_infos[N_SERVICES] = {
69 { "label_username_example", TRUE },
70 { "label_username_g_example", FALSE },
71 { "label_username_f_example", FALSE },
75 EmpathyAccountSettings *settings;
77 GtkWidget *table_common_settings;
78 GtkWidget *apply_button;
79 GtkWidget *cancel_button;
80 GtkWidget *entry_password;
81 GtkWidget *spinbutton_port;
82 GtkWidget *radiobutton_reuse;
86 gboolean contains_pending_changes;
88 /* An EmpathyAccountWidget can be used to either create an account or
89 * modify it. When we are creating an account, this member is set to TRUE */
90 gboolean creating_account;
92 /* whether there are any other real accounts. Necessary so we know whether
93 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
94 * button should be sensitive) */
95 gboolean other_accounts_exist;
97 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
98 * embedded in this account widget can't be used any more
99 * workaround because some async callbacks can be called after the
100 * widget has been destroyed */
103 TpAccountManager *account_manager;
105 GtkWidget *param_account_widget;
106 GtkWidget *param_password_widget;
108 gboolean automatic_change;
109 GtkWidget *remember_password_widget;
111 /* Used only for IRC accounts */
112 EmpathyIrcNetworkChooser *irc_network_chooser;
114 /* Used for 'special' XMPP account having a service associated ensuring that
115 * JIDs have a specific suffix; such as Facebook for example */
118 gboolean dispose_run;
119 } EmpathyAccountWidgetPriv;
125 PROP_CREATING_ACCOUNT,
126 PROP_OTHER_ACCOUNTS_EXIST,
136 static void account_widget_apply_and_log_in (EmpathyAccountWidget *);
142 static guint signals[LAST_SIGNAL] = { 0 };
144 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
145 #define CHANGED_TIMEOUT 300
148 #define DIGITS "(["DIGIT"]+)"
149 #define ALPHA "a-zA-Z"
150 #define ALPHAS "(["ALPHA"]+)"
151 #define ALPHADIGIT ALPHA DIGIT
152 #define ALPHADIGITS "(["ALPHADIGIT"]+)"
153 #define ALPHADIGITDASH ALPHA DIGIT "-"
154 #define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
156 #define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
157 #define TOPLABEL "("ALPHAS \
158 "| (["ALPHA"]"ALPHADIGITDASHS "["ALPHADIGIT"]))"
159 #define DOMAINLABEL "("ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
161 #define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
162 /* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
163 #define HOST "("HOSTNAME "|" HOSTNUMBER")"
164 /* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
165 #define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
167 /* UIN is digital according to the unofficial specification:
168 * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
169 * 5 digits minimum according to http://en.wikipedia.org/wiki/ICQ#UIN
170 * According to an user, we can also provide an email address instead of the
172 #define ICQ_USER_NAME "((["DIGIT"]{5,})|"EMAIL_LOCALPART"@"HOST")"
174 /* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
175 #define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
176 #define IRC_NICK_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
177 /* user = 1*( %x01-09 / %x0B-0C / %x0E-1F / %x21-3F / %x41-FF )
178 * ; any octet except NUL, CR, LF, " " and "@"
180 * so technically, like so many other places in IRC, we should be using arrays
181 * of bytes here rather than UTF-8 strings. Life: too short. In practice this
182 * will always be ASCII.
184 #define IRC_USER_NAME "([^\r\n@ ])+"
186 /* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
187 * We just exclude invalid characters to avoid ucschars and other redundant
189 #define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
190 /* ID is an email according to the unofficial specification:
191 * http://www.hypothetic.org/docs/msn/general/names.php */
192 #define MSN_USER_NAME EMAIL_LOCALPART
193 /* Based on the official help:
194 * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html
195 * Looks like an email address can be used as well (bgo #655959)
197 #define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})|("EMAIL_LOCALPART"@"HOST")"
199 #define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
200 #define ACCOUNT_REGEX_IRC "^"IRC_NICK_NAME"$"
201 #define USERNAME_REGEX_IRC "^"IRC_USER_NAME"$"
202 #define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@"HOST"$"
203 #define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
204 #define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
207 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
210 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
214 /* we hit this case because of the 'other-accounts-exist' property handler
215 * being called during init (before constructed()) */
216 if (priv->apply_button == NULL || priv->cancel_button == NULL)
219 gtk_widget_set_sensitive (priv->apply_button, sensitive);
220 gtk_widget_set_sensitive (priv->cancel_button,
221 (sensitive || priv->creating_account) && priv->other_accounts_exist);
225 /* We can't grab default if the widget hasn't be packed in a
229 window = gtk_widget_get_toplevel (priv->apply_button);
230 if (window != NULL &&
231 gtk_widget_is_toplevel (window))
233 gtk_widget_set_can_default (priv->apply_button, TRUE);
234 gtk_widget_grab_default (priv->apply_button);
241 account_widget_set_entry_highlighting (GtkEntry *entry,
244 g_return_if_fail (GTK_IS_ENTRY (entry));
248 GtkStyleContext *style;
251 style = gtk_widget_get_style_context (GTK_WIDGET (entry));
252 gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
255 /* Here we take the current theme colour and add it to
256 * the colour for white and average the two. This
257 * gives a colour which is inline with the theme but
260 empathy_make_color_whiter (&color);
262 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, &color);
266 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, NULL);
271 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
273 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
276 is_valid = empathy_account_settings_is_valid (priv->settings);
279 account_widget_set_control_buttons_sensitivity (self, is_valid);
281 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
285 account_widget_entry_changed_common (EmpathyAccountWidget *self,
286 GtkEntry *entry, gboolean focus)
289 const gchar *param_name;
290 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
291 gboolean prev_status;
292 gboolean curr_status;
294 str = gtk_entry_get_text (entry);
295 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
296 prev_status = empathy_account_settings_parameter_is_valid (priv->settings,
299 if (EMP_STR_EMPTY (str))
301 const gchar *value = NULL;
303 empathy_account_settings_unset (priv->settings, param_name);
307 value = empathy_account_settings_get_string (priv->settings,
309 DEBUG ("Unset %s and restore to %s", param_name, value);
310 gtk_entry_set_text (entry, value ? value : "");
315 DEBUG ("Setting %s to %s", param_name,
316 tp_strdiff (param_name, "password") ? str : "***");
317 empathy_account_settings_set_string (priv->settings, param_name, str);
320 curr_status = empathy_account_settings_parameter_is_valid (priv->settings,
322 if (curr_status != prev_status)
323 account_widget_set_entry_highlighting (entry, !curr_status);
327 account_widget_entry_changed_cb (GtkEditable *entry,
328 EmpathyAccountWidget *self)
330 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
332 if (priv->automatic_change)
335 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
336 empathy_account_widget_changed (self);
340 account_widget_entry_map_cb (GtkEntry *entry,
341 EmpathyAccountWidget *self)
343 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
344 const gchar *param_name;
347 /* need to initialize input highlighting */
348 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
349 is_valid = empathy_account_settings_parameter_is_valid (priv->settings,
351 account_widget_set_entry_highlighting (entry, !is_valid);
355 account_widget_int_changed_cb (GtkWidget *widget,
356 EmpathyAccountWidget *self)
358 const gchar *param_name;
360 const gchar *signature;
361 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
363 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
364 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
366 signature = empathy_account_settings_get_dbus_signature (priv->settings,
368 g_return_if_fail (signature != NULL);
370 DEBUG ("Setting %s to %d", param_name, value);
372 switch ((int)*signature)
374 case DBUS_TYPE_INT16:
375 case DBUS_TYPE_INT32:
376 empathy_account_settings_set_int32 (priv->settings, param_name, value);
378 case DBUS_TYPE_INT64:
379 empathy_account_settings_set_int64 (priv->settings, param_name, value);
381 case DBUS_TYPE_UINT16:
382 case DBUS_TYPE_UINT32:
383 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
385 case DBUS_TYPE_UINT64:
386 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
389 g_return_if_reached ();
392 empathy_account_widget_changed (self);
396 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
397 EmpathyAccountWidget *self)
400 gboolean default_value;
401 const gchar *param_name;
402 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
404 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
405 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
407 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
408 * always unset the param and set the value if different from the
410 empathy_account_settings_unset (priv->settings, param_name);
411 default_value = empathy_account_settings_get_boolean (priv->settings,
414 if (default_value == value)
416 DEBUG ("Unset %s and restore to %d", param_name, default_value);
420 DEBUG ("Setting %s to %d", param_name, value);
421 empathy_account_settings_set_boolean (priv->settings, param_name, value);
424 empathy_account_widget_changed (self);
428 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
429 EmpathyAccountWidget *self)
431 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
435 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
436 port = empathy_account_settings_get_uint32 (priv->settings, "port");
440 if (port == 5222 || port == 0)
445 if (port == 5223 || port == 0)
449 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
451 priv->contains_pending_changes = TRUE;
455 account_widget_combobox_changed_cb (GtkWidget *widget,
456 EmpathyAccountWidget *self)
462 const gchar *default_value = NULL;
463 const gchar *param_name;
464 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
466 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
469 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
470 /* the param value is stored in the first column */
471 gtk_tree_model_get (model, &iter, 0, &value, -1);
473 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
475 v = empathy_account_settings_get_default (priv->settings, param_name);
477 default_value = g_value_get_string (v);
479 if (!tp_strdiff (value, default_value))
481 DEBUG ("Unset %s and restore to %s", param_name, default_value);
482 empathy_account_settings_unset (priv->settings, param_name);
486 DEBUG ("Setting %s to %s", param_name, value);
487 empathy_account_settings_set_string (priv->settings, param_name, value);
490 empathy_account_widget_changed (self);
494 clear_icon_released_cb (GtkEntry *entry,
495 GtkEntryIconPosition icon_pos,
497 EmpathyAccountWidget *self)
499 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
500 const gchar *param_name;
502 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
504 DEBUG ("Unset %s", param_name);
505 empathy_account_settings_unset (priv->settings, param_name);
506 gtk_entry_set_text (entry, "");
508 empathy_account_widget_changed (self);
512 password_entry_changed_cb (GtkEditable *entry,
513 EmpathyAccountWidget *self)
517 str = gtk_entry_get_text (GTK_ENTRY (entry));
519 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
520 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
524 password_entry_activated_cb (GtkEntry *entry,
525 EmpathyAccountWidget *self)
527 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
529 if (gtk_widget_get_sensitive (priv->apply_button))
530 account_widget_apply_and_log_in (self);
534 account_entry_activated_cb (GtkEntry *entry,
535 EmpathyAccountWidget *self)
537 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
539 if (gtk_widget_get_sensitive (priv->apply_button))
540 account_widget_apply_and_log_in (self);
544 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
546 const gchar *param_name)
548 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
550 g_object_set_data_full (G_OBJECT (widget), "param_name",
551 g_strdup (param_name), g_free);
553 if (GTK_IS_SPIN_BUTTON (widget))
556 const gchar *signature;
558 signature = empathy_account_settings_get_dbus_signature (priv->settings,
560 g_return_if_fail (signature != NULL);
562 switch ((int)*signature)
564 case DBUS_TYPE_INT16:
565 case DBUS_TYPE_INT32:
566 value = empathy_account_settings_get_int32 (priv->settings,
569 case DBUS_TYPE_INT64:
570 value = empathy_account_settings_get_int64 (priv->settings,
573 case DBUS_TYPE_UINT16:
574 case DBUS_TYPE_UINT32:
575 value = empathy_account_settings_get_uint32 (priv->settings,
578 case DBUS_TYPE_UINT64:
579 value = empathy_account_settings_get_uint64 (priv->settings,
583 g_return_if_reached ();
586 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
588 g_signal_connect (widget, "value-changed",
589 G_CALLBACK (account_widget_int_changed_cb),
592 else if (GTK_IS_ENTRY (widget))
594 const gchar *str = NULL;
596 str = empathy_account_settings_get_string (priv->settings, param_name);
597 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
599 if (!tp_strdiff (param_name, "account"))
600 priv->param_account_widget = widget;
601 else if (!tp_strdiff (param_name, "password"))
602 priv->param_password_widget = widget;
604 if (strstr (param_name, "password"))
606 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
608 /* Add 'clear' icon */
609 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
610 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
612 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
613 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
615 g_signal_connect (widget, "icon-release",
616 G_CALLBACK (clear_icon_released_cb), self);
617 g_signal_connect (widget, "changed",
618 G_CALLBACK (password_entry_changed_cb), self);
619 g_signal_connect (widget, "activate",
620 G_CALLBACK (password_entry_activated_cb), self);
622 else if (strstr (param_name, "account"))
623 g_signal_connect (widget, "activate",
624 G_CALLBACK (account_entry_activated_cb), self);
627 g_signal_connect (widget, "changed",
628 G_CALLBACK (account_widget_entry_changed_cb), self);
629 g_signal_connect (widget, "map",
630 G_CALLBACK (account_widget_entry_map_cb), self);
632 else if (GTK_IS_TOGGLE_BUTTON (widget))
634 gboolean value = FALSE;
636 value = empathy_account_settings_get_boolean (priv->settings,
638 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
640 g_signal_connect (widget, "toggled",
641 G_CALLBACK (account_widget_checkbutton_toggled_cb),
644 else if (GTK_IS_COMBO_BOX (widget))
646 /* The combo box's model has to contain the param value in its first
647 * column (as a string) */
653 str = empathy_account_settings_get_string (priv->settings, param_name);
654 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
656 valid = gtk_tree_model_get_iter_first (model, &iter);
661 gtk_tree_model_get (model, &iter, 0, &name, -1);
662 if (!tp_strdiff (name, str))
664 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
669 valid = gtk_tree_model_iter_next (model, &iter);
675 g_signal_connect (widget, "changed",
676 G_CALLBACK (account_widget_combobox_changed_cb),
681 DEBUG ("Unknown type of widget for param %s", param_name);
684 gtk_widget_set_sensitive (widget,
685 empathy_account_settings_param_is_supported (priv->settings, param_name));
689 build_translated_params (void)
693 hash = g_hash_table_new (g_str_hash, g_str_equal);
694 g_hash_table_insert (hash, "account", _("Account"));
695 g_hash_table_insert (hash, "password", _("Password"));
696 g_hash_table_insert (hash, "server", _("Server"));
697 g_hash_table_insert (hash, "port", _("Port"));
703 account_widget_generic_format_param_name (const gchar *param_name)
707 static GHashTable *translated_params = NULL;
709 if (G_UNLIKELY (translated_params == NULL))
710 translated_params = build_translated_params ();
712 /* Translate most common parameters */
713 str = g_hash_table_lookup (translated_params, param_name);
715 return g_strdup (str);
717 str = g_strdup (param_name);
719 if (str && g_ascii_isalpha (str[0]))
720 str[0] = g_ascii_toupper (str[0]);
722 while ((p = strchr (str, '-')) != NULL)
724 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
727 p[1] = g_ascii_toupper (p[1]);
737 accounts_widget_generic_setup (EmpathyAccountWidget *self,
738 GtkWidget *table_common_settings,
739 GtkWidget *table_advanced_settings)
741 TpConnectionManagerParam *params, *param;
742 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
744 params = empathy_account_settings_get_tp_params (priv->settings);
746 for (param = params; param != NULL && param->name != NULL; param++)
748 GtkWidget *table_settings;
750 GtkWidget *widget = NULL;
751 gchar *param_name_formatted;
753 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
754 table_settings = table_common_settings;
755 else if (priv->simple)
758 table_settings = table_advanced_settings;
760 param_name_formatted = account_widget_generic_format_param_name
762 g_object_get (table_settings, "n-rows", &n_rows, NULL);
763 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
765 if (param->dbus_signature[0] == 's')
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_entry_new ();
783 if (strcmp (param->name, "account") == 0)
785 g_signal_connect (widget, "realize",
786 G_CALLBACK (gtk_widget_grab_focus),
789 gtk_table_attach (GTK_TABLE (table_settings),
793 GTK_FILL | GTK_EXPAND, 0,
795 gtk_widget_show (widget);
797 /* int types: ynqiuxt. double type is 'd' */
798 else if (param->dbus_signature[0] == 'y' ||
799 param->dbus_signature[0] == 'n' ||
800 param->dbus_signature[0] == 'q' ||
801 param->dbus_signature[0] == 'i' ||
802 param->dbus_signature[0] == 'u' ||
803 param->dbus_signature[0] == 'x' ||
804 param->dbus_signature[0] == 't' ||
805 param->dbus_signature[0] == 'd')
812 switch (param->dbus_signature[0])
814 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
815 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
816 case 'q': minint = 0; maxint = G_MAXUINT16; break;
817 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
818 case 'u': minint = 0; maxint = G_MAXUINT32; break;
819 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
820 case 't': minint = 0; maxint = G_MAXUINT64; break;
821 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
823 default: g_assert_not_reached ();
826 str = g_strdup_printf (_("%s:"), param_name_formatted);
827 widget = gtk_label_new (str);
828 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
831 gtk_table_attach (GTK_TABLE (table_settings),
837 gtk_widget_show (widget);
839 widget = gtk_spin_button_new_with_range (minint, maxint, step);
840 gtk_table_attach (GTK_TABLE (table_settings),
844 GTK_FILL | GTK_EXPAND, 0,
846 gtk_widget_show (widget);
848 else if (param->dbus_signature[0] == 'b')
850 widget = gtk_check_button_new_with_label (param_name_formatted);
851 gtk_table_attach (GTK_TABLE (table_settings),
855 GTK_FILL | GTK_EXPAND, 0,
857 gtk_widget_show (widget);
861 DEBUG ("Unknown signature for param %s: %s",
862 param_name_formatted, param->dbus_signature);
866 empathy_account_widget_setup_widget (self, widget, param->name);
868 g_free (param_name_formatted);
873 account_widget_handle_params_valist (EmpathyAccountWidget *self,
874 const gchar *first_widget,
880 for (name = first_widget; name; name = va_arg (args, const gchar *))
882 const gchar *param_name;
884 param_name = va_arg (args, const gchar *);
885 object = gtk_builder_get_object (self->ui_details->gui, name);
889 g_warning ("Builder is missing object '%s'.", name);
893 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
899 account_widget_cancel_clicked_cb (GtkWidget *button,
900 EmpathyAccountWidget *self)
902 g_signal_emit (self, signals[CANCELLED], 0);
906 account_widget_account_enabled_cb (GObject *source_object,
910 GError *error = NULL;
911 TpAccount *account = TP_ACCOUNT (source_object);
912 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
913 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
915 tp_account_set_enabled_finish (account, res, &error);
919 DEBUG ("Could not enable the account: %s", error->message);
920 g_error_free (error);
924 empathy_connect_new_account (account, priv->account_manager);
927 /* unref widget - part of the workaround */
928 g_object_unref (widget);
932 account_widget_applied_cb (GObject *source_object,
936 GError *error = NULL;
938 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
939 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
940 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
941 gboolean reconnect_required;
943 empathy_account_settings_apply_finish (settings, res, &reconnect_required,
948 DEBUG ("Could not apply changes to account: %s", error->message);
949 g_error_free (error);
953 account = empathy_account_settings_get_account (priv->settings);
957 if (priv->creating_account)
959 /* By default, when an account is created, we enable it. */
961 /* workaround to keep widget alive during async call */
962 g_object_ref (widget);
964 tp_account_set_enabled_async (account, TRUE,
965 account_widget_account_enabled_cb, widget);
966 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
970 /* If the account was offline, we always want to try reconnecting,
971 * to give it a chance to connect if the previous params were wrong.
972 * tp_account_reconnect_async() won't do anything if the requested
973 * presence is offline anyway. */
974 if (tp_account_get_connection_status (account, NULL) ==
975 TP_CONNECTION_STATUS_DISCONNECTED)
976 reconnect_required = TRUE;
978 if (reconnect_required && tp_account_is_enabled (account)
979 && tp_account_is_enabled (account))
981 /* After having applied changes to a user account, we
982 * reconnect it if needed. This is done so the new
983 * information entered by the user is validated on the server. */
984 tp_account_reconnect_async (account, NULL, NULL);
989 if (!priv->destroyed)
990 account_widget_set_control_buttons_sensitivity (widget, FALSE);
992 priv->contains_pending_changes = FALSE;
994 /* unref the widget - part of the workaround */
995 g_object_unref (widget);
999 account_widget_apply_and_log_in (EmpathyAccountWidget *self)
1001 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1002 gboolean display_name_overridden;
1004 if (priv->radiobutton_reuse != NULL)
1006 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
1007 priv->radiobutton_reuse));
1009 DEBUG ("Set register param: %d", !reuse);
1010 empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
1013 g_object_get (priv->settings,
1014 "display-name-overridden", &display_name_overridden, NULL);
1016 if (priv->creating_account || !display_name_overridden)
1018 gchar *display_name;
1020 /* set default display name for new accounts or update if user didn't
1021 * manually override it. */
1022 display_name = empathy_account_widget_get_default_display_name (self);
1024 empathy_account_settings_set_display_name_async (priv->settings,
1025 display_name, NULL, NULL);
1027 g_free (display_name);
1030 /* workaround to keep widget alive during async call */
1031 g_object_ref (self);
1032 empathy_account_settings_apply_async (priv->settings,
1033 account_widget_applied_cb, self);
1037 account_widget_apply_clicked_cb (GtkWidget *button,
1038 EmpathyAccountWidget *self)
1040 account_widget_apply_and_log_in (self);
1044 account_widget_setup_generic (EmpathyAccountWidget *self)
1046 GtkWidget *table_common_settings;
1047 GtkWidget *table_advanced_settings;
1049 table_common_settings = GTK_WIDGET (gtk_builder_get_object
1050 (self->ui_details->gui, "table_common_settings"));
1051 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
1052 (self->ui_details->gui, "table_advanced_settings"));
1054 accounts_widget_generic_setup (self, table_common_settings,
1055 table_advanced_settings);
1057 g_object_unref (self->ui_details->gui);
1061 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
1065 EmpathyAccountWidget *self = user_data;
1066 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1068 if (empathy_account_settings_is_ready (priv->settings))
1069 account_widget_setup_generic (self);
1073 account_widget_build_generic (EmpathyAccountWidget *self,
1074 const char *filename)
1076 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1077 GtkWidget *expander_advanced;
1079 self->ui_details->gui = empathy_builder_get_file (filename,
1080 "table_common_settings", &priv->table_common_settings,
1081 "vbox_generic_settings", &self->ui_details->widget,
1082 "expander_advanced_settings", &expander_advanced,
1086 gtk_widget_hide (expander_advanced);
1088 g_object_ref (self->ui_details->gui);
1090 if (empathy_account_settings_is_ready (priv->settings))
1091 account_widget_setup_generic (self);
1093 g_signal_connect (priv->settings, "notify::ready",
1094 G_CALLBACK (account_widget_settings_ready_cb), self);
1098 account_widget_launch_external_clicked (GtkWidget *button,
1101 GdkAppLaunchContext *context = NULL;
1102 GdkDisplay *display;
1104 GError *error = NULL;
1106 app_info = g_object_get_data (G_OBJECT (button), "app-info");
1108 g_return_if_fail (G_IS_APP_INFO (app_info));
1110 display = gdk_display_get_default ();
1111 context = gdk_display_get_app_launch_context (display);
1113 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1116 g_critical ("Failed to bisho: %s", error->message);
1117 g_clear_error (&error);
1122 account_widget_launch_external_clicked_meego (GtkWidget *button,
1125 if (!tp_strdiff (tp_account_get_storage_provider (account),
1126 "com.meego.libsocialweb"))
1128 /* we know how to handle this external provider */
1129 GDesktopAppInfo *desktop_info;
1130 GError *error = NULL;
1131 GdkAppLaunchContext *context = NULL;
1132 GdkDisplay *display;
1136 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
1137 if (desktop_info == NULL)
1139 g_critical ("Could not locate 'gnome-control-center.desktop'");
1143 /* glib doesn't have API to start a desktop file with args... (#637875) */
1144 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
1145 (GAppInfo *) desktop_info));
1147 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
1150 if (app_info == NULL)
1152 DEBUG ("Failed to create app info: %s", error->message);
1153 g_error_free (error);
1157 display = gdk_display_get_default ();
1158 context = gdk_display_get_app_launch_context (display);
1160 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1163 g_critical ("Failed to bisho: %s", error->message);
1164 g_clear_error (&error);
1168 g_object_unref (desktop_info);
1169 tp_clear_object (&app_info);
1170 tp_clear_object (&context);
1175 account_widget_build_external (EmpathyAccountWidget *self,
1176 EmpathyAccountSettings *settings)
1178 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1179 TpAccount *account = empathy_account_settings_get_account (settings);
1180 GtkWidget *bar, *widget;
1182 const gchar *provider, *name = NULL;
1183 GDesktopAppInfo *desktop_info = NULL;
1185 self->ui_details->widget = gtk_vbox_new (FALSE, 6);
1186 priv->table_common_settings = gtk_table_new (1, 2, FALSE);
1188 provider = tp_account_get_storage_provider (account);
1190 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
1192 name = _("My Web Accounts");
1194 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
1196 /* FIXME: we should publish the .desktop file in some general way */
1197 desktop_info = g_desktop_app_info_new (
1198 "gnome-online-accounts-panel.desktop");
1200 if (desktop_info == NULL)
1201 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
1203 name = g_app_info_get_name (G_APP_INFO (desktop_info));
1208 str = g_strdup_printf (
1209 _("The account %s is edited via %s."),
1210 empathy_account_settings_get_display_name (settings), name);
1214 str = g_strdup_printf (
1215 _("The account %s cannot be edited in Empathy."),
1216 empathy_account_settings_get_display_name (settings));
1219 widget = gtk_label_new (str);
1220 gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
1223 bar = gtk_info_bar_new ();
1224 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
1226 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))),
1228 gtk_container_set_border_width (GTK_CONTAINER (bar), 6);
1230 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
1232 /* we know how to handle this external provider */
1233 widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
1234 _("Launch My Web Accounts"), RESPONSE_LAUNCH);
1236 g_signal_connect (widget, "clicked",
1237 G_CALLBACK (account_widget_launch_external_clicked_meego), account);
1239 else if (desktop_info != NULL)
1241 /* general handler */
1242 str = g_strdup_printf (_("Edit %s"), name);
1244 widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
1245 str, RESPONSE_LAUNCH);
1247 g_object_set_data_full (G_OBJECT (widget), "app-info",
1248 g_object_ref (desktop_info), g_object_unref);
1250 g_signal_connect (widget, "clicked",
1251 G_CALLBACK (account_widget_launch_external_clicked), account);
1256 gtk_box_pack_start (GTK_BOX (self->ui_details->widget), bar,
1258 gtk_box_pack_start (GTK_BOX (self->ui_details->widget),
1259 priv->table_common_settings, FALSE, TRUE, 0);
1261 gtk_widget_show_all (self->ui_details->widget);
1263 tp_clear_object (&desktop_info);
1267 account_widget_build_salut (EmpathyAccountWidget *self,
1268 const char *filename)
1270 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1271 GtkWidget *expander_advanced;
1273 self->ui_details->gui = empathy_builder_get_file (filename,
1274 "table_common_settings", &priv->table_common_settings,
1275 "vbox_salut_settings", &self->ui_details->widget,
1276 "expander_advanced_settings", &expander_advanced,
1279 empathy_account_widget_handle_params (self,
1280 "entry_published", "published-name",
1281 "entry_nickname", "nickname",
1282 "entry_first_name", "first-name",
1283 "entry_last_name", "last-name",
1284 "entry_email", "email",
1289 gtk_widget_hide (expander_advanced);
1291 self->ui_details->default_focus = g_strdup ("entry_first_name");
1295 account_widget_build_irc (EmpathyAccountWidget *self,
1296 const char *filename)
1298 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1300 empathy_account_settings_set_regex (priv->settings, "account",
1302 empathy_account_settings_set_regex (priv->settings, "username",
1303 USERNAME_REGEX_IRC);
1307 priv->irc_network_chooser = empathy_account_widget_irc_build_simple (self,
1312 priv->irc_network_chooser = empathy_account_widget_irc_build (self,
1313 filename, &priv->table_common_settings);
1318 account_widget_build_sip (EmpathyAccountWidget *self,
1319 const char *filename)
1321 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1322 empathy_account_widget_sip_build (self, filename,
1323 &priv->table_common_settings);
1327 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1328 self->ui_details->gui, "remember_password_simple"));
1332 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1333 self->ui_details->gui, "remember_password"));
1338 account_widget_build_msn (EmpathyAccountWidget *self,
1339 const char *filename)
1341 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1343 empathy_account_settings_set_regex (priv->settings, "account",
1348 self->ui_details->gui = empathy_builder_get_file (filename,
1349 "vbox_msn_simple", &self->ui_details->widget,
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 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1360 self->ui_details->gui, "remember_password_simple"));
1364 self->ui_details->gui = empathy_builder_get_file (filename,
1365 "table_common_msn_settings", &priv->table_common_settings,
1366 "vbox_msn_settings", &self->ui_details->widget,
1369 empathy_account_widget_handle_params (self,
1370 "entry_id", "account",
1371 "entry_password", "password",
1372 "entry_server", "server",
1373 "spinbutton_port", "port",
1376 self->ui_details->default_focus = g_strdup ("entry_id");
1378 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1379 self->ui_details->gui, "remember_password"));
1384 suffix_id_widget_changed_cb (GtkWidget *entry,
1385 EmpathyAccountWidget *self)
1387 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1388 const gchar *account;
1390 g_assert (priv->jid_suffix != NULL);
1392 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1394 account = empathy_account_settings_get_string (priv->settings, "account");
1395 if (!EMP_STR_EMPTY (account) &&
1396 !g_str_has_suffix (account, priv->jid_suffix))
1400 tmp = g_strdup_printf ("%s%s", account, priv->jid_suffix);
1402 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1404 empathy_account_settings_set_string (priv->settings, "account", tmp);
1408 empathy_account_widget_changed (self);
1412 remove_jid_suffix (EmpathyAccountWidget *self,
1415 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1417 g_assert (priv->jid_suffix != NULL);
1419 if (!g_str_has_suffix (str, priv->jid_suffix))
1420 return g_strdup (str);
1422 return g_strndup (str, strlen (str) - strlen (priv->jid_suffix));
1426 setup_id_widget_with_suffix (EmpathyAccountWidget *self,
1428 const gchar *suffix)
1430 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1431 const gchar *str = NULL;
1433 g_object_set_data_full (G_OBJECT (widget), "param_name",
1434 g_strdup ("account"), g_free);
1436 g_assert (priv->jid_suffix == NULL);
1437 priv->jid_suffix = g_strdup (suffix);
1439 str = empathy_account_settings_get_string (priv->settings, "account");
1444 tmp = remove_jid_suffix (self, str);
1445 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1449 priv->param_account_widget = widget;
1451 g_signal_connect (widget, "changed",
1452 G_CALLBACK (suffix_id_widget_changed_cb), self);
1456 account_widget_get_service (EmpathyAccountWidget *self)
1458 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1459 const gchar *icon_name, *service;
1461 icon_name = empathy_account_settings_get_icon_name (priv->settings);
1462 service = empathy_account_settings_get_service (priv->settings);
1464 /* Previous versions of Empathy didn't set the Service property on Facebook
1465 * and gtalk accounts, so we check using the icon name as well. */
1466 if (!tp_strdiff (icon_name, "im-google-talk") ||
1467 !tp_strdiff (service, "google-talk"))
1468 return GTALK_SERVICE;
1470 if (!tp_strdiff (icon_name, "im-facebook") ||
1471 !tp_strdiff (service, "facebook"))
1472 return FACEBOOK_SERVICE;
1478 account_widget_build_jabber (EmpathyAccountWidget *self,
1479 const char *filename)
1481 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1482 GtkWidget *spinbutton_port;
1483 GtkWidget *checkbutton_ssl;
1484 GtkWidget *label_id, *label_password;
1485 GtkWidget *label_id_create, *label_password_create;
1486 GtkWidget *label_example_fb;
1487 GtkWidget *label_example;
1488 GtkWidget *expander_advanced;
1489 GtkWidget *entry_id;
1492 service = account_widget_get_service (self);
1494 empathy_account_settings_set_regex (priv->settings, "account",
1495 ACCOUNT_REGEX_JABBER);
1497 if (priv->simple && service == NO_SERVICE)
1499 /* Simple widget for XMPP */
1500 self->ui_details->gui = empathy_builder_get_file (filename,
1501 "vbox_jabber_simple", &self->ui_details->widget,
1502 "label_id_simple", &label_id,
1503 "label_id_create", &label_id_create,
1504 "label_password_simple", &label_password,
1505 "label_password_create", &label_password_create,
1508 if (empathy_account_settings_get_boolean (priv->settings, "register"))
1510 gtk_widget_hide (label_id);
1511 gtk_widget_hide (label_password);
1512 gtk_widget_show (label_id_create);
1513 gtk_widget_show (label_password_create);
1516 empathy_account_widget_handle_params (self,
1517 "entry_id_simple", "account",
1518 "entry_password_simple", "password",
1521 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1523 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1524 self->ui_details->gui, "remember_password_simple"));
1526 else if (priv->simple && service == GTALK_SERVICE)
1528 /* Simple widget for Google Talk */
1529 self->ui_details->gui = empathy_builder_get_file (filename,
1530 "vbox_gtalk_simple", &self->ui_details->widget,
1533 empathy_account_widget_handle_params (self,
1534 "entry_id_g_simple", "account",
1535 "entry_password_g_simple", "password",
1538 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1540 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1541 self->ui_details->gui, "remember_password_g_simple"));
1543 else if (priv->simple && service == FACEBOOK_SERVICE)
1545 /* Simple widget for Facebook */
1546 self->ui_details->gui = empathy_builder_get_file (filename,
1547 "vbox_fb_simple", &self->ui_details->widget,
1548 "entry_id_fb_simple", &entry_id,
1551 empathy_account_widget_handle_params (self,
1552 "entry_password_fb_simple", "password",
1555 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1557 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1559 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1560 self->ui_details->gui, "remember_password_fb_simple"));
1564 ServiceInfo info = services_infos[service];
1566 /* Full widget for XMPP, Google Talk and Facebook*/
1567 self->ui_details->gui = empathy_builder_get_file (filename,
1568 "table_common_settings", &priv->table_common_settings,
1569 "vbox_jabber_settings", &self->ui_details->widget,
1570 "spinbutton_port", &spinbutton_port,
1571 "checkbutton_ssl", &checkbutton_ssl,
1572 "label_username_f_example", &label_example_fb,
1573 info.label_username_example, &label_example,
1574 "expander_advanced", &expander_advanced,
1575 "entry_id", &entry_id,
1576 "label_id", &label_id,
1579 empathy_account_widget_handle_params (self,
1580 "entry_password", "password",
1581 "entry_resource", "resource",
1582 "entry_server", "server",
1583 "spinbutton_port", "port",
1584 "spinbutton_priority", "priority",
1585 "checkbutton_ssl", "old-ssl",
1586 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1587 "checkbutton_encryption", "require-encryption",
1590 if (service == FACEBOOK_SERVICE)
1592 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1594 /* Facebook special case the entry ID widget to hide the
1595 * "@chat.facebook.com" part */
1596 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1600 empathy_account_widget_setup_widget (self, entry_id, "account");
1603 self->ui_details->default_focus = g_strdup ("entry_id");
1604 priv->spinbutton_port = spinbutton_port;
1606 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1607 self->ui_details->gui, "remember_password"));
1609 g_signal_connect (checkbutton_ssl, "toggled",
1610 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1613 if (service == FACEBOOK_SERVICE)
1615 GtkContainer *parent;
1618 /* Removing the label from list of focusable widgets */
1619 parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
1620 children = gtk_container_get_children (parent);
1621 children = g_list_remove (children, label_example_fb);
1622 gtk_container_set_focus_chain (parent, children);
1623 g_list_free (children);
1626 gtk_widget_show (label_example);
1628 if (!info.show_advanced)
1629 gtk_widget_hide (expander_advanced);
1634 account_widget_build_icq (EmpathyAccountWidget *self,
1635 const char *filename)
1637 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1638 GtkWidget *spinbutton_port;
1640 empathy_account_settings_set_regex (priv->settings, "account",
1645 self->ui_details->gui = empathy_builder_get_file (filename,
1646 "vbox_icq_simple", &self->ui_details->widget,
1649 empathy_account_widget_handle_params (self,
1650 "entry_uin_simple", "account",
1651 "entry_password_simple", "password",
1654 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1656 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1657 self->ui_details->gui, "remember_password_simple"));
1661 self->ui_details->gui = empathy_builder_get_file (filename,
1662 "table_common_settings", &priv->table_common_settings,
1663 "vbox_icq_settings", &self->ui_details->widget,
1664 "spinbutton_port", &spinbutton_port,
1667 empathy_account_widget_handle_params (self,
1668 "entry_uin", "account",
1669 "entry_password", "password",
1670 "entry_server", "server",
1671 "spinbutton_port", "port",
1672 "entry_charset", "charset",
1675 self->ui_details->default_focus = g_strdup ("entry_uin");
1677 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1678 self->ui_details->gui, "remember_password"));
1683 account_widget_build_aim (EmpathyAccountWidget *self,
1684 const char *filename)
1686 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1687 GtkWidget *spinbutton_port;
1691 self->ui_details->gui = empathy_builder_get_file (filename,
1692 "vbox_aim_simple", &self->ui_details->widget,
1695 empathy_account_widget_handle_params (self,
1696 "entry_screenname_simple", "account",
1697 "entry_password_simple", "password",
1700 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1702 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1703 self->ui_details->gui, "remember_password_simple"));
1707 self->ui_details->gui = empathy_builder_get_file (filename,
1708 "table_common_settings", &priv->table_common_settings,
1709 "vbox_aim_settings", &self->ui_details->widget,
1710 "spinbutton_port", &spinbutton_port,
1713 empathy_account_widget_handle_params (self,
1714 "entry_screenname", "account",
1715 "entry_password", "password",
1716 "entry_server", "server",
1717 "spinbutton_port", "port",
1720 self->ui_details->default_focus = g_strdup ("entry_screenname");
1722 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1723 self->ui_details->gui, "remember_password"));
1728 account_widget_build_yahoo (EmpathyAccountWidget *self,
1729 const char *filename)
1731 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1733 empathy_account_settings_set_regex (priv->settings, "account",
1734 ACCOUNT_REGEX_YAHOO);
1738 self->ui_details->gui = empathy_builder_get_file (filename,
1739 "vbox_yahoo_simple", &self->ui_details->widget,
1742 empathy_account_widget_handle_params (self,
1743 "entry_id_simple", "account",
1744 "entry_password_simple", "password",
1747 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1749 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1750 self->ui_details->gui, "remember_password_simple"));
1754 self->ui_details->gui = empathy_builder_get_file (filename,
1755 "table_common_settings", &priv->table_common_settings,
1756 "vbox_yahoo_settings", &self->ui_details->widget,
1759 empathy_account_widget_handle_params (self,
1760 "entry_id", "account",
1761 "entry_password", "password",
1762 "entry_locale", "room-list-locale",
1763 "entry_charset", "charset",
1764 "spinbutton_port", "port",
1765 "checkbutton_ignore_invites", "ignore-invites",
1768 self->ui_details->default_focus = g_strdup ("entry_id");
1770 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1771 self->ui_details->gui, "remember_password"));
1776 account_widget_build_groupwise (EmpathyAccountWidget *self,
1777 const char *filename)
1779 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1783 self->ui_details->gui = empathy_builder_get_file (filename,
1784 "vbox_groupwise_simple", &self->ui_details->widget,
1787 empathy_account_widget_handle_params (self,
1788 "entry_id_simple", "account",
1789 "entry_password_simple", "password",
1792 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1794 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1795 self->ui_details->gui, "remember_password_simple"));
1799 self->ui_details->gui = empathy_builder_get_file (filename,
1800 "table_common_groupwise_settings", &priv->table_common_settings,
1801 "vbox_groupwise_settings", &self->ui_details->widget,
1804 empathy_account_widget_handle_params (self,
1805 "entry_id", "account",
1806 "entry_password", "password",
1807 "entry_server", "server",
1808 "spinbutton_port", "port",
1811 self->ui_details->default_focus = g_strdup ("entry_id");
1813 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1814 self->ui_details->gui, "remember_password"));
1819 account_widget_destroy_cb (GtkWidget *widget,
1820 EmpathyAccountWidget *self)
1822 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1823 /* set the destroyed flag - workaround */
1824 priv->destroyed = TRUE;
1826 g_object_unref (self);
1830 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1831 gboolean others_exist)
1833 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1835 priv->other_accounts_exist = others_exist;
1837 if (priv->creating_account)
1838 account_widget_handle_control_buttons_sensitivity (self);
1842 do_set_property (GObject *object,
1844 const GValue *value,
1847 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1852 priv->settings = g_value_dup_object (value);
1855 priv->simple = g_value_get_boolean (value);
1857 case PROP_CREATING_ACCOUNT:
1858 priv->creating_account = g_value_get_boolean (value);
1860 case PROP_OTHER_ACCOUNTS_EXIST:
1861 empathy_account_widget_set_other_accounts_exist (
1862 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1865 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1870 do_get_property (GObject *object,
1875 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1880 g_value_set_string (value,
1881 empathy_account_settings_get_protocol (priv->settings));
1884 g_value_set_object (value, priv->settings);
1887 g_value_set_boolean (value, priv->simple);
1889 case PROP_CREATING_ACCOUNT:
1890 g_value_set_boolean (value, priv->creating_account);
1892 case PROP_OTHER_ACCOUNTS_EXIST:
1893 g_value_set_boolean (value, priv->other_accounts_exist);
1896 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1901 set_apply_button (EmpathyAccountWidget *self)
1903 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1906 /* We can't use the stock button as its accelerator ('A') clashes with the
1908 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1910 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("A_pply"));
1911 gtk_button_set_use_underline (GTK_BUTTON (priv->apply_button), TRUE);
1913 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1914 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1918 presence_changed_cb (TpAccountManager *manager,
1919 TpConnectionPresenceType state,
1920 const gchar *status,
1921 const gchar *message,
1922 EmpathyAccountWidget *self)
1924 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1926 if (priv->destroyed)
1929 if (priv->apply_button == NULL)
1930 /* This button doesn't exist in 'simple' mode */
1933 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1934 priv->creating_account)
1936 /* We are online and creating a new account, display a Login button */
1939 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1940 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1942 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1943 GTK_ICON_SIZE_BUTTON);
1944 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1948 /* We are offline or modifying an existing account, display
1950 set_apply_button (self);
1955 account_manager_ready_cb (GObject *source_object,
1956 GAsyncResult *result,
1959 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1960 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1961 GError *error = NULL;
1962 TpConnectionPresenceType state;
1964 if (!tp_proxy_prepare_finish (account_manager, result, &error))
1966 DEBUG ("Failed to prepare account manager: %s", error->message);
1967 g_error_free (error);
1971 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1974 /* simulate a presence change so the apply button will be changed
1976 presence_changed_cb (account_manager, state, NULL, NULL, self);
1979 g_object_unref (self);
1982 #define WIDGET(cm, proto) \
1983 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1984 account_widget_build_##proto }
1987 /* Meego doesn't support registration */
1989 add_register_buttons (EmpathyAccountWidget *self,
1992 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1993 const TpConnectionManagerProtocol *protocol;
1994 GtkWidget *radiobutton_register;
1995 GtkWidget *vbox = self->ui_details->widget;
1997 if (!priv->creating_account)
2000 protocol = empathy_account_settings_get_tp_protocol (priv->settings);
2001 if (protocol == NULL)
2004 if (!tp_connection_manager_protocol_can_register (protocol))
2007 if (account_widget_get_service (self) != NO_SERVICE)
2013 priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
2014 _("This account already exists on the server"));
2015 radiobutton_register = gtk_radio_button_new_with_label (
2016 gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
2017 _("Create a new account on the server"));
2019 gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
2020 gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
2021 gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
2022 gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
2023 gtk_widget_show (priv->radiobutton_reuse);
2024 gtk_widget_show (radiobutton_register);
2026 #endif /* HAVE_MEEGO */
2029 remember_password_toggled_cb (GtkToggleButton *button,
2030 EmpathyAccountWidget *self)
2032 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2034 if (gtk_toggle_button_get_active (button))
2036 gtk_widget_set_sensitive (priv->param_password_widget, TRUE);
2040 gtk_widget_set_sensitive (priv->param_password_widget, FALSE);
2041 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), "");
2042 empathy_account_settings_unset (priv->settings, "password");
2047 account_settings_password_retrieved_cb (GObject *object,
2050 EmpathyAccountWidget *self = user_data;
2051 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2052 const gchar *password = empathy_account_settings_get_string (
2053 priv->settings, "password");
2055 if (password != NULL)
2057 /* We have to do this so that when we call gtk_entry_set_text,
2058 * the ::changed callback doesn't think the user made the
2060 priv->automatic_change = TRUE;
2061 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), password);
2062 priv->automatic_change = FALSE;
2065 gtk_toggle_button_set_active (
2066 GTK_TOGGLE_BUTTON (priv->remember_password_widget),
2067 !EMP_STR_EMPTY (password));
2071 do_constructed (GObject *obj)
2073 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2074 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2076 TpStorageRestrictionFlags storage_restrictions;
2077 const gchar *display_name, *default_display_name;
2080 const gchar *cm_name;
2081 const gchar *protocol;
2083 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
2085 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
2086 account_widget_build_salut },
2087 WIDGET (gabble, jabber),
2088 WIDGET (butterfly, msn),
2091 WIDGET (haze, yahoo),
2092 WIDGET (haze, groupwise),
2094 WIDGET (sofiasip, sip),
2097 account = empathy_account_settings_get_account (priv->settings);
2099 if (account != NULL)
2100 storage_restrictions = tp_account_get_storage_restrictions (account);
2102 storage_restrictions = 0;
2104 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
2105 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
2107 DEBUG ("Account is provided by an external storage provider");
2109 account_widget_build_external (self, priv->settings);
2113 const gchar *protocol, *cm_name;
2115 cm_name = empathy_account_settings_get_cm (priv->settings);
2116 protocol = empathy_account_settings_get_protocol (priv->settings);
2118 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
2120 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
2121 !tp_strdiff (widgets[i].protocol, protocol))
2125 filename = empathy_file_lookup (widgets[i].file,
2127 widgets[i].func (self, filename);
2134 if (i == G_N_ELEMENTS (widgets))
2136 gchar *filename = empathy_file_lookup (
2137 "empathy-account-widget-generic.ui", "libempathy-gtk");
2138 account_widget_build_generic (self, filename);
2143 /* handle default focus */
2144 if (self->ui_details->default_focus != NULL)
2146 GObject *default_focus_entry;
2148 default_focus_entry = gtk_builder_get_object
2149 (self->ui_details->gui, self->ui_details->default_focus);
2150 g_signal_connect (default_focus_entry, "realize",
2151 G_CALLBACK (gtk_widget_grab_focus),
2155 /* remember password */
2156 if (priv->param_password_widget != NULL
2157 && priv->remember_password_widget != NULL
2158 && empathy_account_settings_supports_sasl (priv->settings))
2162 gtk_toggle_button_set_active (
2163 GTK_TOGGLE_BUTTON (priv->remember_password_widget), TRUE);
2167 gtk_toggle_button_set_active (
2168 GTK_TOGGLE_BUTTON (priv->remember_password_widget),
2169 !EMP_STR_EMPTY (empathy_account_settings_get_string (
2170 priv->settings, "password")));
2172 /* The password might not have been retrieved from the
2173 * keyring yet. We should update the remember password
2174 * toggle button and the password entry when/if it is. */
2175 tp_g_signal_connect_object (priv->settings, "password-retrieved",
2176 G_CALLBACK (account_settings_password_retrieved_cb), self, 0);
2179 g_signal_connect (priv->remember_password_widget, "toggled",
2180 G_CALLBACK (remember_password_toggled_cb), self);
2182 remember_password_toggled_cb (
2183 GTK_TOGGLE_BUTTON (priv->remember_password_widget), self);
2185 else if (priv->remember_password_widget != NULL
2186 && !empathy_account_settings_supports_sasl (priv->settings))
2188 gtk_widget_set_visible (priv->remember_password_widget, FALSE);
2191 /* dup and init the account-manager */
2192 priv->account_manager = tp_account_manager_dup ();
2194 g_object_ref (self);
2195 tp_proxy_prepare_async (priv->account_manager, NULL,
2196 account_manager_ready_cb, self);
2198 /* handle apply and cancel button */
2199 if (!priv->simple &&
2200 !(storage_restrictions &
2201 TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS))
2203 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
2206 /* We can't use the stock button as its accelerator ('C') clashes with
2207 * the Close button. */
2208 priv->cancel_button = gtk_button_new ();
2209 gtk_button_set_label (GTK_BUTTON (priv->cancel_button), _("Ca_ncel"));
2210 gtk_button_set_use_underline (GTK_BUTTON (priv->cancel_button), TRUE);
2212 image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
2213 gtk_button_set_image (GTK_BUTTON (priv->cancel_button), image);
2215 priv->apply_button = gtk_button_new ();
2216 set_apply_button (self);
2218 /* We'll change this button to a "Log in" one if we are creating a new
2219 * account and are connected. */
2220 tp_g_signal_connect_object (priv->account_manager,
2221 "most-available-presence-changed",
2222 G_CALLBACK (presence_changed_cb), obj, 0);
2224 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
2226 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
2229 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
2232 g_signal_connect (priv->cancel_button, "clicked",
2233 G_CALLBACK (account_widget_cancel_clicked_cb),
2235 g_signal_connect (priv->apply_button, "clicked",
2236 G_CALLBACK (account_widget_apply_clicked_cb),
2238 gtk_widget_show_all (hbox);
2240 if (priv->creating_account)
2241 /* When creating an account, the user might have nothing to enter.
2242 * That means that no control interaction might occur,
2243 * so we update the control button sensitivity manually.
2245 account_widget_handle_control_buttons_sensitivity (self);
2247 account_widget_set_control_buttons_sensitivity (self, FALSE);
2251 add_register_buttons (self, account);
2252 #endif /* HAVE_MEEGO */
2254 /* hook up to widget destruction to unref ourselves */
2255 g_signal_connect (self->ui_details->widget, "destroy",
2256 G_CALLBACK (account_widget_destroy_cb), self);
2258 if (self->ui_details->gui != NULL)
2260 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
2261 self->ui_details->widget);
2262 self->ui_details->gui = NULL;
2265 display_name = empathy_account_settings_get_display_name (priv->settings);
2266 default_display_name = empathy_account_widget_get_default_display_name (self);
2268 if (tp_strdiff (display_name, default_display_name) &&
2269 !priv->creating_account)
2271 /* The display name of the account is not the one that we'd assign by
2272 * default; assume that the user changed it manually */
2273 g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
2278 do_dispose (GObject *obj)
2280 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2281 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2283 if (priv->dispose_run)
2286 priv->dispose_run = TRUE;
2288 if (priv->settings != NULL)
2290 g_object_unref (priv->settings);
2291 priv->settings = NULL;
2294 if (priv->account_manager != NULL)
2296 g_object_unref (priv->account_manager);
2297 priv->account_manager = NULL;
2300 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
2301 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
2305 do_finalize (GObject *obj)
2307 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2308 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2310 g_free (self->ui_details->default_focus);
2311 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
2313 g_free (priv->jid_suffix);
2315 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
2316 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
2320 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
2322 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2323 GParamSpec *param_spec;
2325 oclass->get_property = do_get_property;
2326 oclass->set_property = do_set_property;
2327 oclass->constructed = do_constructed;
2328 oclass->dispose = do_dispose;
2329 oclass->finalize = do_finalize;
2331 param_spec = g_param_spec_string ("protocol",
2332 "protocol", "The protocol of the account",
2334 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2335 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2337 param_spec = g_param_spec_object ("settings",
2338 "settings", "The settings of the account",
2339 EMPATHY_TYPE_ACCOUNT_SETTINGS,
2340 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2341 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2343 param_spec = g_param_spec_boolean ("simple",
2344 "simple", "Whether the account widget is a simple or an advanced one",
2346 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2347 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2349 param_spec = g_param_spec_boolean ("creating-account",
2351 "TRUE if we're creating an account, FALSE if we're modifying it",
2353 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2354 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2356 param_spec = g_param_spec_boolean ("other-accounts-exist",
2357 "other-accounts-exist",
2358 "TRUE if there are any other accounts (even if this isn't yet saved)",
2360 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2361 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2364 signals[HANDLE_APPLY] =
2365 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2366 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2367 g_cclosure_marshal_generic,
2371 /* This signal is emitted when an account has been created and enabled. */
2372 signals[ACCOUNT_CREATED] =
2373 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2374 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2375 g_cclosure_marshal_generic,
2379 signals[CANCELLED] =
2380 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2381 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2382 g_cclosure_marshal_generic,
2386 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
2390 empathy_account_widget_init (EmpathyAccountWidget *self)
2392 EmpathyAccountWidgetPriv *priv =
2393 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
2394 EmpathyAccountWidgetPriv);
2397 priv->dispose_run = FALSE;
2399 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
2402 /* public methods */
2405 empathy_account_widget_discard_pending_changes
2406 (EmpathyAccountWidget *widget)
2408 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2410 empathy_account_settings_discard_changes (priv->settings);
2411 priv->contains_pending_changes = FALSE;
2415 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
2417 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2419 return priv->contains_pending_changes;
2423 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
2424 const gchar *first_widget,
2429 va_start (args, first_widget);
2430 account_widget_handle_params_valist (self, first_widget, args);
2435 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
2437 return widget->ui_details->widget;
2440 EmpathyAccountWidget *
2441 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
2444 EmpathyAccountWidget *self;
2446 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
2449 (EMPATHY_TYPE_ACCOUNT_WIDGET,
2450 "settings", settings, "simple", simple,
2452 empathy_account_settings_get_account (settings) == NULL,
2459 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
2461 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2462 const gchar *login_id;
2463 const gchar *protocol, *p;
2464 gchar *default_display_name;
2467 login_id = empathy_account_settings_get_string (priv->settings, "account");
2468 protocol = empathy_account_settings_get_protocol (priv->settings);
2469 service = account_widget_get_service (self);
2471 if (login_id != NULL)
2473 /* TODO: this should be done in empathy-account-widget-irc */
2474 if (!tp_strdiff (protocol, "irc"))
2476 EmpathyIrcNetwork *network;
2478 network = empathy_irc_network_chooser_get_network (
2479 priv->irc_network_chooser);
2480 g_assert (network != NULL);
2482 /* To translators: The first parameter is the login id and the
2483 * second one is the network. The resulting string will be something
2484 * like: "MyUserName on freenode".
2485 * You should reverse the order of these arguments if the
2486 * server should come before the login id in your locale.*/
2487 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2488 login_id, empathy_irc_network_get_name (network));
2490 else if (service == FACEBOOK_SERVICE)
2494 tmp = remove_jid_suffix (self, login_id);
2495 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2500 default_display_name = g_strdup (login_id);
2503 return default_display_name;
2506 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2509 if (protocol != NULL)
2511 /* To translators: The parameter is the protocol name. The resulting
2512 * string will be something like: "Jabber Account" */
2513 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2517 default_display_name = g_strdup (_("New account"));
2520 return default_display_name;
2523 /* Used by subclass to indicate that widget contains pending changes */
2525 empathy_account_widget_changed (EmpathyAccountWidget *self)
2527 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2529 account_widget_handle_control_buttons_sensitivity (self);
2530 priv->contains_pending_changes = TRUE;
2534 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2535 const gchar *account)
2537 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2539 if (priv->param_account_widget == NULL)
2542 gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
2546 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2547 const gchar *account)
2549 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2551 if (priv->param_password_widget == NULL)
2554 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);
2557 EmpathyAccountSettings *
2558 empathy_account_widget_get_settings (EmpathyAccountWidget *self)
2560 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2562 return priv->settings;