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)
52 EmpathyAccountSettings *settings;
54 GtkWidget *table_common_settings;
55 GtkWidget *apply_button;
56 GtkWidget *cancel_button;
57 GtkWidget *entry_password;
58 GtkWidget *button_forget;
59 GtkWidget *spinbutton_port;
60 GtkWidget *enabled_checkbox;
64 gboolean contains_pending_changes;
65 gboolean original_enabled_checkbox_value;
67 /* An EmpathyAccountWidget can be used to either create an account or
68 * modify it. When we are creating an account, this member is set to TRUE */
69 gboolean creating_account;
72 } EmpathyAccountWidgetPriv;
88 static guint signals[LAST_SIGNAL] = { 0 };
90 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
91 #define CHANGED_TIMEOUT 300
94 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
97 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
101 gtk_widget_set_sensitive (priv->apply_button, sensitive);
102 gtk_widget_set_sensitive (priv->cancel_button, sensitive);
103 priv->contains_pending_changes = sensitive;
108 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
110 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
113 is_valid = empathy_account_settings_is_valid (priv->settings);
116 account_widget_set_control_buttons_sensitivity (self, 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_changed_cb (GtkEditable *entry,
156 EmpathyAccountWidget *self)
158 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
159 account_widget_handle_control_buttons_sensitivity (self);
163 account_widget_int_changed_cb (GtkWidget *widget,
164 EmpathyAccountWidget *self)
166 const gchar *param_name;
168 const gchar *signature;
169 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
171 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
172 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
174 signature = empathy_account_settings_get_dbus_signature (priv->settings,
176 g_return_if_fail (signature != NULL);
178 DEBUG ("Setting %s to %d", param_name, value);
180 switch ((int)*signature)
182 case DBUS_TYPE_INT16:
183 case DBUS_TYPE_INT32:
184 empathy_account_settings_set_int32 (priv->settings, param_name, value);
186 case DBUS_TYPE_INT64:
187 empathy_account_settings_set_int64 (priv->settings, param_name, value);
189 case DBUS_TYPE_UINT16:
190 case DBUS_TYPE_UINT32:
191 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
193 case DBUS_TYPE_UINT64:
194 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
197 g_return_if_reached ();
200 account_widget_handle_control_buttons_sensitivity (self);
204 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
205 EmpathyAccountWidget *self)
208 gboolean default_value;
209 const gchar *param_name;
210 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
212 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
213 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
215 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
216 * always unset the param and set the value if different from the
218 empathy_account_settings_unset (priv->settings, param_name);
219 default_value = empathy_account_settings_get_boolean (priv->settings,
222 if (default_value == value)
224 DEBUG ("Unset %s and restore to %d", param_name, default_value);
228 DEBUG ("Setting %s to %d", param_name, value);
229 empathy_account_settings_set_boolean (priv->settings, param_name, value);
232 account_widget_handle_control_buttons_sensitivity (self);
236 account_widget_forget_clicked_cb (GtkWidget *button,
237 EmpathyAccountWidget *self)
239 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
240 const gchar *param_name;
242 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
245 DEBUG ("Unset %s", param_name);
246 empathy_account_settings_unset (priv->settings, param_name);
247 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
249 account_widget_handle_control_buttons_sensitivity (self);
253 account_widget_password_changed_cb (GtkWidget *entry,
254 EmpathyAccountWidget *self)
256 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
259 str = gtk_entry_get_text (GTK_ENTRY (entry));
260 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
264 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
265 EmpathyAccountWidget *self)
267 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
271 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
272 port = empathy_account_settings_get_uint32 (priv->settings, "port");
276 if (port == 5222 || port == 0)
281 if (port == 5223 || port == 0)
285 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
289 account_widget_setup_widget (EmpathyAccountWidget *self,
291 const gchar *param_name)
293 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
295 g_object_set_data_full (G_OBJECT (widget), "param_name",
296 g_strdup (param_name), g_free);
298 if (GTK_IS_SPIN_BUTTON (widget))
301 const gchar *signature;
303 signature = empathy_account_settings_get_dbus_signature (priv->settings,
305 g_return_if_fail (signature != NULL);
307 switch ((int)*signature)
309 case DBUS_TYPE_INT16:
310 case DBUS_TYPE_INT32:
311 value = empathy_account_settings_get_int32 (priv->settings,
314 case DBUS_TYPE_INT64:
315 value = empathy_account_settings_get_int64 (priv->settings,
318 case DBUS_TYPE_UINT16:
319 case DBUS_TYPE_UINT32:
320 value = empathy_account_settings_get_uint32 (priv->settings,
323 case DBUS_TYPE_UINT64:
324 value = empathy_account_settings_get_uint64 (priv->settings,
328 g_return_if_reached ();
331 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
333 g_signal_connect (widget, "value-changed",
334 G_CALLBACK (account_widget_int_changed_cb),
337 else if (GTK_IS_ENTRY (widget))
339 const gchar *str = NULL;
341 str = empathy_account_settings_get_string (priv->settings, param_name);
342 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
344 if (strstr (param_name, "password"))
346 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
349 g_signal_connect (widget, "changed",
350 G_CALLBACK (account_widget_entry_changed_cb), self);
352 else if (GTK_IS_TOGGLE_BUTTON (widget))
354 gboolean value = FALSE;
356 value = empathy_account_settings_get_boolean (priv->settings,
358 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
360 g_signal_connect (widget, "toggled",
361 G_CALLBACK (account_widget_checkbutton_toggled_cb),
366 DEBUG ("Unknown type of widget for param %s", param_name);
371 account_widget_generic_format_param_name (const gchar *param_name)
376 str = g_strdup (param_name);
378 if (str && g_ascii_isalpha (str[0]))
379 str[0] = g_ascii_toupper (str[0]);
381 while ((p = strchr (str, '-')) != NULL)
383 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
386 p[1] = g_ascii_toupper (p[1]);
396 accounts_widget_generic_setup (EmpathyAccountWidget *self,
397 GtkWidget *table_common_settings,
398 GtkWidget *table_advanced_settings)
400 TpConnectionManagerParam *params, *param;
401 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
403 params = empathy_account_settings_get_tp_params (priv->settings);
405 for (param = params; param != NULL && param->name != NULL; param++)
407 GtkWidget *table_settings;
409 GtkWidget *widget = NULL;
410 gchar *param_name_formatted;
412 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
413 table_settings = table_common_settings;
414 else if (priv->simple)
417 table_settings = table_advanced_settings;
419 param_name_formatted = account_widget_generic_format_param_name
421 g_object_get (table_settings, "n-rows", &n_rows, NULL);
422 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
424 if (param->dbus_signature[0] == 's')
428 str = g_strdup_printf (_("%s:"), param_name_formatted);
429 widget = gtk_label_new (str);
430 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
433 gtk_table_attach (GTK_TABLE (table_settings),
439 gtk_widget_show (widget);
441 widget = gtk_entry_new ();
442 if (strcmp (param->name, "account") == 0)
444 g_signal_connect (widget, "realize",
445 G_CALLBACK (gtk_widget_grab_focus),
448 gtk_table_attach (GTK_TABLE (table_settings),
452 GTK_FILL | GTK_EXPAND, 0,
454 gtk_widget_show (widget);
456 /* int types: ynqiuxt. double type is 'd' */
457 else if (param->dbus_signature[0] == 'y' ||
458 param->dbus_signature[0] == 'n' ||
459 param->dbus_signature[0] == 'q' ||
460 param->dbus_signature[0] == 'i' ||
461 param->dbus_signature[0] == 'u' ||
462 param->dbus_signature[0] == 'x' ||
463 param->dbus_signature[0] == 't' ||
464 param->dbus_signature[0] == 'd')
471 switch (param->dbus_signature[0])
473 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
474 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
475 case 'q': minint = 0; maxint = G_MAXUINT16; break;
476 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
477 case 'u': minint = 0; maxint = G_MAXUINT32; break;
478 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
479 case 't': minint = 0; maxint = G_MAXUINT64; break;
480 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
484 str = g_strdup_printf (_("%s:"), param_name_formatted);
485 widget = gtk_label_new (str);
486 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
489 gtk_table_attach (GTK_TABLE (table_settings),
495 gtk_widget_show (widget);
497 widget = gtk_spin_button_new_with_range (minint, maxint, step);
498 gtk_table_attach (GTK_TABLE (table_settings),
502 GTK_FILL | GTK_EXPAND, 0,
504 gtk_widget_show (widget);
506 else if (param->dbus_signature[0] == 'b')
508 widget = gtk_check_button_new_with_label (param_name_formatted);
509 gtk_table_attach (GTK_TABLE (table_settings),
513 GTK_FILL | GTK_EXPAND, 0,
515 gtk_widget_show (widget);
519 DEBUG ("Unknown signature for param %s: %s",
520 param_name_formatted, param->dbus_signature);
524 account_widget_setup_widget (self, widget, param->name);
526 g_free (param_name_formatted);
531 account_widget_handle_params_valist (EmpathyAccountWidget *self,
532 const gchar *first_widget,
538 for (name = first_widget; name; name = va_arg (args, const gchar *))
540 const gchar *param_name;
542 param_name = va_arg (args, const gchar *);
543 object = gtk_builder_get_object (self->ui_details->gui, name);
547 g_warning ("Builder is missing object '%s'.", name);
551 account_widget_setup_widget (self, GTK_WIDGET (object), param_name);
556 account_widget_cancel_clicked_cb (GtkWidget *button,
557 EmpathyAccountWidget *self)
559 g_signal_emit (self, signals[CANCELLED], 0);
563 account_widget_account_enabled_cb (GObject *source_object,
567 GError *error = NULL;
568 EmpathyAccount *account = EMPATHY_ACCOUNT (source_object);
569 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
571 empathy_account_set_enabled_finish (account, res, &error);
575 DEBUG ("Could not automatically enable new account: %s", error->message);
576 g_error_free (error);
580 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
585 account_widget_applied_cb (GObject *source_object,
589 GError *error = NULL;
590 EmpathyAccount *account;
591 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
592 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
593 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
595 empathy_account_settings_apply_finish (settings, res, &error);
599 DEBUG ("Could not apply changes to account: %s", error->message);
600 g_error_free (error);
604 account = empathy_account_settings_get_account (priv->settings);
608 if (priv->creating_account)
610 /* By default, when an account is created, we enable it. */
611 empathy_account_set_enabled_async (account, TRUE,
612 account_widget_account_enabled_cb, widget);
614 else if (priv->enabled_checkbox != NULL)
616 gboolean enabled_checked;
618 enabled_checked = gtk_toggle_button_get_active (
619 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
621 if (empathy_account_is_enabled (account) && enabled_checked)
623 /* After having applied changes to a user account, we
624 * automatically reconnect it. This is done so the new
625 * information entered by the user is validated on the server. */
626 empathy_account_reconnect_async (account, NULL, NULL);
630 /* The account is disabled so we enable it according to the value
631 * of the "Enabled" checkbox */
632 empathy_account_set_enabled_async (account, enabled_checked,
638 account_widget_set_control_buttons_sensitivity (widget, FALSE);
642 account_widget_apply_clicked_cb (GtkWidget *button,
643 EmpathyAccountWidget *self)
645 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
647 empathy_account_settings_apply_async (priv->settings,
648 account_widget_applied_cb, self);
652 account_widget_setup_generic (EmpathyAccountWidget *self)
654 GtkWidget *table_common_settings;
655 GtkWidget *table_advanced_settings;
657 table_common_settings = GTK_WIDGET (gtk_builder_get_object
658 (self->ui_details->gui, "table_common_settings"));
659 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
660 (self->ui_details->gui, "table_advanced_settings"));
662 accounts_widget_generic_setup (self, table_common_settings,
663 table_advanced_settings);
665 g_object_unref (self->ui_details->gui);
669 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
673 EmpathyAccountWidget *self = user_data;
674 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
676 if (empathy_account_settings_is_ready (priv->settings))
677 account_widget_setup_generic (self);
681 account_widget_build_generic (EmpathyAccountWidget *self,
682 const char *filename)
684 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
685 GtkWidget *expander_advanced;
687 self->ui_details->gui = empathy_builder_get_file (filename,
688 "table_common_settings", &priv->table_common_settings,
689 "vbox_generic_settings", &self->ui_details->widget,
690 "expander_advanced_settings", &expander_advanced,
694 gtk_widget_hide (expander_advanced);
696 g_object_ref (self->ui_details->gui);
698 if (empathy_account_settings_is_ready (priv->settings))
699 account_widget_setup_generic (self);
701 g_signal_connect (priv->settings, "notify::ready",
702 G_CALLBACK (account_widget_settings_ready_cb), self);
706 account_widget_build_salut (EmpathyAccountWidget *self,
707 const char *filename)
709 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
711 self->ui_details->gui = empathy_builder_get_file (filename,
712 "table_common_settings", &priv->table_common_settings,
713 "vbox_salut_settings", &self->ui_details->widget,
716 empathy_account_widget_handle_params (self,
717 "entry_published", "published-name",
718 "entry_nickname", "nickname",
719 "entry_first_name", "first-name",
720 "entry_last_name", "last-name",
721 "entry_email", "email",
725 self->ui_details->default_focus = g_strdup ("entry_nickname");
729 account_widget_build_irc (EmpathyAccountWidget *self,
730 const char *filename)
732 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
733 empathy_account_widget_irc_build (self, filename,
734 &priv->table_common_settings);
738 account_widget_build_sip (EmpathyAccountWidget *self,
739 const char *filename)
741 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
742 empathy_account_widget_sip_build (self, filename,
743 &priv->table_common_settings);
747 account_widget_build_msn (EmpathyAccountWidget *self,
748 const char *filename)
750 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
754 self->ui_details->gui = empathy_builder_get_file (filename,
755 "vbox_msn_simple", &self->ui_details->widget,
758 empathy_account_widget_handle_params (self,
759 "entry_id_simple", "account",
760 "entry_password_simple", "password",
763 self->ui_details->default_focus = g_strdup ("entry_id_simple");
767 self->ui_details->gui = empathy_builder_get_file (filename,
768 "table_common_msn_settings", &priv->table_common_settings,
769 "vbox_msn_settings", &self->ui_details->widget,
772 empathy_account_widget_handle_params (self,
773 "entry_id", "account",
774 "entry_password", "password",
775 "entry_server", "server",
776 "spinbutton_port", "port",
779 self->ui_details->default_focus = g_strdup ("entry_id");
780 self->ui_details->add_forget = TRUE;
785 account_widget_build_jabber (EmpathyAccountWidget *self,
786 const char *filename)
788 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
789 GtkWidget *spinbutton_port;
790 GtkWidget *checkbutton_ssl;
791 GtkWidget *label_id, *label_password;
792 GtkWidget *label_id_create, *label_password_create;
796 self->ui_details->gui = empathy_builder_get_file (filename,
797 "vbox_jabber_simple", &self->ui_details->widget,
798 "label_id_simple", &label_id,
799 "label_id_create", &label_id_create,
800 "label_password_simple", &label_password,
801 "label_password_create", &label_password_create,
804 if (empathy_account_settings_get_boolean (priv->settings, "register"))
806 gtk_widget_hide (label_id);
807 gtk_widget_hide (label_password);
808 gtk_widget_show (label_id_create);
809 gtk_widget_show (label_password_create);
812 empathy_account_widget_handle_params (self,
813 "entry_id_simple", "account",
814 "entry_password_simple", "password",
817 self->ui_details->default_focus = g_strdup ("entry_id_simple");
821 self->ui_details->gui = empathy_builder_get_file (filename,
822 "table_common_settings", &priv->table_common_settings,
823 "vbox_jabber_settings", &self->ui_details->widget,
824 "spinbutton_port", &spinbutton_port,
825 "checkbutton_ssl", &checkbutton_ssl,
828 empathy_account_widget_handle_params (self,
829 "entry_id", "account",
830 "entry_password", "password",
831 "entry_resource", "resource",
832 "entry_server", "server",
833 "spinbutton_port", "port",
834 "spinbutton_priority", "priority",
835 "checkbutton_ssl", "old-ssl",
836 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
837 "checkbutton_encryption", "require-encryption",
840 self->ui_details->default_focus = g_strdup ("entry_id");
841 self->ui_details->add_forget = TRUE;
842 priv->spinbutton_port = spinbutton_port;
844 g_signal_connect (checkbutton_ssl, "toggled",
845 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
851 account_widget_build_icq (EmpathyAccountWidget *self,
852 const char *filename)
854 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
855 GtkWidget *spinbutton_port;
859 self->ui_details->gui = empathy_builder_get_file (filename,
860 "vbox_icq_simple", &self->ui_details->widget,
863 empathy_account_widget_handle_params (self,
864 "entry_uin_simple", "account",
865 "entry_password_simple", "password",
868 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
872 self->ui_details->gui = empathy_builder_get_file (filename,
873 "table_common_settings", &priv->table_common_settings,
874 "vbox_icq_settings", &self->ui_details->widget,
875 "spinbutton_port", &spinbutton_port,
878 empathy_account_widget_handle_params (self,
879 "entry_uin", "account",
880 "entry_password", "password",
881 "entry_server", "server",
882 "spinbutton_port", "port",
883 "entry_charset", "charset",
886 self->ui_details->default_focus = g_strdup ("entry_uin");
887 self->ui_details->add_forget = TRUE;
892 account_widget_build_aim (EmpathyAccountWidget *self,
893 const char *filename)
895 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
896 GtkWidget *spinbutton_port;
900 self->ui_details->gui = empathy_builder_get_file (filename,
901 "vbox_aim_simple", &self->ui_details->widget,
904 empathy_account_widget_handle_params (self,
905 "entry_screenname_simple", "account",
906 "entry_password_simple", "password",
909 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
913 self->ui_details->gui = empathy_builder_get_file (filename,
914 "table_common_settings", &priv->table_common_settings,
915 "vbox_aim_settings", &self->ui_details->widget,
916 "spinbutton_port", &spinbutton_port,
919 empathy_account_widget_handle_params (self,
920 "entry_screenname", "account",
921 "entry_password", "password",
922 "entry_server", "server",
923 "spinbutton_port", "port",
926 self->ui_details->default_focus = g_strdup ("entry_screenname");
927 self->ui_details->add_forget = TRUE;
932 account_widget_build_yahoo (EmpathyAccountWidget *self,
933 const char *filename)
935 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
939 self->ui_details->gui = empathy_builder_get_file (filename,
940 "vbox_yahoo_simple", &self->ui_details->widget,
943 empathy_account_widget_handle_params (self,
944 "entry_id_simple", "account",
945 "entry_password_simple", "password",
948 self->ui_details->default_focus = g_strdup ("entry_id_simple");
952 self->ui_details->gui = empathy_builder_get_file (filename,
953 "table_common_settings", &priv->table_common_settings,
954 "vbox_yahoo_settings", &self->ui_details->widget,
957 empathy_account_widget_handle_params (self,
958 "entry_id", "account",
959 "entry_password", "password",
960 "entry_server", "server",
961 "entry_locale", "room-list-locale",
962 "entry_charset", "charset",
963 "spinbutton_port", "port",
964 "checkbutton_yahoojp", "yahoojp",
965 "checkbutton_ignore_invites", "ignore-invites",
968 self->ui_details->default_focus = g_strdup ("entry_id");
969 self->ui_details->add_forget = TRUE;
974 account_widget_build_groupwise (EmpathyAccountWidget *self,
975 const char *filename)
977 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
981 self->ui_details->gui = empathy_builder_get_file (filename,
982 "vbox_groupwise_simple", &self->ui_details->widget,
985 empathy_account_widget_handle_params (self,
986 "entry_id_simple", "account",
987 "entry_password_simple", "password",
990 self->ui_details->default_focus = g_strdup ("entry_id_simple");
994 self->ui_details->gui = empathy_builder_get_file (filename,
995 "table_common_groupwise_settings", &priv->table_common_settings,
996 "vbox_groupwise_settings", &self->ui_details->widget,
999 empathy_account_widget_handle_params (self,
1000 "entry_id", "account",
1001 "entry_password", "password",
1002 "entry_server", "server",
1003 "spinbutton_port", "port",
1006 self->ui_details->default_focus = g_strdup ("entry_id");
1007 self->ui_details->add_forget = TRUE;
1012 account_widget_destroy_cb (GtkWidget *widget,
1013 EmpathyAccountWidget *self)
1015 g_object_unref (self);
1019 empathy_account_widget_enabled_cb (EmpathyAccount *account,
1023 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1024 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1025 gboolean enabled = empathy_account_is_enabled (account);
1027 if (priv->enabled_checkbox != NULL)
1029 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1035 account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
1038 account_widget_handle_control_buttons_sensitivity (
1039 EMPATHY_ACCOUNT_WIDGET (user_data));
1043 do_set_property (GObject *object,
1045 const GValue *value,
1048 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1053 priv->settings = g_value_dup_object (value);
1056 priv->simple = g_value_get_boolean (value);
1058 case PROP_CREATING_ACCOUNT:
1059 priv->creating_account = g_value_get_boolean (value);
1062 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1067 do_get_property (GObject *object,
1072 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1077 g_value_set_string (value,
1078 empathy_account_settings_get_protocol (priv->settings));
1081 g_value_set_object (value, priv->settings);
1084 g_value_set_boolean (value, priv->simple);
1086 case PROP_CREATING_ACCOUNT:
1087 g_value_set_boolean (value, priv->creating_account);
1090 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1094 #define WIDGET(cm, proto) \
1095 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1096 account_widget_build_##proto }
1099 do_constructed (GObject *obj)
1101 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1102 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1103 EmpathyAccount *account;
1104 const gchar *protocol, *cm_name;
1107 const gchar *cm_name;
1108 const gchar *protocol;
1110 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1112 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1113 account_widget_build_salut },
1114 WIDGET (gabble, jabber),
1115 WIDGET (butterfly, msn),
1118 WIDGET (haze, yahoo),
1119 WIDGET (haze, groupwise),
1121 WIDGET (sofiasip, sip),
1124 cm_name = empathy_account_settings_get_cm (priv->settings);
1125 protocol = empathy_account_settings_get_protocol (priv->settings);
1127 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1129 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1130 !tp_strdiff (widgets[i].protocol, protocol))
1134 filename = empathy_file_lookup (widgets[i].file,
1136 widgets[i].func (self, filename);
1143 if (i == G_N_ELEMENTS (widgets))
1145 gchar *filename = empathy_file_lookup (
1146 "empathy-account-widget-generic.ui", "libempathy-gtk");
1147 account_widget_build_generic (self, filename);
1151 /* handle default focus */
1152 if (self->ui_details->default_focus != NULL)
1154 GObject *default_focus_entry;
1156 default_focus_entry = gtk_builder_get_object
1157 (self->ui_details->gui, self->ui_details->default_focus);
1158 g_signal_connect (default_focus_entry, "realize",
1159 G_CALLBACK (gtk_widget_grab_focus),
1163 /* handle forget button */
1164 if (self->ui_details->add_forget)
1166 const gchar *password = NULL;
1168 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1169 (self->ui_details->gui, "button_forget"));
1170 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1171 (self->ui_details->gui, "entry_password"));
1173 password = empathy_account_settings_get_string (priv->settings,
1175 gtk_widget_set_sensitive (priv->button_forget,
1176 !EMP_STR_EMPTY (password));
1178 g_signal_connect (priv->button_forget, "clicked",
1179 G_CALLBACK (account_widget_forget_clicked_cb),
1181 g_signal_connect (priv->entry_password, "changed",
1182 G_CALLBACK (account_widget_password_changed_cb),
1186 /* handle apply and cancel button */
1189 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1191 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1192 priv->apply_button = gtk_button_new_from_stock (
1193 priv->creating_account ? GTK_STOCK_CONNECT : GTK_STOCK_APPLY);
1195 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1197 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1200 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1203 g_signal_connect (priv->cancel_button, "clicked",
1204 G_CALLBACK (account_widget_cancel_clicked_cb),
1206 g_signal_connect (priv->apply_button, "clicked",
1207 G_CALLBACK (account_widget_apply_clicked_cb),
1209 gtk_widget_show_all (hbox);
1210 account_widget_set_control_buttons_sensitivity (self, FALSE);
1213 account = empathy_account_settings_get_account (priv->settings);
1215 if (account != NULL)
1217 g_signal_connect (account, "notify::enabled",
1218 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1221 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1222 if (!priv->creating_account && priv->table_common_settings != NULL)
1224 guint nb_rows, nb_columns;
1226 priv->enabled_checkbox =
1227 gtk_check_button_new_with_label (_("Enabled"));
1228 priv->original_enabled_checkbox_value =
1229 empathy_account_is_enabled (account);
1230 gtk_toggle_button_set_active (
1231 GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1232 priv->original_enabled_checkbox_value);
1234 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1235 "n-columns", &nb_columns, NULL);
1237 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1240 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1241 priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows,
1242 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1244 gtk_widget_show (priv->enabled_checkbox);
1246 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
1247 G_CALLBACK (account_widget_enabled_released_cb), self);
1250 /* hook up to widget destruction to unref ourselves */
1251 g_signal_connect (self->ui_details->widget, "destroy",
1252 G_CALLBACK (account_widget_destroy_cb), self);
1254 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1255 self->ui_details->widget);
1256 self->ui_details->gui = NULL;
1260 do_dispose (GObject *obj)
1262 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1263 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1265 if (priv->dispose_run)
1268 priv->dispose_run = TRUE;
1270 empathy_account_settings_is_ready (priv->settings);
1272 if (priv->settings != NULL)
1274 EmpathyAccount *account;
1275 account = empathy_account_settings_get_account (priv->settings);
1277 if (account != NULL)
1279 g_signal_handlers_disconnect_by_func (account,
1280 empathy_account_widget_enabled_cb, self);
1283 g_object_unref (priv->settings);
1284 priv->settings = NULL;
1287 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1288 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1292 do_finalize (GObject *obj)
1294 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1296 g_free (self->ui_details->default_focus);
1297 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1299 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1300 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1304 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1306 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1307 GParamSpec *param_spec;
1309 oclass->get_property = do_get_property;
1310 oclass->set_property = do_set_property;
1311 oclass->constructed = do_constructed;
1312 oclass->dispose = do_dispose;
1313 oclass->finalize = do_finalize;
1315 param_spec = g_param_spec_string ("protocol",
1316 "protocol", "The protocol of the account",
1318 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1319 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1321 param_spec = g_param_spec_object ("settings",
1322 "settings", "The settings of the account",
1323 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1324 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1325 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1327 param_spec = g_param_spec_boolean ("simple",
1328 "simple", "Whether the account widget is a simple or an advanced one",
1330 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1331 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1333 param_spec = g_param_spec_boolean ("creating-account",
1335 "TRUE if we're creating an account, FALSE if we're modifying it",
1337 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1338 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1340 signals[HANDLE_APPLY] =
1341 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1342 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1343 g_cclosure_marshal_VOID__BOOLEAN,
1347 /* This signal is emitted when an account has been created and enabled. */
1348 signals[ACCOUNT_CREATED] =
1349 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1350 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1351 g_cclosure_marshal_VOID__VOID,
1355 signals[CANCELLED] =
1356 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1357 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1358 g_cclosure_marshal_VOID__VOID,
1362 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1366 empathy_account_widget_init (EmpathyAccountWidget *self)
1368 EmpathyAccountWidgetPriv *priv =
1369 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1370 EmpathyAccountWidgetPriv);
1373 priv->dispose_run = FALSE;
1375 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1378 /* public methods */
1381 empathy_account_widget_discard_pending_changes
1382 (EmpathyAccountWidget *widget)
1384 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1386 empathy_account_settings_discard_changes (priv->settings);
1387 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1388 priv->original_enabled_checkbox_value);
1389 priv->contains_pending_changes = FALSE;
1393 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
1395 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1397 return priv->contains_pending_changes;
1401 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1402 const gchar *first_widget,
1407 va_start (args, first_widget);
1408 account_widget_handle_params_valist (self, first_widget, args);
1413 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1415 return widget->ui_details->widget;
1418 EmpathyAccountWidget *
1419 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1422 EmpathyAccountWidget *self;
1424 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1427 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1428 "settings", settings, "simple", simple,
1430 empathy_account_settings_get_account (settings) == NULL,