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)
67 const gchar *label_username_example;
68 gboolean show_advanced;
71 static ServiceInfo services_infos[N_SERVICES] = {
72 { "label_username_example", TRUE },
73 { "label_username_g_example", TRUE },
74 { "label_username_f_example", FALSE },
78 EmpathyAccountSettings *settings;
80 GtkWidget *table_common_settings;
81 GtkWidget *apply_button;
82 GtkWidget *cancel_button;
83 GtkWidget *entry_password;
84 GtkWidget *spinbutton_port;
85 GtkWidget *enabled_checkbox;
86 GtkWidget *radiobutton_reuse;
90 gboolean contains_pending_changes;
92 /* An EmpathyAccountWidget can be used to either create an account or
93 * modify it. When we are creating an account, this member is set to TRUE */
94 gboolean creating_account;
96 /* whether there are any other real accounts. Necessary so we know whether
97 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
98 * button should be sensitive) */
99 gboolean other_accounts_exist;
101 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
102 * embedded in this account widget can't be used any more
103 * workaround because some async callbacks can be called after the
104 * widget has been destroyed */
107 TpAccountManager *account_manager;
109 GtkWidget *param_account_widget;
110 GtkWidget *param_password_widget;
112 gboolean automatic_change;
113 GtkWidget *remember_password_widget;
115 /* Used only for IRC accounts */
116 EmpathyIrcNetworkChooser *irc_network_chooser;
118 /* Used for 'special' XMPP account having a service associated ensuring that
119 * JIDs have a specific suffix; such as Facebook for example */
122 gboolean dispose_run;
123 } EmpathyAccountWidgetPriv;
129 PROP_CREATING_ACCOUNT,
130 PROP_OTHER_ACCOUNTS_EXIST,
140 static void account_widget_apply_and_log_in (EmpathyAccountWidget *);
146 static guint signals[LAST_SIGNAL] = { 0 };
148 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
149 #define CHANGED_TIMEOUT 300
152 #define DIGITS "(["DIGIT"]+)"
153 #define ALPHA "a-zA-Z"
154 #define ALPHAS "(["ALPHA"]+)"
155 #define ALPHADIGIT ALPHA DIGIT
156 #define ALPHADIGITS "(["ALPHADIGIT"]+)"
157 #define ALPHADIGITDASH ALPHA DIGIT "-"
158 #define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
160 #define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
161 #define TOPLABEL ALPHAS"|(["ALPHA"]" ALPHADIGITDASHS "["ALPHADIGIT"])"
162 #define DOMAINLABEL ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
164 #define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
165 /* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
166 #define HOST "("HOSTNAME "|" HOSTNUMBER")"
167 /* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
168 #define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
170 /* UIN is digital according to the unofficial specification:
171 * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
172 * 5 digits minimum according to http://en.wikipedia.org/wiki/ICQ#UIN
173 * According to an user, we can also provide an email address instead of the
175 #define ICQ_USER_NAME "((["DIGIT"]{5,})|"EMAIL_LOCALPART"@"HOST")"
177 /* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
178 #define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
179 #define IRC_USER_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
180 /* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
181 * We just exclude invalid characters to avoid ucschars and other redundant
183 #define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
184 /* ID is an email according to the unofficial specification:
185 * http://www.hypothetic.org/docs/msn/general/names.php */
186 #define MSN_USER_NAME EMAIL_LOCALPART
187 /* Based on the official help:
188 * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html */
189 #define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})"
191 #define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
192 #define ACCOUNT_REGEX_IRC "^"IRC_USER_NAME"$"
193 #define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@"HOST"$"
194 #define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
195 #define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
198 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
201 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
205 /* we hit this case because of the 'other-accounts-exist' property handler
206 * being called during init (before constructed()) */
207 if (priv->apply_button == NULL || priv->cancel_button == NULL)
210 gtk_widget_set_sensitive (priv->apply_button, sensitive);
211 gtk_widget_set_sensitive (priv->cancel_button,
212 (sensitive || priv->creating_account) && priv->other_accounts_exist);
216 /* We can't grab default if the widget hasn't be packed in a
220 window = gtk_widget_get_toplevel (priv->apply_button);
221 if (window != NULL &&
222 gtk_widget_is_toplevel (window))
224 gtk_widget_set_can_default (priv->apply_button, TRUE);
225 gtk_widget_grab_default (priv->apply_button);
232 account_widget_set_entry_highlighting (GtkEntry *entry,
235 g_return_if_fail (GTK_IS_ENTRY (entry));
239 GtkStyleContext *style;
242 style = gtk_widget_get_style_context (GTK_WIDGET (entry));
243 gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
246 /* Here we take the current theme colour and add it to
247 * the colour for white and average the two. This
248 * gives a colour which is inline with the theme but
251 empathy_make_color_whiter (&color);
253 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, &color);
257 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, NULL);
262 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
264 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
267 is_valid = empathy_account_settings_is_valid (priv->settings);
270 account_widget_set_control_buttons_sensitivity (self, is_valid);
272 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
276 account_widget_entry_changed_common (EmpathyAccountWidget *self,
277 GtkEntry *entry, gboolean focus)
280 const gchar *param_name;
281 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
282 gboolean prev_status;
283 gboolean curr_status;
285 str = gtk_entry_get_text (entry);
286 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
287 prev_status = empathy_account_settings_parameter_is_valid (priv->settings,
290 if (EMP_STR_EMPTY (str))
292 const gchar *value = NULL;
294 empathy_account_settings_unset (priv->settings, param_name);
298 value = empathy_account_settings_get_string (priv->settings,
300 DEBUG ("Unset %s and restore to %s", param_name, value);
301 gtk_entry_set_text (entry, value ? value : "");
306 DEBUG ("Setting %s to %s", param_name,
307 tp_strdiff (param_name, "password") ? str : "***");
308 empathy_account_settings_set_string (priv->settings, param_name, str);
311 curr_status = empathy_account_settings_parameter_is_valid (priv->settings,
313 if (curr_status != prev_status)
314 account_widget_set_entry_highlighting (entry, !curr_status);
318 account_widget_entry_changed_cb (GtkEditable *entry,
319 EmpathyAccountWidget *self)
321 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
323 if (priv->automatic_change)
326 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
327 empathy_account_widget_changed (self);
331 account_widget_entry_map_cb (GtkEntry *entry,
332 EmpathyAccountWidget *self)
334 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
335 const gchar *param_name;
338 /* need to initialize input highlighting */
339 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
340 is_valid = empathy_account_settings_parameter_is_valid (priv->settings,
342 account_widget_set_entry_highlighting (entry, !is_valid);
346 account_widget_int_changed_cb (GtkWidget *widget,
347 EmpathyAccountWidget *self)
349 const gchar *param_name;
351 const gchar *signature;
352 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
354 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
355 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
357 signature = empathy_account_settings_get_dbus_signature (priv->settings,
359 g_return_if_fail (signature != NULL);
361 DEBUG ("Setting %s to %d", param_name, value);
363 switch ((int)*signature)
365 case DBUS_TYPE_INT16:
366 case DBUS_TYPE_INT32:
367 empathy_account_settings_set_int32 (priv->settings, param_name, value);
369 case DBUS_TYPE_INT64:
370 empathy_account_settings_set_int64 (priv->settings, param_name, value);
372 case DBUS_TYPE_UINT16:
373 case DBUS_TYPE_UINT32:
374 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
376 case DBUS_TYPE_UINT64:
377 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
380 g_return_if_reached ();
383 empathy_account_widget_changed (self);
387 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
388 EmpathyAccountWidget *self)
391 gboolean default_value;
392 const gchar *param_name;
393 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
395 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
396 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
398 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
399 * always unset the param and set the value if different from the
401 empathy_account_settings_unset (priv->settings, param_name);
402 default_value = empathy_account_settings_get_boolean (priv->settings,
405 if (default_value == value)
407 DEBUG ("Unset %s and restore to %d", param_name, default_value);
411 DEBUG ("Setting %s to %d", param_name, value);
412 empathy_account_settings_set_boolean (priv->settings, param_name, value);
415 empathy_account_widget_changed (self);
419 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
420 EmpathyAccountWidget *self)
422 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
426 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
427 port = empathy_account_settings_get_uint32 (priv->settings, "port");
431 if (port == 5222 || port == 0)
436 if (port == 5223 || port == 0)
440 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
442 priv->contains_pending_changes = TRUE;
446 account_widget_combobox_changed_cb (GtkWidget *widget,
447 EmpathyAccountWidget *self)
453 const gchar *default_value = NULL;
454 const gchar *param_name;
455 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
457 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
460 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
461 /* the param value is stored in the first column */
462 gtk_tree_model_get (model, &iter, 0, &value, -1);
464 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
466 v = empathy_account_settings_get_default (priv->settings, param_name);
468 default_value = g_value_get_string (v);
470 if (!tp_strdiff (value, default_value))
472 DEBUG ("Unset %s and restore to %s", param_name, default_value);
473 empathy_account_settings_unset (priv->settings, param_name);
477 DEBUG ("Setting %s to %s", param_name, value);
478 empathy_account_settings_set_string (priv->settings, param_name, value);
481 empathy_account_widget_changed (self);
485 clear_icon_released_cb (GtkEntry *entry,
486 GtkEntryIconPosition icon_pos,
488 EmpathyAccountWidget *self)
490 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
491 const gchar *param_name;
493 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
495 DEBUG ("Unset %s", param_name);
496 empathy_account_settings_unset (priv->settings, param_name);
497 gtk_entry_set_text (entry, "");
499 empathy_account_widget_changed (self);
503 password_entry_changed_cb (GtkEditable *entry,
504 EmpathyAccountWidget *self)
508 str = gtk_entry_get_text (GTK_ENTRY (entry));
510 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
511 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
515 password_entry_activated_cb (GtkEntry *entry,
516 EmpathyAccountWidget *self)
518 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
520 if (gtk_widget_get_sensitive (priv->apply_button))
521 account_widget_apply_and_log_in (self);
525 account_entry_activated_cb (GtkEntry *entry,
526 EmpathyAccountWidget *self)
528 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
530 if (gtk_widget_get_sensitive (priv->apply_button))
531 account_widget_apply_and_log_in (self);
535 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
537 const gchar *param_name)
539 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
541 g_object_set_data_full (G_OBJECT (widget), "param_name",
542 g_strdup (param_name), g_free);
544 if (GTK_IS_SPIN_BUTTON (widget))
547 const gchar *signature;
549 signature = empathy_account_settings_get_dbus_signature (priv->settings,
551 g_return_if_fail (signature != NULL);
553 switch ((int)*signature)
555 case DBUS_TYPE_INT16:
556 case DBUS_TYPE_INT32:
557 value = empathy_account_settings_get_int32 (priv->settings,
560 case DBUS_TYPE_INT64:
561 value = empathy_account_settings_get_int64 (priv->settings,
564 case DBUS_TYPE_UINT16:
565 case DBUS_TYPE_UINT32:
566 value = empathy_account_settings_get_uint32 (priv->settings,
569 case DBUS_TYPE_UINT64:
570 value = empathy_account_settings_get_uint64 (priv->settings,
574 g_return_if_reached ();
577 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
579 g_signal_connect (widget, "value-changed",
580 G_CALLBACK (account_widget_int_changed_cb),
583 else if (GTK_IS_ENTRY (widget))
585 const gchar *str = NULL;
587 str = empathy_account_settings_get_string (priv->settings, param_name);
588 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
590 if (!tp_strdiff (param_name, "account"))
591 priv->param_account_widget = widget;
592 else if (!tp_strdiff (param_name, "password"))
593 priv->param_password_widget = widget;
595 if (strstr (param_name, "password"))
597 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
599 /* Add 'clear' icon */
600 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
601 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
603 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
604 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
606 g_signal_connect (widget, "icon-release",
607 G_CALLBACK (clear_icon_released_cb), self);
608 g_signal_connect (widget, "changed",
609 G_CALLBACK (password_entry_changed_cb), self);
610 g_signal_connect (widget, "activate",
611 G_CALLBACK (password_entry_activated_cb), self);
613 else if (strstr (param_name, "account"))
614 g_signal_connect (widget, "activate",
615 G_CALLBACK (account_entry_activated_cb), self);
618 g_signal_connect (widget, "changed",
619 G_CALLBACK (account_widget_entry_changed_cb), self);
620 g_signal_connect (widget, "map",
621 G_CALLBACK (account_widget_entry_map_cb), self);
623 else if (GTK_IS_TOGGLE_BUTTON (widget))
625 gboolean value = FALSE;
627 value = empathy_account_settings_get_boolean (priv->settings,
629 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
631 g_signal_connect (widget, "toggled",
632 G_CALLBACK (account_widget_checkbutton_toggled_cb),
635 else if (GTK_IS_COMBO_BOX (widget))
637 /* The combo box's model has to contain the param value in its first
638 * column (as a string) */
644 str = empathy_account_settings_get_string (priv->settings, param_name);
645 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
647 valid = gtk_tree_model_get_iter_first (model, &iter);
652 gtk_tree_model_get (model, &iter, 0, &name, -1);
653 if (!tp_strdiff (name, str))
655 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
660 valid = gtk_tree_model_iter_next (model, &iter);
666 g_signal_connect (widget, "changed",
667 G_CALLBACK (account_widget_combobox_changed_cb),
672 DEBUG ("Unknown type of widget for param %s", param_name);
677 build_translated_params (void)
681 hash = g_hash_table_new (g_str_hash, g_str_equal);
682 g_hash_table_insert (hash, "account", _("Account"));
683 g_hash_table_insert (hash, "password", _("Password"));
684 g_hash_table_insert (hash, "server", _("Server"));
685 g_hash_table_insert (hash, "port", _("Port"));
691 account_widget_generic_format_param_name (const gchar *param_name)
695 static GHashTable *translated_params = NULL;
697 if (G_UNLIKELY (translated_params == NULL))
698 translated_params = build_translated_params ();
700 /* Translate most common parameters */
701 str = g_hash_table_lookup (translated_params, param_name);
703 return g_strdup (str);
705 str = g_strdup (param_name);
707 if (str && g_ascii_isalpha (str[0]))
708 str[0] = g_ascii_toupper (str[0]);
710 while ((p = strchr (str, '-')) != NULL)
712 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
715 p[1] = g_ascii_toupper (p[1]);
725 accounts_widget_generic_setup (EmpathyAccountWidget *self,
726 GtkWidget *table_common_settings,
727 GtkWidget *table_advanced_settings)
729 TpConnectionManagerParam *params, *param;
730 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
732 params = empathy_account_settings_get_tp_params (priv->settings);
734 for (param = params; param != NULL && param->name != NULL; param++)
736 GtkWidget *table_settings;
738 GtkWidget *widget = NULL;
739 gchar *param_name_formatted;
741 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
742 table_settings = table_common_settings;
743 else if (priv->simple)
746 table_settings = table_advanced_settings;
748 param_name_formatted = account_widget_generic_format_param_name
750 g_object_get (table_settings, "n-rows", &n_rows, NULL);
751 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
753 if (param->dbus_signature[0] == 's')
757 str = g_strdup_printf (_("%s:"), param_name_formatted);
758 widget = gtk_label_new (str);
759 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
762 gtk_table_attach (GTK_TABLE (table_settings),
768 gtk_widget_show (widget);
770 widget = gtk_entry_new ();
771 if (strcmp (param->name, "account") == 0)
773 g_signal_connect (widget, "realize",
774 G_CALLBACK (gtk_widget_grab_focus),
777 gtk_table_attach (GTK_TABLE (table_settings),
781 GTK_FILL | GTK_EXPAND, 0,
783 gtk_widget_show (widget);
785 /* int types: ynqiuxt. double type is 'd' */
786 else if (param->dbus_signature[0] == 'y' ||
787 param->dbus_signature[0] == 'n' ||
788 param->dbus_signature[0] == 'q' ||
789 param->dbus_signature[0] == 'i' ||
790 param->dbus_signature[0] == 'u' ||
791 param->dbus_signature[0] == 'x' ||
792 param->dbus_signature[0] == 't' ||
793 param->dbus_signature[0] == 'd')
800 switch (param->dbus_signature[0])
802 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
803 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
804 case 'q': minint = 0; maxint = G_MAXUINT16; break;
805 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
806 case 'u': minint = 0; maxint = G_MAXUINT32; break;
807 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
808 case 't': minint = 0; maxint = G_MAXUINT64; break;
809 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
811 default: g_assert_not_reached ();
814 str = g_strdup_printf (_("%s:"), param_name_formatted);
815 widget = gtk_label_new (str);
816 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
819 gtk_table_attach (GTK_TABLE (table_settings),
825 gtk_widget_show (widget);
827 widget = gtk_spin_button_new_with_range (minint, maxint, step);
828 gtk_table_attach (GTK_TABLE (table_settings),
832 GTK_FILL | GTK_EXPAND, 0,
834 gtk_widget_show (widget);
836 else if (param->dbus_signature[0] == 'b')
838 widget = gtk_check_button_new_with_label (param_name_formatted);
839 gtk_table_attach (GTK_TABLE (table_settings),
843 GTK_FILL | GTK_EXPAND, 0,
845 gtk_widget_show (widget);
849 DEBUG ("Unknown signature for param %s: %s",
850 param_name_formatted, param->dbus_signature);
854 empathy_account_widget_setup_widget (self, widget, param->name);
856 g_free (param_name_formatted);
861 account_widget_handle_params_valist (EmpathyAccountWidget *self,
862 const gchar *first_widget,
868 for (name = first_widget; name; name = va_arg (args, const gchar *))
870 const gchar *param_name;
872 param_name = va_arg (args, const gchar *);
873 object = gtk_builder_get_object (self->ui_details->gui, name);
877 g_warning ("Builder is missing object '%s'.", name);
881 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
887 account_widget_cancel_clicked_cb (GtkWidget *button,
888 EmpathyAccountWidget *self)
890 g_signal_emit (self, signals[CANCELLED], 0);
894 account_widget_account_enabled_cb (GObject *source_object,
898 GError *error = NULL;
899 TpAccount *account = TP_ACCOUNT (source_object);
900 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
901 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
903 tp_account_set_enabled_finish (account, res, &error);
907 DEBUG ("Could not enable the account: %s", error->message);
908 g_error_free (error);
912 empathy_connect_new_account (account, priv->account_manager);
915 /* unref widget - part of the workaround */
916 g_object_unref (widget);
920 account_widget_applied_cb (GObject *source_object,
924 GError *error = NULL;
926 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
927 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
928 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
929 gboolean reconnect_required;
931 empathy_account_settings_apply_finish (settings, res, &reconnect_required,
936 DEBUG ("Could not apply changes to account: %s", error->message);
937 g_error_free (error);
941 account = empathy_account_settings_get_account (priv->settings);
945 if (priv->creating_account)
947 /* By default, when an account is created, we enable it. */
949 /* workaround to keep widget alive during async call */
950 g_object_ref (widget);
952 tp_account_set_enabled_async (account, TRUE,
953 account_widget_account_enabled_cb, widget);
954 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
956 else if (priv->enabled_checkbox != NULL)
958 gboolean enabled_checked;
962 mx_gtk_light_switch_get_active (
963 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
965 gtk_toggle_button_get_active (
966 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
967 #endif /* HAVE_MEEGO */
969 /* If the account was offline, we always want to try reconnecting,
970 * to give it a chance to connect if the previous params were wrong.
971 * tp_account_reconnect_async() won't do anything if the requested
972 * presence is offline anyway. */
973 if (tp_account_get_connection_status (account, NULL) ==
974 TP_CONNECTION_STATUS_DISCONNECTED)
975 reconnect_required = TRUE;
977 if (reconnect_required && tp_account_is_enabled (account)
980 /* After having applied changes to a user account, we
981 * reconnect it if needed. This is done so the new
982 * information entered by the user is validated on the server. */
983 tp_account_reconnect_async (account, NULL, NULL);
988 if (!priv->destroyed)
989 account_widget_set_control_buttons_sensitivity (widget, FALSE);
991 priv->contains_pending_changes = FALSE;
993 /* unref the widget - part of the workaround */
994 g_object_unref (widget);
998 account_widget_apply_and_log_in (EmpathyAccountWidget *self)
1000 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1001 gboolean display_name_overridden;
1003 if (priv->radiobutton_reuse != NULL)
1005 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
1006 priv->radiobutton_reuse));
1008 DEBUG ("Set register param: %d", !reuse);
1009 empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
1012 g_object_get (priv->settings,
1013 "display-name-overridden", &display_name_overridden, NULL);
1015 if (priv->creating_account || !display_name_overridden)
1017 gchar *display_name;
1019 /* set default display name for new accounts or update if user didn't
1020 * manually override it. */
1021 display_name = empathy_account_widget_get_default_display_name (self);
1023 empathy_account_settings_set_display_name_async (priv->settings,
1024 display_name, NULL, NULL);
1026 g_free (display_name);
1029 /* workaround to keep widget alive during async call */
1030 g_object_ref (self);
1031 empathy_account_settings_apply_async (priv->settings,
1032 account_widget_applied_cb, self);
1036 account_widget_apply_clicked_cb (GtkWidget *button,
1037 EmpathyAccountWidget *self)
1039 account_widget_apply_and_log_in (self);
1043 account_widget_setup_generic (EmpathyAccountWidget *self)
1045 GtkWidget *table_common_settings;
1046 GtkWidget *table_advanced_settings;
1048 table_common_settings = GTK_WIDGET (gtk_builder_get_object
1049 (self->ui_details->gui, "table_common_settings"));
1050 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
1051 (self->ui_details->gui, "table_advanced_settings"));
1053 accounts_widget_generic_setup (self, table_common_settings,
1054 table_advanced_settings);
1056 g_object_unref (self->ui_details->gui);
1060 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
1064 EmpathyAccountWidget *self = user_data;
1065 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1067 if (empathy_account_settings_is_ready (priv->settings))
1068 account_widget_setup_generic (self);
1072 account_widget_build_generic (EmpathyAccountWidget *self,
1073 const char *filename)
1075 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1076 GtkWidget *expander_advanced;
1078 self->ui_details->gui = empathy_builder_get_file (filename,
1079 "table_common_settings", &priv->table_common_settings,
1080 "vbox_generic_settings", &self->ui_details->widget,
1081 "expander_advanced_settings", &expander_advanced,
1085 gtk_widget_hide (expander_advanced);
1087 g_object_ref (self->ui_details->gui);
1089 if (empathy_account_settings_is_ready (priv->settings))
1090 account_widget_setup_generic (self);
1092 g_signal_connect (priv->settings, "notify::ready",
1093 G_CALLBACK (account_widget_settings_ready_cb), self);
1097 account_widget_launch_external_clicked (GtkWidget *button,
1100 if (!tp_strdiff (tp_account_get_storage_provider (account),
1101 "com.meego.libsocialweb"))
1103 /* we know how to handle this external provider */
1104 GDesktopAppInfo *desktop_info;
1105 GError *error = NULL;
1106 GdkAppLaunchContext *context = NULL;
1107 GdkDisplay *display;
1111 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
1112 if (desktop_info == NULL)
1114 g_critical ("Could not locate 'gnome-control-center.desktop'");
1118 /* glib doesn't have API to start a desktop file with args... (#637875) */
1119 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
1120 (GAppInfo *) desktop_info));
1122 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
1125 if (app_info == NULL)
1127 DEBUG ("Failed to create app info: %s", error->message);
1128 g_error_free (error);
1132 display = gdk_display_get_default ();
1133 context = gdk_display_get_app_launch_context (display);
1135 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1138 g_critical ("Failed to bisho: %s", error->message);
1139 g_clear_error (&error);
1143 g_object_unref (desktop_info);
1144 tp_clear_object (&app_info);
1145 tp_clear_object (&context);
1150 account_widget_build_external (EmpathyAccountWidget *self,
1151 EmpathyAccountSettings *settings)
1153 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1154 TpAccount *account = empathy_account_settings_get_account (settings);
1155 GtkWidget *bar, *widget;
1158 self->ui_details->widget = gtk_vbox_new (FALSE, 6);
1159 priv->table_common_settings = gtk_table_new (1, 2, FALSE);
1161 if (!tp_strdiff (tp_account_get_storage_provider (account),
1162 "com.meego.libsocialweb"))
1164 /* we know how to handle this external provider */
1165 str = g_strdup_printf (
1166 _("The account %s is edited via My Web Accounts."),
1167 empathy_account_settings_get_display_name (settings));
1171 str = g_strdup_printf (
1172 _("The account %s cannot be edited in Empathy."),
1173 empathy_account_settings_get_display_name (settings));
1176 widget = gtk_label_new (str);
1177 gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
1180 bar = gtk_info_bar_new ();
1181 gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
1183 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))),
1185 gtk_container_set_border_width (GTK_CONTAINER (bar), 6);
1187 if (!tp_strdiff (tp_account_get_storage_provider (account),
1188 "com.meego.libsocialweb"))
1190 /* we know how to handle this external provider */
1191 widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
1192 _("Launch My Web Accounts"), RESPONSE_LAUNCH);
1194 g_signal_connect (widget, "clicked",
1195 G_CALLBACK (account_widget_launch_external_clicked), account);
1198 gtk_box_pack_start (GTK_BOX (self->ui_details->widget), bar,
1200 gtk_box_pack_start (GTK_BOX (self->ui_details->widget),
1201 priv->table_common_settings, FALSE, TRUE, 0);
1203 gtk_widget_show_all (self->ui_details->widget);
1207 account_widget_build_salut (EmpathyAccountWidget *self,
1208 const char *filename)
1210 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1211 GtkWidget *expander_advanced;
1213 self->ui_details->gui = empathy_builder_get_file (filename,
1214 "table_common_settings", &priv->table_common_settings,
1215 "vbox_salut_settings", &self->ui_details->widget,
1216 "expander_advanced_settings", &expander_advanced,
1219 empathy_account_widget_handle_params (self,
1220 "entry_published", "published-name",
1221 "entry_nickname", "nickname",
1222 "entry_first_name", "first-name",
1223 "entry_last_name", "last-name",
1224 "entry_email", "email",
1229 gtk_widget_hide (expander_advanced);
1231 self->ui_details->default_focus = g_strdup ("entry_first_name");
1235 account_widget_build_irc (EmpathyAccountWidget *self,
1236 const char *filename)
1238 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1240 empathy_account_settings_set_regex (priv->settings, "account",
1245 priv->irc_network_chooser = empathy_account_widget_irc_build_simple (self,
1250 priv->irc_network_chooser = empathy_account_widget_irc_build (self,
1251 filename, &priv->table_common_settings);
1256 account_widget_build_sip (EmpathyAccountWidget *self,
1257 const char *filename)
1259 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1260 empathy_account_widget_sip_build (self, filename,
1261 &priv->table_common_settings);
1265 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1266 self->ui_details->gui, "remember_password_simple"));
1270 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1271 self->ui_details->gui, "remember_password"));
1276 account_widget_build_msn (EmpathyAccountWidget *self,
1277 const char *filename)
1279 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1281 empathy_account_settings_set_regex (priv->settings, "account",
1286 self->ui_details->gui = empathy_builder_get_file (filename,
1287 "vbox_msn_simple", &self->ui_details->widget,
1290 empathy_account_widget_handle_params (self,
1291 "entry_id_simple", "account",
1292 "entry_password_simple", "password",
1295 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1297 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1298 self->ui_details->gui, "remember_password_simple"));
1302 self->ui_details->gui = empathy_builder_get_file (filename,
1303 "table_common_msn_settings", &priv->table_common_settings,
1304 "vbox_msn_settings", &self->ui_details->widget,
1307 empathy_account_widget_handle_params (self,
1308 "entry_id", "account",
1309 "entry_password", "password",
1310 "entry_server", "server",
1311 "spinbutton_port", "port",
1314 self->ui_details->default_focus = g_strdup ("entry_id");
1316 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1317 self->ui_details->gui, "remember_password"));
1322 suffix_id_widget_changed_cb (GtkWidget *entry,
1323 EmpathyAccountWidget *self)
1325 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1326 const gchar *account;
1328 g_assert (priv->jid_suffix != NULL);
1330 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1332 account = empathy_account_settings_get_string (priv->settings, "account");
1333 if (!EMP_STR_EMPTY (account) &&
1334 !g_str_has_suffix (account, priv->jid_suffix))
1338 tmp = g_strdup_printf ("%s%s", account, priv->jid_suffix);
1340 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1342 empathy_account_settings_set_string (priv->settings, "account", tmp);
1346 empathy_account_widget_changed (self);
1350 remove_jid_suffix (EmpathyAccountWidget *self,
1353 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1355 g_assert (priv->jid_suffix != NULL);
1357 if (!g_str_has_suffix (str, priv->jid_suffix))
1358 return g_strdup (str);
1360 return g_strndup (str, strlen (str) - strlen (priv->jid_suffix));
1364 setup_id_widget_with_suffix (EmpathyAccountWidget *self,
1366 const gchar *suffix)
1368 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1369 const gchar *str = NULL;
1371 g_object_set_data_full (G_OBJECT (widget), "param_name",
1372 g_strdup ("account"), g_free);
1374 g_assert (priv->jid_suffix == NULL);
1375 priv->jid_suffix = g_strdup (suffix);
1377 str = empathy_account_settings_get_string (priv->settings, "account");
1382 tmp = remove_jid_suffix (self, str);
1383 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1387 priv->param_account_widget = widget;
1389 g_signal_connect (widget, "changed",
1390 G_CALLBACK (suffix_id_widget_changed_cb), self);
1394 account_widget_get_service (EmpathyAccountWidget *self)
1396 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1397 const gchar *icon_name, *service;
1399 icon_name = empathy_account_settings_get_icon_name (priv->settings);
1400 service = empathy_account_settings_get_service (priv->settings);
1402 /* Previous versions of Empathy didn't set the Service property on Facebook
1403 * and gtalk accounts, so we check using the icon name as well. */
1404 if (!tp_strdiff (icon_name, "im-google-talk") ||
1405 !tp_strdiff (service, "google-talk"))
1406 return GTALK_SERVICE;
1408 if (!tp_strdiff (icon_name, "im-facebook") ||
1409 !tp_strdiff (service, "facebook"))
1410 return FACEBOOK_SERVICE;
1416 account_widget_build_jabber (EmpathyAccountWidget *self,
1417 const char *filename)
1419 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1420 GtkWidget *spinbutton_port;
1421 GtkWidget *checkbutton_ssl;
1422 GtkWidget *label_id, *label_password;
1423 GtkWidget *label_id_create, *label_password_create;
1424 GtkWidget *label_example_fb;
1425 GtkWidget *label_example;
1426 GtkWidget *expander_advanced;
1427 GtkWidget *entry_id;
1430 service = account_widget_get_service (self);
1432 empathy_account_settings_set_regex (priv->settings, "account",
1433 ACCOUNT_REGEX_JABBER);
1435 if (priv->simple && service == NO_SERVICE)
1437 /* Simple widget for XMPP */
1438 self->ui_details->gui = empathy_builder_get_file (filename,
1439 "vbox_jabber_simple", &self->ui_details->widget,
1440 "label_id_simple", &label_id,
1441 "label_id_create", &label_id_create,
1442 "label_password_simple", &label_password,
1443 "label_password_create", &label_password_create,
1446 if (empathy_account_settings_get_boolean (priv->settings, "register"))
1448 gtk_widget_hide (label_id);
1449 gtk_widget_hide (label_password);
1450 gtk_widget_show (label_id_create);
1451 gtk_widget_show (label_password_create);
1454 empathy_account_widget_handle_params (self,
1455 "entry_id_simple", "account",
1456 "entry_password_simple", "password",
1459 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1461 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1462 self->ui_details->gui, "remember_password_simple"));
1464 else if (priv->simple && service == GTALK_SERVICE)
1466 /* Simple widget for Google Talk */
1467 self->ui_details->gui = empathy_builder_get_file (filename,
1468 "vbox_gtalk_simple", &self->ui_details->widget,
1471 empathy_account_widget_handle_params (self,
1472 "entry_id_g_simple", "account",
1473 "entry_password_g_simple", "password",
1476 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1478 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1479 self->ui_details->gui, "remember_password_g_simple"));
1481 else if (priv->simple && service == FACEBOOK_SERVICE)
1483 /* Simple widget for Facebook */
1484 self->ui_details->gui = empathy_builder_get_file (filename,
1485 "vbox_fb_simple", &self->ui_details->widget,
1486 "entry_id_fb_simple", &entry_id,
1489 empathy_account_widget_handle_params (self,
1490 "entry_password_fb_simple", "password",
1493 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1495 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1497 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1498 self->ui_details->gui, "remember_password_fb_simple"));
1502 ServiceInfo info = services_infos[service];
1504 /* Full widget for XMPP, Google Talk and Facebook*/
1505 self->ui_details->gui = empathy_builder_get_file (filename,
1506 "table_common_settings", &priv->table_common_settings,
1507 "vbox_jabber_settings", &self->ui_details->widget,
1508 "spinbutton_port", &spinbutton_port,
1509 "checkbutton_ssl", &checkbutton_ssl,
1510 "label_username_f_example", &label_example_fb,
1511 info.label_username_example, &label_example,
1512 "expander_advanced", &expander_advanced,
1513 "entry_id", &entry_id,
1514 "label_id", &label_id,
1517 empathy_account_widget_handle_params (self,
1518 "entry_password", "password",
1519 "entry_resource", "resource",
1520 "entry_server", "server",
1521 "spinbutton_port", "port",
1522 "spinbutton_priority", "priority",
1523 "checkbutton_ssl", "old-ssl",
1524 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1525 "checkbutton_encryption", "require-encryption",
1528 if (service == FACEBOOK_SERVICE)
1530 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1532 /* Facebook special case the entry ID widget to hide the
1533 * "@chat.facebook.com" part */
1534 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1538 empathy_account_widget_setup_widget (self, entry_id, "account");
1541 self->ui_details->default_focus = g_strdup ("entry_id");
1542 priv->spinbutton_port = spinbutton_port;
1544 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1545 self->ui_details->gui, "remember_password"));
1547 g_signal_connect (checkbutton_ssl, "toggled",
1548 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1551 if (service == FACEBOOK_SERVICE)
1553 GtkContainer *parent;
1556 /* Removing the label from list of focusable widgets */
1557 parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
1558 children = gtk_container_get_children (parent);
1559 children = g_list_remove (children, label_example_fb);
1560 gtk_container_set_focus_chain (parent, children);
1561 g_list_free (children);
1564 gtk_widget_show (label_example);
1566 if (!info.show_advanced)
1567 gtk_widget_hide (expander_advanced);
1572 account_widget_build_icq (EmpathyAccountWidget *self,
1573 const char *filename)
1575 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1576 GtkWidget *spinbutton_port;
1578 empathy_account_settings_set_regex (priv->settings, "account",
1583 self->ui_details->gui = empathy_builder_get_file (filename,
1584 "vbox_icq_simple", &self->ui_details->widget,
1587 empathy_account_widget_handle_params (self,
1588 "entry_uin_simple", "account",
1589 "entry_password_simple", "password",
1592 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1594 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1595 self->ui_details->gui, "remember_password_simple"));
1599 self->ui_details->gui = empathy_builder_get_file (filename,
1600 "table_common_settings", &priv->table_common_settings,
1601 "vbox_icq_settings", &self->ui_details->widget,
1602 "spinbutton_port", &spinbutton_port,
1605 empathy_account_widget_handle_params (self,
1606 "entry_uin", "account",
1607 "entry_password", "password",
1608 "entry_server", "server",
1609 "spinbutton_port", "port",
1610 "entry_charset", "charset",
1613 self->ui_details->default_focus = g_strdup ("entry_uin");
1615 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1616 self->ui_details->gui, "remember_password"));
1621 account_widget_build_aim (EmpathyAccountWidget *self,
1622 const char *filename)
1624 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1625 GtkWidget *spinbutton_port;
1629 self->ui_details->gui = empathy_builder_get_file (filename,
1630 "vbox_aim_simple", &self->ui_details->widget,
1633 empathy_account_widget_handle_params (self,
1634 "entry_screenname_simple", "account",
1635 "entry_password_simple", "password",
1638 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1640 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1641 self->ui_details->gui, "remember_password_simple"));
1645 self->ui_details->gui = empathy_builder_get_file (filename,
1646 "table_common_settings", &priv->table_common_settings,
1647 "vbox_aim_settings", &self->ui_details->widget,
1648 "spinbutton_port", &spinbutton_port,
1651 empathy_account_widget_handle_params (self,
1652 "entry_screenname", "account",
1653 "entry_password", "password",
1654 "entry_server", "server",
1655 "spinbutton_port", "port",
1658 self->ui_details->default_focus = g_strdup ("entry_screenname");
1660 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1661 self->ui_details->gui, "remember_password"));
1666 account_widget_build_yahoo (EmpathyAccountWidget *self,
1667 const char *filename)
1669 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1671 empathy_account_settings_set_regex (priv->settings, "account",
1672 ACCOUNT_REGEX_YAHOO);
1676 self->ui_details->gui = empathy_builder_get_file (filename,
1677 "vbox_yahoo_simple", &self->ui_details->widget,
1680 empathy_account_widget_handle_params (self,
1681 "entry_id_simple", "account",
1682 "entry_password_simple", "password",
1685 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1687 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1688 self->ui_details->gui, "remember_password_simple"));
1692 self->ui_details->gui = empathy_builder_get_file (filename,
1693 "table_common_settings", &priv->table_common_settings,
1694 "vbox_yahoo_settings", &self->ui_details->widget,
1697 empathy_account_widget_handle_params (self,
1698 "entry_id", "account",
1699 "entry_password", "password",
1700 "entry_locale", "room-list-locale",
1701 "entry_charset", "charset",
1702 "spinbutton_port", "port",
1703 "checkbutton_ignore_invites", "ignore-invites",
1706 self->ui_details->default_focus = g_strdup ("entry_id");
1708 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1709 self->ui_details->gui, "remember_password"));
1714 account_widget_build_groupwise (EmpathyAccountWidget *self,
1715 const char *filename)
1717 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1721 self->ui_details->gui = empathy_builder_get_file (filename,
1722 "vbox_groupwise_simple", &self->ui_details->widget,
1725 empathy_account_widget_handle_params (self,
1726 "entry_id_simple", "account",
1727 "entry_password_simple", "password",
1730 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1732 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1733 self->ui_details->gui, "remember_password_simple"));
1737 self->ui_details->gui = empathy_builder_get_file (filename,
1738 "table_common_groupwise_settings", &priv->table_common_settings,
1739 "vbox_groupwise_settings", &self->ui_details->widget,
1742 empathy_account_widget_handle_params (self,
1743 "entry_id", "account",
1744 "entry_password", "password",
1745 "entry_server", "server",
1746 "spinbutton_port", "port",
1749 self->ui_details->default_focus = g_strdup ("entry_id");
1751 priv->remember_password_widget = GTK_WIDGET (gtk_builder_get_object (
1752 self->ui_details->gui, "remember_password"));
1757 account_widget_destroy_cb (GtkWidget *widget,
1758 EmpathyAccountWidget *self)
1760 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1761 /* set the destroyed flag - workaround */
1762 priv->destroyed = TRUE;
1764 g_object_unref (self);
1768 empathy_account_widget_enabled_cb (TpAccount *account,
1772 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1773 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1774 gboolean enabled = tp_account_is_enabled (account);
1776 if (priv->enabled_checkbox != NULL)
1779 mx_gtk_light_switch_set_active (
1780 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1783 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1785 #endif /* HAVE_MEEGO */
1791 account_widget_switch_flipped_cb (MxGtkLightSwitch *sw,
1795 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1797 #endif /* HAVE_MEEGO */
1799 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1804 state = gtk_toggle_button_get_active (toggle_button);
1805 #endif /* HAVE_MEEGO */
1807 account = empathy_account_settings_get_account (priv->settings);
1809 /* Enable the account according to the value of the "Enabled" checkbox */
1810 /* workaround to keep widget alive during async call */
1811 g_object_ref (user_data);
1812 tp_account_set_enabled_async (account, state,
1813 account_widget_account_enabled_cb, user_data);
1817 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1818 gboolean others_exist)
1820 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1822 priv->other_accounts_exist = others_exist;
1824 if (priv->creating_account)
1825 account_widget_handle_control_buttons_sensitivity (self);
1829 do_set_property (GObject *object,
1831 const GValue *value,
1834 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1839 priv->settings = g_value_dup_object (value);
1842 priv->simple = g_value_get_boolean (value);
1844 case PROP_CREATING_ACCOUNT:
1845 priv->creating_account = g_value_get_boolean (value);
1847 case PROP_OTHER_ACCOUNTS_EXIST:
1848 empathy_account_widget_set_other_accounts_exist (
1849 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1852 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1857 do_get_property (GObject *object,
1862 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1867 g_value_set_string (value,
1868 empathy_account_settings_get_protocol (priv->settings));
1871 g_value_set_object (value, priv->settings);
1874 g_value_set_boolean (value, priv->simple);
1876 case PROP_CREATING_ACCOUNT:
1877 g_value_set_boolean (value, priv->creating_account);
1879 case PROP_OTHER_ACCOUNTS_EXIST:
1880 g_value_set_boolean (value, priv->other_accounts_exist);
1883 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1888 set_apply_button (EmpathyAccountWidget *self)
1890 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1893 /* We can't use the stock button as its accelerator ('A') clashes with the
1895 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1897 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("A_pply"));
1898 gtk_button_set_use_underline (GTK_BUTTON (priv->apply_button), TRUE);
1900 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1901 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1905 presence_changed_cb (TpAccountManager *manager,
1906 TpConnectionPresenceType state,
1907 const gchar *status,
1908 const gchar *message,
1909 EmpathyAccountWidget *self)
1911 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1913 if (priv->destroyed)
1916 if (priv->apply_button == NULL)
1917 /* This button doesn't exist in 'simple' mode */
1920 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1921 priv->creating_account)
1923 /* We are online and creating a new account, display a Login button */
1926 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1927 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1929 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1930 GTK_ICON_SIZE_BUTTON);
1931 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1935 /* We are offline or modifying an existing account, display
1937 set_apply_button (self);
1942 account_manager_ready_cb (GObject *source_object,
1943 GAsyncResult *result,
1946 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1947 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1948 GError *error = NULL;
1949 TpConnectionPresenceType state;
1951 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1953 DEBUG ("Failed to prepare account manager: %s", error->message);
1954 g_error_free (error);
1958 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1961 /* simulate a presence change so the apply button will be changed
1963 presence_changed_cb (account_manager, state, NULL, NULL, self);
1966 g_object_unref (self);
1969 #define WIDGET(cm, proto) \
1970 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1971 account_widget_build_##proto }
1974 add_enable_checkbox (EmpathyAccountWidget *self,
1977 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1981 GtkWidget *vbox = self->ui_details->widget;
1982 #endif /* HAVE_MEEGO */
1983 guint nb_rows, nb_columns;
1984 gboolean is_enabled;
1986 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1987 if (priv->creating_account || priv->table_common_settings == NULL)
1990 is_enabled = tp_account_is_enabled (account);
1993 w = gtk_label_new (_("Account:"));
1994 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1996 priv->enabled_checkbox = mx_gtk_light_switch_new ();
1998 mx_gtk_light_switch_set_active (
1999 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
2001 gtk_widget_show (w);
2003 priv->enabled_checkbox =
2004 gtk_check_button_new_with_mnemonic (_("_Enabled"));
2006 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
2008 #endif /* HAVE_MEEGO */
2010 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
2011 "n-columns", &nb_columns, NULL);
2013 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
2017 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
2019 0, 1, nb_rows - 1, nb_rows,
2021 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
2022 priv->enabled_checkbox,
2023 1, nb_columns, nb_rows - 1, nb_rows,
2024 GTK_EXPAND | GTK_FILL, 0, 0, 0);
2026 gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
2027 gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
2028 #endif /* HAVE_MEEGO */
2030 gtk_widget_show (priv->enabled_checkbox);
2033 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
2034 G_CALLBACK (account_widget_switch_flipped_cb), self);
2036 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
2037 G_CALLBACK (account_widget_enabled_toggled_cb), self);
2038 #endif /* HAVE_MEEGO */
2042 /* Meego doesn't support registration */
2044 add_register_buttons (EmpathyAccountWidget *self,
2047 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2048 const TpConnectionManagerProtocol *protocol;
2049 GtkWidget *radiobutton_register;
2050 GtkWidget *vbox = self->ui_details->widget;
2052 if (!priv->creating_account)
2055 protocol = empathy_account_settings_get_tp_protocol (priv->settings);
2056 if (protocol == NULL)
2059 if (!tp_connection_manager_protocol_can_register (protocol))
2062 if (account_widget_get_service (self) != NO_SERVICE)
2068 priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
2069 _("This account already exists on the server"));
2070 radiobutton_register = gtk_radio_button_new_with_label (
2071 gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
2072 _("Create a new account on the server"));
2074 gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
2075 gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
2076 gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
2077 gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
2078 gtk_widget_show (priv->radiobutton_reuse);
2079 gtk_widget_show (radiobutton_register);
2081 #endif /* HAVE_MEEGO */
2084 remember_password_toggled_cb (GtkToggleButton *button,
2085 EmpathyAccountWidget *self)
2087 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2089 if (gtk_toggle_button_get_active (button))
2091 gtk_widget_set_sensitive (priv->param_password_widget, TRUE);
2095 gtk_widget_set_sensitive (priv->param_password_widget, FALSE);
2096 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), "");
2097 empathy_account_settings_unset (priv->settings, "password");
2102 account_settings_password_retrieved_cb (GObject *object,
2105 EmpathyAccountWidget *self = user_data;
2106 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2107 const gchar *password = empathy_account_settings_get_string (
2108 priv->settings, "password");
2110 if (password != NULL)
2112 /* We have to do this so that when we call gtk_entry_set_text,
2113 * the ::changed callback doesn't think the user made the
2115 priv->automatic_change = TRUE;
2116 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), password);
2117 priv->automatic_change = FALSE;
2120 gtk_toggle_button_set_active (
2121 GTK_TOGGLE_BUTTON (priv->remember_password_widget),
2122 !EMP_STR_EMPTY (password));
2126 do_constructed (GObject *obj)
2128 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2129 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2131 TpStorageRestrictionFlags storage_restrictions;
2132 const gchar *display_name, *default_display_name;
2135 const gchar *cm_name;
2136 const gchar *protocol;
2138 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
2140 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
2141 account_widget_build_salut },
2142 WIDGET (gabble, jabber),
2143 WIDGET (butterfly, msn),
2146 WIDGET (haze, yahoo),
2147 WIDGET (haze, groupwise),
2149 WIDGET (sofiasip, sip),
2152 account = empathy_account_settings_get_account (priv->settings);
2154 if (account != NULL)
2155 storage_restrictions = tp_account_get_storage_restrictions (account);
2157 storage_restrictions = 0;
2159 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
2160 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
2162 DEBUG ("Account is provided by an external storage provider");
2164 account_widget_build_external (self, priv->settings);
2168 const gchar *protocol, *cm_name;
2170 cm_name = empathy_account_settings_get_cm (priv->settings);
2171 protocol = empathy_account_settings_get_protocol (priv->settings);
2173 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
2175 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
2176 !tp_strdiff (widgets[i].protocol, protocol))
2180 filename = empathy_file_lookup (widgets[i].file,
2182 widgets[i].func (self, filename);
2189 if (i == G_N_ELEMENTS (widgets))
2191 gchar *filename = empathy_file_lookup (
2192 "empathy-account-widget-generic.ui", "libempathy-gtk");
2193 account_widget_build_generic (self, filename);
2198 /* handle default focus */
2199 if (self->ui_details->default_focus != NULL)
2201 GObject *default_focus_entry;
2203 default_focus_entry = gtk_builder_get_object
2204 (self->ui_details->gui, self->ui_details->default_focus);
2205 g_signal_connect (default_focus_entry, "realize",
2206 G_CALLBACK (gtk_widget_grab_focus),
2210 /* remember password */
2211 if (priv->param_password_widget != NULL
2212 && priv->remember_password_widget != NULL
2213 && empathy_account_settings_supports_sasl (priv->settings))
2217 gtk_toggle_button_set_active (
2218 GTK_TOGGLE_BUTTON (priv->remember_password_widget), TRUE);
2222 gtk_toggle_button_set_active (
2223 GTK_TOGGLE_BUTTON (priv->remember_password_widget),
2224 !EMP_STR_EMPTY (empathy_account_settings_get_string (
2225 priv->settings, "password")));
2227 /* The password might not have been retrieved from the
2228 * keyring yet. We should update the remember password
2229 * toggle button and the password entry when/if it is. */
2230 g_signal_connect (priv->settings, "password-retrieved",
2231 G_CALLBACK (account_settings_password_retrieved_cb), self);
2234 g_signal_connect (priv->remember_password_widget, "toggled",
2235 G_CALLBACK (remember_password_toggled_cb), self);
2237 remember_password_toggled_cb (
2238 GTK_TOGGLE_BUTTON (priv->remember_password_widget), self);
2240 else if (priv->remember_password_widget != NULL
2241 && !empathy_account_settings_supports_sasl (priv->settings))
2243 gtk_widget_set_visible (priv->remember_password_widget, FALSE);
2246 /* dup and init the account-manager */
2247 priv->account_manager = tp_account_manager_dup ();
2249 g_object_ref (self);
2250 tp_account_manager_prepare_async (priv->account_manager, NULL,
2251 account_manager_ready_cb, self);
2253 /* handle apply and cancel button */
2254 if (!priv->simple &&
2255 !(storage_restrictions &
2256 TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS))
2258 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
2261 /* We can't use the stock button as its accelerator ('C') clashes with
2262 * the Close button. */
2263 priv->cancel_button = gtk_button_new ();
2264 gtk_button_set_label (GTK_BUTTON (priv->cancel_button), _("Ca_ncel"));
2265 gtk_button_set_use_underline (GTK_BUTTON (priv->cancel_button), TRUE);
2267 image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
2268 gtk_button_set_image (GTK_BUTTON (priv->cancel_button), image);
2270 priv->apply_button = gtk_button_new ();
2271 set_apply_button (self);
2273 /* We'll change this button to a "Log in" one if we are creating a new
2274 * account and are connected. */
2275 tp_g_signal_connect_object (priv->account_manager,
2276 "most-available-presence-changed",
2277 G_CALLBACK (presence_changed_cb), obj, 0);
2279 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
2281 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
2284 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
2287 g_signal_connect (priv->cancel_button, "clicked",
2288 G_CALLBACK (account_widget_cancel_clicked_cb),
2290 g_signal_connect (priv->apply_button, "clicked",
2291 G_CALLBACK (account_widget_apply_clicked_cb),
2293 gtk_widget_show_all (hbox);
2295 if (priv->creating_account)
2296 /* When creating an account, the user might have nothing to enter.
2297 * That means that no control interaction might occur,
2298 * so we update the control button sensitivity manually.
2300 account_widget_handle_control_buttons_sensitivity (self);
2302 account_widget_set_control_buttons_sensitivity (self, FALSE);
2305 if (account != NULL)
2307 g_signal_connect (account, "notify::enabled",
2308 G_CALLBACK (empathy_account_widget_enabled_cb), self);
2312 add_register_buttons (self, account);
2313 #endif /* HAVE_MEEGO */
2315 /* add the Enable checkbox to accounts that support it */
2316 if (!(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED))
2317 add_enable_checkbox (self, account);
2319 /* hook up to widget destruction to unref ourselves */
2320 g_signal_connect (self->ui_details->widget, "destroy",
2321 G_CALLBACK (account_widget_destroy_cb), self);
2323 if (self->ui_details->gui != NULL)
2325 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
2326 self->ui_details->widget);
2327 self->ui_details->gui = NULL;
2330 display_name = empathy_account_settings_get_display_name (priv->settings);
2331 default_display_name = empathy_account_widget_get_default_display_name (self);
2333 if (tp_strdiff (display_name, default_display_name) &&
2334 !priv->creating_account)
2336 /* The display name of the account is not the one that we'd assign by
2337 * default; assume that the user changed it manually */
2338 g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
2343 do_dispose (GObject *obj)
2345 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2346 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2348 if (priv->dispose_run)
2351 priv->dispose_run = TRUE;
2353 if (priv->settings != NULL)
2356 account = empathy_account_settings_get_account (priv->settings);
2358 if (account != NULL)
2360 g_signal_handlers_disconnect_by_func (account,
2361 empathy_account_widget_enabled_cb, self);
2364 g_object_unref (priv->settings);
2365 priv->settings = NULL;
2368 if (priv->account_manager != NULL)
2370 g_object_unref (priv->account_manager);
2371 priv->account_manager = NULL;
2374 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
2375 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
2379 do_finalize (GObject *obj)
2381 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
2382 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2384 g_free (self->ui_details->default_focus);
2385 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
2387 g_free (priv->jid_suffix);
2389 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
2390 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
2394 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
2396 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2397 GParamSpec *param_spec;
2399 oclass->get_property = do_get_property;
2400 oclass->set_property = do_set_property;
2401 oclass->constructed = do_constructed;
2402 oclass->dispose = do_dispose;
2403 oclass->finalize = do_finalize;
2405 param_spec = g_param_spec_string ("protocol",
2406 "protocol", "The protocol of the account",
2408 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2409 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2411 param_spec = g_param_spec_object ("settings",
2412 "settings", "The settings of the account",
2413 EMPATHY_TYPE_ACCOUNT_SETTINGS,
2414 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2415 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2417 param_spec = g_param_spec_boolean ("simple",
2418 "simple", "Whether the account widget is a simple or an advanced one",
2420 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2421 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2423 param_spec = g_param_spec_boolean ("creating-account",
2425 "TRUE if we're creating an account, FALSE if we're modifying it",
2427 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2428 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2430 param_spec = g_param_spec_boolean ("other-accounts-exist",
2431 "other-accounts-exist",
2432 "TRUE if there are any other accounts (even if this isn't yet saved)",
2434 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2435 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2438 signals[HANDLE_APPLY] =
2439 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2440 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2441 g_cclosure_marshal_VOID__BOOLEAN,
2445 /* This signal is emitted when an account has been created and enabled. */
2446 signals[ACCOUNT_CREATED] =
2447 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2448 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2449 g_cclosure_marshal_VOID__OBJECT,
2453 signals[CANCELLED] =
2454 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2455 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2456 g_cclosure_marshal_VOID__VOID,
2460 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
2464 empathy_account_widget_init (EmpathyAccountWidget *self)
2466 EmpathyAccountWidgetPriv *priv =
2467 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
2468 EmpathyAccountWidgetPriv);
2471 priv->dispose_run = FALSE;
2473 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
2476 /* public methods */
2479 empathy_account_widget_discard_pending_changes
2480 (EmpathyAccountWidget *widget)
2482 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2484 empathy_account_settings_discard_changes (priv->settings);
2485 priv->contains_pending_changes = FALSE;
2489 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
2491 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
2493 return priv->contains_pending_changes;
2497 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
2498 const gchar *first_widget,
2503 va_start (args, first_widget);
2504 account_widget_handle_params_valist (self, first_widget, args);
2509 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
2511 return widget->ui_details->widget;
2514 EmpathyAccountWidget *
2515 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
2518 EmpathyAccountWidget *self;
2520 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
2523 (EMPATHY_TYPE_ACCOUNT_WIDGET,
2524 "settings", settings, "simple", simple,
2526 empathy_account_settings_get_account (settings) == NULL,
2533 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
2535 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2536 const gchar *login_id;
2537 const gchar *protocol, *p;
2538 gchar *default_display_name;
2541 login_id = empathy_account_settings_get_string (priv->settings, "account");
2542 protocol = empathy_account_settings_get_protocol (priv->settings);
2543 service = account_widget_get_service (self);
2545 if (login_id != NULL)
2547 /* TODO: this should be done in empathy-account-widget-irc */
2548 if (!tp_strdiff (protocol, "irc"))
2550 EmpathyIrcNetwork *network;
2552 network = empathy_irc_network_chooser_get_network (
2553 priv->irc_network_chooser);
2554 g_assert (network != NULL);
2556 /* To translators: The first parameter is the login id and the
2557 * second one is the network. The resulting string will be something
2558 * like: "MyUserName on freenode".
2559 * You should reverse the order of these arguments if the
2560 * server should come before the login id in your locale.*/
2561 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2562 login_id, empathy_irc_network_get_name (network));
2564 else if (service == FACEBOOK_SERVICE)
2568 tmp = remove_jid_suffix (self, login_id);
2569 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2574 default_display_name = g_strdup (login_id);
2577 return default_display_name;
2580 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2583 if (protocol != NULL)
2585 /* To translators: The parameter is the protocol name. The resulting
2586 * string will be something like: "Jabber Account" */
2587 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2591 default_display_name = g_strdup (_("New account"));
2594 return default_display_name;
2597 /* Used by subclass to indicate that widget contains pending changes */
2599 empathy_account_widget_changed (EmpathyAccountWidget *self)
2601 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2603 account_widget_handle_control_buttons_sensitivity (self);
2604 priv->contains_pending_changes = TRUE;
2608 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2609 const gchar *account)
2611 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2613 if (priv->param_account_widget == NULL)
2616 gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
2620 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2621 const gchar *account)
2623 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2625 if (priv->param_password_widget == NULL)
2628 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);