Skip to content

Commit

Permalink
Clean up unneeded changes
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
  • Loading branch information
claucambra committed Apr 21, 2022
1 parent f131a9c commit 214688a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 78 deletions.
64 changes: 56 additions & 8 deletions src/gui/tray/activitydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ActivityLink ActivityLink::createFomJsonObject(const QJsonObject &obj)
return activityLink;
}

OCC::Activity Activity::fromActivityJson(const QJsonObject json, const AccountPtr account)
OCC::Activity Activity::fromActivityJson(const QJsonObject &json, const AccountPtr account)
{
const auto activityUser = json.value(QStringLiteral("user")).toString();

Expand Down Expand Up @@ -93,7 +93,7 @@ OCC::Activity Activity::fromActivityJson(const QJsonObject json, const AccountPt
for (auto i = parameters.begin(); i != parameters.end(); ++i) {
const auto parameterJsonObject = i.value().toObject();

activity._subjectRichParameters[i.key()] = RichSubjectParameter {
activity._subjectRichParameters[i.key()] = Activity::RichSubjectParameter {
parameterJsonObject.value(QStringLiteral("type")).toString(),
parameterJsonObject.value(QStringLiteral("id")).toString(),
parameterJsonObject.value(QStringLiteral("name")).toString(),
Expand All @@ -118,8 +118,9 @@ OCC::Activity Activity::fromActivityJson(const QJsonObject json, const AccountPt
}

const auto previewsData = json.value(QStringLiteral("previews")).toArray();
const QMimeDatabase mimeDb;

for(const auto preview : previewsData) {
for(const auto &preview : previewsData) {
const auto jsonPreviewData = preview.toObject();

PreviewData data;
Expand All @@ -129,11 +130,10 @@ OCC::Activity Activity::fromActivityJson(const QJsonObject json, const AccountPt
data._view = jsonPreviewData.value(QStringLiteral("view")).toString();
data._filename = jsonPreviewData.value(QStringLiteral("filename")).toString();

if(data._mimeType.contains(QStringLiteral("text/"))) {
data._source = account->url().toString() + QStringLiteral("/index.php/apps/theming/img/core/filetypes/text.svg");
data._isMimeTypeIcon = true;
} else if (data._mimeType.contains(QStringLiteral("/pdf"))) {
data._source = account->url().toString() + QStringLiteral("/index.php/apps/theming/img/core/filetypes/application-pdf.svg");
const auto mimeType = mimeDb.mimeTypeForName(data._mimeType);

if(data._mimeType.contains(QStringLiteral("text/")) || data._mimeType.contains(QStringLiteral("/pdf"))) {
data._source = account->url().toString() + relativeServerFileTypeIconPath(mimeType);
data._isMimeTypeIcon = true;
} else {
data._source = jsonPreviewData.value(QStringLiteral("source")).toString();
Expand Down Expand Up @@ -164,4 +164,52 @@ OCC::Activity Activity::fromActivityJson(const QJsonObject json, const AccountPt
return activity;
}

QString Activity::relativeServerFileTypeIconPath(const QMimeType &mimeType)
{
if(mimeType.isValid() && mimeType.inherits("text/plain")) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/text.svg");
} else if (mimeType.isValid() && mimeType.name().startsWith("image")) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/image.svg");
} else if (mimeType.isValid() && mimeType.name().startsWith("audio")) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/audio.svg");
} else if (mimeType.isValid() && mimeType.name().startsWith("video")) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/video.svg");
} else if (mimeType.isValid() && (mimeType.inherits("application/vnd.oasis.opendocument.text") ||
mimeType.inherits("application/msword") ||
mimeType.inherits("application/vnd.openxmlformats-officedocument.wordprocessingml.document") ||
mimeType.inherits("application/vnd.openxmlformats-officedocument.wordprocessingml.template")||
mimeType.inherits("application/vnd.ms-word.document.macroEnabled.12") ||
mimeType.inherits("application/vnd.ms-word.template.macroEnabled.12") ||
mimeType.inherits("application/vnd.apple.pages"))) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/x-office-document.svg");
} else if (mimeType.isValid() && mimeType.inherits("application/vnd.oasis.opendocument.graphics")) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/x-office-drawing.svg");
} else if (mimeType.isValid() && (mimeType.inherits("application/vnd.oasis.opendocument.presentation") ||
mimeType.inherits("application/vnd.ms-powerpoint") ||
mimeType.inherits("application/vnd.openxmlformats-officedocument.presentationml.presentation") ||
mimeType.inherits("application/vnd.openxmlformats-officedocument.presentationml.template") ||
mimeType.inherits("application/vnd.openxmlformats-officedocument.presentationml.slideshow") ||
mimeType.inherits("application/vnd.ms-powerpoint.addin.macroEnabled.12") ||
mimeType.inherits("application/vnd.ms-powerpoint.presentation.macroEnabled.12") ||
mimeType.inherits("application/vnd.ms-powerpoint.template.macroEnabled.12") ||
mimeType.inherits("application/vnd.ms-powerpoint.slideshow.macroEnabled.12") ||
mimeType.inherits("application/vnd.apple.keynote"))) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/x-office-presentation.svg");
} else if (mimeType.isValid() && (mimeType.inherits("application/vnd.oasis.opendocument.spreadsheet") ||
mimeType.inherits("application/vnd.ms-excel") ||
mimeType.inherits("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ||
mimeType.inherits("application/vnd.openxmlformats-officedocument.spreadsheetml.template") ||
mimeType.inherits("application/vnd.ms-excel.sheet.macroEnabled.12") ||
mimeType.inherits("application/vnd.ms-excel.template.macroEnabled.12") ||
mimeType.inherits("application/vnd.ms-excel.addin.macroEnabled.12") ||
mimeType.inherits("application/vnd.ms-excel.sheet.binary.macroEnabled.12") ||
mimeType.inherits("application/vnd.apple.numbers"))) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/x-office-document.svg");
} else if (mimeType.isValid() && mimeType.inherits("application/pdf")) {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/application-pdf.svg");
} else {
return QStringLiteral("/index.php/apps/theming/img/core/filetypes/file.svg");
}
}

}
88 changes: 19 additions & 69 deletions src/gui/tray/activitydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace OCC {
class ActivityLink
{
Q_GADGET

Q_PROPERTY(QString imageSource MEMBER _imageSource)
Q_PROPERTY(QString imageSourceHovered MEMBER _imageSourceHovered)
Q_PROPERTY(QString label MEMBER _label)
Expand Down Expand Up @@ -79,40 +79,6 @@ class PreviewData
QString _filename;
};

class RichSubjectParameter
{
Q_GADGET

Q_PROPERTY(QString type MEMBER type)
Q_PROPERTY(QString id MEMBER id)
Q_PROPERTY(QString name MEMBER name)
Q_PROPERTY(QString path MEMBER path)
Q_PROPERTY(QUrl link MEMBER link)

public:
QString type; // Required
QString id; // Required
QString name; // Required
QString path; // Required (for files only)
QUrl link; // Optional (files only)
};

class TalkNotificationData
{
Q_GADGET

Q_PROPERTY(QString conversationToken MEMBER conversationToken)
Q_PROPERTY(QString messageId MEMBER messageId)
Q_PROPERTY(QString messageSent MEMBER messageSent)
Q_PROPERTY(QString userAvatar MEMBER userAvatar)

public:
QString conversationToken;
QString messageId;
QString messageSent;
QString userAvatar;
};

/* ==================================================================== */
/**
* @brief Activity Structure
Expand All @@ -123,33 +89,6 @@ class TalkNotificationData

class Activity
{
Q_GADGET

Q_PROPERTY(Type type MEMBER _type)
Q_PROPERTY(qlonglong id MEMBER _id)
Q_PROPERTY(QString fileAction MEMBER _fileAction)
Q_PROPERTY(int objectId MEMBER _objectId)
Q_PROPERTY(TalkNotificationData talkNotificationData READ talkNotificationData CONSTANT)
Q_PROPERTY(QString objectType MEMBER _objectType)
Q_PROPERTY(QString objectName MEMBER _objectName)
Q_PROPERTY(QString subject MEMBER _subject)
Q_PROPERTY(QString subjectRich MEMBER _subjectRich)
Q_PROPERTY(QString subjectDisplay MEMBER _subjectDisplay)
Q_PROPERTY(QString message MEMBER _message)
Q_PROPERTY(QString folder MEMBER _folder)
Q_PROPERTY(QString file MEMBER _file)
Q_PROPERTY(QString renamedFile MEMBER _renamedFile)
Q_PROPERTY(QUrl link MEMBER _link)
Q_PROPERTY(QDateTime dateTime MEMBER _dateTime)
Q_PROPERTY(qint64 expireAtMsecs MEMBER _expireAtMsecs)
Q_PROPERTY(QString accName MEMBER _accName)
Q_PROPERTY(QString darkIcon MEMBER _darkIcon)
Q_PROPERTY(QString lightIcon MEMBER _lightIcon)
Q_PROPERTY(bool isCurrentUserFileActivity MEMBER _isCurrentUserFileActivity)
Q_PROPERTY(QVector<PreviewData> previews READ previews CONSTANT)
Q_PROPERTY(int status MEMBER _status)
Q_PROPERTY(QVector<ActivityLink> links READ links CONSTANT)

public:
using Identifier = QPair<qlonglong, QString>;

Expand All @@ -159,9 +98,25 @@ class Activity
SyncResultType,
SyncFileItemType
};
Q_ENUM(Type);

static Activity fromActivityJson(const QJsonObject json, const AccountPtr account);
static Activity fromActivityJson(const QJsonObject &json, const AccountPtr account);

static QString relativeServerFileTypeIconPath(const QMimeType &mimeType);

struct RichSubjectParameter {
QString type; // Required
QString id; // Required
QString name; // Required
QString path; // Required (for files only)
QUrl link; // Optional (files only)
};

struct TalkNotificationData {
QString conversationToken;
QString messageId;
QString messageSent;
QString userAvatar;
};

Type _type;
qlonglong _id;
Expand Down Expand Up @@ -199,11 +154,6 @@ class Activity


Identifier ident() const;

private:
TalkNotificationData talkNotificationData() { return _talkNotificationData; };
QVector<PreviewData> previews() { return _previews; };
QVector<ActivityLink> links() { return _links; };
};

bool operator==(const Activity &rhs, const Activity &lhs);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/notificationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
const auto richParams = json.value("subjectRichParameters").toObject();
for(const auto &key : richParams.keys()) {
const auto parameterJsonObject = richParams.value(key).toObject();
a._subjectRichParameters.insert(key, RichSubjectParameter{
a._subjectRichParameters.insert(key, Activity::RichSubjectParameter{
parameterJsonObject.value(QStringLiteral("type")).toString(),
parameterJsonObject.value(QStringLiteral("id")).toString(),
parameterJsonObject.value(QStringLiteral("name")).toString(),
Expand Down

0 comments on commit 214688a

Please sign in to comment.