1
0
forked from blue/squawk
squawk/ui/widgets/settings/settings.cpp

70 lines
2.0 KiB
C++

#include "settings.h"
#include "ui_settings.h"
Settings::Settings(QWidget* parent):
QWidget(parent),
m_ui(new Ui::Settings()),
modifiedSettings()
{
m_ui->setupUi(this);
connect(m_ui->list, &QListWidget::currentItemChanged, this, &Settings::onCurrentPageChanged);
connect(m_ui->General, &PageGeneral::variableModified, this, &Settings::onVariableModified);
connect(m_ui->Appearance, &PageAppearance::variableModified, this, &Settings::onVariableModified);
connect(m_ui->applyButton, &QPushButton::clicked, this, &Settings::apply);
connect(m_ui->okButton, &QPushButton::clicked, this, &Settings::confirm);
connect(m_ui->cancelButton, &QPushButton::clicked, this, &Settings::close);
}
Settings::~Settings()
{
}
void Settings::onCurrentPageChanged(QListWidgetItem* current)
{
if (current != nullptr) {
m_ui->header->setText(current->text());
m_ui->content->setCurrentIndex(m_ui->list->currentRow());
}
}
void Settings::onVariableModified(const QString& key, const QVariant& value)
{
modifiedSettings[key] = value;
}
void Settings::apply()
{
QSettings settings;
for (const std::pair<const QString, QVariant>& pair: modifiedSettings) {
if (pair.first == "style") {
Shared::Global::setStyle(pair.second.toString());
settings.setValue(pair.first, pair.second);
} else if (pair.first == "theme") {
Shared::Global::setTheme(pair.second.toString());
settings.setValue(pair.first, pair.second);
} else if (pair.first == "downloadsPath") {
QString path = pair.second.toString();
if (!Shared::isSubdirectoryOfSettings(path)) {
path = Shared::getAbsoluteWritablePath(path);
if (path.size() > 0) {
settings.setValue(pair.first, path);
emit changeDownloadsPath(path);
}
}
}
}
modifiedSettings.clear();
}
void Settings::confirm()
{
apply();
close();
}