File indexing completed on 2024-12-22 05:01:16
0001 /* 0002 SPDX-FileCopyrightText: 2010-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "collectionpane.h" 0008 #include "kmkernel.h" 0009 #include <MailCommon/MailKernel> 0010 0011 #include <Akonadi/MessageFolderAttribute> 0012 #include <KIdentityManagementCore/Identity> 0013 #include <KIdentityManagementCore/IdentityManager> 0014 #include <MailCommon/FolderSettings> 0015 #include <PimCommonAkonadi/MailUtil> 0016 0017 using namespace MailCommon; 0018 0019 CollectionPane::CollectionPane(bool restoreSession, QAbstractItemModel *model, QItemSelectionModel *selectionModel, QWidget *parent) 0020 : MessageList::Pane(restoreSession, model, selectionModel, parent) 0021 { 0022 } 0023 0024 CollectionPane::~CollectionPane() = default; 0025 0026 void CollectionPane::writeConfig(bool /*restoreSession*/) 0027 { 0028 MessageList::Pane::writeConfig(!KMailSettings::self()->startSpecificFolderAtStartup()); 0029 } 0030 0031 MessageList::StorageModel *CollectionPane::createStorageModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel, QObject *parent) 0032 { 0033 return new CollectionStorageModel(model, selectionModel, parent); 0034 } 0035 0036 CollectionStorageModel::CollectionStorageModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel, QObject *parent) 0037 : MessageList::StorageModel(model, selectionModel, parent) 0038 { 0039 } 0040 0041 CollectionStorageModel::~CollectionStorageModel() = default; 0042 0043 bool CollectionStorageModel::isOutBoundFolder(const Akonadi::Collection &c) const 0044 { 0045 if (c.hasAttribute<Akonadi::MessageFolderAttribute>()) { 0046 return c.attribute<Akonadi::MessageFolderAttribute>()->isOutboundFolder(); 0047 } 0048 QSharedPointer<FolderSettings> fd = FolderSettings::forCollection(c, false); 0049 if (!fd.isNull()) { 0050 const QString folderId(QString::number(c.id())); 0051 // default setting 0052 const KIdentityManagementCore::Identity &identity = kmkernel->identityManager()->identityForUoidOrDefault(fd->identity()); 0053 0054 bool isOnline = false; 0055 if (CommonKernel->isSystemFolderCollection(c) && !PimCommon::MailUtil::isImapFolder(c, isOnline)) { 0056 // local system folders 0057 if (c == CommonKernel->inboxCollectionFolder() || c == CommonKernel->trashCollectionFolder()) { 0058 return false; 0059 } 0060 if (c == CommonKernel->outboxCollectionFolder() || c == CommonKernel->sentCollectionFolder() || c == CommonKernel->templatesCollectionFolder() 0061 || c == CommonKernel->draftsCollectionFolder()) { 0062 return true; 0063 } 0064 } else if (identity.drafts() == folderId || identity.templates() == folderId || identity.fcc() == folderId) { 0065 // drafts, templates or sent of the identity 0066 return true; 0067 } else { 0068 return false; 0069 } 0070 } 0071 0072 return false; 0073 } 0074 0075 #include "moc_collectionpane.cpp"