File indexing completed on 2025-01-19 04:51:59

0001 /*
0002     Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net>
0003     Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
0004 
0005     This library is free software; you can redistribute it and/or modify it
0006     under the terms of the GNU Library General Public License as published by
0007     the Free Software Foundation; either version 2 of the License, or (at your
0008     option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful, but WITHOUT
0011     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0012     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0013     License for more details.
0014 
0015     You should have received a copy of the GNU Library General Public License
0016     along with this library; see the file COPYING.LIB.  If not, write to the
0017     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0018     02110-1301, USA.
0019 */
0020 
0021 #pragma once
0022 #include "kube_export.h"
0023 #include <sink/store.h>
0024 
0025 #include <QSortFilterProxyModel>
0026 #include <QSharedPointer>
0027 #include <QStringList>
0028 
0029 class KUBE_EXPORT MailListModel : public QSortFilterProxyModel
0030 {
0031     Q_OBJECT
0032     Q_PROPERTY (QVariantMap filter READ filter WRITE setFilter NOTIFY filterChanged)
0033     Q_PROPERTY (bool threaded MEMBER mIsThreaded) //READONLY
0034 
0035 public:
0036     enum Status {
0037         NoStatus,
0038         InProgressStatus,
0039         ErrorStatus
0040     };
0041     Q_ENUMS(Status)
0042 
0043     MailListModel(QObject *parent = Q_NULLPTR);
0044     ~MailListModel();
0045 
0046     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
0047 
0048     bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
0049     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
0050 
0051     enum Roles {
0052         Subject  = Qt::UserRole + 1,
0053         Sender,
0054         SenderName,
0055         To,
0056         Cc,
0057         Bcc,
0058         Date,
0059         Unread,
0060         Important,
0061         Draft,
0062         Sent,
0063         Trash,
0064         Id,
0065         MimeMessage,
0066         DomainObject,
0067         ThreadSize,
0068         Mail,
0069         Incomplete,
0070         Status
0071     };
0072 
0073     QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
0074 
0075     void runQuery(const Sink::Query &query);
0076 
0077     void setFilter(const QVariantMap &);
0078     QVariantMap filter() const;
0079 
0080 signals:
0081     void initialItemsLoaded();
0082     void filterChanged();
0083 
0084 private:
0085     void fetchMail(Sink::ApplicationDomain::Mail::Ptr mail);
0086 
0087     QSharedPointer<QAbstractItemModel> m_model;
0088     bool mFetchMails = false;
0089     bool mIsThreaded = true;
0090     QSet<QByteArray> mFetchedMails;
0091     Sink::Query mQuery;
0092 };