forked from LadybirdBrowser/ancient-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsDialog.cpp
68 lines (58 loc) · 2.9 KB
/
SettingsDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2022, Filiph Sandström <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Settings.h"
#include "SettingsDialog.h"
#include <QCloseEvent>
#include <QLabel>
#include <QComboBox>
extern Browser::Settings* s_settings;
SettingsDialog::SettingsDialog(QMainWindow* window)
: m_window(window)
{
m_layout = new QFormLayout;
m_homepage = new QLineEdit;
m_search_engine = new QComboBox; // FIXME: Saved search engine should be preselected in QComboBox
m_ok_button = new QPushButton("&Save");
m_layout->addWidget(new QLabel("Homepage"));
m_layout->addWidget(m_homepage);
m_layout->addWidget(new QLabel("Search engine"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-bananaslug.png")), "BananaSLUG", QVariant("bananaslug"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-bing.png")), "Bing", QVariant("bing"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-brave.png")), "Brave (Default)", QVariant("brave"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/app-coccinellidae.png")), "Coccinellidae Search", QVariant("coccinellidae-serenityos-search"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-duckduckgo.png")), "DuckDuckGo", QVariant("duckduckgo"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-frogfind.png")), "FrogFind", QVariant("frogfind"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-github.png")), "GitHub", QVariant("github"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-google.png")), "Google", QVariant("google"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-metager.png")), "metaGer", QVariant("metager"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-mojeek.png")), "Mojeek", QVariant("mojeek"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-yandex.png")), "Yandex", QVariant("yandex"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-wikipedia.png")), "Wikipedia", QVariant("wikipedia"));
m_search_engine->addItem(QIcon(QString("../icons/16x16/website-wolframalpha.png")), "WolframAlpha", QVariant("wolframalpha"));
m_layout->addWidget(m_search_engine);
// FIXME: Should add field for custom search engine.
m_layout->addWidget(m_ok_button);
m_homepage->setText(s_settings->homepage());
QObject::connect(m_ok_button, &QPushButton::released, this, [this] {
close();
});
setWindowTitle("Preferences");
setFixedWidth(400);
setLayout(m_layout);
show();
setFocus();
}
void SettingsDialog::closeEvent(QCloseEvent *event)
{
save();
event->accept();
}
void SettingsDialog::save()
{
// FIXME: Validate data.
s_settings->set_homepage(m_homepage->text());
s_settings->set_search_engine(m_search_engine->currentData().toString());
}