File indexing completed on 2025-01-05 04:55:00

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 #include <sink/notifier.h>
0025 
0026 #include <QSortFilterProxyModel>
0027 #include <QSharedPointer>
0028 #include <QStringList>
0029 
0030 class KUBE_EXPORT OutboxModel : public QSortFilterProxyModel
0031 {
0032     Q_OBJECT
0033 
0034     Q_PROPERTY (int count READ count NOTIFY countChanged)
0035     Q_PROPERTY (int status READ status NOTIFY statusChanged)
0036 
0037 public:
0038     enum Status {
0039         NoStatus,
0040         PendingStatus,
0041         InProgressStatus,
0042         ErrorStatus
0043     };
0044     Q_ENUMS(Status)
0045 
0046     OutboxModel(QObject *parent = Q_NULLPTR);
0047     ~OutboxModel();
0048 
0049     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
0050 
0051     bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
0052 
0053     enum Roles {
0054         Subject  = Qt::UserRole + 1,
0055         Date,
0056         Status,
0057         Id,
0058         MimeMessage,
0059         DomainObject
0060     };
0061 
0062     QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
0063 
0064     void runQuery(const Sink::Query &query);
0065 
0066     int count() const;
0067     int status() const;
0068 
0069 signals:
0070     void statusChanged();
0071     void countChanged();
0072 
0073 private:
0074     QSharedPointer<QAbstractItemModel> mModel;
0075     QSharedPointer<Sink::Notifier> mNotifier;
0076     int mStatus;
0077 };