kcmknotessummary.cpp 2.61 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   SPDX-FileCopyrightText: 2013-2021 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3

4
   SPDX-License-Identifier: GPL-2.0-or-later
5
6
7
8
9
*/
#include "kcmknotessummary.h"

#include <Akonadi/Notes/NoteUtils>

Laurent Montel's avatar
Laurent Montel committed
10
#include <PimCommonAkonadi/CheckedCollectionWidget>
11
12
13

#include <AkonadiWidgets/ETMViewStateSaver>

Laurent Montel's avatar
Laurent Montel committed
14
#include "knotes_kontact_plugin_debug.h"
15
16
17
18
#include <KAboutData>
#include <KAcceleratorManager>
#include <KCheckableProxyModel>
#include <KLocalizedString>
19
#include <KPluginFactory>
20
21
22
23
24
25
#include <KSharedConfig>

#include <QCheckBox>
#include <QTreeView>
#include <QVBoxLayout>

26
K_PLUGIN_FACTORY_WITH_JSON(KCMKNotesSummaryFactory, "kcmknotessummary.json", registerPlugin<KCMKNotesSummary>();)
27

28
29
KCMKNotesSummary::KCMKNotesSummary(QWidget *parent, const QVariantList &args)
    : KCModule(parent, args)
30
31
32
{
    initGUI();

Laurent Montel's avatar
Laurent Montel committed
33
    connect(mCheckedCollectionWidget->folderTreeView(), &QAbstractItemView::clicked, this, &KCMKNotesSummary::modified);
34
35
36
37
38

    KAcceleratorManager::manage(this);

    load();

Laurent Montel's avatar
Laurent Montel committed
39
40
41
42
43
44
    auto about = new KAboutData(QStringLiteral("kcmknotessummary"),
                                i18n("kcmknotessummary"),
                                QString(),
                                i18n("Notes Summary Configuration Dialog"),
                                KAboutLicense::GPL,
                                i18n("Copyright © 2013-2021 Laurent Montel <montel@kde.org>"));
45
46
47
48
49
50
    about->addAuthor(ki18n("Laurent Montel").toString(), QString(), QStringLiteral("montel@kde.org"));
    setAboutData(about);
}

void KCMKNotesSummary::modified()
{
Laurent Montel's avatar
Laurent Montel committed
51
    Q_EMIT changed(true);
52
53
54
55
}

void KCMKNotesSummary::initGUI()
{
56
    auto layout = new QVBoxLayout(this);
Laurent Montel's avatar
Laurent Montel committed
57
    layout->setContentsMargins(0, 0, 0, 0);
58
59
60
61
62
63
64
65
66

    mCheckedCollectionWidget = new PimCommon::CheckedCollectionWidget(Akonadi::NoteUtils::noteMimeType());
    layout->addWidget(mCheckedCollectionWidget);
}

void KCMKNotesSummary::initFolders()
{
    KSharedConfigPtr _config = KSharedConfig::openConfig(QStringLiteral("kcmknotessummaryrc"));

Laurent Montel's avatar
Laurent Montel committed
67
    mModelState = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(_config->group("CheckState"), this);
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    mModelState->setSelectionModel(mCheckedCollectionWidget->selectionModel());
}

void KCMKNotesSummary::loadFolders()
{
    mModelState->restoreState();
}

void KCMKNotesSummary::storeFolders()
{
    KConfig config(QStringLiteral("kcmknotessummaryrc"));
    mModelState->saveState();
    config.sync();
}

void KCMKNotesSummary::load()
{
    initFolders();
    loadFolders();

Laurent Montel's avatar
Laurent Montel committed
88
    Q_EMIT changed(false);
89
90
91
92
93
94
}

void KCMKNotesSummary::save()
{
    storeFolders();

Laurent Montel's avatar
Laurent Montel committed
95
    Q_EMIT changed(false);
96
97
98
99
}

void KCMKNotesSummary::defaults()
{
Laurent Montel's avatar
Laurent Montel committed
100
    Q_EMIT changed(true);
101
}
102
103

#include "kcmknotessummary.moc"