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 <nbtk/nbtk-gtk.h>
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 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
77 * embedded in this account widget can't be used any more
78 * workaround because some async callbacks can be called after the
79 * widget has been destroyed */
82 TpAccountManager *account_manager;
84 GtkWidget *param_account_widget;
85 GtkWidget *param_password_widget;
88 } EmpathyAccountWidgetPriv;
104 static guint signals[LAST_SIGNAL] = { 0 };
106 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
107 #define CHANGED_TIMEOUT 300
110 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
113 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
117 gtk_widget_set_sensitive (priv->apply_button, sensitive);
118 gtk_widget_set_sensitive (
119 priv->cancel_button, sensitive || priv->creating_account);
124 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
126 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
129 is_valid = empathy_account_settings_is_valid (priv->settings);
132 account_widget_set_control_buttons_sensitivity (self, is_valid);
134 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
138 account_widget_entry_changed_common (EmpathyAccountWidget *self,
139 GtkEntry *entry, gboolean focus)
142 const gchar *param_name;
143 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
145 str = gtk_entry_get_text (entry);
146 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
148 if (EMP_STR_EMPTY (str))
150 const gchar *value = NULL;
152 empathy_account_settings_unset (priv->settings, param_name);
156 value = empathy_account_settings_get_string (priv->settings,
158 DEBUG ("Unset %s and restore to %s", param_name, value);
159 gtk_entry_set_text (entry, value ? value : "");
164 DEBUG ("Setting %s to %s", param_name,
165 tp_strdiff (param_name, "password") ? str : "***");
166 empathy_account_settings_set_string (priv->settings, param_name, str);
171 account_widget_entry_changed_cb (GtkEditable *entry,
172 EmpathyAccountWidget *self)
174 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
175 empathy_account_widget_changed (self);
179 account_widget_int_changed_cb (GtkWidget *widget,
180 EmpathyAccountWidget *self)
182 const gchar *param_name;
184 const gchar *signature;
185 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
187 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
188 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
190 signature = empathy_account_settings_get_dbus_signature (priv->settings,
192 g_return_if_fail (signature != NULL);
194 DEBUG ("Setting %s to %d", param_name, value);
196 switch ((int)*signature)
198 case DBUS_TYPE_INT16:
199 case DBUS_TYPE_INT32:
200 empathy_account_settings_set_int32 (priv->settings, param_name, value);
202 case DBUS_TYPE_INT64:
203 empathy_account_settings_set_int64 (priv->settings, param_name, value);
205 case DBUS_TYPE_UINT16:
206 case DBUS_TYPE_UINT32:
207 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
209 case DBUS_TYPE_UINT64:
210 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
213 g_return_if_reached ();
216 empathy_account_widget_changed (self);
220 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
221 EmpathyAccountWidget *self)
224 gboolean default_value;
225 const gchar *param_name;
226 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
228 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
229 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
231 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
232 * always unset the param and set the value if different from the
234 empathy_account_settings_unset (priv->settings, param_name);
235 default_value = empathy_account_settings_get_boolean (priv->settings,
238 if (default_value == value)
240 DEBUG ("Unset %s and restore to %d", param_name, default_value);
244 DEBUG ("Setting %s to %d", param_name, value);
245 empathy_account_settings_set_boolean (priv->settings, param_name, value);
248 empathy_account_widget_changed (self);
252 account_widget_forget_clicked_cb (GtkWidget *button,
253 EmpathyAccountWidget *self)
255 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
256 const gchar *param_name;
258 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
261 DEBUG ("Unset %s", param_name);
262 empathy_account_settings_unset (priv->settings, param_name);
263 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
265 empathy_account_widget_changed (self);
269 account_widget_password_changed_cb (GtkWidget *entry,
270 EmpathyAccountWidget *self)
272 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
275 str = gtk_entry_get_text (GTK_ENTRY (entry));
276 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
278 priv->contains_pending_changes = TRUE;
282 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
283 EmpathyAccountWidget *self)
285 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
289 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
290 port = empathy_account_settings_get_uint32 (priv->settings, "port");
294 if (port == 5222 || port == 0)
299 if (port == 5223 || port == 0)
303 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
305 priv->contains_pending_changes = TRUE;
309 account_widget_combobox_changed_cb (GtkWidget *widget,
310 EmpathyAccountWidget *self)
316 const gchar *default_value = NULL;
317 const gchar *param_name;
318 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
320 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
323 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
324 /* the param value is stored in the first column */
325 gtk_tree_model_get (model, &iter, 0, &value, -1);
327 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
329 v = empathy_account_settings_get_default (priv->settings, param_name);
331 default_value = g_value_get_string (v);
333 if (!tp_strdiff (value, default_value))
335 DEBUG ("Unset %s and restore to %s", param_name, default_value);
336 empathy_account_settings_unset (priv->settings, param_name);
340 DEBUG ("Setting %s to %s", param_name, value);
341 empathy_account_settings_set_string (priv->settings, param_name, value);
344 empathy_account_widget_changed (self);
348 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
350 const gchar *param_name)
352 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
354 g_object_set_data_full (G_OBJECT (widget), "param_name",
355 g_strdup (param_name), g_free);
357 if (GTK_IS_SPIN_BUTTON (widget))
360 const gchar *signature;
362 signature = empathy_account_settings_get_dbus_signature (priv->settings,
364 g_return_if_fail (signature != NULL);
366 switch ((int)*signature)
368 case DBUS_TYPE_INT16:
369 case DBUS_TYPE_INT32:
370 value = empathy_account_settings_get_int32 (priv->settings,
373 case DBUS_TYPE_INT64:
374 value = empathy_account_settings_get_int64 (priv->settings,
377 case DBUS_TYPE_UINT16:
378 case DBUS_TYPE_UINT32:
379 value = empathy_account_settings_get_uint32 (priv->settings,
382 case DBUS_TYPE_UINT64:
383 value = empathy_account_settings_get_uint64 (priv->settings,
387 g_return_if_reached ();
390 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
392 g_signal_connect (widget, "value-changed",
393 G_CALLBACK (account_widget_int_changed_cb),
396 else if (GTK_IS_ENTRY (widget))
398 const gchar *str = NULL;
400 str = empathy_account_settings_get_string (priv->settings, param_name);
401 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
403 if (!tp_strdiff (param_name, "account"))
404 priv->param_account_widget = widget;
405 else if (!tp_strdiff (param_name, "password"))
406 priv->param_password_widget = widget;
408 if (strstr (param_name, "password"))
410 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
413 g_signal_connect (widget, "changed",
414 G_CALLBACK (account_widget_entry_changed_cb), self);
416 else if (GTK_IS_TOGGLE_BUTTON (widget))
418 gboolean value = FALSE;
420 value = empathy_account_settings_get_boolean (priv->settings,
422 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
424 g_signal_connect (widget, "toggled",
425 G_CALLBACK (account_widget_checkbutton_toggled_cb),
428 else if (GTK_IS_COMBO_BOX (widget))
430 /* The combo box's model has to contain the param value in its first
431 * column (as a string) */
437 str = empathy_account_settings_get_string (priv->settings, param_name);
438 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
440 valid = gtk_tree_model_get_iter_first (model, &iter);
445 gtk_tree_model_get (model, &iter, 0, &name, -1);
446 if (!tp_strdiff (name, str))
448 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
453 valid = gtk_tree_model_iter_next (model, &iter);
459 g_signal_connect (widget, "changed",
460 G_CALLBACK (account_widget_combobox_changed_cb),
465 DEBUG ("Unknown type of widget for param %s", param_name);
470 account_widget_generic_format_param_name (const gchar *param_name)
475 str = g_strdup (param_name);
477 if (str && g_ascii_isalpha (str[0]))
478 str[0] = g_ascii_toupper (str[0]);
480 while ((p = strchr (str, '-')) != NULL)
482 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
485 p[1] = g_ascii_toupper (p[1]);
495 accounts_widget_generic_setup (EmpathyAccountWidget *self,
496 GtkWidget *table_common_settings,
497 GtkWidget *table_advanced_settings)
499 TpConnectionManagerParam *params, *param;
500 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
502 params = empathy_account_settings_get_tp_params (priv->settings);
504 for (param = params; param != NULL && param->name != NULL; param++)
506 GtkWidget *table_settings;
508 GtkWidget *widget = NULL;
509 gchar *param_name_formatted;
511 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
512 table_settings = table_common_settings;
513 else if (priv->simple)
516 table_settings = table_advanced_settings;
518 param_name_formatted = account_widget_generic_format_param_name
520 g_object_get (table_settings, "n-rows", &n_rows, NULL);
521 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
523 if (param->dbus_signature[0] == 's')
527 str = g_strdup_printf (_("%s:"), param_name_formatted);
528 widget = gtk_label_new (str);
529 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
532 gtk_table_attach (GTK_TABLE (table_settings),
538 gtk_widget_show (widget);
540 widget = gtk_entry_new ();
541 if (strcmp (param->name, "account") == 0)
543 g_signal_connect (widget, "realize",
544 G_CALLBACK (gtk_widget_grab_focus),
547 gtk_table_attach (GTK_TABLE (table_settings),
551 GTK_FILL | GTK_EXPAND, 0,
553 gtk_widget_show (widget);
555 /* int types: ynqiuxt. double type is 'd' */
556 else if (param->dbus_signature[0] == 'y' ||
557 param->dbus_signature[0] == 'n' ||
558 param->dbus_signature[0] == 'q' ||
559 param->dbus_signature[0] == 'i' ||
560 param->dbus_signature[0] == 'u' ||
561 param->dbus_signature[0] == 'x' ||
562 param->dbus_signature[0] == 't' ||
563 param->dbus_signature[0] == 'd')
570 switch (param->dbus_signature[0])
572 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
573 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
574 case 'q': minint = 0; maxint = G_MAXUINT16; break;
575 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
576 case 'u': minint = 0; maxint = G_MAXUINT32; break;
577 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
578 case 't': minint = 0; maxint = G_MAXUINT64; break;
579 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
583 str = g_strdup_printf (_("%s:"), param_name_formatted);
584 widget = gtk_label_new (str);
585 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
588 gtk_table_attach (GTK_TABLE (table_settings),
594 gtk_widget_show (widget);
596 widget = gtk_spin_button_new_with_range (minint, maxint, step);
597 gtk_table_attach (GTK_TABLE (table_settings),
601 GTK_FILL | GTK_EXPAND, 0,
603 gtk_widget_show (widget);
605 else if (param->dbus_signature[0] == 'b')
607 widget = gtk_check_button_new_with_label (param_name_formatted);
608 gtk_table_attach (GTK_TABLE (table_settings),
612 GTK_FILL | GTK_EXPAND, 0,
614 gtk_widget_show (widget);
618 DEBUG ("Unknown signature for param %s: %s",
619 param_name_formatted, param->dbus_signature);
623 empathy_account_widget_setup_widget (self, widget, param->name);
625 g_free (param_name_formatted);
630 account_widget_handle_params_valist (EmpathyAccountWidget *self,
631 const gchar *first_widget,
637 for (name = first_widget; name; name = va_arg (args, const gchar *))
639 const gchar *param_name;
641 param_name = va_arg (args, const gchar *);
642 object = gtk_builder_get_object (self->ui_details->gui, name);
646 g_warning ("Builder is missing object '%s'.", name);
650 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
656 account_widget_cancel_clicked_cb (GtkWidget *button,
657 EmpathyAccountWidget *self)
659 g_signal_emit (self, signals[CANCELLED], 0);
663 account_widget_account_enabled_cb (GObject *source_object,
667 GError *error = NULL;
668 TpAccount *account = TP_ACCOUNT (source_object);
669 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
670 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
671 TpConnectionPresenceType presence;
672 gchar *message = NULL;
673 gchar *status = NULL;
675 tp_account_set_enabled_finish (account, res, &error);
679 DEBUG ("Could not enable the account: %s", error->message);
680 g_error_free (error);
684 /* only force presence if presence was offline, unknown or unset */
685 presence = tp_account_get_requested_presence (account, NULL, NULL);
688 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
689 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
690 case TP_CONNECTION_PRESENCE_TYPE_UNSET:
691 presence = tp_account_manager_get_most_available_presence (
692 priv->account_manager, &status, &message);
693 tp_account_request_presence_async (account, presence,
694 status, NULL, NULL, NULL);
697 /* do nothing if the presence is not offline */
702 /* unref widget - part of the workaround */
703 g_object_unref (widget);
709 account_widget_applied_cb (GObject *source_object,
713 GError *error = NULL;
715 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
716 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
717 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
719 empathy_account_settings_apply_finish (settings, res, &error);
723 DEBUG ("Could not apply changes to account: %s", error->message);
724 g_error_free (error);
728 account = empathy_account_settings_get_account (priv->settings);
732 if (priv->creating_account)
734 /* By default, when an account is created, we enable it. */
736 /* workaround to keep widget alive during async call */
737 g_object_ref (widget);
739 tp_account_set_enabled_async (account, TRUE,
740 account_widget_account_enabled_cb, widget);
741 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0, account);
743 else if (priv->enabled_checkbox != NULL)
745 gboolean enabled_checked;
749 nbtk_gtk_light_switch_get_active (
750 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
752 gtk_toggle_button_get_active (
753 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
756 if (tp_account_is_enabled (account) && enabled_checked)
758 /* After having applied changes to a user account, we
759 * automatically reconnect it. This is done so the new
760 * information entered by the user is validated on the server. */
761 tp_account_reconnect_async (account, NULL, NULL);
766 if (!priv->destroyed)
767 account_widget_set_control_buttons_sensitivity (widget, FALSE);
769 priv->contains_pending_changes = FALSE;
771 /* unref the widget - part of the workaround */
772 g_object_unref (widget);
776 account_widget_apply_clicked_cb (GtkWidget *button,
777 EmpathyAccountWidget *self)
779 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
781 if (priv->radiobutton_reuse != NULL)
783 gboolean reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
784 priv->radiobutton_reuse));
786 DEBUG ("Set register param: %d", !reuse);
787 empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
790 /* workaround to keep widget alive during async call */
792 empathy_account_settings_apply_async (priv->settings,
793 account_widget_applied_cb, self);
797 account_widget_setup_generic (EmpathyAccountWidget *self)
799 GtkWidget *table_common_settings;
800 GtkWidget *table_advanced_settings;
802 table_common_settings = GTK_WIDGET (gtk_builder_get_object
803 (self->ui_details->gui, "table_common_settings"));
804 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
805 (self->ui_details->gui, "table_advanced_settings"));
807 accounts_widget_generic_setup (self, table_common_settings,
808 table_advanced_settings);
810 g_object_unref (self->ui_details->gui);
814 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
818 EmpathyAccountWidget *self = user_data;
819 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
821 if (empathy_account_settings_is_ready (priv->settings))
822 account_widget_setup_generic (self);
826 account_widget_build_generic (EmpathyAccountWidget *self,
827 const char *filename)
829 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
830 GtkWidget *expander_advanced;
832 self->ui_details->gui = empathy_builder_get_file (filename,
833 "table_common_settings", &priv->table_common_settings,
834 "vbox_generic_settings", &self->ui_details->widget,
835 "expander_advanced_settings", &expander_advanced,
839 gtk_widget_hide (expander_advanced);
841 g_object_ref (self->ui_details->gui);
843 if (empathy_account_settings_is_ready (priv->settings))
844 account_widget_setup_generic (self);
846 g_signal_connect (priv->settings, "notify::ready",
847 G_CALLBACK (account_widget_settings_ready_cb), self);
851 account_widget_build_salut (EmpathyAccountWidget *self,
852 const char *filename)
854 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
855 GtkWidget *expander_advanced;
857 self->ui_details->gui = empathy_builder_get_file (filename,
858 "table_common_settings", &priv->table_common_settings,
859 "vbox_salut_settings", &self->ui_details->widget,
860 "expander_advanced_settings", &expander_advanced,
863 empathy_account_widget_handle_params (self,
864 "entry_published", "published-name",
865 "entry_nickname", "nickname",
866 "entry_first_name", "first-name",
867 "entry_last_name", "last-name",
868 "entry_email", "email",
873 gtk_widget_hide (expander_advanced);
875 self->ui_details->default_focus = g_strdup ("entry_first_name");
879 account_widget_build_irc (EmpathyAccountWidget *self,
880 const char *filename)
882 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
883 empathy_account_widget_irc_build (self, filename,
884 &priv->table_common_settings);
888 account_widget_build_sip (EmpathyAccountWidget *self,
889 const char *filename)
891 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
892 empathy_account_widget_sip_build (self, filename,
893 &priv->table_common_settings);
897 account_widget_build_msn (EmpathyAccountWidget *self,
898 const char *filename)
900 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
904 self->ui_details->gui = empathy_builder_get_file (filename,
905 "vbox_msn_simple", &self->ui_details->widget,
908 empathy_account_widget_handle_params (self,
909 "entry_id_simple", "account",
910 "entry_password_simple", "password",
913 self->ui_details->default_focus = g_strdup ("entry_id_simple");
917 self->ui_details->gui = empathy_builder_get_file (filename,
918 "table_common_msn_settings", &priv->table_common_settings,
919 "vbox_msn_settings", &self->ui_details->widget,
922 empathy_account_widget_handle_params (self,
923 "entry_id", "account",
924 "entry_password", "password",
925 "entry_server", "server",
926 "spinbutton_port", "port",
929 self->ui_details->default_focus = g_strdup ("entry_id");
930 self->ui_details->add_forget = TRUE;
935 account_widget_is_gtalk (EmpathyAccountWidget *self)
937 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
939 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
944 account_widget_is_facebook (EmpathyAccountWidget *self)
946 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
948 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
952 #define FACEBOOK_SUFFIX "@chat.facebook.com"
955 facebook_id_widget_changed_cb (GtkWidget *entry,
956 EmpathyAccountWidget *self)
958 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
959 const gchar *account;
961 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
963 account = empathy_account_settings_get_string (priv->settings, "account");
964 if (!EMP_STR_EMPTY (account) &&
965 !g_str_has_suffix (account, FACEBOOK_SUFFIX))
969 tmp = g_strdup_printf ("%s%s", account, FACEBOOK_SUFFIX);
971 DEBUG ("Change account from '%s' to '%s'", account, tmp);
973 empathy_account_settings_set_string (priv->settings, "account", tmp);
977 empathy_account_widget_changed (self);
981 remove_facebook_suffix (const gchar *str)
983 if (!g_str_has_suffix (str, FACEBOOK_SUFFIX))
984 return g_strdup (str);
986 return g_strndup (str, strlen (str) - strlen (FACEBOOK_SUFFIX));
990 setup_facebook_id_widget (EmpathyAccountWidget *self,
993 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
994 const gchar *str = NULL;
996 g_object_set_data_full (G_OBJECT (widget), "param_name",
997 g_strdup ("account"), g_free);
999 str = empathy_account_settings_get_string (priv->settings, "account");
1004 tmp = remove_facebook_suffix (str);
1005 gtk_entry_set_text (GTK_ENTRY (widget), tmp);
1009 priv->param_account_widget = widget;
1011 g_signal_connect (widget, "changed",
1012 G_CALLBACK (facebook_id_widget_changed_cb), self);
1016 account_widget_build_jabber (EmpathyAccountWidget *self,
1017 const char *filename)
1019 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1020 GtkWidget *spinbutton_port;
1021 GtkWidget *checkbutton_ssl;
1022 GtkWidget *label_id, *label_password;
1023 GtkWidget *label_id_create, *label_password_create;
1024 GtkWidget *label_example_gtalk, *label_example_jabber, *label_example_fb;
1025 gboolean is_gtalk, is_facebook;
1026 GtkWidget *expander_advanced;
1027 GtkWidget *entry_id;
1029 is_gtalk = account_widget_is_gtalk (self);
1030 is_facebook = account_widget_is_facebook (self);
1032 if (priv->simple && !is_gtalk && !is_facebook)
1034 /* Simple widget for XMPP */
1035 self->ui_details->gui = empathy_builder_get_file (filename,
1036 "vbox_jabber_simple", &self->ui_details->widget,
1037 "label_id_simple", &label_id,
1038 "label_id_create", &label_id_create,
1039 "label_password_simple", &label_password,
1040 "label_password_create", &label_password_create,
1043 if (empathy_account_settings_get_boolean (priv->settings, "register"))
1045 gtk_widget_hide (label_id);
1046 gtk_widget_hide (label_password);
1047 gtk_widget_show (label_id_create);
1048 gtk_widget_show (label_password_create);
1051 empathy_account_widget_handle_params (self,
1052 "entry_id_simple", "account",
1053 "entry_password_simple", "password",
1056 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1058 else if (priv->simple && is_gtalk)
1060 /* Simple widget for Google Talk */
1061 self->ui_details->gui = empathy_builder_get_file (filename,
1062 "vbox_gtalk_simple", &self->ui_details->widget,
1065 empathy_account_widget_handle_params (self,
1066 "entry_id_g_simple", "account",
1067 "entry_password_g_simple", "password",
1070 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
1072 /* TODO: Simple widget for Facebook */
1075 /* Full widget for XMPP, Google Talk and Facebook*/
1076 self->ui_details->gui = empathy_builder_get_file (filename,
1077 "table_common_settings", &priv->table_common_settings,
1078 "vbox_jabber_settings", &self->ui_details->widget,
1079 "spinbutton_port", &spinbutton_port,
1080 "checkbutton_ssl", &checkbutton_ssl,
1081 "label_username_example", &label_example_jabber,
1082 "label_username_g_example", &label_example_gtalk,
1083 "label_username_f_example", &label_example_fb,
1084 "expander_advanced", &expander_advanced,
1085 "entry_id", &entry_id,
1088 empathy_account_widget_handle_params (self,
1089 "entry_password", "password",
1090 "entry_resource", "resource",
1091 "entry_server", "server",
1092 "spinbutton_port", "port",
1093 "spinbutton_priority", "priority",
1094 "checkbutton_ssl", "old-ssl",
1095 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1096 "checkbutton_encryption", "require-encryption",
1101 /* Facebook special case the entry ID widget to hide the
1102 * "@chat.facebook.com" part */
1103 setup_facebook_id_widget (self, entry_id);
1107 empathy_account_widget_setup_widget (self, entry_id, "account");
1110 self->ui_details->default_focus = g_strdup ("entry_id");
1111 self->ui_details->add_forget = TRUE;
1112 priv->spinbutton_port = spinbutton_port;
1114 g_signal_connect (checkbutton_ssl, "toggled",
1115 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1120 gtk_widget_hide (label_example_jabber);
1121 gtk_widget_show (label_example_gtalk);
1123 else if (is_facebook)
1125 gtk_widget_hide (label_example_jabber);
1126 gtk_widget_show (label_example_fb);
1127 gtk_widget_hide (expander_advanced);
1133 account_widget_build_icq (EmpathyAccountWidget *self,
1134 const char *filename)
1136 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1137 GtkWidget *spinbutton_port;
1141 self->ui_details->gui = empathy_builder_get_file (filename,
1142 "vbox_icq_simple", &self->ui_details->widget,
1145 empathy_account_widget_handle_params (self,
1146 "entry_uin_simple", "account",
1147 "entry_password_simple", "password",
1150 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1154 self->ui_details->gui = empathy_builder_get_file (filename,
1155 "table_common_settings", &priv->table_common_settings,
1156 "vbox_icq_settings", &self->ui_details->widget,
1157 "spinbutton_port", &spinbutton_port,
1160 empathy_account_widget_handle_params (self,
1161 "entry_uin", "account",
1162 "entry_password", "password",
1163 "entry_server", "server",
1164 "spinbutton_port", "port",
1165 "entry_charset", "charset",
1168 self->ui_details->default_focus = g_strdup ("entry_uin");
1169 self->ui_details->add_forget = TRUE;
1174 account_widget_build_aim (EmpathyAccountWidget *self,
1175 const char *filename)
1177 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1178 GtkWidget *spinbutton_port;
1182 self->ui_details->gui = empathy_builder_get_file (filename,
1183 "vbox_aim_simple", &self->ui_details->widget,
1186 empathy_account_widget_handle_params (self,
1187 "entry_screenname_simple", "account",
1188 "entry_password_simple", "password",
1191 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1195 self->ui_details->gui = empathy_builder_get_file (filename,
1196 "table_common_settings", &priv->table_common_settings,
1197 "vbox_aim_settings", &self->ui_details->widget,
1198 "spinbutton_port", &spinbutton_port,
1201 empathy_account_widget_handle_params (self,
1202 "entry_screenname", "account",
1203 "entry_password", "password",
1204 "entry_server", "server",
1205 "spinbutton_port", "port",
1208 self->ui_details->default_focus = g_strdup ("entry_screenname");
1209 self->ui_details->add_forget = TRUE;
1214 account_widget_build_yahoo (EmpathyAccountWidget *self,
1215 const char *filename)
1217 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1221 self->ui_details->gui = empathy_builder_get_file (filename,
1222 "vbox_yahoo_simple", &self->ui_details->widget,
1225 empathy_account_widget_handle_params (self,
1226 "entry_id_simple", "account",
1227 "entry_password_simple", "password",
1230 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1234 self->ui_details->gui = empathy_builder_get_file (filename,
1235 "table_common_settings", &priv->table_common_settings,
1236 "vbox_yahoo_settings", &self->ui_details->widget,
1239 empathy_account_widget_handle_params (self,
1240 "entry_id", "account",
1241 "entry_password", "password",
1242 "entry_server", "server",
1243 "entry_locale", "room-list-locale",
1244 "entry_charset", "charset",
1245 "spinbutton_port", "port",
1246 "checkbutton_yahoojp", "yahoojp",
1247 "checkbutton_ignore_invites", "ignore-invites",
1250 self->ui_details->default_focus = g_strdup ("entry_id");
1251 self->ui_details->add_forget = TRUE;
1256 account_widget_build_groupwise (EmpathyAccountWidget *self,
1257 const char *filename)
1259 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1263 self->ui_details->gui = empathy_builder_get_file (filename,
1264 "vbox_groupwise_simple", &self->ui_details->widget,
1267 empathy_account_widget_handle_params (self,
1268 "entry_id_simple", "account",
1269 "entry_password_simple", "password",
1272 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1276 self->ui_details->gui = empathy_builder_get_file (filename,
1277 "table_common_groupwise_settings", &priv->table_common_settings,
1278 "vbox_groupwise_settings", &self->ui_details->widget,
1281 empathy_account_widget_handle_params (self,
1282 "entry_id", "account",
1283 "entry_password", "password",
1284 "entry_server", "server",
1285 "spinbutton_port", "port",
1288 self->ui_details->default_focus = g_strdup ("entry_id");
1289 self->ui_details->add_forget = TRUE;
1294 account_widget_destroy_cb (GtkWidget *widget,
1295 EmpathyAccountWidget *self)
1297 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1298 /* set the destroyed flag - workaround */
1299 priv->destroyed = TRUE;
1301 g_object_unref (self);
1305 empathy_account_widget_enabled_cb (TpAccount *account,
1309 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1310 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1311 gboolean enabled = tp_account_is_enabled (account);
1313 if (priv->enabled_checkbox != NULL)
1316 nbtk_gtk_light_switch_set_active (
1317 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1320 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1322 #endif /* HAVE_MOBLIN */
1328 account_widget_switch_flipped_cb (NbtkGtkLightSwitch *sw,
1332 account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
1334 #endif /* HAVE_MOBLIN */
1336 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1341 state = gtk_toggle_button_get_active (toggle_button);
1344 account = empathy_account_settings_get_account (priv->settings);
1346 /* Enable the account according to the value of the "Enabled" checkbox */
1347 /* workaround to keep widget alive during async call */
1348 g_object_ref (user_data);
1349 tp_account_set_enabled_async (account, state,
1350 account_widget_account_enabled_cb, user_data);
1354 do_set_property (GObject *object,
1356 const GValue *value,
1359 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1364 priv->settings = g_value_dup_object (value);
1367 priv->simple = g_value_get_boolean (value);
1369 case PROP_CREATING_ACCOUNT:
1370 priv->creating_account = g_value_get_boolean (value);
1373 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1378 do_get_property (GObject *object,
1383 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1388 g_value_set_string (value,
1389 empathy_account_settings_get_protocol (priv->settings));
1392 g_value_set_object (value, priv->settings);
1395 g_value_set_boolean (value, priv->simple);
1397 case PROP_CREATING_ACCOUNT:
1398 g_value_set_boolean (value, priv->creating_account);
1401 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1406 presence_changed_cb (TpAccountManager *manager,
1407 TpConnectionPresenceType state,
1408 const gchar *status,
1409 const gchar *message,
1410 EmpathyAccountWidget *self)
1412 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1414 if (priv->destroyed)
1417 if (priv->apply_button == NULL)
1418 /* This button doesn't exist in 'simple' mode */
1421 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
1423 /* We are online, display a Login button */
1426 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1427 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1429 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1430 GTK_ICON_SIZE_BUTTON);
1431 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1435 /* We are offline, display a Save button */
1436 gtk_button_set_image (GTK_BUTTON (priv->apply_button), NULL);
1437 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), TRUE);
1438 gtk_button_set_label (GTK_BUTTON (priv->apply_button), GTK_STOCK_SAVE);
1443 account_manager_ready_cb (GObject *source_object,
1444 GAsyncResult *result,
1447 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1448 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1449 GError *error = NULL;
1450 TpConnectionPresenceType state;
1452 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1454 DEBUG ("Failed to prepare account manager: %s", error->message);
1455 g_error_free (error);
1459 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1462 /* simulate a presence change so the apply button will be changed
1464 presence_changed_cb (account_manager, state, NULL, NULL, self);
1467 g_object_unref (self);
1470 #define WIDGET(cm, proto) \
1471 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1472 account_widget_build_##proto }
1475 add_enable_checkbox (EmpathyAccountWidget *self,
1478 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1482 GtkWidget *vbox = self->ui_details->widget;
1484 guint nb_rows, nb_columns;
1485 gboolean is_enabled;
1487 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1488 if (priv->creating_account || priv->table_common_settings == NULL)
1491 is_enabled = tp_account_is_enabled (account);
1494 w = gtk_label_new (_("Account:"));
1495 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1497 priv->enabled_checkbox = nbtk_gtk_light_switch_new ();
1499 nbtk_gtk_light_switch_set_active (
1500 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1502 gtk_widget_show (w);
1504 priv->enabled_checkbox =
1505 gtk_check_button_new_with_label (_("Enabled"));
1507 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1509 #endif /* HAVE_MOBLIN */
1511 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1512 "n-columns", &nb_columns, NULL);
1514 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1518 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1520 0, 1, nb_rows - 1, nb_rows,
1522 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1523 priv->enabled_checkbox,
1524 1, nb_columns, nb_rows - 1, nb_rows,
1525 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1527 gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
1528 gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
1529 #endif /* HAVE_MOBLIN */
1531 gtk_widget_show (priv->enabled_checkbox);
1534 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1535 G_CALLBACK (account_widget_switch_flipped_cb), self);
1537 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
1538 G_CALLBACK (account_widget_enabled_released_cb), self);
1539 #endif /* HAVE_MOBLIN */
1543 /* Moblin doesn't support registration */
1545 add_register_buttons (EmpathyAccountWidget *self,
1548 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1549 const TpConnectionManagerProtocol *protocol;
1550 GtkWidget *radiobutton_register;
1551 GtkWidget *vbox = self->ui_details->widget;
1553 if (!priv->creating_account)
1556 protocol = empathy_account_settings_get_tp_protocol (priv->settings);
1557 if (protocol == NULL)
1560 if (!tp_connection_manager_protocol_can_register (protocol))
1563 if (account_widget_is_gtalk (self) || account_widget_is_facebook (self))
1569 priv->radiobutton_reuse = gtk_radio_button_new_with_label (NULL,
1570 _("This account already exists on the server"));
1571 radiobutton_register = gtk_radio_button_new_with_label (
1572 gtk_radio_button_get_group (GTK_RADIO_BUTTON (priv->radiobutton_reuse)),
1573 _("Create a new account on the server"));
1575 gtk_box_pack_start (GTK_BOX (vbox), priv->radiobutton_reuse, FALSE, FALSE, 0);
1576 gtk_box_pack_start (GTK_BOX (vbox), radiobutton_register, FALSE, FALSE, 0);
1577 gtk_box_reorder_child (GTK_BOX (vbox), priv->radiobutton_reuse, 0);
1578 gtk_box_reorder_child (GTK_BOX (vbox), radiobutton_register, 1);
1579 gtk_widget_show (priv->radiobutton_reuse);
1580 gtk_widget_show (radiobutton_register);
1585 do_constructed (GObject *obj)
1587 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1588 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1590 const gchar *protocol, *cm_name;
1593 const gchar *cm_name;
1594 const gchar *protocol;
1596 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1598 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1599 account_widget_build_salut },
1600 WIDGET (gabble, jabber),
1601 WIDGET (butterfly, msn),
1604 WIDGET (haze, yahoo),
1605 WIDGET (haze, groupwise),
1607 WIDGET (sofiasip, sip),
1610 cm_name = empathy_account_settings_get_cm (priv->settings);
1611 protocol = empathy_account_settings_get_protocol (priv->settings);
1613 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1615 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1616 !tp_strdiff (widgets[i].protocol, protocol))
1620 filename = empathy_file_lookup (widgets[i].file,
1622 widgets[i].func (self, filename);
1629 if (i == G_N_ELEMENTS (widgets))
1631 gchar *filename = empathy_file_lookup (
1632 "empathy-account-widget-generic.ui", "libempathy-gtk");
1633 account_widget_build_generic (self, filename);
1637 /* handle default focus */
1638 if (self->ui_details->default_focus != NULL)
1640 GObject *default_focus_entry;
1642 default_focus_entry = gtk_builder_get_object
1643 (self->ui_details->gui, self->ui_details->default_focus);
1644 g_signal_connect (default_focus_entry, "realize",
1645 G_CALLBACK (gtk_widget_grab_focus),
1649 /* handle forget button */
1650 if (self->ui_details->add_forget)
1652 const gchar *password = NULL;
1654 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1655 (self->ui_details->gui, "button_forget"));
1656 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1657 (self->ui_details->gui, "entry_password"));
1659 password = empathy_account_settings_get_string (priv->settings,
1661 gtk_widget_set_sensitive (priv->button_forget,
1662 !EMP_STR_EMPTY (password));
1664 g_signal_connect (priv->button_forget, "clicked",
1665 G_CALLBACK (account_widget_forget_clicked_cb),
1667 g_signal_connect (priv->entry_password, "changed",
1668 G_CALLBACK (account_widget_password_changed_cb),
1672 /* dup and init the account-manager */
1673 priv->account_manager = tp_account_manager_dup ();
1675 g_object_ref (self);
1676 tp_account_manager_prepare_async (priv->account_manager, NULL,
1677 account_manager_ready_cb, self);
1679 /* handle apply and cancel button */
1682 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1684 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1686 if (priv->creating_account)
1688 /* Assumre we are offline, display a Save button. We'll update
1689 * it once the account manager is ready if needed */
1690 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
1692 empathy_signal_connect_weak (priv->account_manager,
1693 "most-available-presence-changed",
1694 G_CALLBACK (presence_changed_cb), obj);
1698 /* We are editing an existing account, display an Apply button */
1699 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1702 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1704 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1707 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1710 g_signal_connect (priv->cancel_button, "clicked",
1711 G_CALLBACK (account_widget_cancel_clicked_cb),
1713 g_signal_connect (priv->apply_button, "clicked",
1714 G_CALLBACK (account_widget_apply_clicked_cb),
1716 gtk_widget_show_all (hbox);
1718 if (priv->creating_account)
1719 /* When creating an account, the user might have nothing to enter.
1720 * That means that no control interaction might occur,
1721 * so we update the control button sensitivity manually.
1723 account_widget_handle_control_buttons_sensitivity (self);
1725 account_widget_set_control_buttons_sensitivity (self, FALSE);
1728 account = empathy_account_settings_get_account (priv->settings);
1730 if (account != NULL)
1732 g_signal_connect (account, "notify::enabled",
1733 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1737 add_register_buttons (self, account);
1739 add_enable_checkbox (self, account);
1741 /* hook up to widget destruction to unref ourselves */
1742 g_signal_connect (self->ui_details->widget, "destroy",
1743 G_CALLBACK (account_widget_destroy_cb), self);
1745 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1746 self->ui_details->widget);
1747 self->ui_details->gui = NULL;
1751 do_dispose (GObject *obj)
1753 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1754 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1756 if (priv->dispose_run)
1759 priv->dispose_run = TRUE;
1761 empathy_account_settings_is_ready (priv->settings);
1763 if (priv->settings != NULL)
1766 account = empathy_account_settings_get_account (priv->settings);
1768 if (account != NULL)
1770 g_signal_handlers_disconnect_by_func (account,
1771 empathy_account_widget_enabled_cb, self);
1774 g_object_unref (priv->settings);
1775 priv->settings = NULL;
1778 if (priv->account_manager != NULL)
1780 g_object_unref (priv->account_manager);
1781 priv->account_manager = NULL;
1784 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1785 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1789 do_finalize (GObject *obj)
1791 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1793 g_free (self->ui_details->default_focus);
1794 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1796 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1797 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1801 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1803 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1804 GParamSpec *param_spec;
1806 oclass->get_property = do_get_property;
1807 oclass->set_property = do_set_property;
1808 oclass->constructed = do_constructed;
1809 oclass->dispose = do_dispose;
1810 oclass->finalize = do_finalize;
1812 param_spec = g_param_spec_string ("protocol",
1813 "protocol", "The protocol of the account",
1815 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1816 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1818 param_spec = g_param_spec_object ("settings",
1819 "settings", "The settings of the account",
1820 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1821 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1822 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1824 param_spec = g_param_spec_boolean ("simple",
1825 "simple", "Whether the account widget is a simple or an advanced one",
1827 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1828 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1830 param_spec = g_param_spec_boolean ("creating-account",
1832 "TRUE if we're creating an account, FALSE if we're modifying it",
1834 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1835 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1837 signals[HANDLE_APPLY] =
1838 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1839 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1840 g_cclosure_marshal_VOID__BOOLEAN,
1844 /* This signal is emitted when an account has been created and enabled. */
1845 signals[ACCOUNT_CREATED] =
1846 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1847 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1848 g_cclosure_marshal_VOID__POINTER,
1852 signals[CANCELLED] =
1853 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1854 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1855 g_cclosure_marshal_VOID__VOID,
1859 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1863 empathy_account_widget_init (EmpathyAccountWidget *self)
1865 EmpathyAccountWidgetPriv *priv =
1866 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1867 EmpathyAccountWidgetPriv);
1870 priv->dispose_run = FALSE;
1872 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1875 /* public methods */
1878 empathy_account_widget_discard_pending_changes
1879 (EmpathyAccountWidget *widget)
1881 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1883 empathy_account_settings_discard_changes (priv->settings);
1884 priv->contains_pending_changes = FALSE;
1888 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
1890 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1892 return priv->contains_pending_changes;
1896 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1897 const gchar *first_widget,
1902 va_start (args, first_widget);
1903 account_widget_handle_params_valist (self, first_widget, args);
1908 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1910 return widget->ui_details->widget;
1913 EmpathyAccountWidget *
1914 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1917 EmpathyAccountWidget *self;
1919 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1922 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1923 "settings", settings, "simple", simple,
1925 empathy_account_settings_get_account (settings) == NULL,
1932 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
1934 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1935 const gchar *login_id;
1936 const gchar *protocol, *p;
1937 gchar *default_display_name;
1939 login_id = empathy_account_settings_get_string (priv->settings, "account");
1940 protocol = empathy_account_settings_get_protocol (priv->settings);
1942 if (login_id != NULL)
1944 /* TODO: this should be done in empathy-account-widget-irc */
1945 if (!tp_strdiff (protocol, "irc"))
1947 const gchar* server;
1948 server = empathy_account_settings_get_string (priv->settings,
1951 /* To translators: The first parameter is the login id and the
1952 * second one is the server. The resulting string will be something
1953 * like: "MyUserName on chat.freenode.net".
1954 * You should reverse the order of these arguments if the
1955 * server should come before the login id in your locale.*/
1956 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
1959 else if (account_widget_is_facebook (self))
1963 tmp = remove_facebook_suffix (login_id);
1964 default_display_name = g_strdup_printf ("Facebook (%s)", tmp);
1969 default_display_name = g_strdup (login_id);
1972 return default_display_name;
1975 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
1978 if (protocol != NULL)
1980 /* To translators: The parameter is the protocol name. The resulting
1981 * string will be something like: "Jabber Account" */
1982 default_display_name = g_strdup_printf (_("%s Account"), protocol);
1986 default_display_name = g_strdup (_("New account"));
1989 return default_display_name;
1992 /* Used by subclass to indicate that widget contains pending changes */
1994 empathy_account_widget_changed (EmpathyAccountWidget *self)
1996 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1998 account_widget_handle_control_buttons_sensitivity (self);
1999 priv->contains_pending_changes = TRUE;
2003 empathy_account_widget_set_account_param (EmpathyAccountWidget *self,
2004 const gchar *account)
2006 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2008 if (priv->param_account_widget == NULL)
2011 gtk_entry_set_text (GTK_ENTRY (priv->param_account_widget), account);
2015 empathy_account_widget_set_password_param (EmpathyAccountWidget *self,
2016 const gchar *account)
2018 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
2020 if (priv->param_password_widget == NULL)
2023 gtk_entry_set_text (GTK_ENTRY (priv->param_password_widget), account);