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

search engine can be set to preference #2125

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions guake/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def on_reset_terminal(self, *args):
self.terminal.reset(True, True)

def on_find(self):
# this is not implemented jet
# this is not implemented yet
pass

def on_open_link(self, *args):
Expand All @@ -53,8 +53,18 @@ def on_search_on_web(self, *args):
clipboard = Gtk.Clipboard.get_default(self.window.get_display())
query = clipboard.wait_for_text()
query = quote_plus(query)

# the urls of the search engine options
ENGINES = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This dict should probably be declared outside of this function, don't need to recreate this dict every time we open a link

0 : "google.com/search?safe=off&q=",
1 : "duckduckgo.com/",
2 : "bing.com/search?q=",
3 : "yandex.com/search?text="
}

if query:
search_url = f"https://www.google.com/search?q={query}&safe=off"
# 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))

def on_quick_open(self, *args):
Expand Down
6 changes: 6 additions & 0 deletions guake/data/org.guake.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<summary>Prompt when closing tabs.</summary>
<description>0: Never 1: If process is running 2: Always. Also prompts on quit.</description>
</key>
<key name="search-engine" type="i">
<default>0</default>
<summary>Search engine to use when using web search</summary>
<description>Search engine to use</description>
</key>

<key name="window-ontop" type="b">
<default>true</default>
<summary>Stay on top.</summary>
Expand Down
61 changes: 58 additions & 3 deletions guake/data/prefs.glade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface domain="guake">
<requires lib="gtk+" version="3.18"/>
<object class="GtkAdjustment" id="cell_height_scale_adjustment">
Expand Down Expand Up @@ -135,7 +135,7 @@
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="margin-top">6</property>
<property name="label" translatable="yes">&lt;span size="18000"&gt;&lt;b&gt;Guake properties&lt;/b&gt;&lt;/span&gt;</property>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo introduced?

<property name="label" translatable="yes">&lt;span size="18000"&gt;&lt;b&gt;Guakproperties&lt;/b&gt;&lt;/span&gt;</property>
<property name="use-markup">True</property>
</object>
<packing>
Expand Down Expand Up @@ -224,7 +224,7 @@
<property name="can-focus">False</property>
<property name="left-padding">12</property>
<child>
<!-- n-columns=3 n-rows=3 -->
<!-- n-columns=3 n-rows=4 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -299,6 +299,15 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
Expand Down Expand Up @@ -689,6 +698,49 @@
<property name="position">2</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="lb_search_engine">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Search Engine: </property>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally don't want to do spacing by just adding a bunch of spaces when doing UI work. I assume you did this to make a UI element line up somewhere, but if you want to do that you should use columns. The spaces are difficult for the translators to understand and match, just strip the spaces and if you want to do a re-layout that can be another pr

</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="search_engine_select">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
<items>
<item translatable="yes">Google</item>
<item translatable="yes">DuckDuckGo</item>
<item translatable="yes">Bing</item>
<item translatable="yes">Yandex</item>
</items>
<signal name="changed" handler="on_search_engine_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">3</property>
</packing>
</child>
</object>
</child>
</object>
Expand All @@ -698,6 +750,9 @@
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="tab">
Expand Down
8 changes: 8 additions & 0 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ def on_prompt_on_close_tab_changed(self, combo):
"""Set the `prompt_on_close_tab' property in dconf"""
self.settings.general.set_int("prompt-on-close-tab", combo.get_active())

def on_search_engine_changed(self, combo):
print("VALUE: ", combo.get_active())
Copy link
Collaborator

Choose a reason for hiding this comment

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

We want to use the logging functions over prints so that users can control log levels

self.settings.general.set_int("search-engine", combo.get_active())

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 @@ -1045,6 +1049,10 @@ def load_configs(self):
self.get_widget("prompt_on_close_tab").set_active(value)
self.get_widget("prompt_on_quit").set_sensitive(value != 2)

# search engine
value = self.settings.general.get_int("search-engine")
self.get_widget("search_engine_select").set_active(value)

# use system theme
value = self.settings.general.get_boolean("gtk-use-system-default-theme")
self.get_widget("gtk_use_system_default_theme").set_active(value)
Expand Down