[system/kcron] src: Store viewState in state config
Nicolas Fella <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit c74009689da6d1266d5b5a72099dcf6d352b54e9 by Nicolas Fella.
Committed on 27/07/2026 at 13:40.
Pushed by nicolasfella into branch 'master'.
Store viewState in state config
M +1 -0 src/CMakeLists.txt
M +2 -0 src/kcmCron.cpp
A +35 -0 src/state.cpp [License: GPL(v2.0+)]
A +20 -0 src/state.h [License: GPL(v2.0+)]
M +5 -6 src/ui/main.qml
https://invent.kde.org/system/kcron/-/commit/c74009689da6d1266d5b5a72099dcf6d352b54e9
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 36a9768..4a046c1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -45,6 +45,7 @@ target_sources(kcm_cron PRIVATE
taskvalidator.cpp taskvalidator.h
kcmCron.cpp kcmCron.h
+ state.cpp state.h
)
target_link_libraries(kcm_cron
diff --git a/src/kcmCron.cpp b/src/kcmCron.cpp
index 6c15c8c..0c957dc 100644
--- a/src/kcmCron.cpp
+++ b/src/kcmCron.cpp
@@ -13,6 +13,7 @@
#include "ctInitializationError.h"
#include "ctcron.h"
#include "cthost.h"
+#include "state.h"
#include "task.h"
#include "tasksmodel.h"
#include "taskvalidator.h"
@@ -158,6 +159,7 @@ void KCMCron::registerTypes()
qmlRegisterUncreatableType<VariablesModel>(uri, 1, 0, "VariablesModel", QStringLiteral("Cannot create instances of VariablesModel"));
qmlRegisterUncreatableType<TasksModel>(uri, 1, 0, "TasksModel", QStringLiteral("Cannot create instances of TasksModel"));
qmlRegisterType<TaskValidator>(uri, 1, 0, "TaskValidator");
+ qmlRegisterType<State>(uri, 1, 0, "KCronState");
}
CTCron *KCMCron::currentCron()
diff --git a/src/state.cpp b/src/state.cpp
new file mode 100644
index 0000000..98d2924
--- /dev/null
+++ b/src/state.cpp
@@ -0,0 +1,35 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Nicolas Fella <[email protected]>
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "state.h"
+
+#include <KConfig>
+#include <KConfigGroup>
+
+#include <QSettings>
+
+State::State()
+ : QObject()
+{
+ QSettings settings;
+ if (settings.contains("viewState")) {
+ setViewState(settings.value("viewState").toByteArray());
+ settings.remove("viewState");
+ }
+}
+
+QByteArray State::viewState()
+{
+ const KConfig stateConfig(QStringLiteral("kcronstaterc"), KConfig::SimpleConfig, QStandardPaths::GenericStateLocation);
+ return stateConfig.group(QStringLiteral("General")).readEntry("viewState", QByteArray());
+}
+
+void State::setViewState(const QByteArray &state)
+{
+ KConfig stateConfig(QStringLiteral("kcronstaterc"), KConfig::SimpleConfig, QStandardPaths::GenericStateLocation);
+ stateConfig.group(QStringLiteral("General")).writeEntry("viewState", state);
+
+ Q_EMIT viewStateChanged();
+}
diff --git a/src/state.h b/src/state.h
new file mode 100644
index 0000000..e6541b5
--- /dev/null
+++ b/src/state.h
@@ -0,0 +1,20 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Nicolas Fella <[email protected]>
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#pragma once
+
+#include <QObject>
+
+class State : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QByteArray viewState READ viewState WRITE setViewState NOTIFY viewStateChanged)
+
+public:
+ State();
+
+ [[nodiscard]] QByteArray viewState();
+ void setViewState(const QByteArray &state);
+ Q_SIGNAL void viewStateChanged();
+};
diff --git a/src/ui/main.qml b/src/ui/main.qml
index a047be5..ac027c8 100644
--- a/src/ui/main.qml
+++ b/src/ui/main.qml
@@ -11,6 +11,7 @@ import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.kcmutils as KCM
+import org.kde.private.kcms.cron
KCM.AbstractKCM {
id: root
@@ -83,14 +84,12 @@ KCM.AbstractKCM {
}
}
- Settings {
- id: persistentSettings
-
- property var viewState
+ KCronState {
+ id: stateData
}
- Component.onCompleted: view.restoreState(persistentSettings.viewState)
- Component.onDestruction: persistentSettings.viewState = view.saveState()
+ Component.onCompleted: view.restoreState(stateData.viewState)
+ Component.onDestruction: stateData.viewState = view.saveState()
Connections {
target: kcm