File indexing completed on 2024-11-24 04:53:12

0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef IMAP_MSGLISTMODEL_H
0024 #define IMAP_MSGLISTMODEL_H
0025 
0026 #include <QAbstractProxyModel>
0027 #include "Model.h"
0028 #include "ItemRoles.h"
0029 
0030 /** @short Namespace for IMAP interaction */
0031 namespace Imap
0032 {
0033 
0034 /** @short Classes for handling of mailboxes and connections */
0035 namespace Mailbox
0036 {
0037 
0038 /** @short A model implementing view of the whole IMAP server */
0039 class MsgListModel: public QAbstractProxyModel
0040 {
0041     Q_OBJECT
0042 
0043     Q_PROPERTY(bool itemsValid READ itemsValid NOTIFY indexStateChanged)
0044 
0045 public:
0046     MsgListModel(QObject *parent, Model *model);
0047 
0048     virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const;
0049     virtual QModelIndex parent(const QModelIndex &index) const;
0050     virtual int rowCount(const QModelIndex &parent=QModelIndex()) const;
0051     virtual int columnCount(const QModelIndex &parent=QModelIndex()) const;
0052     virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
0053     virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
0054     virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const;
0055     virtual QVariant data(const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const;
0056     virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const;
0057     virtual Qt::ItemFlags flags(const QModelIndex &index) const;
0058     virtual QStringList mimeTypes() const;
0059     virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
0060     virtual Qt::DropActions supportedDragActions() const;
0061     virtual Qt::DropActions supportedDropActions() const;
0062     virtual QHash<int, QByteArray> roleNames() const;
0063 
0064     QModelIndex currentMailbox() const;
0065 
0066     bool itemsValid() const;
0067 
0068     // These columns MUST NOT be reordered. The GUI stores the view state based on their values and any changes will lead to
0069     // a severe user-visible breakage.
0070     enum { SUBJECT, SEEN, FROM, TO, CC, BCC, DATE, RECEIVED_DATE, SIZE, FLAGGED, ATTACHMENT, COLUMN_COUNT };
0071 
0072 public slots:
0073     void resetMe();
0074     void setMailbox(const QModelIndex &index);
0075     Q_INVOKABLE void setMailbox(const QString &mailboxName);
0076     void handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0077     void handleRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
0078     void handleRowsRemoved(const QModelIndex &parent, int start, int end);
0079     void handleRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
0080     void handleRowsInserted(const QModelIndex &parent, int start, int end);
0081 
0082 signals:
0083     void messageRemoved(void *);
0084     void mailboxChanged(const QModelIndex &mailbox);
0085 
0086     /** @short Messages are available for the first time after selecting new mailbox */
0087     void messagesAvailable();
0088 
0089     void indexStateChanged();
0090 
0091 private:
0092     MsgListModel &operator=(const MsgListModel &);  // don't implement
0093     MsgListModel(const MsgListModel &);  // don't implement
0094 
0095     void checkPersistentIndex() const;
0096 
0097     QPersistentModelIndex msgList;
0098     mutable TreeItemMsgList *msgListPtr;
0099     bool waitingForMessages;
0100 
0101     friend class ThreadingMsgListModel;
0102 };
0103 
0104 }
0105 
0106 }
0107 
0108 #endif /* IMAP_MSGLISTMODEL_H */