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

0001 /******************************************************************************
0002  *
0003  *  SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  *******************************************************************************/
0008 
0009 #pragma once
0010 
0011 #include <QAbstractItemModel>
0012 #include <QList>
0013 namespace Akonadi
0014 {
0015 class MessageStatus;
0016 }
0017 
0018 namespace MessageList
0019 {
0020 namespace Core
0021 {
0022 class MessageItem;
0023 
0024 /**
0025  * The QAbstractItemModel based interface that you need
0026  * to provide for your storage to work with MessageList.
0027  */
0028 class StorageModel : public QAbstractItemModel
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit StorageModel(QObject *parent = nullptr);
0034     ~StorageModel() override;
0035 
0036     /**
0037      * Returns an unique id for this Storage collection.
0038      * FIXME: This could be embedded in "name()" ?
0039      */
0040     virtual QString id() const = 0;
0041 
0042     /**
0043      * Returns the unique id of the last selected message for this StorageModel.
0044      * Returns 0 if this value isn't stored in the configuration.
0045      */
0046     unsigned long preSelectedMessage() const;
0047 
0048     /**
0049      * Stores in the unique id of the last selected message for the specified StorageModel.
0050      * The uniqueIdOfMessage may be 0 (which means that no selection shall be stored in the configuration).
0051      */
0052     void savePreSelectedMessage(unsigned long uniqueIdOfMessage);
0053 
0054     /**
0055      * Returns true if this StorageModel (folder) contains outbound messages and false otherwise.
0056      */
0057     virtual bool containsOutboundMessages() const = 0;
0058 
0059     /**
0060      * Returns (a guess for) the number of unread messages: must be pessimistic (i.e. if you
0061      * have no idea just return rowCount(), which is also what the default implementation does).
0062      * This must be (and is) queried ONLY when the folder is first opened. It doesn't actually need
0063      * to keep the number of messages in sync as they later arrive to the storage.
0064      */
0065     virtual int initialUnreadRowCountGuess() const;
0066 
0067     /**
0068      * This method should use the inner model implementation to fill in the
0069      * base data for the specified MessageItem from the underlying storage slot at
0070      * the specified row index. Must return true if the data fetch was successful
0071      * and false otherwise. For base data we intend: subject, sender, receiver,
0072      * senderOrReceiver, size, date, encryption state, signature state and status.
0073      * If bUseReceiver is true then the "senderOrReceiver"
0074      * field must be set to the receiver, otherwise it must be set to the sender.
0075      */
0076     virtual bool initializeMessageItem(MessageItem *it, int row, bool bUseReceiver) const = 0;
0077 
0078     enum ThreadingDataSubset {
0079         PerfectThreadingOnly, ///< Only the data for messageIdMD5 and inReplyToMD5 is needed
0080         PerfectThreadingPlusReferences, ///< messageIdMD5, inReplyToMD5, referencesIdMD5
0081         PerfectThreadingReferencesAndSubject ///< All of the above plus subject stuff
0082     };
0083 
0084     /**
0085      * This method should use the inner model implementation to fill in the specified subset of
0086      * threading data for the specified MessageItem from the underlying storage slot at
0087      * the specified row index.
0088      */
0089     virtual void fillMessageItemThreadingData(MessageItem *mi, int row, ThreadingDataSubset subset) const = 0;
0090 
0091     /**
0092      * This method should use the inner model implementation to re-fill the date, the status,
0093      * the encryption state, the signature state and eventually update the min/max dates
0094      * for the specified MessageItem from the underlying storage slot at the specified row index.
0095      */
0096     virtual void updateMessageItemData(MessageItem *mi, int row) const = 0;
0097 
0098     /**
0099      * This method should use the inner model implementation to associate the new status
0100      * to the specified message item. The new status should be stored (but doesn't need
0101      * to be set as mi->status() itself as the caller is responsible for this).
0102      */
0103     virtual void setMessageItemStatus(MessageItem *mi, int row, Akonadi::MessageStatus status) = 0;
0104 
0105     /**
0106      * The implementation-specific mime data for this list of items.
0107      *    Called when the user initiates a drag from the messagelist.
0108      */
0109     virtual QMimeData *mimeData(const QList<MessageItem *> &) const = 0;
0110     using QAbstractItemModel::mimeData;
0111 };
0112 } // namespace Core
0113 } // namespace MessageList