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