activitydata.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 ACTIVITYDATA_H
  15. #define ACTIVITYDATA_H
  16. #include "syncfileitem.h"
  17. #include "folder.h"
  18. #include "account.h"
  19. #include <QtCore>
  20. #include <QIcon>
  21. #include <QJsonObject>
  22. #include <QVariantMap>
  23. namespace OCC {
  24. /**
  25. * @brief The ActivityLink class describes actions of an activity
  26. *
  27. * These are part of notifications which are mapped into activities.
  28. */
  29. class ActivityLink
  30. {
  31. Q_GADGET
  32. Q_PROPERTY(QString imageSource MEMBER _imageSource)
  33. Q_PROPERTY(QString imageSourceHovered MEMBER _imageSourceHovered)
  34. Q_PROPERTY(QString label MEMBER _label)
  35. Q_PROPERTY(QString link MEMBER _link)
  36. Q_PROPERTY(QByteArray verb MEMBER _verb)
  37. Q_PROPERTY(bool primary MEMBER _primary)
  38. public:
  39. static ActivityLink createFomJsonObject(const QJsonObject &obj);
  40. public:
  41. QString _imageSource;
  42. QString _imageSourceHovered;
  43. QString _label;
  44. QString _link;
  45. QByteArray _verb;
  46. bool _primary = false;
  47. };
  48. /**
  49. * @brief The PreviewData class describes the data about a file's preview.
  50. */
  51. class PreviewData
  52. {
  53. Q_GADGET
  54. Q_PROPERTY(QString source MEMBER _source)
  55. Q_PROPERTY(QString link MEMBER _link)
  56. Q_PROPERTY(QString mimeType MEMBER _mimeType)
  57. Q_PROPERTY(int fileId MEMBER _fileId)
  58. Q_PROPERTY(QString view MEMBER _view)
  59. Q_PROPERTY(bool isMimeTypeIcon MEMBER _isMimeTypeIcon)
  60. Q_PROPERTY(QString filename MEMBER _filename)
  61. public:
  62. QString _source;
  63. QString _link;
  64. QString _mimeType;
  65. int _fileId = 0;
  66. QString _view;
  67. bool _isMimeTypeIcon = false;
  68. QString _filename;
  69. };
  70. struct RichSubjectParameter {
  71. Q_GADGET
  72. Q_PROPERTY(QString type MEMBER type)
  73. Q_PROPERTY(QString id MEMBER id)
  74. Q_PROPERTY(QString name MEMBER name)
  75. Q_PROPERTY(QString path MEMBER path)
  76. Q_PROPERTY(QUrl link MEMBER link)
  77. public:
  78. QString type; // Required
  79. QString id; // Required
  80. QString name; // Required
  81. QString path; // Required (for files only)
  82. QUrl link; // Optional (files only)
  83. };
  84. struct TalkNotificationData {
  85. Q_GADGET
  86. Q_PROPERTY(QString conversationToken MEMBER conversationToken)
  87. Q_PROPERTY(QString messageId MEMBER messageId)
  88. Q_PROPERTY(QString messageSent MEMBER messageSent)
  89. Q_PROPERTY(QString userAvatar MEMBER userAvatar)
  90. public:
  91. QString conversationToken;
  92. QString messageId;
  93. QString messageSent;
  94. QString userAvatar;
  95. [[nodiscard]] bool operator==(const TalkNotificationData &other) const
  96. {
  97. return conversationToken == other.conversationToken &&
  98. messageId == other.messageId &&
  99. messageSent == other.messageSent &&
  100. userAvatar == other.userAvatar;
  101. }
  102. [[nodiscard]] bool operator!=(const TalkNotificationData &other) const
  103. {
  104. return conversationToken != other.conversationToken ||
  105. messageId != other.messageId ||
  106. messageSent != other.messageSent ||
  107. userAvatar != other.userAvatar;
  108. }
  109. };
  110. /* ==================================================================== */
  111. /**
  112. * @brief Activity Structure
  113. * @ingroup gui
  114. *
  115. * contains all the information describing a single activity.
  116. */
  117. class Activity
  118. {
  119. Q_GADGET
  120. Q_PROPERTY(OCC::Activity::Type type MEMBER _type)
  121. Q_PROPERTY(OCC::TalkNotificationData talkNotificationData MEMBER _talkNotificationData)
  122. Q_PROPERTY(QVariantMap subjectRichParameters MEMBER _subjectRichParameters)
  123. public:
  124. using Identifier = QPair<qlonglong, QString>;
  125. // Note that these are in the order we want to present them in the model!
  126. enum Type {
  127. DummyFetchingActivityType,
  128. NotificationType,
  129. SyncResultType,
  130. SyncFileItemType,
  131. ActivityType,
  132. DummyMoreActivitiesAvailableType,
  133. };
  134. Q_ENUM(Type)
  135. static Activity fromActivityJson(const QJsonObject &json, const AccountPtr account);
  136. static QString relativeServerFileTypeIconPath(const QMimeType &mimeType);
  137. static QString localFilePathForActivity(const Activity &activity, const AccountPtr account);
  138. using RichSubjectParameter = OCC::RichSubjectParameter;
  139. using TalkNotificationData = OCC::TalkNotificationData;
  140. Type _type;
  141. qlonglong _id = 0LL;
  142. QString _fileAction;
  143. int _objectId = 0;
  144. TalkNotificationData _talkNotificationData;
  145. QString _objectType;
  146. QString _objectName;
  147. QString _subject;
  148. QString _subjectRich;
  149. QVariantMap _subjectRichParameters;
  150. QString _subjectDisplay;
  151. QString _message;
  152. QString _folder;
  153. QString _file;
  154. QString _renamedFile;
  155. bool _isMultiObjectActivity = false;
  156. QUrl _link;
  157. QDateTime _dateTime;
  158. qint64 _expireAtMsecs = -1;
  159. QString _accName;
  160. QString _icon;
  161. bool _isCurrentUserFileActivity = false;
  162. QVector<PreviewData> _previews;
  163. // Stores information about the error
  164. SyncFileItem::Status _syncFileItemStatus = SyncFileItem::Status::NoStatus;
  165. SyncResult::Status _syncResultStatus = SyncResult::Status::Undefined;
  166. QVector<ActivityLink> _links;
  167. /**
  168. * @brief Sort operator to sort the list youngest first.
  169. * @param val
  170. * @return
  171. */
  172. bool _shouldNotify = true;
  173. [[nodiscard]] Identifier ident() const;
  174. };
  175. bool operator==(const Activity &rhs, const Activity &lhs);
  176. bool operator!=(const Activity &rhs, const Activity &lhs);
  177. bool operator<(const Activity &rhs, const Activity &lhs);
  178. bool operator>(const Activity &rhs, const Activity &lhs);
  179. /* ==================================================================== */
  180. /**
  181. * @brief The ActivityList
  182. * @ingroup gui
  183. *
  184. * A QList based list of Activities
  185. */
  186. using ActivityList = QList<Activity>;
  187. }
  188. Q_DECLARE_METATYPE(OCC::Activity)
  189. Q_DECLARE_METATYPE(OCC::ActivityList)
  190. Q_DECLARE_METATYPE(OCC::Activity::Type)
  191. Q_DECLARE_METATYPE(OCC::Activity::RichSubjectParameter)
  192. Q_DECLARE_METATYPE(OCC::ActivityLink)
  193. Q_DECLARE_METATYPE(OCC::PreviewData)
  194. #endif // ACTIVITYDATA_H