From d2eb4addd97f5472fee58bd1f4e71b3a9cfdef26 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 31 Mar 2018 22:31:28 +0200 Subject: [PATCH] Distinguish between local an remote sync in settings --- connector/syncthingnotifier.cpp | 3 ++- connector/syncthingnotifier.h | 3 ++- connector/utils.cpp | 5 ++-- plasmoid/lib/syncthingapplet.cpp | 9 +------ tray/gui/traywidget.cpp | 9 +------ widgets/settings/notificationsoptionpage.ui | 11 +++++++-- widgets/settings/settings.cpp | 26 +++++++++++++++++++-- widgets/settings/settings.h | 8 +++++-- widgets/settings/settingsdialog.cpp | 6 +++-- 9 files changed, 52 insertions(+), 28 deletions(-) diff --git a/connector/syncthingnotifier.cpp b/connector/syncthingnotifier.cpp index 2edcfb3..51ff132 100644 --- a/connector/syncthingnotifier.cpp +++ b/connector/syncthingnotifier.cpp @@ -94,7 +94,8 @@ void SyncthingNotifier::emitSyncComplete(ChronoUtilities::DateTime when, const S VAR_UNUSED(index) // discard event if not enabled - if ((m_enabledNotifications & SyncthingHighLevelNotification::SyncComplete) == 0 || !m_initialized) { + if (!m_initialized || (!remoteDev && (m_enabledNotifications & SyncthingHighLevelNotification::LocalSyncComplete) == 0) + || (remoteDev && (m_enabledNotifications & SyncthingHighLevelNotification::LocalSyncComplete) == 0)) { return; } diff --git a/connector/syncthingnotifier.h b/connector/syncthingnotifier.h index 46e1f3c..bdfd501 100644 --- a/connector/syncthingnotifier.h +++ b/connector/syncthingnotifier.h @@ -24,7 +24,8 @@ struct SyncthingDev; enum class SyncthingHighLevelNotification { None = 0x0, ConnectedDisconnected = 0x1, - SyncComplete = 0x2, + LocalSyncComplete = 0x2, + RemoteSyncComplete = 0x4, }; /// \cond diff --git a/connector/utils.cpp b/connector/utils.cpp index 7f0eb50..40e6bf5 100644 --- a/connector/utils.cpp +++ b/connector/utils.cpp @@ -72,14 +72,15 @@ QString syncCompleteString(const std::vector &completedDir return QString(); case 1: if (devName.isEmpty()) { - return QCoreApplication::translate("Data::Utils", "Synchronization of %1 complete").arg(completedDirs.front()->displayName()); + return QCoreApplication::translate("Data::Utils", "Synchronization of local directory %1 complete") + .arg(completedDirs.front()->displayName()); } return QCoreApplication::translate("Data::Utils", "Synchronization of %1 on %2 complete").arg(completedDirs.front()->displayName(), devName); default:; } const auto names(things(completedDirs, [](const auto *dir) { return dir->displayName(); })); if (devName.isEmpty()) { - return QCoreApplication::translate("Data::Utils", "Synchronization of the following directories complete:\n") + return QCoreApplication::translate("Data::Utils", "Synchronization of the following local directories complete:\n") + names.join(QStringLiteral(", ")); } return QCoreApplication::translate("Data::Utils", "Synchronization of the following directories on %1 complete:\n").arg(devName) diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index f3d24d9..00f9d55 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -311,14 +311,7 @@ void SyncthingApplet::handleSettingsChanged() const auto &settings(Settings::values()); // apply notifiction settings - auto notifications(SyncthingHighLevelNotification::None); - if (settings.notifyOn.disconnect) { - notifications |= SyncthingHighLevelNotification::ConnectedDisconnected; - } - if (settings.notifyOn.syncComplete) { - notifications |= SyncthingHighLevelNotification::SyncComplete; - } - m_notifier.setEnabledNotifications(notifications); + settings.notifyOn.apply(m_notifier); // apply appearance settings setSize(config.readEntry("size", QSize(25, 25))); diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index 151af78..d5fb51d 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -365,14 +365,7 @@ void TrayWidget::applySettings(const QString &connectionConfig) const bool reconnectRequired = m_connection.applySettings(*m_selectedConnection); // apply notifiction settings - auto notifications(SyncthingHighLevelNotification::None); - if (settings.notifyOn.disconnect) { - notifications |= SyncthingHighLevelNotification::ConnectedDisconnected; - } - if (settings.notifyOn.syncComplete) { - notifications |= SyncthingHighLevelNotification::SyncComplete; - } - m_notifier.setEnabledNotifications(notifications); + settings.notifyOn.apply(m_notifier); #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD // reconnect to apply settings considering systemd diff --git a/widgets/settings/notificationsoptionpage.ui b/widgets/settings/notificationsoptionpage.ui index 0e3bccc..aff1a67 100644 --- a/widgets/settings/notificationsoptionpage.ui +++ b/widgets/settings/notificationsoptionpage.ui @@ -38,9 +38,16 @@ - + - sync complete + sync of local directory complete + + + + + + + sync of remote directory complete diff --git a/widgets/settings/settings.cpp b/widgets/settings/settings.cpp index 8efcba2..ccf0883 100644 --- a/widgets/settings/settings.cpp +++ b/widgets/settings/settings.cpp @@ -1,4 +1,5 @@ #include "./settings.h" +#include "../../connector/syncthingnotifier.h" #include "../../connector/syncthingprocess.h" // use meta-data of syncthingtray application here @@ -155,7 +156,8 @@ void restore() auto ¬ifyOn = v.notifyOn; notifyOn.disconnect = settings.value(QStringLiteral("notifyOnDisconnect"), notifyOn.disconnect).toBool(); notifyOn.internalErrors = settings.value(QStringLiteral("notifyOnErrors"), notifyOn.internalErrors).toBool(); - notifyOn.syncComplete = settings.value(QStringLiteral("notifyOnSyncComplete"), notifyOn.syncComplete).toBool(); + notifyOn.localSyncComplete = settings.value(QStringLiteral("notifyOnLocalSyncComplete"), notifyOn.localSyncComplete).toBool(); + notifyOn.remoteSyncComplete = settings.value(QStringLiteral("notifyOnRemoteSyncComplete"), notifyOn.remoteSyncComplete).toBool(); notifyOn.syncthingErrors = settings.value(QStringLiteral("showSyncthingNotifications"), notifyOn.syncthingErrors).toBool(); #ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS v.dbusNotifications = settings.value(QStringLiteral("dbusNotifications"), DBusNotification::isAvailable()).toBool(); @@ -239,7 +241,8 @@ void save() const auto ¬ifyOn = v.notifyOn; settings.setValue(QStringLiteral("notifyOnDisconnect"), notifyOn.disconnect); settings.setValue(QStringLiteral("notifyOnErrors"), notifyOn.internalErrors); - settings.setValue(QStringLiteral("notifyOnSyncComplete"), notifyOn.syncComplete); + settings.setValue(QStringLiteral("notifyOnLocalSyncComplete"), notifyOn.localSyncComplete); + settings.setValue(QStringLiteral("notifyOnRemoteSyncComplete"), notifyOn.remoteSyncComplete); settings.setValue(QStringLiteral("showSyncthingNotifications"), notifyOn.syncthingErrors); #ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS settings.setValue(QStringLiteral("dbusNotifications"), v.dbusNotifications); @@ -288,4 +291,23 @@ void save() v.qt.save(settings); } + +/*! + * \brief Applies the notification settings on the specified \a notifier. + */ +void NotifyOn::apply(SyncthingNotifier ¬ifier) const +{ + auto notifications(SyncthingHighLevelNotification::None); + if (disconnect) { + notifications |= SyncthingHighLevelNotification::ConnectedDisconnected; + } + if (localSyncComplete) { + notifications |= SyncthingHighLevelNotification::LocalSyncComplete; + } + if (remoteSyncComplete) { + notifications |= SyncthingHighLevelNotification::RemoteSyncComplete; + } + notifier.setEnabledNotifications(notifications); +} + } // namespace Settings diff --git a/widgets/settings/settings.h b/widgets/settings/settings.h index a4d2990..11ff4d3 100644 --- a/widgets/settings/settings.h +++ b/widgets/settings/settings.h @@ -23,7 +23,8 @@ class QtSettings; namespace Data { class SyncthingProcess; -} +class SyncthingNotifier; +} // namespace Data namespace Settings { @@ -35,8 +36,11 @@ struct SYNCTHINGWIDGETS_EXPORT Connection { struct SYNCTHINGWIDGETS_EXPORT NotifyOn { bool disconnect = true; bool internalErrors = true; - bool syncComplete = false; + bool localSyncComplete = false; + bool remoteSyncComplete = false; bool syncthingErrors = true; + + void apply(Data::SyncthingNotifier ¬ifier) const; }; struct SYNCTHINGWIDGETS_EXPORT Appearance { diff --git a/widgets/settings/settingsdialog.cpp b/widgets/settings/settingsdialog.cpp index f85654c..8189d0b 100644 --- a/widgets/settings/settingsdialog.cpp +++ b/widgets/settings/settingsdialog.cpp @@ -355,7 +355,8 @@ bool NotificationsOptionPage::apply() auto ¬ifyOn = values().notifyOn; notifyOn.disconnect = ui()->notifyOnDisconnectCheckBox->isChecked(); notifyOn.internalErrors = ui()->notifyOnErrorsCheckBox->isChecked(); - notifyOn.syncComplete = ui()->notifyOnSyncCompleteCheckBox->isChecked(); + notifyOn.localSyncComplete = ui()->notifyOnLocalSyncCompleteCheckBox->isChecked(); + notifyOn.remoteSyncComplete = ui()->notifyOnRemoteSyncCompleteCheckBox->isChecked(); notifyOn.syncthingErrors = ui()->showSyncthingNotificationsCheckBox->isChecked(); #ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS if ((values().dbusNotifications = ui()->dbusRadioButton->isChecked()) && !DBusNotification::isAvailable()) { @@ -373,7 +374,8 @@ void NotificationsOptionPage::reset() const auto ¬ifyOn = values().notifyOn; ui()->notifyOnDisconnectCheckBox->setChecked(notifyOn.disconnect); ui()->notifyOnErrorsCheckBox->setChecked(notifyOn.internalErrors); - ui()->notifyOnSyncCompleteCheckBox->setChecked(notifyOn.syncComplete); + ui()->notifyOnLocalSyncCompleteCheckBox->setChecked(notifyOn.localSyncComplete); + ui()->notifyOnRemoteSyncCompleteCheckBox->setChecked(notifyOn.remoteSyncComplete); ui()->showSyncthingNotificationsCheckBox->setChecked(notifyOn.syncthingErrors); #ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS (values().dbusNotifications ? ui()->dbusRadioButton : ui()->qtRadioButton)->setChecked(true);