activitydata.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. /* ==================================================================== */
  71. /**
  72. * @brief Activity Structure
  73. * @ingroup gui
  74. *
  75. * contains all the information describing a single activity.
  76. */
  77. class Activity
  78. {
  79. public:
  80. using Identifier = QPair<qlonglong, QString>;
  81. // Note that these are in the order we want to present them in the model!
  82. enum Type {
  83. DummyFetchingActivityType,
  84. NotificationType,
  85. SyncResultType,
  86. SyncFileItemType,
  87. ActivityType,
  88. DummyMoreActivitiesAvailableType,
  89. };
  90. static Activity fromActivityJson(const QJsonObject &json, const AccountPtr account);
  91. static QString relativeServerFileTypeIconPath(const QMimeType &mimeType);
  92. static QString localFilePathForActivity(const Activity &activity, const AccountPtr account);
  93. struct RichSubjectParameter {
  94. QString type; // Required
  95. QString id; // Required
  96. QString name; // Required
  97. QString path; // Required (for files only)
  98. QUrl link; // Optional (files only)
  99. };
  100. struct TalkNotificationData {
  101. QString conversationToken;
  102. QString messageId;
  103. QString messageSent;
  104. QString userAvatar;
  105. };
  106. Type _type;
  107. qlonglong _id = 0LL;
  108. QString _fileAction;
  109. int _objectId = 0;
  110. TalkNotificationData _talkNotificationData;
  111. QString _objectType;
  112. QString _objectName;
  113. QString _subject;
  114. QString _subjectRich;
  115. QVariantMap _subjectRichParameters;
  116. QString _subjectDisplay;
  117. QString _message;
  118. QString _folder;
  119. QString _file;
  120. QString _renamedFile;
  121. bool _isMultiObjectActivity = false;
  122. QUrl _link;
  123. QDateTime _dateTime;
  124. qint64 _expireAtMsecs = -1;
  125. QString _accName;
  126. QString _icon;
  127. bool _isCurrentUserFileActivity = false;
  128. QVector<PreviewData> _previews;
  129. // Stores information about the error
  130. SyncFileItem::Status _syncFileItemStatus = SyncFileItem::Status::NoStatus;
  131. SyncResult::Status _syncResultStatus = SyncResult::Status::Undefined;
  132. QVector<ActivityLink> _links;
  133. /**
  134. * @brief Sort operator to sort the list youngest first.
  135. * @param val
  136. * @return
  137. */
  138. bool _shouldNotify = true;
  139. [[nodiscard]] Identifier ident() const;
  140. };
  141. bool operator==(const Activity &rhs, const Activity &lhs);
  142. bool operator!=(const Activity &rhs, const Activity &lhs);
  143. bool operator<(const Activity &rhs, const Activity &lhs);
  144. bool operator>(const Activity &rhs, const Activity &lhs);
  145. /* ==================================================================== */
  146. /**
  147. * @brief The ActivityList
  148. * @ingroup gui
  149. *
  150. * A QList based list of Activities
  151. */
  152. using ActivityList = QList<Activity>;
  153. }
  154. Q_DECLARE_METATYPE(OCC::Activity)
  155. Q_DECLARE_METATYPE(OCC::ActivityList)
  156. Q_DECLARE_METATYPE(OCC::Activity::Type)
  157. Q_DECLARE_METATYPE(OCC::Activity::RichSubjectParameter)
  158. Q_DECLARE_METATYPE(OCC::ActivityLink)
  159. Q_DECLARE_METATYPE(OCC::PreviewData)
  160. #endif // ACTIVITYDATA_H