From f4e55a41eee7a305cbad050a6c6fec92d6673ab7 Mon Sep 17 00:00:00 2001 From: Abdullah Mohammed Date: Mon, 17 Oct 2022 21:13:29 -0400 Subject: [PATCH 1/4] create custom search engine input --- guake/callbacks.py | 27 +++++++++++++-------- guake/data/org.guake.gschema.xml | 6 ++++- guake/data/prefs.glade | 40 ++++++++++++++++++++++++++++++++ guake/prefs.py | 23 ++++++++++++++++++ 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/guake/callbacks.py b/guake/callbacks.py index 59b77905b..5bc67fe88 100644 --- a/guake/callbacks.py +++ b/guake/callbacks.py @@ -13,10 +13,10 @@ # the urls of the search engine options ENGINES = { - 0: "google.com/search?safe=off&q=", - 1: "duckduckgo.com/", - 2: "bing.com/search?q=", - 3: "yandex.com/search?text=", + 0: "www.google.com/search?safe=off&q=", + 1: "www.duckduckgo.com/", + 2: "www.bing.com/search?q=", + 3: "www.yandex.com/search?text=", } @@ -62,12 +62,19 @@ def on_search_on_web(self, *args): query = clipboard.wait_for_text() query = quote_plus(query) - if query: - # put the query at the end of the url and https - search_url = ( - "https://www." + ENGINES[self.settings.general.get_int("search-engine")] + query - ) - Gtk.show_uri(self.window.get_screen(), search_url, get_server_time(self.window)) + # nothing selected + if not query: + return + + selected = self.settings.general.get_int("search-engine") + # if custom search is selected, get the engine from the 'custom-search-engine' setting + if selected == 4: + engine = self.settings.general.get_string("custom-search-engine") + else: + engine = ENGINES[selected] + # put the query at the end of the url + search_url = "https://" + engine + query + Gtk.show_uri(self.window.get_screen(), search_url, get_server_time(self.window)) def on_quick_open(self, *args): if self.terminal.get_has_selection(): diff --git a/guake/data/org.guake.gschema.xml b/guake/data/org.guake.gschema.xml index a55d8dc78..c8fc8b670 100644 --- a/guake/data/org.guake.gschema.xml +++ b/guake/data/org.guake.gschema.xml @@ -86,7 +86,11 @@ Search engine to use when using web search Search engine to use - + + '' + Search engine to use when using web search + Custom search engine url to use + true Stay on top. diff --git a/guake/data/prefs.glade b/guake/data/prefs.glade index e688935df..729025bbf 100644 --- a/guake/data/prefs.glade +++ b/guake/data/prefs.glade @@ -725,6 +725,7 @@ DuckDuckGo Bing Yandex + Custom @@ -741,6 +742,45 @@ 3 + + + True + False + 4 + + + True + False + Custom Search: + + + False + True + 0 + + + + + 400 + True + True + + www.google.com/search?q=<search is inserted here> + + + + False + True + 1 + + + + + False + True + 4 + + diff --git a/guake/prefs.py b/guake/prefs.py index 8cc6ea3a9..bc3956ebf 100644 --- a/guake/prefs.py +++ b/guake/prefs.py @@ -297,8 +297,23 @@ def on_prompt_on_close_tab_changed(self, combo): self.settings.general.set_int("prompt-on-close-tab", combo.get_active()) def on_search_engine_changed(self, combo): + """ + Sets the 'search-engine' value in dnonf. + Also controls the editability of 'custom_search' input + """ + custom_search = self.prefDlg.get_widget("custom_search") + # if 'Custom' is selected make the search engine input editable + if combo.get_active() == 4: + custom_search.set_sensitive(True) + else: + # make read-only + custom_search.set_sensitive(False) self.settings.general.set_int("search-engine", combo.get_active()) + def on_custom_search_changed(self, edt): + """Sets the 'custom-search-engine' property in dconf""" + self.settings.general.set_string("custom-search-engine", edt.get_text()) + def on_gtk_theme_name_changed(self, combo): """Set the `gtk_theme_name' property in dconf""" citer = combo.get_active_iter() @@ -1050,7 +1065,15 @@ def load_configs(self): # search engine value = self.settings.general.get_int("search-engine") + custom_search = self.get_widget("custom_search") + custom_search.set_text(self.settings.general.get_string("custom-search-engine")) self.get_widget("search_engine_select").set_active(value) + # if 'Custom' is selected make the search engine input editable + if value == 4: + # make read-only + custom_search.set_sensitive(True) + else: + custom_search.set_sensitive(False) # use system theme value = self.settings.general.get_boolean("gtk-use-system-default-theme") From 898893d8715a30a804e7fd259babed7f7ddd14ff Mon Sep 17 00:00:00 2001 From: Abdullah Mohammed Date: Mon, 17 Oct 2022 21:19:43 -0400 Subject: [PATCH 2/4] added slug file --- ...tom_search_on_web_engine-9f0da9d6c4c3882c.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml diff --git a/releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml b/releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml new file mode 100644 index 000000000..7b0c162b3 --- /dev/null +++ b/releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml @@ -0,0 +1,15 @@ +release_summary: > + Replace this text with content to appear at the top of the section for this + release. + + All of the prelude content is merged together and then rendered + separately from the items listed in other parts of the file, so the text + needs to be worded so that both the prelude and the other items make sense + when read independently. + + Do not use "list" syntax here + +features: + - | + - search engine can be set to custom url and search parameter + - Follow up to #2088 and #2133 From adc5235e8c53ccb447d1d58966ee81fcfea92ffd Mon Sep 17 00:00:00 2001 From: Abdullah Mohammed Date: Mon, 17 Oct 2022 21:21:34 -0400 Subject: [PATCH 3/4] fixed slug file --- .../custom_search_on_web_engine-9f0da9d6c4c3882c.yaml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml b/releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml index 7b0c162b3..36d970d4b 100644 --- a/releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml +++ b/releasenotes/notes/custom_search_on_web_engine-9f0da9d6c4c3882c.yaml @@ -1,13 +1,5 @@ release_summary: > - Replace this text with content to appear at the top of the section for this - release. - - All of the prelude content is merged together and then rendered - separately from the items listed in other parts of the file, so the text - needs to be worded so that both the prelude and the other items make sense - when read independently. - - Do not use "list" syntax here + Added input on general in preferences to add a custom url to search with. features: - | From 8d932d84de7ebcd8c9b382467ebd9352fc9431d7 Mon Sep 17 00:00:00 2001 From: Abdullah Mohammed Date: Wed, 19 Oct 2022 06:30:30 -0400 Subject: [PATCH 4/4] using ENGINES dict to check if 'Custom' option is selected plus added Neeva search engine --- guake/callbacks.py | 11 ++--------- guake/data/prefs.glade | 1 + guake/globals.py | 10 ++++++++++ guake/prefs.py | 5 +++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/guake/callbacks.py b/guake/callbacks.py index 5bc67fe88..f52213d23 100644 --- a/guake/callbacks.py +++ b/guake/callbacks.py @@ -9,16 +9,9 @@ from guake.utils import FullscreenManager from guake.utils import HidePrevention from guake.utils import get_server_time +from guake.globals import ENGINES from urllib.parse import quote_plus -# the urls of the search engine options -ENGINES = { - 0: "www.google.com/search?safe=off&q=", - 1: "www.duckduckgo.com/", - 2: "www.bing.com/search?q=", - 3: "www.yandex.com/search?text=", -} - class TerminalContextMenuCallbacks: def __init__(self, terminal, window, settings, notebook): @@ -68,7 +61,7 @@ def on_search_on_web(self, *args): selected = self.settings.general.get_int("search-engine") # if custom search is selected, get the engine from the 'custom-search-engine' setting - if selected == 4: + if selected not in ENGINES: engine = self.settings.general.get_string("custom-search-engine") else: engine = ENGINES[selected] diff --git a/guake/data/prefs.glade b/guake/data/prefs.glade index 729025bbf..f1b2c2db2 100644 --- a/guake/data/prefs.glade +++ b/guake/data/prefs.glade @@ -725,6 +725,7 @@ DuckDuckGo Bing Yandex + Neeva Custom diff --git a/guake/globals.py b/guake/globals.py index cb9dabb77..3410a3347 100644 --- a/guake/globals.py +++ b/guake/globals.py @@ -117,3 +117,13 @@ def is_run_from_git_workdir(): # Constants for vte regex matching are documented in the pcre2 api: # https://www.pcre.org/current/doc/html/pcre2api.html PCRE2_MULTILINE = 0x00000400 + +# the urls of the search engine options for the search on web feature. +# Additional engines should be added +ENGINES = { + 0: "www.google.com/search?safe=off&q=", + 1: "www.duckduckgo.com/", + 2: "www.bing.com/search?q=", + 3: "www.yandex.com/search?text=", + 4: "neeva.com/search?q=", +} diff --git a/guake/prefs.py b/guake/prefs.py index bc3956ebf..21ecf56c8 100644 --- a/guake/prefs.py +++ b/guake/prefs.py @@ -48,6 +48,7 @@ from guake.globals import MAX_TRANSPARENCY from guake.globals import NAME from guake.globals import QUICK_OPEN_MATCHERS +from guake.globals import ENGINES from guake.palettes import PALETTES from guake.paths import AUTOSTART_FOLDER from guake.paths import LOCALE_DIR @@ -303,7 +304,7 @@ def on_search_engine_changed(self, combo): """ custom_search = self.prefDlg.get_widget("custom_search") # if 'Custom' is selected make the search engine input editable - if combo.get_active() == 4: + if combo.get_active() not in ENGINES: custom_search.set_sensitive(True) else: # make read-only @@ -1069,7 +1070,7 @@ def load_configs(self): custom_search.set_text(self.settings.general.get_string("custom-search-engine")) self.get_widget("search_engine_select").set_active(value) # if 'Custom' is selected make the search engine input editable - if value == 4: + if value not in ENGINES: # make read-only custom_search.set_sensitive(True) else: