Skip to content

Commit c104404

Browse files
committed
Settings: Add search engines Bing, Brave, Coccinellidae SerenityOS Search, DuckDuckGo, FrogFind, GitHub, Google, Mojeek, Yandex
1 parent 46eb88c commit c104404

File tree

5 files changed

+51
-14
lines changed

5 files changed

+51
-14
lines changed

Settings.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ void Settings::set_homepage(QString const& homepage)
2323
m_qsettings->setValue("homepage", homepage);
2424
}
2525

26+
QString Settings::search_engine()
27+
{
28+
return m_qsettings->value("search_engine", "brave").toString();
29+
}
30+
31+
void Settings::set_search_engine(QString const& search_engine)
32+
{
33+
m_qsettings->setValue("search_engine", search_engine);
34+
}
2635
}

Settings.h

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Settings {
2020
QString homepage();
2121
void set_homepage(QString const& homepage);
2222

23+
QString search_engine();
24+
void set_search_engine(QString const& search_engine);
25+
2326
private:
2427
QSettings* m_qsettings;
2528
};

SettingsDialog.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "SettingsDialog.h"
99
#include <QCloseEvent>
1010
#include <QLabel>
11+
#include <QComboBox>
1112

1213
extern Browser::Settings* s_settings;
1314

@@ -16,10 +17,23 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
1617
{
1718
m_layout = new QFormLayout;
1819
m_homepage = new QLineEdit;
20+
m_search_engine = new QComboBox; // FIXME: Saved search engine should be preselected in QComboBox
1921
m_ok_button = new QPushButton("&Save");
2022

2123
m_layout->addWidget(new QLabel("Homepage"));
2224
m_layout->addWidget(m_homepage);
25+
m_layout->addWidget(new QLabel("Search engine"));
26+
m_search_engine->addItem("Bing", QVariant("bing"));
27+
m_search_engine->addItem("Brave (Default)", QVariant("brave"));
28+
m_search_engine->addItem("Coccinellidae SerenityOS Search", QVariant("coccinellidae-serenityos-search"));
29+
m_search_engine->addItem("DuckDuckGo", QVariant("duckduckgo"));
30+
m_search_engine->addItem("FrogFind", QVariant("frogfind"));
31+
m_search_engine->addItem("GitHub", QVariant("github"));
32+
m_search_engine->addItem("Google", QVariant("google"));
33+
m_search_engine->addItem("Mojeek", QVariant("mojeek"));
34+
m_search_engine->addItem("Yandex", QVariant("yandex"));
35+
m_layout->addWidget(m_search_engine);
36+
// FIXME: Should add field for custom search engine.
2337
m_layout->addWidget(m_ok_button);
2438

2539
m_homepage->setText(s_settings->homepage());
@@ -28,7 +42,7 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
2842
close();
2943
});
3044

31-
setWindowTitle("Settings");
45+
setWindowTitle("Preferences");
3246
setFixedWidth(300);
3347
setLayout(m_layout);
3448
show();
@@ -45,4 +59,6 @@ void SettingsDialog::save()
4559
{
4660
// FIXME: Validate data.
4761
s_settings->set_homepage(m_homepage->text());
62+
63+
s_settings->set_search_engine(m_search_engine->currentData().toString());
4864
}

SettingsDialog.h

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <QMainWindow>
1010
#include <QLineEdit>
1111
#include <QPushButton>
12+
#include <QComboBox>
1213

1314
#pragma once
1415

@@ -25,5 +26,6 @@ class SettingsDialog : public QDialog {
2526
QFormLayout* m_layout;
2627
QPushButton* m_ok_button { nullptr };
2728
QLineEdit* m_homepage { nullptr };
29+
QComboBox* m_search_engine { nullptr };
2830
QMainWindow* m_window { nullptr };
2931
};

Tab.cpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,26 @@ void Tab::location_edit_return_pressed()
209209
void Tab::search_edit_return_pressed()
210210
{
211211
QString user_input = m_search_edit->text();
212-
user_input.prepend("https://search.brave.com/search?q=");
213-
214-
/*
215-
* Bing https://www.bing.com/search?q={}
216-
* Brave https://search.brave.com/search?q={} (Default)
217-
* Coccinellidae SerenityOS Search https://search.coccinellidae.serenityos.net/search?q=
218-
* DuckDuckGo https://duckduckgo.com/?q={}
219-
* FrogFind https://frogfind.com/?q={}
220-
* GitHub https://github.com/search?q={}
221-
* Google https://google.com/search?q={}
222-
* Mojeek https://www.mojeek.com/search?q={}
223-
* Yandex https://yandex.com/search/?text={}
224-
*/
212+
213+
if (s_settings->search_engine() == "bing") {
214+
user_input.prepend("https://www.bing.com/search?q=");
215+
} else if (s_settings->search_engine() == "brave") {
216+
user_input.prepend("https://search.brave.com/search?q=");
217+
} else if (s_settings->search_engine() == "coccinellidae-serenityos-search") {
218+
user_input.prepend("https://search.coccinellidae.serenityos.net/search?q=");
219+
} else if (s_settings->search_engine() == "duckduckgo") {
220+
user_input.prepend("https://duckduckgo.com/?q=");
221+
} else if (s_settings->search_engine() == "frogfind") {
222+
user_input.prepend("https://frogfind.com/?q=");
223+
} else if (s_settings->search_engine() == "github") {
224+
user_input.prepend("https://github.com/search?q=");
225+
} else if (s_settings->search_engine() == "google") {
226+
user_input.prepend("https://google.com/search?q=");
227+
} else if (s_settings->search_engine() == "mojeek") {
228+
user_input.prepend("https://www.mojeek.com/search?q=");
229+
} else if (s_settings->search_engine() == "yandex") {
230+
user_input.prepend("https://yandex.com/search/?text=");
231+
}
225232

226233
navigate(user_input);
227234
}

0 commit comments

Comments
 (0)