Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom search engine input #2088 #2134

Merged
merged 4 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions guake/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: "google.com/search?safe=off&q=",
1: "duckduckgo.com/",
2: "bing.com/search?q=",
3: "yandex.com/search?text=",
}


class TerminalContextMenuCallbacks:
def __init__(self, terminal, window, settings, notebook):
Expand Down Expand Up @@ -62,12 +55,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 not in ENGINES:
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():
Expand Down
6 changes: 5 additions & 1 deletion guake/data/org.guake.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@
<summary>Search engine to use when using web search</summary>
<description>Search engine to use</description>
</key>

<key name="custom-search-engine" type="s">
<default>''</default>
<summary>Search engine to use when using web search</summary>
<description>Custom search engine url to use</description>
</key>
<key name="window-ontop" type="b">
<default>true</default>
<summary>Stay on top.</summary>
Expand Down
41 changes: 41 additions & 0 deletions guake/data/prefs.glade
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@
<item translatable="yes">DuckDuckGo</item>
<item translatable="yes">Bing</item>
<item translatable="yes">Yandex</item>
<item translatable="yes">Neeva</item>
<item translatable="yes">Custom</item>
</items>
<signal name="changed" handler="on_search_engine_changed" swapped="no"/>
</object>
Expand All @@ -741,6 +743,45 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel" id="lbl_custom_search">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Custom Search:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="custom_search">
<property name="width-request">400</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="invisible-char">•</property>
<property name="placeholder-text" translatable="yes">www.google.com/search?q=&lt;search is inserted here&gt;</property>
<signal name="changed" handler="on_custom_search_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
10 changes: 10 additions & 0 deletions guake/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=",
}
24 changes: 24 additions & 0 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -297,8 +298,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() not in ENGINES:
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()
Expand Down Expand Up @@ -1050,7 +1066,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 not in ENGINES:
# 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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
release_summary: >
Added input on general in preferences to add a custom url to search with.

features:
- |
- search engine can be set to custom url and search parameter
- Follow up to #2088 and #2133