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;
74 /* If we are creating a new account, this member is set to TRUE once the
75 * account has been created */
76 gboolean account_created;
78 /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
79 * embedded in this account widget can't be used any more
80 * workaround because some async callbacks can be called after the
81 * widget has been destroyed */
84 TpAccountManager *account_manager;
87 } EmpathyAccountWidgetPriv;
103 static guint signals[LAST_SIGNAL] = { 0 };
105 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
106 #define CHANGED_TIMEOUT 300
109 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
112 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
116 gtk_widget_set_sensitive (priv->apply_button, sensitive);
117 gtk_widget_set_sensitive (
118 priv->cancel_button, sensitive || priv->creating_account);
120 priv->contains_pending_changes = sensitive;
125 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
127 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
130 is_valid = empathy_account_settings_is_valid (priv->settings);
133 account_widget_set_control_buttons_sensitivity (self, is_valid);
135 g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
139 account_widget_entry_changed_common (EmpathyAccountWidget *self,
140 GtkEntry *entry, gboolean focus)
143 const gchar *param_name;
144 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
146 str = gtk_entry_get_text (entry);
147 param_name = g_object_get_data (G_OBJECT (entry), "param_name");
149 if (EMP_STR_EMPTY (str))
151 const gchar *value = NULL;
153 empathy_account_settings_unset (priv->settings, param_name);
157 value = empathy_account_settings_get_string (priv->settings,
159 DEBUG ("Unset %s and restore to %s", param_name, value);
160 gtk_entry_set_text (entry, value ? value : "");
165 DEBUG ("Setting %s to %s", param_name,
166 tp_strdiff (param_name, "password") ? str : "***");
167 empathy_account_settings_set_string (priv->settings, param_name, str);
172 account_widget_entry_changed_cb (GtkEditable *entry,
173 EmpathyAccountWidget *self)
175 account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
176 account_widget_handle_control_buttons_sensitivity (self);
180 account_widget_int_changed_cb (GtkWidget *widget,
181 EmpathyAccountWidget *self)
183 const gchar *param_name;
185 const gchar *signature;
186 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
188 value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
189 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
191 signature = empathy_account_settings_get_dbus_signature (priv->settings,
193 g_return_if_fail (signature != NULL);
195 DEBUG ("Setting %s to %d", param_name, value);
197 switch ((int)*signature)
199 case DBUS_TYPE_INT16:
200 case DBUS_TYPE_INT32:
201 empathy_account_settings_set_int32 (priv->settings, param_name, value);
203 case DBUS_TYPE_INT64:
204 empathy_account_settings_set_int64 (priv->settings, param_name, value);
206 case DBUS_TYPE_UINT16:
207 case DBUS_TYPE_UINT32:
208 empathy_account_settings_set_uint32 (priv->settings, param_name, value);
210 case DBUS_TYPE_UINT64:
211 empathy_account_settings_set_uint64 (priv->settings, param_name, value);
214 g_return_if_reached ();
217 account_widget_handle_control_buttons_sensitivity (self);
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);
253 account_widget_forget_clicked_cb (GtkWidget *button,
254 EmpathyAccountWidget *self)
256 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
257 const gchar *param_name;
259 param_name = g_object_get_data (G_OBJECT (priv->entry_password),
262 DEBUG ("Unset %s", param_name);
263 empathy_account_settings_unset (priv->settings, param_name);
264 gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
266 account_widget_handle_control_buttons_sensitivity (self);
270 account_widget_password_changed_cb (GtkWidget *entry,
271 EmpathyAccountWidget *self)
273 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
276 str = gtk_entry_get_text (GTK_ENTRY (entry));
277 gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
281 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
282 EmpathyAccountWidget *self)
284 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
288 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
289 port = empathy_account_settings_get_uint32 (priv->settings, "port");
293 if (port == 5222 || port == 0)
298 if (port == 5223 || port == 0)
302 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
306 account_widget_combobox_changed_cb (GtkWidget *widget,
307 EmpathyAccountWidget *self)
313 const gchar *default_value = NULL;
314 const gchar *param_name;
315 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
317 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
320 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
321 /* the param value is stored in the first column */
322 gtk_tree_model_get (model, &iter, 0, &value, -1);
324 param_name = g_object_get_data (G_OBJECT (widget), "param_name");
326 v = empathy_account_settings_get_default (priv->settings, param_name);
328 default_value = g_value_get_string (v);
330 if (!tp_strdiff (value, default_value))
332 DEBUG ("Unset %s and restore to %s", param_name, default_value);
333 empathy_account_settings_unset (priv->settings, param_name);
337 DEBUG ("Setting %s to %s", param_name, value);
338 empathy_account_settings_set_string (priv->settings, param_name, value);
341 account_widget_handle_control_buttons_sensitivity (self);
345 empathy_account_widget_setup_widget (EmpathyAccountWidget *self,
347 const gchar *param_name)
349 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
351 g_object_set_data_full (G_OBJECT (widget), "param_name",
352 g_strdup (param_name), g_free);
354 if (GTK_IS_SPIN_BUTTON (widget))
357 const gchar *signature;
359 signature = empathy_account_settings_get_dbus_signature (priv->settings,
361 g_return_if_fail (signature != NULL);
363 switch ((int)*signature)
365 case DBUS_TYPE_INT16:
366 case DBUS_TYPE_INT32:
367 value = empathy_account_settings_get_int32 (priv->settings,
370 case DBUS_TYPE_INT64:
371 value = empathy_account_settings_get_int64 (priv->settings,
374 case DBUS_TYPE_UINT16:
375 case DBUS_TYPE_UINT32:
376 value = empathy_account_settings_get_uint32 (priv->settings,
379 case DBUS_TYPE_UINT64:
380 value = empathy_account_settings_get_uint64 (priv->settings,
384 g_return_if_reached ();
387 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
389 g_signal_connect (widget, "value-changed",
390 G_CALLBACK (account_widget_int_changed_cb),
393 else if (GTK_IS_ENTRY (widget))
395 const gchar *str = NULL;
397 str = empathy_account_settings_get_string (priv->settings, param_name);
398 gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
400 if (strstr (param_name, "password"))
402 gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
405 g_signal_connect (widget, "changed",
406 G_CALLBACK (account_widget_entry_changed_cb), self);
408 else if (GTK_IS_TOGGLE_BUTTON (widget))
410 gboolean value = FALSE;
412 value = empathy_account_settings_get_boolean (priv->settings,
414 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
416 g_signal_connect (widget, "toggled",
417 G_CALLBACK (account_widget_checkbutton_toggled_cb),
420 else if (GTK_IS_COMBO_BOX (widget))
422 /* The combo box's model has to contain the param value in its first
423 * column (as a string) */
429 str = empathy_account_settings_get_string (priv->settings, param_name);
430 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
432 valid = gtk_tree_model_get_iter_first (model, &iter);
437 gtk_tree_model_get (model, &iter, 0, &name, -1);
438 if (!tp_strdiff (name, str))
440 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
445 valid = gtk_tree_model_iter_next (model, &iter);
451 g_signal_connect (widget, "changed",
452 G_CALLBACK (account_widget_combobox_changed_cb),
457 DEBUG ("Unknown type of widget for param %s", param_name);
462 account_widget_generic_format_param_name (const gchar *param_name)
467 str = g_strdup (param_name);
469 if (str && g_ascii_isalpha (str[0]))
470 str[0] = g_ascii_toupper (str[0]);
472 while ((p = strchr (str, '-')) != NULL)
474 if (p[1] != '\0' && g_ascii_isalpha (p[1]))
477 p[1] = g_ascii_toupper (p[1]);
487 accounts_widget_generic_setup (EmpathyAccountWidget *self,
488 GtkWidget *table_common_settings,
489 GtkWidget *table_advanced_settings)
491 TpConnectionManagerParam *params, *param;
492 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
494 params = empathy_account_settings_get_tp_params (priv->settings);
496 for (param = params; param != NULL && param->name != NULL; param++)
498 GtkWidget *table_settings;
500 GtkWidget *widget = NULL;
501 gchar *param_name_formatted;
503 if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
504 table_settings = table_common_settings;
505 else if (priv->simple)
508 table_settings = table_advanced_settings;
510 param_name_formatted = account_widget_generic_format_param_name
512 g_object_get (table_settings, "n-rows", &n_rows, NULL);
513 gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
515 if (param->dbus_signature[0] == 's')
519 str = g_strdup_printf (_("%s:"), param_name_formatted);
520 widget = gtk_label_new (str);
521 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
524 gtk_table_attach (GTK_TABLE (table_settings),
530 gtk_widget_show (widget);
532 widget = gtk_entry_new ();
533 if (strcmp (param->name, "account") == 0)
535 g_signal_connect (widget, "realize",
536 G_CALLBACK (gtk_widget_grab_focus),
539 gtk_table_attach (GTK_TABLE (table_settings),
543 GTK_FILL | GTK_EXPAND, 0,
545 gtk_widget_show (widget);
547 /* int types: ynqiuxt. double type is 'd' */
548 else if (param->dbus_signature[0] == 'y' ||
549 param->dbus_signature[0] == 'n' ||
550 param->dbus_signature[0] == 'q' ||
551 param->dbus_signature[0] == 'i' ||
552 param->dbus_signature[0] == 'u' ||
553 param->dbus_signature[0] == 'x' ||
554 param->dbus_signature[0] == 't' ||
555 param->dbus_signature[0] == 'd')
562 switch (param->dbus_signature[0])
564 case 'y': minint = G_MININT8; maxint = G_MAXINT8; break;
565 case 'n': minint = G_MININT16; maxint = G_MAXINT16; break;
566 case 'q': minint = 0; maxint = G_MAXUINT16; break;
567 case 'i': minint = G_MININT32; maxint = G_MAXINT32; break;
568 case 'u': minint = 0; maxint = G_MAXUINT32; break;
569 case 'x': minint = G_MININT64; maxint = G_MAXINT64; break;
570 case 't': minint = 0; maxint = G_MAXUINT64; break;
571 case 'd': minint = G_MININT32; maxint = G_MAXINT32;
575 str = g_strdup_printf (_("%s:"), param_name_formatted);
576 widget = gtk_label_new (str);
577 gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
580 gtk_table_attach (GTK_TABLE (table_settings),
586 gtk_widget_show (widget);
588 widget = gtk_spin_button_new_with_range (minint, maxint, step);
589 gtk_table_attach (GTK_TABLE (table_settings),
593 GTK_FILL | GTK_EXPAND, 0,
595 gtk_widget_show (widget);
597 else if (param->dbus_signature[0] == 'b')
599 widget = gtk_check_button_new_with_label (param_name_formatted);
600 gtk_table_attach (GTK_TABLE (table_settings),
604 GTK_FILL | GTK_EXPAND, 0,
606 gtk_widget_show (widget);
610 DEBUG ("Unknown signature for param %s: %s",
611 param_name_formatted, param->dbus_signature);
615 empathy_account_widget_setup_widget (self, widget, param->name);
617 g_free (param_name_formatted);
622 account_widget_handle_params_valist (EmpathyAccountWidget *self,
623 const gchar *first_widget,
629 for (name = first_widget; name; name = va_arg (args, const gchar *))
631 const gchar *param_name;
633 param_name = va_arg (args, const gchar *);
634 object = gtk_builder_get_object (self->ui_details->gui, name);
638 g_warning ("Builder is missing object '%s'.", name);
642 empathy_account_widget_setup_widget (self, GTK_WIDGET (object),
648 account_widget_cancel_clicked_cb (GtkWidget *button,
649 EmpathyAccountWidget *self)
651 g_signal_emit (self, signals[CANCELLED], 0);
655 account_widget_account_enabled_cb (GObject *source_object,
659 GError *error = NULL;
660 TpAccount *account = TP_ACCOUNT (source_object);
661 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
662 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
663 TpConnectionPresenceType presence;
664 gchar *message = NULL;
665 gchar *status = NULL;
667 tp_account_set_enabled_finish (account, res, &error);
671 DEBUG ("Could not enable the account: %s", error->message);
672 g_error_free (error);
676 /* only force presence if presence was offline, unknown or unset */
677 presence = tp_account_get_requested_presence (account, NULL, NULL);
680 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
681 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
682 case TP_CONNECTION_PRESENCE_TYPE_UNSET:
683 presence = tp_account_manager_get_most_available_presence (
684 priv->account_manager, &status, &message);
685 tp_account_request_presence_async (account, presence,
686 status, NULL, NULL, NULL);
689 /* do nothing if the presence is not offline */
694 /* unref widget - part of the workaround */
695 g_object_unref (widget);
701 account_widget_applied_cb (GObject *source_object,
705 GError *error = NULL;
707 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
708 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
709 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
711 empathy_account_settings_apply_finish (settings, res, &error);
715 DEBUG ("Could not apply changes to account: %s", error->message);
716 g_error_free (error);
720 account = empathy_account_settings_get_account (priv->settings);
724 if (priv->creating_account)
726 /* By default, when an account is created, we enable it. */
728 /* workaround to keep widget alive during async call */
729 g_object_ref (widget);
731 tp_account_set_enabled_async (account, TRUE,
732 account_widget_account_enabled_cb, widget);
733 priv->account_created = TRUE;
734 g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
736 else if (priv->enabled_checkbox != NULL)
738 gboolean enabled_checked;
742 gtk_toggle_button_get_active (
743 GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
745 nbtk_gtk_light_switch_get_active (
746 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox));
749 if (tp_account_is_enabled (account) && enabled_checked)
751 /* After having applied changes to a user account, we
752 * automatically reconnect it. This is done so the new
753 * information entered by the user is validated on the server. */
754 tp_account_reconnect_async (account, NULL, NULL);
759 if (!priv->destroyed)
760 account_widget_set_control_buttons_sensitivity (widget, FALSE);
762 /* unref the widget - part of the workaround */
763 g_object_unref (widget);
767 account_widget_apply_clicked_cb (GtkWidget *button,
768 EmpathyAccountWidget *self)
770 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
772 /* workaround to keep widget alive during async call */
774 empathy_account_settings_apply_async (priv->settings,
775 account_widget_applied_cb, self);
779 account_widget_setup_generic (EmpathyAccountWidget *self)
781 GtkWidget *table_common_settings;
782 GtkWidget *table_advanced_settings;
784 table_common_settings = GTK_WIDGET (gtk_builder_get_object
785 (self->ui_details->gui, "table_common_settings"));
786 table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
787 (self->ui_details->gui, "table_advanced_settings"));
789 accounts_widget_generic_setup (self, table_common_settings,
790 table_advanced_settings);
792 g_object_unref (self->ui_details->gui);
796 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
800 EmpathyAccountWidget *self = user_data;
801 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
803 if (empathy_account_settings_is_ready (priv->settings))
804 account_widget_setup_generic (self);
808 account_widget_build_generic (EmpathyAccountWidget *self,
809 const char *filename)
811 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
812 GtkWidget *expander_advanced;
814 self->ui_details->gui = empathy_builder_get_file (filename,
815 "table_common_settings", &priv->table_common_settings,
816 "vbox_generic_settings", &self->ui_details->widget,
817 "expander_advanced_settings", &expander_advanced,
821 gtk_widget_hide (expander_advanced);
823 g_object_ref (self->ui_details->gui);
825 if (empathy_account_settings_is_ready (priv->settings))
826 account_widget_setup_generic (self);
828 g_signal_connect (priv->settings, "notify::ready",
829 G_CALLBACK (account_widget_settings_ready_cb), self);
833 account_widget_build_salut (EmpathyAccountWidget *self,
834 const char *filename)
836 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
838 self->ui_details->gui = empathy_builder_get_file (filename,
839 "table_common_settings", &priv->table_common_settings,
840 "vbox_salut_settings", &self->ui_details->widget,
843 empathy_account_widget_handle_params (self,
844 "entry_published", "published-name",
845 "entry_nickname", "nickname",
846 "entry_first_name", "first-name",
847 "entry_last_name", "last-name",
848 "entry_email", "email",
852 self->ui_details->default_focus = g_strdup ("entry_first_name");
856 account_widget_build_irc (EmpathyAccountWidget *self,
857 const char *filename)
859 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
860 empathy_account_widget_irc_build (self, filename,
861 &priv->table_common_settings);
865 account_widget_build_sip (EmpathyAccountWidget *self,
866 const char *filename)
868 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
869 empathy_account_widget_sip_build (self, filename,
870 &priv->table_common_settings);
874 account_widget_build_msn (EmpathyAccountWidget *self,
875 const char *filename)
877 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
881 self->ui_details->gui = empathy_builder_get_file (filename,
882 "vbox_msn_simple", &self->ui_details->widget,
885 empathy_account_widget_handle_params (self,
886 "entry_id_simple", "account",
887 "entry_password_simple", "password",
890 self->ui_details->default_focus = g_strdup ("entry_id_simple");
894 self->ui_details->gui = empathy_builder_get_file (filename,
895 "table_common_msn_settings", &priv->table_common_settings,
896 "vbox_msn_settings", &self->ui_details->widget,
899 empathy_account_widget_handle_params (self,
900 "entry_id", "account",
901 "entry_password", "password",
902 "entry_server", "server",
903 "spinbutton_port", "port",
906 self->ui_details->default_focus = g_strdup ("entry_id");
907 self->ui_details->add_forget = TRUE;
912 account_widget_build_jabber (EmpathyAccountWidget *self,
913 const char *filename)
915 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
916 GtkWidget *spinbutton_port;
917 GtkWidget *checkbutton_ssl;
918 GtkWidget *label_id, *label_password;
919 GtkWidget *label_id_create, *label_password_create;
920 GtkWidget *label_example_gtalk, *label_example_jabber;
923 is_gtalk = !tp_strdiff (
924 empathy_account_settings_get_icon_name (priv->settings),
927 if (priv->simple && !is_gtalk)
929 self->ui_details->gui = empathy_builder_get_file (filename,
930 "vbox_jabber_simple", &self->ui_details->widget,
931 "label_id_simple", &label_id,
932 "label_id_create", &label_id_create,
933 "label_password_simple", &label_password,
934 "label_password_create", &label_password_create,
937 if (empathy_account_settings_get_boolean (priv->settings, "register"))
939 gtk_widget_hide (label_id);
940 gtk_widget_hide (label_password);
941 gtk_widget_show (label_id_create);
942 gtk_widget_show (label_password_create);
945 empathy_account_widget_handle_params (self,
946 "entry_id_simple", "account",
947 "entry_password_simple", "password",
950 self->ui_details->default_focus = g_strdup ("entry_id_simple");
952 else if (priv->simple && is_gtalk)
954 self->ui_details->gui = empathy_builder_get_file (filename,
955 "vbox_gtalk_simple", &self->ui_details->widget,
958 empathy_account_widget_handle_params (self,
959 "entry_id_g_simple", "account",
960 "entry_password_g_simple", "password",
963 self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
967 self->ui_details->gui = empathy_builder_get_file (filename,
968 "table_common_settings", &priv->table_common_settings,
969 "vbox_jabber_settings", &self->ui_details->widget,
970 "spinbutton_port", &spinbutton_port,
971 "checkbutton_ssl", &checkbutton_ssl,
972 "label_username_example", &label_example_jabber,
973 "label_username_g_example", &label_example_gtalk,
976 empathy_account_widget_handle_params (self,
977 "entry_id", "account",
978 "entry_password", "password",
979 "entry_resource", "resource",
980 "entry_server", "server",
981 "spinbutton_port", "port",
982 "spinbutton_priority", "priority",
983 "checkbutton_ssl", "old-ssl",
984 "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
985 "checkbutton_encryption", "require-encryption",
988 self->ui_details->default_focus = g_strdup ("entry_id");
989 self->ui_details->add_forget = TRUE;
990 priv->spinbutton_port = spinbutton_port;
992 g_signal_connect (checkbutton_ssl, "toggled",
993 G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
998 gtk_widget_hide (label_example_jabber);
999 gtk_widget_show (label_example_gtalk);
1005 account_widget_build_icq (EmpathyAccountWidget *self,
1006 const char *filename)
1008 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1009 GtkWidget *spinbutton_port;
1013 self->ui_details->gui = empathy_builder_get_file (filename,
1014 "vbox_icq_simple", &self->ui_details->widget,
1017 empathy_account_widget_handle_params (self,
1018 "entry_uin_simple", "account",
1019 "entry_password_simple", "password",
1022 self->ui_details->default_focus = g_strdup ("entry_uin_simple");
1026 self->ui_details->gui = empathy_builder_get_file (filename,
1027 "table_common_settings", &priv->table_common_settings,
1028 "vbox_icq_settings", &self->ui_details->widget,
1029 "spinbutton_port", &spinbutton_port,
1032 empathy_account_widget_handle_params (self,
1033 "entry_uin", "account",
1034 "entry_password", "password",
1035 "entry_server", "server",
1036 "spinbutton_port", "port",
1037 "entry_charset", "charset",
1040 self->ui_details->default_focus = g_strdup ("entry_uin");
1041 self->ui_details->add_forget = TRUE;
1046 account_widget_build_aim (EmpathyAccountWidget *self,
1047 const char *filename)
1049 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1050 GtkWidget *spinbutton_port;
1054 self->ui_details->gui = empathy_builder_get_file (filename,
1055 "vbox_aim_simple", &self->ui_details->widget,
1058 empathy_account_widget_handle_params (self,
1059 "entry_screenname_simple", "account",
1060 "entry_password_simple", "password",
1063 self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
1067 self->ui_details->gui = empathy_builder_get_file (filename,
1068 "table_common_settings", &priv->table_common_settings,
1069 "vbox_aim_settings", &self->ui_details->widget,
1070 "spinbutton_port", &spinbutton_port,
1073 empathy_account_widget_handle_params (self,
1074 "entry_screenname", "account",
1075 "entry_password", "password",
1076 "entry_server", "server",
1077 "spinbutton_port", "port",
1080 self->ui_details->default_focus = g_strdup ("entry_screenname");
1081 self->ui_details->add_forget = TRUE;
1086 account_widget_build_yahoo (EmpathyAccountWidget *self,
1087 const char *filename)
1089 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1093 self->ui_details->gui = empathy_builder_get_file (filename,
1094 "vbox_yahoo_simple", &self->ui_details->widget,
1097 empathy_account_widget_handle_params (self,
1098 "entry_id_simple", "account",
1099 "entry_password_simple", "password",
1102 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1106 self->ui_details->gui = empathy_builder_get_file (filename,
1107 "table_common_settings", &priv->table_common_settings,
1108 "vbox_yahoo_settings", &self->ui_details->widget,
1111 empathy_account_widget_handle_params (self,
1112 "entry_id", "account",
1113 "entry_password", "password",
1114 "entry_server", "server",
1115 "entry_locale", "room-list-locale",
1116 "entry_charset", "charset",
1117 "spinbutton_port", "port",
1118 "checkbutton_yahoojp", "yahoojp",
1119 "checkbutton_ignore_invites", "ignore-invites",
1122 self->ui_details->default_focus = g_strdup ("entry_id");
1123 self->ui_details->add_forget = TRUE;
1128 account_widget_build_groupwise (EmpathyAccountWidget *self,
1129 const char *filename)
1131 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1135 self->ui_details->gui = empathy_builder_get_file (filename,
1136 "vbox_groupwise_simple", &self->ui_details->widget,
1139 empathy_account_widget_handle_params (self,
1140 "entry_id_simple", "account",
1141 "entry_password_simple", "password",
1144 self->ui_details->default_focus = g_strdup ("entry_id_simple");
1148 self->ui_details->gui = empathy_builder_get_file (filename,
1149 "table_common_groupwise_settings", &priv->table_common_settings,
1150 "vbox_groupwise_settings", &self->ui_details->widget,
1153 empathy_account_widget_handle_params (self,
1154 "entry_id", "account",
1155 "entry_password", "password",
1156 "entry_server", "server",
1157 "spinbutton_port", "port",
1160 self->ui_details->default_focus = g_strdup ("entry_id");
1161 self->ui_details->add_forget = TRUE;
1166 account_widget_destroy_cb (GtkWidget *widget,
1167 EmpathyAccountWidget *self)
1169 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1170 /* set the destroyed flag - workaround */
1171 priv->destroyed = TRUE;
1173 g_object_unref (self);
1177 empathy_account_widget_enabled_cb (TpAccount *account,
1181 EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1182 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1183 gboolean enabled = tp_account_is_enabled (account);
1185 if (priv->enabled_checkbox != NULL)
1188 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1191 nbtk_gtk_light_switch_set_active (
1192 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox),
1194 #endif /* HAVE_MOBLIN */
1200 account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
1203 account_widget_switch_flipped_cb (NbtkGtkLightSwitch *sw,
1206 #endif /* HAVE_MOBLIN */
1208 EmpathyAccountWidgetPriv *priv = GET_PRIV (user_data);
1213 state = gtk_toggle_button_get_active (toggle_button);
1216 account = empathy_account_settings_get_account (priv->settings);
1218 /* Enable the account according to the value of the "Enabled" checkbox */
1219 /* workaround to keep widget alive during async call */
1220 g_object_ref (user_data);
1221 tp_account_set_enabled_async (account, state,
1222 account_widget_account_enabled_cb, user_data);
1226 do_set_property (GObject *object,
1228 const GValue *value,
1231 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1236 priv->settings = g_value_dup_object (value);
1239 priv->simple = g_value_get_boolean (value);
1241 case PROP_CREATING_ACCOUNT:
1242 priv->creating_account = g_value_get_boolean (value);
1245 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1250 do_get_property (GObject *object,
1255 EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1260 g_value_set_string (value,
1261 empathy_account_settings_get_protocol (priv->settings));
1264 g_value_set_object (value, priv->settings);
1267 g_value_set_boolean (value, priv->simple);
1269 case PROP_CREATING_ACCOUNT:
1270 g_value_set_boolean (value, priv->creating_account);
1273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1278 presence_changed_cb (TpAccountManager *manager,
1279 TpConnectionPresenceType state,
1280 const gchar *status,
1281 const gchar *message,
1282 EmpathyAccountWidget *self)
1284 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1286 if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
1288 /* We are online, display a Login button */
1291 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE);
1292 gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in"));
1294 image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
1295 GTK_ICON_SIZE_BUTTON);
1296 gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
1300 /* We are offline, display a Save button */
1301 gtk_button_set_image (GTK_BUTTON (priv->apply_button), NULL);
1302 gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), TRUE);
1303 gtk_button_set_label (GTK_BUTTON (priv->apply_button), GTK_STOCK_SAVE);
1308 account_manager_ready_cb (GObject *source_object,
1309 GAsyncResult *result,
1312 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data);
1313 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
1314 GError *error = NULL;
1315 TpConnectionPresenceType state;
1317 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
1319 DEBUG ("Failed to prepare account manager: %s", error->message);
1320 g_error_free (error);
1324 state = tp_account_manager_get_most_available_presence (account_manager, NULL,
1327 /* simulate a presence change so the apply button will be changed
1329 presence_changed_cb (account_manager, state, NULL, NULL, self);
1332 #define WIDGET(cm, proto) \
1333 { #cm, #proto, "empathy-account-widget-"#proto".ui", \
1334 account_widget_build_##proto }
1337 do_constructed (GObject *obj)
1339 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1340 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1342 const gchar *protocol, *cm_name;
1345 const gchar *cm_name;
1346 const gchar *protocol;
1348 void (*func)(EmpathyAccountWidget *self, const gchar *filename);
1350 { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
1351 account_widget_build_salut },
1352 WIDGET (gabble, jabber),
1353 WIDGET (butterfly, msn),
1356 WIDGET (haze, yahoo),
1357 WIDGET (haze, groupwise),
1359 WIDGET (sofiasip, sip),
1362 cm_name = empathy_account_settings_get_cm (priv->settings);
1363 protocol = empathy_account_settings_get_protocol (priv->settings);
1365 for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
1367 if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
1368 !tp_strdiff (widgets[i].protocol, protocol))
1372 filename = empathy_file_lookup (widgets[i].file,
1374 widgets[i].func (self, filename);
1381 if (i == G_N_ELEMENTS (widgets))
1383 gchar *filename = empathy_file_lookup (
1384 "empathy-account-widget-generic.ui", "libempathy-gtk");
1385 account_widget_build_generic (self, filename);
1389 /* handle default focus */
1390 if (self->ui_details->default_focus != NULL)
1392 GObject *default_focus_entry;
1394 default_focus_entry = gtk_builder_get_object
1395 (self->ui_details->gui, self->ui_details->default_focus);
1396 g_signal_connect (default_focus_entry, "realize",
1397 G_CALLBACK (gtk_widget_grab_focus),
1401 /* handle forget button */
1402 if (self->ui_details->add_forget)
1404 const gchar *password = NULL;
1406 priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1407 (self->ui_details->gui, "button_forget"));
1408 priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1409 (self->ui_details->gui, "entry_password"));
1411 password = empathy_account_settings_get_string (priv->settings,
1413 gtk_widget_set_sensitive (priv->button_forget,
1414 !EMP_STR_EMPTY (password));
1416 g_signal_connect (priv->button_forget, "clicked",
1417 G_CALLBACK (account_widget_forget_clicked_cb),
1419 g_signal_connect (priv->entry_password, "changed",
1420 G_CALLBACK (account_widget_password_changed_cb),
1424 /* dup and init the account-manager */
1425 priv->account_manager = tp_account_manager_dup ();
1427 tp_account_manager_prepare_async (priv->account_manager, NULL,
1428 account_manager_ready_cb, self);
1430 /* handle apply and cancel button */
1433 GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1435 priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1437 if (priv->creating_account)
1439 /* Assumre we are offline, display a Save button. We'll update
1440 * it once the account manager is ready if needed */
1441 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
1443 empathy_signal_connect_weak (priv->account_manager,
1444 "most-available-presence-changed",
1445 G_CALLBACK (presence_changed_cb), obj);
1449 /* We are editing an existing account, display an Apply button */
1450 priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1453 gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1455 gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1458 gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1461 g_signal_connect (priv->cancel_button, "clicked",
1462 G_CALLBACK (account_widget_cancel_clicked_cb),
1464 g_signal_connect (priv->apply_button, "clicked",
1465 G_CALLBACK (account_widget_apply_clicked_cb),
1467 gtk_widget_show_all (hbox);
1469 if (priv->creating_account)
1470 /* When creating an account, the user might have nothing to enter.
1471 * That means that no control interaction might occur,
1472 * so we update the control button sensitivity manually.
1474 account_widget_handle_control_buttons_sensitivity (self);
1476 account_widget_set_control_buttons_sensitivity (self, FALSE);
1479 account = empathy_account_settings_get_account (priv->settings);
1481 if (account != NULL)
1483 g_signal_connect (account, "notify::enabled",
1484 G_CALLBACK (empathy_account_widget_enabled_cb), self);
1487 /* handle the "Enabled" checkbox. We only add it when modifying an account */
1488 if (!priv->creating_account && priv->table_common_settings != NULL)
1493 guint nb_rows, nb_columns;
1494 gboolean is_enabled;
1496 is_enabled = tp_account_is_enabled (account);
1499 priv->enabled_checkbox =
1500 gtk_check_button_new_with_label (_("Enabled"));
1502 gtk_toggle_button_set_active (
1503 GTK_TOGGLE_BUTTON (priv->enabled_checkbox), is_enabled);
1505 /* Translators: this is used only when built on a moblin platform */
1506 w = gtk_label_new (_("Account:"));
1507 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1509 priv->enabled_checkbox = nbtk_gtk_light_switch_new ();
1511 nbtk_gtk_light_switch_set_active (
1512 NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);
1514 gtk_widget_show (w);
1515 #endif /* HAVE_MOBLIN */
1517 g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1518 "n-columns", &nb_columns, NULL);
1520 gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1524 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1525 priv->enabled_checkbox,
1526 0, nb_columns, nb_rows - 1, nb_rows,
1527 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1529 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1531 0, 1, nb_rows - 1, nb_rows,
1533 gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1534 priv->enabled_checkbox,
1535 1, nb_columns, nb_rows - 1, nb_rows,
1536 GTK_EXPAND | GTK_FILL, 0, 0, 0);
1537 #endif /* HAVE_MOBLIN */
1539 gtk_widget_show (priv->enabled_checkbox);
1542 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
1543 G_CALLBACK (account_widget_enabled_released_cb), self);
1545 g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
1546 G_CALLBACK (account_widget_switch_flipped_cb), self);
1547 #endif /* HAVE_MOBLIN */
1550 /* hook up to widget destruction to unref ourselves */
1551 g_signal_connect (self->ui_details->widget, "destroy",
1552 G_CALLBACK (account_widget_destroy_cb), self);
1554 empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1555 self->ui_details->widget);
1556 self->ui_details->gui = NULL;
1560 do_dispose (GObject *obj)
1562 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1563 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1565 if (priv->dispose_run)
1568 priv->dispose_run = TRUE;
1570 empathy_account_settings_is_ready (priv->settings);
1572 if (priv->settings != NULL)
1575 account = empathy_account_settings_get_account (priv->settings);
1577 if (account != NULL)
1579 g_signal_handlers_disconnect_by_func (account,
1580 empathy_account_widget_enabled_cb, self);
1583 g_object_unref (priv->settings);
1584 priv->settings = NULL;
1587 if (priv->account_manager != NULL)
1589 g_object_unref (priv->account_manager);
1590 priv->account_manager = NULL;
1593 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1594 G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1598 do_finalize (GObject *obj)
1600 EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1602 g_free (self->ui_details->default_focus);
1603 g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1605 if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1606 G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1610 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1612 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1613 GParamSpec *param_spec;
1615 oclass->get_property = do_get_property;
1616 oclass->set_property = do_set_property;
1617 oclass->constructed = do_constructed;
1618 oclass->dispose = do_dispose;
1619 oclass->finalize = do_finalize;
1621 param_spec = g_param_spec_string ("protocol",
1622 "protocol", "The protocol of the account",
1624 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1625 g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1627 param_spec = g_param_spec_object ("settings",
1628 "settings", "The settings of the account",
1629 EMPATHY_TYPE_ACCOUNT_SETTINGS,
1630 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1631 g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1633 param_spec = g_param_spec_boolean ("simple",
1634 "simple", "Whether the account widget is a simple or an advanced one",
1636 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1637 g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1639 param_spec = g_param_spec_boolean ("creating-account",
1641 "TRUE if we're creating an account, FALSE if we're modifying it",
1643 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1644 g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1646 signals[HANDLE_APPLY] =
1647 g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1648 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1649 g_cclosure_marshal_VOID__BOOLEAN,
1653 /* This signal is emitted when an account has been created and enabled. */
1654 signals[ACCOUNT_CREATED] =
1655 g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1656 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1657 g_cclosure_marshal_VOID__VOID,
1661 signals[CANCELLED] =
1662 g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1663 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1664 g_cclosure_marshal_VOID__VOID,
1668 g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1672 empathy_account_widget_init (EmpathyAccountWidget *self)
1674 EmpathyAccountWidgetPriv *priv =
1675 G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1676 EmpathyAccountWidgetPriv);
1679 priv->dispose_run = FALSE;
1681 self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1684 /* public methods */
1687 empathy_account_widget_discard_pending_changes
1688 (EmpathyAccountWidget *widget)
1690 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1692 empathy_account_settings_discard_changes (priv->settings);
1693 priv->contains_pending_changes = FALSE;
1697 empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
1699 EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1701 if (priv->creating_account && !priv->account_created)
1702 /* We always want to warn the user if he's in the process of creating a
1703 * new account which hasn't been actually created yet. */
1706 return priv->contains_pending_changes;
1710 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1711 const gchar *first_widget,
1716 va_start (args, first_widget);
1717 account_widget_handle_params_valist (self, first_widget, args);
1722 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1724 return widget->ui_details->widget;
1727 EmpathyAccountWidget *
1728 empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
1731 EmpathyAccountWidget *self;
1733 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1736 (EMPATHY_TYPE_ACCOUNT_WIDGET,
1737 "settings", settings, "simple", simple,
1739 empathy_account_settings_get_account (settings) == NULL,
1746 empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
1748 EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1749 const gchar *login_id;
1750 const gchar *protocol, *p;
1751 gchar *default_display_name;
1753 login_id = empathy_account_settings_get_string (priv->settings, "account");
1754 protocol = empathy_account_settings_get_protocol (priv->settings);
1756 if (login_id != NULL)
1758 /* TODO: this should be done in empathy-account-widget-irc */
1759 if (!tp_strdiff (protocol, "irc"))
1761 const gchar* server;
1762 server = empathy_account_settings_get_string (priv->settings,
1765 /* To translators: The first parameter is the login id and the
1766 * second one is the server. The resulting string will be something
1767 * like: "MyUserName on chat.freenode.net".
1768 * You should reverse the order of these arguments if the
1769 * server should come before the login id in your locale.*/
1770 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
1775 default_display_name = g_strdup (login_id);
1778 return default_display_name;
1781 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
1784 if (protocol != NULL)
1786 /* To translators: The parameter is the protocol name. The resulting
1787 * string will be something like: "Jabber Account" */
1788 default_display_name = g_strdup_printf (_("%s Account"), protocol);
1792 default_display_name = g_strdup (_("New account"));
1795 return default_display_name;