2016-03-11 13:37:45 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-03-11 13:37:45 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ACTIVITYLISTMODEL_H
|
|
|
|
#define ACTIVITYLISTMODEL_H
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
2021-10-25 12:37:58 +03:00
|
|
|
#include "activitydata.h"
|
2016-03-11 13:37:45 +03:00
|
|
|
|
2017-04-26 13:15:33 +03:00
|
|
|
class QJsonDocument;
|
|
|
|
|
2016-03-11 13:37:45 +03:00
|
|
|
namespace OCC {
|
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
Q_DECLARE_LOGGING_CATEGORY(lcActivity)
|
|
|
|
|
2016-03-11 13:37:45 +03:00
|
|
|
class AccountState;
|
2021-01-26 13:35:39 +03:00
|
|
|
class ConflictDialog;
|
2021-09-06 16:09:29 +03:00
|
|
|
class InvalidFilenameDialog;
|
2016-03-11 13:37:45 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The ActivityListModel
|
|
|
|
* @ingroup gui
|
|
|
|
*
|
|
|
|
* Simple list model to provide the list view with data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ActivityListModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-08-20 16:17:06 +03:00
|
|
|
|
2022-01-04 17:28:26 +03:00
|
|
|
Q_PROPERTY(quint32 maxActionButtons READ maxActionButtons CONSTANT)
|
|
|
|
|
2021-08-20 16:17:06 +03:00
|
|
|
Q_PROPERTY(AccountState *accountState READ accountState CONSTANT)
|
2016-03-11 13:37:45 +03:00
|
|
|
public:
|
2020-01-13 11:59:34 +03:00
|
|
|
enum DataRole {
|
2022-03-21 19:34:21 +03:00
|
|
|
DarkIconRole = Qt::UserRole + 1,
|
|
|
|
LightIconRole,
|
2021-08-20 16:17:06 +03:00
|
|
|
AccountRole,
|
|
|
|
ObjectTypeRole,
|
2022-03-05 15:44:03 +03:00
|
|
|
ObjectIdRole,
|
|
|
|
ObjectNameRole,
|
2021-08-20 16:17:06 +03:00
|
|
|
ActionsLinksRole,
|
2022-01-04 17:28:26 +03:00
|
|
|
ActionsLinksContextMenuRole,
|
|
|
|
ActionsLinksForActionButtonsRole,
|
2021-08-20 16:17:06 +03:00
|
|
|
ActionTextRole,
|
|
|
|
ActionTextColorRole,
|
|
|
|
ActionRole,
|
|
|
|
MessageRole,
|
|
|
|
DisplayPathRole,
|
|
|
|
PathRole,
|
2021-12-16 18:39:58 +03:00
|
|
|
DisplayLocationRole, // Provides the display path to a file's parent folder, relative to Nextcloud root
|
2021-08-20 16:17:06 +03:00
|
|
|
LinkRole,
|
|
|
|
PointInTimeRole,
|
|
|
|
AccountConnectedRole,
|
|
|
|
DisplayActions,
|
2021-12-16 14:22:04 +03:00
|
|
|
ShareableRole,
|
2022-01-04 17:28:26 +03:00
|
|
|
IsCurrentUserFileActivityRole,
|
2022-01-20 14:54:36 +03:00
|
|
|
ThumbnailRole,
|
2022-03-23 20:06:57 +03:00
|
|
|
TalkNotificationConversationTokenRole,
|
|
|
|
TalkNotificationMessageIdRole,
|
2021-08-20 16:17:06 +03:00
|
|
|
};
|
|
|
|
Q_ENUM(DataRole)
|
|
|
|
|
|
|
|
explicit ActivityListModel(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
explicit ActivityListModel(AccountState *accountState,
|
|
|
|
QObject *parent = nullptr);
|
2016-03-11 13:37:45 +03:00
|
|
|
|
2018-11-11 13:09:29 +03:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
2016-03-11 13:37:45 +03:00
|
|
|
|
2018-11-11 13:09:29 +03:00
|
|
|
bool canFetchMore(const QModelIndex &) const override;
|
|
|
|
void fetchMore(const QModelIndex &) override;
|
2016-03-11 13:37:45 +03:00
|
|
|
|
|
|
|
ActivityList activityList() { return _finalList; }
|
2018-07-18 00:56:31 +03:00
|
|
|
ActivityList errorsList() { return _notificationErrorsLists; }
|
2018-05-14 21:21:30 +03:00
|
|
|
void addNotificationToActivityList(Activity activity);
|
2019-02-01 16:39:59 +03:00
|
|
|
void clearNotifications();
|
2018-05-14 21:21:30 +03:00
|
|
|
void addErrorToActivityList(Activity activity);
|
2019-10-17 19:45:33 +03:00
|
|
|
void addIgnoredFileToList(Activity newActivity);
|
2018-08-24 10:17:47 +03:00
|
|
|
void addSyncFileItemToActivityList(Activity activity);
|
2018-07-18 00:56:31 +03:00
|
|
|
void removeActivityFromActivityList(int row);
|
|
|
|
void removeActivityFromActivityList(Activity activity);
|
2016-03-11 13:37:45 +03:00
|
|
|
|
2021-08-20 16:17:06 +03:00
|
|
|
AccountState *accountState() const;
|
2021-12-23 13:57:08 +03:00
|
|
|
void setAccountState(AccountState *state);
|
2021-08-20 16:17:06 +03:00
|
|
|
|
2022-01-04 17:28:26 +03:00
|
|
|
static constexpr quint32 maxActionButtons()
|
|
|
|
{
|
|
|
|
return MaxActionButtons;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCurrentItem(const int currentItem);
|
|
|
|
|
2016-03-11 13:37:45 +03:00
|
|
|
public slots:
|
2018-03-27 18:19:22 +03:00
|
|
|
void slotRefreshActivity();
|
|
|
|
void slotRemoveAccount();
|
2022-01-04 17:28:26 +03:00
|
|
|
void slotTriggerDefaultAction(const int activityIndex);
|
|
|
|
void slotTriggerAction(const int activityIndex, const int actionIndex);
|
|
|
|
void slotTriggerDismiss(const int activityIndex);
|
2016-03-11 13:37:45 +03:00
|
|
|
|
|
|
|
signals:
|
2018-03-27 18:19:22 +03:00
|
|
|
void activityJobStatusCode(int statusCode);
|
2020-11-18 18:42:37 +03:00
|
|
|
void sendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row);
|
2016-03-11 13:37:45 +03:00
|
|
|
|
2020-01-03 15:39:10 +03:00
|
|
|
protected:
|
2022-02-04 05:39:38 +03:00
|
|
|
void setup();
|
2021-08-20 16:17:06 +03:00
|
|
|
void activitiesReceived(const QJsonDocument &json, int statusCode);
|
2020-01-18 12:30:34 +03:00
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
2020-01-03 15:39:10 +03:00
|
|
|
|
2021-08-20 16:17:06 +03:00
|
|
|
void setCurrentlyFetching(bool value);
|
|
|
|
bool currentlyFetching() const;
|
|
|
|
void setDoneFetching(bool value);
|
|
|
|
void setHideOldActivities(bool value);
|
|
|
|
void setDisplayActions(bool value);
|
|
|
|
|
|
|
|
virtual void startFetchJob();
|
|
|
|
|
2022-01-04 17:28:26 +03:00
|
|
|
// added these for unit tests
|
|
|
|
void setFinalList(const ActivityList &finalList);
|
|
|
|
const ActivityList &finalList() const;
|
|
|
|
int currentItem() const;
|
|
|
|
//
|
|
|
|
|
2016-03-11 13:37:45 +03:00
|
|
|
private:
|
2022-01-04 17:28:26 +03:00
|
|
|
static QVariantList convertLinksToMenuEntries(const Activity &activity);
|
|
|
|
static QVariantList convertLinksToActionButtons(const Activity &activity);
|
|
|
|
static QVariant convertLinkToActionButton(const Activity &activity, const ActivityLink &activityLink);
|
2016-03-11 13:37:45 +03:00
|
|
|
void combineActivityLists();
|
2018-11-19 16:13:51 +03:00
|
|
|
bool canFetchActivities() const;
|
2016-03-11 13:37:45 +03:00
|
|
|
|
2022-01-20 14:54:36 +03:00
|
|
|
void ingestActivities(const QJsonArray &activities);
|
|
|
|
|
2018-03-27 18:19:22 +03:00
|
|
|
ActivityList _activityLists;
|
2018-08-24 10:17:47 +03:00
|
|
|
ActivityList _syncFileItemLists;
|
2018-03-27 18:19:22 +03:00
|
|
|
ActivityList _notificationLists;
|
2019-10-17 19:45:33 +03:00
|
|
|
ActivityList _listOfIgnoredFiles;
|
|
|
|
Activity _notificationIgnoredFiles;
|
2018-05-14 21:21:30 +03:00
|
|
|
ActivityList _notificationErrorsLists;
|
2016-03-11 13:37:45 +03:00
|
|
|
ActivityList _finalList;
|
2018-11-22 12:40:00 +03:00
|
|
|
int _currentItem = 0;
|
2020-01-17 22:25:41 +03:00
|
|
|
|
2021-08-20 16:17:06 +03:00
|
|
|
bool _displayActions = true;
|
|
|
|
|
2020-01-17 22:25:41 +03:00
|
|
|
int _totalActivitiesFetched = 0;
|
|
|
|
int _maxActivities = 100;
|
|
|
|
int _maxActivitiesDays = 30;
|
2020-01-17 22:26:48 +03:00
|
|
|
bool _showMoreActivitiesAvailableEntry = false;
|
2021-01-26 13:35:39 +03:00
|
|
|
|
|
|
|
QPointer<ConflictDialog> _currentConflictDialog;
|
2021-09-06 16:09:29 +03:00
|
|
|
QPointer<InvalidFilenameDialog> _currentInvalidFilenameDialog;
|
2021-08-20 16:17:06 +03:00
|
|
|
|
|
|
|
AccountState *_accountState = nullptr;
|
|
|
|
bool _currentlyFetching = false;
|
|
|
|
bool _doneFetching = false;
|
|
|
|
bool _hideOldActivities = true;
|
2022-01-04 17:28:26 +03:00
|
|
|
|
|
|
|
static constexpr quint32 MaxActionButtons = 2;
|
2016-03-11 13:37:45 +03:00
|
|
|
};
|
|
|
|
}
|
2019-12-19 22:07:14 +03:00
|
|
|
|
2016-03-11 13:37:45 +03:00
|
|
|
#endif // ACTIVITYLISTMODEL_H
|