Add live search support to folders window
authorJosé Dapena Paz <jdapena@igalia.com>
Tue, 2 Feb 2010 16:57:45 +0000 (17:57 +0100)
committerJosé Dapena Paz <jdapena@igalia.com>
Tue, 2 Feb 2010 17:03:12 +0000 (18:03 +0100)
src/hildon2/modest-folder-window.c
src/widgets/modest-folder-view.c
src/widgets/modest-folder-view.h

index c4a283a..324393c 100644 (file)
@@ -41,9 +41,7 @@
 #include <modest-defs.h>
 #include <modest-ui-actions.h>
 #include <modest-window.h>
-#include <hildon/hildon-program.h>
-#include <hildon/hildon-banner.h>
-#include <hildon/hildon-button.h>
+#include <hildon/hildon.h>
 #include <tny-account-store-view.h>
 #include <tny-gtk-folder-list-store.h>
 #include <modest-header-window.h>
@@ -327,6 +325,9 @@ modest_folder_window_new (TnyFolderStoreQuery *query)
        GdkModifierType accel_mods;
        GtkAccelGroup *accel_group;
        GtkWidget *top_alignment;
+#ifdef MODEST_TOOLKIT_HILDON2
+       GtkWidget *live_search;
+#endif
        
        self  = MODEST_FOLDER_WINDOW(g_object_new(MODEST_TYPE_FOLDER_WINDOW, NULL));
        priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
@@ -340,6 +341,10 @@ modest_folder_window_new (TnyFolderStoreQuery *query)
                                  self);
 
        priv->folder_view  = modest_platform_create_folder_view (query);
+#ifdef MODEST_TOOLKIT_HILDON2
+       live_search = modest_folder_view_setup_live_search (MODEST_FOLDER_VIEW (priv->folder_view));
+       hildon_live_search_widget_hook (HILDON_LIVE_SEARCH (live_search), GTK_WIDGET (self), priv->folder_view);
+#endif
        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), 
@@ -374,6 +379,9 @@ modest_folder_window_new (TnyFolderStoreQuery *query)
 
        gtk_container_add (GTK_CONTAINER (pannable), priv->folder_view);
        gtk_container_add (GTK_CONTAINER (top_alignment), pannable);
+#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), top_alignment, TRUE, TRUE, 0);
        gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
 
index c916b55..94147a3 100644 (file)
@@ -63,6 +63,9 @@
 #include "modest-ui-constants.h"
 #include "widgets/modest-window.h"
 #include <modest-account-protocol.h>
+#ifdef MODEST_TOOLKIT_HILDON2
+#include <hildon/hildon.h>
+#endif
 
 /* Folder view drag types */
 const GtkTargetEntry folder_view_drag_types[] =
@@ -234,6 +237,9 @@ struct _ModestFolderViewPrivate {
        gchar **hidding_ids;
        guint n_selected;
        ModestFolderViewFilter filter;
+#ifdef MODEST_TOOLKIT_HILDON2
+       GtkWidget *live_search;
+#endif
 
        TnyFolderStoreQuery  *query;
        gboolean              do_refresh;
@@ -567,6 +573,7 @@ format_compact_style (gchar **item_name,
        TnyFolder *folder;
        gboolean is_special;
        TnyFolderType folder_type;
+       gboolean l_use_markup;
 
        if (!TNY_IS_FOLDER (instance))
                return;
@@ -623,10 +630,12 @@ format_compact_style (gchar **item_name,
                g_object_unref (account);
 
                *item_name = g_string_free (buffer, FALSE);
-               *use_markup = FALSE;
+               l_use_markup = FALSE;
        } else {
-               *use_markup = FALSE;
+               l_use_markup = FALSE;
        }
+       if (use_markup)
+               *use_markup = l_use_markup;
 }
 
 static void
@@ -1355,6 +1364,9 @@ modest_folder_view_init (ModestFolderView *obj)
        priv->outbox_deleted_handler = 0;
        priv->reexpand = TRUE;
        priv->signal_handlers = 0;
+#ifdef MODEST_TOOLKIT_HILDON2
+       priv->live_search = NULL;
+#endif
 
        /* Initialize the local account name */
        conf = modest_runtime_get_conf();
@@ -2333,6 +2345,50 @@ filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
                }
        }
 
+#ifdef MODEST_TOOLKIT_HILDON2
+       if (retval && (priv->live_search)) {
+               const gchar *needle;
+               needle = hildon_live_search_get_text (HILDON_LIVE_SEARCH (priv->live_search));
+               if (needle && needle[0] != '\0') {
+                       gchar *haystack;
+                       gboolean is_local;
+                       
+                       haystack = g_strdup (fname);
+                       if (type != TNY_FOLDER_TYPE_ROOT) {
+                               is_local = modest_tny_folder_is_local_folder (TNY_FOLDER (instance)) ||
+                                       modest_tny_folder_is_memory_card_folder (TNY_FOLDER (instance));
+                               if (is_local) {
+                                       TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
+                                       type = modest_tny_folder_get_local_or_mmc_folder_type (TNY_FOLDER (instance));
+                                       if (type != TNY_FOLDER_TYPE_UNKNOWN) {
+                                               g_free (haystack);
+                                               haystack = g_strdup (modest_local_folder_info_get_type_display_name (type));
+                                       }
+                               } else {
+                               }
+                       } else {
+                               if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (instance))) {
+                                       g_free (haystack);
+                                       haystack = g_strdup (priv->local_account_name);
+                               } else if (modest_tny_account_is_memory_card_account (TNY_ACCOUNT (instance))) {
+                                       g_free (haystack);
+                                       haystack = g_strdup (tny_account_get_name (TNY_ACCOUNT (instance)));
+                               }
+                       }
+
+                       if (type == TNY_FOLDER_TYPE_INBOX &&
+                           g_str_has_suffix (haystack, "Inbox")) {
+                               g_free (haystack);
+                               haystack = g_strdup (_("mcen_me_folder_inbox"));
+                       }
+                       format_compact_style (&haystack, instance, priv->mailbox, FALSE, 
+                                     priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ALL, NULL);
+                       retval = modest_text_utils_live_search_find (haystack, needle);
+                       g_free (haystack);
+               }
+       }
+#endif
+
        /* Free */
        g_object_unref (instance);
         g_free (fname);
@@ -4395,3 +4451,31 @@ modest_folder_view_get_model_tny_list (ModestFolderView *self)
        return ret_value;
 
 }
+
+#ifdef MODEST_TOOLKIT_HILDON2
+static gboolean
+on_live_search_refilter (HildonLiveSearch *livesearch,
+                        ModestFolderView *self)
+{
+       GtkTreeModel *filter_model;
+
+       if (get_inner_models (self, &filter_model, NULL, NULL))
+               gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
+
+       return TRUE;
+}
+
+GtkWidget *
+modest_folder_view_setup_live_search (ModestFolderView *self)
+{
+       ModestFolderViewPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_FOLDER_VIEW (self), NULL);
+       priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
+       priv->live_search = hildon_live_search_new ();
+
+       g_signal_connect (G_OBJECT (priv->live_search), "refilter", G_CALLBACK (on_live_search_refilter), self);
+
+       return priv->live_search;
+}
+#endif
index 1b098aa..ff916b3 100644 (file)
@@ -381,6 +381,19 @@ gboolean modest_folder_view_get_activity (ModestFolderView *self);
  */
 TnyList *modest_folder_view_get_model_tny_list (ModestFolderView *self);
 
+#ifdef MODEST_TOOLKIT_HILDON2
+/**
+ * modest_folder_view_setup_live_search:
+ * @self: a #ModestAccountView
+ *
+ * obtains a properly set up #HildonLiveSearch for @self
+ *
+ * Returns: a #HildonLiveSearch
+ */
+GtkWidget *modest_folder_view_setup_live_search (ModestFolderView *self);
+#endif
+
+
 G_END_DECLS
 
 #endif /* __MODEST_FOLDER_VIEW_H__ */