* First review of ModestFolderView visual names for folders
[modest] / src / widgets / modest-folder-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 <string.h>
32
33 #include <tny-account-store-view.h>
34 #include <tny-gtk-account-list-model.h>
35 #include <tny-gtk-folder-store-tree-model.h>
36 #include <tny-gtk-header-list-model.h>
37 #include <tny-folder.h>
38 #include <tny-account-store.h>
39 #include <tny-account.h>
40 #include <tny-folder.h>
41 #include <tny-camel-folder.h>
42 #include <tny-simple-list.h>
43 #include <modest-tny-folder.h>
44 #include <modest-marshal.h>
45 #include <modest-icon-names.h>
46 #include <modest-tny-account-store.h>
47 #include <modest-text-utils.h>
48 #include <modest-runtime.h>
49 #include "modest-folder-view.h"
50 #include <modest-dnd.h>
51 #include <modest-platform.h>
52
53 /* 'private'/'protected' functions */
54 static void modest_folder_view_class_init  (ModestFolderViewClass *klass);
55 static void modest_folder_view_init        (ModestFolderView *obj);
56 static void modest_folder_view_finalize    (GObject *obj);
57
58 static void         tny_account_store_view_init (gpointer g, 
59                                                  gpointer iface_data);
60
61 static void         modest_folder_view_set_account_store (TnyAccountStoreView *self, 
62                                                           TnyAccountStore     *account_store);
63
64 static gboolean     update_model           (ModestFolderView *self,
65                                             ModestTnyAccountStore *account_store);
66
67 static void         on_selection_changed   (GtkTreeSelection *sel, gpointer data);
68
69 static void         on_account_update      (TnyAccountStore *account_store, 
70                                             const gchar *account,
71                                             gpointer user_data);
72
73 static void         on_accounts_reloaded   (TnyAccountStore *store, 
74                                             gpointer user_data);
75
76 static gint         cmp_rows               (GtkTreeModel *tree_model, 
77                                             GtkTreeIter *iter1, 
78                                             GtkTreeIter *iter2,
79                                             gpointer user_data);
80
81 /* DnD functions */
82 static void         on_drag_data_get       (GtkWidget *widget, 
83                                             GdkDragContext *context, 
84                                             GtkSelectionData *selection_data, 
85                                             guint info, 
86                                             guint time, 
87                                             gpointer data);
88
89 static void         on_drag_data_received  (GtkWidget *widget, 
90                                             GdkDragContext *context, 
91                                             gint x, 
92                                             gint y, 
93                                             GtkSelectionData *selection_data, 
94                                             guint info, 
95                                             guint time, 
96                                             gpointer data);
97
98 static gboolean     on_drag_motion         (GtkWidget      *widget,
99                                             GdkDragContext *context,
100                                             gint            x,
101                                             gint            y,
102                                             guint           time,
103                                             gpointer        user_data);
104
105 static gint         expand_row_timeout     (gpointer data);
106
107 static void         setup_drag_and_drop    (GtkTreeView *self);
108
109 static gboolean     on_key_pressed         (GtkWidget *self,
110                                             GdkEventKey *event,
111                                             gpointer user_data);
112
113 static void         on_configuration_key_changed         (ModestConf* conf, 
114                                                           const gchar *key, 
115                                                           ModestConfEvent event, 
116                                                           ModestFolderView *self);
117
118 enum {
119         FOLDER_SELECTION_CHANGED_SIGNAL,
120         LAST_SIGNAL
121 };
122
123 typedef struct _ModestFolderViewPrivate ModestFolderViewPrivate;
124 struct _ModestFolderViewPrivate {
125         TnyAccountStore     *account_store;
126         TnyFolder           *cur_folder;
127         GtkTreeRowReference *cur_row;
128
129         gulong               account_update_signal;
130         gulong               changed_signal;
131         gulong               accounts_reloaded_signal;
132         
133         GtkTreeSelection    *cur_selection;
134         TnyFolderStoreQuery *query;
135         guint                timer_expander;
136
137         gchar               *local_account_name;
138 };
139 #define MODEST_FOLDER_VIEW_GET_PRIVATE(o)                       \
140         (G_TYPE_INSTANCE_GET_PRIVATE((o),                       \
141                                      MODEST_TYPE_FOLDER_VIEW,   \
142                                      ModestFolderViewPrivate))
143 /* globals */
144 static GObjectClass *parent_class = NULL;
145
146 static guint signals[LAST_SIGNAL] = {0}; 
147
148 GType
149 modest_folder_view_get_type (void)
150 {
151         static GType my_type = 0;
152         if (!my_type) {
153                 static const GTypeInfo my_info = {
154                         sizeof(ModestFolderViewClass),
155                         NULL,           /* base init */
156                         NULL,           /* base finalize */
157                         (GClassInitFunc) modest_folder_view_class_init,
158                         NULL,           /* class finalize */
159                         NULL,           /* class data */
160                         sizeof(ModestFolderView),
161                         1,              /* n_preallocs */
162                         (GInstanceInitFunc) modest_folder_view_init,
163                         NULL
164                 };
165
166                 static const GInterfaceInfo tny_account_store_view_info = {
167                         (GInterfaceInitFunc) tny_account_store_view_init, /* interface_init */
168                         NULL,         /* interface_finalize */
169                         NULL          /* interface_data */
170                 };
171
172                                 
173                 my_type = g_type_register_static (GTK_TYPE_TREE_VIEW,
174                                                   "ModestFolderView",
175                                                   &my_info, 0);
176
177                 g_type_add_interface_static (my_type, 
178                                              TNY_TYPE_ACCOUNT_STORE_VIEW, 
179                                              &tny_account_store_view_info);
180         }
181         return my_type;
182 }
183
184 static void
185 modest_folder_view_class_init (ModestFolderViewClass *klass)
186 {
187         GObjectClass *gobject_class;
188         gobject_class = (GObjectClass*) klass;
189
190         parent_class            = g_type_class_peek_parent (klass);
191         gobject_class->finalize = modest_folder_view_finalize;
192
193         g_type_class_add_private (gobject_class,
194                                   sizeof(ModestFolderViewPrivate));
195         
196         signals[FOLDER_SELECTION_CHANGED_SIGNAL] = 
197                 g_signal_new ("folder_selection_changed",
198                               G_TYPE_FROM_CLASS (gobject_class),
199                               G_SIGNAL_RUN_FIRST,
200                               G_STRUCT_OFFSET (ModestFolderViewClass,
201                                                folder_selection_changed),
202                               NULL, NULL,
203                               modest_marshal_VOID__POINTER_BOOLEAN,
204                               G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
205 }
206
207
208
209 static void
210 text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
211                  GtkTreeModel *tree_model,  GtkTreeIter *iter,  gpointer data)
212 {
213         GObject *rendobj;
214         gchar *fname = NULL;
215         gint unread;
216         TnyFolderType type;
217         TnyFolder *folder = NULL;
218         
219         g_return_if_fail (column);
220         g_return_if_fail (tree_model);
221
222         gtk_tree_model_get (tree_model, iter,
223                             TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &fname,
224                             TNY_GTK_FOLDER_STORE_TREE_MODEL_UNREAD_COLUMN, &unread,
225                             TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
226                             TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
227                             -1);
228         rendobj = G_OBJECT(renderer);
229  
230         if (!fname)
231                 return;
232
233         if (!folder) {
234                 g_free (fname);
235                 return;
236         }
237         
238         if (type != TNY_FOLDER_TYPE_ROOT) {
239                 if (modest_tny_folder_is_local_folder (folder)) {
240                         TnyFolderType type;
241                         type = modest_tny_folder_get_local_folder_type (folder);
242                         if (type != TNY_FOLDER_TYPE_UNKNOWN) {
243                                 g_free (fname);
244                                 fname = g_strdup(modest_local_folder_info_get_type_display_name (type));
245                         }
246                 }
247
248                 /* Use bold font style if there are unread messages */                  
249                 if (unread > 0) {
250                         gchar *folder_title = g_strdup_printf ("%s (%d)", fname, unread);
251                         g_object_set (rendobj,"text", folder_title,  "weight", 800, NULL);
252                         g_free (folder_title);
253                 } else 
254                         g_object_set (rendobj,"text", fname, "weight", 400, NULL);
255
256         } else {
257                 ModestFolderViewPrivate *priv;
258                 const gchar *account_name;
259         
260                 priv =  MODEST_FOLDER_VIEW_GET_PRIVATE (data);
261
262                 /* Use bold font style */
263                 account_name = priv->local_account_name;
264                 g_object_set (rendobj,"text", account_name, "weight", 800, NULL);
265 /*              if (modest_tny_folder_is_local_folder (folder)) { */
266 /*              } else { */
267 /*                      if () { */
268 /*                      } else { */
269 /*                      } */
270 /*              } */
271         }
272         
273         g_object_unref (G_OBJECT (folder));
274         g_free (fname);
275 }
276
277
278
279 static void
280 icon_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
281                  GtkTreeModel *tree_model,  GtkTreeIter *iter, gpointer data)
282 {
283         GObject *rendobj;
284         GdkPixbuf *pixbuf;
285         TnyFolderType type;
286         gchar *fname = NULL;
287         gint unread;
288         
289         rendobj = G_OBJECT(renderer);
290         gtk_tree_model_get (tree_model, iter,
291                             TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
292                             TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &fname,
293                             TNY_GTK_FOLDER_STORE_TREE_MODEL_UNREAD_COLUMN, &unread, 
294                             -1);
295         rendobj = G_OBJECT(renderer);
296         
297         if (type == TNY_FOLDER_TYPE_NORMAL || type == TNY_FOLDER_TYPE_UNKNOWN) {
298                 type = modest_tny_folder_guess_folder_type_from_name (fname);
299         }
300         g_free (fname);
301
302         switch (type) {
303         case TNY_FOLDER_TYPE_ROOT:
304                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_ACCOUNT);
305                 break;
306         case TNY_FOLDER_TYPE_INBOX:
307                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_INBOX);
308                 break;
309         case TNY_FOLDER_TYPE_OUTBOX:
310                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_OUTBOX);
311                 break;
312         case TNY_FOLDER_TYPE_JUNK:
313                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_JUNK);
314                 break;
315         case TNY_FOLDER_TYPE_SENT:
316                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_SENT);
317                 break;
318         case TNY_FOLDER_TYPE_TRASH:
319                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_TRASH);
320                 break;
321         case TNY_FOLDER_TYPE_DRAFTS:
322                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_DRAFTS);
323                 break;
324         case TNY_FOLDER_TYPE_NORMAL:
325         default:
326                 pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_NORMAL);
327                 break;
328         }
329         g_object_set (rendobj, "pixbuf", pixbuf, NULL);
330 }
331
332 static void
333 modest_folder_view_init (ModestFolderView *obj)
334 {
335         ModestFolderViewPrivate *priv;
336         GtkTreeViewColumn *column;
337         GtkCellRenderer *renderer;
338         GtkTreeSelection *sel;
339         ModestConf *conf;
340         
341         priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(obj);
342         
343         priv->timer_expander = 0;
344         priv->account_store  = NULL;
345         priv->cur_folder     = NULL;
346         priv->cur_row        = NULL;
347         priv->query          = NULL;
348
349         /* Initialize the local account name */
350         conf = modest_runtime_get_conf();
351         priv->local_account_name = modest_conf_get_string (conf, MODEST_CONF_DEVICE_NAME, NULL);
352
353         /* Build treeview */
354         column = gtk_tree_view_column_new ();   
355         
356         renderer = gtk_cell_renderer_pixbuf_new();
357         gtk_tree_view_column_pack_start (column, renderer, FALSE);
358         gtk_tree_view_column_set_cell_data_func(column, renderer,
359                                                 icon_cell_data, obj, NULL);
360         
361         renderer = gtk_cell_renderer_text_new();
362         gtk_tree_view_column_pack_start (column, renderer, FALSE);
363         gtk_tree_view_column_set_cell_data_func(column, renderer,
364                                                 text_cell_data, obj, NULL);
365         
366         sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(obj));
367         gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
368
369         gtk_tree_view_column_set_spacing (column, 2);
370         gtk_tree_view_column_set_resizable (column, TRUE);
371         gtk_tree_view_column_set_fixed_width (column, TRUE);            
372         gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW(obj), FALSE);
373         gtk_tree_view_set_enable_search     (GTK_TREE_VIEW(obj), FALSE);
374
375         gtk_tree_view_append_column (GTK_TREE_VIEW(obj),column);
376
377         /* Setup drag and drop */
378         setup_drag_and_drop (GTK_TREE_VIEW(obj));
379
380         /* Connect signals */
381         g_signal_connect (G_OBJECT (obj), 
382                           "key-press-event", 
383                           G_CALLBACK (on_key_pressed), NULL);
384
385         /*
386          * Track changes in the local account name (in the device it
387          * will be the device name)
388          */
389         g_signal_connect (G_OBJECT(conf), 
390                           "key_changed",
391                           G_CALLBACK(on_configuration_key_changed), obj);
392
393 }
394
395 static void
396 tny_account_store_view_init (gpointer g, gpointer iface_data)
397 {
398         TnyAccountStoreViewIface *klass = (TnyAccountStoreViewIface *)g;
399
400         klass->set_account_store_func = modest_folder_view_set_account_store;
401
402         return;
403 }
404
405 static void
406 modest_folder_view_finalize (GObject *obj)
407 {
408         ModestFolderViewPrivate *priv;
409         GtkTreeSelection    *sel;
410         
411         g_return_if_fail (obj);
412         
413         priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(obj);
414
415         if (priv->timer_expander != 0) {
416                 g_source_remove (priv->timer_expander);
417                 priv->timer_expander = 0;
418         }
419
420         if (priv->account_store) {
421                 g_signal_handler_disconnect (G_OBJECT(priv->account_store),
422                                              priv->account_update_signal);
423                 g_signal_handler_disconnect (G_OBJECT(priv->account_store),
424                                              priv->accounts_reloaded_signal);
425                 g_object_unref (G_OBJECT(priv->account_store));
426                 priv->account_store = NULL;
427         }
428
429         if (priv->query) {
430                 g_object_unref (G_OBJECT (priv->query));
431                 priv->query = NULL;
432         }
433
434         sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(obj));
435         if (sel)
436                 g_signal_handler_disconnect (G_OBJECT(sel), priv->changed_signal);
437
438         g_free (priv->local_account_name);
439         
440         G_OBJECT_CLASS(parent_class)->finalize (obj);
441 }
442
443
444 static void
445 modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore *account_store)
446 {
447         ModestFolderViewPrivate *priv;
448         TnyDevice *device;
449
450         g_return_if_fail (MODEST_IS_FOLDER_VIEW (self));
451         g_return_if_fail (TNY_IS_ACCOUNT_STORE (account_store));
452
453         priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
454         device = tny_account_store_get_device (account_store);
455
456         if (G_UNLIKELY (priv->account_store)) {
457
458                 if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), 
459                                                    priv->account_update_signal))
460                         g_signal_handler_disconnect (G_OBJECT (priv->account_store), 
461                                                      priv->account_update_signal);
462                 if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), 
463                                                    priv->accounts_reloaded_signal))
464                         g_signal_handler_disconnect (G_OBJECT (priv->account_store), 
465                                                      priv->accounts_reloaded_signal);
466
467                 g_object_unref (G_OBJECT (priv->account_store));
468         }
469
470         priv->account_store = g_object_ref (G_OBJECT (account_store));
471
472         priv->account_update_signal = 
473                 g_signal_connect (G_OBJECT(account_store), "account_update",
474                                   G_CALLBACK (on_account_update), self);
475
476         priv->accounts_reloaded_signal = 
477                 g_signal_connect (G_OBJECT(account_store), "accounts_reloaded",
478                                   G_CALLBACK (on_accounts_reloaded), self);
479         
480         if (!update_model (MODEST_FOLDER_VIEW (self),
481                            MODEST_TNY_ACCOUNT_STORE (priv->account_store)))
482                 g_printerr ("modest: failed to update model\n");
483
484         g_object_unref (G_OBJECT (device));
485 }
486
487 static void
488 on_account_update (TnyAccountStore *account_store, const gchar *account,
489                    gpointer user_data)
490 {
491         if (!update_model (MODEST_FOLDER_VIEW(user_data), 
492                            MODEST_TNY_ACCOUNT_STORE(account_store)))
493                 g_printerr ("modest: failed to update model for changes in '%s'",
494                             account);
495 }
496
497 static void 
498 on_accounts_reloaded   (TnyAccountStore *account_store, 
499                         gpointer user_data)
500 {
501         update_model (MODEST_FOLDER_VIEW (user_data), 
502                       MODEST_TNY_ACCOUNT_STORE(account_store));
503 }
504
505 void
506 modest_folder_view_set_title (ModestFolderView *self, const gchar *title)
507 {
508         GtkTreeViewColumn *col;
509         
510         g_return_if_fail (self);
511
512         col = gtk_tree_view_get_column (GTK_TREE_VIEW(self), 0);
513         if (!col) {
514                 g_printerr ("modest: failed get column for title\n");
515                 return;
516         }
517
518         gtk_tree_view_column_set_title (col, title);
519         gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self),
520                                            title != NULL);
521 }
522
523 GtkWidget*
524 modest_folder_view_new (TnyFolderStoreQuery *query)
525 {
526         GObject *self;
527         ModestFolderViewPrivate *priv;
528         GtkTreeSelection *sel;
529         
530         self = G_OBJECT (g_object_new (MODEST_TYPE_FOLDER_VIEW, NULL));
531         priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
532
533         priv->query = g_object_ref (query);
534         
535         sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(self));
536         priv->changed_signal = g_signal_connect (sel, "changed",
537                                                  G_CALLBACK (on_selection_changed), self);
538         return GTK_WIDGET(self);
539 }
540
541 /* this feels dirty; any other way to expand all the root items? */
542 static void
543 expand_root_items (ModestFolderView *self)
544 {
545         GtkTreePath *path;
546         path = gtk_tree_path_new_first ();
547
548         /* all folders should have child items, so.. */
549         while (gtk_tree_view_expand_row (GTK_TREE_VIEW(self), path, FALSE))
550                 gtk_tree_path_next (path);
551         
552         gtk_tree_path_free (path);
553 }
554
555 static gboolean
556 update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
557 {
558         ModestFolderViewPrivate *priv;
559
560         TnyList          *account_list;
561         GtkTreeModel     *model, *sortable;
562
563         g_return_val_if_fail (account_store, FALSE);
564
565         priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(self);
566         
567         /* Notify that there is no folder selected*/
568         g_signal_emit (G_OBJECT(self), 
569                        signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
570                        NULL, TRUE);
571         
572         /* FIXME: the local accounts are not shown when the query
573            selects only the subscribed folders. */
574 /*      model        = tny_gtk_folder_store_tree_model_new (TRUE, priv->query); */
575         model        = tny_gtk_folder_store_tree_model_new (TRUE, NULL);
576         account_list = TNY_LIST(model);
577
578         tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
579                                         account_list,
580                                         TNY_ACCOUNT_STORE_STORE_ACCOUNTS);      
581         if (account_list) {
582                 sortable = gtk_tree_model_sort_new_with_model (model);
583                 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
584                                                       TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, 
585                                                       GTK_SORT_ASCENDING);
586                 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
587                                                  TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
588                                                  cmp_rows, NULL, NULL);
589
590                 /* Set new model */
591                 gtk_tree_view_set_model (GTK_TREE_VIEW(self), sortable);
592                 expand_root_items (self); /* expand all account folders */
593                 g_object_unref (account_list);
594         }
595         
596         return TRUE;
597 }
598
599
600 static void
601 on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
602 {
603         GtkTreeModel            *model_sort, *model;
604         TnyFolder               *folder = NULL;
605         GtkTreeIter             iter, iter_sort;
606         GtkTreePath            *path;
607         ModestFolderView        *tree_view;
608         ModestFolderViewPrivate *priv;
609         gint                    type;
610
611         g_return_if_fail (sel);
612         g_return_if_fail (user_data);
613         
614         priv = MODEST_FOLDER_VIEW_GET_PRIVATE(user_data);
615         priv->cur_selection = sel;
616         
617         /* folder was _un_selected if true */
618         if (!gtk_tree_selection_get_selected (sel, &model_sort, &iter_sort)) {
619                 if (priv->cur_folder)
620                         g_object_unref (priv->cur_folder);
621                 if (priv->cur_row)
622                         gtk_tree_row_reference_free (priv->cur_row);
623                 priv->cur_folder = NULL;
624                 priv->cur_row = NULL;
625                 return; 
626         }
627
628         model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model_sort));
629         gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (model_sort),
630                                                         &iter,
631                                                         &iter_sort);
632
633         tree_view = MODEST_FOLDER_VIEW (user_data);
634
635         gtk_tree_model_get (model, &iter,
636                             TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
637                             TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
638                             -1);
639
640         /* If the folder is the same do not notify */
641         if ((type == TNY_FOLDER_TYPE_ROOT) || (priv->cur_folder == folder)) {
642                 g_object_unref (folder);
643                 return;
644         }
645         
646         /* Current folder was unselected */
647         if (priv->cur_folder) {
648                 g_signal_emit (G_OBJECT(tree_view), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
649                                priv->cur_folder, FALSE);
650                 g_object_unref (priv->cur_folder);
651         }
652
653         if (priv->cur_row)
654                 gtk_tree_row_reference_free (priv->cur_row);
655
656         /* New current references */
657         path = gtk_tree_model_get_path (model_sort, &iter_sort);
658         priv->cur_folder = folder;
659         priv->cur_row = gtk_tree_row_reference_new (model_sort, path);
660
661         /* Frees */
662         gtk_tree_path_free (path);
663
664         /* New folder has been selected */
665         g_signal_emit (G_OBJECT(tree_view), 
666                        signals[FOLDER_SELECTION_CHANGED_SIGNAL], 
667                        0, folder, TRUE); 
668 }
669
670 TnyFolder *
671 modest_folder_view_get_selected (ModestFolderView *self)
672 {
673         ModestFolderViewPrivate *priv;
674
675         g_return_val_if_fail (self, NULL);
676         
677         priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
678         if (priv->cur_folder)
679                 g_object_ref (priv->cur_folder);
680
681         return priv->cur_folder;
682 }
683
684 static gint
685 cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
686           gpointer user_data)
687 {
688         gint cmp;
689         gchar         *name1, *name2;
690         TnyFolderType type;
691         TnyFolder     *folder1, *folder2;
692         
693         gtk_tree_model_get (tree_model, iter1,
694                             TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name1,
695                             TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
696                             TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder1,
697                             -1);
698         gtk_tree_model_get (tree_model, iter2,
699                             TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name2,
700                             TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder2,
701                             -1);
702
703         /* local_folders should be the last one */
704         if (type == TNY_FOLDER_TYPE_ROOT) {
705                 /* the account name is also the name of the root folder
706                  * in case of local folders */
707                 if (name1 && strcmp (name1, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
708                         cmp = +1;
709                 else if (name2 && strcmp (name2, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
710                         cmp = -1;
711                 else 
712                         cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
713         } else 
714                 cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
715
716         
717         if (folder1)
718                 g_object_unref(G_OBJECT(folder1));
719         if (folder2)
720                 g_object_unref(G_OBJECT(folder2));
721         
722         g_free (name1);
723         g_free (name2);
724
725         return cmp;     
726 }
727
728 /*****************************************************************************/
729 /*                        DRAG and DROP stuff                                */
730 /*****************************************************************************/
731
732 /*
733  * This function fills the #GtkSelectionData with the row and the
734  * model that has been dragged. It's called when this widget is a
735  * source for dnd after the event drop happened
736  */
737 static void
738 on_drag_data_get (GtkWidget *widget, 
739                   GdkDragContext *context, 
740                   GtkSelectionData *selection_data, 
741                   guint info, 
742                   guint time, 
743                   gpointer data)
744 {
745         GtkTreeSelection *selection;
746         GtkTreeModel *model_sort, *model;
747         GtkTreeIter iter;
748         GtkTreePath *source_row_sort;
749         GtkTreePath *source_row;
750
751         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
752         gtk_tree_selection_get_selected (selection, &model_sort, &iter);
753         source_row_sort = gtk_tree_model_get_path (model_sort, &iter);
754
755         /* Get the unsorted path and model */
756         model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model_sort));
757         source_row = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT (model_sort),
758                                                                      source_row_sort);
759
760         gtk_tree_set_row_drag_data (selection_data,
761                                     model,
762                                     source_row);
763
764         gtk_tree_path_free (source_row_sort);
765         gtk_tree_path_free (source_row);
766 }
767
768 typedef struct _DndHelper {
769         gboolean delete_source;
770         GtkTreePath *source_row;
771         GdkDragContext *context;
772         guint time;
773 } DndHelper;
774
775
776 /*
777  * This function is the callback of the
778  * modest_mail_operation_xfer_msg() and
779  * modest_mail_operation_xfer_folder() calls. We check here if the
780  * message/folder was correctly asynchronously transferred. The reason
781  * to use the same callback is that the code is the same, it only has
782  * to check that the operation went fine and then finalize the drag
783  * and drop action
784  */
785 static void
786 on_progress_changed (ModestMailOperation *mail_op, gpointer user_data)
787 {
788         gboolean success;
789         DndHelper *helper;
790
791         helper = (DndHelper *) user_data;
792
793         if (!modest_mail_operation_is_finished (mail_op))
794                 return;
795
796         if (modest_mail_operation_get_status (mail_op) == 
797             MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
798                 success = TRUE;
799         } else {
800                 success = FALSE;
801         }
802
803         /* Notify the drag source. Never call delete, the monitor will
804            do the job if needed */
805         gtk_drag_finish (helper->context, success, FALSE, helper->time);
806
807         /* Free the helper */
808         gtk_tree_path_free (helper->source_row);        
809         g_slice_free (DndHelper, helper);
810 }
811
812 /*
813  * This function is used by drag_data_received_cb to manage drag and
814  * drop of a header, i.e, and drag from the header view to the folder
815  * view.
816  */
817 static void
818 drag_and_drop_from_header_view (GtkTreeModel *source_model,
819                                 GtkTreeModel *dest_model,
820                                 GtkTreePath  *dest_row,
821                                 DndHelper    *helper)
822 {
823         TnyHeader *header;
824         TnyFolder *folder;
825         ModestMailOperation *mail_op;
826         GtkTreeIter source_iter, dest_iter;
827
828         /* Get header */
829         gtk_tree_model_get_iter (source_model, &source_iter, helper->source_row);
830         gtk_tree_model_get (source_model, &source_iter, 
831                             TNY_GTK_HEADER_LIST_MODEL_INSTANCE_COLUMN, 
832                             &header, -1);
833
834         /* Get Folder */
835         gtk_tree_model_get_iter (dest_model, &dest_iter, dest_row);
836         gtk_tree_model_get (dest_model, &dest_iter, 
837                             TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, 
838                             &folder, -1);
839
840         /* Transfer message */
841         mail_op = modest_mail_operation_new ();
842         modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
843                                          mail_op);
844         g_signal_connect (G_OBJECT (mail_op), "progress-changed",
845                           G_CALLBACK (on_progress_changed), helper);
846
847         modest_mail_operation_xfer_msg (mail_op, header, folder, helper->delete_source);
848
849         /* Frees */
850         g_object_unref (G_OBJECT (mail_op));
851         g_object_unref (G_OBJECT (header));
852         g_object_unref (G_OBJECT (folder));
853 }
854
855 /*
856  * This function is used by drag_data_received_cb to manage drag and
857  * drop of a folder, i.e, and drag from the folder view to the same
858  * folder view.
859  */
860 static void
861 drag_and_drop_from_folder_view (GtkTreeModel     *source_model,
862                                 GtkTreeModel     *dest_model,
863                                 GtkTreePath      *dest_row,
864                                 GtkSelectionData *selection_data,
865                                 DndHelper        *helper)
866 {
867         ModestMailOperation *mail_op;
868         GtkTreeIter parent_iter, iter;
869         TnyFolderStore *parent_folder;
870         TnyFolder *folder;
871
872         /* Check if the drag is possible */
873         if (!gtk_tree_path_compare (helper->source_row, dest_row) ||
874             !gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (dest_model),
875                                                    dest_row,
876                                                    selection_data)) {
877
878                 gtk_drag_finish (helper->context, FALSE, FALSE, helper->time);
879                 gtk_tree_path_free (helper->source_row);        
880                 g_slice_free (DndHelper, helper);
881                 return;
882         }
883
884         /* Get data */
885         gtk_tree_model_get_iter (source_model, &parent_iter, dest_row);
886         gtk_tree_model_get_iter (source_model, &iter, helper->source_row);
887         gtk_tree_model_get (source_model, &parent_iter, 
888                             TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, 
889                             &parent_folder, -1);
890         gtk_tree_model_get (source_model, &iter,
891                             TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
892                             &folder, -1);
893
894         /* Do the mail operation */
895         mail_op = modest_mail_operation_new ();
896         modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
897                                          mail_op);
898         g_signal_connect (G_OBJECT (mail_op), "progress-changed",
899                           G_CALLBACK (on_progress_changed), helper);
900
901         modest_mail_operation_xfer_folder (mail_op, 
902                                            folder, 
903                                            parent_folder,
904                                            helper->delete_source);
905
906         /* Frees */
907         g_object_unref (G_OBJECT (parent_folder));
908         g_object_unref (G_OBJECT (folder));
909         g_object_unref (G_OBJECT (mail_op));
910 }
911
912 /*
913  * This function receives the data set by the "drag-data-get" signal
914  * handler. This information comes within the #GtkSelectionData. This
915  * function will manage both the drags of folders of the treeview and
916  * drags of headers of the header view widget.
917  */
918 static void 
919 on_drag_data_received (GtkWidget *widget, 
920                        GdkDragContext *context, 
921                        gint x, 
922                        gint y, 
923                        GtkSelectionData *selection_data, 
924                        guint target_type, 
925                        guint time, 
926                        gpointer data)
927 {
928         GtkWidget *source_widget;
929         GtkTreeModel *model_sort, *dest_model, *source_model;
930         GtkTreePath *source_row, *dest_row, *child_dest_row;
931         GtkTreeViewDropPosition pos;
932         gboolean success = FALSE, delete_source = FALSE;
933         DndHelper *helper;
934
935         /* Do not allow further process */
936         g_signal_stop_emission_by_name (widget, "drag-data-received");
937
938         /* Get the action */
939         if (context->action == GDK_ACTION_MOVE)
940                 delete_source = TRUE;
941
942         /* Check if the get_data failed */
943         if (selection_data == NULL || selection_data->length < 0)
944                 gtk_drag_finish (context, success, FALSE, time);
945
946         /* Get the models */
947         source_widget = gtk_drag_get_source_widget (context);
948         gtk_tree_get_row_drag_data (selection_data,
949                                     &source_model,
950                                     &source_row);
951
952         model_sort = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
953         /* Select the destination model */
954         if (source_widget == widget) {
955                 dest_model = source_model;
956         } else {
957                 dest_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model_sort));
958         }
959
960         /* Get the path to the destination row. Can not call
961            gtk_tree_view_get_drag_dest_row() because the source row
962            is not selected anymore */
963         gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), x, y,
964                                            &dest_row, &pos);
965
966         /* Only allow drops IN other rows */
967         if (!dest_row || pos == GTK_TREE_VIEW_DROP_BEFORE || pos == GTK_TREE_VIEW_DROP_AFTER)
968                 gtk_drag_finish (context, success, FALSE, time);
969
970         /* Create the helper */
971         helper = g_slice_new0 (DndHelper);
972         helper->delete_source = delete_source;
973         helper->source_row = gtk_tree_path_copy (source_row);
974         helper->context = context;
975         helper->time = time;
976
977         /* Get path from the unsorted model */
978         child_dest_row = 
979                 gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT (model_sort),
980                                                                 dest_row);
981         gtk_tree_path_free (dest_row);
982
983         /* Drags from the header view */
984         if (source_widget != widget) {
985
986                 drag_and_drop_from_header_view (source_model,
987                                                 dest_model,
988                                                 child_dest_row,
989                                                 helper);
990         } else {
991
992
993                 drag_and_drop_from_folder_view (source_model,
994                                                 dest_model,
995                                                 child_dest_row,
996                                                 selection_data, 
997                                                 helper);
998         }
999
1000         /* Frees */
1001         gtk_tree_path_free (source_row);
1002         gtk_tree_path_free (child_dest_row);
1003 }
1004
1005 /*
1006  * We define a "drag-drop" signal handler because we do not want to
1007  * use the default one, because the default one always calls
1008  * gtk_drag_finish and we prefer to do it in the "drag-data-received"
1009  * signal handler, because there we have all the information available
1010  * to know if the dnd was a success or not.
1011  */
1012 static gboolean
1013 drag_drop_cb (GtkWidget      *widget,
1014               GdkDragContext *context,
1015               gint            x,
1016               gint            y,
1017               guint           time,
1018               gpointer        user_data) 
1019 {
1020         gpointer target;
1021
1022         if (!context->targets)
1023                 return FALSE;
1024
1025         /* Check if we're dragging a folder row */
1026         target = gtk_drag_dest_find_target (widget, context, NULL);
1027
1028         /* Request the data from the source. */
1029         gtk_drag_get_data(widget, context, target, time);
1030
1031     return TRUE;
1032 }
1033
1034 /*
1035  * This function expands a node of a tree view if it's not expanded
1036  * yet. Not sure why it needs the threads stuff, but gtk+`example code
1037  * does that, so that's why they're here.
1038  */
1039 static gint
1040 expand_row_timeout (gpointer data)
1041 {
1042         GtkTreeView *tree_view = data;
1043         GtkTreePath *dest_path = NULL;
1044         GtkTreeViewDropPosition pos;
1045         gboolean result = FALSE;
1046         
1047         GDK_THREADS_ENTER ();
1048         
1049         gtk_tree_view_get_drag_dest_row (tree_view,
1050                                          &dest_path,
1051                                          &pos);
1052         
1053         if (dest_path &&
1054             (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER ||
1055              pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)) {
1056                 gtk_tree_view_expand_row (tree_view, dest_path, FALSE);
1057                 gtk_tree_path_free (dest_path);
1058         }
1059         else {
1060                 if (dest_path)
1061                         gtk_tree_path_free (dest_path);
1062                 
1063                 result = TRUE;
1064         }
1065         
1066         GDK_THREADS_LEAVE ();
1067
1068         return result;
1069 }
1070
1071 /*
1072  * This function is called whenever the pointer is moved over a widget
1073  * while dragging some data. It installs a timeout that will expand a
1074  * node of the treeview if not expanded yet. This function also calls
1075  * gdk_drag_status in order to set the suggested action that will be
1076  * used by the "drag-data-received" signal handler to know if we
1077  * should do a move or just a copy of the data.
1078  */
1079 static gboolean
1080 on_drag_motion (GtkWidget      *widget,
1081                 GdkDragContext *context,
1082                 gint            x,
1083                 gint            y,
1084                 guint           time,
1085                 gpointer        user_data)  
1086 {
1087         GtkTreeViewDropPosition pos;
1088         GtkTreePath *dest_row;
1089         ModestFolderViewPrivate *priv;
1090         GdkDragAction suggested_action;
1091         gboolean valid_location = FALSE;
1092
1093         priv = MODEST_FOLDER_VIEW_GET_PRIVATE (widget);
1094
1095         if (priv->timer_expander != 0) {
1096                 g_source_remove (priv->timer_expander);
1097                 priv->timer_expander = 0;
1098         }
1099
1100         gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
1101                                            x, y,
1102                                            &dest_row,
1103                                            &pos);
1104
1105         /* Do not allow drops between folders */
1106         if (!dest_row ||
1107             pos == GTK_TREE_VIEW_DROP_BEFORE || 
1108             pos == GTK_TREE_VIEW_DROP_AFTER) {
1109                 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), NULL, 0);
1110                 gdk_drag_status(context, 0, time);
1111                 valid_location = FALSE;
1112                 goto out;
1113         } else {
1114                 valid_location = TRUE;
1115         }
1116
1117         /* Expand the selected row after 1/2 second */
1118         if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), dest_row)) {
1119                 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), dest_row, pos);
1120                 priv->timer_expander = g_timeout_add (500, expand_row_timeout, widget);
1121         }
1122         gtk_tree_path_free (dest_row);
1123
1124         /* Select the desired action. By default we pick MOVE */
1125         suggested_action = GDK_ACTION_MOVE;
1126
1127         if (context->actions == GDK_ACTION_COPY)
1128             gdk_drag_status(context, GDK_ACTION_COPY, time);
1129         else if (context->actions == GDK_ACTION_MOVE)
1130             gdk_drag_status(context, GDK_ACTION_MOVE, time);
1131         else if (context->actions & suggested_action)
1132             gdk_drag_status(context, suggested_action, time);
1133         else
1134             gdk_drag_status(context, GDK_ACTION_DEFAULT, time);
1135
1136  out:
1137         g_signal_stop_emission_by_name (widget, "drag-motion");
1138         return valid_location;
1139 }
1140
1141
1142 /* Folder view drag types */
1143 const GtkTargetEntry folder_view_drag_types[] =
1144 {
1145         { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, MODEST_FOLDER_ROW },
1146         { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_APP,    MODEST_HEADER_ROW }
1147 };
1148
1149 /*
1150  * This function sets the treeview as a source and a target for dnd
1151  * events. It also connects all the requirede signals.
1152  */
1153 static void
1154 setup_drag_and_drop (GtkTreeView *self)
1155 {
1156         /* Set up the folder view as a dnd destination. Set only the
1157            highlight flag, otherwise gtk will have a different
1158            behaviour */
1159         gtk_drag_dest_set (GTK_WIDGET (self),
1160                            GTK_DEST_DEFAULT_HIGHLIGHT,
1161                            folder_view_drag_types,
1162                            G_N_ELEMENTS (folder_view_drag_types),
1163                            GDK_ACTION_MOVE | GDK_ACTION_COPY);
1164
1165         g_signal_connect (G_OBJECT (self),
1166                           "drag_data_received",
1167                           G_CALLBACK (on_drag_data_received),
1168                           NULL);
1169
1170
1171         /* Set up the treeview as a dnd source */
1172         gtk_drag_source_set (GTK_WIDGET (self),
1173                              GDK_BUTTON1_MASK,
1174                              folder_view_drag_types,
1175                              G_N_ELEMENTS (folder_view_drag_types),
1176                              GDK_ACTION_MOVE | GDK_ACTION_COPY);
1177
1178         g_signal_connect (G_OBJECT (self),
1179                           "drag_motion",
1180                           G_CALLBACK (on_drag_motion),
1181                           NULL);
1182         
1183         g_signal_connect (G_OBJECT (self),
1184                           "drag_data_get",
1185                           G_CALLBACK (on_drag_data_get),
1186                           NULL);
1187
1188         g_signal_connect (G_OBJECT (self),
1189                           "drag_drop",
1190                           G_CALLBACK (drag_drop_cb),
1191                           NULL);
1192 }
1193
1194 /*
1195  * This function manages the navigation through the folders using the
1196  * keyboard or the hardware keys in the device
1197  */
1198 static gboolean
1199 on_key_pressed (GtkWidget *self,
1200                 GdkEventKey *event,
1201                 gpointer user_data)
1202 {
1203         GtkTreeSelection *selection;
1204         GtkTreeIter iter;
1205         GtkTreeModel *model;
1206         gboolean retval = FALSE;
1207
1208         /* Up and Down are automatically managed by the treeview */
1209         if (event->keyval == GDK_Return) {
1210                 /* Expand/Collapse the selected row */
1211                 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
1212                 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
1213                         GtkTreePath *path;
1214
1215                         path = gtk_tree_model_get_path (model, &iter);
1216
1217                         if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (self), path))
1218                                 gtk_tree_view_collapse_row (GTK_TREE_VIEW (self), path);
1219                         else
1220                                 gtk_tree_view_expand_row (GTK_TREE_VIEW (self), path, FALSE);
1221                         gtk_tree_path_free (path);
1222                 }
1223                 /* No further processing */
1224                 retval = TRUE;
1225         }
1226
1227         return retval;
1228 }
1229
1230 /*
1231  * We listen to the changes in the local folder account name key,
1232  * because we want to show the right name in the view. The local
1233  * folder account name corresponds to the device name in the Maemo
1234  * version. We do this because we do not want to query gconf on each
1235  * tree view refresh. It's better to cache it and change whenever
1236  * necessary.
1237  */
1238 static void 
1239 on_configuration_key_changed (ModestConf* conf, 
1240                               const gchar *key, 
1241                               ModestConfEvent event, 
1242                               ModestFolderView *self)
1243 {
1244         ModestFolderViewPrivate *priv;
1245         GtkTreeViewColumn *tree_column;
1246
1247         if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME))
1248                 return;
1249
1250         priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
1251
1252         g_free (priv->local_account_name);
1253
1254         if (event == MODEST_CONF_EVENT_KEY_UNSET)
1255                 priv->local_account_name = g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
1256         else
1257                 priv->local_account_name = modest_conf_get_string (modest_runtime_get_conf(),
1258                                                                    MODEST_CONF_DEVICE_NAME, NULL);
1259
1260         /* Force a redraw */
1261         tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 
1262                                                 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
1263         gtk_tree_view_column_queue_resize (tree_column);
1264 }