From db4b0321791264f82f292a906ba119b8abd479c3 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 27 Jun 2018 17:38:22 +0200 Subject: [PATCH] Show connected device names in additional status --- connector/syncthingconnection.cpp | 7 ++- connector/syncthingconnection.h | 4 +- .../translations/syncthingconnector_de_DE.ts | 62 +++++++++---------- .../translations/syncthingconnector_en_US.ts | 62 +++++++++---------- .../translations/syncthingplasmoid_de_DE.ts | 6 +- .../translations/syncthingplasmoid_en_US.ts | 6 +- tray/translations/syncthingtray_de_DE.ts | 30 ++++----- tray/translations/syncthingtray_en_US.ts | 30 ++++----- widgets/misc/statusinfo.cpp | 54 +++++++++++++--- .../translations/syncthingwidgets_de_DE.ts | 28 ++++++++- .../translations/syncthingwidgets_en_US.ts | 28 ++++++++- 11 files changed, 201 insertions(+), 116 deletions(-) diff --git a/connector/syncthingconnection.cpp b/connector/syncthingconnection.cpp index 136b913..6099ca3 100644 --- a/connector/syncthingconnection.cpp +++ b/connector/syncthingconnection.cpp @@ -661,12 +661,13 @@ QString SyncthingConnection::deviceNameOrId(const QString &deviceId) const * \brief Returns the number of devices Syncthing is currently connected to. * \remarks Computed by looping devInfo(). */ -std::size_t SyncthingConnection::connectedDevices() const +std::vector SyncthingConnection::connectedDevices() const { - size_t connectedDevs = 0; + std::vector connectedDevs; + connectedDevs.reserve(devInfo().size()); for (const SyncthingDev &dev : devInfo()) { if (dev.isConnected()) { - ++connectedDevs; + connectedDevs.emplace_back(&dev); } } return connectedDevs; diff --git a/connector/syncthingconnection.h b/connector/syncthingconnection.h index 8191118..bee49af 100644 --- a/connector/syncthingconnection.h +++ b/connector/syncthingconnection.h @@ -83,7 +83,7 @@ class LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnection : public QObject { Q_PROPERTY(double totalIncomingRate READ totalIncomingRate NOTIFY trafficChanged) Q_PROPERTY(double totalOutgoingRate READ totalOutgoingRate NOTIFY trafficChanged) Q_PROPERTY(QList expectedSslErrors READ expectedSslErrors) - Q_PROPERTY(std::size_t connectedDevices READ connectedDevices) + Q_PROPERTY(std::vector connectedDevices READ connectedDevices) Q_PROPERTY(QStringList directoryIds READ directoryIds) Q_PROPERTY(QStringList deviceIds READ deviceIds) Q_PROPERTY(QJsonObject rawConfig READ rawConfig NOTIFY newConfig) @@ -136,7 +136,7 @@ public: QStringList directoryIds() const; QStringList deviceIds() const; QString deviceNameOrId(const QString &deviceId) const; - std::size_t connectedDevices() const; + std::vector connectedDevices() const; const QJsonObject &rawConfig() const; public Q_SLOTS: diff --git a/connector/translations/syncthingconnector_de_DE.ts b/connector/translations/syncthingconnector_de_DE.ts index 121981d..c937bcd 100644 --- a/connector/translations/syncthingconnector_de_DE.ts +++ b/connector/translations/syncthingconnector_de_DE.ts @@ -65,153 +65,153 @@ Fehler beim Anfordern Gerät zu Pausieren/Fortzusetzen - + Unable to request QR-Code: Fehler beim Abfragen des QR-Codes: - + Unable to parse Syncthing log: Fehler beim Auslesen des Syncthing-Logs: - + Unable to request Syncthing log: Fehler beim Abfragen des Syncthing-Logs: - + Unable to locate certificate used by Syncthing. Das SSL-Zertifikat von Syncthing kann nicht gefunden werden. - + Unable to load certificate used by Syncthing. Das SSL-Zertifikat von Syncthing kann nicht ausgelesen werden. - + Unable to parse Syncthing config: Fehler beim Auslesen der Syncthing-Konfiguration: - + Unable to request Syncthing config: Fehler beim Abfragen der Syncthing-Konfiguration: - + Unable to parse Syncthing status: Fehler beim Auslesen des Syncthing-Status: - + Unable to request Syncthing status: Fehler beim Abfragen des Syncthing-Status: - + Unable to parse connections: Fehler beim Auslesen der Verbindungen: - + Unable to request connections: Fehler beim Abfragen der Verbindungen: - + Unable to parse directory statistics: Fehler beim Auslesen der Verzeichnisstatistiken: - - + + Unable to request directory statistics: Fehler beim Abfragen der Verzeichnisstatistiken: - + Unable to parse device statistics: Fehler beim Auslesen der Gerätestatistiken: - + Unable to request device statistics: Fehler beim Abfragen der Gerätestatistiken: - + Unable to parse errors: Fehler beim Auslesen der Syncthing-Fehlermeldungen: - + Unable to request errors: Fehler beim Abfragen der Syncthing-Fehlermeldungen: - + Unable to request clearing errors: Fehler beim Löschen der Fehlermeldungen: - + Unable to parse Syncthing events: Fehler beim Auslesen der Syncthing-Ereignisse: - + Unable to request Syncthing events: Fehler beim Abfragen der Syncthing-Ereignisse: - + Unable to post config: Fehler beim Senden der neuen Konfiguration: - + Unable to request rescan: Fehler beim Anfordern eines Verzeichnis-Rescans: - + Unable to request device pause/resume: Fehler beim Anfordern Gerät zu Pausieren/Fortzusetzen: - + Unable to request directory pause/resume: Fehler beim Anfordern Verzeichnis zu Pausieren/Fortzusetzen: - + Unable to request restart: Fehler beim Anfordern eines Neustarts: - + Unable to request shutdown: Fehler beim Anfordern Syncthing zu beenden: - + Unable to parse status for directory %1: Fehler beim Auslesen des Status von Verzeichnis %1: - + Unable to parse completion for device/directory %1/%2: Fehler beim Auslesen des Fortschrittes von Verzeichnis %1/%2: - + Unable to request completion for device/directory %1/%2: Fehler beim Anfordern des Fortschrittes von Verzeichnis %1/%2: - + at offset %1 bei Zeichen %1 diff --git a/connector/translations/syncthingconnector_en_US.ts b/connector/translations/syncthingconnector_en_US.ts index bd7846d..cf3336b 100644 --- a/connector/translations/syncthingconnector_en_US.ts +++ b/connector/translations/syncthingconnector_en_US.ts @@ -65,153 +65,153 @@ - + Unable to request QR-Code: - + Unable to parse Syncthing log: - + Unable to request Syncthing log: - + Unable to locate certificate used by Syncthing. - + Unable to load certificate used by Syncthing. - + Unable to parse Syncthing config: - + Unable to request Syncthing config: - + Unable to parse Syncthing status: - + Unable to request Syncthing status: - + Unable to parse connections: - + Unable to request connections: - + Unable to parse directory statistics: - - + + Unable to request directory statistics: - + Unable to parse device statistics: - + Unable to request device statistics: - + Unable to parse errors: - + Unable to request errors: - + Unable to request clearing errors: - + Unable to parse Syncthing events: - + Unable to request Syncthing events: - + Unable to post config: - + Unable to request rescan: - + Unable to request device pause/resume: - + Unable to request directory pause/resume: - + Unable to request restart: - + Unable to request shutdown: - + Unable to parse status for directory %1: - + Unable to parse completion for device/directory %1/%2: - + Unable to request completion for device/directory %1/%2: - + at offset %1 diff --git a/plasmoid/translations/syncthingplasmoid_de_DE.ts b/plasmoid/translations/syncthingplasmoid_de_DE.ts index b287cf0..e5f2c30 100644 --- a/plasmoid/translations/syncthingplasmoid_de_DE.ts +++ b/plasmoid/translations/syncthingplasmoid_de_DE.ts @@ -212,17 +212,17 @@ Plasmoid::SyncthingApplet - + About Über Syncthing Plasmoid - + New notifications Neue Benachrichtigungen - + D-Bus error - unable to diff --git a/plasmoid/translations/syncthingplasmoid_en_US.ts b/plasmoid/translations/syncthingplasmoid_en_US.ts index 4540b4a..129b25a 100644 --- a/plasmoid/translations/syncthingplasmoid_en_US.ts +++ b/plasmoid/translations/syncthingplasmoid_en_US.ts @@ -212,17 +212,17 @@ Plasmoid::SyncthingApplet - + About - + New notifications - + D-Bus error - unable to diff --git a/tray/translations/syncthingtray_de_DE.ts b/tray/translations/syncthingtray_de_DE.ts index 95add02..2771510 100644 --- a/tray/translations/syncthingtray_de_DE.ts +++ b/tray/translations/syncthingtray_de_DE.ts @@ -83,27 +83,27 @@ Beenden - + Error Fehler - + Syncthing notification - click to dismiss Neue Syncthing-Benachrichtigung - + Syncthing device wants to connect - click for web UI Neues Gerät möchte verbinden - + New Syncthing directory - click for web UI Neues Syncthing-Verzeichnis - + Disconnected from Syncthing Verbindung zu Syncthing getrennt @@ -193,7 +193,7 @@ For <i>all</i> notifications, checkout the log - + New notifications Neue Benachrichtigungen @@ -224,27 +224,27 @@ For <i>all</i> notifications, checkout the log Ignorieren - + View own device ID Eigene Geräte-ID anzeigen - + Restart Syncthing Syncthing neustarten - + Show Syncthing log Syncthing-Log zeigen - + Rescan all directories Alle Verzeichnisse neu scannen - + Connection Verbindung @@ -307,22 +307,22 @@ For <i>all</i> notifications, checkout the log Fehler beim - + You must configure how to connect to Syncthing when using Syncthing Tray the first time. Vor der ersten Verwendung muss eingestellt werden, wie sich das Syncthing Tray mit Syncthing verbinden soll. - + Note that the settings dialog allows importing URL, credentials and API-key from the local Syncthing configuration. Der Einstellungsdialog ermöglicht es die URL, Zugangsdaten und den API-Key automatisch aus der lokalen Syncthing-Konfiguration auszulesen. - + The system tray is (currently) not available. You could open the tray menu as a regular window using the -w flag, though. Das System-Tray bzw. der Infobereich ist aktuell nicht verfügbar. Es wäre möglich, Syncthing Tray als normales Fenster zu starten (mit Option -w). - + The Qt libraries have not been built with tray icon support. You could open the tray menu as a regular window using the -w flag, though. Die verwendete Qt-Bibliothek wurde nicht mit Unterstützung für System-Tray konfiguriert. Es wäre möglich, Syncthing Tray als normales Fenster zu starten (mit Option -w). diff --git a/tray/translations/syncthingtray_en_US.ts b/tray/translations/syncthingtray_en_US.ts index f8d023b..71c89ac 100644 --- a/tray/translations/syncthingtray_en_US.ts +++ b/tray/translations/syncthingtray_en_US.ts @@ -88,27 +88,27 @@ - + Error - + Syncthing notification - click to dismiss - + Syncthing device wants to connect - click for web UI - + New Syncthing directory - click for web UI - + Disconnected from Syncthing @@ -192,7 +192,7 @@ For <i>all</i> notifications, checkout the log - + New notifications @@ -223,27 +223,27 @@ For <i>all</i> notifications, checkout the log - + View own device ID - + Restart Syncthing - + Show Syncthing log - + Rescan all directories - + Connection @@ -306,22 +306,22 @@ For <i>all</i> notifications, checkout the log - + You must configure how to connect to Syncthing when using Syncthing Tray the first time. - + Note that the settings dialog allows importing URL, credentials and API-key from the local Syncthing configuration. - + The system tray is (currently) not available. You could open the tray menu as a regular window using the -w flag, though. - + The Qt libraries have not been built with tray icon support. You could open the tray menu as a regular window using the -w flag, though. diff --git a/widgets/misc/statusinfo.cpp b/widgets/misc/statusinfo.cpp index c61b648..edb0b13 100644 --- a/widgets/misc/statusinfo.cpp +++ b/widgets/misc/statusinfo.cpp @@ -77,21 +77,57 @@ void StatusInfo::updateConnectionStatus(const SyncthingConnection &connection) void StatusInfo::updateConnectedDevices(const SyncthingConnection &connection) { + m_additionalStatusText.clear(); + switch (connection.status()) { case SyncthingStatus::Idle: case SyncthingStatus::OutOfSync: case SyncthingStatus::Scanning: - case SyncthingStatus::Synchronizing: - if (const size_t connectedDevices = connection.connectedDevices()) { - m_additionalStatusText - = QCoreApplication::translate("QtGui::StatusInfo", "Conntected to %1 devices", nullptr, trQuandity(connectedDevices)) - .arg(connectedDevices); - } else { + case SyncthingStatus::Synchronizing: { + // find devices we're currently connected to + const auto connectedDevices(connection.connectedDevices()); + + // handle case when not connected to other devices + if (connectedDevices.empty()) { m_additionalStatusText = QCoreApplication::translate("QtGui::StatusInfo", "Not connected to other devices"); + return; } - break; - default: - m_additionalStatusText.clear(); + + // get up to 2 device names + const auto deviceCount = trQuandity(connectedDevices.size()); + const auto deviceNames = [&] { + QStringList deviceNames; + deviceNames.reserve(2); + for (const auto *dev : connectedDevices) { + if (dev->name.isEmpty()) { + continue; + } + deviceNames << dev->name; + if (deviceNames.size() > 2) { + break; + } + } + return deviceNames; + }(); + + // update status text + if (deviceNames.empty()) { + m_additionalStatusText + = QCoreApplication::translate("QtGui::StatusInfo", "Conntected to %1 devices", nullptr, deviceCount).arg(deviceCount); + } else if (deviceNames.size() < deviceCount) { + m_additionalStatusText + = QCoreApplication::translate("QtGui::StatusInfo", "Conntected to %1 and %2 other devices", nullptr, deviceCount - deviceNames.size()) + .arg(deviceNames.join(QStringLiteral(", "))) + .arg(deviceCount - deviceNames.size()); + } else if (deviceNames.size() == 2) { + m_additionalStatusText = QCoreApplication::translate("QtGui::StatusInfo", "Conntected to %1 and %2", nullptr, deviceCount) + .arg(deviceNames[0], deviceNames[1]); + } else if (deviceNames.size() == 1) { + m_additionalStatusText = QCoreApplication::translate("QtGui::StatusInfo", "Conntected to %1", nullptr, deviceCount).arg(deviceNames[0]); + } + return; + } + default:; } } } // namespace QtGui diff --git a/widgets/translations/syncthingwidgets_de_DE.ts b/widgets/translations/syncthingwidgets_de_DE.ts index 5255755..03fc6e3 100644 --- a/widgets/translations/syncthingwidgets_de_DE.ts +++ b/widgets/translations/syncthingwidgets_de_DE.ts @@ -674,15 +674,39 @@ Status ist unbekannt - + Conntected to %1 devices Mit %1 Gerät verbunden Mit %1 Geräten verbunden + + + Conntected to %1 and %2 other devices + + Mit %1 und einem weiteren Gerät verbunden + Mit %1 und %2 weiteren Geräten verbunden + + + + + Conntected to %1 and %2 + + Mit %1 und %2 verbunden + + + + + + Conntected to %1 + + Mit %1 verbunden + + + - + Not connected to other devices Nicht mit anderen Geräten verbunden diff --git a/widgets/translations/syncthingwidgets_en_US.ts b/widgets/translations/syncthingwidgets_en_US.ts index 3fded83..1d33d39 100644 --- a/widgets/translations/syncthingwidgets_en_US.ts +++ b/widgets/translations/syncthingwidgets_en_US.ts @@ -672,15 +672,39 @@ - + Conntected to %1 devices + + Conntected to %1 device + Conntected to %1 devices + + + + + Conntected to %1 and %2 other devices + + Conntected to %1 and %2 other device + Conntected to %1 and %2 other devices + + + + + Conntected to %1 and %2 + + + + + + + + Conntected to %1 - + Not connected to other devices