[pim/korganizer] src: Persist checked calendars by stable remote path
David Faure <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 0d4385f39858cf8047a8489e3797dec5486d25de by David Faure.
Committed on 05/08/2026 at 12:22.
Pushed by winterz into branch 'master'.
Persist checked calendars by stable remote path
Use ETMViewStateSaver's RemotePathKeys format and saveStateKeepingMissingCollections(),
so the calendar selection survives a resource re-listing its collections with new ids,
and isn't wiped when quitting before the asynchronous restore has finished.
M +21 -6 src/actionmanager.cpp
M +4 -1 src/actionmanager.h
https://invent.kde.org/pim/korganizer/-/commit/0d4385f39858cf8047a8489e3797dec5486d25de
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index 0e1325f9e..616f167de 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -76,6 +76,14 @@
#include <QToolBar>
#include <QWindow>
+namespace
+{
+KConfigGroup collectionSelectionGroup()
+{
+ return KSharedConfig::openConfig()->group(QStringLiteral("GlobalCollectionSelection"));
+}
+}
+
KOWindowList *ActionManager::mWindowList = nullptr;
ActionManager::ActionManager(KXMLGUIClient *client,
@@ -109,7 +117,6 @@ ActionManager::~ActionManager()
// Take this window out of the window list.
mWindowList->removeWindow(mMainWindow);
- delete mCollectionSelectionModelStateSaver;
delete mCollectionViewStateSaver;
delete mCalendarView;
@@ -186,8 +193,7 @@ void ActionManager::createCalendarAkonadi()
Q_ASSERT(calendar());
KSharedConfig::Ptr config = KSharedConfig::openConfig();
- mCollectionSelectionModelStateSaver = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(config->group(QStringLiteral("GlobalCollectionSelection")));
- mCollectionSelectionModelStateSaver->setSelectionModel(calendar()->checkableProxyModel()->selectionModel());
+ mCollectionSelectionModel = calendar()->checkableProxyModel()->selectionModel();
AkonadiCollectionViewFactory factory(mCalendarView);
mCalendarView->addExtension(&factory);
@@ -871,7 +877,12 @@ void ActionManager::readSettings()
void ActionManager::restoreCollectionViewSetting()
{
- mCollectionSelectionModelStateSaver->restoreState();
+ // The saver deletes itself once the model is populated (or after its own timeout).
+ auto *selectionSaver = new Akonadi::ETMViewStateSaver;
+ selectionSaver->setSelectionModel(mCollectionSelectionModel);
+ const KConfigGroup group = collectionSelectionGroup();
+ selectionSaver->restoreState(group);
+
mCollectionViewStateSaver->restoreState();
}
@@ -898,10 +909,14 @@ void ActionManager::writeSettings()
}
mCollectionViewStateSaver->saveState();
- mCollectionSelectionModelStateSaver->saveState();
+
+ Akonadi::ETMViewStateSaver selectionSaver;
+ selectionSaver.setKeyFormat(Akonadi::ETMViewStateSaver::RemotePathKeys);
+ selectionSaver.setSelectionModel(mCollectionSelectionModel);
+ KConfigGroup selectionGroup = collectionSelectionGroup();
+ selectionSaver.saveState(selectionGroup);
KConfigGroup selectionViewGroup = config->group(QStringLiteral("GlobalCollectionView"));
- KConfigGroup selectionGroup = config->group(QStringLiteral("GlobalCollectionSelection"));
selectionGroup.sync();
selectionViewGroup.sync();
config->sync();
diff --git a/src/actionmanager.h b/src/actionmanager.h
index 85de65ad2..352e4ce45 100644
--- a/src/actionmanager.h
+++ b/src/actionmanager.h
@@ -37,6 +37,7 @@ class ETMViewStateSaver;
}
class QAction;
+class QItemSelectionModel;
class QMenuBar;
class QToolBar;
class KSelectAction;
@@ -361,6 +362,8 @@ private:
AkonadiCollectionView *mCollectionView = nullptr;
KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionViewStateSaver = nullptr;
- KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionSelectionModelStateSaver = nullptr;
+ // The checked calendars are saved/restored directly (see actionmanager.cpp), because they need
+ // a non-default key format and the safer save. Not owned.
+ QItemSelectionModel *mCollectionSelectionModel = nullptr;
KHamburgerMenu *mHamburgerMenu = nullptr;
};