[epiphany] Update libdazzle and make use of new DzlSuggestionEntry changes



commit 12b7e8dca6733c1ffdd63e1f2ff808b9f48dd503
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Wed Sep 5 21:33:15 2018 +0200

    Update libdazzle and make use of new DzlSuggestionEntry changes

 lib/ephy-suggestion.c                      |   1 +
 lib/ephy-suggestion.h                      |   1 +
 lib/widgets/ephy-location-entry.c          |  30 ++++++++-
 src/ephy-location-controller.c             |  12 ++--
 src/ephy-suggestion-model.c                | 101 +++++------------------------
 src/search-provider/ephy-search-provider.c |   2 +
 subprojects/libdazzle.wrap                 |   2 +-
 7 files changed, 54 insertions(+), 95 deletions(-)
---
diff --git a/lib/ephy-suggestion.c b/lib/ephy-suggestion.c
index 9c7beec36..f61989cbf 100644
--- a/lib/ephy-suggestion.c
+++ b/lib/ephy-suggestion.c
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Copyright © 2017 Igalia S.L.
+ * Copyright © 2018 Jan-Michael Brummer
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/lib/ephy-suggestion.h b/lib/ephy-suggestion.h
index ca461120b..943b6bf2b 100644
--- a/lib/ephy-suggestion.h
+++ b/lib/ephy-suggestion.h
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Copyright © 2017 Igalia S.L.
+ * Copyright © 2018 Jan-Michael Brummer
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 5e6c7de4e..927968bfb 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -126,6 +126,10 @@ G_DEFINE_TYPE_WITH_CODE (EphyLocationEntry, ephy_location_entry, GTK_TYPE_OVERLA
                          G_IMPLEMENT_INTERFACE (EPHY_TYPE_TITLE_WIDGET,
                                                 ephy_location_entry_title_widget_interface_init))
 
+static void
+editable_changed_cb (GtkEditable       *editable,
+                     EphyLocationEntry *entry);
+
 static void
 ephy_location_entry_activate (EphyLocationEntry *entry)
 {
@@ -195,7 +199,11 @@ ephy_location_entry_title_widget_set_address (EphyTitleWidget *widget,
   entry->hash = g_str_hash (effective_text ? effective_text : text);
 
   entry->block_update = TRUE;
+  g_signal_handlers_block_by_func (entry->url_entry, G_CALLBACK (editable_changed_cb), entry);
   gtk_entry_set_text (GTK_ENTRY (entry->url_entry), effective_text ? effective_text : text);
+  g_signal_handlers_unblock_by_func (entry->url_entry, G_CALLBACK (editable_changed_cb), entry);
+
+  dzl_suggestion_entry_hide_suggestions (DZL_SUGGESTION_ENTRY (entry->url_entry));
   entry->block_update = FALSE;
   g_free (effective_text);
 
@@ -737,12 +745,31 @@ ephy_location_entry_suggestion_activated (DzlSuggestionEntry *entry,
 {
   EphyLocationEntry *lentry = EPHY_LOCATION_ENTRY (user_data);
   DzlSuggestion *suggestion = dzl_suggestion_entry_get_suggestion (entry);
+  g_signal_handlers_block_by_func (entry, G_CALLBACK (editable_changed_cb), user_data);
   gtk_entry_set_text (GTK_ENTRY (entry), ephy_suggestion_get_uri (EPHY_SUGGESTION (suggestion)));
+  g_signal_handlers_unblock_by_func (entry, G_CALLBACK (editable_changed_cb), user_data);
+
+  g_signal_stop_emission_by_name (entry, "suggestion-activated");
+
+  dzl_suggestion_entry_hide_suggestions (entry);
 
   /* Now trigger the load.... */
   ephy_location_entry_activate (EPHY_LOCATION_ENTRY (lentry));
 }
 
+static void
+suggestion_selected (DzlSuggestionEntry *entry,
+                     DzlSuggestion      *suggestion,
+                     gpointer            user_data)
+{
+  const gchar *uri = dzl_suggestion_get_id (suggestion);
+
+  g_signal_handlers_block_by_func (entry, G_CALLBACK (editable_changed_cb), user_data);
+  gtk_entry_set_text (GTK_ENTRY (entry), uri);
+  gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+  g_signal_handlers_unblock_by_func (entry, G_CALLBACK (editable_changed_cb), user_data);
+}
+
 static void
 ephy_location_entry_construct_contents (EphyLocationEntry *entry)
 {
@@ -762,6 +789,8 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
   gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (entry->url_entry)), "url_entry");
   g_signal_connect (G_OBJECT (entry->url_entry), "copy-clipboard", G_CALLBACK 
(ephy_location_entry_copy_clipboard), NULL);
   g_signal_connect (G_OBJECT (entry->url_entry), "cut-clipboard", G_CALLBACK 
(ephy_location_entry_cut_clipboard), NULL);
+  g_signal_connect (G_OBJECT (entry->url_entry), "changed", G_CALLBACK (editable_changed_cb), entry);
+  g_signal_connect (G_OBJECT (entry->url_entry), "suggestion-selected", G_CALLBACK (suggestion_selected), 
entry);
   gtk_widget_show (GTK_WIDGET (entry->url_entry));
   gtk_overlay_add_overlay (GTK_OVERLAY (entry), GTK_WIDGET (entry->url_entry));
 
@@ -800,7 +829,6 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
                     "signal::icon-press", G_CALLBACK (icon_button_icon_press_event_cb), entry,
                     "signal::populate-popup", G_CALLBACK (entry_populate_popup_cb), entry,
                     "signal::key-press-event", G_CALLBACK (entry_key_press_cb), entry,
-                    "signal::changed", G_CALLBACK (editable_changed_cb), entry,
                     NULL);
 
   g_signal_connect (entry->url_entry, "suggestion-activated",
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index a3d4cb18f..c63a959ab 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -177,15 +177,14 @@ static void
 user_changed_cb (GtkWidget *widget, EphyLocationController *controller)
 {
   const char *address;
-  GtkWidget *entry;
+  DzlSuggestionEntry *entry = DZL_SUGGESTION_ENTRY (ephy_location_entry_get_entry (EPHY_LOCATION_ENTRY 
(widget)));
   GListModel *model;
 
-  address = ephy_title_widget_get_address (EPHY_TITLE_WIDGET (widget));
+  address = dzl_suggestion_entry_get_typed_text (entry);
 
   LOG ("user_changed_cb, address %s", address);
 
-  entry = ephy_location_entry_get_entry (EPHY_LOCATION_ENTRY (widget));
-  model = dzl_suggestion_entry_get_model (DZL_SUGGESTION_ENTRY (entry));
+  model = dzl_suggestion_entry_get_model (entry);
 
   ephy_suggestion_model_query_async (EPHY_SUGGESTION_MODEL (model), address, NULL, NULL, NULL);
 }
@@ -300,7 +299,6 @@ reader_mode_button_press_event_cb (GtkWidget *widget,
   ephy_web_view_toggle_reader_mode (view, ephy_location_entry_get_reader_mode_state (lentry));
 }
 
-
 static void
 ephy_location_controller_constructed (GObject *object)
 {
@@ -326,6 +324,8 @@ ephy_location_controller_constructed (GObject *object)
     return;
 
   entry = ephy_location_entry_get_entry (EPHY_LOCATION_ENTRY (controller->title_widget));
+  g_signal_connect (controller->title_widget, "user-changed", G_CALLBACK (user_changed_cb), controller);
+
   controller->longpress_gesture = gtk_gesture_long_press_new (entry);
   gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (controller->longpress_gesture), TRUE);
   g_signal_connect (controller->longpress_gesture, "pressed", G_CALLBACK (longpress_gesture_cb), entry);
@@ -349,8 +349,6 @@ ephy_location_controller_constructed (GObject *object)
   g_signal_connect_object (entry, "activate",
                            G_CALLBACK (entry_activate_cb),
                            controller, 0);
-  g_signal_connect_object (widget, "user-changed",
-                           G_CALLBACK (user_changed_cb), controller, 0);
   g_signal_connect_object (widget, "get-location",
                            G_CALLBACK (get_location_cb), controller, 0);
   g_signal_connect_object (widget, "get-title",
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index 5f84ba83e..fb70be375 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -33,7 +33,7 @@ struct _EphySuggestionModel {
   EphyHistoryService   *history_service;
   EphyBookmarksManager *bookmarks_manager;
   GSequence            *items;
-  GSList               *search_terms;
+  gchar               **search_terms;
   GCancellable         *icon_cancellable;
 };
 
@@ -63,7 +63,7 @@ ephy_suggestion_model_finalize (GObject *object)
   g_cancellable_cancel (self->icon_cancellable);
   g_clear_object (&self->icon_cancellable);
 
-  g_slist_free_full (self->search_terms, (GDestroyNotify)g_regex_unref);
+  g_strfreev (self->search_terms);
 
   G_OBJECT_CLASS (ephy_suggestion_model_parent_class)->finalize (object);
 }
@@ -193,82 +193,11 @@ static void
 update_search_terms (EphySuggestionModel *self,
                      const char          *text)
 {
-  const char *current;
-  const char *ptr;
-  char *tmp;
-  char *term;
-  GRegex *term_regex;
-  GRegex *quote_regex;
-  gint count;
-  gboolean inside_quotes = FALSE;
-
   g_assert (EPHY_IS_SUGGESTION_MODEL (self));
 
-  if (self->search_terms) {
-    g_slist_free_full (self->search_terms, (GDestroyNotify)g_regex_unref);
-    self->search_terms = NULL;
-  }
-
-  quote_regex = g_regex_new ("\"", G_REGEX_OPTIMIZE,
-                             G_REGEX_MATCH_NOTEMPTY, NULL);
-
-  /*
-   * This code loops through the string using pointer arythmetics.
-   * Although the string we are handling may contain UTF-8 chars
-   * this works because only ASCII chars affect what is actually
-   * copied from the string as a search term.
-   */
-  for (count = 0, current = ptr = text; ptr[0] != '\0'; ptr++, count++) {
-    /*
-     * If we found a double quote character; we will
-     * consume bytes up until the next quote, or
-     * end of line;
-     */
-    if (ptr[0] == '"')
-      inside_quotes = !inside_quotes;
-
-    /*
-     * If we found a space, and we are not looking for a
-     * closing double quote, or if the next char is the
-     * end of the string, append what we have already as
-     * a search term.
-     */
-    if (((ptr[0] == ' ') && (!inside_quotes)) || ptr[1] == '\0') {
-      /*
-       * We special-case the end of the line because
-       * we would otherwise not copy the last character
-       * of the search string, since the for loop will
-       * stop before that.
-       */
-      if (ptr[1] == '\0')
-        count++;
-
-      /*
-       * remove quotes, and quote any regex-sensitive
-       * characters
-       */
-      tmp = g_regex_escape_string (current, count);
-      term = g_regex_replace (quote_regex, tmp, -1, 0,
-                              "", G_REGEX_MATCH_NOTEMPTY, NULL);
-      g_strstrip (term);
-      g_free (tmp);
-
-      /* we don't want empty search terms */
-      if (term[0] != '\0') {
-        term_regex = g_regex_new (term,
-                                  G_REGEX_CASELESS | G_REGEX_OPTIMIZE,
-                                  G_REGEX_MATCH_NOTEMPTY, NULL);
-        self->search_terms = g_slist_append (self->search_terms, term_regex);
-      }
-      g_free (term);
-
-      /* count will be incremented by the for loop */
-      count = -1;
-      current = ptr + 1;
-    }
-  }
+  g_strfreev (self->search_terms);
 
-  g_regex_unref (quote_regex);
+  self->search_terms = g_strsplit (text, " ", -1);
 }
 
 static gboolean
@@ -280,13 +209,13 @@ should_add_bookmark_to_model (EphySuggestionModel *self,
   gboolean ret = TRUE;
 
   if (self->search_terms) {
-    GSList *iter;
-    GRegex *current = NULL;
+    guint len = g_strv_length (self->search_terms);
+    guint i;
 
-    for (iter = self->search_terms; iter != NULL; iter = iter->next) {
-      current = (GRegex *)iter->data;
-      if ((!g_regex_match (current, title ? title : "", G_REGEX_MATCH_NOTEMPTY, NULL)) &&
-          (!g_regex_match (current, location ? location : "", G_REGEX_MATCH_NOTEMPTY, NULL))) {
+    for (i = 0; i < len; i++) {
+      gchar *str = self->search_terms[i];
+
+      if (!strstr (str, title ? title : "") && !strstr (str, location ? location : "")) {
         ret = FALSE;
         break;
       }
@@ -445,16 +374,16 @@ query_completed_cb (EphyHistoryService *service,
   query = g_task_get_task_data (task);
   urls = (GList *)result_data;
 
-  removed = g_sequence_get_length (self->items);
-
-  g_clear_pointer (&self->items, g_sequence_free);
-  self->items = g_sequence_new (g_object_unref);
-
   g_cancellable_cancel (self->icon_cancellable);
   g_clear_object (&self->icon_cancellable);
 
   self->icon_cancellable = g_cancellable_new ();
 
+  removed = g_sequence_get_length (self->items);
+
+  g_clear_pointer (&self->items, g_sequence_free);
+  self->items = g_sequence_new (g_object_unref);
+
   if (strlen (query) > 0) {
     added = add_bookmarks (self, query);
     added += add_history (self, urls, query);
diff --git a/src/search-provider/ephy-search-provider.c b/src/search-provider/ephy-search-provider.c
index 97be78448..2f39aff28 100644
--- a/src/search-provider/ephy-search-provider.c
+++ b/src/search-provider/ephy-search-provider.c
@@ -129,6 +129,7 @@ complete_request (GObject      *object,
   char **results;
   GError *error;
   error = NULL;
+
   results = gather_results_finish (self, result, &error);
 
   if (results) {
@@ -180,6 +181,7 @@ handle_get_result_metas (EphyShellSearchProvider2 *skeleton,
 {
   int i;
   GVariantBuilder builder;
+
   g_application_hold (G_APPLICATION (self));
   g_cancellable_cancel (self->cancellable);
 
diff --git a/subprojects/libdazzle.wrap b/subprojects/libdazzle.wrap
index 6746b4e43..7b8119777 100644
--- a/subprojects/libdazzle.wrap
+++ b/subprojects/libdazzle.wrap
@@ -1,4 +1,4 @@
 [wrap-git]
 directory=libdazzle
 url=https://gitlab.gnome.org/GNOME/libdazzle.git
-revision=82f20d1d57b99f9a16d2aa3087400bdfc3ebd792
+revision=5d6fd6c2c535b86e3e4683d548e45da131bfe01a


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