Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamila San <hello@camila.codes>2018-04-25 18:20:42 +0300
committerCamila San <hello@camila.codes>2018-07-07 14:17:53 +0300
commit9120420dc2e29c7fb02235024b89be9d5404f2f3 (patch)
treec22104e82293667fdebc462674a06da7bdefcf9c
parent581cc2cab29738db84c788c63fffe755a7a5ffaa (diff)
Displays the notification icon when available.
Signed-off-by: Camila San <hello@camila.codes>
-rw-r--r--src/gui/activitydata.h1
-rw-r--r--src/gui/activitylistmodel.cpp14
-rw-r--r--src/gui/activitywidget.cpp1
-rw-r--r--src/gui/servernotificationhandler.cpp16
-rw-r--r--src/gui/servernotificationhandler.h2
5 files changed, 29 insertions, 5 deletions
diff --git a/src/gui/activitydata.h b/src/gui/activitydata.h
index ca2e00e4a..5a95b68be 100644
--- a/src/gui/activitydata.h
+++ b/src/gui/activitydata.h
@@ -16,6 +16,7 @@
#define ACTIVITYDATA_H
#include <QtCore>
+#include <QIcon>
namespace OCC {
/**
diff --git a/src/gui/activitylistmodel.cpp b/src/gui/activitylistmodel.cpp
index faece7d93..ff91a2b07 100644
--- a/src/gui/activitylistmodel.cpp
+++ b/src/gui/activitylistmodel.cpp
@@ -29,6 +29,8 @@
#include "activitydata.h"
#include "activitylistmodel.h"
+#include "servernotificationhandler.h"
+
namespace OCC {
Q_LOGGING_CATEGORY(lcActivity, "nextcloud.gui.activity", QtInfoMsg)
@@ -81,11 +83,13 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
// return QIcon(QLatin1String(":/client/resources/account.png"));
// break;
case ActivityItemDelegate::ActionIconRole:
- if(a._type == Activity::NotificationType)
- return QIcon(QLatin1String(":/client/resources/bell.png"));
- else if(a._type == Activity::ActivityType)
- return QIcon(QLatin1String(":/client/resources/activity.png"));
- return QVariant();
+ if(a._type == Activity::NotificationType){
+ QIcon cachedIcon = ServerNotificationHandler::iconCache.value(a._id);
+ if(!cachedIcon.isNull())
+ return cachedIcon;
+ else QIcon(QLatin1String(":/client/resources/bell.png"));
+ }
+ return QIcon(QLatin1String(":/client/resources/activity.png"));
break;
case ActivityItemDelegate::ActionRole:{
QVariant type;
diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index df62cba6a..cdfda0575 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -368,6 +368,7 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list)
emit guiLog(activity._subject, activity._accName);
}
}
+
_model->addToActivityList(activity);
}
}
diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp
index 64a45a83e..66d4ac51f 100644
--- a/src/gui/servernotificationhandler.cpp
+++ b/src/gui/servernotificationhandler.cpp
@@ -17,6 +17,8 @@
#include "capabilities.h"
#include "networkjobs.h"
+#include "iconjob.h"
+
#include <QJsonDocument>
#include <QJsonObject>
@@ -28,6 +30,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;
ServerNotificationHandler::ServerNotificationHandler(AccountState *accountState, QObject *parent)
: QObject(parent)
@@ -73,6 +76,13 @@ void ServerNotificationHandler::slotEtagResponseHeaderReceived(const QByteArray
}
}
+void ServerNotificationHandler::slotIconDownloaded(QByteArray iconData){
+ QPixmap pixmap;
+ pixmap.loadFromData(iconData);
+ iconCache.insert(sender()->property("activityId").toInt(), QIcon(pixmap));
+ qDebug() << "Icon cached for activity " << sender()->property("activityId").toInt();
+}
+
void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &json, int statusCode)
{
if (statusCode != successStatusCode && statusCode != notModifiedStatusCode) {
@@ -102,6 +112,12 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
a._subject = json.value("subject").toString();
a._message = json.value("message").toString();
+ if(!json.value("icon").toString().isEmpty()){
+ IconJob *iconJob = new IconJob(QUrl(json.value("icon").toString()));
+ iconJob->setProperty("activityId", a._id);
+ connect(iconJob, &IconJob::jobFinished, this, &ServerNotificationHandler::slotIconDownloaded);
+ }
+
QString s = json.value("link").toString();
if (!s.isEmpty()) {
QUrl link(s);
diff --git a/src/gui/servernotificationhandler.h b/src/gui/servernotificationhandler.h
index c63cc8fb5..0858dd874 100644
--- a/src/gui/servernotificationhandler.h
+++ b/src/gui/servernotificationhandler.h
@@ -28,6 +28,7 @@ class ServerNotificationHandler : public QObject
Q_OBJECT
public:
explicit ServerNotificationHandler(AccountState *accountState, QObject *parent = 0);
+ static QMap<int, QIcon> iconCache;
signals:
void newNotificationList(ActivityList);
@@ -38,6 +39,7 @@ public slots:
private slots:
void slotNotificationsReceived(const QJsonDocument &json, int statusCode);
void slotEtagResponseHeaderReceived(const QByteArray &value, int statusCode);
+ void slotIconDownloaded(QByteArray iconData);
private:
QPointer<JsonApiJob> _notificationJob;