summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@igalia.com>2017-08-27 21:40:12 -0500
committerMichael Catanzaro <mcatanzaro@igalia.com>2017-08-27 21:40:12 -0500
commit2e7c37ddaa8deb515470ca6eed433130b6e4825d (patch)
treeb1e4f5437f5d48502ba66c497c91e3df4ed88cfb
parent98ca0c47541c9ffa7ce17a2940d56f72302e79ad (diff)
downloadepiphany-dazzle.tar.gz
Implement DzlSuggestion vfuncsdazzle
-rw-r--r--src/ephy-suggestion-model.c37
-rw-r--r--src/ephy-suggestion-model.h2
-rw-r--r--src/ephy-suggestion.c92
-rw-r--r--src/ephy-suggestion.h33
-rw-r--r--src/meson.build1
5 files changed, 137 insertions, 28 deletions
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index a843ef5ff..023b05cfa 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
- * Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
+ * Copyright © 2017 Christian Hergert <chergert@redhat.com>
*
* 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
@@ -19,6 +19,8 @@
#include "config.h"
#include "ephy-suggestion-model.h"
+#include "ephy-suggestion.h"
+
#include <dazzle.h>
#include <glib/gi18n.h>
@@ -135,7 +137,7 @@ ephy_suggestion_model_init (EphySuggestionModel *self)
static GType
ephy_suggestion_model_get_item_type (GListModel *model)
{
- return DZL_TYPE_SUGGESTION;
+ return EPHY_TYPE_SUGGESTION;
}
static guint
@@ -324,20 +326,11 @@ query_completed_cb (EphyHistoryService *service,
title = ephy_bookmark_get_title (bookmark);
if (should_add_bookmark_to_model (self, query, title, url)) {
- DzlSuggestion *suggestion;
- char *escaped_url = g_markup_escape_text (url, -1);
- char *escaped_title = g_markup_escape_text (title, -1);
-
- suggestion = g_object_new (DZL_TYPE_SUGGESTION,
- "title", escaped_url,
- "subtitle", escaped_title,
- "id", url,
- NULL);
+ EphySuggestion *suggestion;
+
+ suggestion = ephy_suggestion_new (title, url);
g_sequence_append (self->items, suggestion);
added++;
-
- g_free (escaped_url);
- g_free (escaped_title);
}
}
@@ -346,21 +339,11 @@ query_completed_cb (EphyHistoryService *service,
for (const GList *p = g_list_last (urls); p != NULL; p = p->prev) {
EphyHistoryURL *url = (EphyHistoryURL *)p->data;
- DzlSuggestion *suggestion;
- char *escaped_url = g_markup_escape_text (url->url, -1);
- char *escaped_title = g_markup_escape_text (url->title, -1);
-
- suggestion = g_object_new (DZL_TYPE_SUGGESTION,
- "icon-name", "web-browser-symbolic",
- "id", url->url,
- "title", escaped_url,
- "subtitle", escaped_title,
- NULL);
+ EphySuggestion *suggestion;
+
+ suggestion = ephy_suggestion_new (url->title, url->url);
g_sequence_prepend (self->items, suggestion);
added++;
-
- g_free (escaped_url);
- g_free (escaped_title);
}
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
diff --git a/src/ephy-suggestion-model.h b/src/ephy-suggestion-model.h
index 613e9aab9..625789076 100644
--- a/src/ephy-suggestion-model.h
+++ b/src/ephy-suggestion-model.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
- * Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
+ * Copyright © 2017 Christian Hergert <chergert@redhat.com>
*
* 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/src/ephy-suggestion.c b/src/ephy-suggestion.c
new file mode 100644
index 000000000..66dc5a5d0
--- /dev/null
+++ b/src/ephy-suggestion.c
@@ -0,0 +1,92 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Igalia S.L.
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "ephy-suggestion.h"
+
+#include <dazzle.h>
+#include <glib.h>
+#include <string.h>
+
+struct _EphySuggestion {
+ DzlSuggestion parent;
+};
+
+G_DEFINE_TYPE (EphySuggestion, ephy_suggestion, DZL_TYPE_SUGGESTION)
+
+char *
+ephy_suggestion_suggest_suffix (DzlSuggestion *self,
+ const char *typed_text)
+{
+ const char *suffix;
+ const char *url;
+
+ if (typed_text == NULL || strlen (typed_text) == 0 ||
+ g_str_has_prefix ("www.", typed_text) ||
+ g_str_has_prefix ("http://www.", typed_text) ||
+ g_str_has_prefix ("https://www.", typed_text))
+ return NULL;
+
+ url = dzl_suggestion_get_id (self);
+ suffix = strstr (url, typed_text);
+
+ return suffix ? g_strdup (&suffix[strlen (typed_text)]) : NULL;
+}
+
+char *
+ephy_suggestion_replace_typed_text (DzlSuggestion *self,
+ const char *typed_text)
+{
+ const char *url = dzl_suggestion_get_id (self);
+
+ return g_strdup (url);
+}
+
+static void
+ephy_suggestion_class_init (EphySuggestionClass *klass)
+{
+ DzlSuggestionClass *dzl_suggestion_class = DZL_SUGGESTION_CLASS (klass);
+
+ dzl_suggestion_class->suggest_suffix = ephy_suggestion_suggest_suffix;
+ dzl_suggestion_class->replace_typed_text = ephy_suggestion_replace_typed_text;
+}
+
+static void
+ephy_suggestion_init (EphySuggestion *self)
+{
+}
+
+EphySuggestion *
+ephy_suggestion_new (const char *title,
+ const char *uri)
+{
+ EphySuggestion *suggestion;
+ char *escaped_title = g_markup_escape_text (title, -1);
+ char *escaped_uri = g_markup_escape_text (uri, -1);
+
+ suggestion = g_object_new (EPHY_TYPE_SUGGESTION,
+ "icon-name", "web-browser-symbolic",
+ "id", uri,
+ "title", escaped_title,
+ "subtitle", escaped_uri,
+ NULL);
+ g_free (escaped_title);
+ g_free (escaped_uri);
+
+ return suggestion;
+}
diff --git a/src/ephy-suggestion.h b/src/ephy-suggestion.h
new file mode 100644
index 000000000..2cbdd319c
--- /dev/null
+++ b/src/ephy-suggestion.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Igalia S.L.
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <dazzle.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_SUGGESTION (ephy_suggestion_get_type())
+
+G_DECLARE_FINAL_TYPE (EphySuggestion, ephy_suggestion, EPHY, SUGGESTION, DzlSuggestion)
+
+// FIXME: How about favicon?
+EphySuggestion *ephy_suggestion_new (const char *title,
+ const char *uri);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index b6e219718..ba46af732 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -35,6 +35,7 @@ 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',