Change to singleton AlligatorSettings class

This commit is contained in:
Bart De Vries 2021-04-09 16:55:05 +02:00
parent 81c2ad90d1
commit 436e66542a
4 changed files with 17 additions and 15 deletions

View File

@ -4,4 +4,5 @@ Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
Singleton=true

View File

@ -93,9 +93,8 @@ int Database::version()
void Database::cleanup()
{
AlligatorSettings settings;
int count = settings.deleteAfterCount();
int type = settings.deleteAfterType();
int count = AlligatorSettings::self()->deleteAfterCount();
int type = AlligatorSettings::self()->deleteAfterType();
if (type == 0) { // Never delete Entries
return;

View File

@ -63,6 +63,10 @@ int main(int argc, char *argv[])
engine->setObjectOwnership(&DataManager::instance(), QQmlEngine::CppOwnership);
return &DataManager::instance();
});
qmlRegisterSingletonType<AlligatorSettings>("org.kde.alligator", 1, 0, "AlligatorSettings", [](QQmlEngine *engine, QJSEngine *) -> QObject * {
engine->setObjectOwnership(AlligatorSettings::self(), QQmlEngine::CppOwnership);
return AlligatorSettings::self();
});
QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
@ -81,11 +85,8 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty(QStringLiteral("_aboutData"), QVariant::fromValue(about));
AlligatorSettings settings;
engine.rootContext()->setContextProperty(QStringLiteral("_settings"), &settings);
QObject::connect(&app, &QCoreApplication::aboutToQuit, &settings, &AlligatorSettings::save);
// Make sure that settings are saved before the application exits
QObject::connect(&app, &QCoreApplication::aboutToQuit, AlligatorSettings::self(), &AlligatorSettings::save);
Database::instance();

View File

@ -10,6 +10,7 @@ import QtQuick.Controls 2.14 as Controls
import QtQuick.Layouts 1.14
import org.kde.kirigami 2.12 as Kirigami
import org.kde.alligator 1.0
Kirigami.ScrollablePage {
title: i18n("Settings")
@ -27,25 +28,25 @@ Kirigami.ScrollablePage {
id: numberNewEpisodes
Kirigami.FormData.label: i18n("# of episodes to label as new when adding a new subscription:")
value: _settings.numberNewEpisodes
value: AlligatorSettings.numberNewEpisodes
onValueModified: _settings.numberNewEpisodes = value
onValueModified: AlligatorSettings.numberNewEpisodes = value
}
Controls.CheckBox {
id: autoDownload
checked: _settings.autoDownload
checked: AlligatorSettings.autoDownload
text: i18n("Automatically download new episodes")
onToggled: _settings.autoDownload = checked
onToggled: AlligatorSettings.autoDownload = checked
}
Controls.CheckBox {
id: allowStreaming
checked: _settings.allowStreaming
checked: AlligatorSettings.allowStreaming
text: i18n("Allow streaming of audio")
onToggled: _settings.allowStreaming = checked
onToggled: AlligatorSettings.allowStreaming = checked
}
}