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 gtk_toggle_button_get_active (
749 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
751 nbtk_gtk_light_switch_get_active (
752 NBTK_GTK_LIGHT_SWITCH (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_build_jabber (EmpathyAccountWidget *self,
921 const char *filename)
923 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
924 GtkWidget *spinbutton_port;
925 GtkWidget *checkbutton_ssl;
926 GtkWidget *label_id, *label_password;
927 GtkWidget *label_id_create, *label_password_create;
928 GtkWidget *label_example_gtalk, *label_example_jabber;
931 is_gtalk = !tp_strdiff (
932 empathy_account_settings_get_icon_name (priv->settings),
935 if (priv->simple && !is_gtalk)
937 self->ui_details->gui = empathy_builder_get_file (filename,
938 "vbox_jabber_simple", &self->ui_details->widget,
939 "label_id_simple", &label_id,
940 "label_id_create", &label_id_create,
941 "label_password_simple", &label_password,
942 "label_password_create", &label_password_create,
945 if (empathy_account_settings_get_boolean (priv->settings, "register"))
947 gtk_widget_hide (label_id);
948 gtk_widget_hide (label_password);
949 gtk_widget_show (label_id_create);
950 gtk_widget_show (label_password_create);
953 empathy_account_widget_handle_params (self,
954 "entry_id_simple", "account",
955 "entry_password_simple", "password",
958 self->ui_details->default_focus = g_strdup ("entry_id_simple");
960 else if (priv->simple && is_gtalk)
962 self->ui_details->gui = empathy_builder_get_file (filename,
963 "vbox_gtalk_simple", &self->ui_details->widget,
966 empathy_account_widget_handle_params (self,
967 "entry_id_g_simple", "account",
968 "entry_password_g_simple", "password",
971 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
975 self->ui_details->gui = empathy_builder_get_file (filename,
976 "table_common_settings", &priv->table_common_settings,
977 "vbox_jabber_settings", &self->ui_details->widget,
978 "spinbutton_port", &spinbutton_port,
979 "checkbutton_ssl", &checkbutton_ssl,
980 "label_username_example", &label_example_jabber,
981 "label_username_g_example", &label_example_gtalk,
984 empathy_account_widget_handle_params (self,
985 "entry_id", "account",
986 "entry_password", "password",
987 "entry_resource", "resource",
988 "entry_server", "server",
989 "spinbutton_port", "port",
990 "spinbutton_priority", "priority",
991 "checkbutton_ssl", "old-ssl",
992 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
993 "checkbutton_encryption", "require-encryption",
996 self->ui_details->default_focus = g_strdup ("entry_id");
997 self->ui_details->add_forget = TRUE;
998 priv->spinbutton_port = spinbutton_port;
1000 g_signal_connect (checkbutton_ssl, "toggled",
1001 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
1006 gtk_widget_hide (label_example_jabber);
1007 gtk_widget_show (label_example_gtalk);
1013 account_widget_build_icq (EmpathyAccountWidget *self,
1014 const char *filename)
1016 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1017 GtkWidget *spinbutton_port;
1021 self->ui_details->gui = empathy_builder_get_file (filename,
1022 "vbox_icq_simple", &self->ui_details->widget,
1025 empathy_account_widget_handle_params (self,
1026 "entry_uin_simple", "account",
1027 "entry_password_simple", "password",
1030 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1034 self->ui_details->gui = empathy_builder_get_file (filename,
1035 "table_common_settings", &priv->table_common_settings,
1036 "vbox_icq_settings", &self->ui_details->widget,
1037 "spinbutton_port", &spinbutton_port,
1040 empathy_account_widget_handle_params (self,
1041 "entry_uin", "account",
1042 "entry_password", "password",
1043 "entry_server", "server",
1044 "spinbutton_port", "port",
1045 "entry_charset", "charset",
1048 self->ui_details->default_focus = g_strdup ("entry_uin");
1049 self->ui_details->add_forget = TRUE;
1054 account_widget_build_aim (EmpathyAccountWidget *self,
1055 const char *filename)
1057 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1058 GtkWidget *spinbutton_port;
1062 self->ui_details->gui = empathy_builder_get_file (filename,
1063 "vbox_aim_simple", &self->ui_details->widget,
1066 empathy_account_widget_handle_params (self,
1067 "entry_screenname_simple", "account",
1068 "entry_password_simple", "password",
1071 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1075 self->ui_details->gui = empathy_builder_get_file (filename,
1076 "table_common_settings", &priv->table_common_settings,
1077 "vbox_aim_settings", &self->ui_details->widget,
1078 "spinbutton_port", &spinbutton_port,
1081 empathy_account_widget_handle_params (self,
1082 "entry_screenname", "account",
1083 "entry_password", "password",
1084 "entry_server", "server",
1085 "spinbutton_port", "port",
1088 self->ui_details->default_focus = g_strdup ("entry_screenname");
1089 self->ui_details->add_forget = TRUE;
1094 account_widget_build_yahoo (EmpathyAccountWidget *self,
1095 const char *filename)
1097 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1101 self->ui_details->gui = empathy_builder_get_file (filename,
1102 "vbox_yahoo_simple", &self->ui_details->widget,
1105 empathy_account_widget_handle_params (self,
1106 "entry_id_simple", "account",
1107 "entry_password_simple", "password",
1110 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1114 self->ui_details->gui = empathy_builder_get_file (filename,
1115 "table_common_settings", &priv->table_common_settings,
1116 "vbox_yahoo_settings", &self->ui_details->widget,
1119 empathy_account_widget_handle_params (self,
1120 "entry_id", "account",
1121 "entry_password", "password",
1122 "entry_server", "server",
1123 "entry_locale", "room-list-locale",
1124 "entry_charset", "charset",
1125 "spinbutton_port", "port",
1126 "checkbutton_yahoojp", "yahoojp",
1127 "checkbutton_ignore_invites", "ignore-invites",
1130 self->ui_details->default_focus = g_strdup ("entry_id");
1131 self->ui_details->add_forget = TRUE;
1136 account_widget_build_groupwise (EmpathyAccountWidget *self,
1137 const char *filename)
1139 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1143 self->ui_details->gui = empathy_builder_get_file (filename,
1144 "vbox_groupwise_simple", &self->ui_details->widget,
1147 empathy_account_widget_handle_params (self,
1148 "entry_id_simple", "account",
1149 "entry_password_simple", "password",
1152 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1156 self->ui_details->gui = empathy_builder_get_file (filename,
1157 "table_common_groupwise_settings", &priv->table_common_settings,
1158 "vbox_groupwise_settings", &self->ui_details->widget,
1161 empathy_account_widget_handle_params (self,
1162 "entry_id", "account",
1163 "entry_password", "password",
1164 "entry_server", "server",
1165 "spinbutton_port", "port",
1168 self->ui_details->default_focus = g_strdup ("entry_id");
1169 self->ui_details->add_forget = TRUE;
1174 account_widget_destroy_cb (GtkWidget *widget,
1175 EmpathyAccountWidget *self)
1177 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1178 /* set the destroyed flag - workaround */
1179 priv->destroyed = TRUE;
1181 g_object_unref (self);
1185 empathy_account_widget_enabled_cb (TpAccount *account,
1189 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1190 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1191 gboolean enabled = tp_account_is_enabled (account);
1193 if (priv->enabled_checkbox != NULL)
1196 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1199 nbtk_gtk_light_switch_set_active (
1200 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1202 #endif /* HAVE_MOBLIN */
1208 account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
1211 account_widget_switch_flipped_cb (NbtkGtkLightSwitch *sw,
1214 #endif /* HAVE_MOBLIN */
1216 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1221 state = gtk_toggle_button_get_active (toggle_button);
1224 account = empathy_account_settings_get_account (priv->settings);
1226 /* Enable the account according to the value of the "Enabled" checkbox */
1227 /* workaround to keep widget alive during async call */
1228 g_object_ref (user_data);
1229 tp_account_set_enabled_async (account, state,
1230 account_widget_account_enabled_cb, user_data);
1234 do_set_property (GObject *object,
1236 const GValue *value,
1239 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1244 priv->settings = g_value_dup_object (value);
1247 priv->simple = g_value_get_boolean (value);
1249 case PROP_CREATING_ACCOUNT:
1250 priv->creating_account = g_value_get_boolean (value);
1253 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1258 do_get_property (GObject *object,
1263 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1268 g_value_set_string (value,
1269 empathy_account_settings_get_protocol (priv->settings));
1272 g_value_set_object (value, priv->settings);
1275 g_value_set_boolean (value, priv->simple);
1277 case PROP_CREATING_ACCOUNT:
1278 g_value_set_boolean (value, priv->creating_account);
1281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1286 presence_changed_cb (TpAccountManager *manager,
1287 TpConnectionPresenceType state,
1288 const gchar *status,
1289 const gchar *message,
1290 EmpathyAccountWidget *self)
1292 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1294 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
1296 /* We are online, display a Login button */
1299 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1300 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1302 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1303 GTK_ICON_SIZE_BUTTON);
1304 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1308 /* We are offline, display a Save button */
1309 gtk_button_set_image (GTK_BUTTON (priv->apply_button), NULL);
1310 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), TRUE);
1311 gtk_button_set_label (GTK_BUTTON (priv->apply_button), GTK_STOCK_SAVE);
1316 account_manager_ready_cb (GObject *source_object,
1317 GAsyncResult *result,
1320 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1321 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1322 GError *error = NULL;
1323 TpConnectionPresenceType state;
1325 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1327 DEBUG ("Failed to prepare account manager: %s", error->message);
1328 g_error_free (error);
1332 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1335 /* simulate a presence change so the apply button will be changed
1337 presence_changed_cb (account_manager, state, NULL, NULL, self);
1340 #define WIDGET(cm, proto) \
1341 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1342 account_widget_build_##proto }
1345 do_constructed (GObject *obj)
1347 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1348 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1350 const gchar *protocol, *cm_name;
1353 const gchar *cm_name;
1354 const gchar *protocol;
1356 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1358 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1359 account_widget_build_salut },
1360 WIDGET (gabble, jabber),
1361 WIDGET (butterfly, msn),
1364 WIDGET (haze, yahoo),
1365 WIDGET (haze, groupwise),
1367 WIDGET (sofiasip, sip),
1370 cm_name = empathy_account_settings_get_cm (priv->settings);
1371 protocol = empathy_account_settings_get_protocol (priv->settings);
1373 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1375 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1376 !tp_strdiff (widgets[i].protocol, protocol))
1380 filename = empathy_file_lookup (widgets[i].file,
1382 widgets[i].func (self, filename);
1389 if (i == G_N_ELEMENTS (widgets))
1391 gchar *filename = empathy_file_lookup (
1392 "empathy-account-widget-generic.ui", "libempathy-gtk");
1393 account_widget_build_generic (self, filename);
1397 /* handle default focus */
1398 if (self->ui_details->default_focus != NULL)
1400 GObject *default_focus_entry;
1402 default_focus_entry = gtk_builder_get_object
1403 (self->ui_details->gui, self->ui_details->default_focus);
1404 g_signal_connect (default_focus_entry, "realize",
1405 G_CALLBACK (gtk_widget_grab_focus),
1409 /* handle forget button */
1410 if (self->ui_details->add_forget)
1412 const gchar *password = NULL;
1414 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1415 (self->ui_details->gui, "button_forget"));
1416 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1417 (self->ui_details->gui, "entry_password"));
1419 password = empathy_account_settings_get_string (priv->settings,
1421 gtk_widget_set_sensitive (priv->button_forget,
1422 !EMP_STR_EMPTY (password));
1424 g_signal_connect (priv->button_forget, "clicked",
1425 G_CALLBACK (account_widget_forget_clicked_cb),
1427 g_signal_connect (priv->entry_password, "changed",
1428 G_CALLBACK (account_widget_password_changed_cb),
1432 /* dup and init the account-manager */
1433 priv->account_manager = tp_account_manager_dup ();
1435 tp_account_manager_prepare_async (priv->account_manager, NULL,
1436 account_manager_ready_cb, self);
1438 /* handle apply and cancel button */
1441 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1443 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1445 if (priv->creating_account)
1447 /* Assumre we are offline, display a Save button. We'll update
1448 * it once the account manager is ready if needed */
1449 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
1451 empathy_signal_connect_weak (priv->account_manager,
1452 "most-available-presence-changed",
1453 G_CALLBACK (presence_changed_cb), obj);
1457 /* We are editing an existing account, display an Apply button */
1458 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1461 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1463 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1466 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1469 g_signal_connect (priv->cancel_button, "clicked",
1470 G_CALLBACK (account_widget_cancel_clicked_cb),
1472 g_signal_connect (priv->apply_button, "clicked",
1473 G_CALLBACK (account_widget_apply_clicked_cb),
1475 gtk_widget_show_all (hbox);
1477 if (priv->creating_account)
1478 /* When creating an account, the user might have nothing to enter.
1479 * That means that no control interaction might occur,
1480 * so we update the control button sensitivity manually.
1482 account_widget_handle_control_buttons_sensitivity (self);
1484 account_widget_set_control_buttons_sensitivity (self, FALSE);
1487 account = empathy_account_settings_get_account (priv->settings);
1489 if (account != NULL)
1491 g_signal_connect (account, "notify::enabled",
1492 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1495 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1496 if (!priv->creating_account && priv->table_common_settings != NULL)
1501 guint nb_rows, nb_columns;
1502 gboolean is_enabled;
1504 is_enabled = tp_account_is_enabled (account);
1507 priv->enabled_checkbox =
1508 gtk_check_button_new_with_label (_("Enabled"));
1510 gtk_toggle_button_set_active (
1511 GTK_TOGGLE_BUTTON (priv->enabled_checkbox), is_enabled);
1513 /* Translators: this is used only when built on a moblin platform */
1514 w = gtk_label_new (_("Account:"));
1515 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1517 priv->enabled_checkbox = nbtk_gtk_light_switch_new ();
1519 nbtk_gtk_light_switch_set_active (
1520 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1522 gtk_widget_show (w);
1523 #endif /* HAVE_MOBLIN */
1525 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1526 "n-columns", &nb_columns, NULL);
1528 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1532 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1533 priv->enabled_checkbox,
1534 0, nb_columns, nb_rows - 1, nb_rows,
1535 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1537 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1539 0, 1, nb_rows - 1, nb_rows,
1541 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1542 priv->enabled_checkbox,
1543 1, nb_columns, nb_rows - 1, nb_rows,
1544 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1545 #endif /* HAVE_MOBLIN */
1547 gtk_widget_show (priv->enabled_checkbox);
1550 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
1551 G_CALLBACK (account_widget_enabled_released_cb), self);
1553 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1554 G_CALLBACK (account_widget_switch_flipped_cb), self);
1555 #endif /* HAVE_MOBLIN */
1558 /* hook up to widget destruction to unref ourselves */
1559 g_signal_connect (self->ui_details->widget, "destroy",
1560 G_CALLBACK (account_widget_destroy_cb), self);
1562 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1563 self->ui_details->widget);
1564 self->ui_details->gui = NULL;
1568 do_dispose (GObject *obj)
1570 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1571 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1573 if (priv->dispose_run)
1576 priv->dispose_run = TRUE;
1578 empathy_account_settings_is_ready (priv->settings);
1580 if (priv->settings != NULL)
1583 account = empathy_account_settings_get_account (priv->settings);
1585 if (account != NULL)
1587 g_signal_handlers_disconnect_by_func (account,
1588 empathy_account_widget_enabled_cb, self);
1591 g_object_unref (priv->settings);
1592 priv->settings = NULL;
1595 if (priv->account_manager != NULL)
1597 g_object_unref (priv->account_manager);
1598 priv->account_manager = NULL;
1601 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1602 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1606 do_finalize (GObject *obj)
1608 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1610 g_free (self->ui_details->default_focus);
1611 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1613 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1614 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1618 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1620 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1621 GParamSpec *param_spec;
1623 oclass->get_property = do_get_property;
1624 oclass->set_property = do_set_property;
1625 oclass->constructed = do_constructed;
1626 oclass->dispose = do_dispose;
1627 oclass->finalize = do_finalize;
1629 param_spec = g_param_spec_string ("protocol",
1630 "protocol", "The protocol of the account",
1632 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1633 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1635 param_spec = g_param_spec_object ("settings",
1636 "settings", "The settings of the account",
1637 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1638 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1639 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1641 param_spec = g_param_spec_boolean ("simple",
1642 "simple", "Whether the account widget is a simple or an advanced one",
1644 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1645 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1647 param_spec = g_param_spec_boolean ("creating-account",
1649 "TRUE if we're creating an account, FALSE if we're modifying it",
1651 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1652 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1654 signals[HANDLE_APPLY] =
1655 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1656 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1657 g_cclosure_marshal_VOID__BOOLEAN,
1661 /* This signal is emitted when an account has been created and enabled. */
1662 signals[ACCOUNT_CREATED] =
1663 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1664 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1665 g_cclosure_marshal_VOID__VOID,
1669 signals[CANCELLED] =
1670 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1671 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1672 g_cclosure_marshal_VOID__VOID,
1676 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1680 empathy_account_widget_init (EmpathyAccountWidget *self)
1682 EmpathyAccountWidgetPriv *priv =
1683 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1684 EmpathyAccountWidgetPriv);
1687 priv->dispose_run = FALSE;
1689 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1692 /* public methods */
1695 empathy_account_widget_discard_pending_changes
1696 (EmpathyAccountWidget *widget)
1698 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1700 empathy_account_settings_discard_changes (priv->settings);
1701 priv->contains_pending_changes = FALSE;
1705 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
1707 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1709 return priv->contains_pending_changes;
1713 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1714 const gchar *first_widget,
1719 va_start (args, first_widget);
1720 account_widget_handle_params_valist (self, first_widget, args);
1725 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1727 return widget->ui_details->widget;
1730 EmpathyAccountWidget *
1731 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1734 EmpathyAccountWidget *self;
1736 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1739 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1740 "settings", settings, "simple", simple,
1742 empathy_account_settings_get_account (settings) == NULL,
1749 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
1751 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1752 const gchar *login_id;
1753 const gchar *protocol, *p;
1754 gchar *default_display_name;
1756 login_id = empathy_account_settings_get_string (priv->settings, "account");
1757 protocol = empathy_account_settings_get_protocol (priv->settings);
1759 if (login_id != NULL)
1761 /* TODO: this should be done in empathy-account-widget-irc */
1762 if (!tp_strdiff (protocol, "irc"))
1764 const gchar* server;
1765 server = empathy_account_settings_get_string (priv->settings,
1768 /* To translators: The first parameter is the login id and the
1769 * second one is the server. The resulting string will be something
1770 * like: "MyUserName on chat.freenode.net".
1771 * You should reverse the order of these arguments if the
1772 * server should come before the login id in your locale.*/
1773 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
1778 default_display_name = g_strdup (login_id);
1781 return default_display_name;
1784 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
1787 if (protocol != NULL)
1789 /* To translators: The parameter is the protocol name. The resulting
1790 * string will be something like: "Jabber Account" */
1791 default_display_name = g_strdup_printf (_("%s Account"), protocol);
1795 default_display_name = g_strdup (_("New account"));
1798 return default_display_name;