File indexing completed on 2024-12-15 04:54:46

0001 /*
0002     SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "messagelist/storagemodelbase.h"
0010 #include "messagelist_export.h"
0011 
0012 #include <Akonadi/Collection>
0013 #include <Akonadi/Item>
0014 #include <KMime/KMimeMessage>
0015 #include <QList>
0016 
0017 class QAbstractItemModel;
0018 class QItemSelectionModel;
0019 
0020 namespace Akonadi
0021 {
0022 class Item;
0023 }
0024 
0025 namespace MessageList
0026 {
0027 namespace Core
0028 {
0029 class MessageItem;
0030 }
0031 
0032 /**
0033  * The Akonadi specific implementation of the Core::StorageModel.
0034  */
0035 class MESSAGELIST_EXPORT StorageModel : public MessageList::Core::StorageModel
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     /**
0041      * Create a StorageModel wrapping the specified folder.
0042      */
0043     explicit StorageModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel, QObject *parent = nullptr);
0044     ~StorageModel() override;
0045 
0046     [[nodiscard]] Akonadi::Collection::List displayedCollections() const;
0047 
0048     [[nodiscard]] QString id() const override;
0049     [[nodiscard]] bool containsOutboundMessages() const override;
0050 
0051     [[nodiscard]] virtual bool isOutBoundFolder(const Akonadi::Collection &c) const;
0052 
0053     [[nodiscard]] int initialUnreadRowCountGuess() const override;
0054     [[nodiscard]] bool initializeMessageItem(MessageList::Core::MessageItem *mi, int row, bool bUseReceiver) const override;
0055     void fillMessageItemThreadingData(MessageList::Core::MessageItem *mi, int row, ThreadingDataSubset subset) const override;
0056     void updateMessageItemData(MessageList::Core::MessageItem *mi, int row) const override;
0057     void setMessageItemStatus(MessageList::Core::MessageItem *mi, int row, Akonadi::MessageStatus status) override;
0058 
0059     [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0060     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0061     [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0062     [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
0063     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0064 
0065     QMimeData *mimeData(const QList<MessageList::Core::MessageItem *> &) const override;
0066     using MessageList::Core::StorageModel::mimeData;
0067 
0068     [[nodiscard]] Akonadi::Item itemForRow(int row) const;
0069     [[nodiscard]] Akonadi::Collection parentCollectionForRow(int row) const;
0070     [[nodiscard]] KMime::Message::Ptr messageForRow(int row) const;
0071 
0072     [[nodiscard]] Akonadi::Collection collectionForId(Akonadi::Collection::Id colId) const;
0073 
0074     void resetModelStorage();
0075 
0076 private:
0077     class StorageModelPrivate;
0078     std::unique_ptr<StorageModelPrivate> const d;
0079 };
0080 } // namespace MessageList