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

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 <krecursivefilterproxymodel.h>
0024 #include <QSharedPointer>
0025 #include <QSet>
0026 #include <sink/notifier.h>
0027 
0028 namespace Sink {
0029     class Query;
0030 }
0031 
0032 class KUBE_EXPORT FolderListModel : public KRecursiveFilterProxyModel
0033 {
0034     Q_OBJECT
0035 
0036     Q_PROPERTY (QVariant accountId READ accountId WRITE setAccountId)
0037     Q_PROPERTY (QVariant folderId READ folderId WRITE setFolderId)
0038 
0039 public:
0040     enum Status {
0041         NoStatus,
0042         InProgressStatus,
0043         ErrorStatus,
0044         SuccessStatus,
0045     };
0046     Q_ENUMS(Status)
0047 
0048     FolderListModel(QObject *parent = Q_NULLPTR);
0049     ~FolderListModel();
0050 
0051     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
0052 
0053     enum Roles {
0054         Name  = Qt::UserRole + 1,
0055         Icon,
0056         Id,
0057         DomainObject,
0058         Status,
0059         Trash,
0060         Enabled,
0061         HasNewData
0062     };
0063     Q_ENUMS(Roles)
0064 
0065     QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
0066 
0067     void setAccountId(const QVariant &accountId);
0068     QVariant accountId() const;
0069 
0070     void setFolderId(const QVariant &folderId);
0071     QVariant folderId() const;
0072 
0073 signals:
0074     void initialItemsLoaded();
0075 
0076 protected:
0077     bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
0078     bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
0079     void fetchMore(const QModelIndex &left) Q_DECL_OVERRIDE;
0080 
0081 private:
0082     void runQuery(const Sink::Query &query);
0083     QSharedPointer<QAbstractItemModel> mModel;
0084     QSet<QByteArray> mHasNewData;
0085     QScopedPointer<Sink::Notifier> mNotifier;
0086 };