Retreive and svg data from icon property url for activity entries

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
Dominique Fuchs 2020-01-16 14:01:54 +01:00
parent 06fdde8f1e
commit cd80c749d6
6 changed files with 33 additions and 10 deletions

View 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);
}

View file

@ -66,6 +66,7 @@ public:
QDateTime _dateTime;
QString _accName;
QString _icon;
QString _iconData;
// Stores information about the error
int _status;

View 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;

View 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);

View 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);
}

View 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);