[gnome-calendar/search-improvements] search-view: handle search independently



commit c22866fbfd4f7ebf2a45d204033cb478bb1fb813
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Jan 7 15:30:43 2015 -0200

    search-view: handle search independently
    
    Instead of letting GcalWindow handle the searches,
    make GcalSearchView handle it so the widget has
    more control over the general appearance of the
    popover.

 src/gcal-search-view.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcal-search-view.h |    5 +++++
 src/gcal-window.c      |    8 ++------
 3 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/src/gcal-search-view.c b/src/gcal-search-view.c
index ea76d0c..2ef83e8 100644
--- a/src/gcal-search-view.c
+++ b/src/gcal-search-view.c
@@ -496,6 +496,9 @@ gcal_search_view_constructed (GObject *object)
   gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->listbox), (GtkListBoxSortFunc) sort_by_event, object, 
NULL);
 
   gcal_manager_set_search_subscriber (priv->manager, E_CAL_DATA_MODEL_SUBSCRIBER (object), 0, 0);
+
+  /* don't fill the list with all events on startup */
+  gcal_search_view_search (GCAL_SEARCH_VIEW (object), NULL, NULL);
 }
 
 static void
@@ -693,3 +696,48 @@ gcal_search_view_set_time_format (GcalSearchView *view,
   priv = gcal_search_view_get_instance_private (view);
   priv->format_24h = format_24h;
 }
+
+/**
+ * gcal_search_view_set_search:
+ * @view: a #GcalSearchView instance
+ * @field: the field to perform the search.
+ * @query: what the search will look for.
+ *
+ *
+ *
+ * Returns:
+ */
+void
+gcal_search_view_search (GcalSearchView *view,
+                         const gchar    *field,
+                         const gchar    *query)
+{
+  GcalSearchViewPrivate *priv;
+
+  priv = gcal_search_view_get_instance_private (view);
+
+  /* Only perform search on valid non-empty strings */
+  if (query && g_utf8_strlen (query, -1) > 0)
+    {
+      gchar *search_query;
+
+      search_query = g_strdup_printf ("(contains? \"%s\" \"%s\")", field != NULL? field : "summary",
+                                      query != NULL? query : "");
+
+      gcal_manager_set_query (priv->manager, search_query);
+
+      g_free (search_query);
+    }
+  else
+    {
+      /**
+       * Since the priv->events hash table will always call
+       * free_row_data on rows - and free_row_data removes the
+       * row from the list by calling gtk_widget_destroy - the
+       * following code will in fact clear the list.
+       */
+      g_hash_table_remove_all (priv->row_to_event);
+      g_hash_table_remove_all (priv->events);
+    }
+}
+
diff --git a/src/gcal-search-view.h b/src/gcal-search-view.h
index 52f806f..030b82c 100644
--- a/src/gcal-search-view.h
+++ b/src/gcal-search-view.h
@@ -55,6 +55,11 @@ GType          gcal_search_view_get_type         (void);
 void           gcal_search_view_set_time_format  (GcalSearchView *view,
                                                   gboolean        format_24h);
 
+void           gcal_search_view_search           (GcalSearchView *view,
+                                                  const gchar    *field,
+                                                  const gchar    *query);
+
+
 GtkWidget*     gcal_search_view_new              (GcalManager *manager);
 
 G_END_DECLS
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 293f3e4..2acb93e 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1038,7 +1038,6 @@ search_toggled (GObject    *object,
   if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (priv->search_bar)))
     {
       g_debug ("Entering search mode");
-      gcal_manager_set_query (priv->manager, NULL);
       gtk_widget_show (priv->search_bar);
 
       /* update header_bar widget */
@@ -1063,12 +1062,9 @@ search_changed (GtkEditable *editable,
 
   if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (priv->search_bar)))
     {
-      gchar *query;
-
       /* perform the search */
-      query = g_strdup_printf ("(contains? \"summary\" \"%s\")", gtk_entry_get_text (GTK_ENTRY 
(priv->search_entry)));
-      gcal_manager_set_query (priv->manager, query);
-      g_free (query);
+      gcal_search_view_search (GCAL_SEARCH_VIEW (priv->views[GCAL_WINDOW_VIEW_SEARCH]), "summary",
+                               gtk_entry_get_text (GTK_ENTRY (priv->search_entry)));
 
       if (gtk_entry_get_text_length (GTK_ENTRY (priv->search_entry)) != 0)
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]