1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
30 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
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-store-observer.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 <tny-camel-account.h>
45 #include <modest-tny-account.h>
46 #include <modest-tny-folder.h>
47 #include <modest-tny-local-folders-account.h>
48 #include <modest-tny-outbox-account.h>
49 #include <modest-marshal.h>
50 #include <modest-icon-names.h>
51 #include <modest-tny-account-store.h>
52 #include <modest-text-utils.h>
53 #include <modest-runtime.h>
54 #include "modest-folder-view.h"
55 #include <modest-platform.h>
56 #include <modest-widget-memory.h>
57 #include <modest-ui-actions.h>
58 #include "modest-dnd.h"
59 #include "widgets/modest-window.h"
61 /* Folder view drag types */
62 const GtkTargetEntry folder_view_drag_types[] =
64 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, MODEST_FOLDER_ROW },
65 { GTK_TREE_PATH_AS_STRING_LIST, GTK_TARGET_SAME_APP, MODEST_HEADER_ROW }
68 /* 'private'/'protected' functions */
69 static void modest_folder_view_class_init (ModestFolderViewClass *klass);
70 static void modest_folder_view_init (ModestFolderView *obj);
71 static void modest_folder_view_finalize (GObject *obj);
73 static void tny_account_store_view_init (gpointer g,
76 static void modest_folder_view_set_account_store (TnyAccountStoreView *self,
77 TnyAccountStore *account_store);
79 static void on_selection_changed (GtkTreeSelection *sel,
82 static void on_account_removed (TnyAccountStore *self,
86 static void on_account_inserted (TnyAccountStore *self,
90 static void on_account_changed (TnyAccountStore *self,
94 static gint cmp_rows (GtkTreeModel *tree_model,
99 static gboolean filter_row (GtkTreeModel *model,
103 static gboolean on_key_pressed (GtkWidget *self,
107 static void on_configuration_key_changed (ModestConf* conf,
109 ModestConfEvent event,
110 ModestConfNotificationId notification_id,
111 ModestFolderView *self);
114 static void on_drag_data_get (GtkWidget *widget,
115 GdkDragContext *context,
116 GtkSelectionData *selection_data,
121 static void on_drag_data_received (GtkWidget *widget,
122 GdkDragContext *context,
125 GtkSelectionData *selection_data,
130 static gboolean on_drag_motion (GtkWidget *widget,
131 GdkDragContext *context,
137 static void expand_root_items (ModestFolderView *self);
139 static gint expand_row_timeout (gpointer data);
141 static void setup_drag_and_drop (GtkTreeView *self);
143 static gboolean _clipboard_set_selected_data (ModestFolderView *folder_view,
146 static void _clear_hidding_filter (ModestFolderView *folder_view);
148 static void on_row_inserted_maybe_select_folder (GtkTreeModel *tree_model,
151 ModestFolderView *self);
153 static void on_display_name_changed (ModestAccountMgr *self,
154 const gchar *account,
158 FOLDER_SELECTION_CHANGED_SIGNAL,
159 FOLDER_DISPLAY_NAME_CHANGED_SIGNAL,
163 typedef struct _ModestFolderViewPrivate ModestFolderViewPrivate;
164 struct _ModestFolderViewPrivate {
165 TnyAccountStore *account_store;
166 TnyFolderStore *cur_folder_store;
168 TnyFolder *folder_to_select; /* folder to select after the next update */
170 gulong changed_signal;
171 gulong account_inserted_signal;
172 gulong account_removed_signal;
173 gulong account_changed_signal;
174 gulong conf_key_signal;
175 gulong display_name_changed_signal;
177 /* not unref this object, its a singlenton */
178 ModestEmailClipboard *clipboard;
180 /* Filter tree model */
184 TnyFolderStoreQuery *query;
185 guint timer_expander;
187 gchar *local_account_name;
188 gchar *visible_account_id;
189 ModestFolderViewStyle style;
191 gboolean reselect; /* we use this to force a reselection of the INBOX */
192 gboolean show_non_move;
193 gboolean reexpand; /* next time we expose, we'll expand all root folders */
195 #define MODEST_FOLDER_VIEW_GET_PRIVATE(o) \
196 (G_TYPE_INSTANCE_GET_PRIVATE((o), \
197 MODEST_TYPE_FOLDER_VIEW, \
198 ModestFolderViewPrivate))
200 static GObjectClass *parent_class = NULL;
202 static guint signals[LAST_SIGNAL] = {0};
205 modest_folder_view_get_type (void)
207 static GType my_type = 0;
209 static const GTypeInfo my_info = {
210 sizeof(ModestFolderViewClass),
211 NULL, /* base init */
212 NULL, /* base finalize */
213 (GClassInitFunc) modest_folder_view_class_init,
214 NULL, /* class finalize */
215 NULL, /* class data */
216 sizeof(ModestFolderView),
218 (GInstanceInitFunc) modest_folder_view_init,
222 static const GInterfaceInfo tny_account_store_view_info = {
223 (GInterfaceInitFunc) tny_account_store_view_init, /* interface_init */
224 NULL, /* interface_finalize */
225 NULL /* interface_data */
229 my_type = g_type_register_static (GTK_TYPE_TREE_VIEW,
233 g_type_add_interface_static (my_type,
234 TNY_TYPE_ACCOUNT_STORE_VIEW,
235 &tny_account_store_view_info);
241 modest_folder_view_class_init (ModestFolderViewClass *klass)
243 GObjectClass *gobject_class;
244 gobject_class = (GObjectClass*) klass;
246 parent_class = g_type_class_peek_parent (klass);
247 gobject_class->finalize = modest_folder_view_finalize;
249 g_type_class_add_private (gobject_class,
250 sizeof(ModestFolderViewPrivate));
252 signals[FOLDER_SELECTION_CHANGED_SIGNAL] =
253 g_signal_new ("folder_selection_changed",
254 G_TYPE_FROM_CLASS (gobject_class),
256 G_STRUCT_OFFSET (ModestFolderViewClass,
257 folder_selection_changed),
259 modest_marshal_VOID__POINTER_BOOLEAN,
260 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
263 * This signal is emitted whenever the currently selected
264 * folder display name is computed. Note that the name could
265 * be different to the folder name, because we could append
266 * the unread messages count to the folder name to build the
267 * folder display name
269 signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL] =
270 g_signal_new ("folder-display-name-changed",
271 G_TYPE_FROM_CLASS (gobject_class),
273 G_STRUCT_OFFSET (ModestFolderViewClass,
274 folder_display_name_changed),
276 g_cclosure_marshal_VOID__STRING,
277 G_TYPE_NONE, 1, G_TYPE_STRING);
280 /* Simplify checks for NULLs: */
282 strings_are_equal (const gchar *a, const gchar *b)
288 return (strcmp (a, b) == 0);
295 on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
297 GObject *instance = NULL;
299 gtk_tree_model_get (model, iter,
300 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
304 return FALSE; /* keep walking */
306 if (!TNY_IS_ACCOUNT (instance)) {
307 g_object_unref (instance);
308 return FALSE; /* keep walking */
311 /* Check if this is the looked-for account: */
312 TnyAccount *this_account = TNY_ACCOUNT (instance);
313 TnyAccount *account = TNY_ACCOUNT (data);
315 const gchar *this_account_id = tny_account_get_id(this_account);
316 const gchar *account_id = tny_account_get_id(account);
317 g_object_unref (instance);
320 /* printf ("DEBUG: %s: this_account_id=%s, account_id=%s\n", __FUNCTION__, this_account_id, account_id); */
321 if (strings_are_equal(this_account_id, account_id)) {
322 /* Tell the model that the data has changed, so that
323 * it calls the cell_data_func callbacks again: */
324 /* TODO: This does not seem to actually cause the new string to be shown: */
325 gtk_tree_model_row_changed (model, path, iter);
327 return TRUE; /* stop walking */
330 return FALSE; /* keep walking */
335 ModestFolderView *self;
336 gchar *previous_name;
337 } GetMmcAccountNameData;
340 on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data)
342 /* printf ("DEBU1G: %s: account name=%s\n", __FUNCTION__, tny_account_get_name (TNY_ACCOUNT(account))); */
344 GetMmcAccountNameData *data = (GetMmcAccountNameData*)user_data;
346 if (!strings_are_equal (
347 tny_account_get_name(TNY_ACCOUNT(account)),
348 data->previous_name)) {
350 /* Tell the model that the data has changed, so that
351 * it calls the cell_data_func callbacks again: */
352 ModestFolderView *self = data->self;
353 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
355 gtk_tree_model_foreach(model, on_model_foreach_set_name, account);
358 g_free (data->previous_name);
359 g_slice_free (GetMmcAccountNameData, data);
363 text_cell_data (GtkTreeViewColumn *column,
364 GtkCellRenderer *renderer,
365 GtkTreeModel *tree_model,
369 ModestFolderViewPrivate *priv;
370 GObject *rendobj = (GObject *) renderer;
372 TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
373 GObject *instance = NULL;
375 gtk_tree_model_get (tree_model, iter,
376 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &fname,
377 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
378 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
388 ModestFolderView *self = MODEST_FOLDER_VIEW (data);
389 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
391 gchar *item_name = NULL;
392 gint item_weight = 400;
394 if (type != TNY_FOLDER_TYPE_ROOT) {
397 if (modest_tny_folder_is_local_folder (TNY_FOLDER (instance)) ||
398 modest_tny_folder_is_memory_card_folder (TNY_FOLDER (instance))) {
399 type = modest_tny_folder_get_local_or_mmc_folder_type (TNY_FOLDER (instance));
400 if (type != TNY_FOLDER_TYPE_UNKNOWN) {
402 fname = g_strdup (modest_local_folder_info_get_type_display_name (type));
406 /* note: we cannot reliably get the counts from the tree model, we need
407 * to use explicit calls on tny_folder for some reason.
409 /* Select the number to show: the unread or unsent messages. in case of outbox/drafts, show all */
410 if ((type == TNY_FOLDER_TYPE_DRAFTS) ||
411 (type == TNY_FOLDER_TYPE_OUTBOX) ||
412 (type == TNY_FOLDER_TYPE_MERGE)) /* _OUTBOX actually returns _MERGE... */
413 number = tny_folder_get_all_count (TNY_FOLDER(instance));
415 number = tny_folder_get_unread_count (TNY_FOLDER(instance));
417 /* Use bold font style if there are unread or unset messages */
419 item_name = g_strdup_printf ("%s (%d)", fname, number);
422 item_name = g_strdup (fname);
426 } else if (TNY_IS_ACCOUNT (instance)) {
427 /* If it's a server account */
428 if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (instance))) {
429 item_name = g_strdup (priv->local_account_name);
431 } else if (modest_tny_account_is_memory_card_account (TNY_ACCOUNT (instance))) {
432 /* fname is only correct when the items are first
433 * added to the model, not when the account is
434 * changed later, so get the name from the account
436 item_name = g_strdup (tny_account_get_name (TNY_ACCOUNT (instance)));
439 item_name = g_strdup (fname);
445 item_name = g_strdup ("unknown");
447 if (item_name && item_weight) {
448 /* Set the name in the treeview cell: */
449 g_object_set (rendobj,"text", item_name, "weight", item_weight, NULL);
451 /* Notify display name observers */
452 /* TODO: What listens for this signal, and how can it use only the new name? */
453 if (((GObject *) priv->cur_folder_store) == instance) {
454 g_signal_emit (G_OBJECT(self),
455 signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
462 /* If it is a Memory card account, make sure that we have the correct name.
463 * This function will be trigerred again when the name has been retrieved: */
464 if (TNY_IS_STORE_ACCOUNT (instance) &&
465 modest_tny_account_is_memory_card_account (TNY_ACCOUNT (instance))) {
467 /* Get the account name asynchronously: */
468 GetMmcAccountNameData *callback_data =
469 g_slice_new0(GetMmcAccountNameData);
470 callback_data->self = self;
472 const gchar *name = tny_account_get_name (TNY_ACCOUNT(instance));
474 callback_data->previous_name = g_strdup (name);
476 modest_tny_account_get_mmc_account_name (TNY_STORE_ACCOUNT (instance),
477 on_get_mmc_account_name, callback_data);
480 g_object_unref (G_OBJECT (instance));
487 GdkPixbuf *pixbuf_open;
488 GdkPixbuf *pixbuf_close;
493 get_folder_icons (TnyFolderType type, GObject *instance)
495 GdkPixbuf *pixbuf = NULL;
496 GdkPixbuf *pixbuf_open = NULL;
497 GdkPixbuf *pixbuf_close = NULL;
498 ThreePixbufs *retval = g_slice_new (ThreePixbufs);
500 static GdkPixbuf *inbox_pixbuf = NULL, *outbox_pixbuf = NULL,
501 *junk_pixbuf = NULL, *sent_pixbuf = NULL,
502 *trash_pixbuf = NULL, *draft_pixbuf = NULL,
503 *normal_pixbuf = NULL, *anorm_pixbuf = NULL,
504 *ammc_pixbuf = NULL, *avirt_pixbuf = NULL;
506 static GdkPixbuf *inbox_pixbuf_open = NULL, *outbox_pixbuf_open = NULL,
507 *junk_pixbuf_open = NULL, *sent_pixbuf_open = NULL,
508 *trash_pixbuf_open = NULL, *draft_pixbuf_open = NULL,
509 *normal_pixbuf_open = NULL, *anorm_pixbuf_open = NULL,
510 *ammc_pixbuf_open = NULL, *avirt_pixbuf_open = NULL;
512 static GdkPixbuf *inbox_pixbuf_close = NULL, *outbox_pixbuf_close = NULL,
513 *junk_pixbuf_close = NULL, *sent_pixbuf_close = NULL,
514 *trash_pixbuf_close = NULL, *draft_pixbuf_close = NULL,
515 *normal_pixbuf_close = NULL, *anorm_pixbuf_close = NULL,
516 *ammc_pixbuf_close = NULL, *avirt_pixbuf_close = NULL;
519 /* MERGE is not needed anymore as the folder now has the correct type jschmid */
520 /* We include the MERGE type here because it's used to create
521 the local OUTBOX folder */
522 if (type == TNY_FOLDER_TYPE_NORMAL ||
523 type == TNY_FOLDER_TYPE_UNKNOWN) {
524 type = modest_tny_folder_guess_folder_type (TNY_FOLDER (instance));
528 case TNY_FOLDER_TYPE_INVALID:
529 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
532 case TNY_FOLDER_TYPE_ROOT:
533 if (TNY_IS_ACCOUNT (instance)) {
535 if (modest_tny_account_is_virtual_local_folders (
536 TNY_ACCOUNT (instance))) {
539 avirt_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_LOCAL_FOLDERS,
540 MODEST_ICON_SIZE_SMALL));
542 if (!avirt_pixbuf_open) {
543 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
544 MODEST_ICON_SIZE_SMALL);
545 avirt_pixbuf_open = gdk_pixbuf_copy (avirt_pixbuf);
546 gdk_pixbuf_composite (emblem, avirt_pixbuf_open, 0, 0,
547 MIN (gdk_pixbuf_get_width (emblem),
548 gdk_pixbuf_get_width (avirt_pixbuf_open)),
549 MIN (gdk_pixbuf_get_height (emblem),
550 gdk_pixbuf_get_height (avirt_pixbuf_open)),
551 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
552 g_object_unref (emblem);
555 if (!avirt_pixbuf_close) {
556 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
557 MODEST_ICON_SIZE_SMALL);
558 avirt_pixbuf_close = gdk_pixbuf_copy (avirt_pixbuf);
559 gdk_pixbuf_composite (emblem, avirt_pixbuf_close, 0, 0,
560 MIN (gdk_pixbuf_get_width (emblem),
561 gdk_pixbuf_get_width (avirt_pixbuf_close)),
562 MIN (gdk_pixbuf_get_height (emblem),
563 gdk_pixbuf_get_height (avirt_pixbuf_close)),
564 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
565 g_object_unref (emblem);
569 pixbuf = g_object_ref (avirt_pixbuf);
570 pixbuf_open = g_object_ref (avirt_pixbuf_open);
571 pixbuf_close = g_object_ref (avirt_pixbuf_close);
575 const gchar *account_id = tny_account_get_id (TNY_ACCOUNT (instance));
577 if (!strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
579 ammc_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_MMC,
580 MODEST_ICON_SIZE_SMALL));
582 if (!ammc_pixbuf_open) {
583 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
584 MODEST_ICON_SIZE_SMALL);
585 ammc_pixbuf_open = gdk_pixbuf_copy (ammc_pixbuf);
586 gdk_pixbuf_composite (emblem, ammc_pixbuf_open, 0, 0,
587 MIN (gdk_pixbuf_get_width (emblem),
588 gdk_pixbuf_get_width (ammc_pixbuf_open)),
589 MIN (gdk_pixbuf_get_height (emblem),
590 gdk_pixbuf_get_height (ammc_pixbuf_open)),
591 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
592 g_object_unref (emblem);
595 if (!ammc_pixbuf_close) {
596 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
597 MODEST_ICON_SIZE_SMALL);
598 ammc_pixbuf_close = gdk_pixbuf_copy (ammc_pixbuf);
599 gdk_pixbuf_composite (emblem, ammc_pixbuf_close, 0, 0,
600 MIN (gdk_pixbuf_get_width (emblem),
601 gdk_pixbuf_get_width (ammc_pixbuf_close)),
602 MIN (gdk_pixbuf_get_height (emblem),
603 gdk_pixbuf_get_height (ammc_pixbuf_close)),
604 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
605 g_object_unref (emblem);
609 pixbuf = g_object_ref (ammc_pixbuf);
610 pixbuf_open = g_object_ref (ammc_pixbuf_open);
611 pixbuf_close = g_object_ref (ammc_pixbuf_close);
616 anorm_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_ACCOUNT,
617 MODEST_ICON_SIZE_SMALL));
618 if (!anorm_pixbuf_open) {
619 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
620 MODEST_ICON_SIZE_SMALL);
621 anorm_pixbuf_open = gdk_pixbuf_copy (anorm_pixbuf);
622 gdk_pixbuf_composite (emblem, anorm_pixbuf_open, 0, 0,
623 MIN (gdk_pixbuf_get_width (emblem),
624 gdk_pixbuf_get_width (anorm_pixbuf_open)),
625 MIN (gdk_pixbuf_get_height (emblem),
626 gdk_pixbuf_get_height (anorm_pixbuf_open)),
627 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
628 g_object_unref (emblem);
631 if (!anorm_pixbuf_close) {
632 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
633 MODEST_ICON_SIZE_SMALL);
634 anorm_pixbuf_close = gdk_pixbuf_copy (anorm_pixbuf);
635 gdk_pixbuf_composite (emblem, anorm_pixbuf_close, 0, 0,
636 MIN (gdk_pixbuf_get_width (emblem),
637 gdk_pixbuf_get_width (anorm_pixbuf_close)),
638 MIN (gdk_pixbuf_get_height (emblem),
639 gdk_pixbuf_get_height (anorm_pixbuf_close)),
640 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
641 g_object_unref (emblem);
645 pixbuf = g_object_ref (anorm_pixbuf);
646 pixbuf_open = g_object_ref (anorm_pixbuf_open);
647 pixbuf_close = g_object_ref (anorm_pixbuf_close);
653 case TNY_FOLDER_TYPE_INBOX:
656 inbox_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_INBOX,
657 MODEST_ICON_SIZE_SMALL));
659 if (!inbox_pixbuf_open) {
660 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
661 MODEST_ICON_SIZE_SMALL);
662 inbox_pixbuf_open = gdk_pixbuf_copy (inbox_pixbuf);
663 gdk_pixbuf_composite (emblem, inbox_pixbuf_open, 0, 0,
664 MIN (gdk_pixbuf_get_width (emblem),
665 gdk_pixbuf_get_width (inbox_pixbuf_open)),
666 MIN (gdk_pixbuf_get_height (emblem),
667 gdk_pixbuf_get_height (inbox_pixbuf_open)),
668 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
669 g_object_unref (emblem);
672 if (!inbox_pixbuf_close) {
673 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
674 MODEST_ICON_SIZE_SMALL);
675 inbox_pixbuf_close = gdk_pixbuf_copy (inbox_pixbuf);
676 gdk_pixbuf_composite (emblem, inbox_pixbuf_close, 0, 0,
677 MIN (gdk_pixbuf_get_width (emblem),
678 gdk_pixbuf_get_width (inbox_pixbuf_close)),
679 MIN (gdk_pixbuf_get_height (emblem),
680 gdk_pixbuf_get_height (inbox_pixbuf_close)),
681 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
682 g_object_unref (emblem);
686 pixbuf = g_object_ref (inbox_pixbuf);
687 pixbuf_open = g_object_ref (inbox_pixbuf_open);
688 pixbuf_close = g_object_ref (inbox_pixbuf_close);
691 case TNY_FOLDER_TYPE_OUTBOX:
693 outbox_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_OUTBOX,
694 MODEST_ICON_SIZE_SMALL));
696 if (!outbox_pixbuf_open) {
697 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
698 MODEST_ICON_SIZE_SMALL);
699 outbox_pixbuf_open = gdk_pixbuf_copy (outbox_pixbuf);
700 gdk_pixbuf_composite (emblem, outbox_pixbuf_open, 0, 0,
701 MIN (gdk_pixbuf_get_width (emblem),
702 gdk_pixbuf_get_width (outbox_pixbuf_open)),
703 MIN (gdk_pixbuf_get_height (emblem),
704 gdk_pixbuf_get_height (outbox_pixbuf_open)),
705 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
706 g_object_unref (emblem);
709 if (!outbox_pixbuf_close) {
710 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
711 MODEST_ICON_SIZE_SMALL);
712 outbox_pixbuf_close = gdk_pixbuf_copy (outbox_pixbuf);
713 gdk_pixbuf_composite (emblem, outbox_pixbuf_close, 0, 0,
714 MIN (gdk_pixbuf_get_width (emblem),
715 gdk_pixbuf_get_width (outbox_pixbuf_close)),
716 MIN (gdk_pixbuf_get_height (emblem),
717 gdk_pixbuf_get_height (outbox_pixbuf_close)),
718 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
719 g_object_unref (emblem);
723 pixbuf = g_object_ref (outbox_pixbuf);
724 pixbuf_open = g_object_ref (outbox_pixbuf_open);
725 pixbuf_close = g_object_ref (outbox_pixbuf_close);
728 case TNY_FOLDER_TYPE_JUNK:
730 junk_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_JUNK,
731 MODEST_ICON_SIZE_SMALL));
732 if (!junk_pixbuf_open) {
733 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
734 MODEST_ICON_SIZE_SMALL);
735 junk_pixbuf_open = gdk_pixbuf_copy (junk_pixbuf);
736 gdk_pixbuf_composite (emblem, junk_pixbuf_open, 0, 0,
737 MIN (gdk_pixbuf_get_width (emblem),
738 gdk_pixbuf_get_width (junk_pixbuf_open)),
739 MIN (gdk_pixbuf_get_height (emblem),
740 gdk_pixbuf_get_height (junk_pixbuf_open)),
741 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
742 g_object_unref (emblem);
745 if (!junk_pixbuf_close) {
746 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
747 MODEST_ICON_SIZE_SMALL);
748 junk_pixbuf_close = gdk_pixbuf_copy (junk_pixbuf);
749 gdk_pixbuf_composite (emblem, junk_pixbuf_close, 0, 0,
750 MIN (gdk_pixbuf_get_width (emblem),
751 gdk_pixbuf_get_width (junk_pixbuf_close)),
752 MIN (gdk_pixbuf_get_height (emblem),
753 gdk_pixbuf_get_height (junk_pixbuf_close)),
754 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
755 g_object_unref (emblem);
759 pixbuf = g_object_ref (junk_pixbuf);
760 pixbuf_open = g_object_ref (junk_pixbuf_open);
761 pixbuf_close = g_object_ref (junk_pixbuf_close);
765 case TNY_FOLDER_TYPE_SENT:
767 sent_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_SENT,
768 MODEST_ICON_SIZE_SMALL));
770 if (!sent_pixbuf_open) {
771 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
772 MODEST_ICON_SIZE_SMALL);
773 sent_pixbuf_open = gdk_pixbuf_copy (sent_pixbuf);
774 gdk_pixbuf_composite (emblem, sent_pixbuf_open, 0, 0,
775 MIN (gdk_pixbuf_get_width (emblem),
776 gdk_pixbuf_get_width (sent_pixbuf_open)),
777 MIN (gdk_pixbuf_get_height (emblem),
778 gdk_pixbuf_get_height (sent_pixbuf_open)),
779 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
780 g_object_unref (emblem);
783 if (!sent_pixbuf_close) {
784 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
785 MODEST_ICON_SIZE_SMALL);
786 sent_pixbuf_close = gdk_pixbuf_copy (sent_pixbuf);
787 gdk_pixbuf_composite (emblem, sent_pixbuf_close, 0, 0,
788 MIN (gdk_pixbuf_get_width (emblem),
789 gdk_pixbuf_get_width (sent_pixbuf_close)),
790 MIN (gdk_pixbuf_get_height (emblem),
791 gdk_pixbuf_get_height (sent_pixbuf_close)),
792 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
793 g_object_unref (emblem);
797 pixbuf = g_object_ref (sent_pixbuf);
798 pixbuf_open = g_object_ref (sent_pixbuf_open);
799 pixbuf_close = g_object_ref (sent_pixbuf_close);
803 case TNY_FOLDER_TYPE_TRASH:
805 trash_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_TRASH,
806 MODEST_ICON_SIZE_SMALL));
807 if (!trash_pixbuf_open) {
808 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
809 MODEST_ICON_SIZE_SMALL);
810 trash_pixbuf_open = gdk_pixbuf_copy (trash_pixbuf);
811 gdk_pixbuf_composite (emblem, trash_pixbuf_open, 0, 0,
812 MIN (gdk_pixbuf_get_width (emblem),
813 gdk_pixbuf_get_width (trash_pixbuf_open)),
814 MIN (gdk_pixbuf_get_height (emblem),
815 gdk_pixbuf_get_height (trash_pixbuf_open)),
816 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
817 g_object_unref (emblem);
820 if (!trash_pixbuf_close) {
821 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
822 MODEST_ICON_SIZE_SMALL);
823 trash_pixbuf_close = gdk_pixbuf_copy (trash_pixbuf);
824 gdk_pixbuf_composite (emblem, trash_pixbuf_close, 0, 0,
825 MIN (gdk_pixbuf_get_width (emblem),
826 gdk_pixbuf_get_width (trash_pixbuf_close)),
827 MIN (gdk_pixbuf_get_height (emblem),
828 gdk_pixbuf_get_height (trash_pixbuf_close)),
829 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
830 g_object_unref (emblem);
834 pixbuf = g_object_ref (trash_pixbuf);
835 pixbuf_open = g_object_ref (trash_pixbuf_open);
836 pixbuf_close = g_object_ref (trash_pixbuf_close);
839 case TNY_FOLDER_TYPE_DRAFTS:
841 draft_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_DRAFTS,
842 MODEST_ICON_SIZE_SMALL));
844 if (!draft_pixbuf_open) {
845 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
846 MODEST_ICON_SIZE_SMALL);
847 draft_pixbuf_open = gdk_pixbuf_copy (draft_pixbuf);
848 gdk_pixbuf_composite (emblem, draft_pixbuf_open, 0, 0,
849 MIN (gdk_pixbuf_get_width (emblem),
850 gdk_pixbuf_get_width (draft_pixbuf_open)),
851 MIN (gdk_pixbuf_get_height (emblem),
852 gdk_pixbuf_get_height (draft_pixbuf_open)),
853 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
854 g_object_unref (emblem);
857 if (!draft_pixbuf_close) {
858 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
859 MODEST_ICON_SIZE_SMALL);
860 draft_pixbuf_close = gdk_pixbuf_copy (draft_pixbuf);
861 gdk_pixbuf_composite (emblem, draft_pixbuf_close, 0, 0,
862 MIN (gdk_pixbuf_get_width (emblem),
863 gdk_pixbuf_get_width (draft_pixbuf_close)),
864 MIN (gdk_pixbuf_get_height (emblem),
865 gdk_pixbuf_get_height (draft_pixbuf_close)),
866 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
867 g_object_unref (emblem);
871 pixbuf = g_object_ref (draft_pixbuf);
872 pixbuf_open = g_object_ref (draft_pixbuf_open);
873 pixbuf_close = g_object_ref (draft_pixbuf_close);
876 case TNY_FOLDER_TYPE_NORMAL:
879 normal_pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (MODEST_FOLDER_ICON_NORMAL,
880 MODEST_ICON_SIZE_SMALL));
882 if (!normal_pixbuf_open) {
883 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_exp",
884 MODEST_ICON_SIZE_SMALL);
885 normal_pixbuf_open = gdk_pixbuf_copy (normal_pixbuf);
886 gdk_pixbuf_composite (emblem, normal_pixbuf_open, 0, 0,
887 MIN (gdk_pixbuf_get_width (emblem),
888 gdk_pixbuf_get_width (normal_pixbuf_open)),
889 MIN (gdk_pixbuf_get_height (emblem),
890 gdk_pixbuf_get_height (normal_pixbuf_open)),
891 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
892 g_object_unref (emblem);
895 if (!normal_pixbuf_close) {
896 GdkPixbuf *emblem = modest_platform_get_icon ("qgn_list_gene_fldr_clp",
897 MODEST_ICON_SIZE_SMALL);
898 normal_pixbuf_close = gdk_pixbuf_copy (normal_pixbuf);
899 gdk_pixbuf_composite (emblem, normal_pixbuf_close, 0, 0,
900 MIN (gdk_pixbuf_get_width (emblem),
901 gdk_pixbuf_get_width (normal_pixbuf_close)),
902 MIN (gdk_pixbuf_get_height (emblem),
903 gdk_pixbuf_get_height (normal_pixbuf_close)),
904 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
905 g_object_unref (emblem);
909 pixbuf = g_object_ref (normal_pixbuf);
910 pixbuf_open = g_object_ref (normal_pixbuf_open);
911 pixbuf_close = g_object_ref (normal_pixbuf_close);
917 retval->pixbuf = pixbuf;
918 retval->pixbuf_open = pixbuf_open;
919 retval->pixbuf_close = pixbuf_close;
926 free_pixbufs (ThreePixbufs *pixbufs)
928 g_object_unref (pixbufs->pixbuf);
929 g_object_unref (pixbufs->pixbuf_open);
930 g_object_unref (pixbufs->pixbuf_close);
931 g_slice_free (ThreePixbufs, pixbufs);
935 icon_cell_data (GtkTreeViewColumn *column,
936 GtkCellRenderer *renderer,
937 GtkTreeModel *tree_model,
941 GObject *rendobj = NULL, *instance = NULL;
942 TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
943 gboolean has_children;
944 ThreePixbufs *pixbufs;
946 rendobj = (GObject *) renderer;
948 gtk_tree_model_get (tree_model, iter,
949 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
950 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
956 has_children = gtk_tree_model_iter_has_child (tree_model, iter);
957 pixbufs = get_folder_icons (type, instance);
958 g_object_unref (instance);
961 g_object_set (rendobj, "pixbuf", pixbufs->pixbuf, NULL);
964 g_object_set (rendobj, "pixbuf-expander-open", pixbufs->pixbuf_open, NULL);
965 g_object_set (rendobj, "pixbuf-expander-closed", pixbufs->pixbuf_close, NULL);
968 free_pixbufs (pixbufs);
974 add_columns (GtkWidget *treeview)
976 GtkTreeViewColumn *column;
977 GtkCellRenderer *renderer;
978 GtkTreeSelection *sel;
981 column = gtk_tree_view_column_new ();
983 /* Set icon and text render function */
984 renderer = gtk_cell_renderer_pixbuf_new();
985 gtk_tree_view_column_pack_start (column, renderer, FALSE);
986 gtk_tree_view_column_set_cell_data_func(column, renderer,
987 icon_cell_data, treeview, NULL);
989 renderer = gtk_cell_renderer_text_new();
990 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END,
991 "ellipsize-set", TRUE, NULL);
992 gtk_tree_view_column_pack_start (column, renderer, TRUE);
993 gtk_tree_view_column_set_cell_data_func(column, renderer,
994 text_cell_data, treeview, NULL);
996 /* Set selection mode */
997 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(treeview));
998 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
1000 /* Set treeview appearance */
1001 gtk_tree_view_column_set_spacing (column, 2);
1002 gtk_tree_view_column_set_resizable (column, TRUE);
1003 gtk_tree_view_column_set_fixed_width (column, TRUE);
1004 gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW(treeview), FALSE);
1005 gtk_tree_view_set_enable_search (GTK_TREE_VIEW(treeview), FALSE);
1008 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview),column);
1012 modest_folder_view_init (ModestFolderView *obj)
1014 ModestFolderViewPrivate *priv;
1017 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(obj);
1019 priv->timer_expander = 0;
1020 priv->account_store = NULL;
1022 priv->style = MODEST_FOLDER_VIEW_STYLE_SHOW_ALL;
1023 priv->cur_folder_store = NULL;
1024 priv->visible_account_id = NULL;
1025 priv->folder_to_select = NULL;
1027 priv->reexpand = TRUE;
1029 /* Initialize the local account name */
1030 conf = modest_runtime_get_conf();
1031 priv->local_account_name = modest_conf_get_string (conf, MODEST_CONF_DEVICE_NAME, NULL);
1033 /* Init email clipboard */
1034 priv->clipboard = modest_runtime_get_email_clipboard ();
1035 priv->hidding_ids = NULL;
1036 priv->n_selected = 0;
1037 priv->reselect = FALSE;
1038 priv->show_non_move = TRUE;
1040 /* Build treeview */
1041 add_columns (GTK_WIDGET (obj));
1043 /* Setup drag and drop */
1044 setup_drag_and_drop (GTK_TREE_VIEW(obj));
1046 /* Connect signals */
1047 g_signal_connect (G_OBJECT (obj),
1049 G_CALLBACK (on_key_pressed), NULL);
1051 priv->display_name_changed_signal =
1052 g_signal_connect (modest_runtime_get_account_mgr (),
1053 "display_name_changed",
1054 G_CALLBACK (on_display_name_changed),
1058 * Track changes in the local account name (in the device it
1059 * will be the device name)
1061 priv->conf_key_signal = g_signal_connect (G_OBJECT(conf),
1063 G_CALLBACK(on_configuration_key_changed),
1068 tny_account_store_view_init (gpointer g, gpointer iface_data)
1070 TnyAccountStoreViewIface *klass = (TnyAccountStoreViewIface *)g;
1072 klass->set_account_store_func = modest_folder_view_set_account_store;
1078 modest_folder_view_finalize (GObject *obj)
1080 ModestFolderViewPrivate *priv;
1081 GtkTreeSelection *sel;
1083 g_return_if_fail (obj);
1085 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(obj);
1087 if (priv->timer_expander != 0) {
1088 g_source_remove (priv->timer_expander);
1089 priv->timer_expander = 0;
1092 if (priv->account_store) {
1093 g_signal_handler_disconnect (G_OBJECT(priv->account_store),
1094 priv->account_inserted_signal);
1095 g_signal_handler_disconnect (G_OBJECT(priv->account_store),
1096 priv->account_removed_signal);
1097 g_signal_handler_disconnect (G_OBJECT(priv->account_store),
1098 priv->account_changed_signal);
1099 g_object_unref (G_OBJECT(priv->account_store));
1100 priv->account_store = NULL;
1104 g_object_unref (G_OBJECT (priv->query));
1108 /* modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(obj)); */
1109 if (priv->folder_to_select) {
1110 g_object_unref (G_OBJECT(priv->folder_to_select));
1111 priv->folder_to_select = NULL;
1114 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(obj));
1116 g_signal_handler_disconnect (G_OBJECT(sel), priv->changed_signal);
1118 g_free (priv->local_account_name);
1119 g_free (priv->visible_account_id);
1121 if (priv->conf_key_signal) {
1122 g_signal_handler_disconnect (modest_runtime_get_conf (),
1123 priv->conf_key_signal);
1124 priv->conf_key_signal = 0;
1127 if (priv->cur_folder_store) {
1128 if (TNY_IS_FOLDER(priv->cur_folder_store))
1129 tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), FALSE, NULL);
1131 g_object_unref (priv->cur_folder_store);
1132 priv->cur_folder_store = NULL;
1135 /* Clear hidding array created by cut operation */
1136 _clear_hidding_filter (MODEST_FOLDER_VIEW (obj));
1138 G_OBJECT_CLASS(parent_class)->finalize (obj);
1143 modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore *account_store)
1145 ModestFolderViewPrivate *priv;
1148 g_return_if_fail (MODEST_IS_FOLDER_VIEW (self));
1149 g_return_if_fail (TNY_IS_ACCOUNT_STORE (account_store));
1151 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
1152 device = tny_account_store_get_device (account_store);
1154 if (G_UNLIKELY (priv->account_store)) {
1156 if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
1157 priv->account_inserted_signal))
1158 g_signal_handler_disconnect (G_OBJECT (priv->account_store),
1159 priv->account_inserted_signal);
1160 if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
1161 priv->account_removed_signal))
1162 g_signal_handler_disconnect (G_OBJECT (priv->account_store),
1163 priv->account_removed_signal);
1164 if (g_signal_handler_is_connected (G_OBJECT (priv->account_store),
1165 priv->account_changed_signal))
1166 g_signal_handler_disconnect (G_OBJECT (priv->account_store),
1167 priv->account_changed_signal);
1168 g_object_unref (G_OBJECT (priv->account_store));
1171 priv->account_store = g_object_ref (G_OBJECT (account_store));
1173 priv->account_removed_signal =
1174 g_signal_connect (G_OBJECT(account_store), "account_removed",
1175 G_CALLBACK (on_account_removed), self);
1177 priv->account_inserted_signal =
1178 g_signal_connect (G_OBJECT(account_store), "account_inserted",
1179 G_CALLBACK (on_account_inserted), self);
1181 priv->account_changed_signal =
1182 g_signal_connect (G_OBJECT(account_store), "account_changed",
1183 G_CALLBACK (on_account_changed), self);
1185 modest_folder_view_update_model (MODEST_FOLDER_VIEW (self), account_store);
1187 g_object_unref (G_OBJECT (device));
1191 on_connection_status_changed (TnyAccount *self,
1192 TnyConnectionStatus status,
1195 /* If the account becomes online then refresh it */
1196 if (status == TNY_CONNECTION_STATUS_CONNECTED) {
1197 const gchar *acc_name;
1198 GtkWidget *my_window;
1200 my_window = gtk_widget_get_ancestor (GTK_WIDGET (user_data), MODEST_TYPE_WINDOW);
1201 acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (self);
1202 modest_ui_actions_do_send_receive (acc_name, MODEST_WINDOW (my_window));
1207 on_account_inserted (TnyAccountStore *account_store,
1208 TnyAccount *account,
1211 ModestFolderViewPrivate *priv;
1212 GtkTreeModel *sort_model, *filter_model;
1214 /* Ignore transport account insertions, we're not showing them
1215 in the folder view */
1216 if (TNY_IS_TRANSPORT_ACCOUNT (account))
1219 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (user_data);
1221 /* If we're adding a new account, and there is no previous
1222 one, we need to select the visible server account */
1223 if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
1224 !priv->visible_account_id)
1225 modest_widget_memory_restore (modest_runtime_get_conf(),
1226 G_OBJECT (user_data),
1227 MODEST_CONF_FOLDER_VIEW_KEY);
1229 /* Get the inner model */
1230 filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
1231 sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
1233 /* Insert the account in the model */
1234 tny_list_append (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
1235 G_OBJECT (account));
1238 /* When the store account gets online refresh it */
1239 g_signal_connect (account, "connection_status_changed",
1240 G_CALLBACK (on_connection_status_changed),
1241 MODEST_FOLDER_VIEW (user_data));
1243 /* Refilter the model */
1244 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
1249 on_account_changed (TnyAccountStore *account_store,
1250 TnyAccount *tny_account,
1253 ModestFolderViewPrivate *priv;
1254 GtkTreeModel *sort_model, *filter_model;
1256 /* Ignore transport account insertions, we're not showing them
1257 in the folder view */
1258 if (TNY_IS_TRANSPORT_ACCOUNT (tny_account))
1261 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (user_data);
1263 /* Get the inner model */
1264 filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
1265 sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
1267 /* Remove the account from the model */
1268 tny_list_remove (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
1269 G_OBJECT (tny_account));
1271 /* Insert the account in the model */
1272 tny_list_append (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
1273 G_OBJECT (tny_account));
1275 /* Refilter the model */
1276 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
1281 * Selects the first inbox or the local account in an idle
1284 on_idle_select_first_inbox_or_local (gpointer user_data)
1286 ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
1288 modest_folder_view_select_first_inbox_or_local (self);
1295 on_account_removed (TnyAccountStore *account_store,
1296 TnyAccount *account,
1299 ModestFolderView *self = NULL;
1300 ModestFolderViewPrivate *priv;
1301 GtkTreeModel *sort_model, *filter_model;
1302 GtkTreeSelection *sel = NULL;
1303 gboolean same_account_selected = FALSE;
1305 /* Ignore transport account removals, we're not showing them
1306 in the folder view */
1307 if (TNY_IS_TRANSPORT_ACCOUNT (account))
1310 self = MODEST_FOLDER_VIEW (user_data);
1311 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
1313 /* Invalidate the cur_folder_store only if the selected folder
1314 belongs to the account that is being removed */
1315 if (priv->cur_folder_store) {
1316 TnyAccount *selected_folder_account = NULL;
1318 if (TNY_IS_FOLDER (priv->cur_folder_store)) {
1319 selected_folder_account =
1320 tny_folder_get_account (TNY_FOLDER (priv->cur_folder_store));
1322 selected_folder_account =
1323 TNY_ACCOUNT (g_object_ref (priv->cur_folder_store));
1326 if (selected_folder_account == account) {
1327 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
1328 gtk_tree_selection_unselect_all (sel);
1329 same_account_selected = TRUE;
1331 g_object_unref (selected_folder_account);
1334 /* Invalidate row to select only if the folder to select
1335 belongs to the account that is being removed*/
1336 if (priv->folder_to_select) {
1337 TnyAccount *folder_to_select_account = NULL;
1339 folder_to_select_account = tny_folder_get_account (priv->folder_to_select);
1340 if (folder_to_select_account == account) {
1341 modest_folder_view_disable_next_folder_selection (self);
1342 g_object_unref (priv->folder_to_select);
1343 priv->folder_to_select = NULL;
1345 g_object_unref (folder_to_select_account);
1348 /* Remove the account from the model */
1349 filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
1350 sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
1351 tny_list_remove (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
1352 G_OBJECT (account));
1354 /* If the removed account is the currently viewed one then
1355 clear the configuration value. The new visible account will be the default account */
1356 if (priv->visible_account_id &&
1357 !strcmp (priv->visible_account_id, tny_account_get_id (account))) {
1359 /* Clear the current visible account_id */
1360 modest_folder_view_set_account_id_of_visible_server_account (self, NULL);
1362 /* Call the restore method, this will set the new visible account */
1363 modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self),
1364 MODEST_CONF_FOLDER_VIEW_KEY);
1367 /* Refilter the model */
1368 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
1370 /* Select the first INBOX if the currently selected folder
1371 belongs to the account that is being deleted */
1372 if (same_account_selected)
1373 g_idle_add (on_idle_select_first_inbox_or_local, self);
1377 modest_folder_view_set_title (ModestFolderView *self, const gchar *title)
1379 GtkTreeViewColumn *col;
1381 g_return_if_fail (self && MODEST_IS_FOLDER_VIEW(self));
1383 col = gtk_tree_view_get_column (GTK_TREE_VIEW(self), 0);
1385 g_printerr ("modest: failed get column for title\n");
1389 gtk_tree_view_column_set_title (col, title);
1390 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self),
1395 modest_folder_view_on_map (ModestFolderView *self,
1396 GdkEventExpose *event,
1399 ModestFolderViewPrivate *priv;
1401 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
1403 /* This won't happen often */
1404 if (G_UNLIKELY (priv->reselect)) {
1405 /* Select the first inbox or the local account if not found */
1407 /* TODO: this could cause a lock at startup, so we
1408 comment it for the moment. We know that this will
1409 be a bug, because the INBOX is not selected, but we
1410 need to rewrite some parts of Modest to avoid the
1411 deathlock situation */
1412 /* TODO: check if this is still the case */
1413 priv->reselect = FALSE;
1414 modest_folder_view_select_first_inbox_or_local (self);
1415 /* Notify the display name observers */
1416 g_signal_emit (G_OBJECT(self),
1417 signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
1421 if (priv->reexpand) {
1422 expand_root_items (self);
1423 priv->reexpand = FALSE;
1430 modest_folder_view_new (TnyFolderStoreQuery *query)
1433 ModestFolderViewPrivate *priv;
1434 GtkTreeSelection *sel;
1436 self = G_OBJECT (g_object_new (MODEST_TYPE_FOLDER_VIEW, NULL));
1437 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
1440 priv->query = g_object_ref (query);
1442 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(self));
1443 priv->changed_signal = g_signal_connect (sel, "changed",
1444 G_CALLBACK (on_selection_changed), self);
1446 g_signal_connect (self, "expose-event", G_CALLBACK (modest_folder_view_on_map), NULL);
1448 return GTK_WIDGET(self);
1451 /* this feels dirty; any other way to expand all the root items? */
1453 expand_root_items (ModestFolderView *self)
1456 GtkTreeModel *model;
1459 model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
1460 path = gtk_tree_path_new_first ();
1462 /* all folders should have child items, so.. */
1464 gtk_tree_view_expand_row (GTK_TREE_VIEW(self), path, FALSE);
1465 gtk_tree_path_next (path);
1466 } while (gtk_tree_model_get_iter (model, &iter, path));
1468 gtk_tree_path_free (path);
1472 * We use this function to implement the
1473 * MODEST_FOLDER_VIEW_STYLE_SHOW_ONE style. We only show the default
1474 * account in this case, and the local folders.
1477 filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1479 ModestFolderViewPrivate *priv;
1480 gboolean retval = TRUE;
1481 TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
1482 GObject *instance = NULL;
1483 const gchar *id = NULL;
1485 gboolean found = FALSE;
1486 gboolean cleared = FALSE;
1488 g_return_val_if_fail (MODEST_IS_FOLDER_VIEW (data), FALSE);
1489 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (data);
1491 gtk_tree_model_get (model, iter,
1492 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
1493 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
1496 /* Do not show if there is no instance, this could indeed
1497 happen when the model is being modified while it's being
1498 drawn. This could occur for example when moving folders
1503 if (type == TNY_FOLDER_TYPE_ROOT) {
1504 /* TNY_FOLDER_TYPE_ROOT means that the instance is an
1505 account instead of a folder. */
1506 if (TNY_IS_ACCOUNT (instance)) {
1507 TnyAccount *acc = TNY_ACCOUNT (instance);
1508 const gchar *account_id = tny_account_get_id (acc);
1510 /* If it isn't a special folder,
1511 * don't show it unless it is the visible account: */
1512 if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
1513 !modest_tny_account_is_virtual_local_folders (acc) &&
1514 strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
1516 /* Show only the visible account id */
1517 if (priv->visible_account_id) {
1518 if (strcmp (account_id, priv->visible_account_id))
1525 /* Never show these to the user. They are merged into one folder
1526 * in the local-folders account instead: */
1527 if (retval && MODEST_IS_TNY_OUTBOX_ACCOUNT (acc))
1532 /* Check hiding (if necessary) */
1533 cleared = modest_email_clipboard_cleared (priv->clipboard);
1534 if ((retval) && (!cleared) && (TNY_IS_FOLDER (instance))) {
1535 id = tny_folder_get_id (TNY_FOLDER(instance));
1536 if (priv->hidding_ids != NULL)
1537 for (i=0; i < priv->n_selected && !found; i++)
1538 if (priv->hidding_ids[i] != NULL && id != NULL)
1539 found = (!strcmp (priv->hidding_ids[i], id));
1545 /* If this is a move to dialog, hide Sent, Outbox and Drafts
1546 folder as no message can be move there according to UI specs */
1547 if (!priv->show_non_move) {
1549 case TNY_FOLDER_TYPE_OUTBOX:
1550 case TNY_FOLDER_TYPE_SENT:
1551 case TNY_FOLDER_TYPE_DRAFTS:
1554 case TNY_FOLDER_TYPE_UNKNOWN:
1555 case TNY_FOLDER_TYPE_NORMAL:
1556 type = modest_tny_folder_guess_folder_type(TNY_FOLDER(instance));
1557 if (type == TNY_FOLDER_TYPE_INVALID)
1558 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
1560 if (type == TNY_FOLDER_TYPE_OUTBOX ||
1561 type == TNY_FOLDER_TYPE_SENT
1562 || type == TNY_FOLDER_TYPE_DRAFTS)
1571 g_object_unref (instance);
1578 modest_folder_view_update_model (ModestFolderView *self,
1579 TnyAccountStore *account_store)
1581 ModestFolderViewPrivate *priv;
1582 GtkTreeModel *model /* , *old_model */;
1583 GtkTreeModel *filter_model = NULL, *sortable = NULL;
1585 g_return_val_if_fail (self && MODEST_IS_FOLDER_VIEW (self), FALSE);
1586 g_return_val_if_fail (account_store && MODEST_IS_TNY_ACCOUNT_STORE(account_store),
1589 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
1591 /* Notify that there is no folder selected */
1592 g_signal_emit (G_OBJECT(self),
1593 signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
1595 if (priv->cur_folder_store) {
1596 g_object_unref (priv->cur_folder_store);
1597 priv->cur_folder_store = NULL;
1600 /* FIXME: the local accounts are not shown when the query
1601 selects only the subscribed folders */
1602 model = tny_gtk_folder_store_tree_model_new (NULL);
1604 /* Get the accounts: */
1605 tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
1607 TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
1609 sortable = gtk_tree_model_sort_new_with_model (model);
1610 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
1611 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
1612 GTK_SORT_ASCENDING);
1613 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
1614 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
1615 cmp_rows, NULL, NULL);
1617 /* Create filter model */
1618 filter_model = gtk_tree_model_filter_new (sortable, NULL);
1619 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model),
1625 gtk_tree_view_set_model (GTK_TREE_VIEW(self), filter_model);
1626 g_signal_connect (G_OBJECT(filter_model), "row-inserted",
1627 (GCallback) on_row_inserted_maybe_select_folder, self);
1630 g_object_unref (model);
1631 g_object_unref (filter_model);
1632 g_object_unref (sortable);
1634 /* Force a reselection of the INBOX next time the widget is shown */
1635 priv->reselect = TRUE;
1642 on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
1644 GtkTreeModel *model = NULL;
1645 TnyFolderStore *folder = NULL;
1647 ModestFolderView *tree_view = NULL;
1648 ModestFolderViewPrivate *priv = NULL;
1649 gboolean selected = FALSE;
1651 g_return_if_fail (sel);
1652 g_return_if_fail (user_data);
1654 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(user_data);
1656 selected = gtk_tree_selection_get_selected (sel, &model, &iter);
1658 /* Notify the display name observers */
1659 /* TODO: this is redundant, and it's only required because we sometimes lose the focus of the folder
1661 g_signal_emit (G_OBJECT(user_data),
1662 signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
1665 tree_view = MODEST_FOLDER_VIEW (user_data);
1668 gtk_tree_model_get (model, &iter,
1669 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
1672 /* If the folder is the same do not notify */
1673 if (folder && priv->cur_folder_store == folder) {
1674 g_object_unref (folder);
1679 /* Current folder was unselected */
1680 if (priv->cur_folder_store) {
1681 g_signal_emit (G_OBJECT(tree_view), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
1682 priv->cur_folder_store, FALSE);
1684 if (TNY_IS_FOLDER(priv->cur_folder_store))
1685 tny_folder_sync_async (TNY_FOLDER(priv->cur_folder_store),
1686 FALSE, NULL, NULL, NULL);
1688 /* FALSE --> don't expunge the messages */
1690 g_object_unref (priv->cur_folder_store);
1691 priv->cur_folder_store = NULL;
1694 /* New current references */
1695 priv->cur_folder_store = folder;
1697 /* New folder has been selected. Do not notify if there is
1698 nothing new selected */
1700 g_signal_emit (G_OBJECT(tree_view),
1701 signals[FOLDER_SELECTION_CHANGED_SIGNAL],
1702 0, priv->cur_folder_store, TRUE);
1707 modest_folder_view_get_selected (ModestFolderView *self)
1709 ModestFolderViewPrivate *priv;
1711 g_return_val_if_fail (self && MODEST_IS_FOLDER_VIEW(self), NULL);
1713 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
1714 if (priv->cur_folder_store)
1715 g_object_ref (priv->cur_folder_store);
1717 return priv->cur_folder_store;
1721 get_cmp_rows_type_pos (GObject *folder)
1723 /* Remote accounts -> Local account -> MMC account .*/
1726 if (TNY_IS_ACCOUNT (folder) &&
1727 modest_tny_account_is_virtual_local_folders (
1728 TNY_ACCOUNT (folder))) {
1730 } else if (TNY_IS_ACCOUNT (folder)) {
1731 TnyAccount *account = TNY_ACCOUNT (folder);
1732 const gchar *account_id = tny_account_get_id (account);
1733 if (!strcmp (account_id, MODEST_MMC_ACCOUNT_ID))
1739 printf ("DEBUG: %s: unexpected type.\n", __FUNCTION__);
1740 return -1; /* Should never happen */
1745 get_cmp_subfolder_type_pos (TnyFolderType t)
1747 /* Inbox, Outbox, Drafts, Sent, User */
1751 case TNY_FOLDER_TYPE_INBOX:
1754 case TNY_FOLDER_TYPE_OUTBOX:
1757 case TNY_FOLDER_TYPE_DRAFTS:
1760 case TNY_FOLDER_TYPE_SENT:
1769 * This function orders the mail accounts according to these rules:
1770 * 1st - remote accounts
1771 * 2nd - local account
1775 cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
1779 gchar *name1 = NULL;
1780 gchar *name2 = NULL;
1781 TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
1782 TnyFolderType type2 = TNY_FOLDER_TYPE_UNKNOWN;
1783 GObject *folder1 = NULL;
1784 GObject *folder2 = NULL;
1786 gtk_tree_model_get (tree_model, iter1,
1787 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name1,
1788 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
1789 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder1,
1791 gtk_tree_model_get (tree_model, iter2,
1792 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name2,
1793 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type2,
1794 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder2,
1797 /* Return if we get no folder. This could happen when folder
1798 operations are happening. The model is updated after the
1799 folder copy/move actually occurs, so there could be
1800 situations where the model to be drawn is not correct */
1801 if (!folder1 || !folder2)
1804 if (type == TNY_FOLDER_TYPE_ROOT) {
1805 /* Compare the types, so that
1806 * Remote accounts -> Local account -> MMC account .*/
1807 const gint pos1 = get_cmp_rows_type_pos (folder1);
1808 const gint pos2 = get_cmp_rows_type_pos (folder2);
1809 /* printf ("DEBUG: %s:\n type1=%s, pos1=%d\n type2=%s, pos2=%d\n",
1810 __FUNCTION__, G_OBJECT_TYPE_NAME(folder1), pos1, G_OBJECT_TYPE_NAME(folder2), pos2); */
1813 else if (pos1 > pos2)
1816 /* Compare items of the same type: */
1818 TnyAccount *account1 = NULL;
1819 if (TNY_IS_ACCOUNT (folder1))
1820 account1 = TNY_ACCOUNT (folder1);
1822 TnyAccount *account2 = NULL;
1823 if (TNY_IS_ACCOUNT (folder2))
1824 account2 = TNY_ACCOUNT (folder2);
1826 const gchar *account_id = account1 ? tny_account_get_id (account1) : NULL;
1827 const gchar *account_id2 = account2 ? tny_account_get_id (account2) : NULL;
1829 if (!account_id && !account_id2) {
1831 } else if (!account_id) {
1833 } else if (!account_id2) {
1835 } else if (!strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
1838 cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
1842 gint cmp1 = 0, cmp2 = 0;
1843 /* get the parent to know if it's a local folder */
1846 gboolean has_parent;
1847 has_parent = gtk_tree_model_iter_parent (tree_model, &parent, iter1);
1849 GObject *parent_folder;
1850 TnyFolderType parent_type = TNY_FOLDER_TYPE_UNKNOWN;
1851 gtk_tree_model_get (tree_model, &parent,
1852 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &parent_type,
1853 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &parent_folder,
1855 if ((parent_type == TNY_FOLDER_TYPE_ROOT) &&
1856 TNY_IS_ACCOUNT (parent_folder) &&
1857 modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
1858 cmp1 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_or_mmc_folder_type
1859 (TNY_FOLDER (folder1)));
1860 cmp2 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_or_mmc_folder_type
1861 (TNY_FOLDER (folder2)));
1863 g_object_unref (parent_folder);
1866 /* if they are not local folders */
1868 cmp1 = get_cmp_subfolder_type_pos (tny_folder_get_folder_type (TNY_FOLDER (folder1)));
1869 cmp2 = get_cmp_subfolder_type_pos (tny_folder_get_folder_type (TNY_FOLDER (folder2)));
1873 cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
1875 cmp = (cmp1 - cmp2);
1880 g_object_unref(G_OBJECT(folder1));
1882 g_object_unref(G_OBJECT(folder2));
1890 /*****************************************************************************/
1891 /* DRAG and DROP stuff */
1892 /*****************************************************************************/
1894 * This function fills the #GtkSelectionData with the row and the
1895 * model that has been dragged. It's called when this widget is a
1896 * source for dnd after the event drop happened
1899 on_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data,
1900 guint info, guint time, gpointer data)
1902 GtkTreeSelection *selection;
1903 GtkTreeModel *model;
1905 GtkTreePath *source_row;
1907 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
1908 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
1910 source_row = gtk_tree_model_get_path (model, &iter);
1911 gtk_tree_set_row_drag_data (selection_data,
1915 gtk_tree_path_free (source_row);
1919 typedef struct _DndHelper {
1920 ModestFolderView *folder_view;
1921 gboolean delete_source;
1922 GtkTreePath *source_row;
1923 GdkDragContext *context;
1928 dnd_helper_destroyer (DndHelper *helper)
1930 /* Free the helper */
1931 g_object_unref (helper->folder_view);
1932 gtk_tree_path_free (helper->source_row);
1933 g_slice_free (DndHelper, helper);
1937 * This function is the callback of the
1938 * modest_mail_operation_xfer_msgs () and
1939 * modest_mail_operation_xfer_folder() calls. We check here if the
1940 * message/folder was correctly asynchronously transferred. The reason
1941 * to use the same callback is that the code is the same, it only has
1942 * to check that the operation went fine and then finalize the drag
1946 xfer_cb (ModestMailOperation *mail_op,
1952 helper = (DndHelper *) user_data;
1954 if (modest_mail_operation_get_status (mail_op) ==
1955 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
1961 /* Notify the drag source. Never call delete, the monitor will
1962 do the job if needed */
1963 gtk_drag_finish (helper->context, success, FALSE, helper->time);
1965 /* Free the helper */
1966 dnd_helper_destroyer (helper);
1969 /* get the folder for the row the treepath refers to. */
1970 /* folder must be unref'd */
1971 static TnyFolderStore *
1972 tree_path_to_folder (GtkTreeModel *model, GtkTreePath *path)
1975 TnyFolderStore *folder = NULL;
1977 if (gtk_tree_model_get_iter (model,&iter, path))
1978 gtk_tree_model_get (model, &iter,
1979 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
1985 * This function is used by drag_data_received_cb to manage drag and
1986 * drop of a header, i.e, and drag from the header view to the folder
1990 drag_and_drop_from_header_view (GtkTreeModel *source_model,
1991 GtkTreeModel *dest_model,
1992 GtkTreePath *dest_row,
1993 GtkSelectionData *selection_data,
1996 TnyList *headers = NULL;
1997 TnyFolder *folder = NULL;
1998 TnyFolderType folder_type;
1999 ModestMailOperation *mail_op = NULL;
2000 GtkTreeIter source_iter, dest_iter;
2001 ModestWindowMgr *mgr = NULL;
2002 ModestWindow *main_win = NULL;
2003 gchar **uris, **tmp;
2006 /* Build the list of headers */
2007 mgr = modest_runtime_get_window_mgr ();
2008 headers = tny_simple_list_new ();
2009 uris = modest_dnd_selection_data_get_paths (selection_data);
2012 while (*tmp != NULL) {
2017 path = gtk_tree_path_new_from_string (*tmp);
2018 gtk_tree_model_get_iter (source_model, &source_iter, path);
2019 gtk_tree_model_get (source_model, &source_iter,
2020 TNY_GTK_HEADER_LIST_MODEL_INSTANCE_COLUMN,
2023 /* Do not enable d&d of headers already opened */
2024 if (!modest_window_mgr_find_registered_header(mgr, header, NULL))
2025 tny_list_append (headers, G_OBJECT (header));
2027 /* Free and go on */
2028 gtk_tree_path_free (path);
2029 g_object_unref (header);
2034 /* Get the target folder */
2035 gtk_tree_model_get_iter (dest_model, &dest_iter, dest_row);
2036 gtk_tree_model_get (dest_model, &dest_iter,
2037 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
2040 if (!folder || !TNY_IS_FOLDER(folder)) {
2041 /* g_warning ("%s: not a valid target folder (%p)", __FUNCTION__, folder); */
2045 folder_type = modest_tny_folder_guess_folder_type (folder);
2046 if (folder_type == TNY_FOLDER_TYPE_INVALID) {
2047 /* g_warning ("%s: invalid target folder", __FUNCTION__); */
2048 goto cleanup; /* cannot move messages there */
2051 if (modest_tny_folder_get_rules((TNY_FOLDER(folder))) & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
2052 /* g_warning ("folder not writable"); */
2053 goto cleanup; /* verboten! */
2056 /* Ask for confirmation to move */
2057 main_win = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
2059 g_warning ("%s: BUG: no main window found", __FUNCTION__);
2063 response = modest_ui_actions_msgs_move_to_confirmation (main_win, folder,
2065 if (response == GTK_RESPONSE_CANCEL)
2068 /* Transfer messages */
2069 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) main_win,
2070 modest_ui_actions_move_folder_error_handler,
2073 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2076 modest_mail_operation_xfer_msgs (mail_op,
2079 helper->delete_source,
2084 if (G_IS_OBJECT(mail_op))
2085 g_object_unref (G_OBJECT (mail_op));
2086 if (G_IS_OBJECT(folder))
2087 g_object_unref (G_OBJECT (folder));
2088 if (G_IS_OBJECT(headers))
2089 g_object_unref (headers);
2093 TnyFolderStore *src_folder;
2094 TnyFolderStore *dst_folder;
2095 ModestFolderView *folder_view;
2100 dnd_folder_info_destroyer (DndFolderInfo *info)
2102 if (info->src_folder)
2103 g_object_unref (info->src_folder);
2104 if (info->dst_folder)
2105 g_object_unref (info->dst_folder);
2106 if (info->folder_view)
2107 g_object_unref (info->folder_view);
2108 g_slice_free (DndFolderInfo, info);
2112 dnd_on_connection_failed_destroyer (DndFolderInfo *info,
2113 GtkWindow *parent_window,
2114 TnyAccount *account)
2116 time_t dnd_time = info->helper->time;
2117 GdkDragContext *context = info->helper->context;
2120 modest_ui_actions_on_account_connection_error (parent_window, account);
2122 /* Free the helper & info */
2123 dnd_helper_destroyer (info->helper);
2124 dnd_folder_info_destroyer (info);
2126 /* Notify the drag source. Never call delete, the monitor will
2127 do the job if needed */
2128 gtk_drag_finish (context, FALSE, FALSE, dnd_time);
2133 drag_and_drop_from_folder_view_src_folder_performer (gboolean canceled,
2135 GtkWindow *parent_window,
2136 TnyAccount *account,
2139 DndFolderInfo *info = NULL;
2140 ModestMailOperation *mail_op;
2142 info = (DndFolderInfo *) user_data;
2144 if (err || canceled) {
2145 dnd_on_connection_failed_destroyer (info, parent_window, account);
2149 /* Do the mail operation */
2150 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
2151 modest_ui_actions_move_folder_error_handler,
2152 info->src_folder, NULL);
2154 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2157 /* Transfer the folder */
2158 modest_mail_operation_xfer_folder (mail_op,
2159 TNY_FOLDER (info->src_folder),
2161 info->helper->delete_source,
2165 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
2166 TNY_FOLDER (info->dst_folder), TRUE);
2168 g_object_unref (G_OBJECT (mail_op));
2173 drag_and_drop_from_folder_view_dst_folder_performer (gboolean canceled,
2175 GtkWindow *parent_window,
2176 TnyAccount *account,
2179 DndFolderInfo *info = NULL;
2181 info = (DndFolderInfo *) user_data;
2183 if (err || canceled) {
2184 dnd_on_connection_failed_destroyer (info, parent_window, account);
2188 /* Connect to source folder and perform the copy/move */
2189 modest_platform_connect_if_remote_and_perform (NULL,
2191 drag_and_drop_from_folder_view_src_folder_performer,
2196 * This function is used by drag_data_received_cb to manage drag and
2197 * drop of a folder, i.e, and drag from the folder view to the same
2201 drag_and_drop_from_folder_view (GtkTreeModel *source_model,
2202 GtkTreeModel *dest_model,
2203 GtkTreePath *dest_row,
2204 GtkSelectionData *selection_data,
2207 GtkTreeIter dest_iter, iter;
2208 TnyFolderStore *dest_folder = NULL;
2209 TnyFolderStore *folder = NULL;
2210 gboolean forbidden = FALSE;
2212 DndFolderInfo *info = NULL;
2214 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE); /* don't create */
2216 g_warning ("%s: BUG: no main window", __FUNCTION__);
2221 /* check the folder rules for the destination */
2222 folder = tree_path_to_folder (dest_model, dest_row);
2223 if (TNY_IS_FOLDER(folder)) {
2224 ModestTnyFolderRules rules =
2225 modest_tny_folder_get_rules (TNY_FOLDER (folder));
2226 forbidden = rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE;
2227 } else if (TNY_IS_FOLDER_STORE(folder)) {
2228 /* enable local root as destination for folders */
2229 if (!MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (folder)
2230 && TNY_IS_ACCOUNT (folder))
2233 g_object_unref (folder);
2236 /* check the folder rules for the source */
2237 folder = tree_path_to_folder (source_model, helper->source_row);
2238 if (TNY_IS_FOLDER(folder)) {
2239 ModestTnyFolderRules rules =
2240 modest_tny_folder_get_rules (TNY_FOLDER (folder));
2241 forbidden = rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE;
2244 g_object_unref (folder);
2248 /* Check if the drag is possible */
2249 if (forbidden || !gtk_tree_path_compare (helper->source_row, dest_row)) {
2250 gtk_drag_finish (helper->context, FALSE, FALSE, helper->time);
2251 gtk_tree_path_free (helper->source_row);
2252 g_slice_free (DndHelper, helper);
2257 gtk_tree_model_get_iter (dest_model, &dest_iter, dest_row);
2258 gtk_tree_model_get (dest_model, &dest_iter,
2259 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
2261 gtk_tree_model_get_iter (source_model, &iter, helper->source_row);
2262 gtk_tree_model_get (source_model, &iter,
2263 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
2266 /* Create the info for the performer */
2267 info = g_slice_new (DndFolderInfo);
2268 info->src_folder = g_object_ref (folder);
2269 info->dst_folder = g_object_ref (dest_folder);
2270 info->folder_view = g_object_ref (helper->folder_view);
2271 info->helper = helper;
2273 /* Connect to the destination folder and perform the copy/move */
2274 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (win),
2276 drag_and_drop_from_folder_view_dst_folder_performer,
2280 g_object_unref (dest_folder);
2281 g_object_unref (folder);
2285 * This function receives the data set by the "drag-data-get" signal
2286 * handler. This information comes within the #GtkSelectionData. This
2287 * function will manage both the drags of folders of the treeview and
2288 * drags of headers of the header view widget.
2291 on_drag_data_received (GtkWidget *widget,
2292 GdkDragContext *context,
2295 GtkSelectionData *selection_data,
2300 GtkWidget *source_widget;
2301 GtkTreeModel *dest_model, *source_model;
2302 GtkTreePath *source_row, *dest_row;
2303 GtkTreeViewDropPosition pos;
2304 gboolean success = FALSE, delete_source = FALSE;
2305 DndHelper *helper = NULL;
2307 /* Do not allow further process */
2308 g_signal_stop_emission_by_name (widget, "drag-data-received");
2309 source_widget = gtk_drag_get_source_widget (context);
2311 /* Get the action */
2312 if (context->action == GDK_ACTION_MOVE) {
2313 delete_source = TRUE;
2315 /* Notify that there is no folder selected. We need to
2316 do this in order to update the headers view (and
2317 its monitors, because when moving, the old folder
2318 won't longer exist. We can not wait for the end of
2319 the operation, because the operation won't start if
2320 the folder is in use */
2321 if (source_widget == widget) {
2322 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
2323 gtk_tree_selection_unselect_all (sel);
2327 /* Check if the get_data failed */
2328 if (selection_data == NULL || selection_data->length < 0)
2329 gtk_drag_finish (context, success, FALSE, time);
2331 /* Select the destination model */
2332 dest_model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
2334 /* Get the path to the destination row. Can not call
2335 gtk_tree_view_get_drag_dest_row() because the source row
2336 is not selected anymore */
2337 gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), x, y,
2340 /* Only allow drops IN other rows */
2342 pos == GTK_TREE_VIEW_DROP_BEFORE ||
2343 pos == GTK_TREE_VIEW_DROP_AFTER)
2344 gtk_drag_finish (context, success, FALSE, time);
2346 /* Create the helper */
2347 helper = g_slice_new0 (DndHelper);
2348 helper->delete_source = delete_source;
2349 helper->context = context;
2350 helper->time = time;
2351 helper->folder_view = g_object_ref (widget);
2353 /* Drags from the header view */
2354 if (source_widget != widget) {
2355 source_model = gtk_tree_view_get_model (GTK_TREE_VIEW (source_widget));
2357 drag_and_drop_from_header_view (source_model,
2363 /* Get the source model and row */
2364 gtk_tree_get_row_drag_data (selection_data,
2367 helper->source_row = gtk_tree_path_copy (source_row);
2369 drag_and_drop_from_folder_view (source_model,
2375 gtk_tree_path_free (source_row);
2379 gtk_tree_path_free (dest_row);
2383 * We define a "drag-drop" signal handler because we do not want to
2384 * use the default one, because the default one always calls
2385 * gtk_drag_finish and we prefer to do it in the "drag-data-received"
2386 * signal handler, because there we have all the information available
2387 * to know if the dnd was a success or not.
2390 drag_drop_cb (GtkWidget *widget,
2391 GdkDragContext *context,
2399 if (!context->targets)
2402 /* Check if we're dragging a folder row */
2403 target = gtk_drag_dest_find_target (widget, context, NULL);
2405 /* Request the data from the source. */
2406 gtk_drag_get_data(widget, context, target, time);
2412 * This function expands a node of a tree view if it's not expanded
2413 * yet. Not sure why it needs the threads stuff, but gtk+`example code
2414 * does that, so that's why they're here.
2417 expand_row_timeout (gpointer data)
2419 GtkTreeView *tree_view = data;
2420 GtkTreePath *dest_path = NULL;
2421 GtkTreeViewDropPosition pos;
2422 gboolean result = FALSE;
2424 gdk_threads_enter ();
2426 gtk_tree_view_get_drag_dest_row (tree_view,
2431 (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER ||
2432 pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)) {
2433 gtk_tree_view_expand_row (tree_view, dest_path, FALSE);
2434 gtk_tree_path_free (dest_path);
2438 gtk_tree_path_free (dest_path);
2443 gdk_threads_leave ();
2449 * This function is called whenever the pointer is moved over a widget
2450 * while dragging some data. It installs a timeout that will expand a
2451 * node of the treeview if not expanded yet. This function also calls
2452 * gdk_drag_status in order to set the suggested action that will be
2453 * used by the "drag-data-received" signal handler to know if we
2454 * should do a move or just a copy of the data.
2457 on_drag_motion (GtkWidget *widget,
2458 GdkDragContext *context,
2464 GtkTreeViewDropPosition pos;
2465 GtkTreePath *dest_row;
2466 GtkTreeModel *dest_model;
2467 ModestFolderViewPrivate *priv;
2468 GdkDragAction suggested_action;
2469 gboolean valid_location = FALSE;
2470 TnyFolderStore *folder = NULL;
2472 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (widget);
2474 if (priv->timer_expander != 0) {
2475 g_source_remove (priv->timer_expander);
2476 priv->timer_expander = 0;
2479 gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
2484 /* Do not allow drops between folders */
2486 pos == GTK_TREE_VIEW_DROP_BEFORE ||
2487 pos == GTK_TREE_VIEW_DROP_AFTER) {
2488 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), NULL, 0);
2489 gdk_drag_status(context, 0, time);
2490 valid_location = FALSE;
2493 valid_location = TRUE;
2496 /* Check that the destination folder is writable */
2497 dest_model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
2498 folder = tree_path_to_folder (dest_model, dest_row);
2499 if (folder && TNY_IS_FOLDER (folder)) {
2500 ModestTnyFolderRules rules = modest_tny_folder_get_rules(TNY_FOLDER (folder));
2502 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
2503 valid_location = FALSE;
2508 /* Expand the selected row after 1/2 second */
2509 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), dest_row)) {
2510 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), dest_row, pos);
2511 priv->timer_expander = g_timeout_add (500, expand_row_timeout, widget);
2514 /* Select the desired action. By default we pick MOVE */
2515 suggested_action = GDK_ACTION_MOVE;
2517 if (context->actions == GDK_ACTION_COPY)
2518 gdk_drag_status(context, GDK_ACTION_COPY, time);
2519 else if (context->actions == GDK_ACTION_MOVE)
2520 gdk_drag_status(context, GDK_ACTION_MOVE, time);
2521 else if (context->actions & suggested_action)
2522 gdk_drag_status(context, suggested_action, time);
2524 gdk_drag_status(context, GDK_ACTION_DEFAULT, time);
2528 g_object_unref (folder);
2530 gtk_tree_path_free (dest_row);
2531 g_signal_stop_emission_by_name (widget, "drag-motion");
2533 return valid_location;
2537 * This function sets the treeview as a source and a target for dnd
2538 * events. It also connects all the requirede signals.
2541 setup_drag_and_drop (GtkTreeView *self)
2543 /* Set up the folder view as a dnd destination. Set only the
2544 highlight flag, otherwise gtk will have a different
2546 gtk_drag_dest_set (GTK_WIDGET (self),
2547 GTK_DEST_DEFAULT_HIGHLIGHT,
2548 folder_view_drag_types,
2549 G_N_ELEMENTS (folder_view_drag_types),
2550 GDK_ACTION_MOVE | GDK_ACTION_COPY);
2552 g_signal_connect (G_OBJECT (self),
2553 "drag_data_received",
2554 G_CALLBACK (on_drag_data_received),
2558 /* Set up the treeview as a dnd source */
2559 gtk_drag_source_set (GTK_WIDGET (self),
2561 folder_view_drag_types,
2562 G_N_ELEMENTS (folder_view_drag_types),
2563 GDK_ACTION_MOVE | GDK_ACTION_COPY);
2565 g_signal_connect (G_OBJECT (self),
2567 G_CALLBACK (on_drag_motion),
2570 g_signal_connect (G_OBJECT (self),
2572 G_CALLBACK (on_drag_data_get),
2575 g_signal_connect (G_OBJECT (self),
2577 G_CALLBACK (drag_drop_cb),
2582 * This function manages the navigation through the folders using the
2583 * keyboard or the hardware keys in the device
2586 on_key_pressed (GtkWidget *self,
2590 GtkTreeSelection *selection;
2592 GtkTreeModel *model;
2593 gboolean retval = FALSE;
2595 /* Up and Down are automatically managed by the treeview */
2596 if (event->keyval == GDK_Return) {
2597 /* Expand/Collapse the selected row */
2598 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
2599 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
2602 path = gtk_tree_model_get_path (model, &iter);
2604 if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (self), path))
2605 gtk_tree_view_collapse_row (GTK_TREE_VIEW (self), path);
2607 gtk_tree_view_expand_row (GTK_TREE_VIEW (self), path, FALSE);
2608 gtk_tree_path_free (path);
2610 /* No further processing */
2618 * We listen to the changes in the local folder account name key,
2619 * because we want to show the right name in the view. The local
2620 * folder account name corresponds to the device name in the Maemo
2621 * version. We do this because we do not want to query gconf on each
2622 * tree view refresh. It's better to cache it and change whenever
2626 on_configuration_key_changed (ModestConf* conf,
2628 ModestConfEvent event,
2629 ModestConfNotificationId id,
2630 ModestFolderView *self)
2632 ModestFolderViewPrivate *priv;
2635 g_return_if_fail (MODEST_IS_FOLDER_VIEW (self));
2636 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
2638 if (!strcmp (key, MODEST_CONF_DEVICE_NAME)) {
2639 g_free (priv->local_account_name);
2641 if (event == MODEST_CONF_EVENT_KEY_UNSET)
2642 priv->local_account_name = g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
2644 priv->local_account_name = modest_conf_get_string (modest_runtime_get_conf(),
2645 MODEST_CONF_DEVICE_NAME, NULL);
2647 /* Force a redraw */
2648 #if GTK_CHECK_VERSION(2, 8, 0)
2649 GtkTreeViewColumn * tree_column;
2651 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self),
2652 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
2653 gtk_tree_view_column_queue_resize (tree_column);
2655 gtk_widget_queue_draw (GTK_WIDGET (self));
2661 modest_folder_view_set_style (ModestFolderView *self,
2662 ModestFolderViewStyle style)
2664 ModestFolderViewPrivate *priv;
2666 g_return_if_fail (self && MODEST_IS_FOLDER_VIEW(self));
2667 g_return_if_fail (style == MODEST_FOLDER_VIEW_STYLE_SHOW_ALL ||
2668 style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE);
2670 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
2673 priv->style = style;
2677 modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *self,
2678 const gchar *account_id)
2680 ModestFolderViewPrivate *priv;
2681 GtkTreeModel *model;
2683 g_return_if_fail (self && MODEST_IS_FOLDER_VIEW(self));
2685 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
2687 /* This will be used by the filter_row callback,
2688 * to decided which rows to show: */
2689 if (priv->visible_account_id) {
2690 g_free (priv->visible_account_id);
2691 priv->visible_account_id = NULL;
2694 priv->visible_account_id = g_strdup (account_id);
2697 model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
2698 if (GTK_IS_TREE_MODEL_FILTER (model))
2699 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
2701 /* Save settings to gconf */
2702 modest_widget_memory_save (modest_runtime_get_conf (), G_OBJECT(self),
2703 MODEST_CONF_FOLDER_VIEW_KEY);
2707 modest_folder_view_get_account_id_of_visible_server_account (ModestFolderView *self)
2709 ModestFolderViewPrivate *priv;
2711 g_return_val_if_fail (self && MODEST_IS_FOLDER_VIEW(self), NULL);
2713 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
2715 return (const gchar *) priv->visible_account_id;
2719 find_inbox_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *inbox_iter)
2723 TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
2725 gtk_tree_model_get (model, iter,
2726 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN,
2729 gboolean result = FALSE;
2730 if (type == TNY_FOLDER_TYPE_INBOX) {
2734 *inbox_iter = *iter;
2738 if (gtk_tree_model_iter_children (model, &child, iter)) {
2739 if (find_inbox_iter (model, &child, inbox_iter))
2743 } while (gtk_tree_model_iter_next (model, iter));
2752 modest_folder_view_select_first_inbox_or_local (ModestFolderView *self)
2754 GtkTreeModel *model;
2755 GtkTreeIter iter, inbox_iter;
2756 GtkTreeSelection *sel;
2757 GtkTreePath *path = NULL;
2759 g_return_if_fail (self && MODEST_IS_FOLDER_VIEW(self));
2761 model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
2765 expand_root_items (self);
2766 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
2768 if (!gtk_tree_model_get_iter_first (model, &iter)) {
2769 g_warning ("%s: model is empty", __FUNCTION__);
2773 if (find_inbox_iter (model, &iter, &inbox_iter))
2774 path = gtk_tree_model_get_path (model, &inbox_iter);
2776 path = gtk_tree_path_new_first ();
2778 /* Select the row and free */
2779 gtk_tree_view_set_cursor (GTK_TREE_VIEW (self), path, NULL, FALSE);
2780 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (self), path, NULL, FALSE, 0.0, 0.0);
2781 gtk_tree_path_free (path);
2784 gtk_widget_grab_focus (GTK_WIDGET(self));
2790 find_folder_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *folder_iter,
2795 TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
2796 TnyFolder* a_folder;
2799 gtk_tree_model_get (model, iter,
2800 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &a_folder,
2801 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name,
2802 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
2806 if (folder == a_folder) {
2807 g_object_unref (a_folder);
2808 *folder_iter = *iter;
2811 g_object_unref (a_folder);
2813 if (gtk_tree_model_iter_children (model, &child, iter)) {
2814 if (find_folder_iter (model, &child, folder_iter, folder))
2818 } while (gtk_tree_model_iter_next (model, iter));
2825 on_row_inserted_maybe_select_folder (GtkTreeModel *tree_model, GtkTreePath *path, GtkTreeIter *iter,
2826 ModestFolderView *self)
2828 ModestFolderViewPrivate *priv = NULL;
2829 GtkTreeSelection *sel;
2830 TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
2831 GObject *instance = NULL;
2833 if (!MODEST_IS_FOLDER_VIEW(self))
2836 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
2838 priv->reexpand = TRUE;
2840 gtk_tree_model_get (tree_model, iter,
2841 TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
2842 TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
2844 if (type == TNY_FOLDER_TYPE_INBOX && priv->folder_to_select == NULL) {
2845 priv->folder_to_select = g_object_ref (instance);
2847 g_object_unref (instance);
2850 if (priv->folder_to_select) {
2852 if (!modest_folder_view_select_folder (self, priv->folder_to_select,
2855 path = gtk_tree_model_get_path (tree_model, iter);
2856 gtk_tree_view_expand_to_path (GTK_TREE_VIEW(self), path);
2858 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
2860 gtk_tree_selection_select_iter (sel, iter);
2861 gtk_tree_view_set_cursor (GTK_TREE_VIEW(self), path, NULL, FALSE);
2863 gtk_tree_path_free (path);
2868 modest_folder_view_disable_next_folder_selection (self);
2869 /* g_object_unref (priv->folder_to_select); */
2870 /* priv->folder_to_select = NULL; */
2872 /* Refilter the model */
2873 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (tree_model));
2879 modest_folder_view_disable_next_folder_selection (ModestFolderView *self)
2881 ModestFolderViewPrivate *priv;
2883 g_return_if_fail (self && MODEST_IS_FOLDER_VIEW(self));
2885 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
2887 if (priv->folder_to_select)
2888 g_object_unref(priv->folder_to_select);
2890 priv->folder_to_select = NULL;
2894 modest_folder_view_select_folder (ModestFolderView *self, TnyFolder *folder,
2895 gboolean after_change)
2897 GtkTreeModel *model;
2898 GtkTreeIter iter, folder_iter;
2899 GtkTreeSelection *sel;
2900 ModestFolderViewPrivate *priv = NULL;
2902 g_return_val_if_fail (self && MODEST_IS_FOLDER_VIEW (self), FALSE);
2903 g_return_val_if_fail (folder && TNY_IS_FOLDER (folder), FALSE);
2905 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
2908 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
2909 gtk_tree_selection_unselect_all (sel);
2911 if (priv->folder_to_select)
2912 g_object_unref(priv->folder_to_select);
2913 priv->folder_to_select = TNY_FOLDER(g_object_ref(folder));
2917 model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
2922 /* Refilter the model, before selecting the folder */
2923 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
2925 if (!gtk_tree_model_get_iter_first (model, &iter)) {
2926 g_warning ("%s: model is empty", __FUNCTION__);
2930 if (find_folder_iter (model, &iter, &folder_iter, folder)) {
2933 path = gtk_tree_model_get_path (model, &folder_iter);
2934 gtk_tree_view_expand_to_path (GTK_TREE_VIEW(self), path);
2936 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
2937 gtk_tree_selection_select_iter (sel, &folder_iter);
2938 gtk_tree_view_set_cursor (GTK_TREE_VIEW(self), path, NULL, FALSE);
2940 gtk_tree_path_free (path);
2948 modest_folder_view_copy_selection (ModestFolderView *self)
2950 g_return_if_fail (self && MODEST_IS_FOLDER_VIEW(self));
2952 /* Copy selection */
2953 _clipboard_set_selected_data (self, FALSE);
2957 modest_folder_view_cut_selection (ModestFolderView *folder_view)
2959 ModestFolderViewPrivate *priv = NULL;
2960 GtkTreeModel *model = NULL;
2961 const gchar **hidding = NULL;
2962 guint i, n_selected;
2964 g_return_if_fail (folder_view && MODEST_IS_FOLDER_VIEW (folder_view));
2965 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (folder_view);
2967 /* Copy selection */
2968 if (!_clipboard_set_selected_data (folder_view, TRUE))
2971 /* Get hidding ids */
2972 hidding = modest_email_clipboard_get_hidding_ids (priv->clipboard, &n_selected);
2974 /* Clear hidding array created by previous cut operation */
2975 _clear_hidding_filter (MODEST_FOLDER_VIEW (folder_view));
2977 /* Copy hidding array */
2978 priv->n_selected = n_selected;
2979 priv->hidding_ids = g_malloc0(sizeof(gchar *) * n_selected);
2980 for (i=0; i < n_selected; i++)
2981 priv->hidding_ids[i] = g_strdup(hidding[i]);
2983 /* Hide cut folders */
2984 model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view));
2985 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
2989 modest_folder_view_copy_model (ModestFolderView *folder_view_src,
2990 ModestFolderView *folder_view_dst)
2992 GtkTreeModel *filter_model = NULL;
2993 GtkTreeModel *model = NULL;
2994 GtkTreeModel *new_filter_model = NULL;
2996 g_return_if_fail (folder_view_src && MODEST_IS_FOLDER_VIEW (folder_view_src));
2997 g_return_if_fail (folder_view_dst && MODEST_IS_FOLDER_VIEW (folder_view_dst));
3000 filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view_src));
3001 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter_model));
3003 /* Build new filter model */
3004 new_filter_model = gtk_tree_model_filter_new (model, NULL);
3005 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (new_filter_model),
3009 /* Set copied model */
3010 gtk_tree_view_set_model (GTK_TREE_VIEW (folder_view_dst), new_filter_model);
3011 g_signal_connect (G_OBJECT(new_filter_model), "row-inserted",
3012 (GCallback) on_row_inserted_maybe_select_folder, folder_view_dst);
3015 g_object_unref (new_filter_model);
3019 modest_folder_view_show_non_move_folders (ModestFolderView *folder_view,
3022 GtkTreeModel *model = NULL;
3023 ModestFolderViewPrivate* priv;
3025 g_return_if_fail (folder_view && MODEST_IS_FOLDER_VIEW (folder_view));
3027 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(folder_view);
3028 priv->show_non_move = show;
3029 /* modest_folder_view_update_model(folder_view, */
3030 /* TNY_ACCOUNT_STORE(modest_runtime_get_account_store())); */
3032 /* Hide special folders */
3033 model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view));
3034 if (GTK_IS_TREE_MODEL_FILTER (model)) {
3035 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
3039 /* Returns FALSE if it did not selected anything */
3041 _clipboard_set_selected_data (ModestFolderView *folder_view,
3044 ModestFolderViewPrivate *priv = NULL;
3045 TnyFolderStore *folder = NULL;
3046 gboolean retval = FALSE;
3048 g_return_val_if_fail (MODEST_IS_FOLDER_VIEW (folder_view), FALSE);
3049 priv = MODEST_FOLDER_VIEW_GET_PRIVATE (folder_view);
3051 /* Set selected data on clipboard */
3052 g_return_val_if_fail (MODEST_IS_EMAIL_CLIPBOARD (priv->clipboard), FALSE);
3053 folder = modest_folder_view_get_selected (folder_view);
3055 /* Do not allow to select an account */
3056 if (TNY_IS_FOLDER (folder)) {
3057 modest_email_clipboard_set_data (priv->clipboard, TNY_FOLDER(folder), NULL, delete);
3062 g_object_unref (folder);
3068 _clear_hidding_filter (ModestFolderView *folder_view)
3070 ModestFolderViewPrivate *priv;
3073 g_return_if_fail (MODEST_IS_FOLDER_VIEW (folder_view));
3074 priv = MODEST_FOLDER_VIEW_GET_PRIVATE(folder_view);
3076 if (priv->hidding_ids != NULL) {
3077 for (i=0; i < priv->n_selected; i++)
3078 g_free (priv->hidding_ids[i]);
3079 g_free(priv->hidding_ids);
3085 on_display_name_changed (ModestAccountMgr *mgr,
3086 const gchar *account,
3089 ModestFolderView *self;
3091 self = MODEST_FOLDER_VIEW (user_data);
3093 /* Force a redraw */
3094 #if GTK_CHECK_VERSION(2, 8, 0)
3095 GtkTreeViewColumn * tree_column;
3097 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self),
3098 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
3099 gtk_tree_view_column_queue_resize (tree_column);
3101 gtk_widget_queue_draw (GTK_WIDGET (self));