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 3 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
27 changes: 17 additions & 10 deletions guake/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=",
}


Expand Down Expand Up @@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for the custom option should be checking to see if it's the last index. Hardcoding to 4 can generate unexpected bugs if the list of preset search engines changes length in the future.

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
40 changes: 40 additions & 0 deletions guake/data/prefs.glade
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
<item translatable="yes">DuckDuckGo</item>
<item translatable="yes">Bing</item>
<item translatable="yes">Yandex</item>
<item translatable="yes">Custom</item>
</items>
<signal name="changed" handler="on_search_engine_changed" swapped="no"/>
</object>
Expand All @@ -741,6 +742,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
23 changes: 23 additions & 0 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar deal here

# 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