2 * Copyright (C) 2006-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
21 * Martyn Russell <martyn@imendio.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
31 #include <glib/gi18n-lib.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-account.h>
36 #include <telepathy-glib/connection-manager.h>
37 #include <telepathy-glib/util.h>
38 #include <dbus/dbus-protocol.h>
40 #include "empathy-account-widget.h"
41 #include "empathy-account-widget-private.h"
42 #include "empathy-account-widget-sip.h"
43 #include "empathy-account-widget-irc.h"
44 #include "empathy-ui-utils.h"
46 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
47 #include <libempathy/empathy-debug.h>
49 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT)
53 EmpathyAccountSettings *settings;
55 GtkWidget *table_common_settings;
56 GtkWidget *apply_button;
57 GtkWidget *cancel_button;
58 GtkWidget *entry_password;
59 GtkWidget *button_forget;
60 GtkWidget *spinbutton_port;
61 GtkWidget *enabled_checkbox;
65 /* An EmpathyAccountWidget can be used to either create an account or
66 * modify it. When we are creating an account, this member is set to TRUE */
67 gboolean creating_account;
69 /* After having applied changes to a user account, we automatically
70 * disconnect him. Once he's disconnected, he will be reconnected,
71 * depending on the value of this member which should be set to the checked
72 * state of the "Enabled" checkbox. This is done so the new information
73 * entered by the user is validated on the server. */
74 gboolean re_enable_accound;
77 } EmpathyAccountWidgetPriv;
93 static guint signals[LAST_SIGNAL] = { 0 };
95 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
96 #define CHANGED_TIMEOUT 300
99 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
102 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
106 gtk_widget_set_sensitive (priv->apply_button, sensitive);
107 gtk_widget_set_sensitive (priv->cancel_button, sensitive);
112 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
114 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
117 is_valid = empathy_account_settings_is_valid (priv->settings);
121 gtk_widget_set_sensitive (priv->apply_button, is_valid);
122 gtk_widget_set_sensitive (priv->cancel_button, is_valid);
125 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
129 account_widget_entry_changed_common (EmpathyAccountWidget *self,
130 GtkEntry *entry, gboolean focus)
133 const gchar *param_name;
134 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
136 str = gtk_entry_get_text (entry);
137 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
139 if (EMP_STR_EMPTY (str))
141 const gchar *value = NULL;
143 empathy_account_settings_unset (priv->settings, param_name);
147 value = empathy_account_settings_get_string (priv->settings,
149 DEBUG ("Unset %s and restore to %s", param_name, value);
150 gtk_entry_set_text (entry, value ? value : "");
155 DEBUG ("Setting %s to %s", param_name,
156 tp_strdiff (param_name, "password") ? str : "***");
157 empathy_account_settings_set_string (priv->settings, param_name, str);
162 account_widget_entry_focus_cb (GtkWidget *widget,
163 GdkEventFocus *event,
164 EmpathyAccountWidget *self)
166 account_widget_entry_changed_common (self, GTK_ENTRY (widget), TRUE);
172 account_widget_entry_changed_cb (GtkEditable *entry,
173 EmpathyAccountWidget *self)
175 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
176 account_widget_handle_control_buttons_sensitivity (self);
180 account_widget_int_changed_cb (GtkWidget *widget,
181 EmpathyAccountWidget *self)
183 const gchar *param_name;
185 const gchar *signature;
186 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
188 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
189 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
191 signature = empathy_account_settings_get_dbus_signature (priv->settings,
193 g_return_if_fail (signature != NULL);
195 DEBUG ("Setting %s to %d", param_name, value);
197 switch ((int)*signature)
199 case DBUS_TYPE_INT16:
200 case DBUS_TYPE_INT32:
201 empathy_account_settings_set_int32 (priv->settings, param_name, value);
203 case DBUS_TYPE_INT64:
204 empathy_account_settings_set_int64 (priv->settings, param_name, value);
206 case DBUS_TYPE_UINT16:
207 case DBUS_TYPE_UINT32:
208 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
210 case DBUS_TYPE_UINT64:
211 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
214 g_return_if_reached ();
217 account_widget_handle_control_buttons_sensitivity (self);
221 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
222 EmpathyAccountWidget *self)
225 gboolean default_value;
226 const gchar *param_name;
227 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
229 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
230 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
232 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
233 * always unset the param and set the value if different from the
235 empathy_account_settings_unset (priv->settings, param_name);
236 default_value = empathy_account_settings_get_boolean (priv->settings,
239 if (default_value == value)
241 DEBUG ("Unset %s and restore to %d", param_name, default_value);
245 DEBUG ("Setting %s to %d", param_name, value);
246 empathy_account_settings_set_boolean (priv->settings, param_name, value);
249 account_widget_handle_control_buttons_sensitivity (self);
253 account_widget_forget_clicked_cb (GtkWidget *button,
254 EmpathyAccountWidget *self)
256 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
257 const gchar *param_name;
259 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
262 DEBUG ("Unset %s", param_name);
263 empathy_account_settings_unset (priv->settings, param_name);
264 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
266 account_widget_handle_control_buttons_sensitivity (self);
270 account_widget_password_changed_cb (GtkWidget *entry,
271 EmpathyAccountWidget *self)
273 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
276 str = gtk_entry_get_text (GTK_ENTRY (entry));
277 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
281 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
282 EmpathyAccountWidget *self)
284 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
288 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
289 port = empathy_account_settings_get_uint32 (priv->settings, "port");
293 if (port == 5222 || port == 0)
298 if (port == 5223 || port == 0)
302 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
306 account_widget_setup_widget (EmpathyAccountWidget *self,
308 const gchar *param_name)
310 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
312 g_object_set_data_full (G_OBJECT (widget), "param_name",
313 g_strdup (param_name), g_free);
315 if (GTK_IS_SPIN_BUTTON (widget))
318 const gchar *signature;
320 signature = empathy_account_settings_get_dbus_signature (priv->settings,
322 g_return_if_fail (signature != NULL);
324 switch ((int)*signature)
326 case DBUS_TYPE_INT16:
327 case DBUS_TYPE_INT32:
328 value = empathy_account_settings_get_int32 (priv->settings,
331 case DBUS_TYPE_INT64:
332 value = empathy_account_settings_get_int64 (priv->settings,
335 case DBUS_TYPE_UINT16:
336 case DBUS_TYPE_UINT32:
337 value = empathy_account_settings_get_uint32 (priv->settings,
340 case DBUS_TYPE_UINT64:
341 value = empathy_account_settings_get_uint64 (priv->settings,
345 g_return_if_reached ();
348 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
350 g_signal_connect (widget, "value-changed",
351 G_CALLBACK (account_widget_int_changed_cb),
354 else if (GTK_IS_ENTRY (widget))
356 const gchar *str = NULL;
358 str = empathy_account_settings_get_string (priv->settings, param_name);
359 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
361 if (strstr (param_name, "password"))
363 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
366 g_signal_connect (widget, "focus-out-event",
367 G_CALLBACK (account_widget_entry_focus_cb),
369 g_signal_connect (widget, "changed",
370 G_CALLBACK (account_widget_entry_changed_cb), self);
372 else if (GTK_IS_TOGGLE_BUTTON (widget))
374 gboolean value = FALSE;
376 value = empathy_account_settings_get_boolean (priv->settings,
378 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
380 g_signal_connect (widget, "toggled",
381 G_CALLBACK (account_widget_checkbutton_toggled_cb),
386 DEBUG ("Unknown type of widget for param %s", param_name);
391 account_widget_generic_format_param_name (const gchar *param_name)
396 str = g_strdup (param_name);
398 if (str && g_ascii_isalpha (str[0]))
399 str[0] = g_ascii_toupper (str[0]);
401 while ((p = strchr (str, '-')) != NULL)
403 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
406 p[1] = g_ascii_toupper (p[1]);
416 accounts_widget_generic_setup (EmpathyAccountWidget *self,
417 GtkWidget *table_common_settings,
418 GtkWidget *table_advanced_settings)
420 TpConnectionManagerParam *params, *param;
421 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
423 params = empathy_account_settings_get_tp_params (priv->settings);
425 for (param = params; param != NULL && param->name != NULL; param++)
427 GtkWidget *table_settings;
429 GtkWidget *widget = NULL;
430 gchar *param_name_formatted;
432 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
433 table_settings = table_common_settings;
434 else if (priv->simple)
437 table_settings = table_advanced_settings;
439 param_name_formatted = account_widget_generic_format_param_name
441 g_object_get (table_settings, "n-rows", &n_rows, NULL);
442 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
444 if (param->dbus_signature[0] == 's')
448 str = g_strdup_printf (_("%s:"), param_name_formatted);
449 widget = gtk_label_new (str);
450 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
453 gtk_table_attach (GTK_TABLE (table_settings),
459 gtk_widget_show (widget);
461 widget = gtk_entry_new ();
462 if (strcmp (param->name, "account") == 0)
464 g_signal_connect (widget, "realize",
465 G_CALLBACK (gtk_widget_grab_focus),
468 gtk_table_attach (GTK_TABLE (table_settings),
472 GTK_FILL | GTK_EXPAND, 0,
474 gtk_widget_show (widget);
476 /* int types: ynqiuxt. double type is 'd' */
477 else if (param->dbus_signature[0] == 'y' ||
478 param->dbus_signature[0] == 'n' ||
479 param->dbus_signature[0] == 'q' ||
480 param->dbus_signature[0] == 'i' ||
481 param->dbus_signature[0] == 'u' ||
482 param->dbus_signature[0] == 'x' ||
483 param->dbus_signature[0] == 't' ||
484 param->dbus_signature[0] == 'd')
491 switch (param->dbus_signature[0])
493 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
494 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
495 case 'q': minint = 0; maxint = G_MAXUINT16; break;
496 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
497 case 'u': minint = 0; maxint = G_MAXUINT32; break;
498 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
499 case 't': minint = 0; maxint = G_MAXUINT64; break;
500 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
504 str = g_strdup_printf (_("%s:"), param_name_formatted);
505 widget = gtk_label_new (str);
506 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
509 gtk_table_attach (GTK_TABLE (table_settings),
515 gtk_widget_show (widget);
517 widget = gtk_spin_button_new_with_range (minint, maxint, step);
518 gtk_table_attach (GTK_TABLE (table_settings),
522 GTK_FILL | GTK_EXPAND, 0,
524 gtk_widget_show (widget);
526 else if (param->dbus_signature[0] == 'b')
528 widget = gtk_check_button_new_with_label (param_name_formatted);
529 gtk_table_attach (GTK_TABLE (table_settings),
533 GTK_FILL | GTK_EXPAND, 0,
535 gtk_widget_show (widget);
539 DEBUG ("Unknown signature for param %s: %s",
540 param_name_formatted, param->dbus_signature);
544 account_widget_setup_widget (self, widget, param->name);
546 g_free (param_name_formatted);
551 account_widget_handle_params_valist (EmpathyAccountWidget *self,
552 const gchar *first_widget,
558 for (name = first_widget; name; name = va_arg (args, const gchar *))
560 const gchar *param_name;
562 param_name = va_arg (args, const gchar *);
563 object = gtk_builder_get_object (self->ui_details->gui, name);
567 g_warning ("Builder is missing object '%s'.", name);
571 account_widget_setup_widget (self, GTK_WIDGET (object), param_name);
576 account_widget_cancel_clicked_cb (GtkWidget *button,
577 EmpathyAccountWidget *self)
579 g_signal_emit (self, signals[CANCELLED], 0);
583 account_widget_account_enabled_cb (GObject *source_object,
587 GError *error = NULL;
588 EmpathyAccount *account = EMPATHY_ACCOUNT (source_object);
589 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
591 empathy_account_set_enabled_finish (account, res, &error);
595 DEBUG ("Could not automatically enable new account: %s", error->message);
596 g_error_free (error);
600 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
605 account_widget_applied_cb (GObject *source_object,
609 GError *error = NULL;
610 EmpathyAccount *account;
611 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
612 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
613 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
615 empathy_account_settings_apply_finish (settings, res, &error);
619 DEBUG ("Could not apply changes to account: %s", error->message);
620 g_error_free (error);
624 account = empathy_account_settings_get_account (priv->settings);
626 if (priv->creating_account)
628 /* By default, when an account is created, we enable it. */
629 empathy_account_set_enabled_async (account, TRUE,
630 account_widget_account_enabled_cb, widget);
632 else if (account != NULL && priv->enabled_checkbox != NULL)
634 gboolean enabled_checked;
636 enabled_checked = gtk_toggle_button_get_active (
637 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
639 if (empathy_account_is_enabled (account))
641 /* We want to disable the account (and possibly re-enable it) to make
642 * sure that the new settings are effective */
643 priv->re_enable_accound = enabled_checked;
644 empathy_account_set_enabled_async (account, FALSE, NULL, NULL);
648 /* The account is already disable so we just enable it according
649 * to the value of the "Enabled" checkbox */
650 empathy_account_set_enabled_async (account, enabled_checked,
655 account_widget_set_control_buttons_sensitivity (widget, FALSE);
659 account_widget_apply_clicked_cb (GtkWidget *button,
660 EmpathyAccountWidget *self)
662 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
664 empathy_account_settings_apply_async (priv->settings,
665 account_widget_applied_cb, self);
669 account_widget_setup_generic (EmpathyAccountWidget *self)
671 GtkWidget *table_common_settings;
672 GtkWidget *table_advanced_settings;
674 table_common_settings = GTK_WIDGET (gtk_builder_get_object
675 (self->ui_details->gui, "table_common_settings"));
676 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
677 (self->ui_details->gui, "table_advanced_settings"));
679 accounts_widget_generic_setup (self, table_common_settings,
680 table_advanced_settings);
682 g_object_unref (self->ui_details->gui);
686 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
690 EmpathyAccountWidget *self = user_data;
691 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
693 if (empathy_account_settings_is_ready (priv->settings))
694 account_widget_setup_generic (self);
698 account_widget_build_generic (EmpathyAccountWidget *self,
699 const char *filename)
701 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
702 GtkWidget *expander_advanced;
704 self->ui_details->gui = empathy_builder_get_file (filename,
705 "table_common_settings", &priv->table_common_settings,
706 "vbox_generic_settings", &self->ui_details->widget,
707 "expander_advanced_settings", &expander_advanced,
711 gtk_widget_hide (expander_advanced);
713 g_object_ref (self->ui_details->gui);
715 if (empathy_account_settings_is_ready (priv->settings))
716 account_widget_setup_generic (self);
718 g_signal_connect (priv->settings, "notify::ready",
719 G_CALLBACK (account_widget_settings_ready_cb), self);
723 account_widget_build_salut (EmpathyAccountWidget *self,
724 const char *filename)
726 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
728 self->ui_details->gui = empathy_builder_get_file (filename,
729 "table_common_settings", &priv->table_common_settings,
730 "vbox_salut_settings", &self->ui_details->widget,
733 empathy_account_widget_handle_params (self,
734 "entry_published", "published-name",
735 "entry_nickname", "nickname",
736 "entry_first_name", "first-name",
737 "entry_last_name", "last-name",
738 "entry_email", "email",
742 self->ui_details->default_focus = g_strdup ("entry_nickname");
746 account_widget_build_msn (EmpathyAccountWidget *self,
747 const char *filename)
749 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
753 self->ui_details->gui = empathy_builder_get_file (filename,
754 "vbox_msn_simple", &self->ui_details->widget,
757 empathy_account_widget_handle_params (self,
758 "entry_id_simple", "account",
759 "entry_password_simple", "password",
762 self->ui_details->default_focus = g_strdup ("entry_id_simple");
766 self->ui_details->gui = empathy_builder_get_file (filename,
767 "table_common_msn_settings", &priv->table_common_settings,
768 "vbox_msn_settings", &self->ui_details->widget,
771 empathy_account_widget_handle_params (self,
772 "entry_id", "account",
773 "entry_password", "password",
774 "entry_server", "server",
775 "spinbutton_port", "port",
778 self->ui_details->default_focus = g_strdup ("entry_id");
779 self->ui_details->add_forget = TRUE;
784 account_widget_build_jabber (EmpathyAccountWidget *self,
785 const char *filename)
787 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
788 GtkWidget *spinbutton_port;
789 GtkWidget *checkbutton_ssl;
790 GtkWidget *label_id, *label_password;
791 GtkWidget *label_id_create, *label_password_create;
795 self->ui_details->gui = empathy_builder_get_file (filename,
796 "vbox_jabber_simple", &self->ui_details->widget,
797 "label_id_simple", &label_id,
798 "label_id_create", &label_id_create,
799 "label_password_simple", &label_password,
800 "label_password_create", &label_password_create,
803 if (empathy_account_settings_get_boolean (priv->settings, "register"))
805 gtk_widget_hide (label_id);
806 gtk_widget_hide (label_password);
807 gtk_widget_show (label_id_create);
808 gtk_widget_show (label_password_create);
811 empathy_account_widget_handle_params (self,
812 "entry_id_simple", "account",
813 "entry_password_simple", "password",
816 self->ui_details->default_focus = g_strdup ("entry_id_simple");
820 self->ui_details->gui = empathy_builder_get_file (filename,
821 "table_common_settings", &priv->table_common_settings,
822 "vbox_jabber_settings", &self->ui_details->widget,
823 "spinbutton_port", &spinbutton_port,
824 "checkbutton_ssl", &checkbutton_ssl,
827 empathy_account_widget_handle_params (self,
828 "entry_id", "account",
829 "entry_password", "password",
830 "entry_resource", "resource",
831 "entry_server", "server",
832 "spinbutton_port", "port",
833 "spinbutton_priority", "priority",
834 "checkbutton_ssl", "old-ssl",
835 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
836 "checkbutton_encryption", "require-encryption",
839 self->ui_details->default_focus = g_strdup ("entry_id");
840 self->ui_details->add_forget = TRUE;
841 priv->spinbutton_port = spinbutton_port;
843 g_signal_connect (checkbutton_ssl, "toggled",
844 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
850 account_widget_build_icq (EmpathyAccountWidget *self,
851 const char *filename)
853 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
854 GtkWidget *spinbutton_port;
858 self->ui_details->gui = empathy_builder_get_file (filename,
859 "vbox_icq_simple", &self->ui_details->widget,
862 empathy_account_widget_handle_params (self,
863 "entry_uin_simple", "account",
864 "entry_password_simple", "password",
867 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
871 self->ui_details->gui = empathy_builder_get_file (filename,
872 "table_common_settings", &priv->table_common_settings,
873 "vbox_icq_settings", &self->ui_details->widget,
874 "spinbutton_port", &spinbutton_port,
877 empathy_account_widget_handle_params (self,
878 "entry_uin", "account",
879 "entry_password", "password",
880 "entry_server", "server",
881 "spinbutton_port", "port",
882 "entry_charset", "charset",
885 self->ui_details->default_focus = g_strdup ("entry_uin");
886 self->ui_details->add_forget = TRUE;
891 account_widget_build_aim (EmpathyAccountWidget *self,
892 const char *filename)
894 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
895 GtkWidget *spinbutton_port;
899 self->ui_details->gui = empathy_builder_get_file (filename,
900 "vbox_aim_simple", &self->ui_details->widget,
903 empathy_account_widget_handle_params (self,
904 "entry_screenname_simple", "account",
905 "entry_password_simple", "password",
908 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
912 self->ui_details->gui = empathy_builder_get_file (filename,
913 "table_common_settings", &priv->table_common_settings,
914 "vbox_aim_settings", &self->ui_details->widget,
915 "spinbutton_port", &spinbutton_port,
918 empathy_account_widget_handle_params (self,
919 "entry_screenname", "account",
920 "entry_password", "password",
921 "entry_server", "server",
922 "spinbutton_port", "port",
925 self->ui_details->default_focus = g_strdup ("entry_screenname");
926 self->ui_details->add_forget = TRUE;
931 account_widget_build_yahoo (EmpathyAccountWidget *self,
932 const char *filename)
934 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
938 self->ui_details->gui = empathy_builder_get_file (filename,
939 "vbox_yahoo_simple", &self->ui_details->widget,
942 empathy_account_widget_handle_params (self,
943 "entry_id_simple", "account",
944 "entry_password_simple", "password",
947 self->ui_details->default_focus = g_strdup ("entry_id_simple");
951 self->ui_details->gui = empathy_builder_get_file (filename,
952 "table_common_settings", &priv->table_common_settings,
953 "vbox_yahoo_settings", &self->ui_details->widget,
956 empathy_account_widget_handle_params (self,
957 "entry_id", "account",
958 "entry_password", "password",
959 "entry_server", "server",
960 "entry_locale", "room-list-locale",
961 "entry_charset", "charset",
962 "spinbutton_port", "port",
963 "checkbutton_yahoojp", "yahoojp",
964 "checkbutton_ignore_invites", "ignore-invites",
967 self->ui_details->default_focus = g_strdup ("entry_id");
968 self->ui_details->add_forget = TRUE;
973 account_widget_build_groupwise (EmpathyAccountWidget *self,
974 const char *filename)
976 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
980 self->ui_details->gui = empathy_builder_get_file (filename,
981 "vbox_groupwise_simple", &self->ui_details->widget,
984 empathy_account_widget_handle_params (self,
985 "entry_id_simple", "account",
986 "entry_password_simple", "password",
989 self->ui_details->default_focus = g_strdup ("entry_id_simple");
993 self->ui_details->gui = empathy_builder_get_file (filename,
994 "table_common_groupwise_settings", &priv->table_common_settings,
995 "vbox_groupwise_settings", &self->ui_details->widget,
998 empathy_account_widget_handle_params (self,
999 "entry_id", "account",
1000 "entry_password", "password",
1001 "entry_server", "server",
1002 "spinbutton_port", "port",
1005 self->ui_details->default_focus = g_strdup ("entry_id");
1006 self->ui_details->add_forget = TRUE;
1011 account_widget_destroy_cb (GtkWidget *widget,
1012 EmpathyAccountWidget *self)
1014 g_object_unref (self);
1018 empathy_account_widget_enabled_cb (EmpathyAccount *account,
1022 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1023 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1024 gboolean enabled = empathy_account_is_enabled (account);
1026 if (!enabled && priv->re_enable_accound)
1028 /* The account has been disabled because we were applying changes.
1029 * However, the user wants the account to be enabled so let's re-enable
1031 empathy_account_set_enabled_async (account, TRUE, NULL, NULL);
1033 else if (priv->enabled_checkbox != NULL)
1035 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1041 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1044 account_widget_handle_control_buttons_sensitivity (
1045 EMPATHY_ACCOUNT_WIDGET (user_data));
1049 do_set_property (GObject *object,
1051 const GValue *value,
1054 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1059 priv->protocol = g_value_dup_string (value);
1062 priv->settings = g_value_dup_object (value);
1065 priv->simple = g_value_get_boolean (value);
1067 case PROP_CREATING_ACCOUNT:
1068 priv->creating_account = g_value_get_boolean (value);
1071 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1076 do_get_property (GObject *object,
1081 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1086 g_value_set_string (value, priv->protocol);
1089 g_value_set_object (value, priv->settings);
1092 g_value_set_boolean (value, priv->simple);
1094 case PROP_CREATING_ACCOUNT:
1095 g_value_set_boolean (value, priv->creating_account);
1098 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1103 do_constructed (GObject *obj)
1105 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1106 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1107 EmpathyAccount *account;
1108 char *uiname, *filename;
1110 uiname = g_strconcat ("empathy-account-widget-", priv->protocol,
1112 filename = empathy_file_lookup (uiname, "libempathy-gtk");
1114 if (!tp_strdiff (priv->protocol, "local-xmpp"))
1115 account_widget_build_salut (self, filename);
1116 else if (!tp_strdiff (priv->protocol, "msn"))
1117 account_widget_build_msn (self, filename);
1118 else if (!tp_strdiff (priv->protocol, "jabber"))
1119 account_widget_build_jabber (self, filename);
1120 else if (!tp_strdiff (priv->protocol, "icq"))
1121 account_widget_build_icq (self, filename);
1122 else if (!tp_strdiff (priv->protocol, "aim"))
1123 account_widget_build_aim (self, filename);
1124 else if (!tp_strdiff (priv->protocol, "yahoo"))
1125 account_widget_build_yahoo (self, filename);
1126 else if (!tp_strdiff (priv->protocol, "groupwise"))
1127 account_widget_build_groupwise (self, filename);
1128 else if (!tp_strdiff (priv->protocol, "irc"))
1129 empathy_account_widget_irc_build (self, filename,
1130 &priv->table_common_settings);
1131 else if (!tp_strdiff (priv->protocol, "sip"))
1132 empathy_account_widget_sip_build (self, filename,
1133 &priv->table_common_settings);
1134 else if (!tp_strdiff (priv->protocol, "generic"))
1135 account_widget_build_generic (self, filename);
1140 filename = empathy_file_lookup (
1141 "empathy-account-widget-generic.ui", "libempathy-gtk");
1142 account_widget_build_generic (self, filename);
1148 /* handle default focus */
1149 if (self->ui_details->default_focus != NULL)
1151 GObject *default_focus_entry;
1153 default_focus_entry = gtk_builder_get_object
1154 (self->ui_details->gui, self->ui_details->default_focus);
1155 g_signal_connect (default_focus_entry, "realize",
1156 G_CALLBACK (gtk_widget_grab_focus),
1160 /* handle forget button */
1161 if (self->ui_details->add_forget)
1163 const gchar *password = NULL;
1165 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1166 (self->ui_details->gui, "button_forget"));
1167 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1168 (self->ui_details->gui, "entry_password"));
1170 password = empathy_account_settings_get_string (priv->settings,
1172 gtk_widget_set_sensitive (priv->button_forget,
1173 !EMP_STR_EMPTY (password));
1175 g_signal_connect (priv->button_forget, "clicked",
1176 G_CALLBACK (account_widget_forget_clicked_cb),
1178 g_signal_connect (priv->entry_password, "changed",
1179 G_CALLBACK (account_widget_password_changed_cb),
1183 /* handle apply and cancel button */
1186 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1188 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1189 priv->apply_button = gtk_button_new_from_stock (
1190 priv->creating_account ? GTK_STOCK_CONNECT : GTK_STOCK_APPLY);
1192 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1194 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1197 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1200 g_signal_connect (priv->cancel_button, "clicked",
1201 G_CALLBACK (account_widget_cancel_clicked_cb),
1203 g_signal_connect (priv->apply_button, "clicked",
1204 G_CALLBACK (account_widget_apply_clicked_cb),
1206 gtk_widget_show_all (hbox);
1207 account_widget_set_control_buttons_sensitivity (self, FALSE);
1210 account = empathy_account_settings_get_account (priv->settings);
1212 if (account != NULL)
1214 g_signal_connect (account, "notify::enabled",
1215 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1218 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1219 if (!priv->creating_account && priv->table_common_settings != NULL)
1221 guint nb_rows, nb_columns;
1223 priv->enabled_checkbox =
1224 gtk_check_button_new_with_label (_("Enabled"));
1225 gtk_toggle_button_set_active (
1226 GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1227 empathy_account_is_enabled (account));
1229 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1230 "n-columns", &nb_columns, NULL);
1232 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1235 gtk_table_attach_defaults (GTK_TABLE (priv->table_common_settings),
1236 priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows);
1238 gtk_widget_show (priv->enabled_checkbox);
1240 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
1241 G_CALLBACK (account_widget_enabled_toggled_cb), self);
1244 /* hook up to widget destruction to unref ourselves */
1245 g_signal_connect (self->ui_details->widget, "destroy",
1246 G_CALLBACK (account_widget_destroy_cb), self);
1248 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1249 self->ui_details->widget);
1250 self->ui_details->gui = NULL;
1254 do_dispose (GObject *obj)
1256 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1257 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1259 if (priv->dispose_run)
1262 priv->dispose_run = TRUE;
1264 empathy_account_settings_is_ready (priv->settings);
1266 if (priv->settings != NULL)
1268 EmpathyAccount *account;
1269 account = empathy_account_settings_get_account (priv->settings);
1271 if (account != NULL)
1273 g_signal_handlers_disconnect_by_func (account,
1274 empathy_account_widget_enabled_cb, self);
1277 g_object_unref (priv->settings);
1278 priv->settings = NULL;
1281 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1282 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1286 do_finalize (GObject *obj)
1288 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1289 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1291 g_free (self->ui_details->default_focus);
1292 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1294 g_free (priv->protocol);
1296 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1297 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1301 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1303 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1304 GParamSpec *param_spec;
1306 oclass->get_property = do_get_property;
1307 oclass->set_property = do_set_property;
1308 oclass->constructed = do_constructed;
1309 oclass->dispose = do_dispose;
1310 oclass->finalize = do_finalize;
1312 param_spec = g_param_spec_string ("protocol",
1313 "protocol", "The protocol of the account",
1315 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1316 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1318 param_spec = g_param_spec_object ("settings",
1319 "settings", "The settings of the account",
1320 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1321 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1322 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1324 param_spec = g_param_spec_boolean ("simple",
1325 "simple", "Whether the account widget is a simple or an advanced one",
1327 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1328 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1330 param_spec = g_param_spec_boolean ("creating-account",
1332 "TRUE if we're creating an account, FALSE if we're modifying it",
1334 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1335 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1337 signals[HANDLE_APPLY] =
1338 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1339 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1340 g_cclosure_marshal_VOID__BOOLEAN,
1344 /* This signal is emitted when an account has been created and enabled. */
1345 signals[ACCOUNT_CREATED] =
1346 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1347 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1348 g_cclosure_marshal_VOID__VOID,
1352 signals[CANCELLED] =
1353 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1354 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1355 g_cclosure_marshal_VOID__VOID,
1359 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1363 empathy_account_widget_init (EmpathyAccountWidget *self)
1365 EmpathyAccountWidgetPriv *priv =
1366 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1367 EmpathyAccountWidgetPriv);
1370 priv->dispose_run = FALSE;
1372 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1375 /* public methods */
1378 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1379 const gchar *first_widget,
1384 va_start (args, first_widget);
1385 account_widget_handle_params_valist (self, first_widget, args);
1390 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1392 return widget->ui_details->widget;
1395 EmpathyAccountWidget *
1396 empathy_account_widget_new_for_protocol (const char *protocol,
1397 EmpathyAccountSettings *settings,
1400 EmpathyAccountWidget *self;
1402 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1403 g_return_val_if_fail (protocol != NULL, NULL);
1406 (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol,
1407 "settings", settings, "simple", simple,
1409 empathy_account_settings_get_account (settings) == NULL,