1/*
2 * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#ifndef ACTIVITYLISTMODEL_H
16#define ACTIVITYLISTMODEL_H
17
18#include <QtCore>
19
20#include "activitydata.h"
21
22class QJsonDocument;
23
24namespace OCC {
25
26Q_DECLARE_LOGGING_CATEGORY(lcActivity)
27
28class AccountState;
29
30/**
31 * @brief The ActivityListModel
32 * @ingroup gui
33 *
34 * Simple list model to provide the list view with data.
35 */
36
37class ActivityListModel : public QAbstractListModel
38{
39 Q_OBJECT
40public:
41 explicit ActivityListModel(QWidget *parent = 0);
42
43 QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
44 int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
45
46 bool canFetchMore(const QModelIndex &) const Q_DECL_OVERRIDE;
47 void fetchMore(const QModelIndex &) Q_DECL_OVERRIDE;
48
49 ActivityList activityList() { return _finalList; }
50
51public slots:
52 void slotRefreshActivity(AccountState *ast);
53 void slotRemoveAccount(AccountState *ast);
54
55private slots:
56 void slotActivitiesReceived(const QJsonDocument &json, int statusCode);
57
58signals:
59 void activityJobStatusCode(AccountState *ast, int statusCode);
60
61private:
62 void startFetchJob(AccountState *s);
63 void combineActivityLists();
64
65 QMap<AccountState *, ActivityList> _activityLists;
66 ActivityList _finalList;
67 QSet<AccountState *> _currentlyFetching;
68};
69}
70#endif // ACTIVITYLISTMODEL_H
71