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