File indexing completed on 2024-12-22 05:00:55

0001 /*
0002    SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "mailkernel.h"
0008 
0009 #include <Akonadi/ChangeRecorder>
0010 #include <Akonadi/EntityMimeTypeFilterModel>
0011 #include <Akonadi/EntityTreeModel>
0012 #include <Akonadi/Session>
0013 #include <KIdentityManagementCore/IdentityManager>
0014 #include <KSharedConfig>
0015 #include <MailCommon/FolderCollectionMonitor>
0016 #include <MailCommon/MailKernel>
0017 #include <MessageComposer/AkonadiSender>
0018 
0019 MailKernel::MailKernel(const KSharedConfigPtr &config, QObject *parent)
0020     : QObject(parent)
0021     , mConfig(config)
0022     , mIdentityManager(new KIdentityManagementCore::IdentityManager(true, this))
0023     , mMessageSender(new MessageComposer::AkonadiSender(this))
0024 {
0025     auto session = new Akonadi::Session("UnifiedMailbox Kernel ETM", this);
0026 
0027     mFolderCollectionMonitor = new MailCommon::FolderCollectionMonitor(session, this);
0028 
0029     mEntityTreeModel = new Akonadi::EntityTreeModel(folderCollectionMonitor(), this);
0030     mEntityTreeModel->setListFilter(Akonadi::CollectionFetchScope::Enabled);
0031     mEntityTreeModel->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation);
0032 
0033     mCollectionModel = new Akonadi::EntityMimeTypeFilterModel(this);
0034     mCollectionModel->setSourceModel(mEntityTreeModel);
0035     mCollectionModel->addMimeTypeInclusionFilter(Akonadi::Collection::mimeType());
0036     mCollectionModel->setHeaderGroup(Akonadi::EntityTreeModel::CollectionTreeHeaders);
0037     mCollectionModel->setDynamicSortFilter(true);
0038     mCollectionModel->setSortCaseSensitivity(Qt::CaseInsensitive);
0039 
0040     CommonKernel->registerKernelIf(this);
0041     CommonKernel->registerSettingsIf(this);
0042 }
0043 
0044 MailKernel::~MailKernel()
0045 {
0046     CommonKernel->registerKernelIf(nullptr);
0047     CommonKernel->registerSettingsIf(nullptr);
0048 }
0049 
0050 KIdentityManagementCore::IdentityManager *MailKernel::identityManager()
0051 {
0052     return mIdentityManager;
0053 }
0054 
0055 MessageComposer::MessageSender *MailKernel::msgSender()
0056 {
0057     return mMessageSender;
0058 }
0059 
0060 Akonadi::EntityMimeTypeFilterModel *MailKernel::collectionModel() const
0061 {
0062     return mCollectionModel;
0063 }
0064 
0065 KSharedConfig::Ptr MailKernel::config()
0066 {
0067     return mConfig;
0068 }
0069 
0070 void MailKernel::syncConfig()
0071 {
0072     Q_ASSERT(false);
0073 }
0074 
0075 MailCommon::JobScheduler *MailKernel::jobScheduler() const
0076 {
0077     Q_ASSERT(false);
0078     return nullptr;
0079 }
0080 
0081 Akonadi::ChangeRecorder *MailKernel::folderCollectionMonitor() const
0082 {
0083     return mFolderCollectionMonitor->monitor();
0084 }
0085 
0086 void MailKernel::updateSystemTray()
0087 {
0088     Q_ASSERT(false);
0089 }
0090 
0091 bool MailKernel::showPopupAfterDnD()
0092 {
0093     return false;
0094 }
0095 
0096 qreal MailKernel::closeToQuotaThreshold()
0097 {
0098     return 80;
0099 }
0100 
0101 QStringList MailKernel::customTemplates()
0102 {
0103     Q_ASSERT(false);
0104     return {};
0105 }
0106 
0107 bool MailKernel::excludeImportantMailFromExpiry()
0108 {
0109     Q_ASSERT(false);
0110     return true;
0111 }
0112 
0113 Akonadi::Collection::Id MailKernel::lastSelectedFolder()
0114 {
0115     Q_ASSERT(false);
0116     return Akonadi::Collection::Id();
0117 }
0118 
0119 void MailKernel::setLastSelectedFolder(Akonadi::Collection::Id col)
0120 {
0121     Q_UNUSED(col)
0122 }
0123 
0124 void MailKernel::expunge(Akonadi::Collection::Id id, bool sync)
0125 {
0126     Akonadi::Collection col(id);
0127     if (col.isValid()) {
0128         mFolderCollectionMonitor->expunge(Akonadi::Collection(col), sync);
0129     }
0130 }
0131 
0132 #include "moc_mailkernel.cpp"