File indexing completed on 2025-01-05 04:55:04
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 0024 #include <QStandardItemModel> 0025 #include <QSortFilterProxyModel> 0026 #include <QVariantMap> 0027 #include <QSet> 0028 #include <QRegularExpression> 0029 #include <QString> 0030 #include <QDateTime> 0031 #include <fabric.h> 0032 #include <sink/store.h> 0033 0034 #include "eventoccurrencemodel.h" 0035 0036 namespace Sink { 0037 namespace ApplicationDomain { 0038 class Mail; 0039 }; 0040 }; 0041 0042 class KUBE_EXPORT InboundModel : public QSortFilterProxyModel 0043 { 0044 Q_OBJECT 0045 0046 Q_PROPERTY(QDateTime currentDate WRITE setCurrentDate) 0047 Q_PROPERTY (QVariantMap filter READ filter WRITE setFilter NOTIFY filterChanged) 0048 Q_PROPERTY (QVariantMap config READ config WRITE setConfig NOTIFY configChanged) 0049 0050 public: 0051 InboundModel(QObject *parent = Q_NULLPTR); 0052 ~InboundModel(); 0053 0054 Q_INVOKABLE void insert(const QByteArray &key, const QVariantMap &); 0055 Q_INVOKABLE void update(const QByteArray &key, const QVariantMap &); 0056 Q_INVOKABLE void refresh(); 0057 Q_INVOKABLE int firstRecentIndex(); 0058 Q_INVOKABLE void setCurrentDate(const QDateTime &dt); 0059 Q_INVOKABLE void ignoreSender(const QVariant &mail); 0060 0061 0062 void configure( 0063 const QSet<QString> &_senderBlacklist, 0064 const QSet<QString> &_toBlacklist, 0065 const QString &_senderNameContainsFilter, 0066 const QMap<QString, QString> &_perFolderMimeMessageWhitelistFilter, 0067 const QList<QRegularExpression> &_messageFilter, 0068 const QList<QString> &_folderSpecialPurposeBlacklist, 0069 const QList<QString> &_folderNameBlacklist 0070 ); 0071 0072 void setConfig(const QVariantMap &); 0073 QVariantMap config() const; 0074 0075 void setFilter(const QVariantMap &); 0076 QVariantMap filter() const; 0077 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0078 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 0079 0080 QHash<int, QByteArray> roleNames() const override; 0081 0082 bool canFetchMore(const QModelIndex &parent) const override; 0083 void fetchMore(const QModelIndex &parent) override; 0084 Q_INVOKABLE void tryFetchMore(); 0085 0086 signals: 0087 void entryAdded(const QVariantMap &message); 0088 void initialItemsLoaded(); 0089 void filterChanged(); 0090 void configChanged(); 0091 void fetchingMore(); 0092 0093 private slots: 0094 void mailRowsInserted(const QModelIndex &parent, int first, int last); 0095 void mailRowsRemoved(const QModelIndex &parent, int first, int last); 0096 void mailDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); 0097 void eventRowsInserted(const QModelIndex &parent, int first, int last); 0098 void eventRowsRemoved(const QModelIndex &parent, int first, int last); 0099 void eventDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); 0100 0101 private: 0102 0103 void runQuery(const Sink::Query &query); 0104 void refreshMail(); 0105 void refreshCalendar(); 0106 void getAllByType(const QString &type, std::function<QModelIndex(const QModelIndex &)> callback); 0107 void removeAllByType(const QString &type); 0108 void saveSettings(); 0109 void loadSettings(); 0110 void initInboundFilter(); 0111 void add(const QSharedPointer<Sink::ApplicationDomain::Mail> &); 0112 void remove(const QSharedPointer<Sink::ApplicationDomain::Mail> &); 0113 void update(const QSharedPointer<Sink::ApplicationDomain::Mail> &); 0114 QVariantMap toVariantMap(const QSharedPointer<Sink::ApplicationDomain::Mail> &mail); 0115 QString folderName(const QByteArray &id) const; 0116 bool filter(const EventOccurrenceModel::Occurrence &mail); 0117 0118 QHash<QByteArray, int> mRoles; 0119 QHash<int, QByteArray> mRoleNames; 0120 QHash<QByteArray, QString> mFolderNames; 0121 QSharedPointer<QAbstractItemModel> mSourceModel; 0122 QSharedPointer<QAbstractItemModel> m_model; 0123 QSharedPointer<QAbstractItemModel> mEventSourceModel; 0124 QSharedPointer<QStandardItemModel> mInboundModel; 0125 0126 QSet<QString> senderBlacklist; 0127 QSet<QString> toBlacklist; 0128 QString senderNameContainsFilter; 0129 QMap<QString, QString> perFolderMimeMessageWhitelistFilter; 0130 QList<QRegularExpression> messageFilter; 0131 QList<QString> folderSpecialPurposeBlacklist; 0132 QList<QString> folderNameBlacklist; 0133 QDateTime mCurrentDateTime; 0134 QVariantMap mFilter; 0135 0136 int mMinNumberOfItems; 0137 bool mEventsLoaded; 0138 };