]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-account-widget.c
Updated Basque language
[empathy.git] / libempathy-gtk / empathy-account-widget.c
1 /*
2  * Copyright (C) 2006-2007 Imendio AB
3  * Copyright (C) 2007-2009 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
19  *
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>
24  */
25
26 #include <config.h>
27
28 #include <string.h>
29
30 #include <gtk/gtk.h>
31 #include <glib/gi18n-lib.h>
32
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-account.h>
35
36 #include <telepathy-glib/connection-manager.h>
37 #include <telepathy-glib/util.h>
38 #include <dbus/dbus-protocol.h>
39
40 #include "empathy-account-widget.h"
41 #include "empathy-account-widget-private.h"
42 #include "empathy-account-widget-sip.h"
43 #include "empathy-account-widget-irc.h"
44 #include "empathy-ui-utils.h"
45
46 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
47 #include <libempathy/empathy-debug.h>
48
49 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT)
50
51 typedef struct {
52   char *protocol;
53   EmpathyAccountSettings *settings;
54
55   GtkWidget *table_common_settings;
56   GtkWidget *apply_button;
57   GtkWidget *cancel_button;
58   GtkWidget *entry_password;
59   GtkWidget *button_forget;
60   GtkWidget *spinbutton_port;
61   GtkWidget *enabled_checkbox;
62
63   gboolean simple;
64
65   /* An EmpathyAccountWidget can be used to either create an account or
66    * modify it. When we are creating an account, this member is set to TRUE */
67   gboolean creating_account;
68
69   gboolean dispose_run;
70 } EmpathyAccountWidgetPriv;
71
72 enum {
73   PROP_PROTOCOL = 1,
74   PROP_SETTINGS,
75   PROP_SIMPLE,
76   PROP_CREATING_ACCOUNT
77 };
78
79 enum {
80   HANDLE_APPLY,
81   ACCOUNT_CREATED,
82   CANCELLED,
83   LAST_SIGNAL
84 };
85
86 static guint signals[LAST_SIGNAL] = { 0 };
87
88 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountWidget)
89 #define CHANGED_TIMEOUT 300
90
91 static void
92 account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
93     gboolean sensitive)
94 {
95   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
96
97   if (!priv->simple)
98     {
99       gtk_widget_set_sensitive (priv->apply_button, sensitive);
100       gtk_widget_set_sensitive (priv->cancel_button, sensitive);
101     }
102 }
103
104 static void
105 account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
106 {
107   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
108   gboolean is_valid;
109
110   is_valid = empathy_account_settings_is_valid (priv->settings);
111
112   if (!priv->simple)
113     {
114       gtk_widget_set_sensitive (priv->apply_button, is_valid);
115       gtk_widget_set_sensitive (priv->cancel_button, is_valid);
116     }
117
118   g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
119 }
120
121 static void
122 account_widget_entry_changed_common (EmpathyAccountWidget *self,
123     GtkEntry *entry, gboolean focus)
124 {
125   const gchar *str;
126   const gchar *param_name;
127   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
128
129   str = gtk_entry_get_text (entry);
130   param_name = g_object_get_data (G_OBJECT (entry), "param_name");
131
132   if (EMP_STR_EMPTY (str))
133     {
134       const gchar *value = NULL;
135
136       empathy_account_settings_unset (priv->settings, param_name);
137
138       if (focus)
139         {
140           value = empathy_account_settings_get_string (priv->settings,
141               param_name);
142           DEBUG ("Unset %s and restore to %s", param_name, value);
143           gtk_entry_set_text (entry, value ? value : "");
144         }
145     }
146   else
147     {
148       DEBUG ("Setting %s to %s", param_name,
149           tp_strdiff (param_name, "password") ? str : "***");
150       empathy_account_settings_set_string (priv->settings, param_name, str);
151     }
152 }
153
154 static gboolean
155 account_widget_entry_focus_cb (GtkWidget *widget,
156     GdkEventFocus *event,
157     EmpathyAccountWidget *self)
158 {
159   account_widget_entry_changed_common (self, GTK_ENTRY (widget), TRUE);
160
161   return FALSE;
162 }
163
164 static void
165 account_widget_entry_changed_cb (GtkEditable *entry,
166     EmpathyAccountWidget *self)
167 {
168   account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE);
169   account_widget_handle_control_buttons_sensitivity (self);
170 }
171
172 static void
173 account_widget_int_changed_cb (GtkWidget *widget,
174     EmpathyAccountWidget *self)
175 {
176   const gchar *param_name;
177   gint value;
178   const gchar *signature;
179   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
180
181   value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
182   param_name = g_object_get_data (G_OBJECT (widget), "param_name");
183
184   signature = empathy_account_settings_get_dbus_signature (priv->settings,
185     param_name);
186   g_return_if_fail (signature != NULL);
187
188   DEBUG ("Setting %s to %d", param_name, value);
189
190   switch ((int)*signature)
191     {
192     case DBUS_TYPE_INT16:
193     case DBUS_TYPE_INT32:
194       empathy_account_settings_set_int32 (priv->settings, param_name, value);
195       break;
196     case DBUS_TYPE_INT64:
197       empathy_account_settings_set_int64 (priv->settings, param_name, value);
198       break;
199     case DBUS_TYPE_UINT16:
200     case DBUS_TYPE_UINT32:
201       empathy_account_settings_set_uint32 (priv->settings, param_name, value);
202       break;
203     case DBUS_TYPE_UINT64:
204       empathy_account_settings_set_uint64 (priv->settings, param_name, value);
205       break;
206     default:
207       g_return_if_reached ();
208     }
209
210   account_widget_handle_control_buttons_sensitivity (self);
211 }
212
213 static void
214 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
215     EmpathyAccountWidget *self)
216 {
217   gboolean     value;
218   gboolean     default_value;
219   const gchar *param_name;
220   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
221
222   value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
223   param_name = g_object_get_data (G_OBJECT (widget), "param_name");
224
225   /* FIXME: This is ugly! checkbox don't have a "not-set" value so we
226    * always unset the param and set the value if different from the
227    * default value. */
228   empathy_account_settings_unset (priv->settings, param_name);
229   default_value = empathy_account_settings_get_boolean (priv->settings,
230       param_name);
231
232   if (default_value == value)
233     {
234       DEBUG ("Unset %s and restore to %d", param_name, default_value);
235     }
236   else
237     {
238       DEBUG ("Setting %s to %d", param_name, value);
239       empathy_account_settings_set_boolean (priv->settings, param_name, value);
240     }
241
242   account_widget_handle_control_buttons_sensitivity (self);
243 }
244
245 static void
246 account_widget_forget_clicked_cb (GtkWidget *button,
247     EmpathyAccountWidget *self)
248 {
249   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
250   const gchar *param_name;
251
252   param_name = g_object_get_data (G_OBJECT (priv->entry_password),
253       "param_name");
254
255   DEBUG ("Unset %s", param_name);
256   empathy_account_settings_unset (priv->settings, param_name);
257   gtk_entry_set_text (GTK_ENTRY (priv->entry_password), "");
258
259   account_widget_handle_control_buttons_sensitivity (self);
260 }
261
262 static void
263 account_widget_password_changed_cb (GtkWidget *entry,
264     EmpathyAccountWidget *self)
265 {
266   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
267   const gchar *str;
268
269   str = gtk_entry_get_text (GTK_ENTRY (entry));
270   gtk_widget_set_sensitive (priv->button_forget, !EMP_STR_EMPTY (str));
271 }
272
273 static void
274 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
275     EmpathyAccountWidget *self)
276 {
277   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
278   gboolean   value;
279   gint32       port = 0;
280
281   value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
282   port = empathy_account_settings_get_uint32 (priv->settings, "port");
283
284   if (value)
285     {
286       if (port == 5222 || port == 0)
287         port = 5223;
288     }
289   else
290     {
291       if (port == 5223 || port == 0)
292         port = 5222;
293     }
294
295   gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spinbutton_port), port);
296 }
297
298 static void
299 account_widget_setup_widget (EmpathyAccountWidget *self,
300     GtkWidget *widget,
301     const gchar *param_name)
302 {
303   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
304
305   g_object_set_data_full (G_OBJECT (widget), "param_name",
306       g_strdup (param_name), g_free);
307
308   if (GTK_IS_SPIN_BUTTON (widget))
309     {
310       gint value = 0;
311       const gchar *signature;
312
313       signature = empathy_account_settings_get_dbus_signature (priv->settings,
314           param_name);
315       g_return_if_fail (signature != NULL);
316
317       switch ((int)*signature)
318         {
319           case DBUS_TYPE_INT16:
320           case DBUS_TYPE_INT32:
321             value = empathy_account_settings_get_int32 (priv->settings,
322               param_name);
323             break;
324           case DBUS_TYPE_INT64:
325             value = empathy_account_settings_get_int64 (priv->settings,
326               param_name);
327             break;
328           case DBUS_TYPE_UINT16:
329           case DBUS_TYPE_UINT32:
330             value = empathy_account_settings_get_uint32 (priv->settings,
331               param_name);
332             break;
333           case DBUS_TYPE_UINT64:
334             value = empathy_account_settings_get_uint64 (priv->settings,
335                 param_name);
336             break;
337           default:
338             g_return_if_reached ();
339         }
340
341       gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
342
343       g_signal_connect (widget, "value-changed",
344           G_CALLBACK (account_widget_int_changed_cb),
345           self);
346     }
347   else if (GTK_IS_ENTRY (widget))
348     {
349       const gchar *str = NULL;
350
351       str = empathy_account_settings_get_string (priv->settings, param_name);
352       gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
353
354       if (strstr (param_name, "password"))
355         {
356           gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
357         }
358
359       g_signal_connect (widget, "focus-out-event",
360           G_CALLBACK (account_widget_entry_focus_cb),
361           self);
362       g_signal_connect (widget, "changed",
363           G_CALLBACK (account_widget_entry_changed_cb), self);
364     }
365   else if (GTK_IS_TOGGLE_BUTTON (widget))
366     {
367       gboolean value = FALSE;
368
369       value = empathy_account_settings_get_boolean (priv->settings,
370           param_name);
371       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
372
373       g_signal_connect (widget, "toggled",
374           G_CALLBACK (account_widget_checkbutton_toggled_cb),
375           self);
376     }
377   else
378     {
379       DEBUG ("Unknown type of widget for param %s", param_name);
380     }
381 }
382
383 static gchar *
384 account_widget_generic_format_param_name (const gchar *param_name)
385 {
386   gchar *str;
387   gchar *p;
388
389   str = g_strdup (param_name);
390
391   if (str && g_ascii_isalpha (str[0]))
392     str[0] = g_ascii_toupper (str[0]);
393
394   while ((p = strchr (str, '-')) != NULL)
395     {
396       if (p[1] != '\0' && g_ascii_isalpha (p[1]))
397         {
398           p[0] = ' ';
399           p[1] = g_ascii_toupper (p[1]);
400         }
401
402       p++;
403     }
404
405   return str;
406 }
407
408 static void
409 accounts_widget_generic_setup (EmpathyAccountWidget *self,
410     GtkWidget *table_common_settings,
411     GtkWidget *table_advanced_settings)
412 {
413   TpConnectionManagerParam *params, *param;
414   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
415
416   params = empathy_account_settings_get_tp_params (priv->settings);
417
418   for (param = params; param != NULL && param->name != NULL; param++)
419     {
420       GtkWidget       *table_settings;
421       guint            n_rows = 0;
422       GtkWidget       *widget = NULL;
423       gchar           *param_name_formatted;
424
425       if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
426         table_settings = table_common_settings;
427       else if (priv->simple)
428         return;
429       else
430         table_settings = table_advanced_settings;
431
432       param_name_formatted = account_widget_generic_format_param_name
433         (param->name);
434       g_object_get (table_settings, "n-rows", &n_rows, NULL);
435       gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
436
437       if (param->dbus_signature[0] == 's')
438         {
439           gchar *str;
440
441           str = g_strdup_printf (_("%s:"), param_name_formatted);
442           widget = gtk_label_new (str);
443           gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
444           g_free (str);
445
446           gtk_table_attach (GTK_TABLE (table_settings),
447               widget,
448               0, 1,
449               n_rows - 1, n_rows,
450               GTK_FILL, 0,
451               0, 0);
452           gtk_widget_show (widget);
453
454           widget = gtk_entry_new ();
455           if (strcmp (param->name, "account") == 0)
456             {
457               g_signal_connect (widget, "realize",
458                   G_CALLBACK (gtk_widget_grab_focus),
459                   NULL);
460             }
461           gtk_table_attach (GTK_TABLE (table_settings),
462               widget,
463               1, 2,
464               n_rows - 1, n_rows,
465               GTK_FILL | GTK_EXPAND, 0,
466               0, 0);
467           gtk_widget_show (widget);
468         }
469       /* int types: ynqiuxt. double type is 'd' */
470       else if (param->dbus_signature[0] == 'y' ||
471           param->dbus_signature[0] == 'n' ||
472           param->dbus_signature[0] == 'q' ||
473           param->dbus_signature[0] == 'i' ||
474           param->dbus_signature[0] == 'u' ||
475           param->dbus_signature[0] == 'x' ||
476           param->dbus_signature[0] == 't' ||
477           param->dbus_signature[0] == 'd')
478         {
479           gchar   *str = NULL;
480           gdouble  minint = 0;
481           gdouble  maxint = 0;
482           gdouble  step = 1;
483
484           switch (param->dbus_signature[0])
485             {
486             case 'y': minint = G_MININT8;  maxint = G_MAXINT8;   break;
487             case 'n': minint = G_MININT16; maxint = G_MAXINT16;  break;
488             case 'q': minint = 0;          maxint = G_MAXUINT16; break;
489             case 'i': minint = G_MININT32; maxint = G_MAXINT32;  break;
490             case 'u': minint = 0;          maxint = G_MAXUINT32; break;
491             case 'x': minint = G_MININT64; maxint = G_MAXINT64;  break;
492             case 't': minint = 0;          maxint = G_MAXUINT64; break;
493             case 'd': minint = G_MININT32; maxint = G_MAXINT32;
494               step = 0.1; break;
495             }
496
497           str = g_strdup_printf (_("%s:"), param_name_formatted);
498           widget = gtk_label_new (str);
499           gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
500           g_free (str);
501
502           gtk_table_attach (GTK_TABLE (table_settings),
503               widget,
504               0, 1,
505               n_rows - 1, n_rows,
506               GTK_FILL, 0,
507               0, 0);
508           gtk_widget_show (widget);
509
510           widget = gtk_spin_button_new_with_range (minint, maxint, step);
511           gtk_table_attach (GTK_TABLE (table_settings),
512               widget,
513               1, 2,
514               n_rows - 1, n_rows,
515               GTK_FILL | GTK_EXPAND, 0,
516               0, 0);
517           gtk_widget_show (widget);
518         }
519       else if (param->dbus_signature[0] == 'b')
520         {
521           widget = gtk_check_button_new_with_label (param_name_formatted);
522           gtk_table_attach (GTK_TABLE (table_settings),
523               widget,
524               0, 2,
525               n_rows - 1, n_rows,
526               GTK_FILL | GTK_EXPAND, 0,
527               0, 0);
528           gtk_widget_show (widget);
529         }
530       else
531         {
532           DEBUG ("Unknown signature for param %s: %s",
533               param_name_formatted, param->dbus_signature);
534         }
535
536       if (widget)
537         account_widget_setup_widget (self, widget, param->name);
538
539       g_free (param_name_formatted);
540     }
541 }
542
543 static void
544 account_widget_handle_params_valist (EmpathyAccountWidget *self,
545     const gchar *first_widget,
546     va_list args)
547 {
548   GObject *object;
549   const gchar *name;
550
551   for (name = first_widget; name; name = va_arg (args, const gchar *))
552     {
553       const gchar *param_name;
554
555       param_name = va_arg (args, const gchar *);
556       object = gtk_builder_get_object (self->ui_details->gui, name);
557
558       if (!object)
559         {
560           g_warning ("Builder is missing object '%s'.", name);
561           continue;
562         }
563
564       account_widget_setup_widget (self, GTK_WIDGET (object), param_name);
565     }
566 }
567
568 static void
569 account_widget_cancel_clicked_cb (GtkWidget *button,
570     EmpathyAccountWidget *self)
571 {
572   g_signal_emit (self, signals[CANCELLED], 0);
573 }
574
575 static void
576 account_widget_account_enabled_cb (GObject *source_object,
577     GAsyncResult *res,
578     gpointer user_data)
579 {
580   GError *error = NULL;
581   EmpathyAccount *account = EMPATHY_ACCOUNT (source_object);
582   EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
583
584   empathy_account_set_enabled_finish (account, res, &error);
585
586   if (error != NULL)
587     {
588       DEBUG ("Could not automatically enable new account: %s", error->message);
589       g_error_free (error);
590     }
591   else
592     {
593       g_signal_emit (widget, signals[ACCOUNT_CREATED], 0);
594     }
595 }
596
597 static void
598 account_widget_applied_cb (GObject *source_object,
599     GAsyncResult *res,
600     gpointer user_data)
601 {
602   GError *error = NULL;
603   EmpathyAccount *account;
604   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
605   EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
606   EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
607
608   empathy_account_settings_apply_finish (settings, res, &error);
609
610   if (error != NULL)
611     {
612       DEBUG ("Could not apply changes to account: %s", error->message);
613       g_error_free (error);
614       return;
615     }
616
617   account = empathy_account_settings_get_account (priv->settings);
618
619   if (account != NULL)
620     {
621       if (priv->creating_account)
622         {
623           /* By default, when an account is created, we enable it. */
624           empathy_account_set_enabled_async (account, TRUE,
625               account_widget_account_enabled_cb, widget);
626         }
627       else if (priv->enabled_checkbox != NULL)
628         {
629           gboolean enabled_checked;
630
631           enabled_checked = gtk_toggle_button_get_active (
632               GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
633
634           if (empathy_account_is_enabled (account) && enabled_checked)
635             {
636               /* After having applied changes to a user account, we
637                * automatically reconnect it. This is done so the new
638                * information entered by the user is validated on the server. */
639               empathy_account_reconnect_async (account, NULL, NULL);
640             }
641           else
642             {
643               /* The account is disabled so we enable it according to the value
644                * of the "Enabled" checkbox */
645               empathy_account_set_enabled_async (account, enabled_checked,
646                   NULL, NULL);
647             }
648         }
649     }
650
651   account_widget_set_control_buttons_sensitivity (widget, FALSE);
652 }
653
654 static void
655 account_widget_apply_clicked_cb (GtkWidget *button,
656     EmpathyAccountWidget *self)
657 {
658   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
659
660   empathy_account_settings_apply_async (priv->settings,
661       account_widget_applied_cb, self);
662 }
663
664 static void
665 account_widget_setup_generic (EmpathyAccountWidget *self)
666 {
667   GtkWidget *table_common_settings;
668   GtkWidget *table_advanced_settings;
669
670   table_common_settings = GTK_WIDGET (gtk_builder_get_object
671       (self->ui_details->gui, "table_common_settings"));
672   table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
673       (self->ui_details->gui, "table_advanced_settings"));
674
675   accounts_widget_generic_setup (self, table_common_settings,
676       table_advanced_settings);
677
678   g_object_unref (self->ui_details->gui);
679 }
680
681 static void
682 account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
683     GParamSpec *pspec,
684     gpointer user_data)
685 {
686   EmpathyAccountWidget *self = user_data;
687   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
688
689   if (empathy_account_settings_is_ready (priv->settings))
690     account_widget_setup_generic (self);
691 }
692
693 static void
694 account_widget_build_generic (EmpathyAccountWidget *self,
695     const char *filename)
696 {
697   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
698   GtkWidget *expander_advanced;
699
700   self->ui_details->gui = empathy_builder_get_file (filename,
701       "table_common_settings", &priv->table_common_settings,
702       "vbox_generic_settings", &self->ui_details->widget,
703       "expander_advanced_settings", &expander_advanced,
704       NULL);
705
706   if (priv->simple)
707     gtk_widget_hide (expander_advanced);
708
709   g_object_ref (self->ui_details->gui);
710
711   if (empathy_account_settings_is_ready (priv->settings))
712     account_widget_setup_generic (self);
713   else
714     g_signal_connect (priv->settings, "notify::ready",
715         G_CALLBACK (account_widget_settings_ready_cb), self);
716 }
717
718 static void
719 account_widget_build_salut (EmpathyAccountWidget *self,
720     const char *filename)
721 {
722   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
723
724   self->ui_details->gui = empathy_builder_get_file (filename,
725       "table_common_settings", &priv->table_common_settings,
726       "vbox_salut_settings", &self->ui_details->widget,
727       NULL);
728
729   empathy_account_widget_handle_params (self,
730       "entry_published", "published-name",
731       "entry_nickname", "nickname",
732       "entry_first_name", "first-name",
733       "entry_last_name", "last-name",
734       "entry_email", "email",
735       "entry_jid", "jid",
736       NULL);
737
738   self->ui_details->default_focus = g_strdup ("entry_nickname");
739 }
740
741 static void
742 account_widget_build_msn (EmpathyAccountWidget *self,
743     const char *filename)
744 {
745   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
746
747   if (priv->simple)
748     {
749       self->ui_details->gui = empathy_builder_get_file (filename,
750           "vbox_msn_simple", &self->ui_details->widget,
751           NULL);
752
753       empathy_account_widget_handle_params (self,
754           "entry_id_simple", "account",
755           "entry_password_simple", "password",
756           NULL);
757
758       self->ui_details->default_focus = g_strdup ("entry_id_simple");
759     }
760   else
761     {
762       self->ui_details->gui = empathy_builder_get_file (filename,
763           "table_common_msn_settings", &priv->table_common_settings,
764           "vbox_msn_settings", &self->ui_details->widget,
765           NULL);
766
767       empathy_account_widget_handle_params (self,
768           "entry_id", "account",
769           "entry_password", "password",
770           "entry_server", "server",
771           "spinbutton_port", "port",
772           NULL);
773
774       self->ui_details->default_focus = g_strdup ("entry_id");
775       self->ui_details->add_forget = TRUE;
776     }
777 }
778
779 static void
780 account_widget_build_jabber (EmpathyAccountWidget *self,
781     const char *filename)
782 {
783   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
784   GtkWidget *spinbutton_port;
785   GtkWidget *checkbutton_ssl;
786   GtkWidget *label_id, *label_password;
787   GtkWidget *label_id_create, *label_password_create;
788
789   if (priv->simple)
790     {
791       self->ui_details->gui = empathy_builder_get_file (filename,
792           "vbox_jabber_simple", &self->ui_details->widget,
793           "label_id_simple", &label_id,
794           "label_id_create", &label_id_create,
795           "label_password_simple", &label_password,
796           "label_password_create", &label_password_create,
797           NULL);
798
799       if (empathy_account_settings_get_boolean (priv->settings, "register"))
800         {
801           gtk_widget_hide (label_id);
802           gtk_widget_hide (label_password);
803           gtk_widget_show (label_id_create);
804           gtk_widget_show (label_password_create);
805         }
806
807       empathy_account_widget_handle_params (self,
808           "entry_id_simple", "account",
809           "entry_password_simple", "password",
810           NULL);
811
812       self->ui_details->default_focus = g_strdup ("entry_id_simple");
813     }
814   else
815     {
816       self->ui_details->gui = empathy_builder_get_file (filename,
817           "table_common_settings", &priv->table_common_settings,
818           "vbox_jabber_settings", &self->ui_details->widget,
819           "spinbutton_port", &spinbutton_port,
820           "checkbutton_ssl", &checkbutton_ssl,
821           NULL);
822
823       empathy_account_widget_handle_params (self,
824           "entry_id", "account",
825           "entry_password", "password",
826           "entry_resource", "resource",
827           "entry_server", "server",
828           "spinbutton_port", "port",
829           "spinbutton_priority", "priority",
830           "checkbutton_ssl", "old-ssl",
831           "checkbutton_ignore_ssl_errors", "ignore-ssl-errors",
832           "checkbutton_encryption", "require-encryption",
833           NULL);
834
835       self->ui_details->default_focus = g_strdup ("entry_id");
836       self->ui_details->add_forget = TRUE;
837       priv->spinbutton_port = spinbutton_port;
838
839       g_signal_connect (checkbutton_ssl, "toggled",
840           G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
841           self);
842     }
843 }
844
845 static void
846 account_widget_build_icq (EmpathyAccountWidget *self,
847     const char *filename)
848 {
849   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
850   GtkWidget *spinbutton_port;
851
852   if (priv->simple)
853     {
854       self->ui_details->gui = empathy_builder_get_file (filename,
855           "vbox_icq_simple", &self->ui_details->widget,
856           NULL);
857
858       empathy_account_widget_handle_params (self,
859           "entry_uin_simple", "account",
860           "entry_password_simple", "password",
861           NULL);
862
863       self->ui_details->default_focus = g_strdup ("entry_uin_simple");
864     }
865   else
866     {
867       self->ui_details->gui = empathy_builder_get_file (filename,
868           "table_common_settings", &priv->table_common_settings,
869           "vbox_icq_settings", &self->ui_details->widget,
870           "spinbutton_port", &spinbutton_port,
871           NULL);
872
873       empathy_account_widget_handle_params (self,
874           "entry_uin", "account",
875           "entry_password", "password",
876           "entry_server", "server",
877           "spinbutton_port", "port",
878           "entry_charset", "charset",
879           NULL);
880
881       self->ui_details->default_focus = g_strdup ("entry_uin");
882       self->ui_details->add_forget = TRUE;
883     }
884 }
885
886 static void
887 account_widget_build_aim (EmpathyAccountWidget *self,
888     const char *filename)
889 {
890   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
891   GtkWidget *spinbutton_port;
892
893   if (priv->simple)
894     {
895       self->ui_details->gui = empathy_builder_get_file (filename,
896           "vbox_aim_simple", &self->ui_details->widget,
897           NULL);
898
899       empathy_account_widget_handle_params (self,
900           "entry_screenname_simple", "account",
901           "entry_password_simple", "password",
902           NULL);
903
904       self->ui_details->default_focus = g_strdup ("entry_screenname_simple");
905     }
906   else
907     {
908       self->ui_details->gui = empathy_builder_get_file (filename,
909           "table_common_settings", &priv->table_common_settings,
910           "vbox_aim_settings", &self->ui_details->widget,
911           "spinbutton_port", &spinbutton_port,
912           NULL);
913
914       empathy_account_widget_handle_params (self,
915           "entry_screenname", "account",
916           "entry_password", "password",
917           "entry_server", "server",
918           "spinbutton_port", "port",
919           NULL);
920
921       self->ui_details->default_focus = g_strdup ("entry_screenname");
922       self->ui_details->add_forget = TRUE;
923     }
924 }
925
926 static void
927 account_widget_build_yahoo (EmpathyAccountWidget *self,
928     const char *filename)
929 {
930   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
931
932   if (priv->simple)
933     {
934       self->ui_details->gui = empathy_builder_get_file (filename,
935           "vbox_yahoo_simple", &self->ui_details->widget,
936           NULL);
937
938       empathy_account_widget_handle_params (self,
939           "entry_id_simple", "account",
940           "entry_password_simple", "password",
941           NULL);
942
943       self->ui_details->default_focus = g_strdup ("entry_id_simple");
944     }
945   else
946     {
947       self->ui_details->gui = empathy_builder_get_file (filename,
948           "table_common_settings", &priv->table_common_settings,
949           "vbox_yahoo_settings", &self->ui_details->widget,
950           NULL);
951
952       empathy_account_widget_handle_params (self,
953           "entry_id", "account",
954           "entry_password", "password",
955           "entry_server", "server",
956           "entry_locale", "room-list-locale",
957           "entry_charset", "charset",
958           "spinbutton_port", "port",
959           "checkbutton_yahoojp", "yahoojp",
960           "checkbutton_ignore_invites", "ignore-invites",
961           NULL);
962
963       self->ui_details->default_focus = g_strdup ("entry_id");
964       self->ui_details->add_forget = TRUE;
965     }
966 }
967
968 static void
969 account_widget_build_groupwise (EmpathyAccountWidget *self,
970     const char *filename)
971 {
972   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
973
974   if (priv->simple)
975     {
976       self->ui_details->gui = empathy_builder_get_file (filename,
977           "vbox_groupwise_simple", &self->ui_details->widget,
978           NULL);
979
980       empathy_account_widget_handle_params (self,
981           "entry_id_simple", "account",
982           "entry_password_simple", "password",
983           NULL);
984
985       self->ui_details->default_focus = g_strdup ("entry_id_simple");
986     }
987   else
988     {
989       self->ui_details->gui = empathy_builder_get_file (filename,
990           "table_common_groupwise_settings", &priv->table_common_settings,
991           "vbox_groupwise_settings", &self->ui_details->widget,
992           NULL);
993
994       empathy_account_widget_handle_params (self,
995           "entry_id", "account",
996           "entry_password", "password",
997           "entry_server", "server",
998           "spinbutton_port", "port",
999           NULL);
1000
1001       self->ui_details->default_focus = g_strdup ("entry_id");
1002       self->ui_details->add_forget = TRUE;
1003     }
1004 }
1005
1006 static void
1007 account_widget_destroy_cb (GtkWidget *widget,
1008     EmpathyAccountWidget *self)
1009 {
1010   g_object_unref (self);
1011 }
1012
1013 static void
1014 empathy_account_widget_enabled_cb (EmpathyAccount *account,
1015       GParamSpec *spec,
1016       gpointer user_data)
1017 {
1018   EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
1019   EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
1020   gboolean enabled = empathy_account_is_enabled (account);
1021
1022   if (priv->enabled_checkbox != NULL)
1023     {
1024       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1025           enabled);
1026     }
1027 }
1028
1029 static void
1030 account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
1031     gpointer user_data)
1032 {
1033   account_widget_handle_control_buttons_sensitivity (
1034       EMPATHY_ACCOUNT_WIDGET (user_data));
1035 }
1036
1037 static void
1038 do_set_property (GObject *object,
1039     guint prop_id,
1040     const GValue *value,
1041     GParamSpec *pspec)
1042 {
1043   EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1044
1045   switch (prop_id)
1046     {
1047     case PROP_PROTOCOL:
1048       priv->protocol = g_value_dup_string (value);
1049       break;
1050     case PROP_SETTINGS:
1051       priv->settings = g_value_dup_object (value);
1052       break;
1053     case PROP_SIMPLE:
1054       priv->simple = g_value_get_boolean (value);
1055       break;
1056     case PROP_CREATING_ACCOUNT:
1057       priv->creating_account = g_value_get_boolean (value);
1058       break;
1059     default:
1060       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1061     }
1062 }
1063
1064 static void
1065 do_get_property (GObject *object,
1066     guint prop_id,
1067     GValue *value,
1068     GParamSpec *pspec)
1069 {
1070   EmpathyAccountWidgetPriv *priv = GET_PRIV (object);
1071
1072   switch (prop_id)
1073     {
1074     case PROP_PROTOCOL:
1075       g_value_set_string (value, priv->protocol);
1076       break;
1077     case PROP_SETTINGS:
1078       g_value_set_object (value, priv->settings);
1079       break;
1080     case PROP_SIMPLE:
1081       g_value_set_boolean (value, priv->simple);
1082       break;
1083     case PROP_CREATING_ACCOUNT:
1084       g_value_set_boolean (value, priv->creating_account);
1085       break;
1086     default:
1087       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1088     }
1089 }
1090
1091 static void
1092 do_constructed (GObject *obj)
1093 {
1094   EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1095   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1096   EmpathyAccount *account;
1097   char *uiname, *filename;
1098
1099   uiname = g_strconcat ("empathy-account-widget-", priv->protocol,
1100       ".ui", NULL);
1101   filename = empathy_file_lookup (uiname, "libempathy-gtk");
1102
1103   if (!tp_strdiff (priv->protocol, "local-xmpp"))
1104     account_widget_build_salut (self, filename);
1105   else if (!tp_strdiff (priv->protocol, "msn"))
1106     account_widget_build_msn (self, filename);
1107   else if (!tp_strdiff (priv->protocol, "jabber"))
1108     account_widget_build_jabber (self, filename);
1109   else if (!tp_strdiff (priv->protocol, "icq"))
1110     account_widget_build_icq (self, filename);
1111   else if (!tp_strdiff (priv->protocol, "aim"))
1112     account_widget_build_aim (self, filename);
1113   else if (!tp_strdiff (priv->protocol, "yahoo"))
1114     account_widget_build_yahoo (self, filename);
1115   else if (!tp_strdiff (priv->protocol, "groupwise"))
1116     account_widget_build_groupwise (self, filename);
1117   else if (!tp_strdiff (priv->protocol, "irc"))
1118     empathy_account_widget_irc_build (self, filename,
1119         &priv->table_common_settings);
1120   else if (!tp_strdiff (priv->protocol, "sip"))
1121     empathy_account_widget_sip_build (self, filename,
1122         &priv->table_common_settings);
1123   else if (!tp_strdiff (priv->protocol, "generic"))
1124     account_widget_build_generic (self, filename);
1125   else
1126     {
1127       g_free (filename);
1128
1129       filename = empathy_file_lookup (
1130           "empathy-account-widget-generic.ui", "libempathy-gtk");
1131       account_widget_build_generic (self, filename);
1132     }
1133
1134   g_free (uiname);
1135   g_free (filename);
1136
1137   /* handle default focus */
1138   if (self->ui_details->default_focus != NULL)
1139     {
1140       GObject *default_focus_entry;
1141
1142       default_focus_entry = gtk_builder_get_object
1143         (self->ui_details->gui, self->ui_details->default_focus);
1144       g_signal_connect (default_focus_entry, "realize",
1145           G_CALLBACK (gtk_widget_grab_focus),
1146           NULL);
1147     }
1148
1149   /* handle forget button */
1150   if (self->ui_details->add_forget)
1151     {
1152       const gchar *password = NULL;
1153
1154       priv->button_forget = GTK_WIDGET (gtk_builder_get_object
1155           (self->ui_details->gui, "button_forget"));
1156       priv->entry_password = GTK_WIDGET (gtk_builder_get_object
1157           (self->ui_details->gui, "entry_password"));
1158
1159       password = empathy_account_settings_get_string (priv->settings,
1160           "password");
1161       gtk_widget_set_sensitive (priv->button_forget,
1162           !EMP_STR_EMPTY (password));
1163
1164       g_signal_connect (priv->button_forget, "clicked",
1165           G_CALLBACK (account_widget_forget_clicked_cb),
1166           self);
1167       g_signal_connect (priv->entry_password, "changed",
1168           G_CALLBACK (account_widget_password_changed_cb),
1169           self);
1170     }
1171
1172   /* handle apply and cancel button */
1173   if (!priv->simple)
1174     {
1175       GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
1176
1177       priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1178       priv->apply_button = gtk_button_new_from_stock (
1179         priv->creating_account ? GTK_STOCK_CONNECT : GTK_STOCK_APPLY);
1180
1181       gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
1182           TRUE, 3);
1183       gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
1184           TRUE, 3);
1185
1186       gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
1187           FALSE, 3);
1188
1189       g_signal_connect (priv->cancel_button, "clicked",
1190           G_CALLBACK (account_widget_cancel_clicked_cb),
1191           self);
1192       g_signal_connect (priv->apply_button, "clicked",
1193           G_CALLBACK (account_widget_apply_clicked_cb),
1194           self);
1195       gtk_widget_show_all (hbox);
1196       account_widget_set_control_buttons_sensitivity (self, FALSE);
1197     }
1198
1199   account = empathy_account_settings_get_account (priv->settings);
1200
1201   if (account != NULL)
1202     {
1203       g_signal_connect (account, "notify::enabled",
1204           G_CALLBACK (empathy_account_widget_enabled_cb), self);
1205     }
1206
1207   /* handle the "Enabled" checkbox. We only add it when modifying an account */
1208   if (!priv->creating_account && priv->table_common_settings != NULL)
1209     {
1210       guint nb_rows, nb_columns;
1211
1212       priv->enabled_checkbox =
1213           gtk_check_button_new_with_label (_("Enabled"));
1214       gtk_toggle_button_set_active (
1215           GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
1216           empathy_account_is_enabled (account));
1217
1218       g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
1219           "n-columns", &nb_columns, NULL);
1220
1221       gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
1222           nb_columns);
1223
1224       gtk_table_attach (GTK_TABLE (priv->table_common_settings),
1225           priv->enabled_checkbox, 0, nb_columns, nb_rows - 1, nb_rows,
1226           GTK_EXPAND | GTK_FILL, 0, 0, 0);
1227
1228       gtk_widget_show (priv->enabled_checkbox);
1229
1230       g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
1231           G_CALLBACK (account_widget_enabled_toggled_cb), self);
1232     }
1233
1234   /* hook up to widget destruction to unref ourselves */
1235   g_signal_connect (self->ui_details->widget, "destroy",
1236       G_CALLBACK (account_widget_destroy_cb), self);
1237
1238   empathy_builder_unref_and_keep_widget (self->ui_details->gui,
1239       self->ui_details->widget);
1240   self->ui_details->gui = NULL;
1241 }
1242
1243 static void
1244 do_dispose (GObject *obj)
1245 {
1246   EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1247   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1248
1249   if (priv->dispose_run)
1250     return;
1251
1252   priv->dispose_run = TRUE;
1253
1254   empathy_account_settings_is_ready (priv->settings);
1255
1256   if (priv->settings != NULL)
1257     {
1258       EmpathyAccount *account;
1259       account = empathy_account_settings_get_account (priv->settings);
1260
1261       if (account != NULL)
1262         {
1263           g_signal_handlers_disconnect_by_func (account,
1264               empathy_account_widget_enabled_cb, self);
1265         }
1266
1267       g_object_unref (priv->settings);
1268       priv->settings = NULL;
1269     }
1270
1271   if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL)
1272     G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose (obj);
1273 }
1274
1275 static void
1276 do_finalize (GObject *obj)
1277 {
1278   EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
1279   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
1280
1281   g_free (self->ui_details->default_focus);
1282   g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
1283
1284   g_free (priv->protocol);
1285
1286   if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
1287     G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
1288 }
1289
1290 static void
1291 empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
1292 {
1293   GObjectClass *oclass = G_OBJECT_CLASS (klass);
1294   GParamSpec *param_spec;
1295
1296   oclass->get_property = do_get_property;
1297   oclass->set_property = do_set_property;
1298   oclass->constructed = do_constructed;
1299   oclass->dispose = do_dispose;
1300   oclass->finalize = do_finalize;
1301
1302   param_spec = g_param_spec_string ("protocol",
1303       "protocol", "The protocol of the account",
1304       NULL,
1305       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1306   g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
1307
1308   param_spec = g_param_spec_object ("settings",
1309       "settings", "The settings of the account",
1310       EMPATHY_TYPE_ACCOUNT_SETTINGS,
1311       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1312   g_object_class_install_property (oclass, PROP_SETTINGS, param_spec);
1313
1314   param_spec = g_param_spec_boolean ("simple",
1315       "simple", "Whether the account widget is a simple or an advanced one",
1316       FALSE,
1317       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1318   g_object_class_install_property (oclass, PROP_SIMPLE, param_spec);
1319
1320   param_spec = g_param_spec_boolean ("creating-account",
1321       "creating-account",
1322       "TRUE if we're creating an account, FALSE if we're modifying it",
1323       FALSE,
1324       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1325   g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
1326
1327   signals[HANDLE_APPLY] =
1328     g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
1329         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1330         g_cclosure_marshal_VOID__BOOLEAN,
1331         G_TYPE_NONE,
1332         1, G_TYPE_BOOLEAN);
1333
1334   /* This signal is emitted when an account has been created and enabled. */
1335   signals[ACCOUNT_CREATED] =
1336       g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
1337           G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1338           g_cclosure_marshal_VOID__VOID,
1339           G_TYPE_NONE,
1340           0);
1341
1342   signals[CANCELLED] =
1343       g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
1344           G_SIGNAL_RUN_LAST, 0, NULL, NULL,
1345           g_cclosure_marshal_VOID__VOID,
1346           G_TYPE_NONE,
1347           0);
1348
1349   g_type_class_add_private (klass, sizeof (EmpathyAccountWidgetPriv));
1350 }
1351
1352 static void
1353 empathy_account_widget_init (EmpathyAccountWidget *self)
1354 {
1355   EmpathyAccountWidgetPriv *priv =
1356     G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_ACCOUNT_WIDGET,
1357         EmpathyAccountWidgetPriv);
1358
1359   self->priv = priv;
1360   priv->dispose_run = FALSE;
1361
1362   self->ui_details = g_slice_new0 (EmpathyAccountWidgetUIDetails);
1363 }
1364
1365 /* public methods */
1366
1367 void
1368 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
1369     const gchar *first_widget,
1370     ...)
1371 {
1372   va_list args;
1373
1374   va_start (args, first_widget);
1375   account_widget_handle_params_valist (self, first_widget, args);
1376   va_end (args);
1377 }
1378
1379 GtkWidget *
1380 empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
1381 {
1382   return widget->ui_details->widget;
1383 }
1384
1385 EmpathyAccountWidget *
1386 empathy_account_widget_new_for_protocol (const char *protocol,
1387     EmpathyAccountSettings *settings,
1388     gboolean simple)
1389 {
1390   EmpathyAccountWidget *self;
1391
1392   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
1393   g_return_val_if_fail (protocol != NULL, NULL);
1394
1395   self = g_object_new
1396     (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol,
1397         "settings", settings, "simple", simple,
1398         "creating-account",
1399         empathy_account_settings_get_account (settings) == NULL,
1400         NULL);
1401
1402   return self;
1403 }