diff --git a/src/alligatorsettings.kcfgc b/src/alligatorsettings.kcfgc index c524e2c2..e1226458 100644 --- a/src/alligatorsettings.kcfgc +++ b/src/alligatorsettings.kcfgc @@ -4,4 +4,5 @@ Mutators=true DefaultValueGetters=true GenerateProperties=true ParentInConstructor=true - +Singleton=true + diff --git a/src/database.cpp b/src/database.cpp index 5b0dbeb9..2c4c8b26 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 954dcd3e..c15d0a7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,6 +63,10 @@ int main(int argc, char *argv[]) engine->setObjectOwnership(&DataManager::instance(), QQmlEngine::CppOwnership); return &DataManager::instance(); }); + qmlRegisterSingletonType("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(); diff --git a/src/qml/SettingsPage.qml b/src/qml/SettingsPage.qml index 24fd68f7..d1cba822 100644 --- a/src/qml/SettingsPage.qml +++ b/src/qml/SettingsPage.qml @@ -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 } }