From e3c7a5a2ffc8115b3d0949be78960baa7cfb95b0 Mon Sep 17 00:00:00 2001 From: Camila San Date: Wed, 25 Apr 2018 17:20:42 +0200 Subject: [PATCH] Changes Activity list view icons, buttons and drawing. - Displays the notification icon when available. - Adds dismiss button with an icon. - Handles buttons actions in the list view. - Changes what is painted first (activityitemdelegate) for each row in the activity list. Signed-off-by: Camila San --- client.qrc | 4 +- resources/bell.png | Bin 495 -> 0 bytes resources/bell.svg | 4 + resources/close.svg | 4 + src/gui/activitydata.h | 1 + src/gui/activityitemdelegate.cpp | 207 ++++++++++++++++---------- src/gui/activityitemdelegate.h | 7 +- src/gui/activitylistmodel.cpp | 18 ++- src/gui/activitywidget.cpp | 47 +++--- src/gui/activitywidget.h | 5 +- src/gui/notificationwidget.cpp | 2 +- src/gui/notificationwidget.ui | 4 +- src/gui/servernotificationhandler.cpp | 16 ++ src/gui/servernotificationhandler.h | 2 + 14 files changed, 207 insertions(+), 114 deletions(-) delete mode 100644 resources/bell.png create mode 100644 resources/bell.svg create mode 100644 resources/close.svg diff --git a/client.qrc b/client.qrc index 546070187..506476d74 100644 --- a/client.qrc +++ b/client.qrc @@ -22,6 +22,8 @@ resources/account.png resources/more.svg resources/delete.png - resources/bell.png + resources/close.svg + resources/bell.svg + diff --git a/resources/bell.png b/resources/bell.png deleted file mode 100644 index d96a82bc3d25d2a230fdbbd948c33d88e80ae931..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 495 zcmVS7xDdMR1b2xmckOd0LHpdfnN5NlA#Y$| z0}%v4ppnsE5O|5`st9e=aq|ou56qb}qd#~SFXw%~?{l8pThP3QaU0z@z*oG&p%&GS zGPY4o*e@*O0mfoqZWU3%aSEEWpV+~pW<0InCz{?!Kq%EVA1-*6*Lhuaxk%z3arv^`2hj@a|xQqAk1P$T~cF}|XXKm3A%;O){@f{m6W9q7q l6W$h&=s^7C0yeV_oB$f + + + diff --git a/resources/close.svg b/resources/close.svg new file mode 100644 index 000000000..c58fe6379 --- /dev/null +++ b/resources/close.svg @@ -0,0 +1,4 @@ + + + + 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 +#include namespace OCC { /** diff --git a/src/gui/activityitemdelegate.cpp b/src/gui/activityitemdelegate.cpp index 80f41b42c..4579ac399 100644 --- a/src/gui/activityitemdelegate.cpp +++ b/src/gui/activityitemdelegate.cpp @@ -30,7 +30,9 @@ namespace OCC { int ActivityItemDelegate::_iconHeight = 0; int ActivityItemDelegate::_margin = 0; -int ActivityItemDelegate::_buttonWidth = 0; +int ActivityItemDelegate::_primaryButtonWidth = 0; +int ActivityItemDelegate::_secondaryButtonWidth = 0; +int ActivityItemDelegate::_spaceBetweenButtons = 0; int ActivityItemDelegate::_timeWidth = 0; int ActivityItemDelegate::_buttonHeight = 0; @@ -55,9 +57,9 @@ int ActivityItemDelegate::rowHeight() QFont f = opt.font; QFontMetrics fm(f); - _margin = fm.height() / 4; + _margin = fm.height() / 2; } - return iconHeight() + 2 * _margin; + return iconHeight() + 5 * _margin; } QSize ActivityItemDelegate::sizeHint(const QStyleOptionViewItem &option, @@ -71,126 +73,158 @@ QSize ActivityItemDelegate::sizeHint(const QStyleOptionViewItem &option, void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { -// QIcon userIcon = qvariant_cast(index.data(UserIconRole)); -// QString pathText = qvariant_cast(index.data(PathRole)); -// QString remoteLink = qvariant_cast(index.data(LinkRole)); -// userIconRect.setLeft(actionIconRect.right() + margin); -// userIconRect.setWidth(iconWidth); -// userIconRect.setHeight(iconHeight); -// userIconRect.setTop(actionIconRect.top()); -// QRect userIconRect = option.rect; -// pm = userIcon.pixmap(iconWidth, iconHeight, QIcon::Normal); -// painter->drawPixmap(QPoint(userIconRect.left(), userIconRect.top()), pm); - QStyledItemDelegate::paint(painter, option, index); QFont font = option.font; QFontMetrics fm(font); - int margin = fm.height() / 4; + int margin = fm.height() / 2.5; painter->save(); + int iconSize = 16; + int iconOffset = qRound(fm.height() / 4.0 * 7.0); + int offset = 4; - QIcon actionIcon = qvariant_cast(index.data(ActionIconRole)); + // get the data Activity::Type activityType = qvariant_cast(index.data(ActionRole)); + QIcon actionIcon = qvariant_cast(index.data(ActionIconRole)); QString actionText = qvariant_cast(index.data(ActionTextRole)); QString messageText = qvariant_cast(index.data(MessageRole)); + QList customList = index.data(ActionsLinksRole).toList(); QString timeText = qvariant_cast(index.data(PointInTimeRole)); - QString accountRole = qvariant_cast(index.data(AccountRole)); bool accountOnline = qvariant_cast(index.data(AccountConnectedRole)); // activity/notification icons QRect actionIconRect = option.rect; - int iconHeight = qRound(fm.height() / 5.0 * 8.0); - int iconWidth = iconHeight; - actionIconRect.setLeft(option.rect.left() + margin); - actionIconRect.setWidth(iconWidth); - actionIconRect.setHeight(iconHeight); - actionIconRect.setTop(actionIconRect.top() + margin); - - // time rect - QRect timeBox; - int atPos = accountRole.indexOf(QLatin1Char('@')); - if (atPos > -1) { - accountRole.remove(0, atPos + 1); - } - QString timeStr = tr("%1 on %2").arg(timeText, accountRole); - if (!accountOnline) timeStr = tr("%1 on %2 (disconnected)").arg(timeText, accountRole); - int textTopOffset = qRound((iconHeight - fm.height()) / 2.0); - int timeBoxWidth = fm.width(timeStr); - timeBox.setTop(actionIconRect.top() + textTopOffset); - timeBox.setLeft(option.rect.right() - timeBoxWidth - margin); - timeBox.setRight(option.rect.right() + margin); - timeBox.setHeight(fm.height()); - _timeWidth = timeBox.width(); + actionIconRect.setLeft(option.rect.left() + iconOffset/3); + actionIconRect.setRight(option.rect.left() + iconOffset); + actionIconRect.setTop(option.rect.top() + qRound((option.rect.height() - 16)/3.0)); // subject text rect - QRect actionTextBox = timeBox; + QRect actionTextBox = actionIconRect; int actionTextBoxWidth = fm.width(actionText); + actionTextBox.setTop(option.rect.top() + margin + offset/2); + actionTextBox.setHeight(fm.height()); actionTextBox.setLeft(actionIconRect.right() + margin); actionTextBox.setRight(actionTextBox.left() + actionTextBoxWidth + margin); // message text rect - QRect messageTextBox = timeBox; - if(!messageText.isEmpty()){ - int messageTextBoxWidth = fm.width(messageText.prepend(" - ")); - messageTextBox.setLeft(actionTextBox.right() - margin); - messageTextBox.setRight(messageTextBox.left() + messageTextBoxWidth); - } else { - messageTextBox.setWidth(0); + QRect messageTextBox = actionTextBox; + messageTextBox.setTop(option.rect.top() + fm.height() + margin); + messageTextBox.setHeight(actionTextBox.height()); + messageTextBox.setBottom(messageTextBox.top() + fm.height()); + if(messageText.isEmpty()){ + messageTextBox.setHeight(0); + messageTextBox.setBottom(messageTextBox.top()); } - QStyleOptionButton optionsButton; + // time box rect + QRect timeBox = messageTextBox; + QString timeStr = tr("%1").arg(timeText); + timeBox.setTop(option.rect.top() + fm.height() + fm.height() + margin + offset/2); + timeBox.setHeight(actionTextBox.height()); + timeBox.setBottom(timeBox.top() + fm.height()); + + // buttons + QStyleOptionButton primaryButton; + QStyleOptionButton secondaryButton; if(activityType == Activity::Type::NotificationType){ - int rightMargin = margin * 2; - int leftMargin = margin * 4; - int right = timeBox.left() - rightMargin; - int left = timeBox.left() - leftMargin; - optionsButton.rect = option.rect; - optionsButton.text = "..."; - int btnTextWidth = fm.width(optionsButton.text.toAscii()); - optionsButton.rect.setLeft(left - btnTextWidth); - optionsButton.rect.setRight(right); - optionsButton.rect.setTop(option.rect.top() + 5); - optionsButton.rect.setHeight(option.rect.height() - 10); - optionsButton.features |= QStyleOptionButton::DefaultButton; - optionsButton.state |= QStyle::State_Raised; - _buttonWidth = optionsButton.rect.size().width(); - _buttonHeight = optionsButton.rect.height(); + int rightMargin = margin; + int leftMargin = margin * offset; + int top = option.rect.top() + margin - offset; + int buttonSize = option.rect.height()/2.5; + _buttonHeight = buttonSize; + _spaceBetweenButtons = leftMargin; + + // Secondary will be 'Dismiss' or '...' + secondaryButton.rect = option.rect; + secondaryButton.icon = QIcon(QLatin1String(":/client/resources/close.svg")); + if(customList.size() > 1) + secondaryButton.icon = QIcon(QLatin1String(":/client/resources/more.png")); + + int right = option.rect.right() - rightMargin; + int left = right - buttonSize; + secondaryButton.iconSize = QSize(buttonSize, buttonSize); + secondaryButton.rect.setLeft(left); + secondaryButton.rect.setRight(right); + secondaryButton.rect.setTop(top); + secondaryButton.rect.setHeight(_buttonHeight); + secondaryButton.features |= QStyleOptionButton::DefaultButton; + secondaryButton.state |= QStyle::State_Raised; + + // Primary button will be 'More Information' + primaryButton.rect = option.rect; + primaryButton.text = tr("More information"); + right = secondaryButton.rect.left() - rightMargin; + left = secondaryButton.rect.left() - leftMargin; + primaryButton.rect.setLeft(left - fm.width(primaryButton.text)); + primaryButton.rect.setRight(right); + primaryButton.rect.setTop(top); + primaryButton.rect.setHeight(_buttonHeight); + primaryButton.features |= QStyleOptionButton::DefaultButton; + primaryButton.state |= QStyle::State_Raised; + + // save info to be able to filter mouse clicks + _primaryButtonWidth = primaryButton.rect.size().width(); + _secondaryButtonWidth = secondaryButton.rect.size().width(); } - /* === start drawing === */ - QPixmap pm = actionIcon.pixmap(iconWidth, iconHeight, QIcon::Normal); + // draw the icon + QPixmap pm = actionIcon.pixmap(iconSize, iconSize, QIcon::Normal); painter->drawPixmap(QPoint(actionIconRect.left(), actionIconRect.top()), pm); + // change pen color if use is not online + QPalette p = option.palette; + if(!accountOnline) + painter->setPen(p.color(QPalette::Disabled, QPalette::Text)); + + // change pen color if the line is selected QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) cg = QPalette::Inactive; - if (option.state & QStyle::State_Selected) { + + if (option.state & QStyle::State_Selected) painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); - } else { + else painter->setPen(option.palette.color(cg, QPalette::Text)); - } - int spaceLeftForText = (option.rect.width() - (actionIconRect.width() + _buttonWidth))/4; + // calculate space for text - use the max possible before using the elipses + int spaceLeftForText = option.rect.width() - (actionIconRect.width() + margin) - + (_primaryButtonWidth + _secondaryButtonWidth + _spaceBetweenButtons); + // draw the subject const QString elidedAction = fm.elidedText(actionText, Qt::ElideRight, spaceLeftForText); painter->drawText(actionTextBox, elidedAction); + // draw the buttons + if(activityType == Activity::Type::NotificationType){ + QApplication::style()->drawControl(QStyle::CE_PushButton, &primaryButton, painter); + QApplication::style()->drawControl(QStyle::CE_PushButton, &secondaryButton, painter); + } + + // draw the message + // change pen color for the message if(!messageText.isEmpty()){ + painter->setPen(p.color(QPalette::Disabled, QPalette::Text)); + + // check if line is selected + if (option.state & QStyle::State_Selected) + painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); + const QString elidedMessage = fm.elidedText(messageText, Qt::ElideRight, spaceLeftForText); painter->drawText(messageTextBox, elidedMessage); } - if(activityType == Activity::Type::NotificationType) - QApplication::style()->drawControl(QStyle::CE_PushButton, &optionsButton, painter); + // change pen color for the time + painter->setPen(p.color(QPalette::Disabled, QPalette::Highlight)); - if (!accountOnline) { - QPalette p = option.palette; - painter->setPen(p.color(QPalette::Disabled, QPalette::Text)); - } + // check if line is selected + if (option.state & QStyle::State_Selected) + painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); + // draw the time const QString elidedTime = fm.elidedText(timeStr, Qt::ElideRight, spaceLeftForText); painter->drawText(timeBox, elidedTime); + painter->restore(); } @@ -200,14 +234,27 @@ bool ActivityItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, if(qvariant_cast(index.data(ActionRole)) == Activity::Type::NotificationType){ if (event->type() == QEvent::MouseButtonRelease){ QMouseEvent *mouseEvent = (QMouseEvent*)event; - int x = option.rect.left() + option.rect.width() - _buttonWidth - _timeWidth; - int y = option.rect.top(); - if (mouseEvent->x() > x && mouseEvent->x() < (x + _buttonWidth)){ - if(mouseEvent->y() > y && mouseEvent->y() < (y + _buttonHeight)) - emit buttonClickedOnItemView(index); + if(mouseEvent){ + int mouseEventX = mouseEvent->x(); + int mouseEventY = mouseEvent->y(); + int buttonsWidth = _primaryButtonWidth + _spaceBetweenButtons + _secondaryButtonWidth; + int x = option.rect.left() + option.rect.width() - buttonsWidth - _timeWidth; + int y = option.rect.top(); + + if (mouseEventX > x && mouseEventX < x + buttonsWidth){ + if(mouseEventY > y && mouseEventY < y + _buttonHeight){ + if (mouseEventX > x && mouseEventX < x + _primaryButtonWidth) + emit primaryButtonClickedOnItemView(index); + + x += _primaryButtonWidth + _spaceBetweenButtons; + if (mouseEventX > x && mouseEventX < x + _secondaryButtonWidth) + emit secondaryButtonClickedOnItemView(index); + } + } } } } + return QStyledItemDelegate::editorEvent(event, model, option, index); } diff --git a/src/gui/activityitemdelegate.h b/src/gui/activityitemdelegate.h index 821969aeb..9979f1223 100644 --- a/src/gui/activityitemdelegate.h +++ b/src/gui/activityitemdelegate.h @@ -47,12 +47,15 @@ public: static int iconHeight(); signals: - void buttonClickedOnItemView(const QModelIndex &index); + void primaryButtonClickedOnItemView(const QModelIndex &index); + void secondaryButtonClickedOnItemView(const QModelIndex &index); private: static int _margin; static int _iconHeight; - static int _buttonWidth; + static int _primaryButtonWidth; + static int _secondaryButtonWidth; + static int _spaceBetweenButtons; static int _timeWidth; static int _buttonHeight; }; diff --git a/src/gui/activitylistmodel.cpp b/src/gui/activitylistmodel.cpp index faece7d93..17b92a1ab 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) @@ -43,6 +45,10 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const { Activity a; + // filter the get action here + // send only the text of the get action + // if there is more than one send the icon? the ... + if (!index.isValid()) return QVariant(); @@ -67,7 +73,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const } return QVariant(); break; - case ActivityItemDelegate::ActionsLinksRole:{ + case ActivityItemDelegate::ActionsLinksRole:{ QList customList; foreach (ActivityLink customItem, a._links) { QVariant customVariant; @@ -81,10 +87,12 @@ 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")); + if(a._type == Activity::NotificationType){ + QIcon cachedIcon = ServerNotificationHandler::iconCache.value(a._id); + if(!cachedIcon.isNull()) + return cachedIcon; + else return QIcon(QLatin1String(":/client/resources/bell.svg")); + } else return QIcon(QLatin1String(":/client/resources/activity.png")); return QVariant(); break; case ActivityItemDelegate::ActionRole:{ diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 048fca3dc..27c13267d 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -38,6 +38,7 @@ #include "theme.h" #include "ocsjob.h" #include "configfile.h" +#include "guiutility.h" #include "ui_activitywidget.h" @@ -92,8 +93,9 @@ ActivityWidget::ActivityWidget(AccountState *accountState, QWidget *parent) connect(_model, &QAbstractItemModel::rowsInserted, this, &ActivityWidget::rowsInserted); - connect(delegate, &ActivityItemDelegate::buttonClickedOnItemView, this, &ActivityWidget::slotButtonClickedOnListView); - connect(this, &ActivityWidget::sendNotificationRequest, this, &ActivityWidget::slotSendNotificationRequest); + connect(delegate, &ActivityItemDelegate::primaryButtonClickedOnItemView, this, &ActivityWidget::slotPrimaryButtonClickedOnListView); + connect(delegate, &ActivityItemDelegate::secondaryButtonClickedOnItemView, this, &ActivityWidget::slotSecondaryButtonClickedOnListView); + //connect(this, &ActivityWidget::sendNotificationRequest, this, &ActivityWidget::slotSendNotificationRequest); connect(_ui->_activityList, &QListView::activated, this, &ActivityWidget::slotOpenFile); @@ -106,32 +108,34 @@ ActivityWidget::~ActivityWidget() delete _ui; } -void ActivityWidget::slotButtonClickedOnListView(const QModelIndex &index){ +void ActivityWidget::slotPrimaryButtonClickedOnListView(const QModelIndex &index){ + QUrl link = qvariant_cast(index.data(ActivityItemDelegate::LinkRole)); + if(!link.isEmpty()) + Utility::openBrowser(link, this); +} + +void ActivityWidget::slotSecondaryButtonClickedOnListView(const QModelIndex &index){ QList customList = index.data(ActivityItemDelegate::ActionsLinksRole).toList(); QList actionLinks; foreach(QVariant customItem, customList){ actionLinks << qvariant_cast(customItem); } - QMenu menu; - QUrl link = qvariant_cast(index.data(ActivityItemDelegate::LinkRole)); - if(!link.isEmpty()){ - QAction *menuAction = new QAction(tr("More Information"), &menu); - connect(menuAction, &QAction::triggered, this, [link] { QDesktopServices::openUrl(link); }); - menu.addAction(menuAction); + const QString accountName = index.data(ActivityItemDelegate::AccountRole).toString(); + if(actionLinks.size() == 1){ + if(actionLinks.at(0)._verb == "DELETE") + slotSendNotificationRequest(index.data(ActivityItemDelegate::AccountRole).toString(), actionLinks.at(0)._link, actionLinks.at(0)._verb, index.row()); + } else if(actionLinks.size() > 1){ + QMenu menu; + foreach (ActivityLink actionLink, actionLinks) { + QAction *menuAction = new QAction(actionLink._label, &menu); + connect(menuAction, &QAction::triggered, this, [this, index, accountName, actionLink] { + this->slotSendNotificationRequest(accountName, actionLink._link, actionLink._verb, index.row()); + }); + menu.addAction(menuAction); + } + menu.exec(QCursor::pos()); } - - foreach (ActivityLink actionLink, actionLinks) { - QAction *menuAction = new QAction(actionLink._label, &menu); - menuAction->setProperty("activityRow", QVariant::fromValue(index.row())); - connect(menuAction, &QAction::triggered, this, [this, index, actionLink] { - qCInfo(lcActivity) << "Notification Link: " << actionLink._verb << actionLink._link; - emit this->sendNotificationRequest(qvariant_cast(index.data(ActivityItemDelegate::AccountRole)), actionLink._link, actionLink._verb, index.row()); - }); - menu.addAction(menuAction); - } - - menu.exec(QCursor::pos()); } void ActivityWidget::slotNotificationRequestFinished(int statusCode) @@ -369,6 +373,7 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) emit guiLog(activity._subject, activity._accName); } } + _model->addToActivityList(activity); } } diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h index f4bce9301..c451380cc 100644 --- a/src/gui/activitywidget.h +++ b/src/gui/activitywidget.h @@ -86,7 +86,7 @@ signals: void rowsInserted(); void hideActivityTab(bool); void newNotification(); - void sendNotificationRequest(const QString &, const QString &link, const QByteArray &verb, int row); + void sendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row); private slots: void slotBuildNotificationDisplay(const ActivityList &list); @@ -97,7 +97,8 @@ private slots: void scheduleWidgetToRemove(NotificationWidget *widget, int milliseconds = 100); void slotCheckToCleanWidgets(); void slotNotificationRequestFinished(int statusCode); - void slotButtonClickedOnListView(const QModelIndex &index); + void slotPrimaryButtonClickedOnListView(const QModelIndex &index); + void slotSecondaryButtonClickedOnListView(const QModelIndex &index); private: void showLabels(); diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp index 8481a51ad..93dac7201 100644 --- a/src/gui/notificationwidget.cpp +++ b/src/gui/notificationwidget.cpp @@ -47,7 +47,7 @@ void NotificationWidget::setActivity(const Activity &activity) _ui._subjectLabel->setText(activity._subject); _ui._messageLabel->setText(activity._message); - _ui._notifIcon->setPixmap(QPixmap(":/client/resources/bell.png")); + _ui._notifIcon->setPixmap(QPixmap(":/client/resources/bell.svg")); _ui._notifIcon->setMinimumWidth(22); _ui._notifIcon->setMinimumHeight(22); _ui._notifIcon->show(); diff --git a/src/gui/notificationwidget.ui b/src/gui/notificationwidget.ui index fc71d3061..cab22d4d8 100644 --- a/src/gui/notificationwidget.ui +++ b/src/gui/notificationwidget.ui @@ -7,7 +7,7 @@ 0 0 725 - 125 + 129 @@ -75,7 +75,7 @@ - ../../../../resources/bell.png + ../../resources/bell.svg Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft 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 #include @@ -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 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 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 _notificationJob;