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 /* An EmpathyAccountWidget can be used to either create an account or
65 * modify it. When we are creating an account, this member is set to TRUE */
66 gboolean creating_account;
69 } EmpathyAccountWidgetPriv;
85 static guint signals[LAST_SIGNAL] = { 0 };
87 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
88 #define CHANGED_TIMEOUT 300
91 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
94 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
98 gtk_widget_set_sensitive (priv->apply_button, sensitive);
99 gtk_widget_set_sensitive (priv->cancel_button, sensitive);
104 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
106 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
109 is_valid = empathy_account_settings_is_valid (priv->settings);
113 gtk_widget_set_sensitive (priv->apply_button, is_valid);
114 gtk_widget_set_sensitive (priv->cancel_button, is_valid);
117 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
121 account_widget_entry_changed_common (EmpathyAccountWidget *self,
122 GtkEntry *entry, gboolean focus)
125 const gchar *param_name;
126 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
128 str = gtk_entry_get_text (entry);
129 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
131 if (EMP_STR_EMPTY (str))
133 const gchar *value = NULL;
135 empathy_account_settings_unset (priv->settings, param_name);
139 value = empathy_account_settings_get_string (priv->settings,
141 DEBUG ("Unset %s and restore to %s", param_name, value);
142 gtk_entry_set_text (entry, value ? value : "");
147 DEBUG ("Setting %s to %s", param_name,
148 tp_strdiff (param_name, "password") ? str : "***");
149 empathy_account_settings_set_string (priv->settings, param_name, str);
154 account_widget_entry_focus_cb (GtkWidget *widget,
155 GdkEventFocus *event,
156 EmpathyAccountWidget *self)
158 account_widget_entry_changed_common (self, GTK_ENTRY (widget), TRUE);
164 account_widget_entry_changed_cb (GtkEditable *entry,
165 EmpathyAccountWidget *self)
167 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
168 account_widget_handle_control_buttons_sensitivity (self);
172 account_widget_int_changed_cb (GtkWidget *widget,
173 EmpathyAccountWidget *self)
175 const gchar *param_name;
177 const gchar *signature;
178 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
180 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
181 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
183 signature = empathy_account_settings_get_dbus_signature (priv->settings,
185 g_return_if_fail (signature != NULL);
187 DEBUG ("Setting %s to %d", param_name, value);
189 switch ((int)*signature)
191 case DBUS_TYPE_INT16:
192 case DBUS_TYPE_INT32:
193 empathy_account_settings_set_int32 (priv->settings, param_name, value);
195 case DBUS_TYPE_INT64:
196 empathy_account_settings_set_int64 (priv->settings, param_name, value);
198 case DBUS_TYPE_UINT16:
199 case DBUS_TYPE_UINT32:
200 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
202 case DBUS_TYPE_UINT64:
203 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
206 g_return_if_reached ();
209 account_widget_handle_control_buttons_sensitivity (self);
213 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
214 EmpathyAccountWidget *self)
217 gboolean default_value;
218 const gchar *param_name;
219 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
221 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
222 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
224 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
225 * always unset the param and set the value if different from the
227 empathy_account_settings_unset (priv->settings, param_name);
228 default_value = empathy_account_settings_get_boolean (priv->settings,
231 if (default_value == value)
233 DEBUG ("Unset %s and restore to %d", param_name, default_value);
237 DEBUG ("Setting %s to %d", param_name, value);
238 empathy_account_settings_set_boolean (priv->settings, param_name, value);
241 account_widget_handle_control_buttons_sensitivity (self);
245 account_widget_forget_clicked_cb (GtkWidget *button,
246 EmpathyAccountWidget *self)
248 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
249 const gchar *param_name;
251 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
254 DEBUG ("Unset %s", param_name);
255 empathy_account_settings_unset (priv->settings, param_name);
256 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
258 account_widget_handle_control_buttons_sensitivity (self);
262 account_widget_password_changed_cb (GtkWidget *entry,
263 EmpathyAccountWidget *self)
265 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
268 str = gtk_entry_get_text (GTK_ENTRY (entry));
269 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
273 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
274 EmpathyAccountWidget *self)
276 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
280 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
281 port = empathy_account_settings_get_uint32 (priv->settings, "port");
285 if (port == 5222 || port == 0)
290 if (port == 5223 || port == 0)
294 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
298 account_widget_setup_widget (EmpathyAccountWidget *self,
300 const gchar *param_name)
302 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
304 g_object_set_data_full (G_OBJECT (widget), "param_name",
305 g_strdup (param_name), g_free);
307 if (GTK_IS_SPIN_BUTTON (widget))
310 const gchar *signature;
312 signature = empathy_account_settings_get_dbus_signature (priv->settings,
314 g_return_if_fail (signature != NULL);
316 switch ((int)*signature)
318 case DBUS_TYPE_INT16:
319 case DBUS_TYPE_INT32:
320 value = empathy_account_settings_get_int32 (priv->settings,
323 case DBUS_TYPE_INT64:
324 value = empathy_account_settings_get_int64 (priv->settings,
327 case DBUS_TYPE_UINT16:
328 case DBUS_TYPE_UINT32:
329 value = empathy_account_settings_get_uint32 (priv->settings,
332 case DBUS_TYPE_UINT64:
333 value = empathy_account_settings_get_uint64 (priv->settings,
337 g_return_if_reached ();
340 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
342 g_signal_connect (widget, "value-changed",
343 G_CALLBACK (account_widget_int_changed_cb),
346 else if (GTK_IS_ENTRY (widget))
348 const gchar *str = NULL;
350 str = empathy_account_settings_get_string (priv->settings, param_name);
351 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
353 if (strstr (param_name, "password"))
355 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
358 g_signal_connect (widget, "focus-out-event",
359 G_CALLBACK (account_widget_entry_focus_cb),
361 g_signal_connect (widget, "changed",
362 G_CALLBACK (account_widget_entry_changed_cb), self);
364 else if (GTK_IS_TOGGLE_BUTTON (widget))
366 gboolean value = FALSE;
368 value = empathy_account_settings_get_boolean (priv->settings,
370 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
372 g_signal_connect (widget, "toggled",
373 G_CALLBACK (account_widget_checkbutton_toggled_cb),
378 DEBUG ("Unknown type of widget for param %s", param_name);
383 account_widget_generic_format_param_name (const gchar *param_name)
388 str = g_strdup (param_name);
390 if (str && g_ascii_isalpha (str[0]))
391 str[0] = g_ascii_toupper (str[0]);
393 while ((p = strchr (str, '-')) != NULL)
395 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
398 p[1] = g_ascii_toupper (p[1]);
408 accounts_widget_generic_setup (EmpathyAccountWidget *self,
409 GtkWidget *table_common_settings,
410 GtkWidget *table_advanced_settings)
412 TpConnectionManagerParam *params, *param;
413 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
415 params = empathy_account_settings_get_tp_params (priv->settings);
417 for (param = params; param != NULL && param->name != NULL; param++)
419 GtkWidget *table_settings;
421 GtkWidget *widget = NULL;
422 gchar *param_name_formatted;
424 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
425 table_settings = table_common_settings;
426 else if (priv->simple)
429 table_settings = table_advanced_settings;
431 param_name_formatted = account_widget_generic_format_param_name
433 g_object_get (table_settings, "n-rows", &n_rows, NULL);
434 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
436 if (param->dbus_signature[0] == 's')
440 str = g_strdup_printf (_("%s:"), param_name_formatted);
441 widget = gtk_label_new (str);
442 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
445 gtk_table_attach (GTK_TABLE (table_settings),
451 gtk_widget_show (widget);
453 widget = gtk_entry_new ();
454 if (strcmp (param->name, "account") == 0)
456 g_signal_connect (widget, "realize",
457 G_CALLBACK (gtk_widget_grab_focus),
460 gtk_table_attach (GTK_TABLE (table_settings),
464 GTK_FILL | GTK_EXPAND, 0,
466 gtk_widget_show (widget);
468 /* int types: ynqiuxt. double type is 'd' */
469 else if (param->dbus_signature[0] == 'y' ||
470 param->dbus_signature[0] == 'n' ||
471 param->dbus_signature[0] == 'q' ||
472 param->dbus_signature[0] == 'i' ||
473 param->dbus_signature[0] == 'u' ||
474 param->dbus_signature[0] == 'x' ||
475 param->dbus_signature[0] == 't' ||
476 param->dbus_signature[0] == 'd')
483 switch (param->dbus_signature[0])
485 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
486 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
487 case 'q': minint = 0; maxint = G_MAXUINT16; break;
488 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
489 case 'u': minint = 0; maxint = G_MAXUINT32; break;
490 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
491 case 't': minint = 0; maxint = G_MAXUINT64; break;
492 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
496 str = g_strdup_printf (_("%s:"), param_name_formatted);
497 widget = gtk_label_new (str);
498 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
501 gtk_table_attach (GTK_TABLE (table_settings),
507 gtk_widget_show (widget);
509 widget = gtk_spin_button_new_with_range (minint, maxint, step);
510 gtk_table_attach (GTK_TABLE (table_settings),
514 GTK_FILL | GTK_EXPAND, 0,
516 gtk_widget_show (widget);
518 else if (param->dbus_signature[0] == 'b')
520 widget = gtk_check_button_new_with_label (param_name_formatted);
521 gtk_table_attach (GTK_TABLE (table_settings),
525 GTK_FILL | GTK_EXPAND, 0,
527 gtk_widget_show (widget);
531 DEBUG ("Unknown signature for param %s: %s",
532 param_name_formatted, param->dbus_signature);
536 account_widget_setup_widget (self, widget, param->name);
538 g_free (param_name_formatted);
543 account_widget_handle_params_valist (EmpathyAccountWidget *self,
544 const gchar *first_widget,
550 for (name = first_widget; name; name = va_arg (args, const gchar *))
552 const gchar *param_name;
554 param_name = va_arg (args, const gchar *);
555 object = gtk_builder_get_object (self->ui_details->gui, name);
559 g_warning ("Builder is missing object '%s'.", name);
563 account_widget_setup_widget (self, GTK_WIDGET (object), param_name);
568 account_widget_cancel_clicked_cb (GtkWidget *button,
569 EmpathyAccountWidget *self)
571 g_signal_emit (self, signals[CANCELLED], 0);
575 account_widget_account_enabled_cb (GObject *source_object,
579 GError *error = NULL;
580 EmpathyAccount *account = EMPATHY_ACCOUNT (source_object);
581 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
583 empathy_account_set_enabled_finish (account, res, &error);
587 DEBUG ("Could not automatically enable new account: %s", error->message);
588 g_error_free (error);
592 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
597 account_widget_applied_cb (GObject *source_object,
601 GError *error = NULL;
602 EmpathyAccount *account;
603 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
604 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
605 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
607 empathy_account_settings_apply_finish (settings, res, &error);
611 DEBUG ("Could not apply changes to account: %s", error->message);
612 g_error_free (error);
616 account = empathy_account_settings_get_account (priv->settings);
620 if (priv->creating_account)
622 /* By default, when an account is created, we enable it. */
623 empathy_account_set_enabled_async (account, TRUE,
624 account_widget_account_enabled_cb, widget);
626 else if (priv->enabled_checkbox != NULL)
628 gboolean enabled_checked;
630 enabled_checked = gtk_toggle_button_get_active (
631 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
633 if (empathy_account_is_enabled (account) && enabled_checked)
635 /* After having applied changes to a user account, we
636 * automatically reconnect it. This is done so the new
637 * information entered by the user is validated on the server. */
638 empathy_account_reconnect_async (account, NULL, NULL);
642 /* The account is disabled so we enable it according to the value
643 * of the "Enabled" checkbox */
644 empathy_account_set_enabled_async (account, enabled_checked,
650 account_widget_set_control_buttons_sensitivity (widget, FALSE);
654 account_widget_apply_clicked_cb (GtkWidget *button,
655 EmpathyAccountWidget *self)
657 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
659 empathy_account_settings_apply_async (priv->settings,
660 account_widget_applied_cb, self);
664 account_widget_setup_generic (EmpathyAccountWidget *self)
666 GtkWidget *table_common_settings;
667 GtkWidget *table_advanced_settings;
669 table_common_settings = GTK_WIDGET (gtk_builder_get_object
670 (self->ui_details->gui, "table_common_settings"));
671 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
672 (self->ui_details->gui, "table_advanced_settings"));
674 accounts_widget_generic_setup (self, table_common_settings,
675 table_advanced_settings);
677 g_object_unref (self->ui_details->gui);
681 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
685 EmpathyAccountWidget *self = user_data;
686 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
688 if (empathy_account_settings_is_ready (priv->settings))
689 account_widget_setup_generic (self);
693 account_widget_build_generic (EmpathyAccountWidget *self,
694 const char *filename)
696 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
697 GtkWidget *expander_advanced;
699 self->ui_details->gui = empathy_builder_get_file (filename,
700 "table_common_settings", &priv->table_common_settings,
701 "vbox_generic_settings", &self->ui_details->widget,
702 "expander_advanced_settings", &expander_advanced,
706 gtk_widget_hide (expander_advanced);
708 g_object_ref (self->ui_details->gui);
710 if (empathy_account_settings_is_ready (priv->settings))
711 account_widget_setup_generic (self);
713 g_signal_connect (priv->settings, "notify::ready",
714 G_CALLBACK (account_widget_settings_ready_cb), self);
718 account_widget_build_salut (EmpathyAccountWidget *self,
719 const char *filename)
721 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
723 self->ui_details->gui = empathy_builder_get_file (filename,
724 "table_common_settings", &priv->table_common_settings,
725 "vbox_salut_settings", &self->ui_details->widget,
728 empathy_account_widget_handle_params (self,
729 "entry_published", "published-name",
730 "entry_nickname", "nickname",
731 "entry_first_name", "first-name",
732 "entry_last_name", "last-name",
733 "entry_email", "email",
737 self->ui_details->default_focus = g_strdup ("entry_nickname");
741 account_widget_build_irc (EmpathyAccountWidget *self,
742 const char *filename)
744 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
745 empathy_account_widget_irc_build (self, filename,
746 &priv->table_common_settings);
750 account_widget_build_sip (EmpathyAccountWidget *self,
751 const char *filename)
753 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
754 empathy_account_widget_sip_build (self, filename,
755 &priv->table_common_settings);
759 account_widget_build_msn (EmpathyAccountWidget *self,
760 const char *filename)
762 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
766 self->ui_details->gui = empathy_builder_get_file (filename,
767 "vbox_msn_simple", &self->ui_details->widget,
770 empathy_account_widget_handle_params (self,
771 "entry_id_simple", "account",
772 "entry_password_simple", "password",
775 self->ui_details->default_focus = g_strdup ("entry_id_simple");
779 self->ui_details->gui = empathy_builder_get_file (filename,
780 "table_common_msn_settings", &priv->table_common_settings,
781 "vbox_msn_settings", &self->ui_details->widget,
784 empathy_account_widget_handle_params (self,
785 "entry_id", "account",
786 "entry_password", "password",
787 "entry_server", "server",
788 "spinbutton_port", "port",
791 self->ui_details->default_focus = g_strdup ("entry_id");
792 self->ui_details->add_forget = TRUE;
797 account_widget_build_jabber (EmpathyAccountWidget *self,
798 const char *filename)
800 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
801 GtkWidget *spinbutton_port;
802 GtkWidget *checkbutton_ssl;
803 GtkWidget *label_id, *label_password;
804 GtkWidget *label_id_create, *label_password_create;
808 self->ui_details->gui = empathy_builder_get_file (filename,
809 "vbox_jabber_simple", &self->ui_details->widget,
810 "label_id_simple", &label_id,
811 "label_id_create", &label_id_create,
812 "label_password_simple", &label_password,
813 "label_password_create", &label_password_create,
816 if (empathy_account_settings_get_boolean (priv->settings, "register"))
818 gtk_widget_hide (label_id);
819 gtk_widget_hide (label_password);
820 gtk_widget_show (label_id_create);
821 gtk_widget_show (label_password_create);
824 empathy_account_widget_handle_params (self,
825 "entry_id_simple", "account",
826 "entry_password_simple", "password",
829 self->ui_details->default_focus = g_strdup ("entry_id_simple");
833 self->ui_details->gui = empathy_builder_get_file (filename,
834 "table_common_settings", &priv->table_common_settings,
835 "vbox_jabber_settings", &self->ui_details->widget,
836 "spinbutton_port", &spinbutton_port,
837 "checkbutton_ssl", &checkbutton_ssl,
840 empathy_account_widget_handle_params (self,
841 "entry_id", "account",
842 "entry_password", "password",
843 "entry_resource", "resource",
844 "entry_server", "server",
845 "spinbutton_port", "port",
846 "spinbutton_priority", "priority",
847 "checkbutton_ssl", "old-ssl",
848 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
849 "checkbutton_encryption", "require-encryption",
852 self->ui_details->default_focus = g_strdup ("entry_id");
853 self->ui_details->add_forget = TRUE;
854 priv->spinbutton_port = spinbutton_port;
856 g_signal_connect (checkbutton_ssl, "toggled",
857 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
863 account_widget_build_icq (EmpathyAccountWidget *self,
864 const char *filename)
866 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
867 GtkWidget *spinbutton_port;
871 self->ui_details->gui = empathy_builder_get_file (filename,
872 "vbox_icq_simple", &self->ui_details->widget,
875 empathy_account_widget_handle_params (self,
876 "entry_uin_simple", "account",
877 "entry_password_simple", "password",
880 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
884 self->ui_details->gui = empathy_builder_get_file (filename,
885 "table_common_settings", &priv->table_common_settings,
886 "vbox_icq_settings", &self->ui_details->widget,
887 "spinbutton_port", &spinbutton_port,
890 empathy_account_widget_handle_params (self,
891 "entry_uin", "account",
892 "entry_password", "password",
893 "entry_server", "server",
894 "spinbutton_port", "port",
895 "entry_charset", "charset",
898 self->ui_details->default_focus = g_strdup ("entry_uin");
899 self->ui_details->add_forget = TRUE;
904 account_widget_build_aim (EmpathyAccountWidget *self,
905 const char *filename)
907 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
908 GtkWidget *spinbutton_port;
912 self->ui_details->gui = empathy_builder_get_file (filename,
913 "vbox_aim_simple", &self->ui_details->widget,
916 empathy_account_widget_handle_params (self,
917 "entry_screenname_simple", "account",
918 "entry_password_simple", "password",
921 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
925 self->ui_details->gui = empathy_builder_get_file (filename,
926 "table_common_settings", &priv->table_common_settings,
927 "vbox_aim_settings", &self->ui_details->widget,
928 "spinbutton_port", &spinbutton_port,
931 empathy_account_widget_handle_params (self,
932 "entry_screenname", "account",
933 "entry_password", "password",
934 "entry_server", "server",
935 "spinbutton_port", "port",
938 self->ui_details->default_focus = g_strdup ("entry_screenname");
939 self->ui_details->add_forget = TRUE;
944 account_widget_build_yahoo (EmpathyAccountWidget *self,
945 const char *filename)
947 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
951 self->ui_details->gui = empathy_builder_get_file (filename,
952 "vbox_yahoo_simple", &self->ui_details->widget,
955 empathy_account_widget_handle_params (self,
956 "entry_id_simple", "account",
957 "entry_password_simple", "password",
960 self->ui_details->default_focus = g_strdup ("entry_id_simple");
964 self->ui_details->gui = empathy_builder_get_file (filename,
965 "table_common_settings", &priv->table_common_settings,
966 "vbox_yahoo_settings", &self->ui_details->widget,
969 empathy_account_widget_handle_params (self,
970 "entry_id", "account",
971 "entry_password", "password",
972 "entry_server", "server",
973 "entry_locale", "room-list-locale",
974 "entry_charset", "charset",
975 "spinbutton_port", "port",
976 "checkbutton_yahoojp", "yahoojp",
977 "checkbutton_ignore_invites", "ignore-invites",
980 self->ui_details->default_focus = g_strdup ("entry_id");
981 self->ui_details->add_forget = TRUE;
986 account_widget_build_groupwise (EmpathyAccountWidget *self,
987 const char *filename)
989 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
993 self->ui_details->gui = empathy_builder_get_file (filename,
994 "vbox_groupwise_simple", &self->ui_details->widget,
997 empathy_account_widget_handle_params (self,
998 "entry_id_simple", "account",
999 "entry_password_simple", "password",
1002 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1006 self->ui_details->gui = empathy_builder_get_file (filename,
1007 "table_common_groupwise_settings", &priv->table_common_settings,
1008 "vbox_groupwise_settings", &self->ui_details->widget,
1011 empathy_account_widget_handle_params (self,
1012 "entry_id", "account",
1013 "entry_password", "password",
1014 "entry_server", "server",
1015 "spinbutton_port", "port",
1018 self->ui_details->default_focus = g_strdup ("entry_id");
1019 self->ui_details->add_forget = TRUE;
1024 account_widget_destroy_cb (GtkWidget *widget,
1025 EmpathyAccountWidget *self)
1027 g_object_unref (self);
1031 empathy_account_widget_enabled_cb (EmpathyAccount *account,
1035 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1036 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1037 gboolean enabled = empathy_account_is_enabled (account);
1039 if (priv->enabled_checkbox != NULL)
1041 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1047 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1050 account_widget_handle_control_buttons_sensitivity (
1051 EMPATHY_ACCOUNT_WIDGET (user_data));
1055 do_set_property (GObject *object,
1057 const GValue *value,
1060 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1065 priv->settings = g_value_dup_object (value);
1068 priv->simple = g_value_get_boolean (value);
1070 case PROP_CREATING_ACCOUNT:
1071 priv->creating_account = g_value_get_boolean (value);
1074 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1079 do_get_property (GObject *object,
1084 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1089 g_value_set_string (value,
1090 empathy_account_settings_get_protocol (priv->settings));
1093 g_value_set_object (value, priv->settings);
1096 g_value_set_boolean (value, priv->simple);
1098 case PROP_CREATING_ACCOUNT:
1099 g_value_set_boolean (value, priv->creating_account);
1102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1106 #define WIDGET(cm, proto) \
1107 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1108 account_widget_build_##proto }
1111 do_constructed (GObject *obj)
1113 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1114 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1115 EmpathyAccount *account;
1116 const gchar *protocol, *cm_name;
1119 const gchar *cm_name;
1120 const gchar *protocol;
1122 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1124 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1125 account_widget_build_salut },
1126 WIDGET (gabble, jabber),
1127 WIDGET (butterfly, msn),
1130 WIDGET (haze, yahoo),
1131 WIDGET (haze, groupwise),
1133 WIDGET (sofiasip, sip),
1136 cm_name = empathy_account_settings_get_cm (priv->settings);
1137 protocol = empathy_account_settings_get_protocol (priv->settings);
1139 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1141 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1142 !tp_strdiff (widgets[i].protocol, protocol))
1146 filename = empathy_file_lookup (widgets[i].file,
1148 widgets[i].func (self, filename);
1155 if (i == G_N_ELEMENTS (widgets))
1157 gchar *filename = empathy_file_lookup (
1158 "empathy-account-widget-generic.ui", "libempathy-gtk");
1159 account_widget_build_generic (self, filename);
1163 /* handle default focus */
1164 if (self->ui_details->default_focus != NULL)
1166 GObject *default_focus_entry;
1168 default_focus_entry = gtk_builder_get_object
1169 (self->ui_details->gui, self->ui_details->default_focus);
1170 g_signal_connect (default_focus_entry, "realize",
1171 G_CALLBACK (gtk_widget_grab_focus),
1175 /* handle forget button */
1176 if (self->ui_details->add_forget)
1178 const gchar *password = NULL;
1180 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1181 (self->ui_details->gui, "button_forget"));
1182 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1183 (self->ui_details->gui, "entry_password"));
1185 password = empathy_account_settings_get_string (priv->settings,
1187 gtk_widget_set_sensitive (priv->button_forget,
1188 !EMP_STR_EMPTY (password));
1190 g_signal_connect (priv->button_forget, "clicked",
1191 G_CALLBACK (account_widget_forget_clicked_cb),
1193 g_signal_connect (priv->entry_password, "changed",
1194 G_CALLBACK (account_widget_password_changed_cb),
1198 /* handle apply and cancel button */
1201 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1203 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1204 priv->apply_button = gtk_button_new_from_stock (
1205 priv->creating_account ? GTK_STOCK_CONNECT : GTK_STOCK_APPLY);
1207 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1209 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1212 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1215 g_signal_connect (priv->cancel_button, "clicked",
1216 G_CALLBACK (account_widget_cancel_clicked_cb),
1218 g_signal_connect (priv->apply_button, "clicked",
1219 G_CALLBACK (account_widget_apply_clicked_cb),
1221 gtk_widget_show_all (hbox);
1222 account_widget_set_control_buttons_sensitivity (self, FALSE);
1225 account = empathy_account_settings_get_account (priv->settings);
1227 if (account != NULL)
1229 g_signal_connect (account, "notify::enabled",
1230 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1233 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1234 if (!priv->creating_account && priv->table_common_settings != NULL)
1236 guint nb_rows, nb_columns;
1238 priv->enabled_checkbox =
1239 gtk_check_button_new_with_label (_("Enabled"));
1240 gtk_toggle_button_set_active (
1241 GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1242 empathy_account_is_enabled (account));
1244 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1245 "n-columns", &nb_columns, NULL);
1247 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1250 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1251 priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows,
1252 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1254 gtk_widget_show (priv->enabled_checkbox);
1256 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
1257 G_CALLBACK (account_widget_enabled_toggled_cb), self);
1260 /* hook up to widget destruction to unref ourselves */
1261 g_signal_connect (self->ui_details->widget, "destroy",
1262 G_CALLBACK (account_widget_destroy_cb), self);
1264 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1265 self->ui_details->widget);
1266 self->ui_details->gui = NULL;
1270 do_dispose (GObject *obj)
1272 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1273 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1275 if (priv->dispose_run)
1278 priv->dispose_run = TRUE;
1280 empathy_account_settings_is_ready (priv->settings);
1282 if (priv->settings != NULL)
1284 EmpathyAccount *account;
1285 account = empathy_account_settings_get_account (priv->settings);
1287 if (account != NULL)
1289 g_signal_handlers_disconnect_by_func (account,
1290 empathy_account_widget_enabled_cb, self);
1293 g_object_unref (priv->settings);
1294 priv->settings = NULL;
1297 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1298 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1302 do_finalize (GObject *obj)
1304 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1306 g_free (self->ui_details->default_focus);
1307 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1309 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1310 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1314 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1316 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1317 GParamSpec *param_spec;
1319 oclass->get_property = do_get_property;
1320 oclass->set_property = do_set_property;
1321 oclass->constructed = do_constructed;
1322 oclass->dispose = do_dispose;
1323 oclass->finalize = do_finalize;
1325 param_spec = g_param_spec_string ("protocol",
1326 "protocol", "The protocol of the account",
1328 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1329 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1331 param_spec = g_param_spec_object ("settings",
1332 "settings", "The settings of the account",
1333 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1334 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1335 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1337 param_spec = g_param_spec_boolean ("simple",
1338 "simple", "Whether the account widget is a simple or an advanced one",
1340 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1341 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1343 param_spec = g_param_spec_boolean ("creating-account",
1345 "TRUE if we're creating an account, FALSE if we're modifying it",
1347 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1348 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1350 signals[HANDLE_APPLY] =
1351 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1352 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1353 g_cclosure_marshal_VOID__BOOLEAN,
1357 /* This signal is emitted when an account has been created and enabled. */
1358 signals[ACCOUNT_CREATED] =
1359 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1360 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1361 g_cclosure_marshal_VOID__VOID,
1365 signals[CANCELLED] =
1366 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1367 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1368 g_cclosure_marshal_VOID__VOID,
1372 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1376 empathy_account_widget_init (EmpathyAccountWidget *self)
1378 EmpathyAccountWidgetPriv *priv =
1379 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1380 EmpathyAccountWidgetPriv);
1383 priv->dispose_run = FALSE;
1385 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1388 /* public methods */
1391 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1392 const gchar *first_widget,
1397 va_start (args, first_widget);
1398 account_widget_handle_params_valist (self, first_widget, args);
1403 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1405 return widget->ui_details->widget;
1408 EmpathyAccountWidget *
1409 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1412 EmpathyAccountWidget *self;
1414 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1417 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1418 "settings", settings, "simple", simple,
1420 empathy_account_settings_get_account (settings) == NULL,