diff options
author | Klaas Freitag <freitag@owncloud.com> | 2016-03-23 18:59:03 +0300 |
---|---|---|
committer | Klaas Freitag <freitag@owncloud.com> | 2016-03-23 19:02:13 +0300 |
commit | 1fe5d6bb0cfb6d556b8eb6bf7b35a668cdcff243 (patch) | |
tree | 3fa0ba24094de54da78b2ea0f8db3f4ef47cd822 /src/gui/notificationwidget.cpp | |
parent | 0c944a06f9ce67c8cf259f37cb8e32f29ba2f99a (diff) |
Notifications: Handle Notifications without an action.
The policy that was said is that if a notification has no action, the
client can and should display a close-button. This patch does it.
In additon to that, the client needs a blacklist of closed notifcations
otherwise they would re-appear next time the server notifications are
fetched again.
Also, changed the cleanup of not-longer-used widgets to be more robust.
Diffstat (limited to 'src/gui/notificationwidget.cpp')
-rw-r--r-- | src/gui/notificationwidget.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp index 88217f136..15dd7fc90 100644 --- a/src/gui/notificationwidget.cpp +++ b/src/gui/notificationwidget.cpp @@ -54,13 +54,22 @@ void NotificationWidget::setActivity(const Activity& activity) foreach( auto button, _ui._buttonBox->buttons() ) { _ui._buttonBox->removeButton(button); } + _buttons.clear(); // display buttons for the links - foreach( auto link, activity._links ) { - QPushButton *b = _ui._buttonBox->addButton( link._label, QDialogButtonBox::AcceptRole); - b->setDefault(link._isPrimary); + if( activity._links.isEmpty() ) { + // in case there is no action defined, do a close button. + QPushButton *b = _ui._buttonBox->addButton( QDialogButtonBox::Close ); + b->setDefault(true); connect(b, SIGNAL(clicked()), this, SLOT(slotButtonClicked())); _buttons.append(b); + } else { + foreach( auto link, activity._links ) { + QPushButton *b = _ui._buttonBox->addButton(link._label, QDialogButtonBox::AcceptRole); + b->setDefault(link._isPrimary); + connect(b, SIGNAL(clicked()), this, SLOT(slotButtonClicked())); + _buttons.append(b); + } } } @@ -84,12 +93,24 @@ void NotificationWidget::slotButtonClicked() } // if the button was found, the link must be called + if( index > -1 && _myActivity._links.count() == 0 ) { + // no links, that means it was the close button + // empty link. Just close and remove the widget. + QString doneText = tr("Closing in a few seconds..."); + _ui._timeLabel->setText(doneText); + emit requestCleanupAndBlacklist(_myActivity); + return; + } + if( index > -1 && index < _myActivity._links.count() ) { ActivityLink triggeredLink = _myActivity._links.at(index); _actionLabel = triggeredLink._label; - qDebug() << Q_FUNC_INFO << "Notification Link: "<< triggeredLink._verb << triggeredLink._link; - _progressIndi->startAnimation(); - emit sendNotificationRequest( _accountName, triggeredLink._link, triggeredLink._verb ); + + if( ! triggeredLink._link.isEmpty() ) { + qDebug() << Q_FUNC_INFO << "Notification Link: "<< triggeredLink._verb << triggeredLink._link; + _progressIndi->startAnimation(); + emit sendNotificationRequest( _accountName, triggeredLink._link, triggeredLink._verb ); + } } } } @@ -116,12 +137,6 @@ void NotificationWidget::slotNotificationRequestFinished(int statusCode) //* The second parameter is a time, such as 'selected at 09:58pm' doneText = tr("'%1' selected at %2").arg(_actionLabel).arg(timeStr); - - // start a timer, so that activity widget can remove this widget after a - // certain time. It needs to be done by ActivityWidget because it also - // needs to hide the scrollview if no widget is left any more. - // method readyToClose() checks for the timer value to see if it is expired - _closeTimer.start(); } _ui._timeLabel->setText( doneText ); @@ -129,9 +144,4 @@ void NotificationWidget::slotNotificationRequestFinished(int statusCode) } -bool NotificationWidget::readyToClose() -{ - return _closeTimer.isValid() && _closeTimer.elapsed() > NOTIFICATION_WIDGET_CLOSE_AFTER_MILLISECS; -} - } |