a9d8836346df2b851bc875323c5ba6cfaab2be1f
[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         g_message(__FUNCTION__);
249         if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter))
250                 return;
251         do
252         {
253                 gchar* cur_name;
254                 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
255                                                                                          &cur_name, -1);
256                 if (g_str_equal(cur_name, account_name))
257                 {
258                         ModestAccountData* account_data = 
259                                 modest_account_mgr_get_account_data (account_mgr, account_name);
260                         if (!account_data)
261                                 return;
262                         gchar* last_updated_string = get_last_updated_string(account_mgr, account_data);
263                         gtk_list_store_set(model, &iter, 
264                                            MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
265                                            -1);
266                         g_free (last_updated_string);
267                         modest_account_mgr_free_account_data (account_mgr, account_data);
268                         return;
269                 }
270         }
271         while (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter));
272 }
273
274 static void
275 on_account_inserted (TnyAccountStore *account_store, 
276                      TnyAccount *account,
277                      gpointer user_data)
278 {
279         ModestAccountView *self;
280         ModestAccountViewPrivate *priv;
281
282         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (user_data));
283
284         self = MODEST_ACCOUNT_VIEW (user_data);
285         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
286
287         /* Do not refresh the view with transport accounts */
288         if (TNY_IS_STORE_ACCOUNT (account))
289                 update_account_view (priv->account_mgr, self);
290 }
291
292 static void
293 on_account_removed (TnyAccountStore *account_store, 
294                     TnyAccount *account,
295                     gpointer user_data)
296 {
297         ModestAccountView *self;
298         ModestAccountViewPrivate *priv;
299
300         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (user_data));
301
302         self = MODEST_ACCOUNT_VIEW (user_data);
303         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
304
305         update_account_view (priv->account_mgr, self);
306 }
307
308
309 static void
310 on_account_changed (TnyAccountStore *account_store, 
311                     TnyAccount *account,
312                     gpointer user_data)
313 {
314         ModestAccountView *self = NULL;
315         ModestAccountViewPrivate *priv = NULL;
316
317         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (user_data));
318         g_return_if_fail (account);
319         g_return_if_fail (TNY_IS_ACCOUNT (account));
320
321         self = MODEST_ACCOUNT_VIEW (user_data);
322         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
323         
324         g_warning ("account changed: %s", tny_account_get_id(account));
325         
326         /* Update account view */
327 /*      update_account_view (priv->account_mgr, self); */
328 }
329
330 static void
331 on_account_default_toggled (GtkCellRendererToggle *cell_renderer, 
332                             gchar *path,
333                             ModestAccountView *self)
334 {
335         ModestAccountViewPrivate *priv;
336         GtkTreeModel *model;
337         GtkTreeIter iter;
338         gchar *account_name = NULL;
339
340         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
341
342         /* If it's active then do nothing, no need to reenable it as
343            default account */
344         if (gtk_cell_renderer_toggle_get_active (cell_renderer))
345                 return;
346
347         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
348         model = gtk_tree_view_get_model (GTK_TREE_VIEW(self));  
349         gtk_tree_model_get_iter_from_string (model, &iter, path);
350         
351         gtk_tree_model_get (model, &iter, 
352                             MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
353                             &account_name, -1);
354
355         /* Set this previously-non-default account as the
356            default. We're not updating here the value of the
357            DEFAULT_COLUMN because we'll do it in the
358            "default_account_changed" signal handler. We do it like
359            this because that way the signal handler is useful also
360            when we're inserting a new account and there is no other
361            one defined, in that case the change of account is provoked
362            by the account mgr and not by a signal toggle.*/
363         modest_account_mgr_set_default_account (priv->account_mgr, account_name);
364
365         g_free (account_name);
366 }
367
368 void
369 bold_if_default_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
370                             GtkTreeModel *tree_model,  GtkTreeIter *iter,  gpointer user_data)
371 {
372         gboolean is_default;
373         gtk_tree_model_get (tree_model, iter, MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN,
374                             &is_default, -1);
375         g_object_set (G_OBJECT(renderer),
376                       "weight", is_default ? 800: 400,
377                       NULL);
378 }
379
380 static void
381 init_view (ModestAccountView *self)
382 {
383         ModestAccountViewPrivate *priv;
384         GtkCellRenderer *toggle_renderer, *text_renderer;
385         GtkListStore *model;
386         GtkTreeViewColumn *column;
387         
388         g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
389         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
390                 
391         model = gtk_list_store_new (6,
392                                     G_TYPE_STRING,  /* account name */
393                                     G_TYPE_STRING,  /* account display name */
394                                     G_TYPE_BOOLEAN, /* is-enabled */
395                                     G_TYPE_BOOLEAN, /* is-default */
396                                     G_TYPE_STRING,  /* account proto (pop, imap,...) */
397                                     G_TYPE_STRING   /* last updated (time_t) */
398                 ); 
399                 
400         gtk_tree_sortable_set_sort_column_id (
401                 GTK_TREE_SORTABLE (model), MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, 
402                 GTK_SORT_ASCENDING);
403
404         gtk_tree_view_set_model (GTK_TREE_VIEW(self), GTK_TREE_MODEL(model));
405         g_object_unref (G_OBJECT (model));
406
407         toggle_renderer = gtk_cell_renderer_toggle_new ();
408         text_renderer = gtk_cell_renderer_text_new ();
409
410         /* the is_default column */
411         g_object_set (G_OBJECT(toggle_renderer), "activatable", TRUE, "radio", TRUE, NULL);
412         gtk_tree_view_append_column (GTK_TREE_VIEW(self),
413                                      gtk_tree_view_column_new_with_attributes (
414                                              _("mcen_ti_default"), toggle_renderer,
415                                              "active", MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, NULL));
416                                         
417         /* Disable the Maemo GtkTreeView::allow-checkbox-mode Maemo modification, 
418          * which causes the model column to be updated automatically when the row is clicked.
419          * Making this the default in Maemo's GTK+ is obviously a bug:
420          * https://maemo.org/bugzilla/show_bug.cgi?id=146
421          *
422          * djcb: indeed, they have been removed for post-bora, i added the ifdefs...
423          */
424 #ifdef MODEST_HAVE_HILDON0_WIDGETS
425         g_object_set(G_OBJECT(self), "allow-checkbox-mode", FALSE, NULL);
426         g_object_set(G_OBJECT(toggle_renderer), "checkbox-mode", FALSE, NULL);
427 #endif /* MODEST_HAVE_HILDON0_WIDGETS */
428
429         priv->sig_handlers = 
430                 modest_signal_mgr_connect (priv->sig_handlers,
431                                            G_OBJECT(toggle_renderer), 
432                                            "toggled", 
433                                            G_CALLBACK(on_account_default_toggled),
434                                            self);
435         
436         /* account name */
437         column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_account"), text_renderer, "text",
438                                                             MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, NULL);
439         gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);
440         gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
441                                                 NULL, NULL);
442
443         /* last update for this account */
444         column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_lastupdated"), text_renderer,"text",
445                                                             MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, NULL);
446         gtk_tree_view_append_column (GTK_TREE_VIEW(self),column);
447         gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
448                                                 NULL, NULL);
449                         
450         /* Show the column headers,
451          * which does not seem to be the default on Maemo.
452          */                     
453         gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE);
454
455         priv->sig_handlers = 
456                 modest_signal_mgr_connect (priv->sig_handlers, 
457                                            G_OBJECT (modest_runtime_get_account_store ()),
458                                            "account_removed",
459                                            G_CALLBACK(on_account_removed), 
460                                            self);
461         priv->sig_handlers = 
462                 modest_signal_mgr_connect (priv->sig_handlers, 
463                                            G_OBJECT (modest_runtime_get_account_store ()),
464                                            "account_inserted",
465                                            G_CALLBACK(on_account_inserted), 
466                                            self);
467         priv->sig_handlers = 
468                 modest_signal_mgr_connect (priv->sig_handlers, 
469                                            G_OBJECT (modest_runtime_get_account_store ()),
470                                            "account_changed",
471                                            G_CALLBACK(on_account_changed), 
472                                            self);
473         priv->sig_handlers = 
474                 modest_signal_mgr_connect (priv->sig_handlers, 
475                                            G_OBJECT(priv->account_mgr),
476                                            "account_busy_changed",
477                                            G_CALLBACK(on_account_busy_changed), 
478                                            self);
479         priv->sig_handlers = 
480                 modest_signal_mgr_connect (priv->sig_handlers, 
481                                            G_OBJECT(priv->account_mgr),
482                                            "default_account_changed",
483                                            G_CALLBACK(on_default_account_changed), 
484                                            self);
485 }
486
487
488 ModestAccountView*
489 modest_account_view_new (ModestAccountMgr *account_mgr)
490 {
491         GObject *obj;
492         ModestAccountViewPrivate *priv;
493         
494         g_return_val_if_fail (account_mgr, NULL);
495         
496         obj  = g_object_new(MODEST_TYPE_ACCOUNT_VIEW, NULL);
497         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
498         
499         g_object_ref (G_OBJECT (account_mgr));
500         priv->account_mgr = account_mgr;
501
502         init_view (MODEST_ACCOUNT_VIEW (obj));
503         update_account_view (account_mgr, MODEST_ACCOUNT_VIEW (obj));
504         
505         return MODEST_ACCOUNT_VIEW (obj);
506 }
507
508 gchar *
509 modest_account_view_get_selected_account (ModestAccountView *self)
510 {
511         gchar *account_name = NULL;
512         GtkTreeSelection *sel;
513         GtkTreeModel *model;
514         GtkTreeIter iter;
515
516         g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), NULL);
517         
518         sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
519         if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
520                 gtk_tree_model_get (model, &iter, 
521                                     MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
522                                     &account_name, -1);
523         }
524
525         return account_name;
526 }
527
528 /* This allows us to pass more than one piece of data to the signal handler,
529  * and get a result: */
530 typedef struct 
531 {
532                 ModestAccountView* self;
533                 const gchar *account_name;
534 } ForEachData;
535
536 static gboolean
537 on_model_foreach_select_account(GtkTreeModel *model, 
538         GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
539 {
540         ForEachData *state = (ForEachData*)(user_data);
541         
542         /* Select the item if it has the matching account name: */
543         gchar *this_account_name = NULL;
544         gtk_tree_model_get (model, iter, 
545                 MODEST_ACCOUNT_VIEW_NAME_COLUMN, &this_account_name, 
546                 -1); 
547         if(this_account_name && state->account_name 
548                 && (strcmp (this_account_name, state->account_name) == 0)) {
549                 
550                 GtkTreeSelection *selection = 
551                         gtk_tree_view_get_selection (GTK_TREE_VIEW (state->self));
552                 gtk_tree_selection_select_iter (selection, iter);
553                 
554                 return TRUE; /* Stop walking the tree. */
555         }
556         
557         return FALSE; /* Keep walking the tree. */
558 }
559
560 static void 
561 modest_account_view_select_account (ModestAccountView *account_view, 
562                                     const gchar* account_name)
563 {       
564         /* Create a state instance so we can send two items of data to the signal handler: */
565         ForEachData *state = g_new0 (ForEachData, 1);
566         state->self = account_view;
567         state->account_name = account_name;
568         
569         GtkTreeModel *model = gtk_tree_view_get_model (
570                 GTK_TREE_VIEW (account_view));
571         gtk_tree_model_foreach (model, 
572                 on_model_foreach_select_account, state);
573                 
574         g_free (state);
575 }
576
577 static void
578 on_default_account_changed (ModestAccountMgr *mgr,
579                             gpointer user_data)
580 {
581         GtkTreeIter iter;
582         gchar *default_account_name;
583         GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
584
585         if (!gtk_tree_model_get_iter_first(model, &iter))
586                 return;
587
588         default_account_name = modest_account_mgr_get_default_account (mgr);
589
590         do {
591                 gboolean is_default;
592                 gchar *name;
593
594                 gtk_tree_model_get (model, &iter, 
595                                     MODEST_ACCOUNT_VIEW_NAME_COLUMN, &name,
596                                     MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, &is_default, 
597                                     -1);
598
599                 /* Update the default account column */
600                 if (!strcmp (name, default_account_name))
601                         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
602                                             MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, TRUE, -1);
603                 else
604                         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
605                                             MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, FALSE, -1);
606
607                 g_free (name);
608
609         } while (gtk_tree_model_iter_next(model, &iter));
610
611         /* Free and force a redraw */
612         g_free (default_account_name);
613         gtk_widget_queue_draw (GTK_WIDGET (user_data));
614 }