Add mail operation tracking for progress hint in folder window
[modest] / src / hildon2 / modest-folder-window.c
index 2b3c11a..7598025 100644 (file)
 #include <modest-window.h>
 #include <hildon/hildon-program.h>
 #include <hildon/hildon-banner.h>
+#include <hildon/hildon-button.h>
 #include <tny-account-store-view.h>
 #include <modest-header-window.h>
+#include <modest-ui-dimming-rules.h>
+#include <modest-ui-dimming-manager.h>
+#include <modest-window-priv.h>
+#include "modest-text-utils.h"
+#include "modest-tny-account.h"
+
+typedef enum {
+       EDIT_MODE_COMMAND_MOVE = 1,
+       EDIT_MODE_COMMAND_DELETE = 2,
+       EDIT_MODE_COMMAND_RENAME = 3,
+} EditModeCommand;
 
 /* 'private'/'protected' functions */
 static void modest_folder_window_class_init  (ModestFolderWindowClass *klass);
@@ -56,26 +68,48 @@ static void modest_folder_window_finalize    (GObject *obj);
 static void connect_signals (ModestFolderWindow *self);
 static void modest_folder_window_disconnect_signals (ModestWindow *self);
 
-static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window);
 static void on_folder_activated (ModestFolderView *folder_view,
                                 TnyFolder *folder,
                                 gpointer userdata);
-static void add_to_menu (ModestFolderWindow *self,
-                        HildonAppMenu *menu,
-                        gchar *label,
-                        GCallback callback);
 static void setup_menu (ModestFolderWindow *self);
 
+static void set_delete_edit_mode (GtkButton *button,
+                                 ModestFolderWindow *self);
+static void set_moveto_edit_mode (GtkButton *button,
+                                 ModestFolderWindow *self);
+static void set_rename_edit_mode (GtkButton *button,
+                                 ModestFolderWindow *self);
+static void modest_folder_window_pack_toolbar (ModestHildon2Window *self,
+                                              GtkPackType pack_type,
+                                              GtkWidget *toolbar);
+static void edit_mode_changed (ModestFolderWindow *folder_window,
+                              gint edit_mode_id,
+                              gboolean enabled,
+                              ModestFolderWindow *self);
+static void on_progress_list_changed (ModestWindowMgr *mgr,
+                                     ModestFolderWindow *self);
+static gboolean on_map_event (GtkWidget *widget,
+                             GdkEvent *event,
+                             gpointer userdata);
+static void update_progress_hint (ModestFolderWindow *self);
+static void on_queue_changed    (ModestMailOperationQueue *queue,
+                                ModestMailOperation *mail_op,
+                                ModestMailOperationQueueNotification type,
+                                ModestFolderWindow *self);
+
 typedef struct _ModestFolderWindowPrivate ModestFolderWindowPrivate;
 struct _ModestFolderWindowPrivate {
 
        GtkWidget *folder_view;
+       GtkWidget *top_vbox;
+       GtkWidget *new_message_button;
 
        /* signals */
        GSList *sighandlers;
 
-       /* Display state */
-       osso_display_state_t display_state;
+       gchar *current_store_account;
+       gboolean progress_hint;
+       guint queue_change_handler;
 };
 #define MODEST_FOLDER_WINDOW_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                                          MODEST_TYPE_FOLDER_WINDOW, \
@@ -103,7 +137,7 @@ modest_folder_window_get_type (void)
                        (GInstanceInitFunc) modest_folder_window_init,
                        NULL
                };
-               my_type = g_type_register_static (MODEST_TYPE_WINDOW,
+               my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
                                                  "ModestFolderWindow",
                                                  &my_info, 0);
        }
@@ -116,15 +150,15 @@ modest_folder_window_class_init (ModestFolderWindowClass *klass)
        GObjectClass *gobject_class;
        gobject_class = (GObjectClass*) klass;
        ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
+       ModestHildon2WindowClass *modest_hildon2_window_class = (ModestHildon2WindowClass *) klass;
 
        parent_class            = g_type_class_peek_parent (klass);
        gobject_class->finalize = modest_folder_window_finalize;
 
        g_type_class_add_private (gobject_class, sizeof(ModestFolderWindowPrivate));
        
-       modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented;
-       modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented;
        modest_window_class->disconnect_signals_func = modest_folder_window_disconnect_signals;
+       modest_hildon2_window_class->pack_toolbar_func = modest_folder_window_pack_toolbar;
 }
 
 static void
@@ -135,13 +169,17 @@ modest_folder_window_init (ModestFolderWindow *obj)
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
 
        priv->sighandlers = NULL;
-       priv->display_state = OSSO_DISPLAY_ON;
        
        priv->folder_view = NULL;
-       
+
+       priv->top_vbox = NULL;
+
        modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
                                            GTK_WINDOW(obj),
                                            "applications_email_folderview");
+       priv->progress_hint = FALSE;
+       priv->current_store_account = NULL;
+       priv->queue_change_handler = 0;
 }
 
 static void
@@ -151,6 +189,11 @@ modest_folder_window_finalize (GObject *obj)
 
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
 
+       if (priv->current_store_account) {
+               g_free (priv->current_store_account);
+               priv->current_store_account = NULL;
+       }
+
        /* Sanity check: shouldn't be needed, the window mgr should
           call this function before */
        modest_folder_window_disconnect_signals (MODEST_WINDOW (obj));  
@@ -160,19 +203,63 @@ modest_folder_window_finalize (GObject *obj)
 
 static void
 modest_folder_window_disconnect_signals (ModestWindow *self)
-{      
-       ModestFolderWindowPrivate *priv;        
+{
+       ModestFolderWindowPrivate *priv;
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
 
+       if (g_signal_handler_is_connected (G_OBJECT (modest_runtime_get_mail_operation_queue ()), 
+                                          priv->queue_change_handler))
+               g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()), 
+                                            priv->queue_change_handler);
+
        modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
-       priv->sighandlers = NULL;       
+       priv->sighandlers = NULL;
+}
+
+static void
+on_visible_account_changed (ModestFolderView *folder_view,
+                           const gchar *account_id,
+                           gpointer user_data)
+{
+       if (account_id) {
+               TnyAccount *acc = 
+                       modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
+                                                                    MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
+                                                                    account_id);
+               if (acc) {
+                       const gchar *name;
+                       const gchar *mailbox;
+                       gchar *title = NULL;
+                       ModestFolderWindowPrivate *priv;
+
+                       priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (user_data);
+
+                       mailbox = modest_folder_view_get_mailbox (MODEST_FOLDER_VIEW (priv->folder_view));
+                       if (mailbox) {
+                               title = g_strdup (mailbox);
+                       } else {
+                               name = modest_tny_account_get_parent_modest_account_name_for_server_account (acc);
+                               title = modest_account_mgr_get_display_name (modest_runtime_get_account_mgr(),
+                                                                            name);
+                       }
+                       if (title) {
+                               gtk_window_set_title (GTK_WINDOW (user_data), title);
+                               g_free (title);
+                       } else {
+                               gtk_window_set_title (GTK_WINDOW (user_data), _("mcen_ap_name"));
+                       }
+                       g_object_unref (acc);
+               }
+       } else {
+               gtk_window_set_title (GTK_WINDOW (user_data), _("mcen_ap_name"));
+       }
 }
 
 static void
 connect_signals (ModestFolderWindow *self)
-{      
+{
        ModestFolderWindowPrivate *priv;
-       
+
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
 
        /* folder view */
@@ -180,27 +267,22 @@ connect_signals (ModestFolderWindow *self)
                                                       G_OBJECT (priv->folder_view), "folder-activated", 
                                                       G_CALLBACK (on_folder_activated), self);
 
-       /* TODO: connect folder view activate */
-       
-       /* window */
+       priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
+                                                      G_OBJECT (modest_runtime_get_window_mgr ()),
+                                                      "progress-list-changed",
+                                                      G_CALLBACK (on_progress_list_changed), self);
 
-       /* we don't register this in sighandlers, as it should be run after disconnecting all signals,
-        * in destroy stage */
+       priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
+                                                      G_OBJECT (priv->folder_view),
+                                                      "visible-account-changed",
+                                                      G_CALLBACK (on_visible_account_changed), self);
 
-       
-}
+       priv->sighandlers = 
+               modest_signal_mgr_connect (priv->sighandlers,
+                                          G_OBJECT (priv->new_message_button),
+                                          "clicked",
+                                          G_CALLBACK (modest_ui_actions_on_new_msg), self);
 
-static void 
-osso_display_event_cb (osso_display_state_t state, 
-                      gpointer data)
-{
-       ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (data);
-
-       priv->display_state = state;
-
-       /* Stop blinking if the screen becomes on */
-       if (priv->display_state == OSSO_DISPLAY_ON)
-               modest_platform_remove_new_mail_notifications (TRUE);
 }
 
 ModestWindow *
@@ -211,25 +293,66 @@ modest_folder_window_new (TnyFolderStoreQuery *query)
        HildonProgram *app;
        GdkPixbuf *window_icon;
        GtkWidget *pannable;
+       GtkWidget *action_area_box;
+       GdkPixbuf *new_message_pixbuf;
+       guint accel_key;
+       GdkModifierType accel_mods;
+       GtkAccelGroup *accel_group;
+       GtkWidget *top_alignment;
        
        self  = MODEST_FOLDER_WINDOW(g_object_new(MODEST_TYPE_FOLDER_WINDOW, NULL));
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
+
        pannable = hildon_pannable_area_new ();
+
+       priv->queue_change_handler =
+               g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
+                                 "queue-changed",
+                                 G_CALLBACK (on_queue_changed),
+                                 self);
+
        priv->folder_view  = modest_platform_create_folder_view (query);
        modest_folder_view_set_cell_style (MODEST_FOLDER_VIEW (priv->folder_view),
                                           MODEST_FOLDER_VIEW_CELL_STYLE_COMPACT);
+       modest_folder_view_set_filter (MODEST_FOLDER_VIEW (priv->folder_view), 
+                                      MODEST_FOLDER_VIEW_FILTER_HIDE_ACCOUNTS);
+
+       g_signal_connect (G_OBJECT (self), "edit-mode-changed",
+                         G_CALLBACK (edit_mode_changed), (gpointer) self);
+
+       action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->folder_view));
+       priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
+
+       hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
+       new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
+       hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
+       g_object_unref (new_message_pixbuf);
 
+       gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
+       gtk_widget_show_all (priv->new_message_button);
+       hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->folder_view), TRUE);
+       
        setup_menu (self);
 
        /* Set account store */
        tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
                                                  TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
 
+       priv->top_vbox = gtk_vbox_new (0, FALSE);
+       top_alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (top_alignment),
+                                  0, 0,
+                                  HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DOUBLE);
+
        gtk_container_add (GTK_CONTAINER (pannable), priv->folder_view);
-       gtk_container_add (GTK_CONTAINER (self), pannable);
+       gtk_container_add (GTK_CONTAINER (top_alignment), pannable);
+       gtk_box_pack_end (GTK_BOX (priv->top_vbox), top_alignment, TRUE, TRUE, 0);
+       gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
 
        gtk_widget_show (priv->folder_view);
        gtk_widget_show (pannable);
+       gtk_widget_show (priv->top_vbox);
+       gtk_widget_show (top_alignment);
 
        connect_signals (MODEST_FOLDER_WINDOW (self));
 
@@ -250,41 +373,47 @@ modest_folder_window_new (TnyFolderStoreQuery *query)
                g_object_unref (window_icon);
        }
 
-       /* Listen for changes in the screen, we don't want to show a
-          led pattern when the display is on for example */
-       osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (),
-                                     osso_display_event_cb,
-                                     self); 
-
        /* Dont't restore settings here, 
         * because it requires a gtk_widget_show(), 
         * and we don't want to do that until later,
         * so that the UI is not visible for non-menu D-Bus activation.
         */
 
-       return MODEST_WINDOW(self);
-}
-
-static gboolean
-on_zoom_minus_plus_not_implemented (ModestWindow *window)
-{
-       g_return_val_if_fail (MODEST_IS_FOLDER_WINDOW (window), FALSE);
-
-       hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
-       return FALSE;
-
-}
-
-gboolean
-modest_folder_window_screen_is_on (ModestFolderWindow *self)
-{
-       ModestFolderWindowPrivate *priv = NULL;
+       /* Register edit modes */
+       modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), 
+                                                 EDIT_MODE_COMMAND_DELETE,
+                                                 _("mcen_ti_edit_folder_delete"), 
+                                                 _HL("wdgt_bd_delete"),
+                                                 GTK_TREE_VIEW (priv->folder_view),
+                                                 GTK_SELECTION_SINGLE,
+                                                 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_delete_folder));
+       modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), 
+                                                 EDIT_MODE_COMMAND_MOVE,
+                                                 _("mcen_ti_edit_move_folder"), 
+                                                 _HL("wdgt_bd_move"),
+                                                 GTK_TREE_VIEW (priv->folder_view),
+                                                 GTK_SELECTION_SINGLE,
+                                                 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_move_to)); 
+       modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), 
+                                                 EDIT_MODE_COMMAND_RENAME,
+                                                 _("mcen_ti_edit_rename_folder"), 
+                                                 _HL("wdgt_bd_rename"),
+                                                 GTK_TREE_VIEW (priv->folder_view),
+                                                 GTK_SELECTION_SINGLE,
+                                                 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_rename_folder));
+       
+       g_signal_connect (G_OBJECT (self), "map-event",
+                         G_CALLBACK (on_map_event),
+                         G_OBJECT (self));
+       update_progress_hint (self);
 
-       g_return_val_if_fail (MODEST_IS_FOLDER_WINDOW(self), FALSE);
+       accel_group = gtk_accel_group_new ();
+       gtk_accelerator_parse ("<Control>n", &accel_key, &accel_mods);
+       gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group,
+                                   accel_key, accel_mods, 0);
+       gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
 
-       priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
-       
-       return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE;
+       return MODEST_WINDOW(self);
 }
 
 ModestFolderView *
@@ -311,7 +440,7 @@ modest_folder_window_set_account (ModestFolderWindow *self,
        g_return_if_fail (MODEST_IS_FOLDER_WINDOW(self));
 
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
-       
+
        /* Get account data */
        mgr = modest_runtime_get_account_mgr ();
 
@@ -323,78 +452,67 @@ modest_folder_window_set_account (ModestFolderWindow *self,
        if (!store_settings)
                goto free_refs;
 
-       modest_folder_view_set_account_id_of_visible_server_account 
+       if (priv->current_store_account != NULL)
+               g_free (priv->current_store_account);
+       priv->current_store_account = g_strdup (modest_server_account_settings_get_account_name (store_settings));
+
+       modest_folder_view_set_account_id_of_visible_server_account
                (MODEST_FOLDER_VIEW (priv->folder_view),
-                modest_server_account_settings_get_account_name (store_settings));
+                priv->current_store_account);
 
        modest_window_set_active_account (MODEST_WINDOW (self), account_name);
-       gtk_window_set_title (GTK_WINDOW (self), 
-                             modest_account_settings_get_display_name (settings));
+       update_progress_hint (self);
 
 free_refs:
-       if (store_settings) 
+       if (store_settings)
                g_object_unref (store_settings);
        if (settings)
                g_object_unref (settings);
 
 }
 
-static void add_to_menu (ModestFolderWindow *self,
-                        HildonAppMenu *menu,
-                        gchar *label,
-                        GCallback callback)
-{
-       GtkWidget *button;
-
-       button = gtk_button_new_with_label (label);
-       g_signal_connect_after (G_OBJECT (button), "clicked",
-                               callback, (gpointer) self);
-       hildon_app_menu_append (menu, GTK_BUTTON (button));
-}
-
-static void setup_menu (ModestFolderWindow *self)
+void
+modest_folder_window_set_mailbox (ModestFolderWindow *self,
+                                 const gchar *mailbox)
 {
        ModestFolderWindowPrivate *priv = NULL;
-       GtkWidget *app_menu;
 
        g_return_if_fail (MODEST_IS_FOLDER_WINDOW(self));
-
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
 
-       app_menu = hildon_app_menu_new ();
+       modest_folder_view_set_mailbox (MODEST_FOLDER_VIEW (priv->folder_view), mailbox);
+
+}
+
+static void
+setup_menu (ModestFolderWindow *self)
+{
+       g_return_if_fail (MODEST_IS_FOLDER_WINDOW(self));
 
        /* folders actions */
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("TODO: new folder"),
-                    G_CALLBACK (modest_ui_actions_on_new_folder));
-/*     add_to_menu (self, HILDON_APP_MENU (app_menu), _("mcen_me_user_renamefolder"), */
-/*                  G_CALLBACK ()); */
-/*     add_to_menu (self, HILDON_APP_MENU (app_menu), _("TODO: move folder"), */
-/*                  G_CALLBACK ()); */
-/*     add_to_menu (self, HILDON_APP_MENU (app_menu), _("TODO: delete folder"), */
-/*                  G_CALLBACK ()); */
-
-       /* new message */
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("mcen_me_viewer_newemail"),
-                    G_CALLBACK (modest_ui_actions_on_new_msg));
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_folder"), NULL,
+                                          APP_MENU_CALLBACK (modest_ui_actions_on_new_folder),
+                                          NULL);
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_rename_folder"), NULL,
+                                          APP_MENU_CALLBACK (set_rename_edit_mode),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_rename_folder));
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_move_folder"), NULL,
+                                          APP_MENU_CALLBACK (set_moveto_edit_mode),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_folder_window_move_to));
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_delete_folder"), NULL,
+                                          APP_MENU_CALLBACK (set_delete_edit_mode),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_folder_window_delete));
 
        /* send receive actions should be only one visible always */
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("mcen_me_inbox_sendandreceive"),
-                    G_CALLBACK (modest_ui_actions_on_send_receive));
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("mcen_me_outbox_cancelsend"),
-                    G_CALLBACK (modest_ui_actions_cancel_send));
-
-       /* Settings menu buttons */
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("TODO: new account"),
-                    G_CALLBACK (modest_ui_actions_on_new_account));
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("TODO: edit accounts"),
-                    G_CALLBACK (modest_ui_actions_on_accounts));
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("mcen_me_inbox_options"),
-                    G_CALLBACK (modest_ui_actions_on_settings));
-       add_to_menu (self, HILDON_APP_MENU (app_menu), _("mcen_me_inbox_globalsmtpservers"),
-                    G_CALLBACK (modest_ui_actions_on_smtp_servers));
-       
-       hildon_stackable_window_set_main_menu (HILDON_STACKABLE_WINDOW (self), 
-                                              HILDON_APP_MENU (app_menu));
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), 
+                                          _("mcen_me_inbox_sendandreceive"), 
+                                          NULL,
+                                          APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive));
+
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
+                                          APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
 }
 
 static void
@@ -416,12 +534,245 @@ on_folder_activated (ModestFolderView *folder_view,
        if (!TNY_IS_FOLDER (folder))
                return;
 
-       headerwin = modest_header_window_new (folder);
-       modest_window_mgr_register_window (modest_runtime_get_window_mgr (), 
-                                          MODEST_WINDOW (headerwin),
-                                          MODEST_WINDOW (self));
+       /* We cannot open noselect folders (fake ones) */
+       if (tny_folder_get_caps (folder) & TNY_FOLDER_CAPS_NOSELECT)
+               return;
+
+       headerwin = modest_header_window_new (folder, modest_window_get_active_account (MODEST_WINDOW (self)));
+
+       if (modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
+                                              MODEST_WINDOW (headerwin),
+                                              MODEST_WINDOW (self))) {
+               gtk_widget_show (GTK_WIDGET (headerwin));
+       } else {
+               gtk_widget_destroy (GTK_WIDGET (headerwin));
+               headerwin = NULL;
+       }
+}
+
+static void
+set_delete_edit_mode (GtkButton *button,
+                     ModestFolderWindow *self)
+{
+       modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE);
+}
 
-       modest_window_set_active_account (MODEST_WINDOW (headerwin), 
-                                         modest_window_get_active_account (MODEST_WINDOW (self)));
-       gtk_widget_show (GTK_WIDGET (headerwin));
+static void
+set_moveto_edit_mode (GtkButton *button,
+                     ModestFolderWindow *self)
+{
+       modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE);
 }
+
+static void
+set_rename_edit_mode (GtkButton *button,
+                     ModestFolderWindow *self)
+{
+       modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_RENAME);
+}
+
+static void
+modest_folder_window_pack_toolbar (ModestHildon2Window *self,
+                                  GtkPackType pack_type,
+                                  GtkWidget *toolbar)
+{
+       ModestFolderWindowPrivate *priv;
+
+       g_return_if_fail (MODEST_IS_FOLDER_WINDOW (self));
+       priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
+
+       if (pack_type == GTK_PACK_START) {
+               gtk_box_pack_start (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
+       } else {
+               gtk_box_pack_end (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
+       }
+}
+
+static void 
+edit_mode_changed (ModestFolderWindow *folder_window,
+                  gint edit_mode_id,
+                  gboolean enabled,
+                  ModestFolderWindow *self)
+{
+       ModestFolderWindowPrivate *priv;
+       ModestFolderViewFilter filter = MODEST_FOLDER_VIEW_FILTER_NONE;
+
+       g_return_if_fail (MODEST_IS_FOLDER_WINDOW (self));
+       priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
+
+       switch (edit_mode_id) {
+       case EDIT_MODE_COMMAND_MOVE:
+               filter = MODEST_FOLDER_VIEW_FILTER_MOVEABLE;
+               break;
+       case EDIT_MODE_COMMAND_DELETE:
+               filter = MODEST_FOLDER_VIEW_FILTER_DELETABLE;
+               break;
+       case EDIT_MODE_COMMAND_RENAME:
+               filter = MODEST_FOLDER_VIEW_FILTER_RENAMEABLE;
+               break;
+       case MODEST_HILDON2_WINDOW_EDIT_MODE_NONE:
+               filter = MODEST_FOLDER_VIEW_FILTER_NONE;
+               break;
+       }
+
+       hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->folder_view), !enabled);
+       if (enabled) {
+               modest_folder_view_set_filter (MODEST_FOLDER_VIEW (priv->folder_view), 
+                                              filter);
+       } else {
+               GtkTreeSelection *sel;
+
+               /* Unselect all. This will prevent us from keeping a
+                  reference to a TnyObject that we don't want to
+                  have */
+               sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->folder_view));
+               gtk_tree_selection_unselect_all (sel);
+
+               modest_folder_view_unset_filter (MODEST_FOLDER_VIEW (priv->folder_view), 
+                                                filter);
+       }
+}
+
+static gboolean 
+on_map_event (GtkWidget *widget,
+             GdkEvent *event,
+             gpointer userdata)
+{
+       ModestFolderWindow *self = (ModestFolderWindow *) userdata;
+       ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
+
+       if (priv->progress_hint) {
+               hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
+       }
+
+       return FALSE;
+}
+
+static gboolean
+has_active_operations (ModestFolderWindow *self)
+{
+       GSList *operations = NULL, *node;
+       ModestMailOperationQueue *queue;
+       gboolean has_active = FALSE;
+
+       queue = modest_runtime_get_mail_operation_queue ();
+       operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
+
+       for (node = operations; node != NULL; node = g_slist_next (node)) {
+               if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
+                       has_active = TRUE;
+                       break;
+               }
+       }
+
+       if (operations) {
+               g_slist_foreach (operations, (GFunc) g_object_unref, NULL);
+               g_slist_free (operations);
+       }
+
+       return has_active;
+}
+
+static void
+update_progress_hint (ModestFolderWindow *self)
+{
+       ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
+
+       if (has_active_operations (self)) {
+               priv->progress_hint = TRUE;
+       }
+
+       if (!priv->progress_hint && priv->current_store_account) {
+               priv->progress_hint = modest_window_mgr_has_progress_operation_on_account (modest_runtime_get_window_mgr (),
+                                                                                          priv->current_store_account);
+       }
+
+       modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
+
+       if (GTK_WIDGET_VISIBLE (self)) {
+               hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint ? 1:0);
+       }
+}
+
+static void
+on_progress_list_changed (ModestWindowMgr *mgr,
+                         ModestFolderWindow *self)
+{
+       update_progress_hint (self);
+}
+
+gboolean
+modest_folder_window_transfer_mode_enabled (ModestFolderWindow *self)
+{
+       ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
+
+       return priv->progress_hint;
+}
+
+static void 
+on_mail_operation_started (ModestMailOperation *mail_op,
+                          gpointer user_data)
+{
+       ModestFolderWindow *self;
+       ModestMailOperationTypeOperation op_type;
+       GObject *source = NULL;
+
+       self = MODEST_FOLDER_WINDOW (user_data);
+       op_type = modest_mail_operation_get_type_operation (mail_op);
+       source = modest_mail_operation_get_source(mail_op);
+       if (G_OBJECT (self) == source) {
+               update_progress_hint (self);
+       }
+       g_object_unref (source);
+}
+
+static void 
+on_mail_operation_finished (ModestMailOperation *mail_op,
+                           gpointer user_data)
+{
+       ModestFolderWindow *self;
+
+       self = MODEST_FOLDER_WINDOW (user_data);
+
+       /* Don't disable the progress hint if there are more pending
+          operations from this window */
+       update_progress_hint (self);
+
+       modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
+}
+
+static void
+on_queue_changed (ModestMailOperationQueue *queue,
+                 ModestMailOperation *mail_op,
+                 ModestMailOperationQueueNotification type,
+                 ModestFolderWindow *self)
+{
+       ModestFolderWindowPrivate *priv;
+
+       priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
+
+       /* If this operations was created by another window, do nothing */
+       if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self))) 
+               return;
+
+       if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
+               priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
+                                                              G_OBJECT (mail_op),
+                                                              "operation-started",
+                                                              G_CALLBACK (on_mail_operation_started),
+                                                              self);
+               priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
+                                                              G_OBJECT (mail_op),
+                                                              "operation-finished",
+                                                              G_CALLBACK (on_mail_operation_finished),
+                                                              self);
+       } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
+               priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
+                                                                 G_OBJECT (mail_op),
+                                                                 "operation-started");
+               priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
+                                                                 G_OBJECT (mail_op),
+                                                                 "operation-finished");
+       }
+}
+