* step 2 of the account fixes; for now, account changes
[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-text-utils.h>
36 #include <modest-runtime.h>
37
38 #include <gtk/gtkcellrenderertoggle.h>
39 #include <gtk/gtkcellrenderertext.h>
40 #include <gtk/gtktreeselection.h>
41 #include <gtk/gtkliststore.h>
42 #include <string.h> /* For strcmp(). */
43
44 /* 'private'/'protected' functions */
45 static void modest_account_view_class_init    (ModestAccountViewClass *klass);
46 static void modest_account_view_init          (ModestAccountView *obj);
47 static void modest_account_view_finalize      (GObject *obj);
48
49 static void modest_account_view_select_account (ModestAccountView *account_view, 
50         const gchar* account_name);
51
52 typedef enum {
53         MODEST_ACCOUNT_VIEW_NAME_COLUMN,
54         MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN,
55         MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN,
56         MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN,
57         MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
58         MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN,
59
60         MODEST_ACCOUNT_VIEW_COLUMN_NUM
61 } AccountViewColumns;
62
63 typedef struct _ModestAccountViewPrivate ModestAccountViewPrivate;
64 struct _ModestAccountViewPrivate {
65         ModestAccountMgr *account_mgr;
66
67         /* Signal handlers */
68         gulong acc_inserted_handler, acc_removed_handler,
69                 acc_busy_changed_handler, acc_changed_handler;
70 };
71 #define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
72                                                  MODEST_TYPE_ACCOUNT_VIEW, \
73                                                  ModestAccountViewPrivate))
74 /* globals */
75 static GtkTreeViewClass *parent_class = NULL;
76
77 GType
78 modest_account_view_get_type (void)
79 {
80         static GType my_type = 0;
81         if (!my_type) {
82                 static const GTypeInfo my_info = {
83                         sizeof(ModestAccountViewClass),
84                         NULL,           /* base init */
85                         NULL,           /* base finalize */
86                         (GClassInitFunc) modest_account_view_class_init,
87                         NULL,           /* class finalize */
88                         NULL,           /* class data */
89                         sizeof(ModestAccountView),
90                         1,              /* n_preallocs */
91                         (GInstanceInitFunc) modest_account_view_init,
92                         NULL
93                 };
94                 my_type = g_type_register_static (GTK_TYPE_TREE_VIEW,
95                                                   "ModestAccountView",
96                                                   &my_info, 0);
97         }
98         return my_type;
99 }
100
101 static void
102 modest_account_view_class_init (ModestAccountViewClass *klass)
103 {
104         GObjectClass *gobject_class;
105         gobject_class = (GObjectClass*) klass;
106
107         parent_class            = g_type_class_peek_parent (klass);
108         gobject_class->finalize = modest_account_view_finalize;
109
110         g_type_class_add_private (gobject_class, sizeof(ModestAccountViewPrivate));
111 }
112
113 static void
114 modest_account_view_init (ModestAccountView *obj)
115 {
116         ModestAccountViewPrivate *priv;
117
118         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
119         
120         priv->account_mgr = NULL; 
121         priv->acc_inserted_handler = 0;
122         priv->acc_removed_handler = 0;
123         priv->acc_busy_changed_handler = 0;
124         priv->acc_changed_handler = 0;
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         if (priv->account_mgr) {
135                 if (g_signal_handler_is_connected (modest_runtime_get_account_store (),
136                                                    priv->acc_inserted_handler))
137                         g_signal_handler_disconnect (modest_runtime_get_account_store (), 
138                                                      priv->acc_inserted_handler);
139
140                 if (g_signal_handler_is_connected (modest_runtime_get_account_store (),
141                                                    priv->acc_removed_handler))
142                         g_signal_handler_disconnect (modest_runtime_get_account_store (), 
143                                                      priv->acc_removed_handler);
144
145                 if (priv->acc_busy_changed_handler)
146                         g_signal_handler_disconnect (priv->account_mgr, priv->acc_busy_changed_handler);
147                 if (priv->acc_changed_handler)
148                         g_signal_handler_disconnect (priv->account_mgr, priv->acc_changed_handler);
149                 
150                 g_object_unref (G_OBJECT(priv->account_mgr));
151                 priv->account_mgr = NULL; 
152         }
153         
154         G_OBJECT_CLASS(parent_class)->finalize (obj);
155 }
156
157 /* Get the string for the last updated time. Result must be g_freed */
158 static gchar*
159 get_last_updated_string(ModestAccountMgr* account_mgr, ModestAccountData *account_data)
160 {
161         /* FIXME: let's assume that 'last update' applies to the store account... */
162         gchar* last_updated_string;
163         time_t last_updated = account_data->store_account->last_updated;
164         if (!modest_account_mgr_account_is_busy(account_mgr, account_data->account_name)) {
165                 if (last_updated > 0) 
166                         last_updated_string = modest_text_utils_get_display_date(last_updated);
167                 else
168                         last_updated_string = g_strdup (_("mcen_va_never"));
169         } else  {
170                 /* FIXME: There should be a logical name in the UI specs */
171                 last_updated_string = g_strdup(_("..."));
172         }
173         return last_updated_string;
174 }
175
176 static void
177 update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
178 {
179         GSList *account_names, *cursor;
180         GtkListStore *model;
181                 
182         model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(view)));
183         
184         /* Get the ID of the currently-selected account, 
185          * so we can select it again after rebuilding the list.
186          * Note that the name doesn't change even when the display name changes.
187          */
188         gchar *selected_name = modest_account_view_get_selected_account (view);
189
190         gtk_list_store_clear (model);
191
192         /* Note: We do not show disabled accounts.
193          * Of course, this means that there is no UI to enable or disable 
194          * accounts. That is OK for maemo where no such feature or UI is 
195          * specified, so the "enabled" property is used internally to avoid 
196          * showing unfinished accounts. If a user-visible "enabled" is 
197          * needed in the future, we must use a second property for the 
198          * current use instead */
199         cursor = account_names = modest_account_mgr_account_names (account_mgr,
200                 TRUE /* only enabled accounts. */);
201
202         while (cursor) {
203                 gchar *account_name;
204                 ModestAccountData *account_data;
205                 
206                 account_name = (gchar*)cursor->data;
207                 
208                 account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
209                 if (!account_data) {
210                         g_printerr ("modest: failed to get account data for %s\n", account_name);
211                         continue;
212                 }
213
214                 /* don't display accounts without stores */
215                 if (account_data->store_account) {
216
217                         GtkTreeIter iter;
218                         
219                         gchar *last_updated_string = get_last_updated_string(account_mgr, account_data);
220                         
221                         if (account_data->is_enabled) {
222                                 gtk_list_store_insert_with_values (
223                                         model, &iter, 0,
224                                         MODEST_ACCOUNT_VIEW_NAME_COLUMN,          account_name,
225                                         MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN,  account_data->display_name,
226                                         MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN,    account_data->is_enabled,
227                                         MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN,    account_data->is_default,
228
229                                         MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
230                                         modest_protocol_info_get_transport_store_protocol_name (account_data->store_account->proto),
231         
232                                         MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN,  last_updated_string,
233                                         -1);
234                         }
235                         g_free (last_updated_string);
236                 }
237
238                 modest_account_mgr_free_account_data (account_mgr, account_data);
239                 cursor = cursor->next;
240         }
241
242         modest_account_mgr_free_account_names (account_names);
243         account_names = NULL;
244         
245         /* Try to re-select the same account: */
246         if (selected_name) {
247                 modest_account_view_select_account (view, selected_name);
248                 g_free (selected_name);
249         }
250 }
251
252 static void
253 on_account_busy_changed(ModestAccountMgr *account_mgr, 
254                         const gchar *account_name,
255                         gboolean busy, 
256                         ModestAccountView *self)
257 {
258         GtkListStore *model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(self)));
259         GtkTreeIter iter;
260         g_message(__FUNCTION__);
261         if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter))
262                 return;
263         do
264         {
265                 gchar* cur_name;
266                 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
267                                                                                          &cur_name, -1);
268                 if (g_str_equal(cur_name, account_name))
269                 {
270                         ModestAccountData* account_data = 
271                                 modest_account_mgr_get_account_data (account_mgr, account_name);
272                         if (!account_data)
273                                 return;
274                         gchar* last_updated_string = get_last_updated_string(account_mgr, account_data);
275                         gtk_list_store_set(model, &iter, 
276                                            MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
277                                            -1);
278                         g_free (last_updated_string);
279                         modest_account_mgr_free_account_data (account_mgr, account_data);
280                         return;
281                 }
282         }
283         while (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter));
284 }
285
286 static void
287 on_account_inserted (TnyAccountStore *account_store, 
288                      TnyAccount *account,
289                      gpointer user_data)
290 {
291         ModestAccountView *self;
292         ModestAccountViewPrivate *priv;
293
294         self = MODEST_ACCOUNT_VIEW (user_data);
295         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
296
297         update_account_view (priv->account_mgr, self);
298 }
299
300 static void
301 on_account_removed (TnyAccountStore *account_store, 
302                     TnyAccount *account,
303                     gpointer user_data)
304 {
305         ModestAccountView *self;
306         ModestAccountViewPrivate *priv;
307
308         self = MODEST_ACCOUNT_VIEW (user_data);
309         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
310
311         update_account_view (priv->account_mgr, self);
312 }
313
314
315 static void
316 on_account_changed (TnyAccountStore *account_store, 
317                     TnyAccount *account,
318                     gpointer user_data)
319 {
320         ModestAccountView *self;
321         ModestAccountViewPrivate *priv;
322
323         self = MODEST_ACCOUNT_VIEW (user_data);
324         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
325
326         g_warning ("account changed: %s", tny_account_get_id(account));
327         
328         update_account_view (priv->account_mgr, self);
329 }
330
331
332
333 static gboolean
334 find_default_account(ModestAccountView *self, GtkTreeIter *iter)
335 {
336         GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
337         gboolean result;
338         for (result = gtk_tree_model_get_iter_first(model, iter);
339              result == TRUE; result = gtk_tree_model_iter_next(model, iter))
340         {
341                 gboolean is_default;
342                 gtk_tree_model_get (model, iter, MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, &is_default, -1);
343                 if(is_default)
344                         return TRUE;
345         }
346
347         return FALSE;
348 }
349
350 static void
351 on_account_default_toggled (GtkCellRendererToggle *cell_renderer, gchar *path,
352                            ModestAccountView *self)
353 {
354         gboolean is_default = gtk_cell_renderer_toggle_get_active (cell_renderer);
355         if (is_default) {
356                 /* Do not allow an account to be marked non-default.
357                  * Only allow this to be changed by setting another account to default: */
358                 gtk_cell_renderer_toggle_set_active (cell_renderer, TRUE);
359                 return;
360         }
361
362         ModestAccountViewPrivate *priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
363         GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(self));
364         
365         GtkTreeIter iter;
366         if (!gtk_tree_model_get_iter_from_string (model, &iter, path)) {
367                 g_printerr ("modest: cannot find iterator\n");
368                 return;
369         }
370         
371         gchar *account_name = NULL;
372         gtk_tree_model_get (model, &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, &account_name,
373                             -1);
374         
375         /* Set this previously-non-default account as the default: */
376         if (modest_account_mgr_set_default_account (priv->account_mgr, account_name))
377         {
378                 /* Explicitely set default column because we are ignoring gconf changes */
379                 GtkTreeIter old_default_iter;
380                 if (find_default_account (self, &old_default_iter)) {
381                         gtk_list_store_set (GTK_LIST_STORE (model), &old_default_iter,
382                                             MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, FALSE, -1);
383                 } else {
384                         g_warning ("%s: Did not find old default account in view", __FUNCTION__);
385                 }
386
387                 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
388                                     MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, TRUE, -1);
389         }
390
391         g_free (account_name);
392 }
393
394 void
395 bold_if_default_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
396                             GtkTreeModel *tree_model,  GtkTreeIter *iter,  gpointer user_data)
397 {
398         gboolean is_default;
399         gtk_tree_model_get (tree_model, iter, MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN,
400                             &is_default, -1);
401         g_object_set (G_OBJECT(renderer),
402                       "weight", is_default ? 800: 400,
403                       NULL);
404 }
405
406 static void
407 init_view (ModestAccountView *self)
408 {
409         ModestAccountViewPrivate *priv;
410         GtkCellRenderer *toggle_renderer, *text_renderer;
411         GtkListStore *model;
412         GtkTreeViewColumn *column;
413         
414         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
415                 
416         model = gtk_list_store_new (6,
417                                     G_TYPE_STRING,  /* account name */
418                                     G_TYPE_STRING,  /* account display name */
419                                     G_TYPE_BOOLEAN, /* is-enabled */
420                                     G_TYPE_BOOLEAN, /* is-default */
421                                     G_TYPE_STRING,  /* account proto (pop, imap,...) */
422                                     G_TYPE_STRING   /* last updated (time_t) */
423                 ); 
424                 
425         gtk_tree_sortable_set_sort_column_id (
426                 GTK_TREE_SORTABLE (model), MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, 
427                 GTK_SORT_ASCENDING);
428
429         gtk_tree_view_set_model (GTK_TREE_VIEW(self), GTK_TREE_MODEL(model));
430         g_object_unref (G_OBJECT (model));
431
432         toggle_renderer = gtk_cell_renderer_toggle_new ();
433         text_renderer = gtk_cell_renderer_text_new ();
434
435         /* the is_default column */
436         g_object_set (G_OBJECT(toggle_renderer), "activatable", TRUE, "radio", TRUE, NULL);
437         gtk_tree_view_append_column (GTK_TREE_VIEW(self),
438                                      gtk_tree_view_column_new_with_attributes (
439                                              _("mcen_ti_default"), toggle_renderer,
440                                              "active", MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, NULL));
441                                         
442         /* Disable the Maemo GtkTreeView::allow-checkbox-mode Maemo modification, 
443          * which causes the model column to be updated automatically when the row is clicked.
444          * Making this the default in Maemo's GTK+ is obviously a bug:
445          * https://maemo.org/bugzilla/show_bug.cgi?id=146
446          *
447          * djcb: indeed, they have been removed for post-bora, i added the ifdefs...
448          */
449 #ifdef MODEST_HILDON_VERSION_0  
450         g_object_set(G_OBJECT(self), "allow-checkbox-mode", FALSE, NULL);
451         g_object_set(G_OBJECT(toggle_renderer), "checkbox-mode", FALSE, NULL);
452 #endif /*MODEST_HILDON_VERSION_0 */
453         g_signal_connect (G_OBJECT(toggle_renderer), "toggled", G_CALLBACK(on_account_default_toggled),
454                           self);
455         
456         /* account name */
457         column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_account"), text_renderer, "text",
458                                                             MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, NULL);
459         gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);
460         gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
461                                                 NULL, NULL);
462
463         /* last update for this account */
464         column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_lastupdated"), text_renderer,"text",
465                                                             MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, NULL);
466         gtk_tree_view_append_column (GTK_TREE_VIEW(self),column);
467         gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
468                                                 NULL, NULL);
469                         
470         /* Show the column headers,
471          * which does not seem to be the default on Maemo.
472          */                     
473         gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE);
474
475         priv->acc_removed_handler = g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),
476                                                       "account_removed",
477                                                       G_CALLBACK(on_account_removed), self);
478
479         priv->acc_inserted_handler = g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),
480                                                        "account_inserted",
481                                                        G_CALLBACK(on_account_inserted), self);
482         
483         priv->acc_busy_changed_handler = g_signal_connect (G_OBJECT(priv->account_mgr),
484                                                            "account_busy_changed",
485                                                            G_CALLBACK(on_account_busy_changed), self);
486
487         priv->acc_changed_handler = g_signal_connect (G_OBJECT(priv->account_mgr),
488                                                       "account_changed",
489                                                       G_CALLBACK(on_account_changed), self);
490 }
491
492
493
494 ModestAccountView*
495 modest_account_view_new (ModestAccountMgr *account_mgr)
496 {
497         GObject *obj;
498         ModestAccountViewPrivate *priv;
499         
500         g_return_val_if_fail (account_mgr, NULL);
501         
502         obj  = g_object_new(MODEST_TYPE_ACCOUNT_VIEW, NULL);
503         priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
504         
505         g_object_ref (G_OBJECT (account_mgr));
506         priv->account_mgr = account_mgr;
507
508         init_view (MODEST_ACCOUNT_VIEW (obj));
509         update_account_view (account_mgr, MODEST_ACCOUNT_VIEW (obj));
510         
511         return MODEST_ACCOUNT_VIEW (obj);
512 }
513
514 gchar *
515 modest_account_view_get_selected_account (ModestAccountView *self)
516 {
517         gchar *account_name = NULL;
518         GtkTreeSelection *sel;
519         GtkTreeModel *model;
520         GtkTreeIter iter;
521
522         g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), NULL);
523         
524         sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
525         if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
526                 gtk_tree_model_get (model, &iter, 
527                                     MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
528                                     &account_name, -1);
529         }
530
531         return account_name;
532 }
533
534 /* This allows us to pass more than one piece of data to the signal handler,
535  * and get a result: */
536 typedef struct 
537 {
538                 ModestAccountView* self;
539                 const gchar *account_name;
540 } ForEachData;
541
542 static gboolean
543 on_model_foreach_select_account(GtkTreeModel *model, 
544         GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
545 {
546         ForEachData *state = (ForEachData*)(user_data);
547         
548         /* Select the item if it has the matching account name: */
549         gchar *this_account_name = NULL;
550         gtk_tree_model_get (model, iter, 
551                 MODEST_ACCOUNT_VIEW_NAME_COLUMN, &this_account_name, 
552                 -1); 
553         if(this_account_name && state->account_name 
554                 && (strcmp (this_account_name, state->account_name) == 0)) {
555                 
556                 GtkTreeSelection *selection = 
557                         gtk_tree_view_get_selection (GTK_TREE_VIEW (state->self));
558                 gtk_tree_selection_select_iter (selection, iter);
559                 
560                 return TRUE; /* Stop walking the tree. */
561         }
562         
563         return FALSE; /* Keep walking the tree. */
564 }
565
566 static void 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