[epiphany] suggestion: Add unescaped-uri property for the search provider
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] suggestion: Add unescaped-uri property for the search provider
- Date: Sat, 9 Sep 2017 21:44:05 +0000 (UTC)
commit 068b93e9e6870ea01fbd0fa2efe4a3e89846a576
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Sat Sep 9 16:40:51 2017 -0500
suggestion: Add unescaped-uri property for the search provider
The titles produced by the search provider need to be not escaped.
Also, take this opportunity to properly decode the URIs for display.
lib/ephy-suggestion.c | 68 +++++++++++++++++++++++++++-
lib/ephy-suggestion.h | 8 ++--
src/search-provider/ephy-search-provider.c | 14 ++++--
3 files changed, 80 insertions(+), 10 deletions(-)
---
diff --git a/lib/ephy-suggestion.c b/lib/ephy-suggestion.c
index 8e7803c..1f970f7 100644
--- a/lib/ephy-suggestion.c
+++ b/lib/ephy-suggestion.c
@@ -26,10 +26,54 @@
struct _EphySuggestion {
DzlSuggestion parent;
+
+ char *unescaped_title;
};
G_DEFINE_TYPE (EphySuggestion, ephy_suggestion, DZL_TYPE_SUGGESTION)
+enum {
+ PROP_0,
+ PROP_UNESCAPED_TITLE,
+ LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
+static void
+ephy_suggestion_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphySuggestion *self = EPHY_SUGGESTION (object);
+
+ switch (prop_id) {
+ case PROP_UNESCAPED_TITLE:
+ self->unescaped_title = g_strdup (g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_suggestion_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphySuggestion *self = EPHY_SUGGESTION (object);
+
+ switch (prop_id) {
+ case PROP_UNESCAPED_TITLE:
+ g_value_set_string (value, self->unescaped_title);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
char *
ephy_suggestion_replace_typed_text (DzlSuggestion *self,
const char *typed_text)
@@ -46,9 +90,22 @@ ephy_suggestion_replace_typed_text (DzlSuggestion *self,
static void
ephy_suggestion_class_init (EphySuggestionClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
DzlSuggestionClass *dzl_suggestion_class = DZL_SUGGESTION_CLASS (klass);
+ object_class->get_property = ephy_suggestion_get_property;
+ object_class->set_property = ephy_suggestion_set_property;
+
dzl_suggestion_class->replace_typed_text = ephy_suggestion_replace_typed_text;
+
+ obj_properties[PROP_UNESCAPED_TITLE] =
+ g_param_spec_string ("unescaped-title",
+ "Unescaped title",
+ "The title of the suggestion, not XML-escaped",
+ "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
}
static void
@@ -68,8 +125,9 @@ ephy_suggestion_new (const char *title,
suggestion = g_object_new (EPHY_TYPE_SUGGESTION,
"icon-name", "web-browser-symbolic",
"id", uri,
- "title", escaped_title,
"subtitle", escaped_uri,
+ "title", escaped_title,
+ "unescaped-title", title,
NULL);
g_free (escaped_title);
@@ -80,6 +138,14 @@ ephy_suggestion_new (const char *title,
}
const char *
+ephy_suggestion_get_unescaped_title (EphySuggestion *self)
+{
+ g_assert (EPHY_IS_SUGGESTION (self));
+
+ return self->unescaped_title;
+}
+
+const char *
ephy_suggestion_get_uri (EphySuggestion *self)
{
g_assert (EPHY_IS_SUGGESTION (self));
diff --git a/lib/ephy-suggestion.h b/lib/ephy-suggestion.h
index c225363..ef9cda1 100644
--- a/lib/ephy-suggestion.h
+++ b/lib/ephy-suggestion.h
@@ -27,9 +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);
-
-const char *ephy_suggestion_get_uri (EphySuggestion *self);
+EphySuggestion *ephy_suggestion_new (const char *title,
+ const char *uri);
+const char *ephy_suggestion_get_unescaped_title (EphySuggestion *self);
+const char *ephy_suggestion_get_uri (EphySuggestion *self);
G_END_DECLS
diff --git a/src/search-provider/ephy-search-provider.c b/src/search-provider/ephy-search-provider.c
index f3f62a6..1334c93 100644
--- a/src/search-provider/ephy-search-provider.c
+++ b/src/search-provider/ephy-search-provider.c
@@ -28,6 +28,7 @@
#include "ephy-profile-utils.h"
#include "ephy-shell.h"
#include "ephy-suggestion-model.h"
+#include "ephy-uri-helpers.h"
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
@@ -196,22 +197,25 @@ handle_get_result_metas (EphyShellSearchProvider2 *skeleton,
g_variant_builder_close (&builder);
} else {
EphySuggestion *suggestion;
- const char *decoded_url;
const char *title;
+ const char *uri;
+ char *decoded_uri;
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));
+ title = ephy_suggestion_get_unescaped_title (suggestion);
+ uri = ephy_suggestion_get_uri (suggestion);
+ decoded_uri = ephy_uri_decode (uri);
g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}",
- "id", g_variant_new_string (decoded_url));
+ "id", g_variant_new_string (decoded_uri));
g_variant_builder_add (&builder, "{sv}",
"name", g_variant_new_string (title));
g_variant_builder_add (&builder, "{sv}",
"gicon", g_variant_new_string ("text-html"));
g_variant_builder_close (&builder);
+
+ g_free (decoded_uri);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]