[epiphany] suggestion: Add get_uri() method and use it



commit 0247936a0f3f4918d1c2f7082f758615090ad5f8
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sat Sep 9 14:38:06 2017 -0500

    suggestion: Add get_uri() method and use it
    
    Let's be self-documenting... it's a lot more clear to have an explicit
    get_uri() method than to expect developers to know that the ID doubles
    as the URI.
    
    This requires moving EphySuggestion down to lib.

 {src => lib}/ephy-suggestion.c             |   15 ++++++++++++++-
 {src => lib}/ephy-suggestion.h             |    6 ++++--
 lib/meson.build                            |    2 ++
 lib/widgets/ephy-location-entry.c          |    4 ++--
 src/ephy-suggestion-model.c                |    8 ++++----
 src/ephy-suggestion-model.h                |   24 ++++++++++++------------
 src/meson.build                            |    1 -
 src/search-provider/ephy-search-provider.c |    4 ++--
 8 files changed, 40 insertions(+), 24 deletions(-)
---
diff --git a/src/ephy-suggestion.c b/lib/ephy-suggestion.c
similarity index 87%
rename from src/ephy-suggestion.c
rename to lib/ephy-suggestion.c
index 94c4156..0b41d3c 100644
--- a/src/ephy-suggestion.c
+++ b/lib/ephy-suggestion.c
@@ -32,7 +32,11 @@ char *
 ephy_suggestion_replace_typed_text (DzlSuggestion *self,
                                     const char    *typed_text)
 {
-  const char *url = dzl_suggestion_get_id (self);
+  const char *url;
+
+  g_assert (EPHY_IS_SUGGESTION (self));
+
+  url = ephy_suggestion_get_uri (EPHY_SUGGESTION (self));
 
   return g_strdup (url);
 }
@@ -64,8 +68,17 @@ ephy_suggestion_new (const char *title,
                              "title", escaped_title,
                              "subtitle", escaped_uri,
                              NULL);
+
   g_free (escaped_title);
   g_free (escaped_uri);
 
   return suggestion;
 }
+
+const char *
+ephy_suggestion_get_uri (EphySuggestion *self)
+{
+  g_assert (EPHY_IS_SUGGESTION (self));
+
+  return dzl_suggestion_get_id (DZL_SUGGESTION (self));
+}
diff --git a/src/ephy-suggestion.h b/lib/ephy-suggestion.h
similarity index 84%
rename from src/ephy-suggestion.h
rename to lib/ephy-suggestion.h
index 2cbdd31..c225363 100644
--- a/src/ephy-suggestion.h
+++ b/lib/ephy-suggestion.h
@@ -27,7 +27,9 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (EphySuggestion, ephy_suggestion, EPHY, SUGGESTION, DzlSuggestion)
 
 // FIXME: How about favicon?
-EphySuggestion *ephy_suggestion_new (const char *title,
-                                     const char *uri);
+EphySuggestion *ephy_suggestion_new     (const char *title,
+                                         const char *uri);
+
+const char     *ephy_suggestion_get_uri (EphySuggestion *self);
 
 G_END_DECLS
diff --git a/lib/meson.build b/lib/meson.build
index aa10557..e992db7 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -35,6 +35,7 @@ libephymisc_sources = [
   'ephy-sqlite-connection.c',
   'ephy-sqlite-statement.c',
   'ephy-string.c',
+  'ephy-suggestion.c',
   'ephy-sync-utils.c',
   'ephy-time-helpers.c',
   'ephy-uri-helpers.c',
@@ -59,6 +60,7 @@ libephymisc_deps = [
   gnome_desktop_dep,
   gtk_dep,
   icu_uc_dep,
+  libdazzle_dep,
   libsecret_dep,
   libsoup_dep,
   libxml_dep,
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 60772e9..5d220d1 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -31,6 +31,7 @@
 #include "ephy-gui.h"
 #include "ephy-lib-type-builtins.h"
 #include "ephy-signal-accumulator.h"
+#include "ephy-suggestion.h"
 #include "ephy-title-widget.h"
 #include "ephy-uri-helpers.h"
 
@@ -368,8 +369,7 @@ static void
 ephy_location_entry_suggestion_activated (DzlSuggestionEntry *entry,
                                           DzlSuggestion      *suggestion)
 {
-  /* The suggestion ID is the unescaped URL, which is what we need. */
-  gtk_entry_set_text (GTK_ENTRY (entry), dzl_suggestion_get_id (suggestion));
+  gtk_entry_set_text (GTK_ENTRY (entry), ephy_suggestion_get_uri (EPHY_SUGGESTION (suggestion)));
 
   /* Now trigger the load.... */
   ephy_location_entry_activate (EPHY_LOCATION_ENTRY (entry));
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index c56e56f..2dd5994 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -402,20 +402,20 @@ ephy_suggestion_model_query_finish (EphySuggestionModel  *self,
 }
 
 EphySuggestion *
-ephy_suggestion_model_get_suggestion_with_id (EphySuggestionModel *self,
-                                              const char          *id)
+ephy_suggestion_model_get_suggestion_with_uri (EphySuggestionModel *self,
+                                               const char          *uri)
 {
   GSequenceIter *iter;
 
   g_return_val_if_fail (EPHY_IS_SUGGESTION_MODEL (self), NULL);
-  g_return_val_if_fail (id != NULL && *id != '\0', NULL);
+  g_return_val_if_fail (uri != NULL && *uri != '\0', NULL);
 
   for (iter = g_sequence_get_begin_iter (self->items);
        !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
     EphySuggestion *suggestion;
 
     suggestion = g_sequence_get (iter);
-    if (strcmp (dzl_suggestion_get_id (DZL_SUGGESTION (suggestion)), id) == 0)
+    if (strcmp (ephy_suggestion_get_uri (suggestion), uri) == 0)
       return suggestion;
   }
 
diff --git a/src/ephy-suggestion-model.h b/src/ephy-suggestion-model.h
index 1286b80..ba1ff06 100644
--- a/src/ephy-suggestion-model.h
+++ b/src/ephy-suggestion-model.h
@@ -30,17 +30,17 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphySuggestionModel, ephy_suggestion_model, EPHY, SUGGESTION_MODEL, GObject)
 
-EphySuggestionModel *ephy_suggestion_model_new                    (EphyHistoryService    *history_service,
-                                                                   EphyBookmarksManager  *bookmarks_manager);
-void                 ephy_suggestion_model_query_async            (EphySuggestionModel   *self,
-                                                                   const gchar           *query,
-                                                                   GCancellable          *cancellable,
-                                                                   GAsyncReadyCallback    callback,
-                                                                   gpointer               user_data);
-gboolean             ephy_suggestion_model_query_finish           (EphySuggestionModel   *self,
-                                                                   GAsyncResult          *result,
-                                                                   GError               **error);
-EphySuggestion      *ephy_suggestion_model_get_suggestion_with_id (EphySuggestionModel *self,
-                                                                   const char          *id);
+EphySuggestionModel *ephy_suggestion_model_new                     (EphyHistoryService    *history_service,
+                                                                    EphyBookmarksManager  
*bookmarks_manager);
+void                 ephy_suggestion_model_query_async             (EphySuggestionModel   *self,
+                                                                    const gchar           *query,
+                                                                    GCancellable          *cancellable,
+                                                                    GAsyncReadyCallback    callback,
+                                                                    gpointer               user_data);
+gboolean             ephy_suggestion_model_query_finish            (EphySuggestionModel   *self,
+                                                                    GAsyncResult          *result,
+                                                                    GError               **error);
+EphySuggestion      *ephy_suggestion_model_get_suggestion_with_uri (EphySuggestionModel *self,
+                                                                    const char          *uri);
 
 G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index 244f743..23835bf 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -35,7 +35,6 @@ libephymain_sources = [
   'ephy-search-engine-dialog.c',
   'ephy-session.c',
   'ephy-shell.c',
-  'ephy-suggestion.c',
   'ephy-suggestion-model.c',
   'ephy-window.c',
   'passwords-dialog.c',
diff --git a/src/search-provider/ephy-search-provider.c b/src/search-provider/ephy-search-provider.c
index 1f7c130..f3f62a6 100644
--- a/src/search-provider/ephy-search-provider.c
+++ b/src/search-provider/ephy-search-provider.c
@@ -73,7 +73,7 @@ on_model_updated (GObject      *source_object,
     n_items = g_list_model_get_n_items (G_LIST_MODEL (self->model));
     for (guint i = 0; i < n_items; i++) {
       suggestion = g_list_model_get_item (G_LIST_MODEL (self->model), i);
-      g_ptr_array_add (results, g_strdup (dzl_suggestion_get_id (DZL_SUGGESTION (suggestion))));
+      g_ptr_array_add (results, g_strdup (ephy_suggestion_get_uri (suggestion)));
     }
   } else {
     g_warning ("Failed to query suggestion model: %s", error->message);
@@ -199,7 +199,7 @@ handle_get_result_metas (EphyShellSearchProvider2 *skeleton,
       const char *decoded_url;
       const char *title;
 
-      suggestion = ephy_suggestion_model_get_suggestion_with_id (self->model, results[i]);
+      suggestion = ephy_suggestion_model_get_suggestion_with_uri (self->model, results[i]);
       /* FIXME: It's not decoded and it's XML escaped, title is escaped too. Bad! */
       decoded_url = dzl_suggestion_get_subtitle (DZL_SUGGESTION (suggestion));
       title = dzl_suggestion_get_title (DZL_SUGGESTION (suggestion));


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