2 * Copyright (C) 2006-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
20 * Martyn Russell <martyn@imendio.com>
21 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
22 * Jonathan Tellier <jonathan.tellier@gmail.com>
23 * Danielle Madeley <danielle.madeley@collabora.co.uk>
27 #include "tpaw-account-widget.h"
28 #include "tpaw-account-widget-private.h"
30 #include <glib/gi18n-lib.h>
31 #include <dbus/dbus-protocol.h>
33 #include "tpaw-account-widget-irc.h"
34 #include "tpaw-account-widget-private.h"
35 #include "tpaw-account-widget-sip.h"
36 #include "tpaw-builder.h"
37 #include "tpaw-utils.h"
39 #define DEBUG_FLAG TPAW_DEBUG_ACCOUNT
40 #include "tpaw-debug.h"
42 G_DEFINE_TYPE (TpawAccountWidget, tpaw_account_widget, GTK_TYPE_BOX)
54 const gchar *label_username_example;
55 gboolean show_advanced;
58 static ServiceInfo services_infos[N_SERVICES] = {
59 { "label_username_example", TRUE },
60 { "label_username_g_example", FALSE },
61 { "label_username_f_example", FALSE },
64 struct _TpawAccountWidgetPriv {
65 TpawAccountSettings *settings;
67 GtkWidget *grid_common_settings;
68 GtkWidget *apply_button;
69 GtkWidget *cancel_button;
70 GtkWidget *entry_password;
71 GtkWidget *spinbutton_port;
72 GtkWidget *radiobutton_reuse;
73 GtkWidget *hbox_buttons;
77 gboolean contains_pending_changes;
79 /* An TpawAccountWidget can be used to either create an account or
80 * modify it. When we are creating an account, this member is set to TRUE */
81 gboolean creating_account;
83 /* whether there are any other real accounts. Necessary so we know whether
84 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
85 * button should be sensitive) */
86 gboolean other_accounts_exist;
88 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
89 * embedded in this account widget can't be used any more
90 * workaround because some async callbacks can be called after the
91 * widget has been destroyed */
94 TpAccountManager *account_manager;
96 GtkWidget *param_account_widget;
97 GtkWidget *param_password_widget;
99 gboolean automatic_change;
100 GtkWidget *remember_password_widget;
102 /* Used only for IRC accounts */
103 TpawIrcNetworkChooser *irc_network_chooser;
105 /* Used for 'special' XMPP account having a service associated ensuring that
106 * JIDs have a specific suffix; such as Facebook for example */
114 PROP_CREATING_ACCOUNT,
115 PROP_OTHER_ACCOUNTS_EXIST,
130 static guint signals[LAST_SIGNAL] = { 0 };
132 #define CHANGED_TIMEOUT 300
135 #define DIGITS "(["DIGIT"]+)"
136 #define ALPHA "a-zA-Z"
137 #define ALPHAS "(["ALPHA"]+)"
138 #define ALPHADIGIT ALPHA DIGIT
139 #define ALPHADIGITS "(["ALPHADIGIT"]+)"
140 #define ALPHADIGITDASH ALPHA DIGIT "-"
141 #define ALPHADIGITDASHS "(["ALPHADIGITDASH"]*)"
143 #define HOSTNUMBER "("DIGITS"\\."DIGITS"\\."DIGITS"\\."DIGITS")"
144 #define TOPLABEL "("ALPHAS \
145 "| (["ALPHA"]"ALPHADIGITDASHS "["ALPHADIGIT"]))"
146 #define DOMAINLABEL "("ALPHADIGITS"|(["ALPHADIGIT"]" ALPHADIGITDASHS \
148 #define HOSTNAME "((" DOMAINLABEL "\\.)+" TOPLABEL ")"
149 /* Based on http://www.ietf.org/rfc/rfc1738.txt (section 5) */
150 #define HOST "("HOSTNAME "|" HOSTNUMBER")"
151 /* Based on http://www.ietf.org/rfc/rfc0822.txt (appendix D) */
152 #define EMAIL_LOCALPART "([^\\(\\)<>@,;:\\\\\"\\[\\]\\s]+)"
154 /* UIN is digital according to the unofficial specification:
155 * http://iserverd.khstu.ru/docum_ext/icqv5.html#CTS
156 * 5 digits minimum according to http://en.wikipedia.org/wiki/ICQ#UIN
157 * According to an user, we can also provide an email address instead of the
159 #define ICQ_USER_NAME "((["DIGIT"]{5,})|"EMAIL_LOCALPART"@"HOST")"
161 /* Based on http://www.ietf.org/rfc/rfc2812.txt (section 2.3.1) */
162 #define IRC_SPECIAL "_\\[\\]{}\\\\|`^"
163 #define IRC_NICK_NAME "(["ALPHA IRC_SPECIAL"]["ALPHADIGITDASH IRC_SPECIAL"]*)"
165 /* Based on http://www.ietf.org/rfc/rfc4622.txt (section 2.2)
166 * We just exclude invalid characters to avoid ucschars and other redundant
168 #define JABBER_USER_NAME "([^@:'\"<>&\\s]+)"
169 /* ID is an email according to the unofficial specification:
170 * http://www.hypothetic.org/docs/msn/general/names.php */
171 #define MSN_USER_NAME EMAIL_LOCALPART
172 /* Based on the official help:
173 * http://help.yahoo.com/l/us/yahoo/edit/registration/edit-01.html
174 * Looks like an email address can be used as well (bgo #655959)
176 #define YAHOO_USER_NAME "(["ALPHA"]["ALPHADIGIT"_\\.]{3,31})|("EMAIL_LOCALPART"@"HOST")"
178 #define ACCOUNT_REGEX_ICQ "^"ICQ_USER_NAME"$"
179 #define ACCOUNT_REGEX_IRC "^"IRC_NICK_NAME"$"
180 #define ACCOUNT_REGEX_JABBER "^"JABBER_USER_NAME"@[^@/]+"
181 #define ACCOUNT_REGEX_MSN "^"MSN_USER_NAME"@"HOST"$"
182 #define ACCOUNT_REGEX_YAHOO "^"YAHOO_USER_NAME"$"
185 account_widget_set_control_buttons_sensitivity (TpawAccountWidget *self,
188 /* we hit this case because of the 'other-accounts-exist' property handler
189 * being called during init (before constructed()) */
190 if (self->priv->apply_button == NULL || self->priv->cancel_button == NULL)
193 gtk_widget_set_sensitive (self->priv->apply_button, sensitive);
197 /* We can't grab default if the widget hasn't be packed in a
201 window = gtk_widget_get_toplevel (self->priv->apply_button);
202 if (window != NULL &&
203 gtk_widget_is_toplevel (window))
205 gtk_widget_set_can_default (self->priv->apply_button, TRUE);
206 gtk_widget_grab_default (self->priv->apply_button);
212 account_widget_set_entry_highlighting (GtkEntry *entry,
215 g_return_if_fail (GTK_IS_ENTRY (entry));
219 GtkStyleContext *style;
222 style = gtk_widget_get_style_context (GTK_WIDGET (entry));
223 gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
226 /* Here we take the current theme colour and add it to
227 * the colour for white and average the two. This
228 * gives a colour which is inline with the theme but
231 tpaw_make_color_whiter (&color);
233 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, &color);
237 gtk_widget_override_background_color (GTK_WIDGET (entry), 0, NULL);
242 account_widget_handle_control_buttons_sensitivity (TpawAccountWidget *self)
246 is_valid = tpaw_account_settings_is_valid (self->priv->settings);
248 account_widget_set_control_buttons_sensitivity (self, is_valid);
250 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
254 account_widget_entry_changed_common (TpawAccountWidget *self,
255 GtkEntry *entry, gboolean focus)
258 const gchar *param_name;
259 gboolean prev_status;
260 gboolean curr_status;
262 str = gtk_entry_get_text (entry);
263 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
264 prev_status = tpaw_account_settings_parameter_is_valid (
265 self->priv->settings, param_name);
267 if (TPAW_STR_EMPTY (str))
269 tpaw_account_settings_unset (self->priv->settings, param_name);
275 value = tpaw_account_settings_dup_string (self->priv->settings,
278 DEBUG ("Unset %s and restore to %s", param_name, value);
279 gtk_entry_set_text (entry, value ? value : "");
285 DEBUG ("Setting %s to %s", param_name,
286 tp_strdiff (param_name, "password") ? str : "***");
287 tpaw_account_settings_set (self->priv->settings, param_name,
288 g_variant_new_string (str));
291 curr_status = tpaw_account_settings_parameter_is_valid (
292 self->priv->settings, param_name);
294 if (curr_status != prev_status)
295 account_widget_set_entry_highlighting (entry, !curr_status);
299 account_widget_entry_changed_cb (GtkEditable *entry,
300 TpawAccountWidget *self)
302 if (self->priv->automatic_change)
305 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
306 tpaw_account_widget_changed (self);
310 account_widget_entry_map_cb (GtkEntry *entry,
311 TpawAccountWidget *self)
313 const gchar *param_name;
316 /* need to initialize input highlighting */
317 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
318 is_valid = tpaw_account_settings_parameter_is_valid (self->priv->settings,
320 account_widget_set_entry_highlighting (entry, !is_valid);
324 account_widget_int_changed_cb (GtkWidget *widget,
325 TpawAccountWidget *self)
327 const gchar *param_name;
329 const gchar *signature;
331 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
332 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
334 signature = tpaw_account_settings_get_dbus_signature (self->priv->settings,
336 g_return_if_fail (signature != NULL);
338 DEBUG ("Setting %s to %d", param_name, value);
340 switch ((int)*signature)
342 case DBUS_TYPE_INT16:
343 case DBUS_TYPE_INT32:
344 tpaw_account_settings_set (self->priv->settings, param_name,
345 g_variant_new_int32 (value));
347 case DBUS_TYPE_INT64:
348 tpaw_account_settings_set (self->priv->settings, param_name,
349 g_variant_new_int64 (value));
351 case DBUS_TYPE_UINT16:
352 case DBUS_TYPE_UINT32:
353 tpaw_account_settings_set (self->priv->settings, param_name,
354 g_variant_new_uint32 (value));
356 case DBUS_TYPE_UINT64:
357 tpaw_account_settings_set (self->priv->settings, param_name,
358 g_variant_new_uint64 (value));
361 g_return_if_reached ();
364 tpaw_account_widget_changed (self);
368 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
369 TpawAccountWidget *self)
372 gboolean default_value;
373 const gchar *param_name;
375 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
376 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
378 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
379 * always unset the param and set the value if different from the
381 tpaw_account_settings_unset (self->priv->settings, param_name);
382 default_value = tpaw_account_settings_get_boolean (self->priv->settings,
385 if (default_value == value)
387 DEBUG ("Unset %s and restore to %d", param_name, default_value);
391 DEBUG ("Setting %s to %d", param_name, value);
392 tpaw_account_settings_set (self->priv->settings, param_name,
393 g_variant_new_boolean (value));
396 tpaw_account_widget_changed (self);
400 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
401 TpawAccountWidget *self)
406 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
407 port = tpaw_account_settings_get_uint32 (self->priv->settings, "port");
411 if (port == 5222 || port == 0)
416 if (port == 5223 || port == 0)
420 gtk_spin_button_set_value (GTK_SPIN_BUTTON (self->priv->spinbutton_port),
423 self->priv->contains_pending_changes = TRUE;
427 account_widget_combobox_changed_cb (GtkWidget *widget,
428 TpawAccountWidget *self)
434 const gchar *default_value = NULL;
435 const gchar *param_name;
437 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
440 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
441 /* the param value is stored in the first column */
442 gtk_tree_model_get (model, &iter, 0, &value, -1);
444 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
446 v = tpaw_account_settings_dup_default (self->priv->settings, param_name);
447 if (v != NULL && g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
448 default_value = g_variant_get_string (v, NULL);
450 if (!tp_strdiff (value, default_value))
452 DEBUG ("Unset %s and restore to %s", param_name, default_value);
453 tpaw_account_settings_unset (self->priv->settings, param_name);
457 DEBUG ("Setting %s to %s", param_name, value);
458 tpaw_account_settings_set (self->priv->settings, param_name,
459 g_variant_new_string (value));
462 tpaw_account_widget_changed (self);
464 tp_clear_pointer (&v, g_variant_unref);
468 clear_icon_released_cb (GtkEntry *entry,
469 GtkEntryIconPosition icon_pos,
471 TpawAccountWidget *self)
473 const gchar *param_name;
475 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
477 DEBUG ("Unset %s", param_name);
478 tpaw_account_settings_unset (self->priv->settings, param_name);
479 gtk_entry_set_text (entry, "");
481 tpaw_account_widget_changed (self);
485 password_entry_changed_cb (GtkEditable *entry,
486 TpawAccountWidget *self)
490 str = gtk_entry_get_text (GTK_ENTRY (entry));
492 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
493 GTK_ENTRY_ICON_SECONDARY, !TPAW_STR_EMPTY (str));
497 password_entry_activated_cb (GtkEntry *entry,
498 TpawAccountWidget *self)
500 if (gtk_widget_get_sensitive (self->priv->apply_button))
501 tpaw_account_widget_apply_and_log_in (self);
505 account_entry_activated_cb (GtkEntry *entry,
506 TpawAccountWidget *self)
508 if (gtk_widget_get_sensitive (self->priv->apply_button))
509 tpaw_account_widget_apply_and_log_in (self);
513 tpaw_account_widget_setup_widget (TpawAccountWidget *self,
515 const gchar *param_name)
517 g_object_set_data_full (G_OBJECT (widget), "param_name",
518 g_strdup (param_name), g_free);
520 if (GTK_IS_SPIN_BUTTON (widget))
523 const gchar *signature;
525 signature = tpaw_account_settings_get_dbus_signature (
526 self->priv->settings, param_name);
527 g_return_if_fail (signature != NULL);
529 switch ((int)*signature)
531 case DBUS_TYPE_INT16:
532 case DBUS_TYPE_INT32:
533 value = tpaw_account_settings_get_int32 (self->priv->settings,
536 case DBUS_TYPE_INT64:
537 value = tpaw_account_settings_get_int64 (self->priv->settings,
540 case DBUS_TYPE_UINT16:
541 case DBUS_TYPE_UINT32:
542 value = tpaw_account_settings_get_uint32 (self->priv->settings,
545 case DBUS_TYPE_UINT64:
546 value = tpaw_account_settings_get_uint64 (self->priv->settings,
550 g_return_if_reached ();
553 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
555 g_signal_connect (widget, "value-changed",
556 G_CALLBACK (account_widget_int_changed_cb),
559 else if (GTK_IS_ENTRY (widget))
563 str = tpaw_account_settings_dup_string (self->priv->settings,
565 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
567 if (!tp_strdiff (param_name, "account"))
568 self->priv->param_account_widget = widget;
569 else if (!tp_strdiff (param_name, "password"))
570 self->priv->param_password_widget = widget;
572 if (strstr (param_name, "password"))
574 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
576 /* Add 'clear' icon */
577 gtk_entry_set_icon_from_stock (GTK_ENTRY (widget),
578 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
580 gtk_entry_set_icon_sensitive (GTK_ENTRY (widget),
581 GTK_ENTRY_ICON_SECONDARY, !TPAW_STR_EMPTY (str));
583 g_signal_connect (widget, "icon-release",
584 G_CALLBACK (clear_icon_released_cb), self);
585 g_signal_connect (widget, "changed",
586 G_CALLBACK (password_entry_changed_cb), self);
587 g_signal_connect (widget, "activate",
588 G_CALLBACK (password_entry_activated_cb), self);
590 else if (strstr (param_name, "account"))
591 g_signal_connect (widget, "activate",
592 G_CALLBACK (account_entry_activated_cb), self);
594 g_signal_connect (widget, "changed",
595 G_CALLBACK (account_widget_entry_changed_cb), self);
596 g_signal_connect (widget, "map",
597 G_CALLBACK (account_widget_entry_map_cb), self);
601 else if (GTK_IS_TOGGLE_BUTTON (widget))
603 gboolean value = FALSE;
605 value = tpaw_account_settings_get_boolean (self->priv->settings,
607 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
609 g_signal_connect (widget, "toggled",
610 G_CALLBACK (account_widget_checkbutton_toggled_cb),
613 else if (GTK_IS_COMBO_BOX (widget))
615 /* The combo box's model has to contain the param value in its first
616 * column (as a string) */
622 str = tpaw_account_settings_dup_string (self->priv->settings,
624 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
626 valid = gtk_tree_model_get_iter_first (model, &iter);
631 gtk_tree_model_get (model, &iter, 0, &name, -1);
632 if (!tp_strdiff (name, str))
634 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
639 valid = gtk_tree_model_iter_next (model, &iter);
647 g_signal_connect (widget, "changed",
648 G_CALLBACK (account_widget_combobox_changed_cb),
653 DEBUG ("Unknown type of widget for param %s", param_name);
656 gtk_widget_set_sensitive (widget,
657 tpaw_account_settings_param_is_supported (self->priv->settings,
662 build_translated_params (void)
666 hash = g_hash_table_new (g_str_hash, g_str_equal);
667 g_hash_table_insert (hash, "account", _("Account"));
668 g_hash_table_insert (hash, "password", _("Password"));
669 g_hash_table_insert (hash, "server", _("Server"));
670 g_hash_table_insert (hash, "port", _("Port"));
676 account_widget_generic_format_param_name (const gchar *param_name)
680 static GHashTable *translated_params = NULL;
682 g_return_val_if_fail (param_name != NULL, NULL);
684 if (G_UNLIKELY (translated_params == NULL))
685 translated_params = build_translated_params ();
687 /* Translate most common parameters */
688 str = g_hash_table_lookup (translated_params, param_name);
690 return g_strdup (str);
692 str = g_strdup (param_name);
694 if (str && g_ascii_isalpha (str[0]))
695 str[0] = g_ascii_toupper (str[0]);
697 while ((p = strchr (str, '-')) != NULL)
699 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
702 p[1] = g_ascii_toupper (p[1]);
712 accounts_widget_generic_setup (TpawAccountWidget *self,
713 GtkWidget *grid_common_settings,
714 GtkWidget *grid_advanced_settings)
717 guint row_common = 0, row_advanced = 0;
719 params = tpaw_account_settings_dup_tp_params (self->priv->settings);
721 for (l = params; l != NULL; l = g_list_next (l))
723 TpConnectionManagerParam *param = l->data;
724 GtkWidget *grid_settings;
726 GtkWidget *widget = NULL;
727 gchar *param_name_formatted;
728 const gchar *dbus_signature;
730 if (tp_connection_manager_param_is_required (param))
732 grid_settings = grid_common_settings;
735 else if (self->priv->simple)
741 grid_settings = grid_advanced_settings;
742 row = row_advanced++;
745 param_name_formatted = account_widget_generic_format_param_name (
746 tp_connection_manager_param_get_name (param));
748 dbus_signature = tp_connection_manager_param_get_dbus_signature (param);
750 if (dbus_signature[0] == 's')
754 str = g_strdup_printf (_("%s"), param_name_formatted);
755 widget = gtk_label_new (str);
756 gtk_misc_set_alignment (GTK_MISC (widget), 1., 0.5);
757 gtk_style_context_add_class (gtk_widget_get_style_context (widget),
758 GTK_STYLE_CLASS_DIM_LABEL);
761 gtk_grid_attach (GTK_GRID (grid_settings),
762 widget, 0, row, 1, 1);
764 gtk_widget_show (widget);
766 widget = gtk_entry_new ();
767 if (g_strcmp0 (tp_connection_manager_param_get_name (param),
770 g_signal_connect (widget, "realize",
771 G_CALLBACK (gtk_widget_grab_focus),
775 gtk_grid_attach (GTK_GRID (grid_settings),
776 widget, 1, row, 1, 1);
778 gtk_widget_show (widget);
780 /* int types: ynqiuxt. double type is 'd' */
781 else if (dbus_signature[0] == 'y' ||
782 dbus_signature[0] == 'n' ||
783 dbus_signature[0] == 'q' ||
784 dbus_signature[0] == 'i' ||
785 dbus_signature[0] == 'u' ||
786 dbus_signature[0] == 'x' ||
787 dbus_signature[0] == 't' ||
788 dbus_signature[0] == 'd')
795 switch (dbus_signature[0])
797 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
798 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
799 case 'q': minint = 0; maxint = G_MAXUINT16; break;
800 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
801 case 'u': minint = 0; maxint = G_MAXUINT32; break;
802 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
803 case 't': minint = 0; maxint = G_MAXUINT64; break;
804 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
806 default: g_assert_not_reached ();
809 str = g_strdup_printf (_("%s:"), param_name_formatted);
810 widget = gtk_label_new (str);
811 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
814 gtk_grid_attach (GTK_GRID (grid_settings),
815 widget, 0, row, 1, 1);
816 gtk_widget_show (widget);
818 widget = gtk_spin_button_new_with_range (minint, maxint, step);
819 gtk_grid_attach (GTK_GRID (grid_settings),
820 widget, 1, row, 1, 1);
821 gtk_widget_show (widget);
823 else if (dbus_signature[0] == 'b')
825 widget = gtk_check_button_new_with_label (param_name_formatted);
826 gtk_grid_attach (GTK_GRID (grid_settings),
827 widget, 0, row, 2, 1);
828 gtk_widget_show (widget);
832 DEBUG ("Unknown signature for param %s: %s",
833 param_name_formatted, dbus_signature);
837 tpaw_account_widget_setup_widget (self, widget,
838 tp_connection_manager_param_get_name (param));
840 g_free (param_name_formatted);
843 g_list_free_full (params, (GDestroyNotify) tp_connection_manager_param_free);
847 account_widget_handle_params_valist (TpawAccountWidget *self,
848 const gchar *first_widget,
854 for (name = first_widget; name; name = va_arg (args, const gchar *))
856 const gchar *param_name;
858 param_name = va_arg (args, const gchar *);
859 object = gtk_builder_get_object (self->ui_details->gui, name);
863 g_warning ("Builder is missing object '%s'.", name);
867 tpaw_account_widget_setup_widget (self, GTK_WIDGET (object),
873 account_widget_cancel_clicked_cb (GtkWidget *button,
874 TpawAccountWidget *self)
876 g_signal_emit (self, signals[CANCELLED], 0);
877 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_CANCEL);
881 account_widget_account_enabled_cb (GObject *source_object,
885 GError *error = NULL;
886 TpAccount *account = TP_ACCOUNT (source_object);
887 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (user_data);
889 tp_account_set_enabled_finish (account, res, &error);
893 DEBUG ("Could not enable the account: %s", error->message);
894 g_error_free (error);
898 tpaw_connect_new_account (account, self->priv->account_manager);
901 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY);
903 /* unref self - part of the workaround */
904 g_object_unref (self);
908 account_widget_applied_cb (GObject *source_object,
912 GError *error = NULL;
914 TpawAccountSettings *settings = TPAW_ACCOUNT_SETTINGS (source_object);
915 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (user_data);
916 gboolean reconnect_required;
917 gboolean fire_close = TRUE;
919 tpaw_account_settings_apply_finish (settings, res, &reconnect_required,
924 DEBUG ("Could not apply changes to account: %s", error->message);
925 g_error_free (error);
929 account = tpaw_account_settings_get_account (self->priv->settings);
933 if (self->priv->creating_account)
935 /* By default, when an account is created, we enable it. */
937 /* workaround to keep self alive during async call */
940 tp_account_set_enabled_async (account, TRUE,
941 account_widget_account_enabled_cb, self);
942 g_signal_emit (self, signals[ACCOUNT_CREATED], 0, account);
944 /* Will be fired in account_widget_account_enabled_cb */
949 /* If the account was offline, we always want to try reconnecting,
950 * to give it a chance to connect if the previous params were wrong.
951 * tp_account_reconnect_async() won't do anything if the requested
952 * presence is offline anyway. */
953 if (tp_account_get_connection_status (account, NULL) ==
954 TP_CONNECTION_STATUS_DISCONNECTED)
955 reconnect_required = TRUE;
957 if (reconnect_required && tp_account_is_enabled (account)
958 && tp_account_is_enabled (account))
960 /* After having applied changes to a user account, we
961 * reconnect it if needed. This is done so the new
962 * information entered by the user is validated on the server. */
963 tp_account_reconnect_async (account, NULL, NULL);
968 if (!self->priv->destroyed)
969 account_widget_set_control_buttons_sensitivity (self, FALSE);
971 self->priv->contains_pending_changes = FALSE;
975 /* announce the widget can be closed */
976 g_signal_emit (self, signals[CLOSE], 0, GTK_RESPONSE_APPLY);
979 /* unref the widget - part of the workaround */
980 g_object_unref (self);
984 tpaw_account_widget_apply_and_log_in (TpawAccountWidget *self)
986 gboolean display_name_overridden;
988 if (self->priv->radiobutton_reuse != NULL)
990 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
991 self->priv->radiobutton_reuse));
993 DEBUG ("Set register param: %d", !reuse);
994 tpaw_account_settings_set (self->priv->settings, "register",
995 g_variant_new_boolean (!reuse));
998 g_object_get (self->priv->settings,
999 "display-name-overridden", &display_name_overridden, NULL);
1001 if (self->priv->creating_account || !display_name_overridden)
1003 gchar *display_name;
1005 /* set default display name for new accounts or update if user didn't
1006 * manually override it. */
1007 display_name = tpaw_account_widget_get_default_display_name (self);
1009 tpaw_account_settings_set_display_name_async (self->priv->settings,
1010 display_name, NULL, NULL);
1012 g_free (display_name);
1015 /* workaround to keep widget alive during async call */
1016 g_object_ref (self);
1017 tpaw_account_settings_apply_async (self->priv->settings,
1018 account_widget_applied_cb, self);
1022 account_widget_apply_clicked_cb (GtkWidget *button,
1023 TpawAccountWidget *self)
1025 tpaw_account_widget_apply_and_log_in (self);
1029 account_widget_setup_generic (TpawAccountWidget *self)
1031 GtkWidget *grid_common_settings;
1032 GtkWidget *grid_advanced_settings;
1034 grid_common_settings = GTK_WIDGET (gtk_builder_get_object
1035 (self->ui_details->gui, "grid_common_settings"));
1036 grid_advanced_settings = GTK_WIDGET (gtk_builder_get_object
1037 (self->ui_details->gui, "grid_advanced_settings"));
1039 accounts_widget_generic_setup (self, grid_common_settings,
1040 grid_advanced_settings);
1042 g_object_unref (self->ui_details->gui);
1046 account_widget_settings_ready_cb (TpawAccountSettings *settings,
1050 TpawAccountWidget *self = user_data;
1052 if (tpaw_account_settings_is_ready (self->priv->settings))
1053 account_widget_setup_generic (self);
1057 account_widget_build_generic (TpawAccountWidget *self,
1058 const char *filename)
1060 GtkWidget *expander_advanced, *box;
1062 self->ui_details->gui = tpaw_builder_get_resource (filename,
1063 "grid_common_settings", &self->priv->grid_common_settings,
1064 "vbox_generic_settings", &box,
1065 "expander_advanced_settings", &expander_advanced,
1068 if (self->priv->simple)
1069 gtk_widget_hide (expander_advanced);
1071 g_object_ref (self->ui_details->gui);
1073 if (tpaw_account_settings_is_ready (self->priv->settings))
1074 account_widget_setup_generic (self);
1076 g_signal_connect (self->priv->settings, "notify::ready",
1077 G_CALLBACK (account_widget_settings_ready_cb), self);
1083 account_widget_build_salut (TpawAccountWidget *self,
1084 const char *filename)
1086 GtkWidget *expander_advanced, *box;
1088 self->ui_details->gui = tpaw_builder_get_resource (filename,
1089 "grid_common_settings", &self->priv->grid_common_settings,
1090 "vbox_salut_settings", &box,
1091 "expander_advanced_settings", &expander_advanced,
1094 tpaw_account_widget_handle_params (self,
1095 "entry_published", "published-name",
1096 "entry_nickname", "nickname",
1097 "entry_first_name", "first-name",
1098 "entry_last_name", "last-name",
1099 "entry_email", "email",
1103 if (self->priv->simple)
1104 gtk_widget_hide (expander_advanced);
1106 self->ui_details->default_focus = g_strdup ("entry_first_name");
1112 account_widget_build_irc (TpawAccountWidget *self,
1113 const char *filename)
1117 tpaw_account_settings_set_regex (self->priv->settings, "account",
1120 if (self->priv->simple)
1122 self->priv->irc_network_chooser = tpaw_account_widget_irc_build_simple
1123 (self, filename, &box);
1127 self->priv->irc_network_chooser = tpaw_account_widget_irc_build (self,
1128 filename, &self->priv->grid_common_settings, &box);
1135 account_widget_build_sip (TpawAccountWidget *self,
1136 const char *filename)
1140 box = tpaw_account_widget_sip_build (self, filename,
1141 &self->priv->grid_common_settings);
1143 if (self->priv->simple)
1145 self->priv->remember_password_widget = GTK_WIDGET (
1146 gtk_builder_get_object (self->ui_details->gui,
1147 "remember_password_simple"));
1151 self->priv->remember_password_widget = GTK_WIDGET (
1152 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1159 account_widget_build_msn (TpawAccountWidget *self,
1160 const char *filename)
1164 tpaw_account_settings_set_regex (self->priv->settings, "account",
1167 if (self->priv->simple)
1169 self->ui_details->gui = tpaw_builder_get_resource (filename,
1170 "vbox_msn_simple", &box,
1173 tpaw_account_widget_handle_params (self,
1174 "entry_id_simple", "account",
1175 "entry_password_simple", "password",
1178 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1180 self->priv->remember_password_widget = GTK_WIDGET (
1181 gtk_builder_get_object (self->ui_details->gui,
1182 "remember_password_simple"));
1186 self->ui_details->gui = tpaw_builder_get_resource (filename,
1187 "grid_common_msn_settings", &self->priv->grid_common_settings,
1188 "vbox_msn_settings", &box,
1191 tpaw_account_widget_handle_params (self,
1192 "entry_id", "account",
1193 "entry_password", "password",
1194 "entry_server", "server",
1195 "spinbutton_port", "port",
1198 self->ui_details->default_focus = g_strdup ("entry_id");
1200 self->priv->remember_password_widget = GTK_WIDGET (
1201 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1208 suffix_id_widget_changed_cb (GtkWidget *entry,
1209 TpawAccountWidget *self)
1213 g_assert (self->priv->jid_suffix != NULL);
1215 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
1217 account = tpaw_account_settings_dup_string (self->priv->settings,
1220 if (!TPAW_STR_EMPTY (account) &&
1221 !g_str_has_suffix (account, self->priv->jid_suffix))
1225 tmp = g_strdup_printf ("%s%s", account, self->priv->jid_suffix);
1227 DEBUG ("Change account from '%s' to '%s'", account, tmp);
1229 tpaw_account_settings_set (self->priv->settings, "account",
1230 g_variant_new_string (tmp));
1234 tpaw_account_widget_changed (self);
1240 remove_jid_suffix (TpawAccountWidget *self,
1243 g_assert (self->priv->jid_suffix != NULL);
1245 if (!g_str_has_suffix (str, self->priv->jid_suffix))
1246 return g_strdup (str);
1248 return g_strndup (str, strlen (str) - strlen (self->priv->jid_suffix));
1252 setup_id_widget_with_suffix (TpawAccountWidget *self,
1254 const gchar *suffix)
1258 g_object_set_data_full (G_OBJECT (widget), "param_name",
1259 g_strdup ("account"), g_free);
1261 g_assert (self->priv->jid_suffix == NULL);
1262 self->priv->jid_suffix = g_strdup (suffix);
1264 str = tpaw_account_settings_dup_string (self->priv->settings, "account");
1269 tmp = remove_jid_suffix (self, str);
1270 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1275 self->priv->param_account_widget = widget;
1277 g_signal_connect (widget, "changed",
1278 G_CALLBACK (suffix_id_widget_changed_cb), self);
1282 account_widget_get_service (TpawAccountWidget *self)
1284 const gchar *icon_name, *service;
1286 icon_name = tpaw_account_settings_get_icon_name (self->priv->settings);
1287 service = tpaw_account_settings_get_service (self->priv->settings);
1289 /* Previous versions of Tpaw didn't set the Service property on Facebook
1290 * and gtalk accounts, so we check using the icon name as well. */
1291 if (!tp_strdiff (icon_name, "im-google-talk") ||
1292 !tp_strdiff (service, "google-talk"))
1293 return GTALK_SERVICE;
1295 if (!tp_strdiff (icon_name, "im-facebook") ||
1296 !tp_strdiff (service, "facebook"))
1297 return FACEBOOK_SERVICE;
1303 account_widget_build_jabber (TpawAccountWidget *self,
1304 const char *filename)
1306 GtkWidget *spinbutton_port;
1307 GtkWidget *checkbutton_ssl;
1308 GtkWidget *label_id, *label_password;
1309 GtkWidget *label_id_create, *label_password_create;
1310 GtkWidget *label_example_fb;
1311 GtkWidget *label_example;
1312 GtkWidget *expander_advanced;
1313 GtkWidget *entry_id;
1317 service = account_widget_get_service (self);
1319 tpaw_account_settings_set_regex (self->priv->settings, "account",
1320 ACCOUNT_REGEX_JABBER);
1322 if (self->priv->simple && service == NO_SERVICE)
1324 /* Simple widget for XMPP */
1325 self->ui_details->gui = tpaw_builder_get_resource (filename,
1326 "vbox_jabber_simple", &box,
1327 "label_id_simple", &label_id,
1328 "label_id_create", &label_id_create,
1329 "label_password_simple", &label_password,
1330 "label_password_create", &label_password_create,
1333 if (tpaw_account_settings_get_boolean (self->priv->settings,
1336 gtk_widget_hide (label_id);
1337 gtk_widget_hide (label_password);
1338 gtk_widget_show (label_id_create);
1339 gtk_widget_show (label_password_create);
1342 tpaw_account_widget_handle_params (self,
1343 "entry_id_simple", "account",
1344 "entry_password_simple", "password",
1347 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1349 self->priv->remember_password_widget = GTK_WIDGET (
1350 gtk_builder_get_object (self->ui_details->gui,
1351 "remember_password_simple"));
1353 else if (self->priv->simple && service == GTALK_SERVICE)
1355 /* Simple widget for Google Talk */
1356 self->ui_details->gui = tpaw_builder_get_resource (filename,
1357 "vbox_gtalk_simple", &box,
1360 tpaw_account_widget_handle_params (self,
1361 "entry_id_g_simple", "account",
1362 "entry_password_g_simple", "password",
1365 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1367 self->priv->remember_password_widget = GTK_WIDGET (
1368 gtk_builder_get_object (self->ui_details->gui,
1369 "remember_password_g_simple"));
1371 else if (self->priv->simple && service == FACEBOOK_SERVICE)
1373 /* Simple widget for Facebook */
1374 self->ui_details->gui = tpaw_builder_get_resource (filename,
1375 "vbox_fb_simple", &box,
1376 "entry_id_fb_simple", &entry_id,
1379 tpaw_account_widget_handle_params (self,
1380 "entry_password_fb_simple", "password",
1383 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1385 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1387 self->priv->remember_password_widget = GTK_WIDGET (
1388 gtk_builder_get_object (self->ui_details->gui,
1389 "remember_password_fb_simple"));
1393 ServiceInfo info = services_infos[service];
1395 /* Full widget for XMPP, Google Talk and Facebook*/
1396 self->ui_details->gui = tpaw_builder_get_resource (filename,
1397 "grid_common_settings", &self->priv->grid_common_settings,
1398 "vbox_jabber_settings", &box,
1399 "spinbutton_port", &spinbutton_port,
1400 "checkbutton_ssl", &checkbutton_ssl,
1401 "label_username_f_example", &label_example_fb,
1402 info.label_username_example, &label_example,
1403 "expander_advanced", &expander_advanced,
1404 "entry_id", &entry_id,
1405 "label_id", &label_id,
1408 tpaw_account_widget_handle_params (self,
1409 "entry_password", "password",
1410 "entry_resource", "resource",
1411 "entry_server", "server",
1412 "spinbutton_port", "port",
1413 "spinbutton_priority", "priority",
1414 "checkbutton_ssl", "old-ssl",
1415 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1416 "checkbutton_encryption", "require-encryption",
1419 if (service == FACEBOOK_SERVICE)
1421 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1423 /* Facebook special case the entry ID widget to hide the
1424 * "@chat.facebook.com" part */
1425 setup_id_widget_with_suffix (self, entry_id, "@chat.facebook.com");
1429 tpaw_account_widget_setup_widget (self, entry_id, "account");
1432 self->ui_details->default_focus = g_strdup ("entry_id");
1433 self->priv->spinbutton_port = spinbutton_port;
1435 self->priv->remember_password_widget = GTK_WIDGET (
1436 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1438 g_signal_connect (checkbutton_ssl, "toggled",
1439 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1442 if (service == FACEBOOK_SERVICE)
1444 GtkContainer *parent;
1447 /* Removing the label from list of focusable widgets */
1448 parent = GTK_CONTAINER (gtk_widget_get_parent (label_example_fb));
1449 children = gtk_container_get_children (parent);
1450 children = g_list_remove (children, label_example_fb);
1451 gtk_container_set_focus_chain (parent, children);
1452 g_list_free (children);
1455 gtk_widget_show (label_example);
1457 if (!info.show_advanced)
1458 gtk_widget_hide (expander_advanced);
1465 account_widget_build_icq (TpawAccountWidget *self,
1466 const char *filename)
1468 GtkWidget *spinbutton_port;
1471 tpaw_account_settings_set_regex (self->priv->settings, "account",
1474 if (self->priv->simple)
1476 self->ui_details->gui = tpaw_builder_get_resource (filename,
1477 "vbox_icq_simple", &box,
1480 tpaw_account_widget_handle_params (self,
1481 "entry_uin_simple", "account",
1482 "entry_password_simple", "password",
1485 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1487 self->priv->remember_password_widget = GTK_WIDGET (
1488 gtk_builder_get_object (self->ui_details->gui,
1489 "remember_password_simple"));
1493 self->ui_details->gui = tpaw_builder_get_resource (filename,
1494 "grid_common_settings", &self->priv->grid_common_settings,
1495 "vbox_icq_settings", &box,
1496 "spinbutton_port", &spinbutton_port,
1499 tpaw_account_widget_handle_params (self,
1500 "entry_uin", "account",
1501 "entry_password", "password",
1502 "entry_server", "server",
1503 "spinbutton_port", "port",
1504 "entry_charset", "charset",
1507 self->ui_details->default_focus = g_strdup ("entry_uin");
1509 self->priv->remember_password_widget = GTK_WIDGET (
1510 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1517 account_widget_build_aim (TpawAccountWidget *self,
1518 const char *filename)
1520 GtkWidget *spinbutton_port, *box;
1522 if (self->priv->simple)
1524 self->ui_details->gui = tpaw_builder_get_resource (filename,
1525 "vbox_aim_simple", &box,
1528 tpaw_account_widget_handle_params (self,
1529 "entry_screenname_simple", "account",
1530 "entry_password_simple", "password",
1533 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1535 self->priv->remember_password_widget = GTK_WIDGET (
1536 gtk_builder_get_object (self->ui_details->gui,
1537 "remember_password_simple"));
1541 self->ui_details->gui = tpaw_builder_get_resource (filename,
1542 "grid_common_settings", &self->priv->grid_common_settings,
1543 "vbox_aim_settings", &box,
1544 "spinbutton_port", &spinbutton_port,
1547 tpaw_account_widget_handle_params (self,
1548 "entry_screenname", "account",
1549 "entry_password", "password",
1550 "entry_server", "server",
1551 "spinbutton_port", "port",
1554 self->ui_details->default_focus = g_strdup ("entry_screenname");
1556 self->priv->remember_password_widget = GTK_WIDGET (
1557 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1564 account_widget_build_yahoo (TpawAccountWidget *self,
1565 const char *filename)
1569 tpaw_account_settings_set_regex (self->priv->settings, "account",
1570 ACCOUNT_REGEX_YAHOO);
1572 if (self->priv->simple)
1574 self->ui_details->gui = tpaw_builder_get_resource (filename,
1575 "vbox_yahoo_simple", &box,
1578 tpaw_account_widget_handle_params (self,
1579 "entry_id_simple", "account",
1580 "entry_password_simple", "password",
1583 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1585 self->priv->remember_password_widget = GTK_WIDGET (
1586 gtk_builder_get_object (self->ui_details->gui,
1587 "remember_password_simple"));
1591 self->ui_details->gui = tpaw_builder_get_resource (filename,
1592 "grid_common_settings", &self->priv->grid_common_settings,
1593 "vbox_yahoo_settings", &box,
1596 tpaw_account_widget_handle_params (self,
1597 "entry_id", "account",
1598 "entry_password", "password",
1599 "entry_locale", "room-list-locale",
1600 "entry_charset", "charset",
1601 "spinbutton_port", "port",
1602 "checkbutton_ignore_invites", "ignore-invites",
1605 self->ui_details->default_focus = g_strdup ("entry_id");
1607 self->priv->remember_password_widget = GTK_WIDGET (
1608 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1615 account_widget_build_groupwise (TpawAccountWidget *self,
1616 const char *filename)
1620 if (self->priv->simple)
1622 self->ui_details->gui = tpaw_builder_get_resource (filename,
1623 "vbox_groupwise_simple", &box,
1626 tpaw_account_widget_handle_params (self,
1627 "entry_id_simple", "account",
1628 "entry_password_simple", "password",
1631 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1633 self->priv->remember_password_widget = GTK_WIDGET (
1634 gtk_builder_get_object (self->ui_details->gui,
1635 "remember_password_simple"));
1639 self->ui_details->gui = tpaw_builder_get_resource (filename,
1640 "grid_common_groupwise_settings", &self->priv->grid_common_settings,
1641 "vbox_groupwise_settings", &box,
1644 tpaw_account_widget_handle_params (self,
1645 "entry_id", "account",
1646 "entry_password", "password",
1647 "entry_server", "server",
1648 "spinbutton_port", "port",
1651 self->ui_details->default_focus = g_strdup ("entry_id");
1653 self->priv->remember_password_widget = GTK_WIDGET (
1654 gtk_builder_get_object (self->ui_details->gui, "remember_password"));
1661 tpaw_account_widget_set_other_accounts_exist (TpawAccountWidget *self,
1662 gboolean others_exist)
1664 self->priv->other_accounts_exist = others_exist;
1666 if (self->priv->creating_account)
1667 account_widget_handle_control_buttons_sensitivity (self);
1671 do_set_property (GObject *object,
1673 const GValue *value,
1676 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (object);
1681 self->priv->settings = g_value_dup_object (value);
1684 self->priv->simple = g_value_get_boolean (value);
1686 case PROP_CREATING_ACCOUNT:
1687 self->priv->creating_account = g_value_get_boolean (value);
1689 case PROP_OTHER_ACCOUNTS_EXIST:
1690 tpaw_account_widget_set_other_accounts_exist (
1691 TPAW_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1694 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1699 do_get_property (GObject *object,
1704 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (object);
1709 g_value_set_string (value,
1710 tpaw_account_settings_get_protocol (self->priv->settings));
1713 g_value_set_object (value, self->priv->settings);
1716 g_value_set_boolean (value, self->priv->simple);
1718 case PROP_CREATING_ACCOUNT:
1719 g_value_set_boolean (value, self->priv->creating_account);
1721 case PROP_OTHER_ACCOUNTS_EXIST:
1722 g_value_set_boolean (value, self->priv->other_accounts_exist);
1725 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1730 set_apply_button (TpawAccountWidget *self)
1734 /* We can't use the stock button as its accelerator ('A') clashes with the
1736 gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE);
1738 gtk_button_set_label (GTK_BUTTON (self->priv->apply_button), _("A_pply"));
1739 gtk_button_set_use_underline (GTK_BUTTON (self->priv->apply_button), TRUE);
1741 image = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
1742 gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image);
1746 presence_changed_cb (TpAccountManager *manager,
1747 TpConnectionPresenceType state,
1748 const gchar *status,
1749 const gchar *message,
1750 TpawAccountWidget *self)
1752 if (self->priv->destroyed)
1755 if (self->priv->apply_button == NULL)
1756 /* This button doesn't exist in 'simple' mode */
1759 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1760 self->priv->creating_account)
1762 /* We are online and creating a new account, display a Login button */
1765 gtk_button_set_use_stock (GTK_BUTTON (self->priv->apply_button), FALSE);
1766 gtk_button_set_label (GTK_BUTTON (self->priv->apply_button),
1769 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1770 GTK_ICON_SIZE_BUTTON);
1771 gtk_button_set_image (GTK_BUTTON (self->priv->apply_button), image);
1775 /* We are offline or modifying an existing account, display
1777 set_apply_button (self);
1782 account_manager_ready_cb (GObject *source_object,
1783 GAsyncResult *result,
1786 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (user_data);
1787 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1788 GError *error = NULL;
1789 TpConnectionPresenceType state;
1791 if (!tp_proxy_prepare_finish (account_manager, result, &error))
1793 DEBUG ("Failed to prepare account manager: %s", error->message);
1794 g_error_free (error);
1798 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1801 /* simulate a presence change so the apply button will be changed
1803 presence_changed_cb (account_manager, state, NULL, NULL, self);
1806 g_object_unref (self);
1809 #define WIDGET(cm, proto) \
1810 { #cm, #proto, TPAW_ACCOUNT_WIDGETS_RESOURCES_PREFIX "/tpaw-account-widget-"#proto".ui", \
1811 account_widget_build_##proto }
1814 add_register_buttons (TpawAccountWidget *self,
1817 TpProtocol *protocol;
1818 GtkWidget *radiobutton_register;
1820 if (!self->priv->creating_account)
1823 protocol = tpaw_account_settings_get_tp_protocol (self->priv->settings);
1824 if (protocol == NULL)
1827 if (!tp_protocol_can_register (protocol))
1830 if (account_widget_get_service (self) != NO_SERVICE)
1833 if (self->priv->simple)
1836 self->priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1837 _("This account already exists on the server"));
1838 radiobutton_register = gtk_radio_button_new_with_label (
1839 gtk_radio_button_get_group (
1840 GTK_RADIO_BUTTON (self->priv->radiobutton_reuse)),
1841 _("Create a new account on the server"));
1843 gtk_box_pack_start (GTK_BOX (self), self->priv->radiobutton_reuse, FALSE,
1845 gtk_box_pack_start (GTK_BOX (self), radiobutton_register, FALSE, FALSE, 0);
1846 gtk_box_reorder_child (GTK_BOX (self), self->priv->radiobutton_reuse, 0);
1847 gtk_box_reorder_child (GTK_BOX (self), radiobutton_register, 1);
1848 gtk_widget_show (self->priv->radiobutton_reuse);
1849 gtk_widget_show (radiobutton_register);
1853 remember_password_toggled_cb (GtkToggleButton *button,
1854 TpawAccountWidget *self)
1856 tpaw_account_settings_set_remember_password (self->priv->settings,
1857 gtk_toggle_button_get_active (button));
1859 if (!self->priv->automatic_change)
1860 tpaw_account_widget_changed (self);
1864 account_settings_password_retrieved_cb (GObject *object,
1867 TpawAccountWidget *self = user_data;
1870 password = tpaw_account_settings_dup_string (
1871 self->priv->settings, "password");
1873 /* We have to do this so that when we call gtk_entry_set_text,
1874 * the ::changed callback doesn't think the user made the
1875 * change. This is also used in remember_password_toggled_cb. */
1876 self->priv->automatic_change = TRUE;
1878 if (password != NULL)
1880 gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget),
1884 gtk_toggle_button_set_active (
1885 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget),
1886 !TPAW_STR_EMPTY (password));
1888 self->priv->automatic_change = FALSE;
1894 do_constructed (GObject *obj)
1896 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (obj);
1898 const gchar *display_name, *default_display_name;
1901 const gchar *cm_name;
1902 const gchar *protocol;
1904 GtkWidget * (*func)(TpawAccountWidget *self, const gchar *filename);
1906 { "salut", "local-xmpp", TPAW_ACCOUNT_WIDGETS_RESOURCES_PREFIX "/tpaw-account-widget-local-xmpp.ui",
1907 account_widget_build_salut },
1908 WIDGET (gabble, jabber),
1912 WIDGET (haze, yahoo),
1913 WIDGET (haze, groupwise),
1915 WIDGET (sofiasip, sip),
1917 const gchar *protocol, *cm_name;
1920 account = tpaw_account_settings_get_account (self->priv->settings);
1922 cm_name = tpaw_account_settings_get_cm (self->priv->settings);
1923 protocol = tpaw_account_settings_get_protocol (self->priv->settings);
1925 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1927 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1928 !tp_strdiff (widgets[i].protocol, protocol))
1930 box = widgets[i].func (self, widgets[i].file);
1935 if (i == G_N_ELEMENTS (widgets))
1937 gchar *filename = TPAW_ACCOUNT_WIDGETS_RESOURCES_PREFIX "/tpaw-account-widget-generic.ui";
1938 box = account_widget_build_generic (self, filename);
1941 gtk_container_add (GTK_CONTAINER (self), box);
1943 /* handle default focus */
1944 if (self->ui_details->default_focus != NULL)
1946 GObject *default_focus_entry;
1948 default_focus_entry = gtk_builder_get_object
1949 (self->ui_details->gui, self->ui_details->default_focus);
1950 g_signal_connect (default_focus_entry, "realize",
1951 G_CALLBACK (gtk_widget_grab_focus),
1955 /* remember password */
1956 if (self->priv->param_password_widget != NULL
1957 && self->priv->remember_password_widget != NULL
1958 && tpaw_account_settings_supports_sasl (self->priv->settings))
1960 if (self->priv->simple)
1962 gtk_toggle_button_set_active (
1963 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), TRUE);
1969 password = tpaw_account_settings_dup_string (self->priv->settings,
1972 /* FIXME: we should enable this checkbox only if the password is
1973 * stored for good in the password storage, not only for the session
1975 gtk_toggle_button_set_active (
1976 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget),
1977 !TPAW_STR_EMPTY (password));
1979 /* The password might not have been retrieved from the
1980 * keyring yet. We should update the remember password
1981 * toggle button and the password entry when/if it is. */
1982 tp_g_signal_connect_object (self->priv->settings,
1983 "password-retrieved",
1984 G_CALLBACK (account_settings_password_retrieved_cb), self, 0);
1989 g_signal_connect (self->priv->remember_password_widget, "toggled",
1990 G_CALLBACK (remember_password_toggled_cb), self);
1992 self->priv->automatic_change = TRUE;
1993 remember_password_toggled_cb (
1994 GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), self);
1995 self->priv->automatic_change = FALSE;
1997 else if (self->priv->remember_password_widget != NULL
1998 && !tpaw_account_settings_supports_sasl (self->priv->settings))
2000 gtk_widget_set_visible (self->priv->remember_password_widget, FALSE);
2001 tpaw_account_settings_set_remember_password (self->priv->settings,
2005 /* dup and init the account-manager */
2006 self->priv->account_manager = tp_account_manager_dup ();
2008 g_object_ref (self);
2009 tp_proxy_prepare_async (self->priv->account_manager, NULL,
2010 account_manager_ready_cb, self);
2012 /* handle apply and cancel button */
2013 self->priv->hbox_buttons = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
2014 gtk_button_box_set_layout (GTK_BUTTON_BOX (self->priv->hbox_buttons),
2016 /* Hard code the default spacing as we cannot easily get this property
2017 * as the widget is not in a GtkDialog yet (and it could end up packed
2018 * in a non-GtkDialog window anyway */
2019 gtk_box_set_spacing (GTK_BOX (self->priv->hbox_buttons), 6);
2021 self->priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
2023 self->priv->apply_button = gtk_button_new ();
2024 set_apply_button (self);
2026 /* We'll change this button to a "Log in" one if we are creating a new
2027 * account and are connected. */
2028 tp_g_signal_connect_object (self->priv->account_manager,
2029 "most-available-presence-changed",
2030 G_CALLBACK (presence_changed_cb), obj, 0);
2032 gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons),
2033 self->priv->apply_button, TRUE, TRUE, 3);
2034 gtk_box_pack_end (GTK_BOX (self->priv->hbox_buttons),
2035 self->priv->cancel_button, TRUE, TRUE, 3);
2037 gtk_box_pack_end (GTK_BOX (self), self->priv->hbox_buttons, FALSE,
2040 g_signal_connect (self->priv->cancel_button, "clicked",
2041 G_CALLBACK (account_widget_cancel_clicked_cb),
2043 g_signal_connect (self->priv->apply_button, "clicked",
2044 G_CALLBACK (account_widget_apply_clicked_cb),
2046 gtk_widget_show_all (self->priv->hbox_buttons);
2048 if (self->priv->creating_account)
2049 /* When creating an account, the user might have nothing to enter.
2050 * That means that no control interaction might occur,
2051 * so we update the control button sensitivity manually.
2053 account_widget_handle_control_buttons_sensitivity (self);
2055 account_widget_set_control_buttons_sensitivity (self, FALSE);
2057 add_register_buttons (self, account);
2059 g_clear_object (&self->ui_details->gui);
2061 display_name = tpaw_account_settings_get_display_name (
2062 self->priv->settings);
2063 default_display_name = tpaw_account_widget_get_default_display_name (self);
2065 if (tp_strdiff (display_name, default_display_name) &&
2066 !self->priv->creating_account)
2068 /* The display name of the account is not the one that we'd assign by
2069 * default; assume that the user changed it manually */
2070 g_object_set (self->priv->settings, "display-name-overridden", TRUE,
2076 do_dispose (GObject *obj)
2078 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (obj);
2080 g_clear_object (&self->priv->settings);
2081 g_clear_object (&self->priv->account_manager);
2083 if (G_OBJECT_CLASS (tpaw_account_widget_parent_class)->dispose != NULL)
2084 G_OBJECT_CLASS (tpaw_account_widget_parent_class)->dispose (obj);
2088 do_finalize (GObject *obj)
2090 TpawAccountWidget *self = TPAW_ACCOUNT_WIDGET (obj);
2092 g_free (self->ui_details->default_focus);
2093 g_slice_free (TpawAccountWidgetUIDetails, self->ui_details);
2095 g_free (self->priv->jid_suffix);
2097 if (G_OBJECT_CLASS (tpaw_account_widget_parent_class)->finalize != NULL)
2098 G_OBJECT_CLASS (tpaw_account_widget_parent_class)->finalize (obj);
2102 tpaw_account_widget_class_init (TpawAccountWidgetClass *klass)
2104 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2105 GParamSpec *param_spec;
2107 oclass->get_property = do_get_property;
2108 oclass->set_property = do_set_property;
2109 oclass->constructed = do_constructed;
2110 oclass->dispose = do_dispose;
2111 oclass->finalize = do_finalize;
2113 param_spec = g_param_spec_string ("protocol",
2114 "protocol", "The protocol of the account",
2116 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
2117 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
2119 param_spec = g_param_spec_object ("settings",
2120 "settings", "The settings of the account",
2121 TPAW_TYPE_ACCOUNT_SETTINGS,
2122 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2123 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
2125 param_spec = g_param_spec_boolean ("simple",
2126 "simple", "Whether the account widget is a simple or an advanced one",
2128 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2129 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
2131 param_spec = g_param_spec_boolean ("creating-account",
2133 "TRUE if we're creating an account, FALSE if we're modifying it",
2135 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2136 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
2138 param_spec = g_param_spec_boolean ("other-accounts-exist",
2139 "other-accounts-exist",
2140 "TRUE if there are any other accounts (even if this isn't yet saved)",
2142 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2143 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
2146 signals[HANDLE_APPLY] =
2147 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
2148 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2149 g_cclosure_marshal_generic,
2153 /* This signal is emitted when an account has been created and enabled. */
2154 signals[ACCOUNT_CREATED] =
2155 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
2156 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2157 g_cclosure_marshal_generic,
2161 signals[CANCELLED] =
2162 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
2163 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2164 g_cclosure_marshal_generic,
2169 g_signal_new ("close", G_TYPE_FROM_CLASS (klass),
2170 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2171 g_cclosure_marshal_VOID__INT,
2175 g_type_class_add_private (klass, sizeof (TpawAccountWidgetPriv));
2179 tpaw_account_widget_init (TpawAccountWidget *self)
2181 self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), TPAW_TYPE_ACCOUNT_WIDGET,
2182 TpawAccountWidgetPriv);
2184 self->ui_details = g_slice_new0 (TpawAccountWidgetUIDetails);
2187 /* public methods */
2190 tpaw_account_widget_discard_pending_changes (TpawAccountWidget *self)
2192 tpaw_account_settings_discard_changes (self->priv->settings);
2193 self->priv->contains_pending_changes = FALSE;
2197 tpaw_account_widget_contains_pending_changes (TpawAccountWidget *self)
2199 return self->priv->contains_pending_changes;
2203 tpaw_account_widget_handle_params (TpawAccountWidget *self,
2204 const gchar *first_widget,
2209 va_start (args, first_widget);
2210 account_widget_handle_params_valist (self, first_widget, args);
2215 tpaw_account_widget_new_for_protocol (TpawAccountSettings *settings,
2218 g_return_val_if_fail (TPAW_IS_ACCOUNT_SETTINGS (settings), NULL);
2220 return g_object_new (TPAW_TYPE_ACCOUNT_WIDGET,
2221 "orientation", GTK_ORIENTATION_VERTICAL,
2222 "settings", settings,
2225 tpaw_account_settings_get_account (settings) == NULL,
2230 tpaw_account_widget_get_default_display_name (TpawAccountWidget *self)
2233 const gchar *protocol, *p;
2234 gchar *default_display_name;
2237 login_id = tpaw_account_settings_dup_string (self->priv->settings,
2239 protocol = tpaw_account_settings_get_protocol (self->priv->settings);
2240 service = account_widget_get_service (self);
2242 if (login_id != NULL)
2244 /* TODO: this should be done in tpaw-account-widget-irc */
2245 if (!tp_strdiff (protocol, "irc"))
2247 TpawIrcNetwork *network;
2249 network = tpaw_irc_network_chooser_get_network (
2250 self->priv->irc_network_chooser);
2251 g_assert (network != NULL);
2253 /* To translators: The first parameter is the login id and the
2254 * second one is the network. The resulting string will be something
2255 * like: "MyUserName on freenode".
2256 * You should reverse the order of these arguments if the
2257 * server should come before the login id in your locale.*/
2258 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2259 login_id, tpaw_irc_network_get_name (network));
2261 else if (service == FACEBOOK_SERVICE && self->priv->jid_suffix != NULL)
2265 tmp = remove_jid_suffix (self, login_id);
2266 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2271 default_display_name = g_strdup (login_id);
2274 return default_display_name;
2277 if ((p = tpaw_protocol_name_to_display_name (protocol)) != NULL)
2280 if (protocol != NULL)
2282 /* To translators: The parameter is the protocol name. The resulting
2283 * string will be something like: "Jabber Account" */
2284 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2288 default_display_name = g_strdup (_("New account"));
2293 return default_display_name;
2296 /* Used by subclass to indicate that widget contains pending changes */
2298 tpaw_account_widget_changed (TpawAccountWidget *self)
2300 account_widget_handle_control_buttons_sensitivity (self);
2301 self->priv->contains_pending_changes = TRUE;
2305 tpaw_account_widget_set_account_param (TpawAccountWidget *self,
2306 const gchar *account)
2308 if (self->priv->param_account_widget == NULL)
2311 gtk_entry_set_text (GTK_ENTRY (self->priv->param_account_widget), account);
2315 tpaw_account_widget_set_password_param (TpawAccountWidget *self,
2316 const gchar *account)
2318 if (self->priv->param_password_widget == NULL)
2321 gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), account);
2324 TpawAccountSettings *
2325 tpaw_account_widget_get_settings (TpawAccountWidget *self)
2327 return self->priv->settings;
2331 tpaw_account_widget_hide_buttons (TpawAccountWidget *self)
2333 gtk_widget_hide (self->priv->hbox_buttons);