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