Retreive and svg data from icon property url for activity entries
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Thu, 16 Jan 2020 13:01:54 +0000 (14:01 +0100)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Thu, 16 Jan 2020 13:01:54 +0000 (14:01 +0100)
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
src/gui/iconjob.cpp
src/gui/tray/ActivityData.h
src/gui/tray/ActivityListModel.cpp
src/gui/tray/ActivityListModel.h
src/gui/tray/NotificationHandler.cpp
src/gui/tray/NotificationHandler.h

index c77a925b18a4c5b95112174fabc77d93e4aa36fa..69f84d4bd791de97d4b74a3101a6340c2ec2a66c 100644 (file)
@@ -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);
 }
 
index d912a7e3c6611e4ec4966bd1cd34bbf5cacb3236..f2fc0e34567668165a38006c509e207e00d4493d 100644 (file)
@@ -66,6 +66,7 @@ public:
     QDateTime _dateTime;
     QString _accName;
     QString _icon;
+    QString _iconData;
 
     // Stores information about the error
     int _status;
index 701c543eed909d6eed1a21c268bf06d6345177de..88f967f6df8ed5a2486ca29c2a6e959d466e6ad0 100644 (file)
@@ -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;
index f073504a0034641c914c0290530806a4f3a03859..c55797d7024ba8bd281550e1a6a042001fb9f1cd 100644 (file)
@@ -78,6 +78,7 @@ public slots:
 
 private slots:
     void slotActivitiesReceived(const QJsonDocument &json, int statusCode);
+    void slotIconDownloaded(QByteArray iconData);
 
 signals:
     void activityJobStatusCode(int statusCode);
index ff218f9258b4be8fe62aa72a0634aad7fa7a6234..4571f9a9dfe138404b70f43294e1ff39d030d412 100644 (file)
@@ -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<int, QIcon> ServerNotificationHandler::iconCache;
+QMap<int, QByteArray> 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);
         }
index 01caef428e1d2622f44a46bd41f0893d777aa718..69e286e783e337b05b25ce3b23060258e61ef7a3 100644 (file)
@@ -14,7 +14,7 @@ class ServerNotificationHandler : public QObject
     Q_OBJECT
 public:
     explicit ServerNotificationHandler(AccountState *accountState, QObject *parent = nullptr);
-    static QMap<int, QIcon> iconCache;
+    static QMap<int, QByteArray> iconCache;
 
 signals:
     void newNotificationList(ActivityList);