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>
34 #include <mx/mx-gtk.h>
35 #endif /* HAVE_MEEGO */
37 #include <libempathy/empathy-utils.h>
39 #include <telepathy-glib/account.h>
40 #include <telepathy-glib/account-manager.h>
41 #include <telepathy-glib/connection-manager.h>
42 #include <telepathy-glib/util.h>
43 #include <dbus/dbus-protocol.h>
45 #include "empathy-account-widget.h"
46 #include "empathy-account-widget-private.h"
47 #include "empathy-account-widget-sip.h"
48 #include "empathy-account-widget-irc.h"
49 #include "empathy-ui-utils.h"
51 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
52 #include <libempathy/empathy-debug.h>
54 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT)
57 EmpathyAccountSettings *settings;
59 GtkWidget *table_common_settings;
60 GtkWidget *apply_button;
61 GtkWidget *cancel_button;
62 GtkWidget *entry_password;
63 GtkWidget *button_forget;
64 GtkWidget *spinbutton_port;
65 GtkWidget *enabled_checkbox;
66 GtkWidget *radiobutton_reuse;
70 gboolean contains_pending_changes;
72 /* An EmpathyAccountWidget can be used to either create an account or
73 * modify it. When we are creating an account, this member is set to TRUE */
74 gboolean creating_account;
76 /* whether there are any other real accounts. Necessary so we know whether
77 * it's safe to dismiss this widget in some cases (eg, whether the Cancel
78 * button should be sensitive) */
79 gboolean other_accounts_exist;
81 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
82 * embedded in this account widget can't be used any more
83 * workaround because some async callbacks can be called after the
84 * widget has been destroyed */
87 TpAccountManager *account_manager;
89 GtkWidget *param_account_widget;
90 GtkWidget *param_password_widget;
93 } EmpathyAccountWidgetPriv;
99 PROP_CREATING_ACCOUNT,
100 PROP_OTHER_ACCOUNTS_EXIST,
110 static guint signals[LAST_SIGNAL] = { 0 };
112 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
113 #define CHANGED_TIMEOUT 300
116 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
119 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
123 /* we hit this case because of the 'other-accounts-exist' property handler
124 * being called during init (before constructed()) */
125 if (priv->apply_button == NULL || priv->cancel_button == NULL)
128 gtk_widget_set_sensitive (priv->apply_button, sensitive);
129 gtk_widget_set_sensitive (priv->cancel_button,
130 (sensitive || priv->creating_account) && priv->other_accounts_exist);
135 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
137 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
140 is_valid = empathy_account_settings_is_valid (priv->settings);
143 account_widget_set_control_buttons_sensitivity (self, is_valid);
145 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
149 account_widget_entry_changed_common (EmpathyAccountWidget *self,
150 GtkEntry *entry, gboolean focus)
153 const gchar *param_name;
154 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
156 str = gtk_entry_get_text (entry);
157 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
159 if (EMP_STR_EMPTY (str))
161 const gchar *value = NULL;
163 empathy_account_settings_unset (priv->settings, param_name);
167 value = empathy_account_settings_get_string (priv->settings,
169 DEBUG ("Unset %s and restore to %s", param_name, value);
170 gtk_entry_set_text (entry, value ? value : "");
175 DEBUG ("Setting %s to %s", param_name,
176 tp_strdiff (param_name, "password") ? str : "***");
177 empathy_account_settings_set_string (priv->settings, param_name, str);
182 account_widget_entry_changed_cb (GtkEditable *entry,
183 EmpathyAccountWidget *self)
185 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
186 empathy_account_widget_changed (self);
190 account_widget_int_changed_cb (GtkWidget *widget,
191 EmpathyAccountWidget *self)
193 const gchar *param_name;
195 const gchar *signature;
196 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
198 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
199 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
201 signature = empathy_account_settings_get_dbus_signature (priv->settings,
203 g_return_if_fail (signature != NULL);
205 DEBUG ("Setting %s to %d", param_name, value);
207 switch ((int)*signature)
209 case DBUS_TYPE_INT16:
210 case DBUS_TYPE_INT32:
211 empathy_account_settings_set_int32 (priv->settings, param_name, value);
213 case DBUS_TYPE_INT64:
214 empathy_account_settings_set_int64 (priv->settings, param_name, value);
216 case DBUS_TYPE_UINT16:
217 case DBUS_TYPE_UINT32:
218 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
220 case DBUS_TYPE_UINT64:
221 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
224 g_return_if_reached ();
227 empathy_account_widget_changed (self);
231 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
232 EmpathyAccountWidget *self)
235 gboolean default_value;
236 const gchar *param_name;
237 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
239 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
240 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
242 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
243 * always unset the param and set the value if different from the
245 empathy_account_settings_unset (priv->settings, param_name);
246 default_value = empathy_account_settings_get_boolean (priv->settings,
249 if (default_value == value)
251 DEBUG ("Unset %s and restore to %d", param_name, default_value);
255 DEBUG ("Setting %s to %d", param_name, value);
256 empathy_account_settings_set_boolean (priv->settings, param_name, value);
259 empathy_account_widget_changed (self);
263 account_widget_forget_clicked_cb (GtkWidget *button,
264 EmpathyAccountWidget *self)
266 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
267 const gchar *param_name;
269 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
272 DEBUG ("Unset %s", param_name);
273 empathy_account_settings_unset (priv->settings, param_name);
274 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
276 empathy_account_widget_changed (self);
280 account_widget_password_changed_cb (GtkWidget *entry,
281 EmpathyAccountWidget *self)
283 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
286 str = gtk_entry_get_text (GTK_ENTRY (entry));
287 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
289 priv->contains_pending_changes = TRUE;
293 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
294 EmpathyAccountWidget *self)
296 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
300 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
301 port = empathy_account_settings_get_uint32 (priv->settings, "port");
305 if (port == 5222 || port == 0)
310 if (port == 5223 || port == 0)
314 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
316 priv->contains_pending_changes = TRUE;
320 account_widget_combobox_changed_cb (GtkWidget *widget,
321 EmpathyAccountWidget *self)
327 const gchar *default_value = NULL;
328 const gchar *param_name;
329 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
331 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
334 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
335 /* the param value is stored in the first column */
336 gtk_tree_model_get (model, &iter, 0, &value, -1);
338 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
340 v = empathy_account_settings_get_default (priv->settings, param_name);
342 default_value = g_value_get_string (v);
344 if (!tp_strdiff (value, default_value))
346 DEBUG ("Unset %s and restore to %s", param_name, default_value);
347 empathy_account_settings_unset (priv->settings, param_name);
351 DEBUG ("Setting %s to %s", param_name, value);
352 empathy_account_settings_set_string (priv->settings, param_name, value);
355 empathy_account_widget_changed (self);
359 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
361 const gchar *param_name)
363 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
365 g_object_set_data_full (G_OBJECT (widget), "param_name",
366 g_strdup (param_name), g_free);
368 if (GTK_IS_SPIN_BUTTON (widget))
371 const gchar *signature;
373 signature = empathy_account_settings_get_dbus_signature (priv->settings,
375 g_return_if_fail (signature != NULL);
377 switch ((int)*signature)
379 case DBUS_TYPE_INT16:
380 case DBUS_TYPE_INT32:
381 value = empathy_account_settings_get_int32 (priv->settings,
384 case DBUS_TYPE_INT64:
385 value = empathy_account_settings_get_int64 (priv->settings,
388 case DBUS_TYPE_UINT16:
389 case DBUS_TYPE_UINT32:
390 value = empathy_account_settings_get_uint32 (priv->settings,
393 case DBUS_TYPE_UINT64:
394 value = empathy_account_settings_get_uint64 (priv->settings,
398 g_return_if_reached ();
401 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
403 g_signal_connect (widget, "value-changed",
404 G_CALLBACK (account_widget_int_changed_cb),
407 else if (GTK_IS_ENTRY (widget))
409 const gchar *str = NULL;
411 str = empathy_account_settings_get_string (priv->settings, param_name);
412 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
414 if (!tp_strdiff (param_name, "account"))
415 priv->param_account_widget = widget;
416 else if (!tp_strdiff (param_name, "password"))
417 priv->param_password_widget = widget;
419 if (strstr (param_name, "password"))
421 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
424 g_signal_connect (widget, "changed",
425 G_CALLBACK (account_widget_entry_changed_cb), self);
427 else if (GTK_IS_TOGGLE_BUTTON (widget))
429 gboolean value = FALSE;
431 value = empathy_account_settings_get_boolean (priv->settings,
433 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
435 g_signal_connect (widget, "toggled",
436 G_CALLBACK (account_widget_checkbutton_toggled_cb),
439 else if (GTK_IS_COMBO_BOX (widget))
441 /* The combo box's model has to contain the param value in its first
442 * column (as a string) */
448 str = empathy_account_settings_get_string (priv->settings, param_name);
449 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
451 valid = gtk_tree_model_get_iter_first (model, &iter);
456 gtk_tree_model_get (model, &iter, 0, &name, -1);
457 if (!tp_strdiff (name, str))
459 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
464 valid = gtk_tree_model_iter_next (model, &iter);
470 g_signal_connect (widget, "changed",
471 G_CALLBACK (account_widget_combobox_changed_cb),
476 DEBUG ("Unknown type of widget for param %s", param_name);
481 account_widget_generic_format_param_name (const gchar *param_name)
486 str = g_strdup (param_name);
488 if (str && g_ascii_isalpha (str[0]))
489 str[0] = g_ascii_toupper (str[0]);
491 while ((p = strchr (str, '-')) != NULL)
493 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
496 p[1] = g_ascii_toupper (p[1]);
506 accounts_widget_generic_setup (EmpathyAccountWidget *self,
507 GtkWidget *table_common_settings,
508 GtkWidget *table_advanced_settings)
510 TpConnectionManagerParam *params, *param;
511 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
513 params = empathy_account_settings_get_tp_params (priv->settings);
515 for (param = params; param != NULL && param->name != NULL; param++)
517 GtkWidget *table_settings;
519 GtkWidget *widget = NULL;
520 gchar *param_name_formatted;
522 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
523 table_settings = table_common_settings;
524 else if (priv->simple)
527 table_settings = table_advanced_settings;
529 param_name_formatted = account_widget_generic_format_param_name
531 g_object_get (table_settings, "n-rows", &n_rows, NULL);
532 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
534 if (param->dbus_signature[0] == 's')
538 str = g_strdup_printf (_("%s:"), param_name_formatted);
539 widget = gtk_label_new (str);
540 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
543 gtk_table_attach (GTK_TABLE (table_settings),
549 gtk_widget_show (widget);
551 widget = gtk_entry_new ();
552 if (strcmp (param->name, "account") == 0)
554 g_signal_connect (widget, "realize",
555 G_CALLBACK (gtk_widget_grab_focus),
558 gtk_table_attach (GTK_TABLE (table_settings),
562 GTK_FILL | GTK_EXPAND, 0,
564 gtk_widget_show (widget);
566 /* int types: ynqiuxt. double type is 'd' */
567 else if (param->dbus_signature[0] == 'y' ||
568 param->dbus_signature[0] == 'n' ||
569 param->dbus_signature[0] == 'q' ||
570 param->dbus_signature[0] == 'i' ||
571 param->dbus_signature[0] == 'u' ||
572 param->dbus_signature[0] == 'x' ||
573 param->dbus_signature[0] == 't' ||
574 param->dbus_signature[0] == 'd')
581 switch (param->dbus_signature[0])
583 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
584 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
585 case 'q': minint = 0; maxint = G_MAXUINT16; break;
586 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
587 case 'u': minint = 0; maxint = G_MAXUINT32; break;
588 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
589 case 't': minint = 0; maxint = G_MAXUINT64; break;
590 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
594 str = g_strdup_printf (_("%s:"), param_name_formatted);
595 widget = gtk_label_new (str);
596 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
599 gtk_table_attach (GTK_TABLE (table_settings),
605 gtk_widget_show (widget);
607 widget = gtk_spin_button_new_with_range (minint, maxint, step);
608 gtk_table_attach (GTK_TABLE (table_settings),
612 GTK_FILL | GTK_EXPAND, 0,
614 gtk_widget_show (widget);
616 else if (param->dbus_signature[0] == 'b')
618 widget = gtk_check_button_new_with_label (param_name_formatted);
619 gtk_table_attach (GTK_TABLE (table_settings),
623 GTK_FILL | GTK_EXPAND, 0,
625 gtk_widget_show (widget);
629 DEBUG ("Unknown signature for param %s: %s",
630 param_name_formatted, param->dbus_signature);
634 empathy_account_widget_setup_widget (self, widget, param->name);
636 g_free (param_name_formatted);
641 account_widget_handle_params_valist (EmpathyAccountWidget *self,
642 const gchar *first_widget,
648 for (name = first_widget; name; name = va_arg (args, const gchar *))
650 const gchar *param_name;
652 param_name = va_arg (args, const gchar *);
653 object = gtk_builder_get_object (self->ui_details->gui, name);
657 g_warning ("Builder is missing object '%s'.", name);
661 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
667 account_widget_cancel_clicked_cb (GtkWidget *button,
668 EmpathyAccountWidget *self)
670 g_signal_emit (self, signals[CANCELLED], 0);
674 account_widget_account_enabled_cb (GObject *source_object,
678 GError *error = NULL;
679 TpAccount *account = TP_ACCOUNT (source_object);
680 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
681 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
683 tp_account_set_enabled_finish (account, res, &error);
687 DEBUG ("Could not enable the account: %s", error->message);
688 g_error_free (error);
692 empathy_connect_new_account (account, priv->account_manager);
695 /* unref widget - part of the workaround */
696 g_object_unref (widget);
700 account_widget_applied_cb (GObject *source_object,
704 GError *error = NULL;
706 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
707 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
708 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
710 empathy_account_settings_apply_finish (settings, res, &error);
714 DEBUG ("Could not apply changes to account: %s", error->message);
715 g_error_free (error);
719 account = empathy_account_settings_get_account (priv->settings);
723 if (priv->creating_account)
725 /* By default, when an account is created, we enable it. */
727 /* workaround to keep widget alive during async call */
728 g_object_ref (widget);
730 tp_account_set_enabled_async (account, TRUE,
731 account_widget_account_enabled_cb, widget);
732 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
734 else if (priv->enabled_checkbox != NULL)
736 gboolean enabled_checked;
740 mx_gtk_light_switch_get_active (
741 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
743 gtk_toggle_button_get_active (
744 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
745 #endif /* HAVE_MEEGO */
747 if (tp_account_is_enabled (account) && enabled_checked)
749 /* After having applied changes to a user account, we
750 * automatically reconnect it. This is done so the new
751 * information entered by the user is validated on the server. */
752 tp_account_reconnect_async (account, NULL, NULL);
757 if (!priv->destroyed)
758 account_widget_set_control_buttons_sensitivity (widget, FALSE);
760 priv->contains_pending_changes = FALSE;
762 /* unref the widget - part of the workaround */
763 g_object_unref (widget);
767 account_widget_apply_clicked_cb (GtkWidget *button,
768 EmpathyAccountWidget *self)
770 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
771 gboolean display_name_overridden;
773 if (priv->radiobutton_reuse != NULL)
775 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
776 priv->radiobutton_reuse));
778 DEBUG ("Set register param: %d", !reuse);
779 empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
782 g_object_get (priv->settings,
783 "display-name-overridden", &display_name_overridden, NULL);
785 if (priv->creating_account || !display_name_overridden)
789 /* set default display name for new accounts or update if user didn't
790 * manually override it. */
791 display_name = empathy_account_widget_get_default_display_name (self);
793 empathy_account_settings_set_display_name_async (priv->settings,
794 display_name, NULL, NULL);
796 g_free (display_name);
799 /* workaround to keep widget alive during async call */
801 empathy_account_settings_apply_async (priv->settings,
802 account_widget_applied_cb, self);
806 account_widget_setup_generic (EmpathyAccountWidget *self)
808 GtkWidget *table_common_settings;
809 GtkWidget *table_advanced_settings;
811 table_common_settings = GTK_WIDGET (gtk_builder_get_object
812 (self->ui_details->gui, "table_common_settings"));
813 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
814 (self->ui_details->gui, "table_advanced_settings"));
816 accounts_widget_generic_setup (self, table_common_settings,
817 table_advanced_settings);
819 g_object_unref (self->ui_details->gui);
823 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
827 EmpathyAccountWidget *self = user_data;
828 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
830 if (empathy_account_settings_is_ready (priv->settings))
831 account_widget_setup_generic (self);
835 account_widget_build_generic (EmpathyAccountWidget *self,
836 const char *filename)
838 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
839 GtkWidget *expander_advanced;
841 self->ui_details->gui = empathy_builder_get_file (filename,
842 "table_common_settings", &priv->table_common_settings,
843 "vbox_generic_settings", &self->ui_details->widget,
844 "expander_advanced_settings", &expander_advanced,
848 gtk_widget_hide (expander_advanced);
850 g_object_ref (self->ui_details->gui);
852 if (empathy_account_settings_is_ready (priv->settings))
853 account_widget_setup_generic (self);
855 g_signal_connect (priv->settings, "notify::ready",
856 G_CALLBACK (account_widget_settings_ready_cb), self);
860 account_widget_build_salut (EmpathyAccountWidget *self,
861 const char *filename)
863 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
864 GtkWidget *expander_advanced;
866 self->ui_details->gui = empathy_builder_get_file (filename,
867 "table_common_settings", &priv->table_common_settings,
868 "vbox_salut_settings", &self->ui_details->widget,
869 "expander_advanced_settings", &expander_advanced,
872 empathy_account_widget_handle_params (self,
873 "entry_published", "published-name",
874 "entry_nickname", "nickname",
875 "entry_first_name", "first-name",
876 "entry_last_name", "last-name",
877 "entry_email", "email",
882 gtk_widget_hide (expander_advanced);
884 self->ui_details->default_focus = g_strdup ("entry_first_name");
888 account_widget_build_irc (EmpathyAccountWidget *self,
889 const char *filename)
891 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
892 empathy_account_widget_irc_build (self, filename,
893 &priv->table_common_settings);
897 account_widget_build_sip (EmpathyAccountWidget *self,
898 const char *filename)
900 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
901 empathy_account_widget_sip_build (self, filename,
902 &priv->table_common_settings);
906 account_widget_build_msn (EmpathyAccountWidget *self,
907 const char *filename)
909 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
913 self->ui_details->gui = empathy_builder_get_file (filename,
914 "vbox_msn_simple", &self->ui_details->widget,
917 empathy_account_widget_handle_params (self,
918 "entry_id_simple", "account",
919 "entry_password_simple", "password",
922 self->ui_details->default_focus = g_strdup ("entry_id_simple");
926 self->ui_details->gui = empathy_builder_get_file (filename,
927 "table_common_msn_settings", &priv->table_common_settings,
928 "vbox_msn_settings", &self->ui_details->widget,
931 empathy_account_widget_handle_params (self,
932 "entry_id", "account",
933 "entry_password", "password",
934 "entry_server", "server",
935 "spinbutton_port", "port",
938 self->ui_details->default_focus = g_strdup ("entry_id");
939 self->ui_details->add_forget = TRUE;
944 account_widget_is_gtalk (EmpathyAccountWidget *self)
946 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
948 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
953 account_widget_is_facebook (EmpathyAccountWidget *self)
955 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
957 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
961 #define FACEBOOK_SUFFIX "@chat.facebook.com"
964 facebook_id_widget_changed_cb (GtkWidget *entry,
965 EmpathyAccountWidget *self)
967 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
968 const gchar *account;
970 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
972 account = empathy_account_settings_get_string (priv->settings, "account");
973 if (!EMP_STR_EMPTY (account) &&
974 !g_str_has_suffix (account, FACEBOOK_SUFFIX))
978 tmp = g_strdup_printf ("%s%s", account, FACEBOOK_SUFFIX);
980 DEBUG ("Change account from '%s' to '%s'", account, tmp);
982 empathy_account_settings_set_string (priv->settings, "account", tmp);
986 empathy_account_widget_changed (self);
990 remove_facebook_suffix (const gchar *str)
992 if (!g_str_has_suffix (str, FACEBOOK_SUFFIX))
993 return g_strdup (str);
995 return g_strndup (str, strlen (str) - strlen (FACEBOOK_SUFFIX));
999 setup_facebook_id_widget (EmpathyAccountWidget *self,
1002 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1003 const gchar *str = NULL;
1005 g_object_set_data_full (G_OBJECT (widget), "param_name",
1006 g_strdup ("account"), g_free);
1008 str = empathy_account_settings_get_string (priv->settings, "account");
1013 tmp = remove_facebook_suffix (str);
1014 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1018 priv->param_account_widget = widget;
1020 g_signal_connect (widget, "changed",
1021 G_CALLBACK (facebook_id_widget_changed_cb), self);
1025 account_widget_build_jabber (EmpathyAccountWidget *self,
1026 const char *filename)
1028 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1029 GtkWidget *spinbutton_port;
1030 GtkWidget *checkbutton_ssl;
1031 GtkWidget *label_id, *label_password;
1032 GtkWidget *label_id_create, *label_password_create;
1033 GtkWidget *label_example_gtalk, *label_example_jabber, *label_example_fb;
1034 gboolean is_gtalk, is_facebook;
1035 GtkWidget *expander_advanced;
1036 GtkWidget *entry_id;
1038 is_gtalk = account_widget_is_gtalk (self);
1039 is_facebook = account_widget_is_facebook (self);
1041 if (priv->simple && !is_gtalk && !is_facebook)
1043 /* Simple widget for XMPP */
1044 self->ui_details->gui = empathy_builder_get_file (filename,
1045 "vbox_jabber_simple", &self->ui_details->widget,
1046 "label_id_simple", &label_id,
1047 "label_id_create", &label_id_create,
1048 "label_password_simple", &label_password,
1049 "label_password_create", &label_password_create,
1052 if (empathy_account_settings_get_boolean (priv->settings, "register"))
1054 gtk_widget_hide (label_id);
1055 gtk_widget_hide (label_password);
1056 gtk_widget_show (label_id_create);
1057 gtk_widget_show (label_password_create);
1060 empathy_account_widget_handle_params (self,
1061 "entry_id_simple", "account",
1062 "entry_password_simple", "password",
1065 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1067 else if (priv->simple && is_gtalk)
1069 /* Simple widget for Google Talk */
1070 self->ui_details->gui = empathy_builder_get_file (filename,
1071 "vbox_gtalk_simple", &self->ui_details->widget,
1074 empathy_account_widget_handle_params (self,
1075 "entry_id_g_simple", "account",
1076 "entry_password_g_simple", "password",
1079 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1081 else if (priv->simple && is_facebook)
1083 /* Simple widget for Facebook */
1084 self->ui_details->gui = empathy_builder_get_file (filename,
1085 "vbox_fb_simple", &self->ui_details->widget,
1086 "entry_id_fb_simple", &entry_id,
1089 empathy_account_widget_handle_params (self,
1090 "entry_password_fb_simple", "password",
1093 setup_facebook_id_widget (self, entry_id);
1095 self->ui_details->default_focus = g_strdup ("entry_id_fb_simple");
1099 /* Full widget for XMPP, Google Talk and Facebook*/
1100 self->ui_details->gui = empathy_builder_get_file (filename,
1101 "table_common_settings", &priv->table_common_settings,
1102 "vbox_jabber_settings", &self->ui_details->widget,
1103 "spinbutton_port", &spinbutton_port,
1104 "checkbutton_ssl", &checkbutton_ssl,
1105 "label_username_example", &label_example_jabber,
1106 "label_username_g_example", &label_example_gtalk,
1107 "label_username_f_example", &label_example_fb,
1108 "expander_advanced", &expander_advanced,
1109 "entry_id", &entry_id,
1110 "label_id", &label_id,
1113 empathy_account_widget_handle_params (self,
1114 "entry_password", "password",
1115 "entry_resource", "resource",
1116 "entry_server", "server",
1117 "spinbutton_port", "port",
1118 "spinbutton_priority", "priority",
1119 "checkbutton_ssl", "old-ssl",
1120 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1121 "checkbutton_encryption", "require-encryption",
1126 gtk_label_set_label (GTK_LABEL (label_id), _("Username:"));
1128 /* Facebook special case the entry ID widget to hide the
1129 * "@chat.facebook.com" part */
1130 setup_facebook_id_widget (self, entry_id);
1134 empathy_account_widget_setup_widget (self, entry_id, "account");
1137 self->ui_details->default_focus = g_strdup ("entry_id");
1138 self->ui_details->add_forget = TRUE;
1139 priv->spinbutton_port = spinbutton_port;
1141 g_signal_connect (checkbutton_ssl, "toggled",
1142 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1147 gtk_widget_hide (label_example_jabber);
1148 gtk_widget_show (label_example_gtalk);
1150 else if (is_facebook)
1152 gtk_widget_hide (label_example_jabber);
1153 gtk_widget_show (label_example_fb);
1154 gtk_widget_hide (expander_advanced);
1160 account_widget_build_icq (EmpathyAccountWidget *self,
1161 const char *filename)
1163 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1164 GtkWidget *spinbutton_port;
1168 self->ui_details->gui = empathy_builder_get_file (filename,
1169 "vbox_icq_simple", &self->ui_details->widget,
1172 empathy_account_widget_handle_params (self,
1173 "entry_uin_simple", "account",
1174 "entry_password_simple", "password",
1177 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1181 self->ui_details->gui = empathy_builder_get_file (filename,
1182 "table_common_settings", &priv->table_common_settings,
1183 "vbox_icq_settings", &self->ui_details->widget,
1184 "spinbutton_port", &spinbutton_port,
1187 empathy_account_widget_handle_params (self,
1188 "entry_uin", "account",
1189 "entry_password", "password",
1190 "entry_server", "server",
1191 "spinbutton_port", "port",
1192 "entry_charset", "charset",
1195 self->ui_details->default_focus = g_strdup ("entry_uin");
1196 self->ui_details->add_forget = TRUE;
1201 account_widget_build_aim (EmpathyAccountWidget *self,
1202 const char *filename)
1204 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1205 GtkWidget *spinbutton_port;
1209 self->ui_details->gui = empathy_builder_get_file (filename,
1210 "vbox_aim_simple", &self->ui_details->widget,
1213 empathy_account_widget_handle_params (self,
1214 "entry_screenname_simple", "account",
1215 "entry_password_simple", "password",
1218 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1222 self->ui_details->gui = empathy_builder_get_file (filename,
1223 "table_common_settings", &priv->table_common_settings,
1224 "vbox_aim_settings", &self->ui_details->widget,
1225 "spinbutton_port", &spinbutton_port,
1228 empathy_account_widget_handle_params (self,
1229 "entry_screenname", "account",
1230 "entry_password", "password",
1231 "entry_server", "server",
1232 "spinbutton_port", "port",
1235 self->ui_details->default_focus = g_strdup ("entry_screenname");
1236 self->ui_details->add_forget = TRUE;
1241 account_widget_build_yahoo (EmpathyAccountWidget *self,
1242 const char *filename)
1244 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1248 self->ui_details->gui = empathy_builder_get_file (filename,
1249 "vbox_yahoo_simple", &self->ui_details->widget,
1252 empathy_account_widget_handle_params (self,
1253 "entry_id_simple", "account",
1254 "entry_password_simple", "password",
1257 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1261 self->ui_details->gui = empathy_builder_get_file (filename,
1262 "table_common_settings", &priv->table_common_settings,
1263 "vbox_yahoo_settings", &self->ui_details->widget,
1266 empathy_account_widget_handle_params (self,
1267 "entry_id", "account",
1268 "entry_password", "password",
1269 "entry_server", "server",
1270 "entry_locale", "room-list-locale",
1271 "entry_charset", "charset",
1272 "spinbutton_port", "port",
1273 "checkbutton_yahoojp", "yahoojp",
1274 "checkbutton_ignore_invites", "ignore-invites",
1277 self->ui_details->default_focus = g_strdup ("entry_id");
1278 self->ui_details->add_forget = TRUE;
1283 account_widget_build_groupwise (EmpathyAccountWidget *self,
1284 const char *filename)
1286 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1290 self->ui_details->gui = empathy_builder_get_file (filename,
1291 "vbox_groupwise_simple", &self->ui_details->widget,
1294 empathy_account_widget_handle_params (self,
1295 "entry_id_simple", "account",
1296 "entry_password_simple", "password",
1299 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1303 self->ui_details->gui = empathy_builder_get_file (filename,
1304 "table_common_groupwise_settings", &priv->table_common_settings,
1305 "vbox_groupwise_settings", &self->ui_details->widget,
1308 empathy_account_widget_handle_params (self,
1309 "entry_id", "account",
1310 "entry_password", "password",
1311 "entry_server", "server",
1312 "spinbutton_port", "port",
1315 self->ui_details->default_focus = g_strdup ("entry_id");
1316 self->ui_details->add_forget = TRUE;
1321 account_widget_destroy_cb (GtkWidget *widget,
1322 EmpathyAccountWidget *self)
1324 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1325 /* set the destroyed flag - workaround */
1326 priv->destroyed = TRUE;
1328 g_object_unref (self);
1332 empathy_account_widget_enabled_cb (TpAccount *account,
1336 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1337 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1338 gboolean enabled = tp_account_is_enabled (account);
1340 if (priv->enabled_checkbox != NULL)
1343 mx_gtk_light_switch_set_active (
1344 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1347 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1349 #endif /* HAVE_MEEGO */
1355 account_widget_switch_flipped_cb (MxGtkLightSwitch *sw,
1359 account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
1361 #endif /* HAVE_MEEGO */
1363 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1368 state = gtk_toggle_button_get_active (toggle_button);
1369 #endif /* HAVE_MEEGO */
1371 account = empathy_account_settings_get_account (priv->settings);
1373 /* Enable the account according to the value of the "Enabled" checkbox */
1374 /* workaround to keep widget alive during async call */
1375 g_object_ref (user_data);
1376 tp_account_set_enabled_async (account, state,
1377 account_widget_account_enabled_cb, user_data);
1381 empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
1382 gboolean others_exist)
1384 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1386 priv->other_accounts_exist = others_exist;
1388 if (priv->creating_account)
1389 account_widget_handle_control_buttons_sensitivity (self);
1393 do_set_property (GObject *object,
1395 const GValue *value,
1398 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1403 priv->settings = g_value_dup_object (value);
1406 priv->simple = g_value_get_boolean (value);
1408 case PROP_CREATING_ACCOUNT:
1409 priv->creating_account = g_value_get_boolean (value);
1411 case PROP_OTHER_ACCOUNTS_EXIST:
1412 empathy_account_widget_set_other_accounts_exist (
1413 EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
1416 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1421 do_get_property (GObject *object,
1426 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1431 g_value_set_string (value,
1432 empathy_account_settings_get_protocol (priv->settings));
1435 g_value_set_object (value, priv->settings);
1438 g_value_set_boolean (value, priv->simple);
1440 case PROP_CREATING_ACCOUNT:
1441 g_value_set_boolean (value, priv->creating_account);
1443 case PROP_OTHER_ACCOUNTS_EXIST:
1444 g_value_set_boolean (value, priv->other_accounts_exist);
1447 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1452 presence_changed_cb (TpAccountManager *manager,
1453 TpConnectionPresenceType state,
1454 const gchar *status,
1455 const gchar *message,
1456 EmpathyAccountWidget *self)
1458 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1460 if (priv->destroyed)
1463 if (priv->apply_button == NULL)
1464 /* This button doesn't exist in 'simple' mode */
1467 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
1468 priv->creating_account)
1470 /* We are online and creating a new account, display a Login button */
1473 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1474 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1476 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1477 GTK_ICON_SIZE_BUTTON);
1478 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1482 /* We are offline or modifying an existing account, display
1484 gtk_button_set_image (GTK_BUTTON (priv->apply_button), NULL);
1485 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), TRUE);
1486 gtk_button_set_label (GTK_BUTTON (priv->apply_button), GTK_STOCK_APPLY);
1491 account_manager_ready_cb (GObject *source_object,
1492 GAsyncResult *result,
1495 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1496 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1497 GError *error = NULL;
1498 TpConnectionPresenceType state;
1500 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1502 DEBUG ("Failed to prepare account manager: %s", error->message);
1503 g_error_free (error);
1507 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1510 /* simulate a presence change so the apply button will be changed
1512 presence_changed_cb (account_manager, state, NULL, NULL, self);
1515 g_object_unref (self);
1518 #define WIDGET(cm, proto) \
1519 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1520 account_widget_build_##proto }
1523 add_enable_checkbox (EmpathyAccountWidget *self,
1526 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1530 GtkWidget *vbox = self->ui_details->widget;
1531 #endif /* HAVE_MEEGO */
1532 guint nb_rows, nb_columns;
1533 gboolean is_enabled;
1535 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1536 if (priv->creating_account || priv->table_common_settings == NULL)
1539 is_enabled = tp_account_is_enabled (account);
1542 w = gtk_label_new (_("Account:"));
1543 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1545 priv->enabled_checkbox = mx_gtk_light_switch_new ();
1547 mx_gtk_light_switch_set_active (
1548 MX_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1550 gtk_widget_show (w);
1552 priv->enabled_checkbox =
1553 gtk_check_button_new_with_label (_("Enabled"));
1555 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1557 #endif /* HAVE_MEEGO */
1559 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1560 "n-columns", &nb_columns, NULL);
1562 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1566 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1568 0, 1, nb_rows - 1, nb_rows,
1570 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1571 priv->enabled_checkbox,
1572 1, nb_columns, nb_rows - 1, nb_rows,
1573 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1575 gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
1576 gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
1577 #endif /* HAVE_MEEGO */
1579 gtk_widget_show (priv->enabled_checkbox);
1582 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1583 G_CALLBACK (account_widget_switch_flipped_cb), self);
1585 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
1586 G_CALLBACK (account_widget_enabled_released_cb), self);
1587 #endif /* HAVE_MEEGO */
1591 /* Meego doesn't support registration */
1593 add_register_buttons (EmpathyAccountWidget *self,
1596 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1597 const TpConnectionManagerProtocol *protocol;
1598 GtkWidget *radiobutton_register;
1599 GtkWidget *vbox = self->ui_details->widget;
1601 if (!priv->creating_account)
1604 protocol = empathy_account_settings_get_tp_protocol (priv->settings);
1605 if (protocol == NULL)
1608 if (!tp_connection_manager_protocol_can_register (protocol))
1611 if (account_widget_is_gtalk (self) || account_widget_is_facebook (self))
1617 priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1618 _("This account already exists on the server"));
1619 radiobutton_register = gtk_radio_button_new_with_label (
1620 gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
1621 _("Create a new account on the server"));
1623 gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
1624 gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
1625 gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
1626 gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
1627 gtk_widget_show (priv->radiobutton_reuse);
1628 gtk_widget_show (radiobutton_register);
1630 #endif /* HAVE_MEEGO */
1633 do_constructed (GObject *obj)
1635 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1636 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1638 const gchar *protocol, *cm_name;
1639 const gchar *display_name, *default_display_name;
1642 const gchar *cm_name;
1643 const gchar *protocol;
1645 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1647 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1648 account_widget_build_salut },
1649 WIDGET (gabble, jabber),
1650 WIDGET (butterfly, msn),
1653 WIDGET (haze, yahoo),
1654 WIDGET (haze, groupwise),
1656 WIDGET (sofiasip, sip),
1659 cm_name = empathy_account_settings_get_cm (priv->settings);
1660 protocol = empathy_account_settings_get_protocol (priv->settings);
1662 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1664 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1665 !tp_strdiff (widgets[i].protocol, protocol))
1669 filename = empathy_file_lookup (widgets[i].file,
1671 widgets[i].func (self, filename);
1678 if (i == G_N_ELEMENTS (widgets))
1680 gchar *filename = empathy_file_lookup (
1681 "empathy-account-widget-generic.ui", "libempathy-gtk");
1682 account_widget_build_generic (self, filename);
1686 /* handle default focus */
1687 if (self->ui_details->default_focus != NULL)
1689 GObject *default_focus_entry;
1691 default_focus_entry = gtk_builder_get_object
1692 (self->ui_details->gui, self->ui_details->default_focus);
1693 g_signal_connect (default_focus_entry, "realize",
1694 G_CALLBACK (gtk_widget_grab_focus),
1698 /* handle forget button */
1699 if (self->ui_details->add_forget)
1701 const gchar *password = NULL;
1703 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1704 (self->ui_details->gui, "button_forget"));
1705 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1706 (self->ui_details->gui, "entry_password"));
1708 password = empathy_account_settings_get_string (priv->settings,
1710 gtk_widget_set_sensitive (priv->button_forget,
1711 !EMP_STR_EMPTY (password));
1713 g_signal_connect (priv->button_forget, "clicked",
1714 G_CALLBACK (account_widget_forget_clicked_cb),
1716 g_signal_connect (priv->entry_password, "changed",
1717 G_CALLBACK (account_widget_password_changed_cb),
1721 /* dup and init the account-manager */
1722 priv->account_manager = tp_account_manager_dup ();
1724 g_object_ref (self);
1725 tp_account_manager_prepare_async (priv->account_manager, NULL,
1726 account_manager_ready_cb, self);
1728 /* handle apply and cancel button */
1731 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1733 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1735 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1737 /* We'll change this button to a "Log in" one if we are creating a new
1738 * account and are connected. */
1739 empathy_signal_connect_weak (priv->account_manager,
1740 "most-available-presence-changed",
1741 G_CALLBACK (presence_changed_cb), obj);
1743 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1745 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1748 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1751 g_signal_connect (priv->cancel_button, "clicked",
1752 G_CALLBACK (account_widget_cancel_clicked_cb),
1754 g_signal_connect (priv->apply_button, "clicked",
1755 G_CALLBACK (account_widget_apply_clicked_cb),
1757 gtk_widget_show_all (hbox);
1759 if (priv->creating_account)
1760 /* When creating an account, the user might have nothing to enter.
1761 * That means that no control interaction might occur,
1762 * so we update the control button sensitivity manually.
1764 account_widget_handle_control_buttons_sensitivity (self);
1766 account_widget_set_control_buttons_sensitivity (self, FALSE);
1769 account = empathy_account_settings_get_account (priv->settings);
1771 if (account != NULL)
1773 g_signal_connect (account, "notify::enabled",
1774 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1778 add_register_buttons (self, account);
1779 #endif /* HAVE_MEEGO */
1780 add_enable_checkbox (self, account);
1782 /* hook up to widget destruction to unref ourselves */
1783 g_signal_connect (self->ui_details->widget, "destroy",
1784 G_CALLBACK (account_widget_destroy_cb), self);
1786 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1787 self->ui_details->widget);
1788 self->ui_details->gui = NULL;
1790 display_name = empathy_account_settings_get_display_name (priv->settings);
1791 default_display_name = empathy_account_widget_get_default_display_name (self);
1793 if (tp_strdiff (display_name, default_display_name))
1795 /* The display name of the account is not the one that we'd assign by
1796 * default; assume that the user changed it manually */
1797 g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
1802 do_dispose (GObject *obj)
1804 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1805 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1807 if (priv->dispose_run)
1810 priv->dispose_run = TRUE;
1812 if (priv->settings != NULL)
1815 account = empathy_account_settings_get_account (priv->settings);
1817 if (account != NULL)
1819 g_signal_handlers_disconnect_by_func (account,
1820 empathy_account_widget_enabled_cb, self);
1823 g_object_unref (priv->settings);
1824 priv->settings = NULL;
1827 if (priv->account_manager != NULL)
1829 g_object_unref (priv->account_manager);
1830 priv->account_manager = NULL;
1833 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1834 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1838 do_finalize (GObject *obj)
1840 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1842 g_free (self->ui_details->default_focus);
1843 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1845 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1846 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1850 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1852 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1853 GParamSpec *param_spec;
1855 oclass->get_property = do_get_property;
1856 oclass->set_property = do_set_property;
1857 oclass->constructed = do_constructed;
1858 oclass->dispose = do_dispose;
1859 oclass->finalize = do_finalize;
1861 param_spec = g_param_spec_string ("protocol",
1862 "protocol", "The protocol of the account",
1864 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1865 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1867 param_spec = g_param_spec_object ("settings",
1868 "settings", "The settings of the account",
1869 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1870 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1871 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1873 param_spec = g_param_spec_boolean ("simple",
1874 "simple", "Whether the account widget is a simple or an advanced one",
1876 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1877 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1879 param_spec = g_param_spec_boolean ("creating-account",
1881 "TRUE if we're creating an account, FALSE if we're modifying it",
1883 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1884 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1886 param_spec = g_param_spec_boolean ("other-accounts-exist",
1887 "other-accounts-exist",
1888 "TRUE if there are any other accounts (even if this isn't yet saved)",
1890 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1891 g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
1894 signals[HANDLE_APPLY] =
1895 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1896 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1897 g_cclosure_marshal_VOID__BOOLEAN,
1901 /* This signal is emitted when an account has been created and enabled. */
1902 signals[ACCOUNT_CREATED] =
1903 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1904 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1905 g_cclosure_marshal_VOID__OBJECT,
1909 signals[CANCELLED] =
1910 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1911 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1912 g_cclosure_marshal_VOID__VOID,
1916 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1920 empathy_account_widget_init (EmpathyAccountWidget *self)
1922 EmpathyAccountWidgetPriv *priv =
1923 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1924 EmpathyAccountWidgetPriv);
1927 priv->dispose_run = FALSE;
1929 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1932 /* public methods */
1935 empathy_account_widget_discard_pending_changes
1936 (EmpathyAccountWidget *widget)
1938 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1940 empathy_account_settings_discard_changes (priv->settings);
1941 priv->contains_pending_changes = FALSE;
1945 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
1947 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1949 return priv->contains_pending_changes;
1953 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1954 const gchar *first_widget,
1959 va_start (args, first_widget);
1960 account_widget_handle_params_valist (self, first_widget, args);
1965 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1967 return widget->ui_details->widget;
1970 EmpathyAccountWidget *
1971 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1974 EmpathyAccountWidget *self;
1976 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1979 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1980 "settings", settings, "simple", simple,
1982 empathy_account_settings_get_account (settings) == NULL,
1989 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
1991 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1992 const gchar *login_id;
1993 const gchar *protocol, *p;
1994 gchar *default_display_name;
1996 login_id = empathy_account_settings_get_string (priv->settings, "account");
1997 protocol = empathy_account_settings_get_protocol (priv->settings);
1999 if (login_id != NULL)
2001 /* TODO: this should be done in empathy-account-widget-irc */
2002 if (!tp_strdiff (protocol, "irc"))
2004 const gchar* server;
2005 server = empathy_account_settings_get_string (priv->settings,
2008 /* To translators: The first parameter is the login id and the
2009 * second one is the server. The resulting string will be something
2010 * like: "MyUserName on chat.freenode.net".
2011 * You should reverse the order of these arguments if the
2012 * server should come before the login id in your locale.*/
2013 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
2016 else if (account_widget_is_facebook (self))
2020 tmp = remove_facebook_suffix (login_id);
2021 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
2026 default_display_name = g_strdup (login_id);
2029 return default_display_name;
2032 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
2035 if (protocol != NULL)
2037 /* To translators: The parameter is the protocol name. The resulting
2038 * string will be something like: "Jabber Account" */
2039 default_display_name = g_strdup_printf (_("%s Account"), protocol);
2043 default_display_name = g_strdup (_("New account"));
2046 return default_display_name;
2049 /* Used by subclass to indicate that widget contains pending changes */
2051 empathy_account_widget_changed (EmpathyAccountWidget *self)
2053 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2055 account_widget_handle_control_buttons_sensitivity (self);
2056 priv->contains_pending_changes = TRUE;
2060 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2061 const gchar *account)
2063 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2065 if (priv->param_account_widget == NULL)
2068 gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
2072 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2073 const gchar *account)
2075 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2077 if (priv->param_password_widget == NULL)
2080 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);