From a7dd3a7da14db1bb0bd59a130d56495f2427295a Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 12 Feb 2018 22:15:36 +0100 Subject: [PATCH 01/22] Displays the actual notification subject in the system tray messages. Signed-off-by: Camila San --- src/gui/activitylistmodel.cpp | 3 +++ src/gui/activitywidget.cpp | 30 +++++++----------------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/gui/activitylistmodel.cpp b/src/gui/activitylistmodel.cpp index 33e57690d..f42e6da10 100644 --- a/src/gui/activitylistmodel.cpp +++ b/src/gui/activitylistmodel.cpp @@ -152,6 +152,9 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st foreach (auto activ, activities) { auto json = activ.toObject(); + qDebug() << "Activity list" + << json.value("subject").toString(); + Activity a; a._type = Activity::ActivityType; a._accName = ast->account()->displayName(); diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 8a29d9152..353fe4fef 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -248,6 +248,8 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) bool newNotificationShown = false; foreach (auto activity, list) { + qDebug() << "Notification list" + << activity._subject; if (_blacklistedNotifications.contains(activity)) { qCInfo(lcActivity) << "Activity in blacklist, skip"; continue; @@ -304,6 +306,10 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) } _guiLoggedNotifications.insert(activity._id); } + + // Assemble a tray notification + QString log = tr("Notification for %1.").arg(activity._accName); + emit guiLog(log, activity._subject); } // check if there are widgets that have no corresponding activity from @@ -339,31 +345,9 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) checkActivityTabVisibility(); - int newGuiLogCount = accNotified.count(); - - if (newGuiLogCount > 0) { + if (newNotificationShown) { // restart the gui log timer now that we show a notification _guiLogTimer.start(); - - // Assemble a tray notification - QString msg = tr("You received %n new notification(s) from %2.", "", accNotified[accNotified.keys().at(0)]).arg(accNotified.keys().at(0)); - - if (newGuiLogCount >= 2) { - QString acc1 = accNotified.keys().at(0); - QString acc2 = accNotified.keys().at(1); - if (newGuiLogCount == 2) { - int notiCount = accNotified[acc1] + accNotified[acc2]; - msg = tr("You received %n new notification(s) from %1 and %2.", "", notiCount).arg(acc1, acc2); - } else { - msg = tr("You received new notifications from %1, %2 and other accounts.").arg(acc1, acc2); - } - } - - const QString log = tr("%1 Notifications - Action Required").arg(Theme::instance()->appNameGUI()); - emit guiLog(log, msg); - } - - if (newNotificationShown) { emit newNotification(); } } From b24751b0992597ac31d638771bebb41b2be2b9a3 Mon Sep 17 00:00:00 2001 From: Camila San Date: Wed, 14 Feb 2018 15:39:41 +0100 Subject: [PATCH 02/22] Adds button to open notification in the browser - to update something, join a call, etc. Signed-off-by: Camila San --- src/gui/activitydata.h | 1 + src/gui/notificationwidget.cpp | 27 +++++++++++++++++++++++++++ src/gui/notificationwidget.h | 1 + src/gui/servernotificationhandler.cpp | 8 ++++++++ 4 files changed, 37 insertions(+) diff --git a/src/gui/activitydata.h b/src/gui/activitydata.h index 40cd35e05..c48965c50 100644 --- a/src/gui/activitydata.h +++ b/src/gui/activitydata.h @@ -59,6 +59,7 @@ public: QUrl _link; QDateTime _dateTime; QString _accName; + QString _appName; QVector _links; /** diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp index cd879451e..95a9bfe3a 100644 --- a/src/gui/notificationwidget.cpp +++ b/src/gui/notificationwidget.cpp @@ -16,6 +16,7 @@ #include "QProgressIndicator.h" #include "common/utility.h" #include "common/asserts.h" +#include "guiutility.h" #include @@ -61,8 +62,25 @@ void NotificationWidget::setActivity(const Activity &activity) } _buttons.clear(); + // open the notification in the browser if there is a link + if(!_myActivity._links.isEmpty()){ + QString buttonText(tr("Open")); + + if(_myActivity._appName == "spreed") + buttonText = tr("Join call"); + + if(_myActivity._appName == "updatenotification") + buttonText = tr("Update"); + + 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()) { + // this condition is never satisfied since there is always a 'dismiss' ActivityLink being added at servernotificationhandler... // in case there is no action defined, do a close button. QPushButton *b = _ui._buttonBox->addButton(QDialogButtonBox::Close); b->setDefault(true); @@ -83,6 +101,11 @@ Activity NotificationWidget::activity() const return _myActivity; } +void NotificationWidget::slotOpenBrowserButtonClicked(){ + QUrl url(_myActivity._link); + Utility::openBrowser(url, this); +} + void NotificationWidget::slotButtonClicked() { QObject *buttonWidget = QObject::sender(); @@ -97,6 +120,10 @@ void NotificationWidget::slotButtonClicked() _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 diff --git a/src/gui/notificationwidget.h b/src/gui/notificationwidget.h index ce0e95f2b..04c5665c9 100644 --- a/src/gui/notificationwidget.h +++ b/src/gui/notificationwidget.h @@ -46,6 +46,7 @@ public slots: private slots: void slotButtonClicked(); + void slotOpenBrowserButtonClicked(); private: Ui_NotificationWidget _ui; diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp index fdf7b4dbf..4392e8f6e 100644 --- a/src/gui/servernotificationhandler.cpp +++ b/src/gui/servernotificationhandler.cpp @@ -79,6 +79,8 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j a._id = json.value("notification_id").toInt(); a._subject = json.value("subject").toString(); a._message = json.value("message").toString(); + a._appName = json.value("app").toString(); + QString s = json.value("link").toString(); if (!s.isEmpty()) { a._link = QUrl(s); @@ -86,6 +88,8 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j a._dateTime = QDateTime::fromString(json.value("datetime").toString(), Qt::ISODate); auto actions = json.value("actions").toArray(); + qDebug() << "Notification ACTIONS:" + << json.value("actions").toString(); foreach (auto action, actions) { auto actionJson = action.toObject(); ActivityLink al; @@ -106,6 +110,10 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j al._isPrimary = false; a._links.append(al); + qDebug() << "Notification LINK:" + << a._link; + + list.append(a); } emit newNotificationList(list); From bfc7aa16c63c6c5fadc12e937a4a656a92fc21bb Mon Sep 17 00:00:00 2001 From: Camila San Date: Wed, 14 Feb 2018 20:37:53 +0100 Subject: [PATCH 03/22] Adds option to toggle display of Sync and Activity notifications. Signed-off-by: Camila San --- src/gui/activitywidget.cpp | 13 ++++++++++--- src/gui/generalsettings.cpp | 20 ++++++++++++++++++++ src/gui/generalsettings.h | 2 ++ src/gui/generalsettings.ui | 14 ++++++++++++++ src/libsync/configfile.cpp | 34 +++++++++++++++++++++++++++++++--- src/libsync/configfile.h | 6 ++++++ 6 files changed, 83 insertions(+), 6 deletions(-) diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 353fe4fef..63af43513 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -37,6 +37,7 @@ #include "servernotificationhandler.h" #include "theme.h" #include "ocsjob.h" +#include "configfile.h" #include "ui_activitywidget.h" @@ -308,8 +309,11 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) } // Assemble a tray notification - QString log = tr("Notification for %1.").arg(activity._accName); - emit guiLog(log, activity._subject); + ConfigFile cfg; + if(cfg.optionalDesktopNotifications()){ + QString log = tr("Notification for %1.").arg(activity._accName); + emit guiLog(log, activity._subject); + } } // check if there are widgets that have no corresponding activity from @@ -599,7 +603,10 @@ void ActivitySettings::slotCopyToClipboard() } QApplication::clipboard()->setText(text); - emit guiLog(tr("Copied to clipboard"), message); + + ConfigFile cfg; + if(cfg.optionalActivityNotifications()) + emit guiLog(tr("Copied to clipboard"), message); } void ActivitySettings::slotRemoveAccount(AccountState *ptr) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 69baaa84b..8cffa9100 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -44,6 +44,10 @@ GeneralSettings::GeneralSettings(QWidget *parent) connect(_ui->desktopNotificationsCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleOptionalDesktopNotifications); + connect(_ui->syncNotificationsCheckBox, &QAbstractButton::toggled, + this, &GeneralSettings::slotToggleOptionalSyncNotifications); + connect(_ui->activityNotificationsCheckBox, &QAbstractButton::toggled, + this, &GeneralSettings::slotToggleOptionalActivityNotifications); connect(_ui->showInExplorerNavigationPaneCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowInExplorerNavigationPane); _ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName())); @@ -115,6 +119,8 @@ void GeneralSettings::loadMiscSettings() ConfigFile cfgFile; _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); _ui->desktopNotificationsCheckBox->setChecked(cfgFile.optionalDesktopNotifications()); + _ui->syncNotificationsCheckBox->setChecked(cfgFile.optionalSyncNotifications()); + _ui->activityNotificationsCheckBox->setChecked(cfgFile.optionalActivityNotifications()); _ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); @@ -171,6 +177,20 @@ void GeneralSettings::slotToggleOptionalDesktopNotifications(bool enable) cfgFile.setOptionalDesktopNotifications(enable); } +void GeneralSettings::slotToggleOptionalSyncNotifications(bool enable) +{ + ConfigFile cfgFile; + cfgFile.setOptionalSyncNotifications(enable); +} + + +void GeneralSettings::slotToggleOptionalActivityNotifications(bool enable) +{ + ConfigFile cfgFile; + cfgFile.setOptionalActivityNotifications(enable); +} + + void GeneralSettings::slotShowInExplorerNavigationPane(bool checked) { ConfigFile cfgFile; diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 4e92337e6..1058ffd6b 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -43,6 +43,8 @@ private slots: void saveMiscSettings(); void slotToggleLaunchOnStartup(bool); void slotToggleOptionalDesktopNotifications(bool); + void slotToggleOptionalSyncNotifications(bool); + void slotToggleOptionalActivityNotifications(bool); void slotShowInExplorerNavigationPane(bool); void slotUpdateInfo(); void slotIgnoreFilesEditor(); diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index aacce23c2..e18cece79 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -20,6 +20,13 @@ General Settings + + + + Show Sync Notifications + + + @@ -44,6 +51,13 @@ + + + + Show Activity Notifications + + + diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 295fafc17..5c5bd564f 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -53,7 +53,9 @@ static const char notificationRefreshIntervalC[] = "notificationRefreshInterval" static const char monoIconsC[] = "monoIcons"; static const char promptDeleteC[] = "promptDeleteAllFiles"; static const char crashReporterC[] = "crashReporter"; -static const char optionalDesktopNoficationsC[] = "optionalDesktopNotifications"; +static const char optionalDesktopNotificationsC[] = "optionalDesktopNotifications"; +static const char optionalSyncNotificationsC[] = "optionalSyncNotifications"; +static const char optionalActivityNotificationsC[] = "optionalActivityNotifications"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; @@ -124,7 +126,19 @@ bool ConfigFile::setConfDir(const QString &value) bool ConfigFile::optionalDesktopNotifications() const { QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalDesktopNoficationsC), true).toBool(); + return settings.value(QLatin1String(optionalDesktopNotificationsC), true).toBool(); +} + +bool ConfigFile::optionalSyncNotifications() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value(QLatin1String(optionalSyncNotificationsC), false).toBool(); +} + +bool ConfigFile::optionalActivityNotifications() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value(QLatin1String(optionalActivityNotificationsC), false).toBool(); } bool ConfigFile::showInExplorerNavigationPane() const @@ -180,7 +194,21 @@ quint64 ConfigFile::targetChunkUploadDuration() const void ConfigFile::setOptionalDesktopNotifications(bool show) { QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(optionalDesktopNoficationsC), show); + settings.setValue(QLatin1String(optionalDesktopNotificationsC), show); + settings.sync(); +} + +void ConfigFile::setOptionalSyncNotifications(bool show) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue(QLatin1String(optionalSyncNotificationsC), show); + settings.sync(); +} + +void ConfigFile::setOptionalActivityNotifications(bool show) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue(QLatin1String(optionalActivityNotificationsC), show); settings.sync(); } diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index c4c66ac1a..a9bb403bb 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -123,6 +123,12 @@ public: bool optionalDesktopNotifications() const; void setOptionalDesktopNotifications(bool show); + bool optionalSyncNotifications() const; + void setOptionalSyncNotifications(bool show); + + bool optionalActivityNotifications() const; + void setOptionalActivityNotifications(bool show); + bool showInExplorerNavigationPane() const; void setShowInExplorerNavigationPane(bool show); From ab7185a6c70ec3701777f74ad7caa92e0dc3cb0f Mon Sep 17 00:00:00 2001 From: Camila San Date: Thu, 15 Feb 2018 20:21:08 +0100 Subject: [PATCH 04/22] Changes notification text in the checkboxes and adds tooltips with explanation about it. - Changes the configuration name in ConfigFile and GeneralSettings accordingly with the new text. - Makes sure the user sees error and conflict messages even if the setting is disabled. Signed-off-by: Camila San --- src/gui/activitywidget.cpp | 6 ++--- src/gui/folder.cpp | 7 +++++- src/gui/generalsettings.cpp | 36 ++++++++++++++++----------- src/gui/generalsettings.h | 6 ++--- src/gui/generalsettings.ui | 23 +++++++++++------ src/gui/owncloudgui.cpp | 6 +---- src/gui/servernotificationhandler.cpp | 2 ++ src/libsync/configfile.cpp | 30 +++++++++++----------- src/libsync/configfile.h | 12 ++++----- 9 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 63af43513..37dacb5dd 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -310,7 +310,7 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) // Assemble a tray notification ConfigFile cfg; - if(cfg.optionalDesktopNotifications()){ + if(cfg.optionalServerNotifications()){ QString log = tr("Notification for %1.").arg(activity._accName); emit guiLog(log, activity._subject); } @@ -604,9 +604,7 @@ void ActivitySettings::slotCopyToClipboard() QApplication::clipboard()->setText(text); - ConfigFile cfg; - if(cfg.optionalActivityNotifications()) - emit guiLog(tr("Copied to clipboard"), message); + emit guiLog(tr("Copied to clipboard"), message); } void ActivitySettings::slotRemoveAccount(AccountState *ptr) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index f0664d218..ee4f5fd64 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -408,8 +408,13 @@ void Folder::createGuiLog(const QString &filename, LogStatus status, int count, break; } + ConfigFile cfg; if (!text.isEmpty()) { - logger->postOptionalGuiLog(tr("Sync Activity"), text); + // Ignores the settings in case of an error or conflict + if(cfg.optionalClientSyncActivities() || + status == LogStatusError || + status == LogStatusConflict) + logger->postOptionalGuiLog(tr("Sync Activity"), text); } } } diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 8cffa9100..705e6df8c 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -42,12 +42,18 @@ GeneralSettings::GeneralSettings(QWidget *parent) { _ui->setupUi(this); - connect(_ui->desktopNotificationsCheckBox, &QAbstractButton::toggled, - this, &GeneralSettings::slotToggleOptionalDesktopNotifications); - connect(_ui->syncNotificationsCheckBox, &QAbstractButton::toggled, - this, &GeneralSettings::slotToggleOptionalSyncNotifications); - connect(_ui->activityNotificationsCheckBox, &QAbstractButton::toggled, - this, &GeneralSettings::slotToggleOptionalActivityNotifications); + connect(_ui->serverNotificationsCheckBox, &QAbstractButton::toggled, + this, &GeneralSettings::slotToggleOptionalServerNotifications); + _ui->serverNotificationsCheckBox->setToolTip(tr("Server notifications that require attention.")); + + connect(_ui->serverActivitiesCheckBox, &QAbstractButton::toggled, + this, &GeneralSettings::slotToggleOptionalServerActivities); + _ui->serverActivitiesCheckBox->setToolTip(tr("Activity feed from the server.")); + + connect(_ui->clientSyncActivitiesCheckBox, &QAbstractButton::toggled, + this, &GeneralSettings::slotToggleOptionalClientSyncActivities); + _ui->clientSyncActivitiesCheckBox->setToolTip(tr("Client sync activity.")); + connect(_ui->showInExplorerNavigationPaneCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowInExplorerNavigationPane); _ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName())); @@ -118,9 +124,9 @@ void GeneralSettings::loadMiscSettings() QScopedValueRollback scope(_currentlyLoading, true); ConfigFile cfgFile; _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); - _ui->desktopNotificationsCheckBox->setChecked(cfgFile.optionalDesktopNotifications()); - _ui->syncNotificationsCheckBox->setChecked(cfgFile.optionalSyncNotifications()); - _ui->activityNotificationsCheckBox->setChecked(cfgFile.optionalActivityNotifications()); + _ui->serverNotificationsCheckBox->setChecked(cfgFile.optionalServerNotifications()); + _ui->serverActivitiesCheckBox->setChecked(cfgFile.optionalServerActivities()); + _ui->clientSyncActivitiesCheckBox->setChecked(cfgFile.optionalClientSyncActivities()); _ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); @@ -171,23 +177,23 @@ void GeneralSettings::slotToggleLaunchOnStartup(bool enable) Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), enable); } -void GeneralSettings::slotToggleOptionalDesktopNotifications(bool enable) +void GeneralSettings::slotToggleOptionalServerNotifications(bool enable) { ConfigFile cfgFile; - cfgFile.setOptionalDesktopNotifications(enable); + cfgFile.setOptionalServerNotifications(enable); } -void GeneralSettings::slotToggleOptionalSyncNotifications(bool enable) +void GeneralSettings::slotToggleOptionalServerActivities(bool enable) { ConfigFile cfgFile; - cfgFile.setOptionalSyncNotifications(enable); + cfgFile.setOptionalServerActivities(enable); } -void GeneralSettings::slotToggleOptionalActivityNotifications(bool enable) +void GeneralSettings::slotToggleOptionalClientSyncActivities(bool enable) { ConfigFile cfgFile; - cfgFile.setOptionalActivityNotifications(enable); + cfgFile.setOptionalClientSyncActivities(enable); } diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 1058ffd6b..4620171d6 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -42,9 +42,9 @@ public: private slots: void saveMiscSettings(); void slotToggleLaunchOnStartup(bool); - void slotToggleOptionalDesktopNotifications(bool); - void slotToggleOptionalSyncNotifications(bool); - void slotToggleOptionalActivityNotifications(bool); + void slotToggleOptionalServerNotifications(bool); + void slotToggleOptionalServerActivities(bool); + void slotToggleOptionalClientSyncActivities(bool); void slotShowInExplorerNavigationPane(bool); void slotUpdateInfo(); void slotIgnoreFilesEditor(); diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index e18cece79..9ef59ef4f 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -21,9 +21,9 @@ - + - Show Sync Notifications + Show Server &Activities @@ -35,9 +35,9 @@ - + - Show &Desktop Notifications + Show Server &Notifications @@ -52,9 +52,18 @@ - + + + + + + -1 + + + + - Show Activity Notifications + Show &Client Sync Activities @@ -267,7 +276,7 @@ autostartCheckBox - desktopNotificationsCheckBox + serverNotificationsCheckBox monoIconsCheckBox ignoredFilesButton newFolderLimitCheckBox diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 10be7f430..135f93c78 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -16,7 +16,6 @@ #include "owncloudgui.h" #include "theme.h" #include "folderman.h" -#include "configfile.h" #include "progressdispatcher.h" #include "owncloudsetupwizard.h" #include "sharedialog.h" @@ -682,10 +681,7 @@ void ownCloudGui::slotShowTrayMessage(const QString &title, const QString &msg) void ownCloudGui::slotShowOptionalTrayMessage(const QString &title, const QString &msg) { - ConfigFile cfg; - if (cfg.optionalDesktopNotifications()) { - slotShowTrayMessage(title, msg); - } + slotShowTrayMessage(title, msg); } diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp index 4392e8f6e..2e5269c6a 100644 --- a/src/gui/servernotificationhandler.cpp +++ b/src/gui/servernotificationhandler.cpp @@ -59,6 +59,8 @@ void ServerNotificationHandler::slotFetchNotifications(AccountState *ptr) void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &json, int statusCode) { + QString strJson(json.toJson(QJsonDocument::Compact)); + qDebug() << strJson; if (statusCode != 200) { qCWarning(lcServerNotification) << "Notifications failed with status code " << statusCode; deleteLater(); diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 5c5bd564f..9abc602b9 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -53,9 +53,9 @@ static const char notificationRefreshIntervalC[] = "notificationRefreshInterval" static const char monoIconsC[] = "monoIcons"; static const char promptDeleteC[] = "promptDeleteAllFiles"; static const char crashReporterC[] = "crashReporter"; -static const char optionalDesktopNotificationsC[] = "optionalDesktopNotifications"; -static const char optionalSyncNotificationsC[] = "optionalSyncNotifications"; -static const char optionalActivityNotificationsC[] = "optionalActivityNotifications"; +static const char optionalServerNotificationsC[] = "optionalServerNotifications"; +static const char optionalServerActivitiesC[] = "optionalServerActivities"; +static const char optionalClientSyncActivitiesC[] = "optionalClientSyncActivities"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; @@ -123,22 +123,22 @@ bool ConfigFile::setConfDir(const QString &value) return false; } -bool ConfigFile::optionalDesktopNotifications() const +bool ConfigFile::optionalServerNotifications() const { QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalDesktopNotificationsC), true).toBool(); + return settings.value(QLatin1String(optionalServerNotificationsC), true).toBool(); } -bool ConfigFile::optionalSyncNotifications() const +bool ConfigFile::optionalServerActivities() const { QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalSyncNotificationsC), false).toBool(); + return settings.value(QLatin1String(optionalServerActivitiesC), false).toBool(); } -bool ConfigFile::optionalActivityNotifications() const +bool ConfigFile::optionalClientSyncActivities() const { QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalActivityNotificationsC), false).toBool(); + return settings.value(QLatin1String(optionalClientSyncActivitiesC), false).toBool(); } bool ConfigFile::showInExplorerNavigationPane() const @@ -191,24 +191,24 @@ quint64 ConfigFile::targetChunkUploadDuration() const return settings.value(QLatin1String(targetChunkUploadDurationC), 60 * 1000).toLongLong(); // default to 1 minute } -void ConfigFile::setOptionalDesktopNotifications(bool show) +void ConfigFile::setOptionalServerNotifications(bool show) { QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(optionalDesktopNotificationsC), show); + settings.setValue(QLatin1String(optionalServerNotificationsC), show); settings.sync(); } -void ConfigFile::setOptionalSyncNotifications(bool show) +void ConfigFile::setOptionalServerActivities(bool show) { QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(optionalSyncNotificationsC), show); + settings.setValue(QLatin1String(optionalServerActivitiesC), show); settings.sync(); } -void ConfigFile::setOptionalActivityNotifications(bool show) +void ConfigFile::setOptionalClientSyncActivities(bool show) { QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(optionalActivityNotificationsC), show); + settings.setValue(QLatin1String(optionalClientSyncActivitiesC), show); settings.sync(); } diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index a9bb403bb..60034b8ee 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -120,14 +120,14 @@ public: static bool setConfDir(const QString &value); - bool optionalDesktopNotifications() const; - void setOptionalDesktopNotifications(bool show); + bool optionalServerNotifications() const; + void setOptionalServerNotifications(bool show); - bool optionalSyncNotifications() const; - void setOptionalSyncNotifications(bool show); + bool optionalServerActivities() const; + void setOptionalServerActivities(bool show); - bool optionalActivityNotifications() const; - void setOptionalActivityNotifications(bool show); + bool optionalClientSyncActivities() const; + void setOptionalClientSyncActivities(bool show); bool showInExplorerNavigationPane() const; void setShowInExplorerNavigationPane(bool show); From 20cf4ed6425030d4961069df9f63eee654ca7b30 Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 16 Feb 2018 18:02:33 +0100 Subject: [PATCH 05/22] Improves Notification Widget UI. - Changes spacing. - Removes QFrame. - Changes icon size. Signed-off-by: Camila San --- resources/bell.png | Bin 900 -> 515 bytes src/gui/notificationwidget.cpp | 4 +- src/gui/notificationwidget.ui | 127 +++++++++++++++++++++++---------- 3 files changed, 90 insertions(+), 41 deletions(-) diff --git a/resources/bell.png b/resources/bell.png index 1947cde8cd2ef742bf48961b3ad75f4a43c79868..b01d6c62e0c31bdb5dbe7ae1d2ec7223800c7130 100644 GIT binary patch delta 479 zcmV<50U-W_2ZID5iBL{Q4GJ0x0000DNk~Le0000S0000S2nGNE0CElAl#wAYf8qiV z4-Xh3Dc5oU00EFmL_t(Y$L-d?OIJ}C$MKiHKr|xLC2?$M3`(_K@bEf75xQ)R!BdMphf$-Ji_JT_jbMaii;n3hI2XRyw5q$kNa?} ziq%wd{Rjqd8h`KsOW3aZplz7Je+KFa`-Vka!DP%Ut!C8lF9l25SA4>?DsEQ8P6jLq z9V-Ltz(NjC(iYKL1lEPw1H$%vI-Up6ns9he1W3K0-A-?uRzI$zJsf`?6D3@6A`93b zx4BSZ3Vlz9cv2JS!+J%q4XkAWw*xkatN2&~R>v}4WK9~y4-Ch+1=9rre`N>H@}xu) zp5Qf3CcfW@gX9H1-{LRvqCsko?;b#umqaw*Z6^n;)4iB(`&HupW&{@>!_u{s% zQkym^+A~p+O4ZJ@4K{zA8b8IED)Oki0q|6$%-;C^LH=!7+KQ(Yp$>QPJN%q?pUhgC zE(AC67DIR$t;A)#$7l57HSb~dKpmLJFTBAQtVRt!v?i)0nx{+gLJ#roxF0<-?E>1A Vxr9Bq$eaKG002ovPDHLkV1kHz(!l@# delta 867 zcmV-p1DyPW1cV16iBL{Q4GJ0x0000DNk~Le0000$0000$2nGNE0IF$m-jN|Nf8YZH z3?e0JDGwh200R+8L_t(|+U=T6XcIvc$A7UJ+e$%OBK0Gdo~l+47Nj16iXtc?(vug_ zO2vz!R>beSVr`&Bym%G_K}$jK z4RE&rw4Hqb4gs^n0N)4vDFI%#d%yyq1?T~~RfE4+Cb(=_;EVM8sw(hl58&-=ZIt2j zz|JVce*&7L3ZDli#fvd;I`0F#Y4?LRMfwSE+QBHp=YfwvQxu+gC)*#zf5^*rE2@z< z?R!)sFPr0(Sn5ks|0e1H>zZUk1EU5IzsQDh4;pg#&H??TQv#ZdZDOMT$n=v~`t^06CR>3#nCSe;khi+khtljrpey2$BQ#dO4JiNhf}4 z(Rgaj!75JxX80(z)%(8(|#ux-Ii6~e~^nlF<`I?@PoC= zuufWTWS8atMxY;f415OO0}n8Ebd`rUlb<`5_ko!*cla;^)D+%SGw@p6&`oh{z7I8n zGy&3b;Hy|5QRSCiU?Oi-3gbJYdf^PWFn@s`s>93bDkGw&T(%okq4JU{!vXEUh>Lbx zRdB%465(?qiAuPbe;!ww{eNw8GqWf%~>j_|o!+K%T#sQmDtjEsT}M<0V@cJ z;$n2XlilQE$pEJdtRu1*+j61PIbz^)k>Y7+;bkR&6JnUp tNbrxM0B=setText(activity._message); _ui._notifIcon->setPixmap(QPixmap(":/client/resources/bell.png")); - _ui._notifIcon->setMinimumWidth(64); - _ui._notifIcon->setMinimumHeight(64); + _ui._notifIcon->setMinimumWidth(28); + _ui._notifIcon->setMinimumHeight(28); _ui._notifIcon->show(); QString tText = tr("Created at %1").arg(Utility::timeAgoInWords(activity._dateTime)); diff --git a/src/gui/notificationwidget.ui b/src/gui/notificationwidget.ui index 7f34baab5..f496e0feb 100644 --- a/src/gui/notificationwidget.ui +++ b/src/gui/notificationwidget.ui @@ -20,42 +20,82 @@ Form + + QLayout::SetMaximumSize + + + 24 + 0 + + 26 + 0 - - - - - 0 - 0 - - - - - - - ../../../../resources/bell.png - - - + + 0 + + + 2 + + + 4 + - - - - 0 - 0 - + + + 6 - - Lorem ipsum dolor sit amet + + 6 - + + + + + 0 + 0 + + + + 0 + + + + + + ../../../../resources/bell.png + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + 0 + + + + + + + + 0 + 0 + + + + Lorem ipsum dolor sit amet + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + @@ -71,6 +111,9 @@ false + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + true @@ -78,6 +121,25 @@ + + 6 + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 32 + 20 + + + + @@ -89,7 +151,7 @@ TextLabel - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -104,19 +166,6 @@ - - - - QFrame::HLine - - - QFrame::Raised - - - 4 - - - From 32e29fb84982e77dcbe43cc1032aa37abe4f12dc Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 16 Feb 2018 19:17:22 +0100 Subject: [PATCH 06/22] Doesn't open the file manager when there isn't a file associated with the Activity. Signed-off-by: Camila San --- src/gui/activitylistmodel.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gui/activitylistmodel.cpp b/src/gui/activitylistmodel.cpp index f42e6da10..ac2d2694e 100644 --- a/src/gui/activitylistmodel.cpp +++ b/src/gui/activitylistmodel.cpp @@ -53,14 +53,16 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const switch (role) { case ActivityItemDelegate::PathRole: - list = FolderMan::instance()->findFileInLocalFolders(a._file, ast->account()); - if (list.count() > 0) { - return QVariant(list.at(0)); - } - // File does not exist anymore? Let's try to open its path - list = FolderMan::instance()->findFileInLocalFolders(QFileInfo(a._file).path(), ast->account()); - if (list.count() > 0) { - return QVariant(list.at(0)); + if(!a._file.isEmpty()){ + list = FolderMan::instance()->findFileInLocalFolders(a._file, ast->account()); + if (list.count() > 0) { + return QVariant(list.at(0)); + } + // File does not exist anymore? Let's try to open its path + list = FolderMan::instance()->findFileInLocalFolders(QFileInfo(a._file).path(), ast->account()); + if (list.count() > 0) { + return QVariant(list.at(0)); + } } return QVariant(); break; From 1a0edc1cd065a63a45a531cdf66580f3b6030a5d Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 23 Feb 2018 12:08:37 +0100 Subject: [PATCH 07/22] Sync activities notifications are never shown unless there is an error. Server activities and notifications are off by default. Signed-off-by: Camila San --- src/gui/folder.cpp | 5 +---- src/gui/generalsettings.cpp | 13 ------------- src/gui/generalsettings.h | 1 - src/gui/generalsettings.ui | 34 +++++++++------------------------- src/libsync/configfile.cpp | 16 +--------------- src/libsync/configfile.h | 3 --- 6 files changed, 11 insertions(+), 61 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index ee4f5fd64..6d3d35a81 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -408,12 +408,9 @@ void Folder::createGuiLog(const QString &filename, LogStatus status, int count, break; } - ConfigFile cfg; if (!text.isEmpty()) { // Ignores the settings in case of an error or conflict - if(cfg.optionalClientSyncActivities() || - status == LogStatusError || - status == LogStatusConflict) + if(status == LogStatusError || status == LogStatusConflict) logger->postOptionalGuiLog(tr("Sync Activity"), text); } } diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 705e6df8c..a91da46ed 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -50,10 +50,6 @@ GeneralSettings::GeneralSettings(QWidget *parent) this, &GeneralSettings::slotToggleOptionalServerActivities); _ui->serverActivitiesCheckBox->setToolTip(tr("Activity feed from the server.")); - connect(_ui->clientSyncActivitiesCheckBox, &QAbstractButton::toggled, - this, &GeneralSettings::slotToggleOptionalClientSyncActivities); - _ui->clientSyncActivitiesCheckBox->setToolTip(tr("Client sync activity.")); - connect(_ui->showInExplorerNavigationPaneCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowInExplorerNavigationPane); _ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName())); @@ -126,7 +122,6 @@ void GeneralSettings::loadMiscSettings() _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); _ui->serverNotificationsCheckBox->setChecked(cfgFile.optionalServerNotifications()); _ui->serverActivitiesCheckBox->setChecked(cfgFile.optionalServerActivities()); - _ui->clientSyncActivitiesCheckBox->setChecked(cfgFile.optionalClientSyncActivities()); _ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); @@ -189,14 +184,6 @@ void GeneralSettings::slotToggleOptionalServerActivities(bool enable) cfgFile.setOptionalServerActivities(enable); } - -void GeneralSettings::slotToggleOptionalClientSyncActivities(bool enable) -{ - ConfigFile cfgFile; - cfgFile.setOptionalClientSyncActivities(enable); -} - - void GeneralSettings::slotShowInExplorerNavigationPane(bool checked) { ConfigFile cfgFile; diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 4620171d6..aa0e16dd9 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -44,7 +44,6 @@ private slots: void slotToggleLaunchOnStartup(bool); void slotToggleOptionalServerNotifications(bool); void slotToggleOptionalServerActivities(bool); - void slotToggleOptionalClientSyncActivities(bool); void slotShowInExplorerNavigationPane(bool); void slotUpdateInfo(); void slotIgnoreFilesEditor(); diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index 9ef59ef4f..fefbf102d 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -20,10 +20,13 @@ General Settings - - + + + + For System Tray + - Show Server &Activities + Use &Monochrome Icons @@ -41,29 +44,10 @@ - - - - For System Tray - + + - Use &Monochrome Icons - - - - - - - - - - -1 - - - - - - Show &Client Sync Activities + Show Server &Activities diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 9abc602b9..886ebc639 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -55,7 +55,6 @@ static const char promptDeleteC[] = "promptDeleteAllFiles"; static const char crashReporterC[] = "crashReporter"; static const char optionalServerNotificationsC[] = "optionalServerNotifications"; static const char optionalServerActivitiesC[] = "optionalServerActivities"; -static const char optionalClientSyncActivitiesC[] = "optionalClientSyncActivities"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; @@ -126,7 +125,7 @@ bool ConfigFile::setConfDir(const QString &value) bool ConfigFile::optionalServerNotifications() const { QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalServerNotificationsC), true).toBool(); + return settings.value(QLatin1String(optionalServerNotificationsC), false).toBool(); } bool ConfigFile::optionalServerActivities() const @@ -135,12 +134,6 @@ bool ConfigFile::optionalServerActivities() const return settings.value(QLatin1String(optionalServerActivitiesC), false).toBool(); } -bool ConfigFile::optionalClientSyncActivities() const -{ - QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalClientSyncActivitiesC), false).toBool(); -} - bool ConfigFile::showInExplorerNavigationPane() const { const bool defaultValue = @@ -205,13 +198,6 @@ void ConfigFile::setOptionalServerActivities(bool show) settings.sync(); } -void ConfigFile::setOptionalClientSyncActivities(bool show) -{ - QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(optionalClientSyncActivitiesC), show); - settings.sync(); -} - void ConfigFile::saveGeometry(QWidget *w) { #ifndef TOKEN_AUTH_ONLY diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index 60034b8ee..f1d87c002 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -126,9 +126,6 @@ public: bool optionalServerActivities() const; void setOptionalServerActivities(bool show); - bool optionalClientSyncActivities() const; - void setOptionalClientSyncActivities(bool show); - bool showInExplorerNavigationPane() const; void setShowInExplorerNavigationPane(bool show); From 4c790591461b9d95d96e1bd2ed4bd5d2834b9fd7 Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 25 Feb 2018 23:54:04 +0100 Subject: [PATCH 08/22] Changes notification icon bell size. Signed-off-by: Camila San --- resources/bell.png | Bin 515 -> 495 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/resources/bell.png b/resources/bell.png index b01d6c62e0c31bdb5dbe7ae1d2ec7223800c7130..d96a82bc3d25d2a230fdbbd948c33d88e80ae931 100644 GIT binary patch delta 457 zcmV;)0XF`F1n&bOiBL{Q4GJ0x0000DNk~Le0000M0000M2nGNE0K~LxJCPwWe-{iV z1oY&icK`qZd`Uz>R5;76)yqp%VHn5p&x|94g_yNTTDoW{Wl$)%5W4IHcZn-^?QZZ7S)b2woy&kFD&B$f5u{8ZWU3%aSEEWpV+~pW<0InCz{?!K zq%EVA1-*L2tz4wZXA9#jyIp@63InR&#aIA{e zRC4_Y25=gG@BvHMuKJ*Dn860>e+m1BMO?vT%qy*C)bK9_OWId_!nG=HR>MvPED0Se z1M9#-4p7n-(OLx7h1mnb_Ix^?2hf^ucuxdKy`bGrZ=6;?uA@C1e;yMhTyY``*dMpK zP+YA+LXD3 TJ-Eo600000NkvXXu0mjfw;s|& From e33d2bf7f70360332c4f5f1c144bd6557c701b24 Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 25 Feb 2018 23:54:57 +0100 Subject: [PATCH 09/22] Removes (s) from time strings. Signed-off-by: Camila San --- src/common/utility.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 29308ea84..30d17c8ba 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -431,27 +431,38 @@ QString Utility::timeAgoInWords(const QDateTime &dt, const QDateTime &from) now = from; } - if (dt.daysTo(now) > 0) { - int dtn = dt.daysTo(now); - return QObject::tr("%n day(s) ago", "", dtn); + if (dt.daysTo(now) == 1) { + return QObject::tr("%n day ago", "", dt.daysTo(now)); + } else if (dt.daysTo(now) > 1) { + return QObject::tr("%n days ago", "", dt.daysTo(now)); } else { qint64 secs = dt.secsTo(now); if (secs < 0) { return QObject::tr("in the future"); } + if (floor(secs / 3600.0) > 0) { int hours = floor(secs / 3600.0); - return (QObject::tr("%n hour(s) ago", "", hours)); + if(hours == 1){ + return (QObject::tr("%n hour ago", "", hours)); + } else { + return (QObject::tr("%n hours ago", "", hours)); + } } else { int minutes = qRound(secs / 60.0); + if (minutes == 0) { if (secs < 5) { return QObject::tr("now"); } else { return QObject::tr("Less than a minute ago"); } + + } else if(minutes == 1){ + return (QObject::tr("%n minute ago", "", minutes)); + } else { + return (QObject::tr("%n minutes ago", "", minutes)); } - return (QObject::tr("%n minute(s) ago", "", minutes)); } } return QObject::tr("Some time ago"); From 4a6a8ca6c6bd62dd5618bb4143eb86ee5bdd570a Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 25 Feb 2018 23:56:54 +0100 Subject: [PATCH 10/22] Removes _appName from Activity data. Signed-off-by: Camila San --- src/gui/activitydata.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/activitydata.h b/src/gui/activitydata.h index c48965c50..40cd35e05 100644 --- a/src/gui/activitydata.h +++ b/src/gui/activitydata.h @@ -59,7 +59,6 @@ public: QUrl _link; QDateTime _dateTime; QString _accName; - QString _appName; QVector _links; /** From 71f47602152b4232032045f3618fd01faebdafe6 Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 25 Feb 2018 23:57:44 +0100 Subject: [PATCH 11/22] Do not display user account when there is only one user in popup message. Signed-off-by: Camila San --- src/gui/activitywidget.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 37dacb5dd..139674511 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -249,8 +249,6 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) bool newNotificationShown = false; foreach (auto activity, list) { - qDebug() << "Notification list" - << activity._subject; if (_blacklistedNotifications.contains(activity)) { qCInfo(lcActivity) << "Activity in blacklist, skip"; continue; @@ -311,9 +309,12 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) // Assemble a tray notification ConfigFile cfg; if(cfg.optionalServerNotifications()){ - QString log = tr("Notification for %1.").arg(activity._accName); - emit guiLog(log, activity._subject); - } + if(AccountManager::instance()->accounts().count() == 1){ + emit guiLog(activity._subject, ""); + } else { + emit guiLog(activity._subject, activity._accName); + } + } } // check if there are widgets that have no corresponding activity from From d71438f181c5cdb4312253e5dcf21a24781332de Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 25 Feb 2018 23:58:28 +0100 Subject: [PATCH 12/22] Adds host and scheme to activity link so it can be opened in the browser. - Removes debug messages. - Removes Activity data _appName - not used anymore. Signed-off-by: Camila San --- src/gui/servernotificationhandler.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp index 2e5269c6a..f8e8e2615 100644 --- a/src/gui/servernotificationhandler.cpp +++ b/src/gui/servernotificationhandler.cpp @@ -59,8 +59,6 @@ void ServerNotificationHandler::slotFetchNotifications(AccountState *ptr) void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &json, int statusCode) { - QString strJson(json.toJson(QJsonDocument::Compact)); - qDebug() << strJson; if (statusCode != 200) { qCWarning(lcServerNotification) << "Notifications failed with status code " << statusCode; deleteLater(); @@ -81,17 +79,19 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j a._id = json.value("notification_id").toInt(); a._subject = json.value("subject").toString(); a._message = json.value("message").toString(); - a._appName = json.value("app").toString(); QString s = json.value("link").toString(); if (!s.isEmpty()) { - a._link = QUrl(s); + QUrl link(s); + if(link.host().isEmpty()){ + link.setScheme(ai->account()->url().scheme()); + link.setHost(ai->account()->url().host()); + } + a._link = link; } a._dateTime = QDateTime::fromString(json.value("datetime").toString(), Qt::ISODate); auto actions = json.value("actions").toArray(); - qDebug() << "Notification ACTIONS:" - << json.value("actions").toString(); foreach (auto action, actions) { auto actionJson = action.toObject(); ActivityLink al; @@ -112,10 +112,6 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j al._isPrimary = false; a._links.append(al); - qDebug() << "Notification LINK:" - << a._link; - - list.append(a); } emit newNotificationList(list); From 44f299eba243b59072f122daefc9402f7328a825 Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 26 Feb 2018 00:00:42 +0100 Subject: [PATCH 13/22] Removes debug messages. Signed-off-by: Camila San --- src/gui/activitylistmodel.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/gui/activitylistmodel.cpp b/src/gui/activitylistmodel.cpp index ac2d2694e..6684fed2a 100644 --- a/src/gui/activitylistmodel.cpp +++ b/src/gui/activitylistmodel.cpp @@ -154,9 +154,6 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st foreach (auto activ, activities) { auto json = activ.toObject(); - qDebug() << "Activity list" - << json.value("subject").toString(); - Activity a; a._type = Activity::ActivityType; a._accName = ast->account()->displayName(); From 0f9d8e15a03754a8f29b67cfaef53f2cf1aa55e9 Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 26 Feb 2018 00:02:09 +0100 Subject: [PATCH 14/22] Only uses 'More information' text in button for notification link. Signed-off-by: Camila San --- src/gui/notificationwidget.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp index 55ea188e0..48ccf8b89 100644 --- a/src/gui/notificationwidget.cpp +++ b/src/gui/notificationwidget.cpp @@ -41,7 +41,6 @@ void NotificationWidget::setActivity(const Activity &activity) _accountName = activity._accName; ASSERT(!_accountName.isEmpty()); - // _ui._headerLabel->setText( ); _ui._subjectLabel->setVisible(!activity._subject.isEmpty()); _ui._messageLabel->setVisible(!activity._message.isEmpty()); @@ -49,8 +48,8 @@ void NotificationWidget::setActivity(const Activity &activity) _ui._messageLabel->setText(activity._message); _ui._notifIcon->setPixmap(QPixmap(":/client/resources/bell.png")); - _ui._notifIcon->setMinimumWidth(28); - _ui._notifIcon->setMinimumHeight(28); + _ui._notifIcon->setMinimumWidth(22); + _ui._notifIcon->setMinimumHeight(22); _ui._notifIcon->show(); QString tText = tr("Created at %1").arg(Utility::timeAgoInWords(activity._dateTime)); @@ -63,15 +62,8 @@ void NotificationWidget::setActivity(const Activity &activity) _buttons.clear(); // open the notification in the browser if there is a link - if(!_myActivity._links.isEmpty()){ - QString buttonText(tr("Open")); - - if(_myActivity._appName == "spreed") - buttonText = tr("Join call"); - - if(_myActivity._appName == "updatenotification") - buttonText = tr("Update"); - + 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); @@ -80,7 +72,7 @@ void NotificationWidget::setActivity(const Activity &activity) // display buttons for the links if (activity._links.isEmpty()) { - // this condition is never satisfied since there is always a 'dismiss' ActivityLink being added at servernotificationhandler... + // 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); From 09a92a518a7b84a3e26c40ada4f604ecf8f0b74b Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 26 Feb 2018 00:03:29 +0100 Subject: [PATCH 15/22] Align text and changes spacing in notification widget. --- src/gui/notificationwidget.ui | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/gui/notificationwidget.ui b/src/gui/notificationwidget.ui index f496e0feb..fc71d3061 100644 --- a/src/gui/notificationwidget.ui +++ b/src/gui/notificationwidget.ui @@ -44,7 +44,13 @@ - 4 + 6 + + + 5 + + + 5 @@ -112,11 +118,17 @@ false - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter true + + 0 + + + 28 + @@ -134,7 +146,7 @@ - 32 + 28 20 @@ -151,7 +163,7 @@ TextLabel - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter From 112c5e10b6ce0b60beba31cdac582a14cc8d2a69 Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 26 Feb 2018 12:02:34 +0100 Subject: [PATCH 16/22] Removes Server Activities option from General settings. Signed-off-by: Camila San --- src/gui/generalsettings.cpp | 11 ----------- src/gui/generalsettings.h | 1 - src/gui/generalsettings.ui | 7 ------- src/libsync/configfile.cpp | 14 -------------- src/libsync/configfile.h | 3 --- 5 files changed, 36 deletions(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index a91da46ed..419b5214b 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -46,10 +46,6 @@ GeneralSettings::GeneralSettings(QWidget *parent) this, &GeneralSettings::slotToggleOptionalServerNotifications); _ui->serverNotificationsCheckBox->setToolTip(tr("Server notifications that require attention.")); - connect(_ui->serverActivitiesCheckBox, &QAbstractButton::toggled, - this, &GeneralSettings::slotToggleOptionalServerActivities); - _ui->serverActivitiesCheckBox->setToolTip(tr("Activity feed from the server.")); - connect(_ui->showInExplorerNavigationPaneCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowInExplorerNavigationPane); _ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName())); @@ -121,7 +117,6 @@ void GeneralSettings::loadMiscSettings() ConfigFile cfgFile; _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); _ui->serverNotificationsCheckBox->setChecked(cfgFile.optionalServerNotifications()); - _ui->serverActivitiesCheckBox->setChecked(cfgFile.optionalServerActivities()); _ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); @@ -178,12 +173,6 @@ void GeneralSettings::slotToggleOptionalServerNotifications(bool enable) cfgFile.setOptionalServerNotifications(enable); } -void GeneralSettings::slotToggleOptionalServerActivities(bool enable) -{ - ConfigFile cfgFile; - cfgFile.setOptionalServerActivities(enable); -} - void GeneralSettings::slotShowInExplorerNavigationPane(bool checked) { ConfigFile cfgFile; diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index aa0e16dd9..74c6520f2 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -43,7 +43,6 @@ private slots: void saveMiscSettings(); void slotToggleLaunchOnStartup(bool); void slotToggleOptionalServerNotifications(bool); - void slotToggleOptionalServerActivities(bool); void slotShowInExplorerNavigationPane(bool); void slotUpdateInfo(); void slotIgnoreFilesEditor(); diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index fefbf102d..abfdb92a9 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -44,13 +44,6 @@ - - - - Show Server &Activities - - - diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 886ebc639..a1af833f2 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -54,7 +54,6 @@ static const char monoIconsC[] = "monoIcons"; static const char promptDeleteC[] = "promptDeleteAllFiles"; static const char crashReporterC[] = "crashReporter"; static const char optionalServerNotificationsC[] = "optionalServerNotifications"; -static const char optionalServerActivitiesC[] = "optionalServerActivities"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; @@ -128,12 +127,6 @@ bool ConfigFile::optionalServerNotifications() const return settings.value(QLatin1String(optionalServerNotificationsC), false).toBool(); } -bool ConfigFile::optionalServerActivities() const -{ - QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalServerActivitiesC), false).toBool(); -} - bool ConfigFile::showInExplorerNavigationPane() const { const bool defaultValue = @@ -191,13 +184,6 @@ void ConfigFile::setOptionalServerNotifications(bool show) settings.sync(); } -void ConfigFile::setOptionalServerActivities(bool show) -{ - QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(optionalServerActivitiesC), show); - settings.sync(); -} - void ConfigFile::saveGeometry(QWidget *w) { #ifndef TOKEN_AUTH_ONLY diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index f1d87c002..f414322a9 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -123,9 +123,6 @@ public: bool optionalServerNotifications() const; void setOptionalServerNotifications(bool show); - bool optionalServerActivities() const; - void setOptionalServerActivities(bool show); - bool showInExplorerNavigationPane() const; void setShowInExplorerNavigationPane(bool show); From 56709f3cfffd9dfd97b906094da3da2a22816e16 Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 26 Feb 2018 12:56:02 +0100 Subject: [PATCH 17/22] Removes string 'Created' from notifications time. Signed-off-by: Camila San --- src/gui/notificationwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp index 48ccf8b89..e84ad557f 100644 --- a/src/gui/notificationwidget.cpp +++ b/src/gui/notificationwidget.cpp @@ -52,7 +52,7 @@ void NotificationWidget::setActivity(const Activity &activity) _ui._notifIcon->setMinimumHeight(22); _ui._notifIcon->show(); - QString tText = tr("Created at %1").arg(Utility::timeAgoInWords(activity._dateTime)); + QString tText = tr("%1").arg(Utility::timeAgoInWords(activity._dateTime)); _ui._timeLabel->setText(tText); // always remove the buttons From 6bf9f65fd3bf1455e68e2ef8ab6dd3900606f77e Mon Sep 17 00:00:00 2001 From: Camila San Date: Tue, 27 Feb 2018 23:05:18 +0100 Subject: [PATCH 18/22] Only notify users of new notifications and only shows them all on startup. Signed-off-by: Camila San --- src/gui/activitywidget.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 139674511..c65407236 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -304,15 +304,15 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) } } _guiLoggedNotifications.insert(activity._id); - } - // Assemble a tray notification - ConfigFile cfg; - if(cfg.optionalServerNotifications()){ - if(AccountManager::instance()->accounts().count() == 1){ - emit guiLog(activity._subject, ""); - } else { - emit guiLog(activity._subject, activity._accName); + // Assemble a tray notification for the NEW notification + ConfigFile cfg; + if(cfg.optionalServerNotifications()){ + if(AccountManager::instance()->accounts().count() == 1){ + emit guiLog(activity._subject, ""); + } else { + emit guiLog(activity._subject, activity._accName); + } } } } From d42401e36af0549fed93e67190021e1a2255f057 Mon Sep 17 00:00:00 2001 From: Camila San Date: Thu, 1 Mar 2018 15:20:16 +0100 Subject: [PATCH 19/22] Changes notifications api endpoint to v2. Signed-off-by: Camila San --- src/gui/servernotificationhandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp index f8e8e2615..e52a8eb9b 100644 --- a/src/gui/servernotificationhandler.cpp +++ b/src/gui/servernotificationhandler.cpp @@ -24,7 +24,7 @@ namespace OCC { Q_LOGGING_CATEGORY(lcServerNotification, "gui.servernotification", QtInfoMsg) -const QString notificationsPath = QLatin1String("ocs/v2.php/apps/notifications/api/v1/notifications"); +const QString notificationsPath = QLatin1String("ocs/v2.php/apps/notifications/api/v2/notifications"); ServerNotificationHandler::ServerNotificationHandler(QObject *parent) : QObject(parent) From 621596f45a4a3faad1fd4f41f64d14ce06328f06 Mon Sep 17 00:00:00 2001 From: Camila San Date: Thu, 1 Mar 2018 22:19:04 +0100 Subject: [PATCH 20/22] Saves notifications ETag response header to use to request only new notifications. Signed-off-by: Camila San --- src/gui/accountstate.cpp | 11 +++++++++++ src/gui/accountstate.h | 11 +++++++++++ src/gui/servernotificationhandler.cpp | 28 +++++++++++++++++++++++---- src/gui/servernotificationhandler.h | 1 + src/libsync/networkjobs.cpp | 14 ++++++++++---- src/libsync/networkjobs.h | 10 ++++++++++ 6 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index a4b44b6a7..64b603e85 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -35,6 +35,7 @@ AccountState::AccountState(AccountPtr account) , _connectionStatus(ConnectionValidator::Undefined) , _waitingForNewCredentials(false) , _maintenanceToConnectedDelay(60000 + (qrand() % (4 * 60000))) // 1-5min delay + , _notificationsEtagResponseHeader("*") { qRegisterMetaType("AccountState*"); @@ -176,6 +177,16 @@ void AccountState::tagLastSuccessfullETagRequest() _timeSinceLastETagCheck.start(); } +QByteArray AccountState::notificationsEtagResponseHeader() const +{ + return _notificationsEtagResponseHeader; +} + +void AccountState::setNotificationsEtagResponseHeader(const QByteArray &value) +{ + _notificationsEtagResponseHeader = value; +} + void AccountState::checkConnectivity() { if (isSignedOut() || _waitingForNewCredentials) { diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 0ee6ec96a..0aca22ce2 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -131,6 +131,16 @@ public: */ void tagLastSuccessfullETagRequest(); + /** Saves the ETag Response header from the last Notifications api + * request with statusCode 200. + */ + QByteArray notificationsEtagResponseHeader() const; + + /** Returns the ETag Response header from the last Notifications api + * request with statusCode 200. + */ + void setNotificationsEtagResponseHeader(const QByteArray &value); + public slots: /// Triggers a ping to the server to update state and /// connection status and errors. @@ -157,6 +167,7 @@ private: bool _waitingForNewCredentials; QElapsedTimer _timeSinceLastETagCheck; QPointer _connectionValidator; + QByteArray _notificationsEtagResponseHeader; /** * Starts counting when the server starts being back up after 503 or diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp index e52a8eb9b..385ac54d3 100644 --- a/src/gui/servernotificationhandler.cpp +++ b/src/gui/servernotificationhandler.cpp @@ -25,6 +25,9 @@ namespace OCC { Q_LOGGING_CATEGORY(lcServerNotification, "gui.servernotification", QtInfoMsg) const QString notificationsPath = QLatin1String("ocs/v2.php/apps/notifications/api/v2/notifications"); +const char propertyAccountStateC[] = "oc_account_state"; +const int successStatusCode = 200; +const int notModifiedStatusCode = 304; ServerNotificationHandler::ServerNotificationHandler(QObject *parent) : QObject(parent) @@ -52,22 +55,39 @@ void ServerNotificationHandler::slotFetchNotifications(AccountState *ptr) _notificationJob = new JsonApiJob(ptr->account(), notificationsPath, this); QObject::connect(_notificationJob.data(), &JsonApiJob::jsonReceived, this, &ServerNotificationHandler::slotNotificationsReceived); - _notificationJob->setProperty("AccountStatePtr", QVariant::fromValue(ptr)); - + QObject::connect(_notificationJob.data(), &JsonApiJob::etagResponseHeaderReceived, + this, &ServerNotificationHandler::slotEtagResponseHeaderReceived); + _notificationJob->setProperty(propertyAccountStateC, QVariant::fromValue(ptr)); + _notificationJob->addRawHeader("If-None-Match", ptr->notificationsEtagResponseHeader()); _notificationJob->start(); } +void ServerNotificationHandler::slotEtagResponseHeaderReceived(const QByteArray &value, int statusCode){ + qCWarning(lcServerNotification) << "New Notification ETag Response Header received " << value; + if(statusCode == successStatusCode){ + qCWarning(lcServerNotification) << "New Notification ETag Response Header received " << value; + AccountState *account = qvariant_cast(sender()->property(propertyAccountStateC)); + account->setNotificationsEtagResponseHeader(value); + } +} + void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &json, int statusCode) { - if (statusCode != 200) { + if (statusCode != successStatusCode && statusCode != notModifiedStatusCode) { qCWarning(lcServerNotification) << "Notifications failed with status code " << statusCode; deleteLater(); return; } + if (statusCode == notModifiedStatusCode) { + qCWarning(lcServerNotification) << "Status code " << statusCode << " Not Modified - No new notifications."; + deleteLater(); + return; + } + auto notifies = json.object().value("ocs").toObject().value("data").toArray(); - AccountState *ai = qvariant_cast(sender()->property("AccountStatePtr")); + AccountState *ai = qvariant_cast(sender()->property(propertyAccountStateC)); ActivityList list; diff --git a/src/gui/servernotificationhandler.h b/src/gui/servernotificationhandler.h index 875c3189e..60f530c07 100644 --- a/src/gui/servernotificationhandler.h +++ b/src/gui/servernotificationhandler.h @@ -37,6 +37,7 @@ public slots: private slots: void slotNotificationsReceived(const QJsonDocument &json, int statusCode); + void slotEtagResponseHeaderReceived(const QByteArray &value, int statusCode); private: QPointer _notificationJob; diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index 193002a74..ff4f6126b 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -789,14 +789,18 @@ void JsonApiJob::addQueryParams(const QUrlQuery ¶ms) _additionalParams = params; } +void JsonApiJob::addRawHeader(const QByteArray &headerName, const QByteArray &value) +{ + _request.setRawHeader(headerName, value); +} + void JsonApiJob::start() { - QNetworkRequest req; - req.setRawHeader("OCS-APIREQUEST", "true"); + addRawHeader("OCS-APIREQUEST", "true"); auto query = _additionalParams; query.addQueryItem(QLatin1String("format"), QLatin1String("json")); QUrl url = Utility::concatUrlPath(account()->url(), path(), query); - sendRequest("GET", url, req); + sendRequest("GET", url, _request); AbstractNetworkJob::start(); } @@ -807,7 +811,6 @@ bool JsonApiJob::finished() << (reply()->error() == QNetworkReply::NoError ? QLatin1String("") : errorString()); int statusCode = 0; - if (reply()->error() != QNetworkReply::NoError) { qCWarning(lcJsonApiJob) << "Network error: " << path() << errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute); emit jsonReceived(QJsonDocument(), statusCode); @@ -839,6 +842,9 @@ bool JsonApiJob::finished() return true; } + if(reply()->rawHeaderList().contains("ETag")) + emit etagResponseHeaderReceived(reply()->rawHeader("ETag"), statusCode); + emit jsonReceived(json, statusCode); return true; } diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h index 994f2046c..853c1db98 100644 --- a/src/libsync/networkjobs.h +++ b/src/libsync/networkjobs.h @@ -341,6 +341,7 @@ public: * This function needs to be called before start() obviously. */ void addQueryParams(const QUrlQuery ¶ms); + void addRawHeader(const QByteArray &headerName, const QByteArray &value); public slots: void start() Q_DECL_OVERRIDE; @@ -356,8 +357,17 @@ signals: */ void jsonReceived(const QJsonDocument &json, int statusCode); + /** + * @brief etagResponseHeaderReceived - signal to report the ETag response header value + * from ocs api v2 + * @param value - the ETag response header value + * @param statusCode - the OCS status code: 100 (!) for success + */ + void etagResponseHeaderReceived(const QByteArray &value, int statusCode); + private: QUrlQuery _additionalParams; + QNetworkRequest _request; }; /** From 3c778980df27429794ba8acbd7a429caf296bb4c Mon Sep 17 00:00:00 2001 From: Camila San Date: Sat, 3 Mar 2018 22:24:01 +0100 Subject: [PATCH 21/22] Makes sure JsonApiJob::finished won't throw a JSON error when status code is 304. Signed-off-by: Camila San --- src/gui/servernotificationhandler.cpp | 1 - src/libsync/networkjobs.cpp | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp index 385ac54d3..4368db612 100644 --- a/src/gui/servernotificationhandler.cpp +++ b/src/gui/servernotificationhandler.cpp @@ -63,7 +63,6 @@ void ServerNotificationHandler::slotFetchNotifications(AccountState *ptr) } void ServerNotificationHandler::slotEtagResponseHeaderReceived(const QByteArray &value, int statusCode){ - qCWarning(lcServerNotification) << "New Notification ETag Response Header received " << value; if(statusCode == successStatusCode){ qCWarning(lcServerNotification) << "New Notification ETag Response Header received " << value; AccountState *account = qvariant_cast(sender()->property(propertyAccountStateC)); diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index ff4f6126b..00e10bc0e 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -49,6 +49,7 @@ Q_LOGGING_CATEGORY(lcMkColJob, "sync.networkjob.mkcol", QtInfoMsg) Q_LOGGING_CATEGORY(lcProppatchJob, "sync.networkjob.proppatch", QtInfoMsg) Q_LOGGING_CATEGORY(lcJsonApiJob, "sync.networkjob.jsonapi", QtInfoMsg) Q_LOGGING_CATEGORY(lcDetermineAuthTypeJob, "sync.networkjob.determineauthtype", QtInfoMsg) +const int notModifiedStatusCode = 304; RequestEtagJob::RequestEtagJob(AccountPtr account, const QString &path, QObject *parent) : AbstractNetworkJob(account, path, parent) @@ -811,8 +812,9 @@ bool JsonApiJob::finished() << (reply()->error() == QNetworkReply::NoError ? QLatin1String("") : errorString()); int statusCode = 0; + int httpStatusCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (reply()->error() != QNetworkReply::NoError) { - qCWarning(lcJsonApiJob) << "Network error: " << path() << errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute); + qCWarning(lcJsonApiJob) << "Network error: " << path() << errorString() << httpStatusCode; emit jsonReceived(QJsonDocument(), statusCode); return true; } @@ -824,7 +826,9 @@ bool JsonApiJob::finished() // this is a error message coming back from ocs. statusCode = rex.cap(1).toInt(); } - + } else if(jsonStr.isEmpty() && httpStatusCode == notModifiedStatusCode){ + qCWarning(lcJsonApiJob) << "Nothing changed so nothing to retrieve - status code: " << httpStatusCode; + statusCode = httpStatusCode; } else { QRegExp rex("\"statuscode\":(\\d+),"); // example: "{"ocs":{"meta":{"status":"ok","statuscode":100,"message":null},"data":{"version":{"major":8,"minor":"... (504) @@ -833,18 +837,19 @@ bool JsonApiJob::finished() } } + // save new ETag value + if(reply()->rawHeaderList().contains("ETag")) + emit etagResponseHeaderReceived(reply()->rawHeader("ETag"), statusCode); + QJsonParseError error; auto json = QJsonDocument::fromJson(jsonStr.toUtf8(), &error); - // empty or invalid response - if (error.error != QJsonParseError::NoError || json.isNull()) { + // empty or invalid response and status code is != 304 because jsonStr is expected to be empty + if ((error.error != QJsonParseError::NoError || json.isNull()) && httpStatusCode != notModifiedStatusCode) { qCWarning(lcJsonApiJob) << "invalid JSON!" << jsonStr << error.errorString(); emit jsonReceived(json, statusCode); return true; } - if(reply()->rawHeaderList().contains("ETag")) - emit etagResponseHeaderReceived(reply()->rawHeader("ETag"), statusCode); - emit jsonReceived(json, statusCode); return true; } From 2e4472a4db655aeb29ab82c6a11bf2c7b5e91af2 Mon Sep 17 00:00:00 2001 From: Camila San Date: Sat, 3 Mar 2018 22:44:24 +0100 Subject: [PATCH 22/22] Enables server notifications by default. Signed-off-by: Camila San --- src/libsync/configfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index a1af833f2..25248bbdf 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -124,7 +124,7 @@ bool ConfigFile::setConfDir(const QString &value) bool ConfigFile::optionalServerNotifications() const { QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(optionalServerNotificationsC), false).toBool(); + return settings.value(QLatin1String(optionalServerNotificationsC), true).toBool(); } bool ConfigFile::showInExplorerNavigationPane() const