From cd80c749d66596ab13d9c4ffb74509b1ab042eda Mon Sep 17 00:00:00 2001 From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Thu, 16 Jan 2020 14:01:54 +0100 Subject: [PATCH] Retreive and svg data from icon property url for activity entries Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- src/gui/iconjob.cpp | 1 + src/gui/tray/ActivityData.h | 1 + src/gui/tray/ActivityListModel.cpp | 26 ++++++++++++++++++++++++-- src/gui/tray/ActivityListModel.h | 1 + src/gui/tray/NotificationHandler.cpp | 12 +++++------- src/gui/tray/NotificationHandler.h | 2 +- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/gui/iconjob.cpp b/src/gui/iconjob.cpp index c77a925b1..69f84d4bd 100644 --- a/src/gui/iconjob.cpp +++ b/src/gui/iconjob.cpp @@ -23,6 +23,7 @@ IconJob::IconJob(const QUrl &url, QObject *parent) : this, &IconJob::finished); QNetworkRequest request(url); + request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); _accessManager.get(request); } diff --git a/src/gui/tray/ActivityData.h b/src/gui/tray/ActivityData.h index d912a7e3c..f2fc0e345 100644 --- a/src/gui/tray/ActivityData.h +++ b/src/gui/tray/ActivityData.h @@ -66,6 +66,7 @@ public: QDateTime _dateTime; QString _accName; QString _icon; + QString _iconData; // Stores information about the error int _status; diff --git a/src/gui/tray/ActivityListModel.cpp b/src/gui/tray/ActivityListModel.cpp index 701c543ee..88f967f6d 100644 --- a/src/gui/tray/ActivityListModel.cpp +++ b/src/gui/tray/ActivityListModel.cpp @@ -22,6 +22,7 @@ #include "accountstate.h" #include "accountmanager.h" #include "folderman.h" +#include "iconjob.h" #include "accessmanager.h" #include "ActivityData.h" @@ -77,7 +78,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const list = FolderMan::instance()->findFileInLocalFolders(relPath, ast->account()); if (list.count() > 0) { if (relPath.startsWith('/') || relPath.startsWith('\\')) { - return relPath.remove(0,1); + return relPath.remove(0, 1); } else { return relPath; } @@ -135,6 +136,11 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const return "qrc:///client/theme/black/state-sync.svg"; } } else { + // We have an activity + if (!a._iconData.isEmpty()) { + QString svgData = "data:image/svg+xml;utf8," + a._iconData; + return svgData; + } return "qrc:///client/theme/black/activity.svg"; } } @@ -242,7 +248,7 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st a._type = Activity::ActivityType; a._objectType = json.value("object_type").toString(); a._accName = ast->account()->displayName(); - a._id = json.value("id").toInt(); + a._id = json.value("activity_id").toInt(); a._fileAction = json.value("type").toString(); a._subject = json.value("subject").toString(); a._message = json.value("message").toString(); @@ -250,6 +256,13 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st a._link = QUrl(json.value("link").toString()); a._dateTime = QDateTime::fromString(json.value("datetime").toString(), Qt::ISODate); a._icon = json.value("icon").toString(); + + if (!a._icon.isEmpty()) { + IconJob *iconJob = new IconJob(QUrl(a._icon)); + iconJob->setProperty("activityId", a._id); + connect(iconJob, &IconJob::jobFinished, this, &ActivityListModel::slotIconDownloaded); + } + list.append(a); } @@ -260,6 +273,15 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st combineActivityLists(); } +void ActivityListModel::slotIconDownloaded(QByteArray iconData) +{ + for (size_t i = 0; i < _activityLists.count(); i++) { + if (_activityLists[i]._id == sender()->property("activityId").toLongLong()) { + _activityLists[i]._iconData = iconData; + } + } +} + void ActivityListModel::addErrorToActivityList(Activity activity) { qCInfo(lcActivity) << "Error successfully added to the notification list: " << activity._subject; diff --git a/src/gui/tray/ActivityListModel.h b/src/gui/tray/ActivityListModel.h index f073504a0..c55797d70 100644 --- a/src/gui/tray/ActivityListModel.h +++ b/src/gui/tray/ActivityListModel.h @@ -78,6 +78,7 @@ public slots: private slots: void slotActivitiesReceived(const QJsonDocument &json, int statusCode); + void slotIconDownloaded(QByteArray iconData); signals: void activityJobStatusCode(int statusCode); diff --git a/src/gui/tray/NotificationHandler.cpp b/src/gui/tray/NotificationHandler.cpp index ff218f925..4571f9a9d 100644 --- a/src/gui/tray/NotificationHandler.cpp +++ b/src/gui/tray/NotificationHandler.cpp @@ -17,7 +17,7 @@ const QString notificationsPath = QLatin1String("ocs/v2.php/apps/notifications/a const char propertyAccountStateC[] = "oc_account_state"; const int successStatusCode = 200; const int notModifiedStatusCode = 304; -QMap ServerNotificationHandler::iconCache; +QMap ServerNotificationHandler::iconCache; ServerNotificationHandler::ServerNotificationHandler(AccountState *accountState, QObject *parent) : QObject(parent) @@ -64,9 +64,7 @@ void ServerNotificationHandler::slotEtagResponseHeaderReceived(const QByteArray void ServerNotificationHandler::slotIconDownloaded(QByteArray iconData) { - QPixmap pixmap; - pixmap.loadFromData(iconData); - iconCache.insert(sender()->property("activityId").toInt(), QIcon(pixmap)); + iconCache.insert(sender()->property("activityId").toInt(),iconData); } void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &json, int statusCode) @@ -94,7 +92,7 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j auto json = element.toObject(); a._type = Activity::NotificationType; a._accName = ai->account()->displayName(); - a._id = json.value("notification_id").toInt(); + a._id = json.value("activity_id").toInt(); //need to know, specially for remote_share a._objectType = json.value("object_type").toString(); @@ -104,8 +102,8 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j a._message = json.value("message").toString(); a._icon = json.value("icon").toString(); - if (!json.value("icon").toString().isEmpty()) { - IconJob *iconJob = new IconJob(QUrl(json.value("icon").toString())); + if (!a._icon.isEmpty()) { + IconJob *iconJob = new IconJob(QUrl(a._icon)); iconJob->setProperty("activityId", a._id); connect(iconJob, &IconJob::jobFinished, this, &ServerNotificationHandler::slotIconDownloaded); } diff --git a/src/gui/tray/NotificationHandler.h b/src/gui/tray/NotificationHandler.h index 01caef428..69e286e78 100644 --- a/src/gui/tray/NotificationHandler.h +++ b/src/gui/tray/NotificationHandler.h @@ -14,7 +14,7 @@ class ServerNotificationHandler : public QObject Q_OBJECT public: explicit ServerNotificationHandler(AccountState *accountState, QObject *parent = nullptr); - static QMap iconCache; + static QMap iconCache; signals: void newNotificationList(ActivityList);