Move asdbus stuff to src/hildon2, as it's hildon/maemo specific.
[modest] / src / hildon2 / modest-header-window.c
index 30816a3..92ad0cb 100644 (file)
 #include <modest-ui-actions.h>
 #include <modest-platform.h>
 #include <modest-text-utils.h>
-#include <hildon/hildon-button.h>
-#include <hildon/hildon-program.h>
-#include <hildon/hildon-banner.h>
+#include <hildon/hildon.h>
 #include <modest-ui-dimming-rules.h>
 #include <modest-tny-folder.h>
+#include <modest-tny-account.h>
 #include <tny-simple-list.h>
+#include <gdk/gdkkeysyms.h>
 
 #define SHOW_LATEST_SIZE 250
 
@@ -74,7 +74,6 @@ struct _ModestHeaderWindowPrivate {
        GtkWidget *top_vbox;
        GtkWidget *new_message_button;
        GtkWidget *show_more_button;
-       GtkWidget *show_more_button2;
 
        /* state bar */
        ContentsState contents_state;
@@ -89,16 +88,12 @@ struct _ModestHeaderWindowPrivate {
        /* signals */
        GSList *sighandlers;
        gulong queue_change_handler;
-       gulong sort_column_handler;
        gulong notify_model;
 
        /* progress hint */
        gboolean progress_hint;
        gchar *current_store_account;
 
-       /* sort button */
-       GtkWidget *sort_button;
-
        /* CSM menu */
        GtkWidget *csm_menu;
        gdouble x_coord;
@@ -106,6 +101,9 @@ struct _ModestHeaderWindowPrivate {
 
        /* weak refs */
        GtkTreeModel *model_weak_ref;
+
+       gboolean limit_headers;
+       GtkWidget   *isearch_toolbar;
 };
 #define MODEST_HEADER_WINDOW_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                                          MODEST_TYPE_HEADER_WINDOW, \
@@ -168,9 +166,6 @@ static void edit_mode_changed (ModestHeaderWindow *header_window,
 static void on_progress_list_changed (ModestWindowMgr *mgr,
                                      ModestHeaderWindow *self);
 static void update_progress_hint (ModestHeaderWindow *self);
-static void on_sort_column_changed (GtkTreeSortable *treesortable,
-                                   gpointer         user_data);
-static void update_sort_button (ModestHeaderWindow *self);
 static void on_horizontal_movement (HildonPannableArea *hildonpannable,
                                    gint                direction,
                                    gdouble             initial_x,
@@ -183,6 +178,17 @@ static gboolean on_key_press(GtkWidget *widget,
                                        gpointer user_data);
 static void modest_header_window_show_more (GtkAction *action, ModestWindow *win);
 
+static void  isearch_toolbar_close  (GtkWidget *widget,
+                                    ModestHeaderWindow *obj);
+static void  isearch_toolbar_search (GtkWidget *widget,
+                                    ModestHeaderWindow *obj);
+#ifndef MODEST_TOOLKIT_HILDON2
+static void  show_isearch_toolbar   (GtkWidget *obj, gpointer data);
+static void  toggle_isearch_toolbar (GtkWidget *obj,
+                                    gpointer data);
+#endif
+
+
 /* globals */
 static GtkWindowClass *parent_class = NULL;
 
@@ -256,16 +262,14 @@ modest_header_window_init (ModestHeaderWindow *obj)
        priv->autoscroll = TRUE;
        priv->progress_hint = FALSE;
        priv->queue_change_handler = 0;
-       priv->sort_column_handler = 0;
        priv->model_weak_ref = NULL;
        priv->current_store_account = NULL;
-       priv->sort_button = NULL;
        priv->new_message_button = NULL;
        priv->show_more_button = NULL;
-       priv->show_more_button2 = NULL;
        priv->x_coord = 0;
        priv->y_coord = 0;
        priv->notify_model = 0;
+       priv->limit_headers = FALSE;
 
        modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
                                            GTK_WINDOW(obj),
@@ -282,7 +286,7 @@ modest_header_window_dispose (GObject *obj)
 
        folder = modest_header_view_get_folder ((ModestHeaderView *) priv->header_view);
        if (folder) {
-               tny_folder_sync_async (folder, FALSE, NULL, NULL, NULL);
+               tny_folder_sync_async (folder, TRUE, NULL, NULL, NULL);
                g_object_unref (folder);
        }
 
@@ -300,11 +304,6 @@ modest_header_window_finalize (GObject *obj)
                g_object_weak_unref ((GObject *) priv->model_weak_ref,
                                     on_header_view_model_destroyed,
                                     obj);
-               if (g_signal_handler_is_connected (G_OBJECT (priv->model_weak_ref),
-                                                  priv->sort_column_handler)) {
-                       g_signal_handler_disconnect (G_OBJECT (priv->model_weak_ref),
-                                                    priv->sort_column_handler);
-               }
                on_header_view_model_destroyed (obj, (GObject *) priv->model_weak_ref);
        }
 
@@ -349,20 +348,6 @@ modest_header_window_disconnect_signals (ModestWindow *self)
                priv->queue_change_handler = 0;
        }
 
-       if (priv->header_view) {
-               GtkTreeModel *sortable;
-
-               sortable = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->header_view));
-               if (sortable) {
-                       if (g_signal_handler_is_connected (G_OBJECT (sortable),
-                                                          priv->sort_column_handler)) {
-                               g_signal_handler_disconnect (G_OBJECT (sortable),
-                                                            priv->sort_column_handler);
-                               priv->sort_column_handler = 0;
-                       }
-               }
-       }
-
        modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
        priv->sighandlers = NULL;
 
@@ -427,12 +412,6 @@ connect_signals (ModestHeaderWindow *self)
                                           "clicked",
                                           G_CALLBACK (modest_header_window_show_more), self);
 
-       priv->sighandlers =
-               modest_signal_mgr_connect (priv->sighandlers,
-                                          G_OBJECT (priv->show_more_button2),
-                                          "clicked",
-                                          G_CALLBACK (modest_header_window_show_more), self);
-
        /* Delete using horizontal gesture */
        /* DISABLED because it's unreliabile */
        if (FALSE) {
@@ -573,7 +552,11 @@ on_mark_read_csm_activated (GtkMenuItem *item,
                                                       priv->x_coord, priv->y_coord);
 
        if (header) {
+               gchar *uid;
                tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
+               uid = modest_tny_folder_get_header_unique_id (header);
+               modest_platform_emit_msg_read_changed_signal (uid, TRUE);
+               g_free (uid);
                g_object_unref (header);
        }
 }
@@ -593,7 +576,11 @@ on_mark_unread_csm_activated (GtkMenuItem *item,
                                                       priv->x_coord, priv->y_coord);
 
        if (header) {
+               gchar *uid;
                tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
+               uid = modest_tny_folder_get_header_unique_id (header);
+               modest_platform_emit_msg_read_changed_signal (uid, FALSE);
+               g_free (uid);
                g_object_unref (header);
        }
 }
@@ -612,7 +599,6 @@ on_header_view_model_destroyed (gpointer user_data,
        priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
        priv->model_weak_ref = NULL;
 
-       priv->sort_column_handler = 0;
 }
 
 static void
@@ -628,22 +614,12 @@ on_header_view_model_changed (GObject *gobject,
                g_object_weak_unref ((GObject *) priv->model_weak_ref,
                                     on_header_view_model_destroyed,
                                     self);
-               if (g_signal_handler_is_connected (G_OBJECT (priv->model_weak_ref),
-                                                  priv->sort_column_handler)) {
-                       g_signal_handler_disconnect (G_OBJECT (priv->model_weak_ref),
-                                                    priv->sort_column_handler);
-               }
                on_header_view_model_destroyed (self, (GObject *) priv->model_weak_ref);
        }
 
        if (!model)
                return;
 
-       /* Connect the signal. Listen to object destruction to disconnect it */
-       priv->sort_column_handler = g_signal_connect ((GObject *) model,
-                                                     "sort-column-changed",
-                                                     G_CALLBACK (on_sort_column_changed),
-                                                     self);
        priv->model_weak_ref = model;
        g_object_weak_ref ((GObject *) model, on_header_view_model_destroyed, self);
 }
@@ -654,10 +630,26 @@ create_header_view (ModestWindow *self, TnyFolder *folder)
        GtkWidget *header_view;
        GtkWidget *delete_item, *mark_read_item, *mark_unread_item;
        ModestHeaderWindowPrivate *priv;
+       TnyAccount *account;
+       ModestProtocolType protocol_type;
 
-       header_view  = modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_TWOLINES);
-       modest_header_view_set_show_latest (MODEST_HEADER_VIEW (header_view), SHOW_LATEST_SIZE);
        priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
+
+       header_view  = modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_TWOLINES);
+
+       account = modest_tny_folder_get_account (folder);
+       priv->limit_headers = FALSE;
+       if (account) {
+               protocol_type = modest_tny_account_get_protocol_type (account);
+               if (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
+                                                                   protocol_type,
+                                                                   MODEST_PROTOCOL_REGISTRY_STORE_LIMIT_HEADER_WINDOW)) {
+                       priv->limit_headers = TRUE;
+               }
+               g_object_unref (account);
+       }
+       modest_header_view_set_show_latest (MODEST_HEADER_VIEW (header_view), priv->limit_headers?SHOW_LATEST_SIZE:0);
+
        priv->notify_model = g_signal_connect ((GObject*) header_view, "notify::model",
                                               G_CALLBACK (on_header_view_model_changed), self);
 
@@ -733,15 +725,9 @@ create_empty_view (ModestWindow *self)
        g_object_unref (new_message_pixbuf);
        gtk_widget_show_all (button);
 
-       priv->show_more_button2 = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-       hildon_button_set_title (HILDON_BUTTON (priv->show_more_button2), _("mcen_va_more"));
-       gtk_widget_hide_all (priv->show_more_button2);
-
        hbox = gtk_hbox_new (TRUE, 0);
        gtk_widget_show (hbox);
        gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
-       gtk_box_pack_start (GTK_BOX (hbox), priv->show_more_button2, TRUE, TRUE, 0);
-
        gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
 
        gtk_widget_show (vbox);
@@ -772,7 +758,7 @@ on_vertical_movement (HildonPannableArea *area,
 ModestWindow *
 modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gchar *mailbox)
 {
-       ModestHeaderWindow *self = NULL;        
+       ModestHeaderWindow *self = NULL;
        ModestHeaderWindowPrivate *priv = NULL;
        HildonProgram *app;
        GdkPixbuf *window_icon;
@@ -783,7 +769,10 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
        GdkPixbuf *new_message_pixbuf;
        GtkWidget *alignment;
        gchar *account_display_name = NULL;
-       
+#ifdef MODEST_TOOLKIT_HILDON2
+       GtkWidget *live_search;
+#endif
+
        self  = MODEST_HEADER_WINDOW(g_object_new(MODEST_TYPE_HEADER_WINDOW, NULL));
        priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
 
@@ -803,6 +792,10 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
                                  self);
 
        priv->header_view  = create_header_view (MODEST_WINDOW (self), folder);
+#ifdef MODEST_TOOLKIT_HILDON2
+       live_search = modest_header_view_setup_live_search (MODEST_HEADER_VIEW (priv->header_view));
+       hildon_live_search_widget_hook (HILDON_LIVE_SEARCH (live_search), GTK_WIDGET (self), priv->header_view);
+#endif
        priv->empty_view = create_empty_view (MODEST_WINDOW (self));
 
        /* Transform the floating reference in a "hard" reference. We
@@ -824,19 +817,17 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
        hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
        g_object_unref (new_message_pixbuf);
 
-       priv->show_more_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-       hildon_button_set_title (HILDON_BUTTON (priv->show_more_button), _("mcen_va_more"));
-
        gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
-       gtk_box_pack_start (GTK_BOX (action_area_box), priv->show_more_button, TRUE, TRUE, 0);
        gtk_widget_show_all (priv->new_message_button);
-       gtk_widget_hide_all (priv->show_more_button);
        hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->header_view), TRUE);
-       
+
        setup_menu (self);
 
         priv->top_vbox = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (alignment), priv->contents_view);
+#ifdef MODEST_TOOLKIT_HILDON2
+       gtk_box_pack_end (GTK_BOX (priv->top_vbox), live_search, FALSE, FALSE, 0);
+#endif
        gtk_box_pack_end (GTK_BOX (priv->top_vbox), alignment, TRUE, TRUE, 0);
 
        gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
@@ -880,6 +871,13 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
                                                  GTK_SELECTION_MULTIPLE,
                                                  EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_move_to));
 
+       priv->isearch_toolbar = hildon_find_toolbar_new (NULL);
+       hildon_window_add_toolbar (HILDON_WINDOW (self), GTK_TOOLBAR (priv->isearch_toolbar));
+       g_signal_connect (G_OBJECT (priv->isearch_toolbar), "close", 
+                         G_CALLBACK (isearch_toolbar_close), self);
+       g_signal_connect (G_OBJECT (priv->isearch_toolbar), "search", 
+                         G_CALLBACK (isearch_toolbar_search), self);
+
 
        modest_window_set_active_account (MODEST_WINDOW (self), account_name);
        modest_window_set_active_mailbox (MODEST_WINDOW (self), mailbox);
@@ -909,7 +907,7 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
                } else {
                        folder_name = modest_tny_folder_get_display_name (folder);
                }
-               
+
                gtk_window_set_title (GTK_WINDOW (self), folder_name);
                g_free (folder_name);
        }
@@ -917,7 +915,6 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
 
 
        update_progress_hint (self);
-       update_sort_button (self);
 
        return MODEST_WINDOW(self);
 }
@@ -944,6 +941,9 @@ static void setup_menu (ModestHeaderWindow *self)
        modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_message"), "<Control>n",
                                           APP_MENU_CALLBACK (modest_ui_actions_on_new_msg),
                                           MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_new_msg));
+       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),
                                           dngettext(GETTEXT_PACKAGE,
                                                     "mcen_me_move_message",
@@ -958,22 +958,23 @@ static void setup_menu (ModestHeaderWindow *self)
        modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_folder_details"), NULL,
                                           APP_MENU_CALLBACK (modest_ui_actions_on_details),
                                           MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_details));
-       priv->sort_button = hildon_button_new (MODEST_EDITABLE_SIZE,
-                                              HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-       hildon_button_set_title (HILDON_BUTTON (priv->sort_button), _("mcen_me_sort"));
-       g_signal_connect_after (G_OBJECT (priv->sort_button), "clicked",
-                               G_CALLBACK (modest_ui_actions_on_sort), (gpointer) self);
-       hildon_button_set_style(HILDON_BUTTON (priv->sort_button), HILDON_BUTTON_STYLE_PICKER);
-       hildon_button_set_title_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
-       hildon_button_set_value_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
-       modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->sort_button),
-                                                 modest_ui_dimming_rules_on_sort);
-       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));
+
+       priv->show_more_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+       hildon_button_set_title (HILDON_BUTTON (priv->show_more_button), _("mcen_va_more"));
+       hildon_button_set_alignment (HILDON_BUTTON (priv->show_more_button), 0.5, 0.5, 1.0, 1.0);
+       hildon_button_set_title_alignment (HILDON_BUTTON (priv->show_more_button), 0.5, 0.5);
+       hildon_button_set_value_alignment (HILDON_BUTTON (priv->show_more_button), 0.5, 0.5);
+       modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->show_more_button),
+                                                 NULL);
+       gtk_widget_hide_all (priv->show_more_button);
+
        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));
+#ifndef MODEST_TOOLKIT_HILDON2
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _HL("wdgt_bd_search"), NULL,
+                                          APP_MENU_CALLBACK (toggle_isearch_toolbar), NULL);
+#endif
 }
 
 static void 
@@ -1033,25 +1034,21 @@ update_view (ModestHeaderWindow *self,
 
        visible = modest_header_view_get_show_latest (MODEST_HEADER_VIEW (priv->header_view));
 
-       if (all_count > 0 && visible < all_count && folder_empty) {
+       if (visible > 0 && all_count > 0 && visible < all_count && folder_empty) {
                modest_header_view_set_show_latest (MODEST_HEADER_VIEW (priv->header_view), visible + SHOW_LATEST_SIZE);
        }
 
        if (visible > all_count)
                visible = all_count;
-       if (visible == all_count) {
+       if (visible == 0 || visible == all_count) {
                gtk_widget_hide_all (priv->show_more_button);
-               gtk_widget_hide_all (priv->show_more_button2);
        } else {
                gtk_widget_show_all (priv->show_more_button);
-               gtk_widget_show_all (priv->show_more_button2);
        }
        show_more_value = g_strdup_printf (_("mcen_va_more_toview"), visible, all_count);
 
        hildon_button_set_value (HILDON_BUTTON (priv->show_more_button),
                                 show_more_value);
-       hildon_button_set_value (HILDON_BUTTON (priv->show_more_button2),
-                                show_more_value);
 }
 
 static void 
@@ -1444,84 +1441,6 @@ edit_mode_changed (ModestHeaderWindow *header_window,
        }
 }
 
-static void 
-on_sort_column_changed (GtkTreeSortable *treesortable,
-                       gpointer         user_data)
-{
-       update_sort_button (MODEST_HEADER_WINDOW (user_data));
-}
-
-static void
-update_sort_button (ModestHeaderWindow *self)
-{
-       ModestHeaderWindowPrivate *priv;
-       GtkTreeSortable *sortable;
-       gint current_sort_colid = -1;
-       GtkSortType current_sort_type;
-       const gchar *value = NULL;
-
-       priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
-
-       /* This could happen as the first time the model is set the
-          header_view is still not assigned to priv->header_view */
-       if (!priv->header_view)
-               return;
-
-       sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->header_view)));
-
-       if (!gtk_tree_sortable_get_sort_column_id (sortable,
-                                                  &current_sort_colid, &current_sort_type)) {
-               value =  _("mcen_li_sort_sender_date_newest");
-       } else {
-               switch (current_sort_colid) {
-               case TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN:
-               {
-                       GList *cols = NULL;
-                       cols = modest_header_view_get_columns (MODEST_HEADER_VIEW (priv->header_view));
-                       if (cols != NULL) {
-                               gpointer flags_sort_type_pointer;
-                               flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data), 
-                                                                            MODEST_HEADER_VIEW_FLAG_SORT);
-                               if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK)
-                                       value = _("mcen_li_sort_priority");
-                               else
-                                       value = _("mcen_li_sort_attachment");
-                               g_list_free(cols);      
-                       }
-               } 
-               break;
-               case TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN:
-               case TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN:
-                       if (current_sort_type == GTK_SORT_ASCENDING)
-                               value = _("mcen_li_sort_sender_recipient_az");
-                       else
-                               value = _("mcen_li_sort_sender_recipient_za");
-                       break;
-               case TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN:
-               case TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN:
-                       if (current_sort_type == GTK_SORT_ASCENDING)
-                               value = _("mcen_li_sort_date_oldest");
-                       else
-                               value = _("mcen_li_sort_date_newest");
-                       break;
-               case TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN:
-                       if (current_sort_type == GTK_SORT_ASCENDING)
-                               value = _("mcen_li_sort_subject_az");
-                       else
-                               value = _("mcen_li_sort_subject_za");
-                       break;
-               case TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN:
-                       if (current_sort_type == GTK_SORT_ASCENDING)
-                               value = _("mcen_li_sort_size_smallest");
-                       else
-                               value = _("mcen_li_sort_size_largest");
-                       break;
-               } 
-       }
-
-       hildon_button_set_value (HILDON_BUTTON (priv->sort_button), value?value:"");
-}
-
 static void
 on_horizontal_movement (HildonPannableArea *hildonpannable,
                        gint                direction,
@@ -1607,3 +1526,75 @@ modest_header_window_show_more (GtkAction *action, ModestWindow *win)
                update_view (self, NULL);
        }
 }
+
+#ifndef MODEST_TOOLKIT_HILDON2
+/* Used for the Ctrl+F accelerator */
+static void
+toggle_isearch_toolbar (GtkWidget *obj,
+                       gpointer data)
+{
+       ModestHeaderWindow *window = MODEST_HEADER_WINDOW (data);
+       ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (window);
+
+       if (GTK_WIDGET_VISIBLE (priv->isearch_toolbar)) {
+               isearch_toolbar_close (obj, data);
+       } else {
+               show_isearch_toolbar (obj, data);
+       }
+}
+
+/* Handler for menu option */
+static void
+show_isearch_toolbar (GtkWidget *obj,
+                     gpointer data)
+{
+       ModestHeaderWindow *window = MODEST_HEADER_WINDOW (data);
+       ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (window);
+
+       gtk_widget_show (priv->isearch_toolbar);
+       hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->isearch_toolbar), TRUE);
+}
+#endif
+
+/* Handler for click on the "X" close button in isearch toolbar */
+static void
+isearch_toolbar_close (GtkWidget *widget,
+                      ModestHeaderWindow *obj)
+{
+       ModestHeaderWindowPrivate *priv;
+
+       priv = MODEST_HEADER_WINDOW_GET_PRIVATE (obj);
+
+       /* Hide toolbar */
+       gtk_widget_hide (priv->isearch_toolbar);
+
+       modest_header_view_set_show_latest (MODEST_HEADER_VIEW (priv->header_view), priv->limit_headers?SHOW_LATEST_SIZE:0);
+       modest_header_view_set_filter_string (MODEST_HEADER_VIEW (priv->header_view), NULL);
+       update_view (obj, NULL);
+}
+
+static void
+isearch_toolbar_search (GtkWidget *widget,
+                       ModestHeaderWindow *obj)
+{
+       ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (obj);
+       gchar *current_search;
+
+       g_object_get (G_OBJECT (widget), "prefix", &current_search, NULL);
+
+       if (current_search && *current_search == '\0') {
+               g_free (current_search);
+               current_search = NULL;
+       }
+
+       /* TODO: set filter */
+       modest_header_view_set_filter_string (MODEST_HEADER_VIEW (priv->header_view), 
+                                             current_search);
+       if (current_search == NULL) {
+               modest_header_view_set_show_latest (MODEST_HEADER_VIEW (priv->header_view), priv->limit_headers?SHOW_LATEST_SIZE:0);
+       } else {
+               modest_header_view_set_show_latest (MODEST_HEADER_VIEW (priv->header_view), 0);
+       }
+       g_free (current_search);
+       update_view (obj, NULL);
+}