File indexing completed on 2024-11-24 04:50:44

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