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;
70 } EmpathyAccountWidgetPriv;
86 static guint signals[LAST_SIGNAL] = { 0 };
88 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
89 #define CHANGED_TIMEOUT 300
92 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
95 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
99 gtk_widget_set_sensitive (priv->apply_button, sensitive);
100 gtk_widget_set_sensitive (priv->cancel_button, sensitive);
105 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
107 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
110 is_valid = empathy_account_settings_is_valid (priv->settings);
114 gtk_widget_set_sensitive (priv->apply_button, is_valid);
115 gtk_widget_set_sensitive (priv->cancel_button, is_valid);
118 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
122 account_widget_entry_changed_common (EmpathyAccountWidget *self,
123 GtkEntry *entry, gboolean focus)
126 const gchar *param_name;
127 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
129 str = gtk_entry_get_text (entry);
130 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
132 if (EMP_STR_EMPTY (str))
134 const gchar *value = NULL;
136 empathy_account_settings_unset (priv->settings, param_name);
140 value = empathy_account_settings_get_string (priv->settings,
142 DEBUG ("Unset %s and restore to %s", param_name, value);
143 gtk_entry_set_text (entry, value ? value : "");
148 DEBUG ("Setting %s to %s", param_name,
149 tp_strdiff (param_name, "password") ? str : "***");
150 empathy_account_settings_set_string (priv->settings, param_name, str);
155 account_widget_entry_focus_cb (GtkWidget *widget,
156 GdkEventFocus *event,
157 EmpathyAccountWidget *self)
159 account_widget_entry_changed_common (self, GTK_ENTRY (widget), TRUE);
165 account_widget_entry_changed_cb (GtkEditable *entry,
166 EmpathyAccountWidget *self)
168 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
169 account_widget_handle_control_buttons_sensitivity (self);
173 account_widget_int_changed_cb (GtkWidget *widget,
174 EmpathyAccountWidget *self)
176 const gchar *param_name;
178 const gchar *signature;
179 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
181 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
182 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
184 signature = empathy_account_settings_get_dbus_signature (priv->settings,
186 g_return_if_fail (signature != NULL);
188 DEBUG ("Setting %s to %d", param_name, value);
190 switch ((int)*signature)
192 case DBUS_TYPE_INT16:
193 case DBUS_TYPE_INT32:
194 empathy_account_settings_set_int32 (priv->settings, param_name, value);
196 case DBUS_TYPE_INT64:
197 empathy_account_settings_set_int64 (priv->settings, param_name, value);
199 case DBUS_TYPE_UINT16:
200 case DBUS_TYPE_UINT32:
201 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
203 case DBUS_TYPE_UINT64:
204 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
207 g_return_if_reached ();
210 account_widget_handle_control_buttons_sensitivity (self);
214 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
215 EmpathyAccountWidget *self)
218 gboolean default_value;
219 const gchar *param_name;
220 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
222 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
223 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
225 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
226 * always unset the param and set the value if different from the
228 empathy_account_settings_unset (priv->settings, param_name);
229 default_value = empathy_account_settings_get_boolean (priv->settings,
232 if (default_value == value)
234 DEBUG ("Unset %s and restore to %d", param_name, default_value);
238 DEBUG ("Setting %s to %d", param_name, value);
239 empathy_account_settings_set_boolean (priv->settings, param_name, value);
242 account_widget_handle_control_buttons_sensitivity (self);
246 account_widget_forget_clicked_cb (GtkWidget *button,
247 EmpathyAccountWidget *self)
249 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
250 const gchar *param_name;
252 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
255 DEBUG ("Unset %s", param_name);
256 empathy_account_settings_unset (priv->settings, param_name);
257 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
259 account_widget_handle_control_buttons_sensitivity (self);
263 account_widget_password_changed_cb (GtkWidget *entry,
264 EmpathyAccountWidget *self)
266 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
269 str = gtk_entry_get_text (GTK_ENTRY (entry));
270 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
274 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
275 EmpathyAccountWidget *self)
277 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
281 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
282 port = empathy_account_settings_get_uint32 (priv->settings, "port");
286 if (port == 5222 || port == 0)
291 if (port == 5223 || port == 0)
295 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
299 account_widget_setup_widget (EmpathyAccountWidget *self,
301 const gchar *param_name)
303 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
305 g_object_set_data_full (G_OBJECT (widget), "param_name",
306 g_strdup (param_name), g_free);
308 if (GTK_IS_SPIN_BUTTON (widget))
311 const gchar *signature;
313 signature = empathy_account_settings_get_dbus_signature (priv->settings,
315 g_return_if_fail (signature != NULL);
317 switch ((int)*signature)
319 case DBUS_TYPE_INT16:
320 case DBUS_TYPE_INT32:
321 value = empathy_account_settings_get_int32 (priv->settings,
324 case DBUS_TYPE_INT64:
325 value = empathy_account_settings_get_int64 (priv->settings,
328 case DBUS_TYPE_UINT16:
329 case DBUS_TYPE_UINT32:
330 value = empathy_account_settings_get_uint32 (priv->settings,
333 case DBUS_TYPE_UINT64:
334 value = empathy_account_settings_get_uint64 (priv->settings,
338 g_return_if_reached ();
341 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
343 g_signal_connect (widget, "value-changed",
344 G_CALLBACK (account_widget_int_changed_cb),
347 else if (GTK_IS_ENTRY (widget))
349 const gchar *str = NULL;
351 str = empathy_account_settings_get_string (priv->settings, param_name);
352 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
354 if (strstr (param_name, "password"))
356 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
359 g_signal_connect (widget, "focus-out-event",
360 G_CALLBACK (account_widget_entry_focus_cb),
362 g_signal_connect (widget, "changed",
363 G_CALLBACK (account_widget_entry_changed_cb), self);
365 else if (GTK_IS_TOGGLE_BUTTON (widget))
367 gboolean value = FALSE;
369 value = empathy_account_settings_get_boolean (priv->settings,
371 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
373 g_signal_connect (widget, "toggled",
374 G_CALLBACK (account_widget_checkbutton_toggled_cb),
379 DEBUG ("Unknown type of widget for param %s", param_name);
384 account_widget_generic_format_param_name (const gchar *param_name)
389 str = g_strdup (param_name);
391 if (str && g_ascii_isalpha (str[0]))
392 str[0] = g_ascii_toupper (str[0]);
394 while ((p = strchr (str, '-')) != NULL)
396 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
399 p[1] = g_ascii_toupper (p[1]);
409 accounts_widget_generic_setup (EmpathyAccountWidget *self,
410 GtkWidget *table_common_settings,
411 GtkWidget *table_advanced_settings)
413 TpConnectionManagerParam *params, *param;
414 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
416 params = empathy_account_settings_get_tp_params (priv->settings);
418 for (param = params; param != NULL && param->name != NULL; param++)
420 GtkWidget *table_settings;
422 GtkWidget *widget = NULL;
423 gchar *param_name_formatted;
425 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
426 table_settings = table_common_settings;
427 else if (priv->simple)
430 table_settings = table_advanced_settings;
432 param_name_formatted = account_widget_generic_format_param_name
434 g_object_get (table_settings, "n-rows", &n_rows, NULL);
435 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
437 if (param->dbus_signature[0] == 's')
441 str = g_strdup_printf (_("%s:"), param_name_formatted);
442 widget = gtk_label_new (str);
443 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
446 gtk_table_attach (GTK_TABLE (table_settings),
452 gtk_widget_show (widget);
454 widget = gtk_entry_new ();
455 if (strcmp (param->name, "account") == 0)
457 g_signal_connect (widget, "realize",
458 G_CALLBACK (gtk_widget_grab_focus),
461 gtk_table_attach (GTK_TABLE (table_settings),
465 GTK_FILL | GTK_EXPAND, 0,
467 gtk_widget_show (widget);
469 /* int types: ynqiuxt. double type is 'd' */
470 else if (param->dbus_signature[0] == 'y' ||
471 param->dbus_signature[0] == 'n' ||
472 param->dbus_signature[0] == 'q' ||
473 param->dbus_signature[0] == 'i' ||
474 param->dbus_signature[0] == 'u' ||
475 param->dbus_signature[0] == 'x' ||
476 param->dbus_signature[0] == 't' ||
477 param->dbus_signature[0] == 'd')
484 switch (param->dbus_signature[0])
486 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
487 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
488 case 'q': minint = 0; maxint = G_MAXUINT16; break;
489 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
490 case 'u': minint = 0; maxint = G_MAXUINT32; break;
491 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
492 case 't': minint = 0; maxint = G_MAXUINT64; break;
493 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
497 str = g_strdup_printf (_("%s:"), param_name_formatted);
498 widget = gtk_label_new (str);
499 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
502 gtk_table_attach (GTK_TABLE (table_settings),
508 gtk_widget_show (widget);
510 widget = gtk_spin_button_new_with_range (minint, maxint, step);
511 gtk_table_attach (GTK_TABLE (table_settings),
515 GTK_FILL | GTK_EXPAND, 0,
517 gtk_widget_show (widget);
519 else if (param->dbus_signature[0] == 'b')
521 widget = gtk_check_button_new_with_label (param_name_formatted);
522 gtk_table_attach (GTK_TABLE (table_settings),
526 GTK_FILL | GTK_EXPAND, 0,
528 gtk_widget_show (widget);
532 DEBUG ("Unknown signature for param %s: %s",
533 param_name_formatted, param->dbus_signature);
537 account_widget_setup_widget (self, widget, param->name);
539 g_free (param_name_formatted);
544 account_widget_handle_params_valist (EmpathyAccountWidget *self,
545 const gchar *first_widget,
551 for (name = first_widget; name; name = va_arg (args, const gchar *))
553 const gchar *param_name;
555 param_name = va_arg (args, const gchar *);
556 object = gtk_builder_get_object (self->ui_details->gui, name);
560 g_warning ("Builder is missing object '%s'.", name);
564 account_widget_setup_widget (self, GTK_WIDGET (object), param_name);
569 account_widget_cancel_clicked_cb (GtkWidget *button,
570 EmpathyAccountWidget *self)
572 g_signal_emit (self, signals[CANCELLED], 0);
576 account_widget_account_enabled_cb (GObject *source_object,
580 GError *error = NULL;
581 EmpathyAccount *account = EMPATHY_ACCOUNT (source_object);
582 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
584 empathy_account_set_enabled_finish (account, res, &error);
588 DEBUG ("Could not automatically enable new account: %s", error->message);
589 g_error_free (error);
593 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
598 account_widget_applied_cb (GObject *source_object,
602 GError *error = NULL;
603 EmpathyAccount *account;
604 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
605 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
606 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
608 empathy_account_settings_apply_finish (settings, res, &error);
612 DEBUG ("Could not apply changes to account: %s", error->message);
613 g_error_free (error);
617 account = empathy_account_settings_get_account (priv->settings);
621 if (priv->creating_account)
623 /* By default, when an account is created, we enable it. */
624 empathy_account_set_enabled_async (account, TRUE,
625 account_widget_account_enabled_cb, widget);
627 else if (priv->enabled_checkbox != NULL)
629 gboolean enabled_checked;
631 enabled_checked = gtk_toggle_button_get_active (
632 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
634 if (empathy_account_is_enabled (account) && enabled_checked)
636 /* After having applied changes to a user account, we
637 * automatically reconnect it. This is done so the new
638 * information entered by the user is validated on the server. */
639 empathy_account_reconnect_async (account, NULL, NULL);
643 /* The account is disabled so we enable it according to the value
644 * of the "Enabled" checkbox */
645 empathy_account_set_enabled_async (account, enabled_checked,
651 account_widget_set_control_buttons_sensitivity (widget, FALSE);
655 account_widget_apply_clicked_cb (GtkWidget *button,
656 EmpathyAccountWidget *self)
658 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
660 empathy_account_settings_apply_async (priv->settings,
661 account_widget_applied_cb, self);
665 account_widget_setup_generic (EmpathyAccountWidget *self)
667 GtkWidget *table_common_settings;
668 GtkWidget *table_advanced_settings;
670 table_common_settings = GTK_WIDGET (gtk_builder_get_object
671 (self->ui_details->gui, "table_common_settings"));
672 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
673 (self->ui_details->gui, "table_advanced_settings"));
675 accounts_widget_generic_setup (self, table_common_settings,
676 table_advanced_settings);
678 g_object_unref (self->ui_details->gui);
682 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
686 EmpathyAccountWidget *self = user_data;
687 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
689 if (empathy_account_settings_is_ready (priv->settings))
690 account_widget_setup_generic (self);
694 account_widget_build_generic (EmpathyAccountWidget *self,
695 const char *filename)
697 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
698 GtkWidget *expander_advanced;
700 self->ui_details->gui = empathy_builder_get_file (filename,
701 "table_common_settings", &priv->table_common_settings,
702 "vbox_generic_settings", &self->ui_details->widget,
703 "expander_advanced_settings", &expander_advanced,
707 gtk_widget_hide (expander_advanced);
709 g_object_ref (self->ui_details->gui);
711 if (empathy_account_settings_is_ready (priv->settings))
712 account_widget_setup_generic (self);
714 g_signal_connect (priv->settings, "notify::ready",
715 G_CALLBACK (account_widget_settings_ready_cb), self);
719 account_widget_build_salut (EmpathyAccountWidget *self,
720 const char *filename)
722 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
724 self->ui_details->gui = empathy_builder_get_file (filename,
725 "table_common_settings", &priv->table_common_settings,
726 "vbox_salut_settings", &self->ui_details->widget,
729 empathy_account_widget_handle_params (self,
730 "entry_published", "published-name",
731 "entry_nickname", "nickname",
732 "entry_first_name", "first-name",
733 "entry_last_name", "last-name",
734 "entry_email", "email",
738 self->ui_details->default_focus = g_strdup ("entry_nickname");
742 account_widget_build_irc (EmpathyAccountWidget *self,
743 const char *filename)
745 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
746 empathy_account_widget_irc_build (self, filename,
747 &priv->table_common_settings);
751 account_widget_build_sip (EmpathyAccountWidget *self,
752 const char *filename)
754 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
755 empathy_account_widget_sip_build (self, filename,
756 &priv->table_common_settings);
760 account_widget_build_msn (EmpathyAccountWidget *self,
761 const char *filename)
763 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
767 self->ui_details->gui = empathy_builder_get_file (filename,
768 "vbox_msn_simple", &self->ui_details->widget,
771 empathy_account_widget_handle_params (self,
772 "entry_id_simple", "account",
773 "entry_password_simple", "password",
776 self->ui_details->default_focus = g_strdup ("entry_id_simple");
780 self->ui_details->gui = empathy_builder_get_file (filename,
781 "table_common_msn_settings", &priv->table_common_settings,
782 "vbox_msn_settings", &self->ui_details->widget,
785 empathy_account_widget_handle_params (self,
786 "entry_id", "account",
787 "entry_password", "password",
788 "entry_server", "server",
789 "spinbutton_port", "port",
792 self->ui_details->default_focus = g_strdup ("entry_id");
793 self->ui_details->add_forget = TRUE;
798 account_widget_build_jabber (EmpathyAccountWidget *self,
799 const char *filename)
801 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
802 GtkWidget *spinbutton_port;
803 GtkWidget *checkbutton_ssl;
804 GtkWidget *label_id, *label_password;
805 GtkWidget *label_id_create, *label_password_create;
809 self->ui_details->gui = empathy_builder_get_file (filename,
810 "vbox_jabber_simple", &self->ui_details->widget,
811 "label_id_simple", &label_id,
812 "label_id_create", &label_id_create,
813 "label_password_simple", &label_password,
814 "label_password_create", &label_password_create,
817 if (empathy_account_settings_get_boolean (priv->settings, "register"))
819 gtk_widget_hide (label_id);
820 gtk_widget_hide (label_password);
821 gtk_widget_show (label_id_create);
822 gtk_widget_show (label_password_create);
825 empathy_account_widget_handle_params (self,
826 "entry_id_simple", "account",
827 "entry_password_simple", "password",
830 self->ui_details->default_focus = g_strdup ("entry_id_simple");
834 self->ui_details->gui = empathy_builder_get_file (filename,
835 "table_common_settings", &priv->table_common_settings,
836 "vbox_jabber_settings", &self->ui_details->widget,
837 "spinbutton_port", &spinbutton_port,
838 "checkbutton_ssl", &checkbutton_ssl,
841 empathy_account_widget_handle_params (self,
842 "entry_id", "account",
843 "entry_password", "password",
844 "entry_resource", "resource",
845 "entry_server", "server",
846 "spinbutton_port", "port",
847 "spinbutton_priority", "priority",
848 "checkbutton_ssl", "old-ssl",
849 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
850 "checkbutton_encryption", "require-encryption",
853 self->ui_details->default_focus = g_strdup ("entry_id");
854 self->ui_details->add_forget = TRUE;
855 priv->spinbutton_port = spinbutton_port;
857 g_signal_connect (checkbutton_ssl, "toggled",
858 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
864 account_widget_build_icq (EmpathyAccountWidget *self,
865 const char *filename)
867 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
868 GtkWidget *spinbutton_port;
872 self->ui_details->gui = empathy_builder_get_file (filename,
873 "vbox_icq_simple", &self->ui_details->widget,
876 empathy_account_widget_handle_params (self,
877 "entry_uin_simple", "account",
878 "entry_password_simple", "password",
881 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
885 self->ui_details->gui = empathy_builder_get_file (filename,
886 "table_common_settings", &priv->table_common_settings,
887 "vbox_icq_settings", &self->ui_details->widget,
888 "spinbutton_port", &spinbutton_port,
891 empathy_account_widget_handle_params (self,
892 "entry_uin", "account",
893 "entry_password", "password",
894 "entry_server", "server",
895 "spinbutton_port", "port",
896 "entry_charset", "charset",
899 self->ui_details->default_focus = g_strdup ("entry_uin");
900 self->ui_details->add_forget = TRUE;
905 account_widget_build_aim (EmpathyAccountWidget *self,
906 const char *filename)
908 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
909 GtkWidget *spinbutton_port;
913 self->ui_details->gui = empathy_builder_get_file (filename,
914 "vbox_aim_simple", &self->ui_details->widget,
917 empathy_account_widget_handle_params (self,
918 "entry_screenname_simple", "account",
919 "entry_password_simple", "password",
922 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
926 self->ui_details->gui = empathy_builder_get_file (filename,
927 "table_common_settings", &priv->table_common_settings,
928 "vbox_aim_settings", &self->ui_details->widget,
929 "spinbutton_port", &spinbutton_port,
932 empathy_account_widget_handle_params (self,
933 "entry_screenname", "account",
934 "entry_password", "password",
935 "entry_server", "server",
936 "spinbutton_port", "port",
939 self->ui_details->default_focus = g_strdup ("entry_screenname");
940 self->ui_details->add_forget = TRUE;
945 account_widget_build_yahoo (EmpathyAccountWidget *self,
946 const char *filename)
948 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
952 self->ui_details->gui = empathy_builder_get_file (filename,
953 "vbox_yahoo_simple", &self->ui_details->widget,
956 empathy_account_widget_handle_params (self,
957 "entry_id_simple", "account",
958 "entry_password_simple", "password",
961 self->ui_details->default_focus = g_strdup ("entry_id_simple");
965 self->ui_details->gui = empathy_builder_get_file (filename,
966 "table_common_settings", &priv->table_common_settings,
967 "vbox_yahoo_settings", &self->ui_details->widget,
970 empathy_account_widget_handle_params (self,
971 "entry_id", "account",
972 "entry_password", "password",
973 "entry_server", "server",
974 "entry_locale", "room-list-locale",
975 "entry_charset", "charset",
976 "spinbutton_port", "port",
977 "checkbutton_yahoojp", "yahoojp",
978 "checkbutton_ignore_invites", "ignore-invites",
981 self->ui_details->default_focus = g_strdup ("entry_id");
982 self->ui_details->add_forget = TRUE;
987 account_widget_build_groupwise (EmpathyAccountWidget *self,
988 const char *filename)
990 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
994 self->ui_details->gui = empathy_builder_get_file (filename,
995 "vbox_groupwise_simple", &self->ui_details->widget,
998 empathy_account_widget_handle_params (self,
999 "entry_id_simple", "account",
1000 "entry_password_simple", "password",
1003 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1007 self->ui_details->gui = empathy_builder_get_file (filename,
1008 "table_common_groupwise_settings", &priv->table_common_settings,
1009 "vbox_groupwise_settings", &self->ui_details->widget,
1012 empathy_account_widget_handle_params (self,
1013 "entry_id", "account",
1014 "entry_password", "password",
1015 "entry_server", "server",
1016 "spinbutton_port", "port",
1019 self->ui_details->default_focus = g_strdup ("entry_id");
1020 self->ui_details->add_forget = TRUE;
1025 account_widget_destroy_cb (GtkWidget *widget,
1026 EmpathyAccountWidget *self)
1028 g_object_unref (self);
1032 empathy_account_widget_enabled_cb (EmpathyAccount *account,
1036 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1037 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1038 gboolean enabled = empathy_account_is_enabled (account);
1040 if (priv->enabled_checkbox != NULL)
1042 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1048 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1051 account_widget_handle_control_buttons_sensitivity (
1052 EMPATHY_ACCOUNT_WIDGET (user_data));
1056 do_set_property (GObject *object,
1058 const GValue *value,
1061 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1066 priv->protocol = g_value_dup_string (value);
1069 priv->settings = g_value_dup_object (value);
1072 priv->simple = g_value_get_boolean (value);
1074 case PROP_CREATING_ACCOUNT:
1075 priv->creating_account = g_value_get_boolean (value);
1078 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1083 do_get_property (GObject *object,
1088 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1093 g_value_set_string (value, priv->protocol);
1096 g_value_set_object (value, priv->settings);
1099 g_value_set_boolean (value, priv->simple);
1101 case PROP_CREATING_ACCOUNT:
1102 g_value_set_boolean (value, priv->creating_account);
1105 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1109 #define WIDGET(cm, proto) \
1110 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1111 account_widget_build_##proto }
1114 do_constructed (GObject *obj)
1116 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1117 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1118 EmpathyAccount *account;
1119 const gchar *protocol, *cm_name;
1122 const gchar *cm_name;
1123 const gchar *protocol;
1125 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1127 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1128 account_widget_build_salut },
1129 WIDGET (gabble, jabber),
1130 WIDGET (butterfly, msn),
1133 WIDGET (haze, yahoo),
1134 WIDGET (haze, groupwise),
1136 WIDGET (sofiasip, sip),
1139 cm_name = empathy_account_settings_get_cm (priv->settings);
1140 protocol = empathy_account_settings_get_protocol (priv->settings);
1142 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1144 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1145 !tp_strdiff (widgets[i].protocol, protocol))
1149 filename = empathy_file_lookup (widgets[i].file,
1151 widgets[i].func (self, filename);
1158 if (i == G_N_ELEMENTS (widgets))
1160 gchar *filename = empathy_file_lookup (
1161 "empathy-account-widget-generic.ui", "libempathy-gtk");
1162 account_widget_build_generic (self, filename);
1166 /* handle default focus */
1167 if (self->ui_details->default_focus != NULL)
1169 GObject *default_focus_entry;
1171 default_focus_entry = gtk_builder_get_object
1172 (self->ui_details->gui, self->ui_details->default_focus);
1173 g_signal_connect (default_focus_entry, "realize",
1174 G_CALLBACK (gtk_widget_grab_focus),
1178 /* handle forget button */
1179 if (self->ui_details->add_forget)
1181 const gchar *password = NULL;
1183 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1184 (self->ui_details->gui, "button_forget"));
1185 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1186 (self->ui_details->gui, "entry_password"));
1188 password = empathy_account_settings_get_string (priv->settings,
1190 gtk_widget_set_sensitive (priv->button_forget,
1191 !EMP_STR_EMPTY (password));
1193 g_signal_connect (priv->button_forget, "clicked",
1194 G_CALLBACK (account_widget_forget_clicked_cb),
1196 g_signal_connect (priv->entry_password, "changed",
1197 G_CALLBACK (account_widget_password_changed_cb),
1201 /* handle apply and cancel button */
1204 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1206 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1207 priv->apply_button = gtk_button_new_from_stock (
1208 priv->creating_account ? GTK_STOCK_CONNECT : GTK_STOCK_APPLY);
1210 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1212 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1215 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1218 g_signal_connect (priv->cancel_button, "clicked",
1219 G_CALLBACK (account_widget_cancel_clicked_cb),
1221 g_signal_connect (priv->apply_button, "clicked",
1222 G_CALLBACK (account_widget_apply_clicked_cb),
1224 gtk_widget_show_all (hbox);
1225 account_widget_set_control_buttons_sensitivity (self, FALSE);
1228 account = empathy_account_settings_get_account (priv->settings);
1230 if (account != NULL)
1232 g_signal_connect (account, "notify::enabled",
1233 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1236 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1237 if (!priv->creating_account && priv->table_common_settings != NULL)
1239 guint nb_rows, nb_columns;
1241 priv->enabled_checkbox =
1242 gtk_check_button_new_with_label (_("Enabled"));
1243 gtk_toggle_button_set_active (
1244 GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1245 empathy_account_is_enabled (account));
1247 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1248 "n-columns", &nb_columns, NULL);
1250 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1253 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1254 priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows,
1255 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1257 gtk_widget_show (priv->enabled_checkbox);
1259 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
1260 G_CALLBACK (account_widget_enabled_toggled_cb), self);
1263 /* hook up to widget destruction to unref ourselves */
1264 g_signal_connect (self->ui_details->widget, "destroy",
1265 G_CALLBACK (account_widget_destroy_cb), self);
1267 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1268 self->ui_details->widget);
1269 self->ui_details->gui = NULL;
1273 do_dispose (GObject *obj)
1275 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1276 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1278 if (priv->dispose_run)
1281 priv->dispose_run = TRUE;
1283 empathy_account_settings_is_ready (priv->settings);
1285 if (priv->settings != NULL)
1287 EmpathyAccount *account;
1288 account = empathy_account_settings_get_account (priv->settings);
1290 if (account != NULL)
1292 g_signal_handlers_disconnect_by_func (account,
1293 empathy_account_widget_enabled_cb, self);
1296 g_object_unref (priv->settings);
1297 priv->settings = NULL;
1300 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1301 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1305 do_finalize (GObject *obj)
1307 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1308 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1310 g_free (self->ui_details->default_focus);
1311 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1313 g_free (priv->protocol);
1315 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1316 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1320 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1322 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1323 GParamSpec *param_spec;
1325 oclass->get_property = do_get_property;
1326 oclass->set_property = do_set_property;
1327 oclass->constructed = do_constructed;
1328 oclass->dispose = do_dispose;
1329 oclass->finalize = do_finalize;
1331 param_spec = g_param_spec_string ("protocol",
1332 "protocol", "The protocol of the account",
1334 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1335 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1337 param_spec = g_param_spec_object ("settings",
1338 "settings", "The settings of the account",
1339 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1340 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1341 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1343 param_spec = g_param_spec_boolean ("simple",
1344 "simple", "Whether the account widget is a simple or an advanced one",
1346 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1347 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1349 param_spec = g_param_spec_boolean ("creating-account",
1351 "TRUE if we're creating an account, FALSE if we're modifying it",
1353 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1354 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1356 signals[HANDLE_APPLY] =
1357 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1358 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1359 g_cclosure_marshal_VOID__BOOLEAN,
1363 /* This signal is emitted when an account has been created and enabled. */
1364 signals[ACCOUNT_CREATED] =
1365 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1366 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1367 g_cclosure_marshal_VOID__VOID,
1371 signals[CANCELLED] =
1372 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1373 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1374 g_cclosure_marshal_VOID__VOID,
1378 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1382 empathy_account_widget_init (EmpathyAccountWidget *self)
1384 EmpathyAccountWidgetPriv *priv =
1385 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1386 EmpathyAccountWidgetPriv);
1389 priv->dispose_run = FALSE;
1391 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1394 /* public methods */
1397 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1398 const gchar *first_widget,
1403 va_start (args, first_widget);
1404 account_widget_handle_params_valist (self, first_widget, args);
1409 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1411 return widget->ui_details->widget;
1414 EmpathyAccountWidget *
1415 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1418 EmpathyAccountWidget *self;
1420 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1423 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1424 "settings", settings, "simple", simple,
1426 empathy_account_settings_get_account (settings) == NULL,