diff --git a/connector/translations/syncthingconnector_de_DE.ts b/connector/translations/syncthingconnector_de_DE.ts index 957bdc6..c674c9d 100644 --- a/connector/translations/syncthingconnector_de_DE.ts +++ b/connector/translations/syncthingconnector_de_DE.ts @@ -257,6 +257,18 @@ %1 Verz. + + + Synchronization of %1 complete + %1 wurde synchronisiert + + + + Synchronization of the following devices complete: + + Folgende Verzeichnisse wurden synchronisiert: + + SyncthingDev diff --git a/connector/translations/syncthingconnector_en_US.ts b/connector/translations/syncthingconnector_en_US.ts index f6fb4d1..811a8da 100644 --- a/connector/translations/syncthingconnector_en_US.ts +++ b/connector/translations/syncthingconnector_en_US.ts @@ -257,6 +257,17 @@ %1 dirs + + + Synchronization of %1 complete + + + + + Synchronization of the following devices complete: + + + SyncthingDev diff --git a/connector/utils.cpp b/connector/utils.cpp index 9c038ec..a8fe6f7 100644 --- a/connector/utils.cpp +++ b/connector/utils.cpp @@ -61,6 +61,26 @@ QString directoryStatusString(quint64 files, quint64 dirs, quint64 size) % QString::fromUtf8(dataSizeToString(size).data()); } +/*! + * \brief Returns the "sync complete" notication message for the specified directories. + */ +QString syncCompleteString(const std::vector &completedDirs) +{ + switch (completedDirs.size()) { + case 0: + return QString(); + case 1: + return QCoreApplication::translate("Data::Utils", "Synchronization of %1 complete").arg(completedDirs.front()->displayName()); + default:; + } + QStringList names; + names.reserve(static_cast(completedDirs.size())); + for (const auto *dir : completedDirs) { + names << dir->displayName(); + } + return QCoreApplication::translate("Data::Utils", "Synchronization of the following devices complete:\n") + names.join(QStringLiteral(", ")); +} + /*! * \brief Returns whether the host specified by the given \a url is the local machine. */ @@ -174,4 +194,5 @@ bool setDevicesPaused(QJsonObject &syncthingConfig, const QStringList &devIds, b return altered; } + } // namespace Data diff --git a/connector/utils.h b/connector/utils.h index e38fdf4..80093c2 100644 --- a/connector/utils.h +++ b/connector/utils.h @@ -9,6 +9,7 @@ #include #include +#include QT_FORWARD_DECLARE_CLASS(QUrl) QT_FORWARD_DECLARE_CLASS(QJsonObject) @@ -19,9 +20,12 @@ class DateTime; namespace Data { +struct SyncthingDir; + QString LIB_SYNCTHING_CONNECTOR_EXPORT agoString(ChronoUtilities::DateTime dateTime); QString LIB_SYNCTHING_CONNECTOR_EXPORT trafficString(uint64 total, double rate); QString LIB_SYNCTHING_CONNECTOR_EXPORT directoryStatusString(quint64 files, quint64 dirs, quint64 size); +QString LIB_SYNCTHING_CONNECTOR_EXPORT syncCompleteString(const std::vector &completedDirs); bool LIB_SYNCTHING_CONNECTOR_EXPORT isLocal(const QUrl &url); bool LIB_SYNCTHING_CONNECTOR_EXPORT setDirectoriesPaused(QJsonObject &syncthingConfig, const QStringList &dirIds, bool paused); bool LIB_SYNCTHING_CONNECTOR_EXPORT setDevicesPaused(QJsonObject &syncthingConfig, const QStringList &dirs, bool paused); diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index d5ee4a7..d69fefe 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -352,19 +352,8 @@ void SyncthingApplet::handleConnectionStatusChanged(SyncthingStatus status) break; default: if (m_status == SyncthingStatus::Synchronizing && settings.notifyOn.syncComplete) { - const vector &completedDirs = m_connection.completedDirs(); - if (!completedDirs.empty()) { - QString message; - if (completedDirs.size() == 1) { - message = tr("Synchronization of %1 complete").arg(completedDirs.front()->displayName()); - } else { - QStringList names; - names.reserve(static_cast(completedDirs.size())); - for (const SyncthingDir *dir : completedDirs) { - names << dir->displayName(); - } - message = tr("Synchronization of the following devices complete:\n") + names.join(QStringLiteral(", ")); - } + const auto message(syncCompleteString(m_connection.completedDirs())); + if (!message.isEmpty()) { m_dbusNotifier.showSyncComplete(message); } } diff --git a/tray/gui/trayicon.cpp b/tray/gui/trayicon.cpp index fae3be2..553017d 100644 --- a/tray/gui/trayicon.cpp +++ b/tray/gui/trayicon.cpp @@ -245,19 +245,8 @@ void TrayIcon::showStatusNotification(SyncthingStatus status) break; default: if (m_status == SyncthingStatus::Synchronizing && settings.notifyOn.syncComplete) { - const vector &completedDirs = connection.completedDirs(); - if (!completedDirs.empty()) { - QString message; - if (completedDirs.size() == 1) { - message = tr("Synchronization of %1 complete").arg(completedDirs.front()->displayName()); - } else { - QStringList names; - names.reserve(static_cast(completedDirs.size())); - for (const SyncthingDir *dir : completedDirs) { - names << dir->displayName(); - } - message = tr("Synchronization of the following devices complete:\n") + names.join(QStringLiteral(", ")); - } + const auto message(syncCompleteString(connection.completedDirs())); + if (!message.isEmpty()) { #ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS if (settings.dbusNotifications) { m_dbusNotifier.showSyncComplete(message);