activitylistmodel.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #ifndef ACTIVITYLISTMODEL_H
  15. #define ACTIVITYLISTMODEL_H
  16. #include <QtCore>
  17. #include "activitydata.h"
  18. class QJsonDocument;
  19. namespace OCC {
  20. Q_DECLARE_LOGGING_CATEGORY(lcActivity)
  21. class AccountState;
  22. class ConflictDialog;
  23. class InvalidFilenameDialog;
  24. class CaseClashFilenameDialog;
  25. /**
  26. * @brief The ActivityListModel
  27. * @ingroup gui
  28. *
  29. * Simple list model to provide the list view with data.
  30. */
  31. class ActivityListModel : public QAbstractListModel
  32. {
  33. Q_OBJECT
  34. Q_PROPERTY(quint32 maxActionButtons READ maxActionButtons CONSTANT)
  35. Q_PROPERTY(AccountState *accountState READ accountState WRITE setAccountState NOTIFY accountStateChanged)
  36. Q_PROPERTY(bool hasSyncConflicts READ hasSyncConflicts NOTIFY hasSyncConflictsChanged)
  37. Q_PROPERTY(OCC::ActivityList allConflicts READ allConflicts NOTIFY allConflictsChanged)
  38. public:
  39. enum DataRole {
  40. DarkIconRole = Qt::UserRole + 1,
  41. LightIconRole,
  42. AccountRole,
  43. ObjectTypeRole,
  44. ObjectIdRole,
  45. ObjectNameRole,
  46. ActionsLinksRole,
  47. ActionsLinksContextMenuRole,
  48. ActionsLinksForActionButtonsRole,
  49. ActionTextRole,
  50. ActionTextColorRole,
  51. ActionRole,
  52. MessageRole,
  53. DisplayPathRole,
  54. PathRole,
  55. OpenablePathRole,
  56. DisplayLocationRole, // Provides the display path to a file's parent folder, relative to Nextcloud root
  57. LinkRole,
  58. PointInTimeRole,
  59. AccountConnectedRole,
  60. DisplayActions,
  61. ShowFileDetailsRole,
  62. ShareableRole,
  63. DismissableRole,
  64. IsCurrentUserFileActivityRole,
  65. ThumbnailRole,
  66. TalkNotificationConversationTokenRole,
  67. TalkNotificationMessageIdRole,
  68. TalkNotificationMessageSentRole,
  69. TalkNotificationUserAvatarRole,
  70. ActivityIndexRole,
  71. ActivityRole,
  72. };
  73. Q_ENUM(DataRole)
  74. enum class ErrorType {
  75. SyncError,
  76. NetworkError,
  77. };
  78. Q_ENUM(ErrorType)
  79. explicit ActivityListModel(QObject *parent = nullptr);
  80. explicit ActivityListModel(AccountState *accountState,
  81. QObject *parent = nullptr);
  82. [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
  83. [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  84. [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
  85. [[nodiscard]] bool canFetchMore(const QModelIndex &) const override;
  86. void fetchMore(const QModelIndex &) override;
  87. ActivityList activityList() { return _finalList; }
  88. ActivityList errorsList() { return _notificationErrorsLists; }
  89. [[nodiscard]] AccountState *accountState() const;
  90. [[nodiscard]] int currentItem() const;
  91. static constexpr quint32 maxActionButtons()
  92. {
  93. return MaxActionButtons;
  94. }
  95. [[nodiscard]] QString replyMessageSent(const Activity &activity) const;
  96. [[nodiscard]] bool hasSyncConflicts() const;
  97. [[nodiscard]] OCC::ActivityList allConflicts() const;
  98. public slots:
  99. void slotRefreshActivity();
  100. void slotRefreshActivityInitial();
  101. void slotRemoveAccount();
  102. void slotTriggerDefaultAction(const int activityIndex);
  103. void slotTriggerAction(const int activityIndex, const int actionIndex);
  104. void slotTriggerDismiss(const int activityIndex);
  105. void addNotificationToActivityList(const OCC::Activity &activity);
  106. void addErrorToActivityList(const OCC::Activity &activity, const ErrorType type);
  107. void addIgnoredFileToList(const OCC::Activity &newActivity);
  108. void addSyncFileItemToActivityList(const OCC::Activity &activity);
  109. void removeActivityFromActivityList(int row);
  110. void removeActivityFromActivityList(const OCC::Activity &activity);
  111. void setAccountState(OCC::AccountState *state);
  112. void setReplyMessageSent(const int activityIndex, const QString &message);
  113. void setCurrentItem(const int currentItem);
  114. signals:
  115. void accountStateChanged();
  116. void hasSyncConflictsChanged();
  117. void allConflictsChanged();
  118. void activityJobStatusCode(int statusCode);
  119. void sendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row);
  120. protected:
  121. [[nodiscard]] bool currentlyFetching() const;
  122. [[nodiscard]] const ActivityList &finalList() const; // added for unit tests
  123. protected slots:
  124. void activitiesReceived(const QJsonDocument &json, int statusCode);
  125. void setAndRefreshCurrentlyFetching(bool value);
  126. void setDoneFetching(bool value);
  127. void setHideOldActivities(bool value);
  128. void setDisplayActions(bool value);
  129. void setFinalList(const OCC::ActivityList &finalList); // added for unit tests
  130. virtual void startFetchJob();
  131. private slots:
  132. void addEntriesToActivityList(const OCC::ActivityList &activityList);
  133. private:
  134. static QVariantList convertLinksToMenuEntries(const Activity &activity);
  135. static QVariantList convertLinksToActionButtons(const Activity &activity);
  136. static QVariant convertLinkToActionButton(const ActivityLink &activityLink);
  137. [[nodiscard]] bool canFetchActivities() const;
  138. void ingestActivities(const QJsonArray &activities);
  139. void appendMoreActivitiesAvailableEntry();
  140. void insertOrRemoveDummyFetchingActivity();
  141. void triggerCaseClashAction(Activity activity);
  142. void displaySingleConflictDialog(const Activity &activity);
  143. void setHasSyncConflicts(bool conflictsFound);
  144. Activity _notificationIgnoredFiles;
  145. Activity _dummyFetchingActivities;
  146. ActivityList _activityLists;
  147. ActivityList _syncFileItemLists;
  148. ActivityList _notificationLists;
  149. ActivityList _listOfIgnoredFiles;
  150. ActivityList _notificationErrorsLists;
  151. ActivityList _finalList;
  152. QSet<qint64> _presentedActivities;
  153. bool _displayActions = true;
  154. int _currentItem = 0;
  155. int _maxActivities = 100;
  156. int _maxActivitiesDays = 30;
  157. bool _showMoreActivitiesAvailableEntry = false;
  158. QPointer<ConflictDialog> _currentConflictDialog;
  159. QPointer<InvalidFilenameDialog> _currentInvalidFilenameDialog;
  160. QPointer<CaseClashFilenameDialog> _currentCaseClashFilenameDialog;
  161. AccountState *_accountState = nullptr;
  162. bool _currentlyFetching = false;
  163. bool _doneFetching = false;
  164. bool _hideOldActivities = true;
  165. bool _hasSyncConflicts = false;
  166. static constexpr quint32 MaxActionButtons = 3;
  167. };
  168. }
  169. #endif // ACTIVITYLISTMODEL_H