mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 06:55:59 +03:00
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 <hello@camila.codes>
This commit is contained in:
parent
00a73b5ded
commit
e3c7a5a2ff
14 changed files with 207 additions and 114 deletions
|
@ -22,6 +22,8 @@
|
|||
<file>resources/account.png</file>
|
||||
<file>resources/more.svg</file>
|
||||
<file>resources/delete.png</file>
|
||||
<file>resources/bell.png</file>
|
||||
<file>resources/close.svg</file>
|
||||
<file>resources/bell.svg</file>
|
||||
</qresource>
|
||||
<qresource prefix="/"/>
|
||||
</RCC>
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 495 B |
4
resources/bell.svg
Normal file
4
resources/bell.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" viewBox="0 0 16 16">
|
||||
<path d="m8 2c-0.5523 0-1 0.4477-1 1 0 0.0472 0.021 0.0873 0.0273 0.1328-1.7366 0.4362-3.0273 1.9953-3.0273 3.8672v2l-1 1v1h10v-1l-1-1v-2c0-1.8719-1.291-3.431-3.0273-3.8672 0.0063-0.0455 0.0273-0.0856 0.0273-0.1328 0-0.5523-0.4477-1-1-1zm-2 10c0 1.1046 0.8954 2 2 2s2-0.8954 2-2z" fill="#000"/>
|
||||
</svg>
|
After Width: | Height: | Size: 456 B |
4
resources/close.svg
Normal file
4
resources/close.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1">
|
||||
<path d="m12.95 11.536l-1.414 1.414-3.536-3.536-3.535 3.536-1.415-1.414 3.536-3.536-3.536-3.536 1.415-1.414 3.535 3.536 3.516-3.555 1.434 1.434-3.536 3.535z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 301 B |
|
@ -16,6 +16,7 @@
|
|||
#define ACTIVITYDATA_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QIcon>
|
||||
|
||||
namespace OCC {
|
||||
/**
|
||||
|
|
|
@ -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<QIcon>(index.data(UserIconRole));
|
||||
// QString pathText = qvariant_cast<QString>(index.data(PathRole));
|
||||
// QString remoteLink = qvariant_cast<QString>(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<QIcon>(index.data(ActionIconRole));
|
||||
// get the data
|
||||
Activity::Type activityType = qvariant_cast<Activity::Type>(index.data(ActionRole));
|
||||
QIcon actionIcon = qvariant_cast<QIcon>(index.data(ActionIconRole));
|
||||
QString actionText = qvariant_cast<QString>(index.data(ActionTextRole));
|
||||
QString messageText = qvariant_cast<QString>(index.data(MessageRole));
|
||||
QList<QVariant> customList = index.data(ActionsLinksRole).toList();
|
||||
QString timeText = qvariant_cast<QString>(index.data(PointInTimeRole));
|
||||
QString accountRole = qvariant_cast<QString>(index.data(AccountRole));
|
||||
bool accountOnline = qvariant_cast<bool>(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<Activity::Type>(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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<QVariant> 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:{
|
||||
|
|
|
@ -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<QString>(index.data(ActivityItemDelegate::LinkRole));
|
||||
if(!link.isEmpty())
|
||||
Utility::openBrowser(link, this);
|
||||
}
|
||||
|
||||
void ActivityWidget::slotSecondaryButtonClickedOnListView(const QModelIndex &index){
|
||||
QList<QVariant> customList = index.data(ActivityItemDelegate::ActionsLinksRole).toList();
|
||||
QList<ActivityLink> actionLinks;
|
||||
foreach(QVariant customItem, customList){
|
||||
actionLinks << qvariant_cast<ActivityLink>(customItem);
|
||||
}
|
||||
|
||||
QMenu menu;
|
||||
QUrl link = qvariant_cast<QString>(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<QString>(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>725</width>
|
||||
<height>125</height>
|
||||
<height>129</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -75,7 +75,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap>../../../../resources/bell.png</pixmap>
|
||||
<pixmap>../../resources/bell.svg</pixmap>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue