Refactor composing "sync complete string"
to prevent code duplication between regular tray icon and plasmoid.
This commit is contained in:
parent
841b250680
commit
404f517b4c
|
@ -257,6 +257,18 @@
|
|||
<numerusform>%1 Verz.</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../utils.cpp" line="73"/>
|
||||
<source>Synchronization of %1 complete</source>
|
||||
<translation>%1 wurde synchronisiert</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../utils.cpp" line="81"/>
|
||||
<source>Synchronization of the following devices complete:
|
||||
</source>
|
||||
<translation>Folgende Verzeichnisse wurden synchronisiert:
|
||||
</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SyncthingDev</name>
|
||||
|
|
|
@ -257,6 +257,17 @@
|
|||
<numerusform>%1 dirs</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../utils.cpp" line="73"/>
|
||||
<source>Synchronization of %1 complete</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../utils.cpp" line="81"/>
|
||||
<source>Synchronization of the following devices complete:
|
||||
</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SyncthingDev</name>
|
||||
|
|
|
@ -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<SyncthingDir *> &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<int>(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
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QStringList>
|
||||
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
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<SyncthingDir *> &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);
|
||||
|
|
|
@ -352,19 +352,8 @@ void SyncthingApplet::handleConnectionStatusChanged(SyncthingStatus status)
|
|||
break;
|
||||
default:
|
||||
if (m_status == SyncthingStatus::Synchronizing && settings.notifyOn.syncComplete) {
|
||||
const vector<SyncthingDir *> &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<int>(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,19 +245,8 @@ void TrayIcon::showStatusNotification(SyncthingStatus status)
|
|||
break;
|
||||
default:
|
||||
if (m_status == SyncthingStatus::Synchronizing && settings.notifyOn.syncComplete) {
|
||||
const vector<SyncthingDir *> &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<int>(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);
|
||||
|
|
Loading…
Reference in New Issue