diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 7fcd24c63..05a93f556 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -33,7 +33,6 @@ set(client_UI_SRCS sslerrordialog.ui addcertificatedialog.ui proxyauthdialog.ui - notificationwidget.ui mnemonicdialog.ui wizard/owncloudadvancedsetuppage.ui wizard/owncloudconnectionmethoddialog.ui @@ -95,7 +94,6 @@ set(client_SRCS proxyauthdialog.cpp synclogdialog.cpp tooltipupdater.cpp - notificationwidget.cpp notificationconfirmjob.cpp servernotificationhandler.cpp guiutility.cpp diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 8327e9adc..687a6703c 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -30,7 +30,6 @@ #include "accountmanager.h" #include "activityitemdelegate.h" #include "QProgressIndicator.h" -#include "notificationwidget.h" #include "notificationconfirmjob.h" #include "servernotificationhandler.h" #include "theme.h" @@ -85,7 +84,6 @@ ActivityWidget::ActivityWidget(AccountState *accountState, QWidget *parent) connect(delegate, &ActivityItemDelegate::primaryButtonClickedOnItemView, this, &ActivityWidget::slotPrimaryButtonClickedOnListView); connect(delegate, &ActivityItemDelegate::secondaryButtonClickedOnItemView, this, &ActivityWidget::slotSecondaryButtonClickedOnListView); connect(_ui->_activityList, &QListView::activated, this, &ActivityWidget::slotOpenFile); - connect(&_removeTimer, &QTimer::timeout, this, &ActivityWidget::slotCheckToCleanWidgets); connect(ProgressDispatcher::instance(), &ProgressDispatcher::progressInfo, this, &ActivityWidget::slotProgressInfo); @@ -347,7 +345,7 @@ void ActivityWidget::slotAccountActivityStatus(int statusCode) _accountsWithoutActivities.remove(_accountState->account()->displayName()); } - checkActivityTabVisibility(); + checkActivityWidgetVisibility(); showLabels(); } @@ -398,16 +396,15 @@ void ActivityWidget::storeActivityList(QTextStream &ts) } } -void ActivityWidget::checkActivityTabVisibility() +void ActivityWidget::checkActivityWidgetVisibility() { int accountCount = AccountManager::instance()->accounts().count(); bool hasAccountsWithActivity = _accountsWithoutActivities.count() != accountCount; - bool hasNotifications = !_widgetForNotifId.isEmpty(); _ui->_activityList->setVisible(hasAccountsWithActivity); - emit hideActivityTab(!hasAccountsWithActivity && !hasNotifications); + emit hideActivityTab(!hasAccountsWithActivity); } void ActivityWidget::slotOpenFile(QModelIndex indx) @@ -508,7 +505,7 @@ void ActivityWidget::slotSendNotificationRequest(const QString &accountName, con } } -void ActivityWidget::endNotificationRequest(NotificationWidget *widget, int replyCode) +void ActivityWidget::endNotificationRequest(int replyCode) { _notificationRequestsRunning--; slotNotificationRequestFinished(replyCode); @@ -523,7 +520,7 @@ void ActivityWidget::slotNotifyNetworkError(QNetworkReply *reply) int resultCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - endNotificationRequest(job->widget(), resultCode); + endNotificationRequest(resultCode); qCWarning(lcActivity) << "Server notify job failed with code " << resultCode; } @@ -534,72 +531,10 @@ void ActivityWidget::slotNotifyServerFinished(const QString &reply, int replyCod return; } - endNotificationRequest(job->widget(), replyCode); + endNotificationRequest(replyCode); qCInfo(lcActivity) << "Server Notification reply code" << replyCode << reply; - - // if the notification was successful start a timer that triggers - // removal of the done widgets in a few seconds - // Add 200 millisecs to the predefined value to make sure that the timer in - // widget's method readyToClose() has elapsed. - if (replyCode == OCS_SUCCESS_STATUS_CODE || replyCode == OCS_SUCCESS_STATUS_CODE_V2) { - //scheduleWidgetToRemove(job->widget()); - } } -// blacklist the activity coming in here. -void ActivityWidget::slotRequestCleanupAndBlacklist(const Activity &blacklistActivity) -{ - if (!_blacklistedNotifications.contains(blacklistActivity)) { - _blacklistedNotifications.append(blacklistActivity); - } - - NotificationWidget *widget = _widgetForNotifId[blacklistActivity.ident()]; - scheduleWidgetToRemove(widget); -} - -void ActivityWidget::scheduleWidgetToRemove(NotificationWidget *widget, int milliseconds) -{ - if (!widget) { - return; - } - // in five seconds from now, remove the widget. - QDateTime removeTime = QDateTime::currentDateTimeUtc().addMSecs(milliseconds); - QDateTime &it = _widgetsToRemove[widget]; - if (!it.isValid() || it > removeTime) { - it = removeTime; - } - if (!_removeTimer.isActive()) { - _removeTimer.start(); - } -} - -// Called every second to see if widgets need to be removed. -void ActivityWidget::slotCheckToCleanWidgets() -{ - auto currentTime = QDateTime::currentDateTimeUtc(); - auto it = _widgetsToRemove.begin(); - while (it != _widgetsToRemove.end()) { - // loop over all widgets in the to-remove queue - QDateTime t = it.value(); - NotificationWidget *widget = it.key(); - - if (currentTime > t) { - // found one to remove! - Activity::Identifier id = widget->activity().ident(); - _widgetForNotifId.remove(id); - widget->deleteLater(); - it = _widgetsToRemove.erase(it); - } else { - ++it; - } - } - - if (_widgetsToRemove.isEmpty()) { - _removeTimer.stop(); - } -} - - /* ==================================================================== */ ActivitySettings::ActivitySettings(AccountState *accountState, QWidget *parent) diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h index ffd301d40..8b74a565e 100644 --- a/src/gui/activitywidget.h +++ b/src/gui/activitywidget.h @@ -37,7 +37,6 @@ namespace OCC { class Account; class AccountStatusPtr; class JsonApiJob; -class NotificationWidget; class ActivityListModel; namespace Ui { @@ -68,7 +67,7 @@ public: * Based on whether activities are enabled and whether notifications are * available. */ - void checkActivityTabVisibility(); + void checkActivityWidgetVisibility(); public slots: void slotOpenFile(QModelIndex indx); @@ -76,7 +75,6 @@ public slots: void slotRefreshNotifications(); void slotRemoveAccount(); void slotAccountActivityStatus(int statusCode); - void slotRequestCleanupAndBlacklist(const Activity &blacklistActivity); void addError(const QString &folderAlias, const QString &message, ErrorCategory category); void slotProgressInfo(const QString &folder, const ProgressInfo &progress); void slotItemCompleted(const QString &folder, const SyncFileItemPtr &item); @@ -93,9 +91,7 @@ private slots: void slotSendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row); void slotNotifyNetworkError(QNetworkReply *); void slotNotifyServerFinished(const QString &reply, int replyCode); - void endNotificationRequest(NotificationWidget *widget, int replyCode); - void scheduleWidgetToRemove(NotificationWidget *widget, int milliseconds = 100); - void slotCheckToCleanWidgets(); + void endNotificationRequest(int replyCode); void slotNotificationRequestFinished(int statusCode); void slotPrimaryButtonClickedOnListView(const QModelIndex &index); void slotSecondaryButtonClickedOnListView(const QModelIndex &index); @@ -105,12 +101,10 @@ private: QString timeString(QDateTime dt, QLocale::FormatType format) const; Ui::ActivityWidget *_ui; QSet _accountsWithoutActivities; - QMap _widgetForNotifId; QElapsedTimer _guiLogTimer; QSet _guiLoggedNotifications; ActivityList _blacklistedNotifications; - QHash _widgetsToRemove; QTimer _removeTimer; // number of currently running notification requests. If non zero, diff --git a/src/gui/notificationconfirmjob.cpp b/src/gui/notificationconfirmjob.cpp index 871ce6449..d9a7a4c34 100644 --- a/src/gui/notificationconfirmjob.cpp +++ b/src/gui/notificationconfirmjob.cpp @@ -20,11 +20,10 @@ namespace OCC { -Q_DECLARE_LOGGING_CATEGORY(lcNotifications) +Q_LOGGING_CATEGORY(lcNotificationsJob, "nextcloud.gui.notifications", QtInfoMsg) NotificationConfirmJob::NotificationConfirmJob(AccountPtr account) : AbstractNetworkJob(account, "") - , _widget(0) { setIgnoreCredentialFailure(true); } @@ -35,20 +34,10 @@ void NotificationConfirmJob::setLinkAndVerb(const QUrl &link, const QByteArray & _verb = verb; } -void NotificationConfirmJob::setWidget(NotificationWidget *widget) -{ - _widget = widget; -} - -NotificationWidget *NotificationConfirmJob::widget() -{ - return _widget; -} - void NotificationConfirmJob::start() { if (!_link.isValid()) { - qCWarning(lcNotifications) << "Attempt to trigger invalid URL: " << _link.toString(); + qCWarning(lcNotificationsJob) << "Attempt to trigger invalid URL: " << _link.toString(); return; } QNetworkRequest req; diff --git a/src/gui/notificationconfirmjob.h b/src/gui/notificationconfirmjob.h index 4602dcf67..fde04d2e6 100644 --- a/src/gui/notificationconfirmjob.h +++ b/src/gui/notificationconfirmjob.h @@ -25,8 +25,6 @@ namespace OCC { -class NotificationWidget; - /** * @brief The NotificationConfirmJob class * @ingroup gui @@ -54,20 +52,6 @@ public: */ void start() Q_DECL_OVERRIDE; - /** - * @brief setWidget stores the associated widget to be able to use - * it when the job has finished - * @param widget pointer to the notification widget to store - */ - void setWidget(NotificationWidget *widget); - - /** - * @brief widget - get the associated notification widget as stored - * with setWidget method. - * @return widget pointer to the notification widget - */ - NotificationWidget *widget(); - signals: /** @@ -83,7 +67,6 @@ private slots: private: QByteArray _verb; QUrl _link; - NotificationWidget *_widget; }; } diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp deleted file mode 100644 index 93dac7201..000000000 --- a/src/gui/notificationwidget.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (C) by Klaas Freitag - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#include "notificationwidget.h" -#include "QProgressIndicator.h" -#include "common/utility.h" -#include "common/asserts.h" -#include "guiutility.h" - -#include - -#include "ocsjob.h" - -namespace OCC { - -Q_LOGGING_CATEGORY(lcNotifications, "nextcloud.gui.notifications", QtInfoMsg) - -NotificationWidget::NotificationWidget(QWidget *parent) - : QWidget(parent) -{ - _ui.setupUi(this); - _progressIndi = new QProgressIndicator(this); - _ui.horizontalLayout->addWidget(_progressIndi); -} - -void NotificationWidget::setActivity(const Activity &activity) -{ - _myActivity = activity; - - _accountName = activity._accName; - ASSERT(!_accountName.isEmpty()); - - _ui._subjectLabel->setVisible(!activity._subject.isEmpty()); - _ui._messageLabel->setVisible(!activity._message.isEmpty()); - - _ui._subjectLabel->setText(activity._subject); - _ui._messageLabel->setText(activity._message); - - _ui._notifIcon->setPixmap(QPixmap(":/client/resources/bell.svg")); - _ui._notifIcon->setMinimumWidth(22); - _ui._notifIcon->setMinimumHeight(22); - _ui._notifIcon->show(); - - QString tText = tr("%1").arg(Utility::timeAgoInWords(activity._dateTime)); - _ui._timeLabel->setText(tText); - - // always remove the buttons - foreach (auto button, _ui._buttonBox->buttons()) { - _ui._buttonBox->removeButton(button); - } - _buttons.clear(); - - // open the notification in the browser if there is a link - if(!_myActivity._link.isEmpty()){ - QString buttonText(tr("More information")); - QPushButton *openBrowser = _ui._buttonBox->addButton(buttonText, QDialogButtonBox::AcceptRole); - openBrowser->setDefault(true); - connect(openBrowser, &QAbstractButton::clicked, this, &NotificationWidget::slotOpenBrowserButtonClicked); - _buttons.prepend(openBrowser); - } - - // display buttons for the links - if (activity._links.isEmpty()) { - // is there any case where this code is executed? - // in case there is no action defined, do a close button. - QPushButton *b = _ui._buttonBox->addButton(QDialogButtonBox::Close); - b->setDefault(true); - connect(b, &QAbstractButton::clicked, this, &NotificationWidget::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, &QAbstractButton::clicked, this, &NotificationWidget::slotButtonClicked); - _buttons.append(b); - } - } -} - -Activity NotificationWidget::activity() const -{ - return _myActivity; -} - -void NotificationWidget::slotOpenBrowserButtonClicked(){ - QUrl url(_myActivity._link); - Utility::openBrowser(url, this); -} - -void NotificationWidget::slotButtonClicked() -{ - QObject *buttonWidget = QObject::sender(); - int index = -1; - if (buttonWidget) { - // find the button that was clicked, it has to be in the list - // of buttons that were added to the button box before. - for (int i = 0; i < _buttons.count(); i++) { - if (_buttons.at(i) == buttonWidget) { - index = i; - } - _buttons.at(i)->setEnabled(false); - } - - // there is an extra button: 'Open' - if(!_myActivity._link.isEmpty()) - index--; - - // 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; - - if (!triggeredLink._link.isEmpty()) { - qCInfo(lcNotifications) << "Notification Link: " << triggeredLink._verb << triggeredLink._link; - _progressIndi->startAnimation(); - emit sendNotificationRequest(_accountName, triggeredLink._link, triggeredLink._verb); - } - } - } -} - -void NotificationWidget::slotNotificationRequestFinished(int statusCode) -{ - int i = 0; - QString doneText; - QLocale locale; - - QString timeStr = locale.toString(QTime::currentTime()); - - // the ocs API returns stat code 100 or 200 inside the xml if it succeeded. - if (statusCode != OCS_SUCCESS_STATUS_CODE && statusCode != OCS_SUCCESS_STATUS_CODE_V2) { - qCWarning(lcNotifications) << "Notification Request to Server failed, leave button visible."; - for (i = 0; i < _buttons.count(); i++) { - _buttons.at(i)->setEnabled(true); - } - //: The second parameter is a time, such as 'failed at 09:58pm' - doneText = tr("%1 request failed at %2").arg(_actionLabel, timeStr); - } else { - // the call to the ocs API succeeded. - _ui._buttonBox->hide(); - - //: The second parameter is a time, such as 'selected at 09:58pm' - doneText = tr("'%1' selected at %2").arg(_actionLabel, timeStr); - } - _ui._timeLabel->setText(doneText); - - _progressIndi->stopAnimation(); -} -} diff --git a/src/gui/notificationwidget.h b/src/gui/notificationwidget.h deleted file mode 100644 index 04c5665c9..000000000 --- a/src/gui/notificationwidget.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) by Klaas Freitag - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#ifndef NOTIFICATIONWIDGET_H -#define NOTIFICATIONWIDGET_H - -#include - -#include "activitydata.h" - -#include "ui_notificationwidget.h" - -#define NOTIFICATION_WIDGET_CLOSE_AFTER_MILLISECS 4800 - -class QProgressIndicator; - -namespace OCC { - -class NotificationWidget : public QWidget -{ - Q_OBJECT -public: - explicit NotificationWidget(QWidget *parent = 0); - - bool readyToClose(); - Activity activity() const; - -signals: - void sendNotificationRequest(const QString &, const QString &link, const QByteArray &verb); - void requestCleanupAndBlacklist(const Activity &activity); - -public slots: - void setActivity(const Activity &activity); - void slotNotificationRequestFinished(int statusCode); - -private slots: - void slotButtonClicked(); - void slotOpenBrowserButtonClicked(); - -private: - Ui_NotificationWidget _ui; - Activity _myActivity; - QList _buttons; - QString _accountName; - QProgressIndicator *_progressIndi; - QString _actionLabel; -}; -} - -#endif // NOTIFICATIONWIDGET_H diff --git a/src/gui/notificationwidget.ui b/src/gui/notificationwidget.ui deleted file mode 100644 index cab22d4d8..000000000 --- a/src/gui/notificationwidget.ui +++ /dev/null @@ -1,185 +0,0 @@ - - - NotificationWidget - - - - 0 - 0 - 725 - 129 - - - - - 0 - 0 - - - - Form - - - - QLayout::SetMaximumSize - - - 24 - - - 0 - - - 26 - - - 0 - - - 0 - - - 2 - - - - - 6 - - - 5 - - - 5 - - - - - 6 - - - 6 - - - - - - 0 - 0 - - - - 0 - - - - - - ../../resources/bell.svg - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - 0 - - - - - - - - 0 - 0 - - - - Lorem ipsum dolor sit amet - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - - - 0 - 0 - - - - Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod temporm - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - true - - - 0 - - - 28 - - - - - - - 6 - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 28 - 20 - - - - - - - - - 8 - - - - TextLabel - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - QDialogButtonBox::Ok - - - - - - - - - - - - diff --git a/src/gui/settingsdialog.ui b/src/gui/settingsdialog.ui index b8164ba63..93ee1d832 100644 --- a/src/gui/settingsdialog.ui +++ b/src/gui/settingsdialog.ui @@ -44,7 +44,7 @@ Qt::Horizontal - QDialogButtonBox::Close + QDialogButtonBox::NoButton