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;
69 gboolean contains_pending_changes;
71 /* An EmpathyAccountWidget can be used to either create an account or
72 * modify it. When we are creating an account, this member is set to TRUE */
73 gboolean creating_account;
75 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
76 * embedded in this account widget can't be used any more
77 * workaround because some async callbacks can be called after the
78 * widget has been destroyed */
81 TpAccountManager *account_manager;
84 } EmpathyAccountWidgetPriv;
100 static guint signals[LAST_SIGNAL] = { 0 };
102 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
103 #define CHANGED_TIMEOUT 300
106 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
109 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
113 gtk_widget_set_sensitive (priv->apply_button, sensitive);
114 gtk_widget_set_sensitive (
115 priv->cancel_button, sensitive || priv->creating_account);
120 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
122 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
125 is_valid = empathy_account_settings_is_valid (priv->settings);
128 account_widget_set_control_buttons_sensitivity (self, is_valid);
130 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
134 account_widget_entry_changed_common (EmpathyAccountWidget *self,
135 GtkEntry *entry, gboolean focus)
138 const gchar *param_name;
139 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
141 str = gtk_entry_get_text (entry);
142 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
144 if (EMP_STR_EMPTY (str))
146 const gchar *value = NULL;
148 empathy_account_settings_unset (priv->settings, param_name);
152 value = empathy_account_settings_get_string (priv->settings,
154 DEBUG ("Unset %s and restore to %s", param_name, value);
155 gtk_entry_set_text (entry, value ? value : "");
160 DEBUG ("Setting %s to %s", param_name,
161 tp_strdiff (param_name, "password") ? str : "***");
162 empathy_account_settings_set_string (priv->settings, param_name, str);
167 account_widget_entry_changed_cb (GtkEditable *entry,
168 EmpathyAccountWidget *self)
170 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
172 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
173 account_widget_handle_control_buttons_sensitivity (self);
175 priv->contains_pending_changes = TRUE;
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 account_widget_handle_control_buttons_sensitivity (self);
217 priv->contains_pending_changes = TRUE;
221 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
222 EmpathyAccountWidget *self)
225 gboolean default_value;
226 const gchar *param_name;
227 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
229 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
230 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
232 /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
233 * always unset the param and set the value if different from the
235 empathy_account_settings_unset (priv->settings, param_name);
236 default_value = empathy_account_settings_get_boolean (priv->settings,
239 if (default_value == value)
241 DEBUG ("Unset %s and restore to %d", param_name, default_value);
245 DEBUG ("Setting %s to %d", param_name, value);
246 empathy_account_settings_set_boolean (priv->settings, param_name, value);
249 account_widget_handle_control_buttons_sensitivity (self);
250 priv->contains_pending_changes = TRUE;
254 account_widget_forget_clicked_cb (GtkWidget *button,
255 EmpathyAccountWidget *self)
257 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
258 const gchar *param_name;
260 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
263 DEBUG ("Unset %s", param_name);
264 empathy_account_settings_unset (priv->settings, param_name);
265 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
267 account_widget_handle_control_buttons_sensitivity (self);
268 priv->contains_pending_changes = TRUE;
272 account_widget_password_changed_cb (GtkWidget *entry,
273 EmpathyAccountWidget *self)
275 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
278 str = gtk_entry_get_text (GTK_ENTRY (entry));
279 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
281 priv->contains_pending_changes = TRUE;
285 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
286 EmpathyAccountWidget *self)
288 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
292 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
293 port = empathy_account_settings_get_uint32 (priv->settings, "port");
297 if (port == 5222 || port == 0)
302 if (port == 5223 || port == 0)
306 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
308 priv->contains_pending_changes = TRUE;
312 account_widget_combobox_changed_cb (GtkWidget *widget,
313 EmpathyAccountWidget *self)
319 const gchar *default_value = NULL;
320 const gchar *param_name;
321 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
323 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
326 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
327 /* the param value is stored in the first column */
328 gtk_tree_model_get (model, &iter, 0, &value, -1);
330 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
332 v = empathy_account_settings_get_default (priv->settings, param_name);
334 default_value = g_value_get_string (v);
336 if (!tp_strdiff (value, default_value))
338 DEBUG ("Unset %s and restore to %s", param_name, default_value);
339 empathy_account_settings_unset (priv->settings, param_name);
343 DEBUG ("Setting %s to %s", param_name, value);
344 empathy_account_settings_set_string (priv->settings, param_name, value);
347 account_widget_handle_control_buttons_sensitivity (self);
348 priv->contains_pending_changes = TRUE;
352 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
354 const gchar *param_name)
356 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
358 g_object_set_data_full (G_OBJECT (widget), "param_name",
359 g_strdup (param_name), g_free);
361 if (GTK_IS_SPIN_BUTTON (widget))
364 const gchar *signature;
366 signature = empathy_account_settings_get_dbus_signature (priv->settings,
368 g_return_if_fail (signature != NULL);
370 switch ((int)*signature)
372 case DBUS_TYPE_INT16:
373 case DBUS_TYPE_INT32:
374 value = empathy_account_settings_get_int32 (priv->settings,
377 case DBUS_TYPE_INT64:
378 value = empathy_account_settings_get_int64 (priv->settings,
381 case DBUS_TYPE_UINT16:
382 case DBUS_TYPE_UINT32:
383 value = empathy_account_settings_get_uint32 (priv->settings,
386 case DBUS_TYPE_UINT64:
387 value = empathy_account_settings_get_uint64 (priv->settings,
391 g_return_if_reached ();
394 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
396 g_signal_connect (widget, "value-changed",
397 G_CALLBACK (account_widget_int_changed_cb),
400 else if (GTK_IS_ENTRY (widget))
402 const gchar *str = NULL;
404 str = empathy_account_settings_get_string (priv->settings, param_name);
405 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
407 if (strstr (param_name, "password"))
409 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
412 g_signal_connect (widget, "changed",
413 G_CALLBACK (account_widget_entry_changed_cb), self);
415 else if (GTK_IS_TOGGLE_BUTTON (widget))
417 gboolean value = FALSE;
419 value = empathy_account_settings_get_boolean (priv->settings,
421 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
423 g_signal_connect (widget, "toggled",
424 G_CALLBACK (account_widget_checkbutton_toggled_cb),
427 else if (GTK_IS_COMBO_BOX (widget))
429 /* The combo box's model has to contain the param value in its first
430 * column (as a string) */
436 str = empathy_account_settings_get_string (priv->settings, param_name);
437 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
439 valid = gtk_tree_model_get_iter_first (model, &iter);
444 gtk_tree_model_get (model, &iter, 0, &name, -1);
445 if (!tp_strdiff (name, str))
447 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
452 valid = gtk_tree_model_iter_next (model, &iter);
458 g_signal_connect (widget, "changed",
459 G_CALLBACK (account_widget_combobox_changed_cb),
464 DEBUG ("Unknown type of widget for param %s", param_name);
469 account_widget_generic_format_param_name (const gchar *param_name)
474 str = g_strdup (param_name);
476 if (str && g_ascii_isalpha (str[0]))
477 str[0] = g_ascii_toupper (str[0]);
479 while ((p = strchr (str, '-')) != NULL)
481 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
484 p[1] = g_ascii_toupper (p[1]);
494 accounts_widget_generic_setup (EmpathyAccountWidget *self,
495 GtkWidget *table_common_settings,
496 GtkWidget *table_advanced_settings)
498 TpConnectionManagerParam *params, *param;
499 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
501 params = empathy_account_settings_get_tp_params (priv->settings);
503 for (param = params; param != NULL && param->name != NULL; param++)
505 GtkWidget *table_settings;
507 GtkWidget *widget = NULL;
508 gchar *param_name_formatted;
510 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
511 table_settings = table_common_settings;
512 else if (priv->simple)
515 table_settings = table_advanced_settings;
517 param_name_formatted = account_widget_generic_format_param_name
519 g_object_get (table_settings, "n-rows", &n_rows, NULL);
520 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
522 if (param->dbus_signature[0] == 's')
526 str = g_strdup_printf (_("%s:"), param_name_formatted);
527 widget = gtk_label_new (str);
528 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
531 gtk_table_attach (GTK_TABLE (table_settings),
537 gtk_widget_show (widget);
539 widget = gtk_entry_new ();
540 if (strcmp (param->name, "account") == 0)
542 g_signal_connect (widget, "realize",
543 G_CALLBACK (gtk_widget_grab_focus),
546 gtk_table_attach (GTK_TABLE (table_settings),
550 GTK_FILL | GTK_EXPAND, 0,
552 gtk_widget_show (widget);
554 /* int types: ynqiuxt. double type is 'd' */
555 else if (param->dbus_signature[0] == 'y' ||
556 param->dbus_signature[0] == 'n' ||
557 param->dbus_signature[0] == 'q' ||
558 param->dbus_signature[0] == 'i' ||
559 param->dbus_signature[0] == 'u' ||
560 param->dbus_signature[0] == 'x' ||
561 param->dbus_signature[0] == 't' ||
562 param->dbus_signature[0] == 'd')
569 switch (param->dbus_signature[0])
571 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
572 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
573 case 'q': minint = 0; maxint = G_MAXUINT16; break;
574 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
575 case 'u': minint = 0; maxint = G_MAXUINT32; break;
576 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
577 case 't': minint = 0; maxint = G_MAXUINT64; break;
578 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
582 str = g_strdup_printf (_("%s:"), param_name_formatted);
583 widget = gtk_label_new (str);
584 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
587 gtk_table_attach (GTK_TABLE (table_settings),
593 gtk_widget_show (widget);
595 widget = gtk_spin_button_new_with_range (minint, maxint, step);
596 gtk_table_attach (GTK_TABLE (table_settings),
600 GTK_FILL | GTK_EXPAND, 0,
602 gtk_widget_show (widget);
604 else if (param->dbus_signature[0] == 'b')
606 widget = gtk_check_button_new_with_label (param_name_formatted);
607 gtk_table_attach (GTK_TABLE (table_settings),
611 GTK_FILL | GTK_EXPAND, 0,
613 gtk_widget_show (widget);
617 DEBUG ("Unknown signature for param %s: %s",
618 param_name_formatted, param->dbus_signature);
622 empathy_account_widget_setup_widget (self, widget, param->name);
624 g_free (param_name_formatted);
629 account_widget_handle_params_valist (EmpathyAccountWidget *self,
630 const gchar *first_widget,
636 for (name = first_widget; name; name = va_arg (args, const gchar *))
638 const gchar *param_name;
640 param_name = va_arg (args, const gchar *);
641 object = gtk_builder_get_object (self->ui_details->gui, name);
645 g_warning ("Builder is missing object '%s'.", name);
649 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
655 account_widget_cancel_clicked_cb (GtkWidget *button,
656 EmpathyAccountWidget *self)
658 g_signal_emit (self, signals[CANCELLED], 0);
662 account_widget_account_enabled_cb (GObject *source_object,
666 GError *error = NULL;
667 TpAccount *account = TP_ACCOUNT (source_object);
668 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
669 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
670 TpConnectionPresenceType presence;
671 gchar *message = NULL;
672 gchar *status = NULL;
674 tp_account_set_enabled_finish (account, res, &error);
678 DEBUG ("Could not enable the account: %s", error->message);
679 g_error_free (error);
683 /* only force presence if presence was offline, unknown or unset */
684 presence = tp_account_get_requested_presence (account, NULL, NULL);
687 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
688 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
689 case TP_CONNECTION_PRESENCE_TYPE_UNSET:
690 presence = tp_account_manager_get_most_available_presence (
691 priv->account_manager, &status, &message);
692 tp_account_request_presence_async (account, presence,
693 status, NULL, NULL, NULL);
696 /* do nothing if the presence is not offline */
701 /* unref widget - part of the workaround */
702 g_object_unref (widget);
708 account_widget_applied_cb (GObject *source_object,
712 GError *error = NULL;
714 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
715 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
716 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
718 empathy_account_settings_apply_finish (settings, res, &error);
722 DEBUG ("Could not apply changes to account: %s", error->message);
723 g_error_free (error);
727 account = empathy_account_settings_get_account (priv->settings);
731 if (priv->creating_account)
733 /* By default, when an account is created, we enable it. */
735 /* workaround to keep widget alive during async call */
736 g_object_ref (widget);
738 tp_account_set_enabled_async (account, TRUE,
739 account_widget_account_enabled_cb, widget);
740 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
742 else if (priv->enabled_checkbox != NULL)
744 gboolean enabled_checked;
748 nbtk_gtk_light_switch_get_active (
749 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
751 gtk_toggle_button_get_active (
752 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
755 if (tp_account_is_enabled (account) && enabled_checked)
757 /* After having applied changes to a user account, we
758 * automatically reconnect it. This is done so the new
759 * information entered by the user is validated on the server. */
760 tp_account_reconnect_async (account, NULL, NULL);
765 if (!priv->destroyed)
766 account_widget_set_control_buttons_sensitivity (widget, FALSE);
768 priv->contains_pending_changes = FALSE;
770 /* unref the widget - part of the workaround */
771 g_object_unref (widget);
775 account_widget_apply_clicked_cb (GtkWidget *button,
776 EmpathyAccountWidget *self)
778 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
780 /* workaround to keep widget alive during async call */
782 empathy_account_settings_apply_async (priv->settings,
783 account_widget_applied_cb, self);
787 account_widget_setup_generic (EmpathyAccountWidget *self)
789 GtkWidget *table_common_settings;
790 GtkWidget *table_advanced_settings;
792 table_common_settings = GTK_WIDGET (gtk_builder_get_object
793 (self->ui_details->gui, "table_common_settings"));
794 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
795 (self->ui_details->gui, "table_advanced_settings"));
797 accounts_widget_generic_setup (self, table_common_settings,
798 table_advanced_settings);
800 g_object_unref (self->ui_details->gui);
804 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
808 EmpathyAccountWidget *self = user_data;
809 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
811 if (empathy_account_settings_is_ready (priv->settings))
812 account_widget_setup_generic (self);
816 account_widget_build_generic (EmpathyAccountWidget *self,
817 const char *filename)
819 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
820 GtkWidget *expander_advanced;
822 self->ui_details->gui = empathy_builder_get_file (filename,
823 "table_common_settings", &priv->table_common_settings,
824 "vbox_generic_settings", &self->ui_details->widget,
825 "expander_advanced_settings", &expander_advanced,
829 gtk_widget_hide (expander_advanced);
831 g_object_ref (self->ui_details->gui);
833 if (empathy_account_settings_is_ready (priv->settings))
834 account_widget_setup_generic (self);
836 g_signal_connect (priv->settings, "notify::ready",
837 G_CALLBACK (account_widget_settings_ready_cb), self);
841 account_widget_build_salut (EmpathyAccountWidget *self,
842 const char *filename)
844 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
846 self->ui_details->gui = empathy_builder_get_file (filename,
847 "table_common_settings", &priv->table_common_settings,
848 "vbox_salut_settings", &self->ui_details->widget,
851 empathy_account_widget_handle_params (self,
852 "entry_published", "published-name",
853 "entry_nickname", "nickname",
854 "entry_first_name", "first-name",
855 "entry_last_name", "last-name",
856 "entry_email", "email",
860 self->ui_details->default_focus = g_strdup ("entry_first_name");
864 account_widget_build_irc (EmpathyAccountWidget *self,
865 const char *filename)
867 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
868 empathy_account_widget_irc_build (self, filename,
869 &priv->table_common_settings);
873 account_widget_build_sip (EmpathyAccountWidget *self,
874 const char *filename)
876 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
877 empathy_account_widget_sip_build (self, filename,
878 &priv->table_common_settings);
882 account_widget_build_msn (EmpathyAccountWidget *self,
883 const char *filename)
885 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
889 self->ui_details->gui = empathy_builder_get_file (filename,
890 "vbox_msn_simple", &self->ui_details->widget,
893 empathy_account_widget_handle_params (self,
894 "entry_id_simple", "account",
895 "entry_password_simple", "password",
898 self->ui_details->default_focus = g_strdup ("entry_id_simple");
902 self->ui_details->gui = empathy_builder_get_file (filename,
903 "table_common_msn_settings", &priv->table_common_settings,
904 "vbox_msn_settings", &self->ui_details->widget,
907 empathy_account_widget_handle_params (self,
908 "entry_id", "account",
909 "entry_password", "password",
910 "entry_server", "server",
911 "spinbutton_port", "port",
914 self->ui_details->default_focus = g_strdup ("entry_id");
915 self->ui_details->add_forget = TRUE;
920 account_widget_is_gtalk (EmpathyAccountWidget *self)
922 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
924 return !tp_strdiff (empathy_account_settings_get_icon_name (priv->settings),
929 account_widget_build_jabber (EmpathyAccountWidget *self,
930 const char *filename)
932 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
933 GtkWidget *spinbutton_port;
934 GtkWidget *checkbutton_ssl;
935 GtkWidget *label_id, *label_password;
936 GtkWidget *label_id_create, *label_password_create;
937 GtkWidget *label_example_gtalk, *label_example_jabber;
940 is_gtalk = account_widget_is_gtalk (self);
942 if (priv->simple && !is_gtalk)
944 self->ui_details->gui = empathy_builder_get_file (filename,
945 "vbox_jabber_simple", &self->ui_details->widget,
946 "label_id_simple", &label_id,
947 "label_id_create", &label_id_create,
948 "label_password_simple", &label_password,
949 "label_password_create", &label_password_create,
952 if (empathy_account_settings_get_boolean (priv->settings, "register"))
954 gtk_widget_hide (label_id);
955 gtk_widget_hide (label_password);
956 gtk_widget_show (label_id_create);
957 gtk_widget_show (label_password_create);
960 empathy_account_widget_handle_params (self,
961 "entry_id_simple", "account",
962 "entry_password_simple", "password",
965 self->ui_details->default_focus = g_strdup ("entry_id_simple");
967 else if (priv->simple && is_gtalk)
969 self->ui_details->gui = empathy_builder_get_file (filename,
970 "vbox_gtalk_simple", &self->ui_details->widget,
973 empathy_account_widget_handle_params (self,
974 "entry_id_g_simple", "account",
975 "entry_password_g_simple", "password",
978 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
982 self->ui_details->gui = empathy_builder_get_file (filename,
983 "table_common_settings", &priv->table_common_settings,
984 "vbox_jabber_settings", &self->ui_details->widget,
985 "spinbutton_port", &spinbutton_port,
986 "checkbutton_ssl", &checkbutton_ssl,
987 "label_username_example", &label_example_jabber,
988 "label_username_g_example", &label_example_gtalk,
991 empathy_account_widget_handle_params (self,
992 "entry_id", "account",
993 "entry_password", "password",
994 "entry_resource", "resource",
995 "entry_server", "server",
996 "spinbutton_port", "port",
997 "spinbutton_priority", "priority",
998 "checkbutton_ssl", "old-ssl",
999 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
1000 "checkbutton_encryption", "require-encryption",
1003 self->ui_details->default_focus = g_strdup ("entry_id");
1004 self->ui_details->add_forget = TRUE;
1005 priv->spinbutton_port = spinbutton_port;
1007 g_signal_connect (checkbutton_ssl, "toggled",
1008 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1013 gtk_widget_hide (label_example_jabber);
1014 gtk_widget_show (label_example_gtalk);
1020 account_widget_build_icq (EmpathyAccountWidget *self,
1021 const char *filename)
1023 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1024 GtkWidget *spinbutton_port;
1028 self->ui_details->gui = empathy_builder_get_file (filename,
1029 "vbox_icq_simple", &self->ui_details->widget,
1032 empathy_account_widget_handle_params (self,
1033 "entry_uin_simple", "account",
1034 "entry_password_simple", "password",
1037 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1041 self->ui_details->gui = empathy_builder_get_file (filename,
1042 "table_common_settings", &priv->table_common_settings,
1043 "vbox_icq_settings", &self->ui_details->widget,
1044 "spinbutton_port", &spinbutton_port,
1047 empathy_account_widget_handle_params (self,
1048 "entry_uin", "account",
1049 "entry_password", "password",
1050 "entry_server", "server",
1051 "spinbutton_port", "port",
1052 "entry_charset", "charset",
1055 self->ui_details->default_focus = g_strdup ("entry_uin");
1056 self->ui_details->add_forget = TRUE;
1061 account_widget_build_aim (EmpathyAccountWidget *self,
1062 const char *filename)
1064 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1065 GtkWidget *spinbutton_port;
1069 self->ui_details->gui = empathy_builder_get_file (filename,
1070 "vbox_aim_simple", &self->ui_details->widget,
1073 empathy_account_widget_handle_params (self,
1074 "entry_screenname_simple", "account",
1075 "entry_password_simple", "password",
1078 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1082 self->ui_details->gui = empathy_builder_get_file (filename,
1083 "table_common_settings", &priv->table_common_settings,
1084 "vbox_aim_settings", &self->ui_details->widget,
1085 "spinbutton_port", &spinbutton_port,
1088 empathy_account_widget_handle_params (self,
1089 "entry_screenname", "account",
1090 "entry_password", "password",
1091 "entry_server", "server",
1092 "spinbutton_port", "port",
1095 self->ui_details->default_focus = g_strdup ("entry_screenname");
1096 self->ui_details->add_forget = TRUE;
1101 account_widget_build_yahoo (EmpathyAccountWidget *self,
1102 const char *filename)
1104 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1108 self->ui_details->gui = empathy_builder_get_file (filename,
1109 "vbox_yahoo_simple", &self->ui_details->widget,
1112 empathy_account_widget_handle_params (self,
1113 "entry_id_simple", "account",
1114 "entry_password_simple", "password",
1117 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1121 self->ui_details->gui = empathy_builder_get_file (filename,
1122 "table_common_settings", &priv->table_common_settings,
1123 "vbox_yahoo_settings", &self->ui_details->widget,
1126 empathy_account_widget_handle_params (self,
1127 "entry_id", "account",
1128 "entry_password", "password",
1129 "entry_server", "server",
1130 "entry_locale", "room-list-locale",
1131 "entry_charset", "charset",
1132 "spinbutton_port", "port",
1133 "checkbutton_yahoojp", "yahoojp",
1134 "checkbutton_ignore_invites", "ignore-invites",
1137 self->ui_details->default_focus = g_strdup ("entry_id");
1138 self->ui_details->add_forget = TRUE;
1143 account_widget_build_groupwise (EmpathyAccountWidget *self,
1144 const char *filename)
1146 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1150 self->ui_details->gui = empathy_builder_get_file (filename,
1151 "vbox_groupwise_simple", &self->ui_details->widget,
1154 empathy_account_widget_handle_params (self,
1155 "entry_id_simple", "account",
1156 "entry_password_simple", "password",
1159 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1163 self->ui_details->gui = empathy_builder_get_file (filename,
1164 "table_common_groupwise_settings", &priv->table_common_settings,
1165 "vbox_groupwise_settings", &self->ui_details->widget,
1168 empathy_account_widget_handle_params (self,
1169 "entry_id", "account",
1170 "entry_password", "password",
1171 "entry_server", "server",
1172 "spinbutton_port", "port",
1175 self->ui_details->default_focus = g_strdup ("entry_id");
1176 self->ui_details->add_forget = TRUE;
1181 account_widget_destroy_cb (GtkWidget *widget,
1182 EmpathyAccountWidget *self)
1184 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1185 /* set the destroyed flag - workaround */
1186 priv->destroyed = TRUE;
1188 g_object_unref (self);
1192 empathy_account_widget_enabled_cb (TpAccount *account,
1196 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1197 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1198 gboolean enabled = tp_account_is_enabled (account);
1200 if (priv->enabled_checkbox != NULL)
1203 nbtk_gtk_light_switch_set_active (
1204 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1207 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1209 #endif /* HAVE_MOBLIN */
1215 account_widget_switch_flipped_cb (NbtkGtkLightSwitch *sw,
1219 account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
1221 #endif /* HAVE_MOBLIN */
1223 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1228 state = gtk_toggle_button_get_active (toggle_button);
1231 account = empathy_account_settings_get_account (priv->settings);
1233 /* Enable the account according to the value of the "Enabled" checkbox */
1234 /* workaround to keep widget alive during async call */
1235 g_object_ref (user_data);
1236 tp_account_set_enabled_async (account, state,
1237 account_widget_account_enabled_cb, user_data);
1241 do_set_property (GObject *object,
1243 const GValue *value,
1246 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1251 priv->settings = g_value_dup_object (value);
1254 priv->simple = g_value_get_boolean (value);
1256 case PROP_CREATING_ACCOUNT:
1257 priv->creating_account = g_value_get_boolean (value);
1260 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1265 do_get_property (GObject *object,
1270 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1275 g_value_set_string (value,
1276 empathy_account_settings_get_protocol (priv->settings));
1279 g_value_set_object (value, priv->settings);
1282 g_value_set_boolean (value, priv->simple);
1284 case PROP_CREATING_ACCOUNT:
1285 g_value_set_boolean (value, priv->creating_account);
1288 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1293 presence_changed_cb (TpAccountManager *manager,
1294 TpConnectionPresenceType state,
1295 const gchar *status,
1296 const gchar *message,
1297 EmpathyAccountWidget *self)
1299 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1301 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
1303 /* We are online, display a Login button */
1306 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1307 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1309 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1310 GTK_ICON_SIZE_BUTTON);
1311 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1315 /* We are offline, display a Save button */
1316 gtk_button_set_image (GTK_BUTTON (priv->apply_button), NULL);
1317 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), TRUE);
1318 gtk_button_set_label (GTK_BUTTON (priv->apply_button), GTK_STOCK_SAVE);
1323 account_manager_ready_cb (GObject *source_object,
1324 GAsyncResult *result,
1327 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1328 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1329 GError *error = NULL;
1330 TpConnectionPresenceType state;
1332 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1334 DEBUG ("Failed to prepare account manager: %s", error->message);
1335 g_error_free (error);
1339 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1342 /* simulate a presence change so the apply button will be changed
1344 presence_changed_cb (account_manager, state, NULL, NULL, self);
1347 #define WIDGET(cm, proto) \
1348 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1349 account_widget_build_##proto }
1352 add_enable_checkbox (EmpathyAccountWidget *self,
1355 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1359 GtkWidget *vbox = self->ui_details->widget;
1361 guint nb_rows, nb_columns;
1362 gboolean is_enabled;
1364 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1365 if (priv->creating_account || priv->table_common_settings == NULL)
1368 is_enabled = tp_account_is_enabled (account);
1371 w = gtk_label_new (_("Account:"));
1372 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1374 priv->enabled_checkbox = nbtk_gtk_light_switch_new ();
1376 nbtk_gtk_light_switch_set_active (
1377 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1379 gtk_widget_show (w);
1381 priv->enabled_checkbox =
1382 gtk_check_button_new_with_label (_("Enabled"));
1384 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1386 #endif /* HAVE_MOBLIN */
1388 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1389 "n-columns", &nb_columns, NULL);
1391 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1395 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1397 0, 1, nb_rows - 1, nb_rows,
1399 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1400 priv->enabled_checkbox,
1401 1, nb_columns, nb_rows - 1, nb_rows,
1402 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1404 gtk_box_pack_start (GTK_BOX (vbox), priv->enabled_checkbox, FALSE, FALSE, 0);
1405 gtk_box_reorder_child (GTK_BOX (vbox), priv->enabled_checkbox, 0);
1406 #endif /* HAVE_MOBLIN */
1408 gtk_widget_show (priv->enabled_checkbox);
1411 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1412 G_CALLBACK (account_widget_switch_flipped_cb), self);
1414 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
1415 G_CALLBACK (account_widget_enabled_released_cb), self);
1416 #endif /* HAVE_MOBLIN */
1420 do_constructed (GObject *obj)
1422 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1423 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1425 const gchar *protocol, *cm_name;
1428 const gchar *cm_name;
1429 const gchar *protocol;
1431 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1433 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1434 account_widget_build_salut },
1435 WIDGET (gabble, jabber),
1436 WIDGET (butterfly, msn),
1439 WIDGET (haze, yahoo),
1440 WIDGET (haze, groupwise),
1442 WIDGET (sofiasip, sip),
1445 cm_name = empathy_account_settings_get_cm (priv->settings);
1446 protocol = empathy_account_settings_get_protocol (priv->settings);
1448 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1450 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1451 !tp_strdiff (widgets[i].protocol, protocol))
1455 filename = empathy_file_lookup (widgets[i].file,
1457 widgets[i].func (self, filename);
1464 if (i == G_N_ELEMENTS (widgets))
1466 gchar *filename = empathy_file_lookup (
1467 "empathy-account-widget-generic.ui", "libempathy-gtk");
1468 account_widget_build_generic (self, filename);
1472 /* handle default focus */
1473 if (self->ui_details->default_focus != NULL)
1475 GObject *default_focus_entry;
1477 default_focus_entry = gtk_builder_get_object
1478 (self->ui_details->gui, self->ui_details->default_focus);
1479 g_signal_connect (default_focus_entry, "realize",
1480 G_CALLBACK (gtk_widget_grab_focus),
1484 /* handle forget button */
1485 if (self->ui_details->add_forget)
1487 const gchar *password = NULL;
1489 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1490 (self->ui_details->gui, "button_forget"));
1491 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1492 (self->ui_details->gui, "entry_password"));
1494 password = empathy_account_settings_get_string (priv->settings,
1496 gtk_widget_set_sensitive (priv->button_forget,
1497 !EMP_STR_EMPTY (password));
1499 g_signal_connect (priv->button_forget, "clicked",
1500 G_CALLBACK (account_widget_forget_clicked_cb),
1502 g_signal_connect (priv->entry_password, "changed",
1503 G_CALLBACK (account_widget_password_changed_cb),
1507 /* dup and init the account-manager */
1508 priv->account_manager = tp_account_manager_dup ();
1510 tp_account_manager_prepare_async (priv->account_manager, NULL,
1511 account_manager_ready_cb, self);
1513 /* handle apply and cancel button */
1516 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1518 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1520 if (priv->creating_account)
1522 /* Assumre we are offline, display a Save button. We'll update
1523 * it once the account manager is ready if needed */
1524 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
1526 empathy_signal_connect_weak (priv->account_manager,
1527 "most-available-presence-changed",
1528 G_CALLBACK (presence_changed_cb), obj);
1532 /* We are editing an existing account, display an Apply button */
1533 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1536 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1538 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1541 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1544 g_signal_connect (priv->cancel_button, "clicked",
1545 G_CALLBACK (account_widget_cancel_clicked_cb),
1547 g_signal_connect (priv->apply_button, "clicked",
1548 G_CALLBACK (account_widget_apply_clicked_cb),
1550 gtk_widget_show_all (hbox);
1552 if (priv->creating_account)
1553 /* When creating an account, the user might have nothing to enter.
1554 * That means that no control interaction might occur,
1555 * so we update the control button sensitivity manually.
1557 account_widget_handle_control_buttons_sensitivity (self);
1559 account_widget_set_control_buttons_sensitivity (self, FALSE);
1562 account = empathy_account_settings_get_account (priv->settings);
1564 if (account != NULL)
1566 g_signal_connect (account, "notify::enabled",
1567 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1570 add_enable_checkbox (self, account);
1572 /* hook up to widget destruction to unref ourselves */
1573 g_signal_connect (self->ui_details->widget, "destroy",
1574 G_CALLBACK (account_widget_destroy_cb), self);
1576 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1577 self->ui_details->widget);
1578 self->ui_details->gui = NULL;
1582 do_dispose (GObject *obj)
1584 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1585 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1587 if (priv->dispose_run)
1590 priv->dispose_run = TRUE;
1592 empathy_account_settings_is_ready (priv->settings);
1594 if (priv->settings != NULL)
1597 account = empathy_account_settings_get_account (priv->settings);
1599 if (account != NULL)
1601 g_signal_handlers_disconnect_by_func (account,
1602 empathy_account_widget_enabled_cb, self);
1605 g_object_unref (priv->settings);
1606 priv->settings = NULL;
1609 if (priv->account_manager != NULL)
1611 g_object_unref (priv->account_manager);
1612 priv->account_manager = NULL;
1615 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1616 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1620 do_finalize (GObject *obj)
1622 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1624 g_free (self->ui_details->default_focus);
1625 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1627 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1628 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1632 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1634 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1635 GParamSpec *param_spec;
1637 oclass->get_property = do_get_property;
1638 oclass->set_property = do_set_property;
1639 oclass->constructed = do_constructed;
1640 oclass->dispose = do_dispose;
1641 oclass->finalize = do_finalize;
1643 param_spec = g_param_spec_string ("protocol",
1644 "protocol", "The protocol of the account",
1646 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1647 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1649 param_spec = g_param_spec_object ("settings",
1650 "settings", "The settings of the account",
1651 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1652 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1653 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1655 param_spec = g_param_spec_boolean ("simple",
1656 "simple", "Whether the account widget is a simple or an advanced one",
1658 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1659 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1661 param_spec = g_param_spec_boolean ("creating-account",
1663 "TRUE if we're creating an account, FALSE if we're modifying it",
1665 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1666 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1668 signals[HANDLE_APPLY] =
1669 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1670 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1671 g_cclosure_marshal_VOID__BOOLEAN,
1675 /* This signal is emitted when an account has been created and enabled. */
1676 signals[ACCOUNT_CREATED] =
1677 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1678 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1679 g_cclosure_marshal_VOID__VOID,
1683 signals[CANCELLED] =
1684 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1685 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1686 g_cclosure_marshal_VOID__VOID,
1690 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1694 empathy_account_widget_init (EmpathyAccountWidget *self)
1696 EmpathyAccountWidgetPriv *priv =
1697 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1698 EmpathyAccountWidgetPriv);
1701 priv->dispose_run = FALSE;
1703 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1706 /* public methods */
1709 empathy_account_widget_discard_pending_changes
1710 (EmpathyAccountWidget *widget)
1712 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1714 empathy_account_settings_discard_changes (priv->settings);
1715 priv->contains_pending_changes = FALSE;
1719 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
1721 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1723 return priv->contains_pending_changes;
1727 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1728 const gchar *first_widget,
1733 va_start (args, first_widget);
1734 account_widget_handle_params_valist (self, first_widget, args);
1739 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1741 return widget->ui_details->widget;
1744 EmpathyAccountWidget *
1745 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1748 EmpathyAccountWidget *self;
1750 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1753 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1754 "settings", settings, "simple", simple,
1756 empathy_account_settings_get_account (settings) == NULL,
1763 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
1765 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1766 const gchar *login_id;
1767 const gchar *protocol, *p;
1768 gchar *default_display_name;
1770 login_id = empathy_account_settings_get_string (priv->settings, "account");
1771 protocol = empathy_account_settings_get_protocol (priv->settings);
1773 if (login_id != NULL)
1775 /* TODO: this should be done in empathy-account-widget-irc */
1776 if (!tp_strdiff (protocol, "irc"))
1778 const gchar* server;
1779 server = empathy_account_settings_get_string (priv->settings,
1782 /* To translators: The first parameter is the login id and the
1783 * second one is the server. The resulting string will be something
1784 * like: "MyUserName on chat.freenode.net".
1785 * You should reverse the order of these arguments if the
1786 * server should come before the login id in your locale.*/
1787 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
1792 default_display_name = g_strdup (login_id);
1795 return default_display_name;
1798 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
1801 if (protocol != NULL)
1803 /* To translators: The parameter is the protocol name. The resulting
1804 * string will be something like: "Jabber Account" */
1805 default_display_name = g_strdup_printf (_("%s Account"), protocol);
1809 default_display_name = g_strdup (_("New account"));
1812 return default_display_name;