f50d502dd6ea19c02783bb6851fae193673aa102
[modest] / src / widgets / modest-account-view.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <glib/gi18n.h>
31 #include "modest-account-view.h"
32
33 #include <modest-account-mgr.h>
34 #include <modest-account-mgr-helpers.h>
35 #include <modest-tny-account.h>
36 #include <modest-text-utils.h>
37 #include <modest-runtime.h>
38 #include <modest-signal-mgr.h>
39
40 #include <gtk/gtkcellrenderertoggle.h>
41 #include <gtk/gtkcellrenderertext.h>
42 #include <gtk/gtktreeselection.h>
43 #include <gtk/gtkliststore.h>
44 #include <string.h> /* For strcmp(). */
45
46 /* 'private'/'protected' functions */
47 static void modest_account_view_class_init    (ModestAccountViewClass *klass);
48 static void modest_account_view_init          (ModestAccountView *obj);
49 static void modest_account_view_finalize      (GObject *obj);
50
51 static void modest_account_view_select_account (ModestAccountView *account_view, 
52                                                 const gchar* account_name);
53
54 static void on_default_account_changed         (ModestAccountMgr *mgr,
55                                                 gpointer user_data);
56
57 typedef enum {
58         MODEST_ACCOUNT_VIEW_NAME_COLUMN,
59         MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN,
60         MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN,
61         MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN,
62         MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
63         MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN,
64
65         MODEST_ACCOUNT_VIEW_COLUMN_NUM
66 } AccountViewColumns;
67
68 typedef struct _ModestAccountViewPrivate ModestAccountViewPrivate;
69 struct _ModestAccountViewPrivate {
70         ModestAccountMgr *account_mgr;
71
72         /* Signal handlers */
73         GSList *sig_handlers;
74 };
75 #define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
76                                                  MODEST_TYPE_ACCOUNT_VIEW, \
77                                                  ModestAccountViewPrivate))
78 /* globals */
79 static GtkTreeViewClass *parent_class = NULL;
80
81 GType
82 modest_account_view_get_type (void)
83 {
84         static GType my_type = 0;
85         if (!my_type) {
86                 static const GTypeInfo my_info = {
87                         sizeof(ModestAccountViewClass),
88                         NULL,           /* base init */
89                         NULL,           /* base finalize */
90                         (GClassInitFunc) modest_account_view_class_init,
91                         NULL,           /* class finalize */
92                         NULL,           /* class data */
93                         sizeof(ModestAccountView),
94                         1,              /* n_preallocs */
95                         (GInstanceInitFunc) modest_account_view_init,
96                         NULL
97                 };
98                 my_type = g_type_register_static (GTK_TYPE_TREE_VIEW,
99                                                   "ModestAccountView",
100                                                   &my_info, 0);
101         }
102         return my_type;
103 }
104
105 static void
106 modest_account_view_class_init (ModestAccountViewClass *klass)
107 {
108         GObjectClass *gobject_class;
109         gobject_class = (GObjectClass*) klass;
110
111         parent_class            = g_type_class_peek_parent (klass);
112         gobject_class->finalize = modest_account_view_finalize;
113
114         g_type_class_add_private (gobject_class, sizeof(ModestAccountViewPrivate));
115 }
116
117 static void
118 modest_account_view_init (ModestAccountView *obj)
119 {
120         ModestAccountViewPrivate *priv;
121         
122         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
123         
124         priv->sig_handlers = NULL;
125 }
126
127 static void
128 modest_account_view_finalize (GObject *obj)
129 {
130         ModestAccountViewPrivate *priv;
131
132         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
133
134         /* Disconnect signals */
135         modest_signal_mgr_disconnect_all_and_destroy (priv->sig_handlers);
136
137         if (priv->account_mgr) {        
138                 g_object_unref (G_OBJECT(priv->account_mgr));
139                 priv->account_mgr = NULL; 
140         }
141         
142         G_OBJECT_CLASS(parent_class)->finalize (obj);
143 }
144
145 /* Get the string for the last updated time. Result must be g_freed */
146 static gchar*
147 get_last_updated_string(ModestAccountMgr* account_mgr, ModestAccountData *account_data)
148 {
149         /* FIXME: let's assume that 'last update' applies to the store account... */
150         gchar* last_updated_string;
151         time_t last_updated = account_data->store_account->last_updated;
152         if (!modest_account_mgr_account_is_busy(account_mgr, account_data->account_name)) {
153                 if (last_updated > 0) 
154                         last_updated_string = modest_text_utils_get_display_date(last_updated);
155                 else
156                         last_updated_string = g_strdup (_("mcen_va_never"));
157         } else  {
158                 /* FIXME: There should be a logical name in the UI specs */
159                 last_updated_string = g_strdup(_("mcen_va_refreshing"));
160         }
161         return last_updated_string;
162 }
163
164 static void
165 update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
166 {
167         GSList *account_names, *cursor;
168         GtkListStore *model;
169                 
170         model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(view)));
171         
172         /* Get the ID of the currently-selected account,
173          * so we can select it again after rebuilding the list.
174          * Note that the name doesn't change even when the display name changes.
175          */
176         gchar *selected_name = modest_account_view_get_selected_account (view);
177
178         gtk_list_store_clear (model);
179
180         /* Note: We do not show disabled accounts.
181          * Of course, this means that there is no UI to enable or disable
182          * accounts. That is OK for maemo where no such feature or UI is
183          * specified, so the "enabled" property is used internally to avoid
184          * showing unfinished accounts. If a user-visible "enabled" is
185          * needed in the future, we must use a second property for the
186          * current use instead */
187         cursor = account_names = modest_account_mgr_account_names (account_mgr,
188                 TRUE /* only enabled accounts. */);
189
190         while (cursor) {
191                 gchar *account_name;
192                 ModestAccountData *account_data;
193                 
194                 account_name = (gchar*)cursor->data;
195                 
196                 account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
197                 if (!account_data) {
198                         g_printerr ("modest: failed to get account data for %s\n", account_name);
199                         continue;
200                 }
201
202                 /* don't display accounts without stores */
203                 if (account_data->store_account) {
204
205                         GtkTreeIter iter;
206                         
207                         gchar *last_updated_string = get_last_updated_string(account_mgr, account_data);
208                         
209                         if (account_data->is_enabled) {
210                                 const gchar *proto_name;
211
212                                 proto_name = modest_protocol_info_get_transport_store_protocol_name (account_data->store_account->proto);
213                                 gtk_list_store_insert_with_values (
214                                         model, &iter, 0,
215                                         MODEST_ACCOUNT_VIEW_NAME_COLUMN, account_name,
216                                         MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, account_data->display_name,
217                                         MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, account_data->is_enabled,
218                                         MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, account_data->is_default,
219                                         MODEST_ACCOUNT_VIEW_PROTO_COLUMN, proto_name,
220                                         MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN,  last_updated_string,
221                                         -1);
222                         }
223                         g_free (last_updated_string);
224                 }
225
226                 modest_account_mgr_free_account_data (account_mgr, account_data);
227                 cursor = cursor->next;
228         }
229
230         modest_account_mgr_free_account_names (account_names);
231         account_names = NULL;
232         
233         /* Try to re-select the same account: */
234         if (selected_name) {
235                 modest_account_view_select_account (view, selected_name);
236                 g_free (selected_name);
237         }
238 }
239
240 static void
241 on_account_busy_changed(ModestAccountMgr *account_mgr, 
242                         const gchar *account_name,
243                         gboolean busy, 
244                         ModestAccountView *self)
245 {
246         GtkListStore *model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(self)));
247         GtkTreeIter iter;
248         gboolean found = FALSE;
249
250         if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter))
251                 return;
252
253         do {
254                 gchar* cur_name;
255                 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 
256                                    MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
257                                    &cur_name, -1);
258
259                 if (g_str_equal(cur_name, account_name)) {
260                         ModestAccountData* account_data = 
261                                 modest_account_mgr_get_account_data (account_mgr, account_name);
262                         if (!account_data) {
263                                 g_free (cur_name);
264                                 return;
265                         }
266                         gchar* last_updated_string = get_last_updated_string(account_mgr, account_data);
267                         gtk_list_store_set(model, &iter, 
268                                            MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
269                                            -1);
270                         g_free (last_updated_string);
271                         modest_account_mgr_free_account_data (account_mgr, account_data);
272                         found = TRUE;
273                 }
274                 g_free (cur_name);
275
276         } while (!found && gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter));
277 }
278
279 static void
280 on_account_inserted (TnyAccountStore *account_store, 
281                      TnyAccount *account,
282                      gpointer user_data)
283 {
284         ModestAccountView *self;
285         ModestAccountViewPrivate *priv;
286
287         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (user_data));
288
289         self = MODEST_ACCOUNT_VIEW (user_data);
290         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
291
292         /* Do not refresh the view with transport accounts */
293         if (TNY_IS_STORE_ACCOUNT (account))
294                 update_account_view (priv->account_mgr, self);
295 }
296
297 static void
298 on_account_removed (TnyAccountStore *account_store, 
299                     TnyAccount *account,
300                     gpointer user_data)
301 {
302         ModestAccountView *self;
303         ModestAccountViewPrivate *priv;
304
305         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (user_data));
306
307         self = MODEST_ACCOUNT_VIEW (user_data);
308         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
309
310         update_account_view (priv->account_mgr, self);
311 }
312
313
314 static void
315 on_account_changed (TnyAccountStore *account_store, 
316                     TnyAccount *account,
317                     gpointer user_data)
318 {
319         ModestAccountView *self = NULL;
320         ModestAccountViewPrivate *priv = NULL;
321
322         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (user_data));
323         g_return_if_fail (account);
324         g_return_if_fail (TNY_IS_ACCOUNT (account));
325
326         self = MODEST_ACCOUNT_VIEW (user_data);
327         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
328         
329         g_warning ("account changed: %s", tny_account_get_id(account));
330         
331         /* Update account view */
332 /*      update_account_view (priv->account_mgr, self); */
333 }
334
335 static void
336 on_account_default_toggled (GtkCellRendererToggle *cell_renderer, 
337                             gchar *path,
338                             ModestAccountView *self)
339 {
340         ModestAccountViewPrivate *priv;
341         GtkTreeModel *model;
342         GtkTreeIter iter;
343         gchar *account_name = NULL;
344
345         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
346
347         /* If it's active then do nothing, no need to reenable it as
348            default account */
349         if (gtk_cell_renderer_toggle_get_active (cell_renderer))
350                 return;
351
352         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
353         model = gtk_tree_view_get_model (GTK_TREE_VIEW(self));  
354         gtk_tree_model_get_iter_from_string (model, &iter, path);
355         
356         gtk_tree_model_get (model, &iter, 
357                             MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
358                             &account_name, -1);
359
360         /* Set this previously-non-default account as the
361            default. We're not updating here the value of the
362            DEFAULT_COLUMN because we'll do it in the
363            "default_account_changed" signal handler. We do it like
364            this because that way the signal handler is useful also
365            when we're inserting a new account and there is no other
366            one defined, in that case the change of account is provoked
367            by the account mgr and not by a signal toggle.*/
368         modest_account_mgr_set_default_account (priv->account_mgr, account_name);
369
370         g_free (account_name);
371 }
372
373 void
374 bold_if_default_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
375                             GtkTreeModel *tree_model,  GtkTreeIter *iter,  gpointer user_data)
376 {
377         gboolean is_default;
378         gtk_tree_model_get (tree_model, iter, MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN,
379                             &is_default, -1);
380         g_object_set (G_OBJECT(renderer),
381                       "weight", is_default ? 800: 400,
382                       NULL);
383 }
384
385 static void
386 init_view (ModestAccountView *self)
387 {
388         ModestAccountViewPrivate *priv;
389         GtkCellRenderer *toggle_renderer, *text_renderer;
390         GtkListStore *model;
391         GtkTreeViewColumn *column;
392         
393         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
394         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
395                 
396         model = gtk_list_store_new (6,
397                                     G_TYPE_STRING,  /* account name */
398                                     G_TYPE_STRING,  /* account display name */
399                                     G_TYPE_BOOLEAN, /* is-enabled */
400                                     G_TYPE_BOOLEAN, /* is-default */
401                                     G_TYPE_STRING,  /* account proto (pop, imap,...) */
402                                     G_TYPE_STRING   /* last updated (time_t) */
403                 ); 
404                 
405         gtk_tree_sortable_set_sort_column_id (
406                 GTK_TREE_SORTABLE (model), MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, 
407                 GTK_SORT_ASCENDING);
408
409         gtk_tree_view_set_model (GTK_TREE_VIEW(self), GTK_TREE_MODEL(model));
410         g_object_unref (G_OBJECT (model));
411
412         toggle_renderer = gtk_cell_renderer_toggle_new ();
413         text_renderer = gtk_cell_renderer_text_new ();
414
415         /* the is_default column */
416         g_object_set (G_OBJECT(toggle_renderer), "activatable", TRUE, "radio", TRUE, NULL);
417         gtk_tree_view_append_column (GTK_TREE_VIEW(self),
418                                      gtk_tree_view_column_new_with_attributes (
419                                              _("mcen_ti_default"), toggle_renderer,
420                                              "active", MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, NULL));
421                                         
422         /* Disable the Maemo GtkTreeView::allow-checkbox-mode Maemo modification, 
423          * which causes the model column to be updated automatically when the row is clicked.
424          * Making this the default in Maemo's GTK+ is obviously a bug:
425          * https://maemo.org/bugzilla/show_bug.cgi?id=146
426          *
427          * djcb: indeed, they have been removed for post-bora, i added the ifdefs...
428          */
429 #ifdef MODEST_HAVE_HILDON0_WIDGETS
430         g_object_set(G_OBJECT(self), "allow-checkbox-mode", FALSE, NULL);
431         g_object_set(G_OBJECT(toggle_renderer), "checkbox-mode", FALSE, NULL);
432 #endif /* MODEST_HAVE_HILDON0_WIDGETS */
433
434         priv->sig_handlers = 
435                 modest_signal_mgr_connect (priv->sig_handlers,
436                                            G_OBJECT(toggle_renderer), 
437                                            "toggled", 
438                                            G_CALLBACK(on_account_default_toggled),
439                                            self);
440         
441         /* account name */
442         column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_account"), text_renderer, "text",
443                                                             MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, NULL);
444         gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);
445         gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
446                                                 NULL, NULL);
447
448         /* last update for this account */
449         column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_lastupdated"), text_renderer,"text",
450                                                             MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, NULL);
451         gtk_tree_view_append_column (GTK_TREE_VIEW(self),column);
452         gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
453                                                 NULL, NULL);
454                         
455         /* Show the column headers,
456          * which does not seem to be the default on Maemo.
457          */                     
458         gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE);
459
460         priv->sig_handlers = 
461                 modest_signal_mgr_connect (priv->sig_handlers, 
462                                            G_OBJECT (modest_runtime_get_account_store ()),
463                                            "account_removed",
464                                            G_CALLBACK(on_account_removed), 
465                                            self);
466         priv->sig_handlers = 
467                 modest_signal_mgr_connect (priv->sig_handlers, 
468                                            G_OBJECT (modest_runtime_get_account_store ()),
469                                            "account_inserted",
470                                            G_CALLBACK(on_account_inserted), 
471                                            self);
472         priv->sig_handlers = 
473                 modest_signal_mgr_connect (priv->sig_handlers, 
474                                            G_OBJECT (modest_runtime_get_account_store ()),
475                                            "account_changed",
476                                            G_CALLBACK(on_account_changed), 
477                                            self);
478         priv->sig_handlers = 
479                 modest_signal_mgr_connect (priv->sig_handlers, 
480                                            G_OBJECT(priv->account_mgr),
481                                            "account_busy_changed",
482                                            G_CALLBACK(on_account_busy_changed), 
483                                            self);
484         priv->sig_handlers = 
485                 modest_signal_mgr_connect (priv->sig_handlers, 
486                                            G_OBJECT(priv->account_mgr),
487                                            "default_account_changed",
488                                            G_CALLBACK(on_default_account_changed), 
489                                            self);
490 }
491
492
493 ModestAccountView*
494 modest_account_view_new (ModestAccountMgr *account_mgr)
495 {
496         GObject *obj;
497         ModestAccountViewPrivate *priv;
498         
499         g_return_val_if_fail (account_mgr, NULL);
500         
501         obj  = g_object_new(MODEST_TYPE_ACCOUNT_VIEW, NULL);
502         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
503         
504         g_object_ref (G_OBJECT (account_mgr));
505         priv->account_mgr = account_mgr;
506
507         init_view (MODEST_ACCOUNT_VIEW (obj));
508         update_account_view (account_mgr, MODEST_ACCOUNT_VIEW (obj));
509         
510         return MODEST_ACCOUNT_VIEW (obj);
511 }
512
513 gchar *
514 modest_account_view_get_selected_account (ModestAccountView *self)
515 {
516         gchar *account_name = NULL;
517         GtkTreeSelection *sel;
518         GtkTreeModel *model;
519         GtkTreeIter iter;
520
521         g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), NULL);
522         
523         sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
524         if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
525                 gtk_tree_model_get (model, &iter, 
526                                     MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
527                                     &account_name, -1);
528         }
529
530         return account_name;
531 }
532
533 /* This allows us to pass more than one piece of data to the signal handler,
534  * and get a result: */
535 typedef struct 
536 {
537                 ModestAccountView* self;
538                 const gchar *account_name;
539 } ForEachData;
540
541 static gboolean
542 on_model_foreach_select_account(GtkTreeModel *model, 
543         GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
544 {
545         ForEachData *state = (ForEachData*)(user_data);
546         
547         /* Select the item if it has the matching account name: */
548         gchar *this_account_name = NULL;
549         gtk_tree_model_get (model, iter, 
550                 MODEST_ACCOUNT_VIEW_NAME_COLUMN, &this_account_name, 
551                 -1); 
552         if(this_account_name && state->account_name 
553                 && (strcmp (this_account_name, state->account_name) == 0)) {
554                 
555                 GtkTreeSelection *selection = 
556                         gtk_tree_view_get_selection (GTK_TREE_VIEW (state->self));
557                 gtk_tree_selection_select_iter (selection, iter);
558                 
559                 return TRUE; /* Stop walking the tree. */
560         }
561         
562         return FALSE; /* Keep walking the tree. */
563 }
564
565 static void 
566 modest_account_view_select_account (ModestAccountView *account_view, 
567                                     const gchar* account_name)
568 {       
569         /* Create a state instance so we can send two items of data to the signal handler: */
570         ForEachData *state = g_new0 (ForEachData, 1);
571         state->self = account_view;
572         state->account_name = account_name;
573         
574         GtkTreeModel *model = gtk_tree_view_get_model (
575                 GTK_TREE_VIEW (account_view));
576         gtk_tree_model_foreach (model, 
577                 on_model_foreach_select_account, state);
578                 
579         g_free (state);
580 }
581
582 static void
583 on_default_account_changed (ModestAccountMgr *mgr,
584                             gpointer user_data)
585 {
586         GtkTreeIter iter;
587         gchar *default_account_name;
588         GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
589
590         if (!gtk_tree_model_get_iter_first(model, &iter))
591                 return;
592
593         default_account_name = modest_account_mgr_get_default_account (mgr);
594
595         do {
596                 gboolean is_default;
597                 gchar *name;
598
599                 gtk_tree_model_get (model, &iter, 
600                                     MODEST_ACCOUNT_VIEW_NAME_COLUMN, &name,
601                                     MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, &is_default, 
602                                     -1);
603
604                 /* Update the default account column */
605                 if (!strcmp (name, default_account_name))
606                         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
607                                             MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, TRUE, -1);
608                 else
609                         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
610                                             MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, FALSE, -1);
611
612                 g_free (name);
613
614         } while (gtk_tree_model_iter_next(model, &iter));
615
616         /* Free and force a redraw */
617         g_free (default_account_name);
618         gtk_widget_queue_draw (GTK_WIDGET (user_data));
619 }