Skip to content

Commit 2335f84

Browse files
PhantomLelDavidy22
authored andcommittedOct 20, 2022
create custom search engine input
1 parent 50c1944 commit 2335f84

File tree

4 files changed

+85
-11
lines changed

4 files changed

+85
-11
lines changed
 

‎guake/callbacks.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
# the urls of the search engine options
1515
ENGINES = {
16-
0: "google.com/search?safe=off&q=",
17-
1: "duckduckgo.com/",
18-
2: "bing.com/search?q=",
19-
3: "yandex.com/search?text=",
16+
0: "www.google.com/search?safe=off&q=",
17+
1: "www.duckduckgo.com/",
18+
2: "www.bing.com/search?q=",
19+
3: "www.yandex.com/search?text=",
2020
}
2121

2222

@@ -62,12 +62,19 @@ def on_search_on_web(self, *args):
6262
query = clipboard.wait_for_text()
6363
query = quote_plus(query)
6464

65-
if query:
66-
# put the query at the end of the url and https
67-
search_url = (
68-
"https://www." + ENGINES[self.settings.general.get_int("search-engine")] + query
69-
)
70-
Gtk.show_uri(self.window.get_screen(), search_url, get_server_time(self.window))
65+
# nothing selected
66+
if not query:
67+
return
68+
69+
selected = self.settings.general.get_int("search-engine")
70+
# if custom search is selected, get the engine from the 'custom-search-engine' setting
71+
if selected == 4:
72+
engine = self.settings.general.get_string("custom-search-engine")
73+
else:
74+
engine = ENGINES[selected]
75+
# put the query at the end of the url
76+
search_url = "https://" + engine + query
77+
Gtk.show_uri(self.window.get_screen(), search_url, get_server_time(self.window))
7178

7279
def on_quick_open(self, *args):
7380
if self.terminal.get_has_selection():

‎guake/data/org.guake.gschema.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@
8686
<summary>Search engine to use when using web search</summary>
8787
<description>Search engine to use</description>
8888
</key>
89-
89+
<key name="custom-search-engine" type="s">
90+
<default>''</default>
91+
<summary>Search engine to use when using web search</summary>
92+
<description>Custom search engine url to use</description>
93+
</key>
9094
<key name="window-ontop" type="b">
9195
<default>true</default>
9296
<summary>Stay on top.</summary>

‎guake/data/prefs.glade

+40
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@
725725
<item translatable="yes">DuckDuckGo</item>
726726
<item translatable="yes">Bing</item>
727727
<item translatable="yes">Yandex</item>
728+
<item translatable="yes">Custom</item>
728729
</items>
729730
<signal name="changed" handler="on_search_engine_changed" swapped="no"/>
730731
</object>
@@ -741,6 +742,45 @@
741742
<property name="position">3</property>
742743
</packing>
743744
</child>
745+
<child>
746+
<object class="GtkBox">
747+
<property name="visible">True</property>
748+
<property name="can-focus">False</property>
749+
<property name="spacing">4</property>
750+
<child>
751+
<object class="GtkLabel" id="lbl_custom_search">
752+
<property name="visible">True</property>
753+
<property name="can-focus">False</property>
754+
<property name="label" translatable="yes">Custom Search:</property>
755+
</object>
756+
<packing>
757+
<property name="expand">False</property>
758+
<property name="fill">True</property>
759+
<property name="position">0</property>
760+
</packing>
761+
</child>
762+
<child>
763+
<object class="GtkEntry" id="custom_search">
764+
<property name="width-request">400</property>
765+
<property name="visible">True</property>
766+
<property name="can-focus">True</property>
767+
<property name="invisible-char">•</property>
768+
<property name="placeholder-text" translatable="yes">www.google.com/search?q=&lt;search is inserted here&gt;</property>
769+
<signal name="changed" handler="on_custom_search_changed" swapped="no"/>
770+
</object>
771+
<packing>
772+
<property name="expand">False</property>
773+
<property name="fill">True</property>
774+
<property name="position">1</property>
775+
</packing>
776+
</child>
777+
</object>
778+
<packing>
779+
<property name="expand">False</property>
780+
<property name="fill">True</property>
781+
<property name="position">4</property>
782+
</packing>
783+
</child>
744784
</object>
745785
</child>
746786
</object>

‎guake/prefs.py

+23
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,23 @@ def on_prompt_on_close_tab_changed(self, combo):
297297
self.settings.general.set_int("prompt-on-close-tab", combo.get_active())
298298

299299
def on_search_engine_changed(self, combo):
300+
"""
301+
Sets the 'search-engine' value in dnonf.
302+
Also controls the editability of 'custom_search' input
303+
"""
304+
custom_search = self.prefDlg.get_widget("custom_search")
305+
# if 'Custom' is selected make the search engine input editable
306+
if combo.get_active() == 4:
307+
custom_search.set_sensitive(True)
308+
else:
309+
# make read-only
310+
custom_search.set_sensitive(False)
300311
self.settings.general.set_int("search-engine", combo.get_active())
301312

313+
def on_custom_search_changed(self, edt):
314+
"""Sets the 'custom-search-engine' property in dconf"""
315+
self.settings.general.set_string("custom-search-engine", edt.get_text())
316+
302317
def on_gtk_theme_name_changed(self, combo):
303318
"""Set the `gtk_theme_name' property in dconf"""
304319
citer = combo.get_active_iter()
@@ -1050,7 +1065,15 @@ def load_configs(self):
10501065

10511066
# search engine
10521067
value = self.settings.general.get_int("search-engine")
1068+
custom_search = self.get_widget("custom_search")
1069+
custom_search.set_text(self.settings.general.get_string("custom-search-engine"))
10531070
self.get_widget("search_engine_select").set_active(value)
1071+
# if 'Custom' is selected make the search engine input editable
1072+
if value == 4:
1073+
# make read-only
1074+
custom_search.set_sensitive(True)
1075+
else:
1076+
custom_search.set_sensitive(False)
10541077

10551078
# use system theme
10561079
value = self.settings.general.get_boolean("gtk-use-system-default-theme")

0 commit comments

Comments
 (0)
Please sign in to comment.