mailkernel.cpp 3.18 KB
Newer Older
1
/*
2
   SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
3

4
   SPDX-License-Identifier: GPL-2.0-or-later
5
6
7
8
9
*/

#include "mailkernel.h"

#include <AkonadiCore/changerecorder.h>
Laurent Montel's avatar
Laurent Montel committed
10
11
12
13
#include <AkonadiCore/entitymimetypefiltermodel.h>
#include <AkonadiCore/entitytreemodel.h>
#include <AkonadiCore/session.h>
#include <KIdentityManagement/kidentitymanagement/identitymanager.h>
14
#include <KSharedConfig>
Laurent Montel's avatar
Laurent Montel committed
15
16
17
#include <MailCommon/FolderCollectionMonitor>
#include <MailCommon/MailKernel>
#include <MessageComposer/AkonadiSender>
18

Daniel Vrátil's avatar
Daniel Vrátil committed
19
MailKernel::MailKernel(const KSharedConfigPtr &config, QObject *parent)
20
21
    : QObject(parent)
    , mConfig(config)
Laurent Montel's avatar
Laurent Montel committed
22
23
    , mIdentityManager(new KIdentityManagement::IdentityManager(true, this))
    , mMessageSender(new MessageComposer::AkonadiSender(this))
24
{
Laurent Montel's avatar
Laurent Montel committed
25
    auto session = new Akonadi::Session("UnifiedMailbox Kernel ETM", this);
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

    mFolderCollectionMonitor = new MailCommon::FolderCollectionMonitor(session, this);

    mEntityTreeModel = new Akonadi::EntityTreeModel(folderCollectionMonitor(), this);
    mEntityTreeModel->setListFilter(Akonadi::CollectionFetchScope::Enabled);
    mEntityTreeModel->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation);

    mCollectionModel = new Akonadi::EntityMimeTypeFilterModel(this);
    mCollectionModel->setSourceModel(mEntityTreeModel);
    mCollectionModel->addMimeTypeInclusionFilter(Akonadi::Collection::mimeType());
    mCollectionModel->setHeaderGroup(Akonadi::EntityTreeModel::CollectionTreeHeaders);
    mCollectionModel->setDynamicSortFilter(true);
    mCollectionModel->setSortCaseSensitivity(Qt::CaseInsensitive);

    CommonKernel->registerKernelIf(this);
    CommonKernel->registerSettingsIf(this);
}

MailKernel::~MailKernel()
{
    CommonKernel->registerKernelIf(nullptr);
    CommonKernel->registerSettingsIf(nullptr);
}

KIdentityManagement::IdentityManager *MailKernel::identityManager()
{
    return mIdentityManager;
}

MessageComposer::MessageSender *MailKernel::msgSender()
{
    return mMessageSender;
}

Akonadi::EntityMimeTypeFilterModel *MailKernel::collectionModel() const
{
    return mCollectionModel;
}

KSharedConfig::Ptr MailKernel::config()
{
    return mConfig;
}

void MailKernel::syncConfig()
{
    Q_ASSERT(false);
}

MailCommon::JobScheduler *MailKernel::jobScheduler() const
{
    Q_ASSERT(false);
    return nullptr;
}

Akonadi::ChangeRecorder *MailKernel::folderCollectionMonitor() const
{
    return mFolderCollectionMonitor->monitor();
}

void MailKernel::updateSystemTray()
{
    Q_ASSERT(false);
}

bool MailKernel::showPopupAfterDnD()
{
    return false;
}

qreal MailKernel::closeToQuotaThreshold()
{
    return 80;
}

QStringList MailKernel::customTemplates()
{
    Q_ASSERT(false);
    return QStringList();
}

bool MailKernel::excludeImportantMailFromExpiry()
{
    Q_ASSERT(false);
    return true;
}

Akonadi::Collection::Id MailKernel::lastSelectedFolder()
{
    Q_ASSERT(false);
    return Akonadi::Collection::Id();
}

void MailKernel::setLastSelectedFolder(Akonadi::Collection::Id col)
{
Laurent Montel's avatar
Laurent Montel committed
121
    Q_UNUSED(col)
122
123
124
125
126
127
128
129
130
}

void MailKernel::expunge(Akonadi::Collection::Id id, bool sync)
{
    Akonadi::Collection col(id);
    if (col.isValid()) {
        mFolderCollectionMonitor->expunge(Akonadi::Collection(col), sync);
    }
}