]> git.0d.be Git - empathy.git/blob - src/empathy-accounts-dialog.c
Port to using EmpathyAccountSettings
[empathy.git] / src / empathy-accounts-dialog.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2005-2007 Imendio AB
4  * Copyright (C) 2007-2008 Collabora Ltd.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA  02110-1301  USA
20  *
21  * Authors: Martyn Russell <martyn@imendio.com>
22  *          Xavier Claessens <xclaesse@gmail.com>
23  */
24
25 #include <config.h>
26
27 #include <string.h>
28 #include <stdlib.h>
29
30 #include <gtk/gtk.h>
31 #include <glib/gi18n.h>
32 #include <dbus/dbus-glib.h>
33
34 #include <telepathy-glib/util.h>
35
36 #include <libempathy/empathy-utils.h>
37 #include <libempathy/empathy-account-manager.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
39 #include <libempathy-gtk/empathy-protocol-chooser.h>
40 #include <libempathy-gtk/empathy-account-widget.h>
41 #include <libempathy-gtk/empathy-account-widget-irc.h>
42 #include <libempathy-gtk/empathy-account-widget-sip.h>
43 #include <libempathy-gtk/empathy-conf.h>
44
45 #include "empathy-accounts-dialog.h"
46 #if 0
47 /* FIXME MC-5 */
48 #include "empathy-import-dialog.h"
49 #endif
50
51 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
52 #include <libempathy/empathy-debug.h>
53
54 /* Flashing delay for icons (milliseconds). */
55 #define FLASH_TIMEOUT 500
56
57 typedef struct {
58         GtkWidget        *window;
59
60         GtkWidget        *alignment_settings;
61
62         GtkWidget        *vbox_details;
63         GtkWidget        *frame_no_protocol;
64
65         GtkWidget        *treeview;
66
67         GtkWidget        *button_add;
68         GtkWidget        *button_remove;
69         GtkWidget        *button_import;
70
71         GtkWidget        *frame_new_account;
72         GtkWidget        *combobox_protocol;
73         GtkWidget        *hbox_type;
74         GtkWidget        *button_create;
75         GtkWidget        *button_back;
76         GtkWidget        *radiobutton_reuse;
77         GtkWidget        *radiobutton_register;
78
79         GtkWidget        *image_type;
80         GtkWidget        *label_name;
81         GtkWidget        *label_type;
82         GtkWidget        *settings_widget;
83
84         gboolean          connecting_show;
85         guint             connecting_id;
86
87         gulong            settings_ready_id;
88         EmpathyAccountSettings *settings_ready;
89
90         EmpathyAccountManager *account_manager;
91 } EmpathyAccountsDialog;
92
93 enum {
94         COL_ENABLED,
95         COL_NAME,
96         COL_STATUS,
97         COL_ACCOUNT_POINTER,
98         COL_ACCOUNT_SETTINGS_POINTER,
99         COL_COUNT
100 };
101
102 static void       accounts_dialog_update (EmpathyAccountsDialog    *dialog,
103                                                              EmpathyAccountSettings           *settings);
104 static void       accounts_dialog_model_setup               (EmpathyAccountsDialog    *dialog);
105 static void       accounts_dialog_model_add_columns         (EmpathyAccountsDialog    *dialog);
106 static void       accounts_dialog_name_editing_started_cb   (GtkCellRenderer          *renderer,
107                                                              GtkCellEditable          *editable,
108                                                              gchar                    *path,
109                                                              EmpathyAccountsDialog    *dialog);
110 static void       accounts_dialog_model_select_first        (EmpathyAccountsDialog    *dialog);
111 static void       accounts_dialog_model_pixbuf_data_func    (GtkTreeViewColumn        *tree_column,
112                                                              GtkCellRenderer          *cell,
113                                                              GtkTreeModel             *model,
114                                                              GtkTreeIter              *iter,
115                                                              EmpathyAccountsDialog    *dialog);
116 static void       accounts_dialog_model_set_selected        (EmpathyAccountsDialog    *dialog,
117                                                              EmpathyAccountSettings *settings);
118 static gboolean   accounts_dialog_model_remove_selected     (EmpathyAccountsDialog    *dialog);
119 static void       accounts_dialog_model_selection_changed   (GtkTreeSelection         *selection,
120                                                              EmpathyAccountsDialog    *dialog);
121 static void       accounts_dialog_account_added_cb          (EmpathyAccountManager    *manager,
122                                                              EmpathyAccount           *account,
123                                                              EmpathyAccountsDialog    *dialog);
124 static void       accounts_dialog_account_removed_cb        (EmpathyAccountManager    *manager,
125                                                              EmpathyAccount           *account,
126                                                              EmpathyAccountsDialog    *dialog);
127 static gboolean   accounts_dialog_row_changed_foreach       (GtkTreeModel             *model,
128                                                              GtkTreePath              *path,
129                                                              GtkTreeIter              *iter,
130                                                              gpointer                  user_data);
131 static gboolean   accounts_dialog_flash_connecting_cb       (EmpathyAccountsDialog    *dialog);
132 static void       accounts_dialog_connection_changed_cb     (EmpathyAccountManager    *manager,
133                                                              EmpathyAccount           *account,
134                                                              TpConnectionStatusReason  reason,
135                                                              TpConnectionStatus        current,
136                                                              TpConnectionStatus        previous,
137                                                              EmpathyAccountsDialog    *dialog);
138 static void       accounts_dialog_button_create_clicked_cb  (GtkWidget                *button,
139                                                              EmpathyAccountsDialog    *dialog);
140 static void       accounts_dialog_button_back_clicked_cb    (GtkWidget                *button,
141                                                              EmpathyAccountsDialog    *dialog);
142 static void       accounts_dialog_button_add_clicked_cb     (GtkWidget                *button,
143                                                              EmpathyAccountsDialog    *dialog);
144 static void       accounts_dialog_button_help_clicked_cb    (GtkWidget                *button,
145                                                              EmpathyAccountsDialog    *dialog);
146 static void       accounts_dialog_button_remove_clicked_cb  (GtkWidget                *button,
147                                                              EmpathyAccountsDialog    *dialog);
148 #if 0
149 /* FIXME MC-5 */
150 static void       accounts_dialog_button_import_clicked_cb  (GtkWidget                *button,
151                                                              EmpathyAccountsDialog    *dialog);
152 #endif
153 static void       accounts_dialog_response_cb               (GtkWidget                *widget,
154                                                              gint                      response,
155                                                              EmpathyAccountsDialog    *dialog);
156 static void       accounts_dialog_destroy_cb                (GtkWidget                *widget,
157                                                              EmpathyAccountsDialog    *dialog);
158
159 static void
160 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
161                                    EmpathyAccountSettings *settings)
162 {
163         gchar *text;
164
165         text = g_markup_printf_escaped ("<big><b>%s</b></big>",
166                         empathy_account_settings_get_display_name (settings));
167         gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
168
169         g_free (text);
170 }
171
172 typedef GtkWidget *CreateWidget (EmpathyAccountSettings *);
173
174 static GtkWidget *
175 get_account_setup_widget (EmpathyAccountSettings *settings)
176 {
177         const gchar *cm = empathy_account_settings_get_cm (settings);
178         const gchar *proto = empathy_account_settings_get_protocol (settings);
179         struct {
180                 const gchar *cm;
181                 const gchar *proto;
182                 CreateWidget *cb;
183         } dialogs[] = {
184                 { "gabble", "jabber", empathy_account_widget_jabber_new},
185                 { "butterfly", "msn", empathy_account_widget_msn_new},
186                 { "salut", "local-xmpp", empathy_account_widget_salut_new},
187                 { "idle", "irc", empathy_account_widget_irc_new},
188                 { "haze", "icq", empathy_account_widget_icq_new},
189                 { "haze", "aim", empathy_account_widget_aim_new},
190                 { "haze", "yahoo", empathy_account_widget_yahoo_new},
191                 { "haze", "groupwise", empathy_account_widget_groupwise_new},
192                 { "sofiasip", "sip", empathy_account_widget_sip_new},
193                 { NULL, NULL, NULL }
194         };
195         int i;
196
197         for (i = 0; dialogs[i].cm != NULL; i++) {
198                 if (!tp_strdiff (cm, dialogs[i].cm)
199                         && !tp_strdiff (proto, dialogs[i].proto))
200                                 return dialogs[i].cb (settings);
201         }
202
203         return empathy_account_widget_generic_new (settings);
204 }
205
206
207 static void
208 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
209         EmpathyAccountSettings *settings)
210 {
211         dialog->settings_widget = get_account_setup_widget (settings);
212
213         gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
214                            dialog->settings_widget);
215         gtk_widget_show (dialog->settings_widget);
216
217
218         gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
219                                       empathy_account_settings_get_icon_name (settings),
220                                       GTK_ICON_SIZE_DIALOG);
221         gtk_widget_set_tooltip_text (dialog->image_type,
222                                      empathy_account_settings_get_protocol (settings));
223
224         accounts_dialog_update_name_label (dialog, settings);
225 }
226
227 static void
228 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
229         GParamSpec *spec, EmpathyAccountsDialog *dialog)
230 {
231         if (empathy_account_settings_is_ready (settings))
232                 account_dialog_create_settings_widget (dialog, settings);
233 }
234
235 static void
236 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
237                                 EmpathyAccountSettings       *settings)
238 {
239         if (dialog->settings_ready != NULL) {
240                         g_signal_handler_disconnect (dialog->settings_ready,
241                                 dialog->settings_ready_id);
242                         dialog->settings_ready = NULL;
243                         dialog->settings_ready_id = 0;
244         }
245
246         if (!settings) {
247                 GtkTreeView  *view;
248                 GtkTreeModel *model;
249
250                 view = GTK_TREE_VIEW (dialog->treeview);
251                 model = gtk_tree_view_get_model (view);
252
253                 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
254                         /* We have configured accounts, select the first one */
255                         accounts_dialog_model_select_first (dialog);
256                         return;
257                 }
258                 if (empathy_protocol_chooser_n_protocols (
259                         EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) {
260                         /* We have no account configured but we have some
261                          * profiles instsalled. The user obviously wants to add
262                          * an account. Click on the Add button for him. */
263                         accounts_dialog_button_add_clicked_cb (dialog->button_add,
264                                                                dialog);
265                         return;
266                 }
267
268                 /* No account and no profile, warn the user */
269                 gtk_widget_hide (dialog->vbox_details);
270                 gtk_widget_hide (dialog->frame_new_account);
271                 gtk_widget_show (dialog->frame_no_protocol);
272                 gtk_widget_set_sensitive (dialog->button_add, FALSE);
273                 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
274                 return;
275         }
276
277         /* We have an account selected, destroy old settings and create a new
278          * one for the account selected */
279         gtk_widget_hide (dialog->frame_new_account);
280         gtk_widget_hide (dialog->frame_no_protocol);
281         gtk_widget_show (dialog->vbox_details);
282         gtk_widget_set_sensitive (dialog->button_add, TRUE);
283         gtk_widget_set_sensitive (dialog->button_remove, TRUE);
284
285         if (dialog->settings_widget) {
286                 gtk_widget_destroy (dialog->settings_widget);
287                 dialog->settings_widget = NULL;
288         }
289
290         if (empathy_account_settings_is_ready (settings))
291                 {
292                         account_dialog_create_settings_widget (dialog, settings);
293                 }
294         else
295                 {
296                         dialog->settings_ready = settings;
297                         dialog->settings_ready_id =
298                                 g_signal_connect (settings, "notify::ready",
299                                         G_CALLBACK (account_dialog_settings_ready_cb), dialog);
300                 }
301
302 }
303
304 static void
305 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
306 {
307         GtkListStore     *store;
308         GtkTreeSelection *selection;
309
310         store = gtk_list_store_new (COL_COUNT,
311                                     G_TYPE_BOOLEAN,        /* enabled */
312                                     G_TYPE_STRING,         /* name */
313                                     G_TYPE_UINT,           /* status */
314                                     EMPATHY_TYPE_ACCOUNT,   /* account */
315                                     EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
316
317         gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
318                                  GTK_TREE_MODEL (store));
319
320         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
321         gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
322
323         g_signal_connect (selection, "changed",
324                           G_CALLBACK (accounts_dialog_model_selection_changed),
325                           dialog);
326
327         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
328                                               COL_NAME, GTK_SORT_ASCENDING);
329
330         accounts_dialog_model_add_columns (dialog);
331
332         g_object_unref (store);
333 }
334
335 static void
336 accounts_dialog_name_edited_cb (GtkCellRendererText   *renderer,
337                                 gchar                 *path,
338                                 gchar                 *new_text,
339                                 EmpathyAccountsDialog *dialog)
340 {
341         EmpathyAccountSettings    *settings;
342         GtkTreeModel *model;
343         GtkTreePath  *treepath;
344         GtkTreeIter   iter;
345
346         if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
347                 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
348                                                        (GSourceFunc) accounts_dialog_flash_connecting_cb,
349                                                        dialog);
350         }
351
352         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
353         treepath = gtk_tree_path_new_from_string (path);
354         gtk_tree_model_get_iter (model, &iter, treepath);
355         gtk_tree_model_get (model, &iter,
356                             COL_ACCOUNT_SETTINGS_POINTER, &settings,
357                             -1);
358         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
359                             COL_NAME, new_text,
360                             -1);
361         gtk_tree_path_free (treepath);
362
363         empathy_account_settings_set_display_name_async (settings, new_text,
364                 NULL, NULL);
365         g_object_unref (settings);
366 }
367
368 static void
369 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
370                                    gchar                 *path,
371                                    EmpathyAccountsDialog *dialog)
372 {
373         EmpathyAccount    *account;
374         GtkTreeModel *model;
375         GtkTreePath  *treepath;
376         GtkTreeIter   iter;
377         gboolean      enabled;
378
379         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
380         treepath = gtk_tree_path_new_from_string (path);
381         gtk_tree_model_get_iter (model, &iter, treepath);
382         gtk_tree_model_get (model, &iter,
383                             COL_ACCOUNT_POINTER, &account,
384                             -1);
385         gtk_tree_path_free (treepath);
386
387         if (account == NULL)
388                 return;
389
390         enabled = empathy_account_is_enabled (account);
391         empathy_account_set_enabled (account, !enabled);
392
393         DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
394                 empathy_account_get_display_name (account));
395
396         g_object_unref (account);
397 }
398
399 static void
400 accounts_dialog_name_editing_started_cb (GtkCellRenderer       *renderer,
401                                          GtkCellEditable       *editable,
402                                          gchar                 *path,
403                                          EmpathyAccountsDialog *dialog)
404 {
405         if (dialog->connecting_id) {
406                 g_source_remove (dialog->connecting_id);
407         }
408         DEBUG ("Editing account name started; stopping flashing");
409 }
410
411 static void
412 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
413 {
414         GtkTreeView       *view;
415         GtkTreeViewColumn *column;
416         GtkCellRenderer   *cell;
417
418         view = GTK_TREE_VIEW (dialog->treeview);
419         gtk_tree_view_set_headers_visible (view, TRUE);
420
421         /* Enabled column */
422         cell = gtk_cell_renderer_toggle_new ();
423         gtk_tree_view_insert_column_with_attributes (view, -1,
424                                                      _("Enabled"),
425                                                      cell,
426                                                      "active", COL_ENABLED,
427                                                      NULL);
428         g_signal_connect (cell, "toggled",
429                           G_CALLBACK (accounts_dialog_enable_toggled_cb),
430                           dialog);
431
432         /* Account column */
433         column = gtk_tree_view_column_new ();
434         gtk_tree_view_column_set_title (column, _("Accounts"));
435         gtk_tree_view_column_set_expand (column, TRUE);
436         gtk_tree_view_append_column (view, column);
437
438         /* Icon renderer */
439         cell = gtk_cell_renderer_pixbuf_new ();
440         gtk_tree_view_column_pack_start (column, cell, FALSE);
441         gtk_tree_view_column_set_cell_data_func (column, cell,
442                                                  (GtkTreeCellDataFunc)
443                                                  accounts_dialog_model_pixbuf_data_func,
444                                                  dialog,
445                                                  NULL);
446
447         /* Name renderer */
448         cell = gtk_cell_renderer_text_new ();
449         g_object_set (cell,
450                       "ellipsize", PANGO_ELLIPSIZE_END,
451                       "width-chars", 25,
452                       "editable", TRUE,
453                       NULL);
454         gtk_tree_view_column_pack_start (column, cell, TRUE);
455         gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
456         g_signal_connect (cell, "edited",
457                           G_CALLBACK (accounts_dialog_name_edited_cb),
458                           dialog);
459         g_signal_connect (cell, "editing-started",
460                           G_CALLBACK (accounts_dialog_name_editing_started_cb),
461                           dialog);
462 }
463
464 static void
465 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
466 {
467         GtkTreeView      *view;
468         GtkTreeModel     *model;
469         GtkTreeSelection *selection;
470         GtkTreeIter       iter;
471
472         /* select first */
473         view = GTK_TREE_VIEW (dialog->treeview);
474         model = gtk_tree_view_get_model (view);
475
476         if (gtk_tree_model_get_iter_first (model, &iter)) {
477                 selection = gtk_tree_view_get_selection (view);
478                 gtk_tree_selection_select_iter (selection, &iter);
479         } else {
480                 accounts_dialog_update_settings (dialog, NULL);
481         }
482 }
483
484 static void
485 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn    *tree_column,
486                                         GtkCellRenderer      *cell,
487                                         GtkTreeModel         *model,
488                                         GtkTreeIter          *iter,
489                                         EmpathyAccountsDialog *dialog)
490 {
491         EmpathyAccountSettings  *settings;
492         const gchar        *icon_name;
493         GdkPixbuf          *pixbuf;
494         TpConnectionStatus  status;
495
496         gtk_tree_model_get (model, iter,
497                             COL_STATUS, &status,
498                             COL_ACCOUNT_SETTINGS_POINTER, &settings,
499                             -1);
500
501         icon_name = empathy_account_settings_get_icon_name (settings);
502         pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
503
504         if (pixbuf) {
505                 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
506                     (status == TP_CONNECTION_STATUS_CONNECTING &&
507                      !dialog->connecting_show)) {
508                         GdkPixbuf *modded_pixbuf;
509
510                         modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
511                                                         TRUE,
512                                                         8,
513                                                         gdk_pixbuf_get_width (pixbuf),
514                                                         gdk_pixbuf_get_height (pixbuf));
515
516                         gdk_pixbuf_saturate_and_pixelate (pixbuf,
517                                                           modded_pixbuf,
518                                                           1.0,
519                                                           TRUE);
520                         g_object_unref (pixbuf);
521                         pixbuf = modded_pixbuf;
522                 }
523         }
524
525         g_object_set (cell,
526                       "visible", TRUE,
527                       "pixbuf", pixbuf,
528                       NULL);
529
530         g_object_unref (settings);
531         if (pixbuf) {
532                 g_object_unref (pixbuf);
533         }
534 }
535
536 static gboolean
537 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
538                                  EmpathyAccountSettings *settings,
539                                  GtkTreeIter           *iter)
540 {
541         GtkTreeView      *view;
542         GtkTreeSelection *selection;
543         GtkTreeModel     *model;
544         gboolean          ok;
545
546         /* Update the status in the model */
547         view = GTK_TREE_VIEW (dialog->treeview);
548         selection = gtk_tree_view_get_selection (view);
549         model = gtk_tree_view_get_model (view);
550
551         for (ok = gtk_tree_model_get_iter_first (model, iter);
552              ok;
553              ok = gtk_tree_model_iter_next (model, iter)) {
554                 EmpathyAccountSettings *this_settings;
555                 gboolean   equal;
556
557                 gtk_tree_model_get (model, iter,
558                                     COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
559                                     -1);
560
561                 equal = (this_settings == settings);
562                 g_object_unref (this_settings);
563
564                 if (equal) {
565                         return TRUE;
566                 }
567         }
568
569         return FALSE;
570 }
571
572 static gboolean
573 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
574                                  EmpathyAccount *account,
575                                  GtkTreeIter    *iter)
576 {
577         GtkTreeView      *view;
578         GtkTreeSelection *selection;
579         GtkTreeModel     *model;
580         gboolean          ok;
581
582         /* Update the status in the model */
583         view = GTK_TREE_VIEW (dialog->treeview);
584         selection = gtk_tree_view_get_selection (view);
585         model = gtk_tree_view_get_model (view);
586
587         for (ok = gtk_tree_model_get_iter_first (model, iter);
588              ok;
589              ok = gtk_tree_model_iter_next (model, iter)) {
590                 EmpathyAccount *this_account;
591                 gboolean   equal;
592
593                 gtk_tree_model_get (model, iter,
594                                     COL_ACCOUNT_POINTER, &this_account,
595                                     -1);
596
597                 equal = (this_account == account);
598                 g_object_unref (this_account);
599
600                 if (equal) {
601                         return TRUE;
602                 }
603         }
604
605         return FALSE;
606 }
607
608 static EmpathyAccountSettings *
609 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
610 {
611         GtkTreeView      *view;
612         GtkTreeModel     *model;
613         GtkTreeSelection *selection;
614         GtkTreeIter       iter;
615         EmpathyAccountSettings   *settings;
616
617         view = GTK_TREE_VIEW (dialog->treeview);
618         selection = gtk_tree_view_get_selection (view);
619
620         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
621                 return NULL;
622         }
623
624         gtk_tree_model_get (model, &iter,
625                 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
626
627         return settings;
628 }
629
630
631 static EmpathyAccount *
632 accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog)
633 {
634         GtkTreeView      *view;
635         GtkTreeModel     *model;
636         GtkTreeSelection *selection;
637         GtkTreeIter       iter;
638         EmpathyAccount   *account;
639
640         view = GTK_TREE_VIEW (dialog->treeview);
641         selection = gtk_tree_view_get_selection (view);
642
643         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
644                 return NULL;
645         }
646
647         gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
648
649         return account;
650 }
651
652 static void
653 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
654                                     EmpathyAccountSettings        *settings)
655 {
656         GtkTreeSelection *selection;
657         GtkTreeIter       iter;
658
659         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
660         if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) {
661                 gtk_tree_selection_select_iter (selection, &iter);
662         }
663 }
664
665 static gboolean
666 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
667 {
668         GtkTreeView      *view;
669         GtkTreeModel     *model;
670         GtkTreeSelection *selection;
671         GtkTreeIter       iter;
672
673         view = GTK_TREE_VIEW (dialog->treeview);
674         selection = gtk_tree_view_get_selection (view);
675
676         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
677                 return FALSE;
678         }
679
680         return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
681 }
682
683 static void
684 accounts_dialog_model_selection_changed (GtkTreeSelection     *selection,
685                                          EmpathyAccountsDialog *dialog)
686 {
687         EmpathyAccountSettings *settings;
688         GtkTreeModel *model;
689         GtkTreeIter   iter;
690         gboolean      is_selection;
691
692         is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
693
694         settings = accounts_dialog_model_get_selected_settings (dialog);
695         accounts_dialog_update_settings (dialog, settings);
696
697         if (settings) {
698                 g_object_unref (settings);
699         }
700 }
701
702 static void
703 accounts_dialog_add (EmpathyAccountsDialog *dialog,
704                                        EmpathyAccountSettings        *settings)
705 {
706         GtkTreeModel       *model;
707         GtkTreeIter         iter;
708         const gchar        *name;
709
710         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
711         name = empathy_account_settings_get_display_name (settings);
712
713         gtk_list_store_append (GTK_LIST_STORE (model), &iter);
714
715         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
716                             COL_ENABLED, FALSE,
717                             COL_NAME, name,
718                             COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
719                             COL_ACCOUNT_SETTINGS_POINTER, settings,
720                             -1);
721 }
722
723
724 static void
725 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
726                                        EmpathyAccount        *account)
727 {
728         EmpathyAccountSettings *settings;
729         GtkTreeModel       *model;
730         GtkTreeIter         iter;
731         TpConnectionStatus  status;
732         const gchar        *name;
733         gboolean            enabled;
734
735         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
736         g_object_get (account, "status", &status, NULL);
737         name = empathy_account_get_display_name (account);
738         enabled = empathy_account_is_enabled (account);
739
740         gtk_list_store_append (GTK_LIST_STORE (model), &iter);
741
742         settings = empathy_account_settings_new_for_account (account);
743
744         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
745                             COL_ENABLED, enabled,
746                             COL_NAME, name,
747                             COL_STATUS, status,
748                             COL_ACCOUNT_POINTER, account,
749                             COL_ACCOUNT_SETTINGS_POINTER, settings,
750                             -1);
751
752         accounts_dialog_connection_changed_cb (dialog->account_manager,
753                                                account,
754                                                TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
755                                                status,
756                                                TP_CONNECTION_STATUS_DISCONNECTED,
757                                                dialog);
758
759         g_object_unref (settings);
760 }
761
762 static void
763 accounts_dialog_update (EmpathyAccountsDialog *dialog,
764                                        EmpathyAccountSettings        *settings)
765 {
766         GtkTreeModel       *model;
767         GtkTreeIter         iter;
768         TpConnectionStatus  status = TP_CONNECTION_STATUS_DISCONNECTED;
769         const gchar        *name;
770         gboolean            enabled = FALSE;
771         EmpathyAccount     *account;
772
773         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
774         name = empathy_account_settings_get_display_name (settings);
775
776         account = empathy_account_settings_get_account (settings);
777         if (account != NULL)
778                 {
779                         enabled = empathy_account_is_enabled (account);
780                         g_object_get (account, "connection-status", &status, NULL);
781                 }
782
783         accounts_dialog_get_settings_iter (dialog, settings, &iter);
784         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
785                             COL_ENABLED, enabled,
786                             COL_NAME, name,
787                             COL_STATUS, status,
788                             COL_ACCOUNT_POINTER, account,
789                             COL_ACCOUNT_SETTINGS_POINTER, settings,
790                             -1);
791 }
792
793 static void
794 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
795                                   EmpathyAccount *account,
796                                   EmpathyAccountsDialog *dialog)
797 {
798         accounts_dialog_add_account (dialog, account);
799 }
800
801
802 static void
803 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
804                                     EmpathyAccount       *account,
805                                     EmpathyAccountsDialog *dialog)
806 {
807         GtkTreeIter iter;
808
809         if (accounts_dialog_get_account_iter (dialog, account, &iter))
810                 gtk_list_store_remove (GTK_LIST_STORE (
811                         gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview))), &iter);
812 }
813
814 static gboolean
815 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
816                                      GtkTreePath  *path,
817                                      GtkTreeIter  *iter,
818                                      gpointer      user_data)
819 {
820         gtk_tree_model_row_changed (model, path, iter);
821
822         return FALSE;
823 }
824
825 static gboolean
826 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
827 {
828         GtkTreeView  *view;
829         GtkTreeModel *model;
830
831         dialog->connecting_show = !dialog->connecting_show;
832
833         view = GTK_TREE_VIEW (dialog->treeview);
834         model = gtk_tree_view_get_model (view);
835
836         gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
837
838         return TRUE;
839 }
840
841 static void
842 accounts_dialog_connection_changed_cb     (EmpathyAccountManager    *manager,
843                                            EmpathyAccount           *account,
844                                            TpConnectionStatusReason  reason,
845                                            TpConnectionStatus        current,
846                                            TpConnectionStatus        previous,
847                                            EmpathyAccountsDialog    *dialog)
848 {
849         GtkTreeModel *model;
850         GtkTreeIter   iter;
851         gboolean      found;
852
853         /* Update the status in the model */
854         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
855
856         if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
857                 GtkTreePath *path;
858
859                 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
860                                     COL_STATUS, current,
861                                     -1);
862
863                 path = gtk_tree_model_get_path (model, &iter);
864                 gtk_tree_model_row_changed (model, path, &iter);
865                 gtk_tree_path_free (path);
866         }
867
868         found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
869
870         if (!found && dialog->connecting_id) {
871                 g_source_remove (dialog->connecting_id);
872                 dialog->connecting_id = 0;
873         }
874
875         if (found && !dialog->connecting_id) {
876                 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
877                                                        (GSourceFunc) accounts_dialog_flash_connecting_cb,
878                                                        dialog);
879         }
880 }
881
882 static void
883 enable_or_disable_account (EmpathyAccountsDialog *dialog,
884                            EmpathyAccount *account,
885                            gboolean enabled)
886 {
887         GtkTreeModel *model;
888         GtkTreeIter   iter;
889
890         /* Update the status in the model */
891         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
892
893         DEBUG ("Account %s is now %s",
894                 empathy_account_get_display_name (account),
895                 enabled ? "enabled" : "disabled");
896
897         if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
898                 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
899                                     COL_ENABLED, enabled,
900                                     -1);
901         }
902 }
903
904 static void
905 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
906                                      EmpathyAccount        *account,
907                                      EmpathyAccountsDialog *dialog)
908 {
909         enable_or_disable_account (dialog, account, FALSE);
910 }
911
912 static void
913 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
914                                     EmpathyAccount        *account,
915                                     EmpathyAccountsDialog *dialog)
916 {
917         enable_or_disable_account (dialog, account, TRUE);
918 }
919
920 static void
921 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
922                                     EmpathyAccount        *account,
923                                     EmpathyAccountsDialog  *dialog)
924 {
925         EmpathyAccountSettings *settings, *selected_settings;
926         GtkTreeModel *model;
927         GtkTreeIter iter;
928
929         model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
930
931         if (!accounts_dialog_get_account_iter (dialog, account, &iter))
932                 return;
933
934         gtk_tree_model_get (model, &iter,
935                 COL_ACCOUNT_SETTINGS_POINTER, &settings,
936                 -1);
937
938         accounts_dialog_update (dialog, settings);
939         selected_settings = accounts_dialog_model_get_selected_settings (dialog);
940
941         if (settings == selected_settings)
942                 accounts_dialog_update_name_label (dialog, settings);
943 }
944
945 static void
946 accounts_dialog_button_create_clicked_cb (GtkWidget             *button,
947                                           EmpathyAccountsDialog  *dialog)
948 {
949         EmpathyAccountSettings *settings;
950         gchar     *str;
951         TpConnectionManager *cm;
952         TpConnectionManagerProtocol *proto;
953
954         cm = empathy_protocol_chooser_dup_selected (
955             EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
956
957         /* Create account */
958         /* To translator: %s is the protocol name */
959         str = g_strdup_printf (_("New %s account"), proto->name);
960
961         settings = empathy_account_settings_new (cm->name, proto->name, str);
962
963         g_free (str);
964
965         if (tp_connection_manager_protocol_can_register (proto)) {
966                 gboolean active;
967
968                 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
969                 if (active) {
970                         empathy_account_settings_set_boolean (settings, "register", TRUE);
971                 }
972         }
973
974         accounts_dialog_add (dialog, settings);
975         accounts_dialog_model_set_selected (dialog, settings);
976
977         g_object_unref (settings);
978         g_object_unref (cm);
979 }
980
981 static void
982 accounts_dialog_button_back_clicked_cb (GtkWidget             *button,
983                                         EmpathyAccountsDialog  *dialog)
984 {
985         EmpathyAccountSettings *settings;
986
987         settings = accounts_dialog_model_get_selected_settings (dialog);
988         accounts_dialog_update (dialog, settings);
989 }
990
991 static void
992 accounts_dialog_protocol_changed_cb (GtkWidget             *widget,
993                                     EmpathyAccountsDialog *dialog)
994 {
995         TpConnectionManager *cm;
996         TpConnectionManagerProtocol *proto;
997
998         cm = empathy_protocol_chooser_dup_selected (
999             EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
1000
1001         if (tp_connection_manager_protocol_can_register (proto)) {
1002                 gtk_widget_show (dialog->radiobutton_register);
1003                 gtk_widget_show (dialog->radiobutton_reuse);
1004         } else {
1005                 gtk_widget_hide (dialog->radiobutton_register);
1006                 gtk_widget_hide (dialog->radiobutton_reuse);
1007         }
1008         g_object_unref (cm);
1009 }
1010
1011 static void
1012 accounts_dialog_button_add_clicked_cb (GtkWidget             *button,
1013                                        EmpathyAccountsDialog *dialog)
1014 {
1015         GtkTreeView      *view;
1016         GtkTreeSelection *selection;
1017         GtkTreeModel     *model;
1018
1019         view = GTK_TREE_VIEW (dialog->treeview);
1020         model = gtk_tree_view_get_model (view);
1021         selection = gtk_tree_view_get_selection (view);
1022         gtk_tree_selection_unselect_all (selection);
1023
1024         gtk_widget_set_sensitive (dialog->button_add, FALSE);
1025         gtk_widget_set_sensitive (dialog->button_remove, FALSE);
1026         gtk_widget_hide (dialog->vbox_details);
1027         gtk_widget_hide (dialog->frame_no_protocol);
1028         gtk_widget_show (dialog->frame_new_account);
1029
1030         /* If we have no account, no need of a back button */
1031         if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
1032                 gtk_widget_show (dialog->button_back);
1033         } else {
1034                 gtk_widget_hide (dialog->button_back);
1035         }
1036
1037         accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
1038         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
1039                                       TRUE);
1040         gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
1041         gtk_widget_grab_focus (dialog->combobox_protocol);
1042 }
1043
1044 static void
1045 accounts_dialog_button_help_clicked_cb (GtkWidget             *button,
1046                                         EmpathyAccountsDialog *dialog)
1047 {
1048         empathy_url_show (button, "ghelp:empathy?empathy-create-account");
1049 }
1050
1051 static void
1052 accounts_dialog_button_remove_clicked_cb (GtkWidget            *button,
1053                                           EmpathyAccountsDialog *dialog)
1054 {
1055         EmpathyAccount *account;
1056         GtkWidget *message_dialog;
1057         gint       res;
1058
1059         account = accounts_dialog_model_get_selected_account (dialog);
1060
1061         if (account == NULL || !empathy_account_is_valid (account)) {
1062                 accounts_dialog_model_remove_selected (dialog);
1063                 accounts_dialog_model_select_first (dialog);
1064                 return;
1065         }
1066         message_dialog = gtk_message_dialog_new
1067                 (GTK_WINDOW (dialog->window),
1068                  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1069                  GTK_MESSAGE_QUESTION,
1070                  GTK_BUTTONS_NONE,
1071                  _("You are about to remove your %s account!\n"
1072                    "Are you sure you want to proceed?"),
1073                  empathy_account_get_display_name (account));
1074
1075         gtk_message_dialog_format_secondary_text
1076                 (GTK_MESSAGE_DIALOG (message_dialog),
1077                  _("Any associated conversations and chat rooms will NOT be "
1078                    "removed if you decide to proceed.\n"
1079                    "\n"
1080                    "Should you decide to add the account back at a later time, "
1081                    "they will still be available."));
1082
1083         gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1084                                GTK_STOCK_CANCEL,
1085                                GTK_RESPONSE_NO);
1086         gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1087                                GTK_STOCK_REMOVE,
1088                                GTK_RESPONSE_YES);
1089
1090         gtk_widget_show (message_dialog);
1091         res = gtk_dialog_run (GTK_DIALOG (message_dialog));
1092
1093         if (res == GTK_RESPONSE_YES) {
1094                 empathy_account_manager_remove (dialog->account_manager, account);
1095                 accounts_dialog_model_select_first (dialog);
1096         }
1097         gtk_widget_destroy (message_dialog);
1098 }
1099
1100 #if 0
1101 /* FIXME MC-5 */
1102 static void
1103 accounts_dialog_button_import_clicked_cb (GtkWidget             *button,
1104                                           EmpathyAccountsDialog *dialog)
1105 {
1106         empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
1107 }
1108 #endif
1109
1110 static void
1111 accounts_dialog_response_cb (GtkWidget            *widget,
1112                              gint                  response,
1113                              EmpathyAccountsDialog *dialog)
1114 {
1115         if (response == GTK_RESPONSE_CLOSE) {
1116                 gtk_widget_destroy (widget);
1117         }
1118 }
1119
1120 static void
1121 accounts_dialog_destroy_cb (GtkWidget            *widget,
1122                             EmpathyAccountsDialog *dialog)
1123 {
1124         GList *accounts, *l;
1125
1126         /* Disconnect signals */
1127         g_signal_handlers_disconnect_by_func (dialog->account_manager,
1128                                               accounts_dialog_account_added_cb,
1129                                               dialog);
1130         g_signal_handlers_disconnect_by_func (dialog->account_manager,
1131                                               accounts_dialog_account_removed_cb,
1132                                               dialog);
1133         g_signal_handlers_disconnect_by_func (dialog->account_manager,
1134                                               accounts_dialog_account_enabled_cb,
1135                                               dialog);
1136         g_signal_handlers_disconnect_by_func (dialog->account_manager,
1137                                               accounts_dialog_account_disabled_cb,
1138                                               dialog);
1139         g_signal_handlers_disconnect_by_func (dialog->account_manager,
1140                                               accounts_dialog_account_changed_cb,
1141                                               dialog);
1142         g_signal_handlers_disconnect_by_func (dialog->account_manager,
1143                                               accounts_dialog_connection_changed_cb,
1144                                               dialog);
1145
1146         /* Delete incomplete accounts */
1147         accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1148         for (l = accounts; l; l = l->next) {
1149                 EmpathyAccount *account;
1150
1151                 account = l->data;
1152                 if (!empathy_account_is_valid (account)) {
1153                         /* FIXME: Warn the user the account is not complete
1154                          *        and is going to be removed. */
1155                         empathy_account_manager_remove (dialog->account_manager, account);
1156                 }
1157
1158                 g_object_unref (account);
1159         }
1160         g_list_free (accounts);
1161
1162         if (dialog->connecting_id) {
1163                 g_source_remove (dialog->connecting_id);
1164         }
1165
1166         g_object_unref (dialog->account_manager);
1167
1168         g_free (dialog);
1169 }
1170
1171 GtkWidget *
1172 empathy_accounts_dialog_show (GtkWindow *parent,
1173                               EmpathyAccount *selected_account)
1174 {
1175         static EmpathyAccountsDialog *dialog = NULL;
1176         GtkBuilder                   *gui;
1177         gchar                        *filename;
1178         GList                        *accounts, *l;
1179         gboolean                      import_asked;
1180
1181         if (dialog) {
1182                 gtk_window_present (GTK_WINDOW (dialog->window));
1183                 return dialog->window;
1184         }
1185
1186         dialog = g_new0 (EmpathyAccountsDialog, 1);
1187
1188         filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1189                                         "src");
1190         gui = empathy_builder_get_file (filename,
1191                                        "accounts_dialog", &dialog->window,
1192                                        "vbox_details", &dialog->vbox_details,
1193                                        "frame_no_protocol", &dialog->frame_no_protocol,
1194                                        "alignment_settings", &dialog->alignment_settings,
1195                                        "treeview", &dialog->treeview,
1196                                        "frame_new_account", &dialog->frame_new_account,
1197                                        "hbox_type", &dialog->hbox_type,
1198                                        "button_create", &dialog->button_create,
1199                                        "button_back", &dialog->button_back,
1200                                        "radiobutton_reuse", &dialog->radiobutton_reuse,
1201                                        "radiobutton_register", &dialog->radiobutton_register,
1202                                        "image_type", &dialog->image_type,
1203                                        "label_name", &dialog->label_name,
1204                                        "button_add", &dialog->button_add,
1205                                        "button_remove", &dialog->button_remove,
1206                                        "button_import", &dialog->button_import,
1207                                        NULL);
1208         g_free (filename);
1209
1210         empathy_builder_connect (gui, dialog,
1211                               "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1212                               "accounts_dialog", "response", accounts_dialog_response_cb,
1213                               "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1214                               "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1215                               "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1216                               "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1217 #if 0
1218 /* FIXME MC-5  */
1219                               "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1220 #endif
1221                               "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1222                               NULL);
1223
1224         g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1225
1226         g_object_unref (gui);
1227
1228         /* Create protocol chooser */
1229         dialog->combobox_protocol = empathy_protocol_chooser_new ();
1230         gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1231                           dialog->combobox_protocol,
1232                           TRUE, TRUE, 0);
1233         gtk_widget_show (dialog->combobox_protocol);
1234         g_signal_connect (dialog->combobox_protocol, "changed",
1235                           G_CALLBACK (accounts_dialog_protocol_changed_cb),
1236                           dialog);
1237
1238         /* Set up signalling */
1239         dialog->account_manager = empathy_account_manager_dup_singleton ();
1240
1241         g_signal_connect (dialog->account_manager, "account-created",
1242                           G_CALLBACK (accounts_dialog_account_added_cb),
1243                           dialog);
1244         g_signal_connect (dialog->account_manager, "account-deleted",
1245                           G_CALLBACK (accounts_dialog_account_removed_cb),
1246                           dialog);
1247         g_signal_connect (dialog->account_manager, "account-enabled",
1248                           G_CALLBACK (accounts_dialog_account_enabled_cb),
1249                           dialog);
1250         g_signal_connect (dialog->account_manager, "account-disabled",
1251                           G_CALLBACK (accounts_dialog_account_disabled_cb),
1252                           dialog);
1253         g_signal_connect (dialog->account_manager, "account-changed",
1254                           G_CALLBACK (accounts_dialog_account_changed_cb),
1255                           dialog);
1256         g_signal_connect (dialog->account_manager, "account-connection-changed",
1257                           G_CALLBACK (accounts_dialog_connection_changed_cb),
1258                           dialog);
1259
1260         accounts_dialog_model_setup (dialog);
1261
1262         /* Add existing accounts */
1263         accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1264         for (l = accounts; l; l = l->next) {
1265                 accounts_dialog_add_account (dialog, l->data);
1266                 g_object_unref (l->data);
1267         }
1268         g_list_free (accounts);
1269
1270         if (selected_account) {
1271                 GtkTreeSelection *selection;
1272                 GtkTreeIter       iter;
1273
1274                 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
1275                 if (accounts_dialog_get_account_iter (dialog, selected_account, &iter)) {
1276                         gtk_tree_selection_select_iter (selection, &iter);
1277                 }
1278         } else {
1279                 accounts_dialog_model_select_first (dialog);
1280         }
1281
1282         if (parent) {
1283                 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1284                                               GTK_WINDOW (parent));
1285         }
1286
1287         gtk_widget_show (dialog->window);
1288
1289         empathy_conf_get_bool (empathy_conf_get (),
1290                                EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1291
1292
1293 #if 0
1294 /* FIXME MC-5 */
1295         if (empathy_import_dialog_accounts_to_import ()) {
1296
1297                 if (!import_asked) {
1298                         empathy_conf_set_bool (empathy_conf_get (),
1299                                                EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1300                         empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1301                                                     FALSE);
1302                 }
1303         } else {
1304                 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1305         }
1306 #endif
1307
1308         return dialog->window;
1309 }
1310