File indexing completed on 2025-01-19 04:51:20

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "kcmknotessummary.h"
0007 
0008 #include <Akonadi/NoteUtils>
0009 
0010 #include <PimCommonAkonadi/CheckedCollectionWidget>
0011 
0012 #include <Akonadi/ETMViewStateSaver>
0013 
0014 #include <KAboutData>
0015 #include <KAcceleratorManager>
0016 #include <KCheckableProxyModel>
0017 #include <KLocalizedString>
0018 #include <KPluginFactory>
0019 #include <KSharedConfig>
0020 
0021 #include <QCheckBox>
0022 #include <QTreeView>
0023 #include <QVBoxLayout>
0024 
0025 K_PLUGIN_CLASS_WITH_JSON(KCMKNotesSummary, "kcmknotessummary.json")
0026 
0027 KCMKNotesSummary::KCMKNotesSummary(QObject *parent, const KPluginMetaData &data)
0028     : KCModule(parent, data)
0029 {
0030     initGUI();
0031 
0032     connect(mCheckedCollectionWidget->folderTreeView(), &QAbstractItemView::clicked, this, &KCMKNotesSummary::modified);
0033 
0034     KAcceleratorManager::manage(widget());
0035 
0036     load();
0037 }
0038 
0039 void KCMKNotesSummary::modified()
0040 {
0041     markAsChanged();
0042 }
0043 
0044 void KCMKNotesSummary::initGUI()
0045 {
0046     auto layout = new QVBoxLayout(widget());
0047     layout->setContentsMargins(0, 0, 0, 0);
0048 
0049     mCheckedCollectionWidget = new PimCommon::CheckedCollectionWidget(Akonadi::NoteUtils::noteMimeType());
0050     layout->addWidget(mCheckedCollectionWidget);
0051 }
0052 
0053 void KCMKNotesSummary::initFolders()
0054 {
0055     KSharedConfigPtr _config = KSharedConfig::openConfig(QStringLiteral("kcmknotessummaryrc"));
0056 
0057     mModelState = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(_config->group(QStringLiteral("CheckState")), widget());
0058     mModelState->setSelectionModel(mCheckedCollectionWidget->selectionModel());
0059 }
0060 
0061 void KCMKNotesSummary::loadFolders()
0062 {
0063     mModelState->restoreState();
0064 }
0065 
0066 void KCMKNotesSummary::storeFolders()
0067 {
0068     KConfig config(QStringLiteral("kcmknotessummaryrc"));
0069     mModelState->saveState();
0070     config.sync();
0071 }
0072 
0073 void KCMKNotesSummary::load()
0074 {
0075     initFolders();
0076     loadFolders();
0077 
0078     setNeedsSave(false);
0079 }
0080 
0081 void KCMKNotesSummary::save()
0082 {
0083     storeFolders();
0084     setNeedsSave(false);
0085 }
0086 
0087 void KCMKNotesSummary::defaults()
0088 {
0089     markAsChanged();
0090 }
0091 
0092 #include "kcmknotessummary.moc"
0093 
0094 #include "moc_kcmknotessummary.cpp"