[epiphany] Revert "Implement search engine manager"
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Revert "Implement search engine manager"
- Date: Thu, 26 Jan 2017 14:39:12 +0000 (UTC)
commit a0545a9e59f982b381e2e2329756edd89ac04aed
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Thu Jan 26 08:38:44 2017 -0600
Revert "Implement search engine manager"
This reverts commit 2829c4330285ddc50243aaabb3ab89971c540af9.
Didn't mean to commit this, it's not quite ready yet.
data/Makefile.am | 6 +-
data/org.gnome.epiphany.search.engines.gschema.xml | 24 ---
embed/ephy-embed-shell.c | 14 --
embed/ephy-embed-shell.h | 3 +-
embed/ephy-embed-utils.c | 25 +--
lib/Makefile.am | 2 -
lib/ephy-search-engine-manager.c | 215 --------------------
lib/ephy-search-engine-manager.h | 47 -----
src/prefs-dialog.c | 115 ++++++++----
src/search-provider/ephy-search-provider.c | 26 +--
10 files changed, 103 insertions(+), 374 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 6d1b850..d6aa63e 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -10,9 +10,7 @@ $(desktop_DATA): $(desktop_in_files)
gsettings_ENUM_NAMESPACE = org.gnome.Epiphany
gsettings_ENUM_FILES = $(top_srcdir)/lib/ephy-prefs.h
-gsettings_SCHEMAS = org.gnome.epiphany.gschema.xml \
- org.gnome.epiphany.host.gschema.xml \
- org.gnome.epiphany.search.engines.gschema.xml
+gsettings_SCHEMAS = org.gnome.epiphany.gschema.xml org.gnome.epiphany.host.gschema.xml
@GSETTINGS_RULES@
appstream_in_files = org.gnome.Epiphany.appdata.xml.in
@@ -26,7 +24,7 @@ $(appstream_XML): $(appstream_in_files)
servicedir = $(datadir)/dbus-1/services
service_in_files = org.gnome.EpiphanySearchProvider.service.in
service_DATA = $(service_in_files:.service.in=.service)
-
+
# Rule to make the service file with bindir expanded
$(service_DATA): $(service_in_files) Makefile
$(AM_V_GEN) sed -e "s|\@libexecdir[@]|$(libexecdir)|g" $< > $@
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 4556ae9..101caf9 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -70,7 +70,6 @@ typedef struct {
GList *web_extensions;
EphyFiltersManager *filters_manager;
GCancellable *cancellable;
- EphySearchEngineManager *search_engine_manager;
} EphyEmbedShellPrivate;
enum {
@@ -125,7 +124,6 @@ ephy_embed_shell_dispose (GObject *object)
g_clear_object (&priv->web_context);
g_clear_object (&priv->dbus_server);
g_clear_object (&priv->filters_manager);
- g_clear_object (&priv->search_engine_manager);
G_OBJECT_CLASS (ephy_embed_shell_parent_class)->dispose (object);
}
@@ -957,8 +955,6 @@ ephy_embed_shell_startup (GApplication *application)
ephy_embed_prefs_set_cookie_accept_policy (cookie_manager, cookie_policy);
g_free (cookie_policy);
- priv->search_engine_manager = ephy_search_engine_manager_new ();
-
#ifdef HAVE_LIBHTTPSEVERYWHERE
/* We might want to be smarter about this in the future. For now,
* trigger an update of the rulesets once each time Epiphany is started.
@@ -1441,13 +1437,3 @@ ephy_embed_shell_get_hosts_manager (EphyEmbedShell *shell)
priv->hosts_manager = ephy_hosts_manager_new ();
return priv->hosts_manager;
}
-
-EphySearchEngineManager *
-ephy_embed_shell_get_search_engine_manager (EphyEmbedShell *shell)
-{
- EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
-
- if (!priv->search_engine_manager)
- priv->search_engine_manager = ephy_search_engine_manager_new ();
- return priv->search_engine_manager;
-}
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index 4fc5d05..e327e7e 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -25,7 +25,6 @@
#include "ephy-downloads-manager.h"
#include "ephy-history-service.h"
#include "ephy-hosts-manager.h"
-#include "ephy-search-engine-manager.h"
G_BEGIN_DECLS
@@ -80,5 +79,5 @@ void ephy_embed_shell_schedule_thumbnail_update (EphyEmbedShell
WebKitUserContentManager *ephy_embed_shell_get_user_content_manager (EphyEmbedShell *shell);
EphyDownloadsManager *ephy_embed_shell_get_downloads_manager (EphyEmbedShell *shell);
EphyHostsManager *ephy_embed_shell_get_hosts_manager (EphyEmbedShell *shell);
-EphySearchEngineManager *ephy_embed_shell_get_search_engine_manager (EphyEmbedShell *shell);
+
G_END_DECLS
diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c
index 81bb4b9..90dcd95 100644
--- a/embed/ephy-embed-utils.c
+++ b/embed/ephy-embed-utils.c
@@ -29,10 +29,10 @@
#include "ephy-string.h"
#include "ephy-view-source-handler.h"
-#include <JavaScriptCore/JavaScript.h>
+#include <string.h>
#include <glib/gi18n.h>
#include <libsoup/soup.h>
-#include <string.h>
+#include <JavaScriptCore/JavaScript.h>
static GRegex *non_search_regex;
static GRegex *domain_regex;
@@ -230,20 +230,15 @@ ephy_embed_utils_normalize_address (const char *address)
char *
ephy_embed_utils_autosearch_address (const char *search_key)
{
- char *query_param;
- const char *url_search;
- char *default_name;
+ char *query_param, *url_search;
char *effective_address;
- EphyEmbedShell *shell;
- EphySearchEngineManager *search_engine_manager;
-
- shell = ephy_embed_shell_get_default ();
- search_engine_manager = ephy_embed_shell_get_search_engine_manager (shell);
- default_name = ephy_search_engine_manager_get_default_engine (search_engine_manager);
- url_search = ephy_search_engine_manager_get_url (search_engine_manager, default_name);
- if (url_search == NULL || url_search[0] == '\0')
- url_search = _("https://duckduckgo.com/?q=%s&t=epiphany");
+ url_search = g_settings_get_string (EPHY_SETTINGS_MAIN,
+ EPHY_PREFS_KEYWORD_SEARCH_URL);
+ if (url_search == NULL || url_search[0] == '\0') {
+ g_free (url_search);
+ url_search = g_strdup (_("https://duckduckgo.com/?q=%s&t=epiphany"));
+ }
query_param = soup_form_encode ("q", search_key, NULL);
#pragma GCC diagnostic push
@@ -253,7 +248,7 @@ ephy_embed_utils_autosearch_address (const char *search_key)
effective_address = g_strdup_printf (url_search, query_param + 2);
#pragma GCC diagnostic pop
g_free (query_param);
- g_free (default_name);
+ g_free (url_search);
return effective_address;
}
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 07b99fa..784dc1c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -30,8 +30,6 @@ libephymisc_la_SOURCES = \
ephy-prefs.h \
ephy-profile-utils.c \
ephy-profile-utils.h \
- ephy-search-engine-manager.c \
- ephy-search-engine-manager.h \
ephy-security-levels.c \
ephy-security-levels.h \
ephy-settings.c \
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 3f9e16b..d1c16a4 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -147,6 +147,7 @@ typedef struct {
enum {
SEARCH_ENGINE_COL_NAME,
+ SEARCH_ENGINE_COL_STOCK_URL,
SEARCH_ENGINE_COL_URL,
SEARCH_ENGINE_NUM_COLS
};
@@ -659,7 +660,7 @@ combo_get_mapping (GValue *value,
while (valid) {
char *item_name;
- gtk_tree_model_get (model, &iter, 0, &item_name, -1);
+ gtk_tree_model_get (model, &iter, 1, &item_name, -1);
if (g_strcmp0 (item_name, settings_name) == 0) {
g_value_set_int (value, i);
@@ -692,7 +693,7 @@ combo_set_mapping (const GValue *value,
if (valid) {
char *item_name;
- gtk_tree_model_get (model, &iter, 0, &item_name, -1);
+ gtk_tree_model_get (model, &iter, 1, &item_name, -1);
variant = g_variant_new_string (item_name);
@@ -1340,23 +1341,82 @@ cookies_set_mapping (const GValue *value,
}
static void
-search_engine_combo_add_search_engines (GtkListStore *store,
- EphySearchEngineManager *manager)
+search_engine_combo_add_default_engines (GtkListStore *store)
{
- guint i, n_engines;
- gchar **engines_names ;
- engines_names = ephy_search_engine_manager_get_names (manager);
- n_engines = g_strv_length (engines_names);
-
- for (i = 0; i < n_engines; i++) {
- const char *name = engines_names[i];
- const char *url = ephy_search_engine_manager_get_url (manager, name);
+ guint i;
+ const char *default_engines[][3] = { /* Search engine option in the preferences dialog */
+ { N_("DuckDuckGo"),
+ "https://duckduckgo.com/?q=%s&t=epiphany",
+ /* For the preferences dialog. Must exactly match the URL
+ * you chose in the gschema, but with & instead of &
+ * If the match is not exact, there will be a spurious, ugly
+ * entry in the preferences combo, so please test this. */
+ N_("https://duckduckgo.com/?q=%s&t=epiphany") },
+ /* Search engine option in the preferences dialog */
+ { N_("Google"),
+ "https://google.com/search?q=%s",
+ /* For the preferences dialog. Consider a regional variant, like google.co.uk */
+ N_("https://google.com/search?q=%s") },
+ /* Search engine option in the preferences dialog */
+ { N_("Bing"),
+ "https://www.bing.com/search?q=%s",
+ /* For the preferences dialog. Consider a regional variant, like uk.bing.com */
+ N_("https://www.bing.com/search?q=%s") }
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (default_engines); ++i) {
gtk_list_store_insert_with_values (store, NULL, -1,
- SEARCH_ENGINE_COL_NAME, name,
- SEARCH_ENGINE_COL_URL, url,
+ SEARCH_ENGINE_COL_NAME,
+ _(default_engines[i][0]),
+ SEARCH_ENGINE_COL_STOCK_URL,
+ default_engines[i][1],
+ SEARCH_ENGINE_COL_URL,
+ _(default_engines[i][2]),
-1);
}
- g_strfreev (engines_names);
+}
+
+/* Has the user manually set the engine to something not in the combo?
+ * If so, add that URL as an extra item in the combo. */
+static void
+search_engine_combo_add_current_engine (GtkListStore *store)
+{
+ GtkTreeIter iter;
+ char *original_url;
+ gboolean in_combo = FALSE;
+ gboolean has_next = FALSE;
+
+ original_url = g_settings_get_string (EPHY_SETTINGS_MAIN,
+ EPHY_PREFS_KEYWORD_SEARCH_URL);
+ if (!original_url)
+ return;
+
+ has_next = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
+
+ while (!in_combo && has_next) {
+ char *stock_url, *url;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
+ SEARCH_ENGINE_COL_STOCK_URL, &stock_url,
+ SEARCH_ENGINE_COL_URL, &url, -1);
+
+ if (strcmp (original_url, stock_url) == 0 ||
+ strcmp (original_url, url) == 0)
+ in_combo = TRUE;
+
+ g_free (stock_url);
+ g_free (url);
+ has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
+ }
+
+ if (!in_combo)
+ gtk_list_store_insert_with_values (store, NULL, -1,
+ SEARCH_ENGINE_COL_NAME, original_url,
+ SEARCH_ENGINE_COL_STOCK_URL, original_url,
+ SEARCH_ENGINE_COL_URL, original_url,
+ -1);
+
+ g_free (original_url);
}
static void
@@ -1364,45 +1424,30 @@ create_search_engine_combo (GtkComboBox *combo)
{
GtkCellRenderer *renderer;
GtkListStore *store;
- char *default_search_engine;
- GSettings *search_engine_settings;
- EphyEmbedShell *shell;
- EphySearchEngineManager *search_engine_manager;
-
- shell = ephy_embed_shell_get_default ();
- search_engine_manager = ephy_embed_shell_get_search_engine_manager (shell);
store = GTK_LIST_STORE (gtk_combo_box_get_model (combo));
- search_engine_combo_add_search_engines (store, search_engine_manager);
+ search_engine_combo_add_default_engines (store);
+ search_engine_combo_add_current_engine (store);
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
- SEARCH_ENGINE_COL_NAME,
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), SEARCH_ENGINE_COL_NAME,
GTK_SORT_ASCENDING);
gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
- default_search_engine = ephy_search_engine_manager_get_default_engine (search_engine_manager);
-
- gtk_combo_box_set_id_column (combo, SEARCH_ENGINE_COL_NAME);
- gtk_combo_box_set_active_id (combo, default_search_engine);
-
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
"text", SEARCH_ENGINE_COL_NAME,
NULL);
- search_engine_settings = ephy_search_engine_manager_get_settings (search_engine_manager);
-
- g_settings_bind_with_mapping (search_engine_settings,
- "default-search-engine",
+ g_settings_bind_with_mapping (EPHY_SETTINGS_MAIN,
+ EPHY_PREFS_KEYWORD_SEARCH_URL,
combo, "active",
G_SETTINGS_BIND_DEFAULT,
combo_get_mapping,
combo_set_mapping,
combo,
NULL);
- g_free (default_search_engine);
}
static gboolean
diff --git a/src/search-provider/ephy-search-provider.c b/src/search-provider/ephy-search-provider.c
index b912886..0926a38 100644
--- a/src/search-provider/ephy-search-provider.c
+++ b/src/search-provider/ephy-search-provider.c
@@ -29,11 +29,11 @@
#include "ephy-profile-utils.h"
#include "ephy-shell.h"
+#include <string.h>
+#include <glib/gi18n.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
-#include <glib/gi18n.h>
#include <libsoup/soup.h>
-#include <string.h>
struct _EphySearchProvider {
GApplication parent_instance;
@@ -278,21 +278,15 @@ launch_search (EphySearchProvider *self,
char **terms,
guint timestamp)
{
- char *search_string;
- const char *url_search;
- char *query_param;
- char *effective_url;
- char *default_name;
- EphyEmbedShell *shell;
- EphySearchEngineManager *search_engine_manager;
+ char *search_string, *url_search, *query_param, *effective_url;
+
+ url_search = g_settings_get_string (self->settings, EPHY_PREFS_KEYWORD_SEARCH_URL);
- shell = ephy_embed_shell_get_default ();
- search_engine_manager = ephy_embed_shell_get_search_engine_manager (shell);
- default_name = ephy_search_engine_manager_get_default_engine (search_engine_manager);
- url_search = ephy_search_engine_manager_get_url (search_engine_manager, default_name);
+ if (url_search == NULL || url_search[0] == '\0') {
+ g_free (url_search);
- if (url_search == NULL || url_search[0] == '\0')
- url_search = _("https://duckduckgo.com/?q=%s&t=epiphany");
+ url_search = g_strdup (_("https://duckduckgo.com/?q=%s&t=epiphany"));
+ }
search_string = g_strjoinv (" ", terms);
query_param = soup_form_encode ("q", search_string, NULL);
@@ -307,9 +301,9 @@ launch_search (EphySearchProvider *self,
launch_uri (effective_url, timestamp);
g_free (query_param);
+ g_free (url_search);
g_free (effective_url);
g_free (search_string);
- g_free (default_name);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]