2017-04-25 00:50:30 +02:00
|
|
|
#include "./statusinfo.h"
|
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingconnection.h>
|
2022-06-07 10:15:28 +02:00
|
|
|
#include <syncthingconnector/syncthingconnectionsettings.h>
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingdev.h>
|
|
|
|
#include <syncthingconnector/utils.h>
|
|
|
|
#include <syncthingmodel/syncthingicons.h>
|
2017-04-25 00:50:30 +02:00
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QIcon>
|
2018-08-04 15:47:43 +02:00
|
|
|
#include <QStringBuilder>
|
2017-04-25 00:50:30 +02:00
|
|
|
|
|
|
|
using namespace Data;
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
StatusInfo::StatusInfo()
|
2022-07-26 23:57:02 +02:00
|
|
|
: m_statusText(QCoreApplication::translate("QtGui::StatusInfo", "Initializing …"))
|
2019-07-31 20:16:43 +02:00
|
|
|
, m_statusIcon(&trayIcons().disconnected)
|
2017-05-01 03:34:43 +02:00
|
|
|
{
|
|
|
|
}
|
2017-04-25 00:50:30 +02:00
|
|
|
|
2018-07-30 21:37:26 +02:00
|
|
|
void StatusInfo::recomputeAdditionalStatusText()
|
|
|
|
{
|
|
|
|
if (m_additionalStatusInfo.isEmpty()) {
|
|
|
|
m_additionalStatusText = m_additionalDeviceInfo;
|
|
|
|
} else if (m_additionalDeviceInfo.isEmpty()) {
|
|
|
|
m_additionalStatusText = m_additionalStatusInfo;
|
|
|
|
} else if (m_additionalStatusInfo.isEmpty() && m_additionalDeviceInfo.isEmpty()) {
|
|
|
|
m_additionalStatusText.clear();
|
|
|
|
} else {
|
|
|
|
m_additionalStatusText = m_additionalStatusInfo % QChar('\n') % m_additionalDeviceInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 18:33:10 +02:00
|
|
|
void StatusInfo::updateConnectionStatus(const SyncthingConnection &connection, const QString &configurationName)
|
2017-04-25 00:50:30 +02:00
|
|
|
{
|
2018-09-05 17:14:14 +02:00
|
|
|
m_additionalStatusInfo.clear();
|
2018-07-30 21:37:26 +02:00
|
|
|
|
2019-07-31 20:16:43 +02:00
|
|
|
const auto &icons = trayIcons();
|
2017-05-01 03:34:43 +02:00
|
|
|
switch (connection.status()) {
|
2017-04-25 00:50:30 +02:00
|
|
|
case SyncthingStatus::Disconnected:
|
2022-07-26 23:52:26 +02:00
|
|
|
if (connection.isConnecting()) {
|
2022-07-26 23:57:02 +02:00
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Connecting to Syncthing …");
|
2017-04-25 00:50:30 +02:00
|
|
|
} else {
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Not connected to Syncthing");
|
2022-07-26 23:52:26 +02:00
|
|
|
if (connection.autoReconnectInterval() > 0) {
|
|
|
|
m_additionalStatusInfo
|
|
|
|
= QCoreApplication::translate("QtGui::StatusInfo", "Trying to reconnect every %1 ms").arg(connection.autoReconnectInterval());
|
|
|
|
}
|
2017-04-25 00:50:30 +02:00
|
|
|
}
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.disconnected;
|
2017-04-25 00:50:30 +02:00
|
|
|
break;
|
|
|
|
case SyncthingStatus::Reconnecting:
|
2022-07-26 23:57:02 +02:00
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Reconnecting …");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.disconnected;
|
2017-04-25 00:50:30 +02:00
|
|
|
break;
|
|
|
|
default:
|
2022-06-07 10:15:28 +02:00
|
|
|
if (connection.hasOutOfSyncDirs() && (connection.statusComputionFlags() & SyncthingStatusComputionFlags::OutOfSync)) {
|
2017-05-01 03:34:43 +02:00
|
|
|
switch (connection.status()) {
|
2017-04-25 00:50:30 +02:00
|
|
|
case SyncthingStatus::Synchronizing:
|
2018-08-04 15:47:43 +02:00
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Synchronization is ongoing");
|
2018-07-30 21:37:26 +02:00
|
|
|
m_additionalStatusInfo = QCoreApplication::translate("QtGui::StatusInfo", "At least one directory is out of sync");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.errorSync;
|
2017-04-25 00:50:30 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "At least one directory is out of sync");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.error;
|
2017-04-25 00:50:30 +02:00
|
|
|
}
|
2022-06-07 10:15:28 +02:00
|
|
|
} else if (connection.hasUnreadNotifications() && (connection.statusComputionFlags() & SyncthingStatusComputionFlags::UnreadNotifications)) {
|
2017-04-25 00:50:30 +02:00
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Notifications available");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.notify;
|
2017-04-25 00:50:30 +02:00
|
|
|
} else {
|
2017-05-01 03:34:43 +02:00
|
|
|
switch (connection.status()) {
|
2017-04-25 00:50:30 +02:00
|
|
|
case SyncthingStatus::Idle:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Syncthing is idling");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.idling;
|
2017-04-25 00:50:30 +02:00
|
|
|
break;
|
|
|
|
case SyncthingStatus::Scanning:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Syncthing is scanning");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.scanninig;
|
2017-04-25 00:50:30 +02:00
|
|
|
break;
|
|
|
|
case SyncthingStatus::Paused:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "At least one device is paused");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.pause;
|
2017-04-25 00:50:30 +02:00
|
|
|
break;
|
|
|
|
case SyncthingStatus::Synchronizing:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Synchronization is ongoing");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.sync;
|
2017-04-25 00:50:30 +02:00
|
|
|
break;
|
2020-12-31 02:48:18 +01:00
|
|
|
case SyncthingStatus::RemoteNotInSync:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "At least one remote directory is not in sync");
|
|
|
|
m_statusIcon = &icons.sync;
|
|
|
|
break;
|
2017-04-25 00:50:30 +02:00
|
|
|
default:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Status is unknown");
|
2019-07-31 20:16:43 +02:00
|
|
|
m_statusIcon = &icons.disconnected;
|
2017-04-25 00:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 21:37:26 +02:00
|
|
|
|
2020-10-19 18:33:10 +02:00
|
|
|
if (!configurationName.isEmpty()) {
|
|
|
|
m_statusText = configurationName % QChar(':') % QChar(' ') % m_statusText;
|
|
|
|
}
|
|
|
|
|
2018-07-30 21:37:26 +02:00
|
|
|
recomputeAdditionalStatusText();
|
2017-10-05 00:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatusInfo::updateConnectedDevices(const SyncthingConnection &connection)
|
|
|
|
{
|
2018-07-30 21:37:26 +02:00
|
|
|
m_additionalDeviceInfo.clear();
|
2018-06-27 17:38:22 +02:00
|
|
|
|
2020-12-31 02:15:12 +01:00
|
|
|
if (connection.isConnected()) {
|
2018-06-27 17:38:22 +02:00
|
|
|
// find devices we're currently connected to
|
|
|
|
const auto connectedDevices(connection.connectedDevices());
|
|
|
|
|
|
|
|
// handle case when not connected to other devices
|
|
|
|
if (connectedDevices.empty()) {
|
2018-07-30 21:37:26 +02:00
|
|
|
m_additionalDeviceInfo = QCoreApplication::translate("QtGui::StatusInfo", "Not connected to other devices");
|
2018-06-27 17:38:22 +02:00
|
|
|
return;
|
2017-05-30 15:06:34 +02:00
|
|
|
}
|
2018-06-27 17:38:22 +02:00
|
|
|
|
|
|
|
// get up to 2 device names
|
|
|
|
const auto deviceCount = trQuandity(connectedDevices.size());
|
|
|
|
const auto deviceNames = [&] {
|
2021-03-20 22:39:40 +01:00
|
|
|
QStringList names;
|
|
|
|
names.reserve(2);
|
2018-06-27 17:38:22 +02:00
|
|
|
for (const auto *dev : connectedDevices) {
|
|
|
|
if (dev->name.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-20 22:39:40 +01:00
|
|
|
names << dev->name;
|
|
|
|
if (names.size() > 2) {
|
2018-06-27 17:38:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-20 22:39:40 +01:00
|
|
|
return names;
|
2018-06-27 17:38:22 +02:00
|
|
|
}();
|
|
|
|
|
|
|
|
// update status text
|
|
|
|
if (deviceNames.empty()) {
|
2018-07-30 21:37:26 +02:00
|
|
|
m_additionalDeviceInfo
|
2018-11-13 18:00:30 +01:00
|
|
|
= QCoreApplication::translate("QtGui::StatusInfo", "Connected to %1 devices", nullptr, deviceCount).arg(deviceCount);
|
2018-06-27 17:38:22 +02:00
|
|
|
} else if (deviceNames.size() < deviceCount) {
|
2021-11-04 00:16:27 +01:00
|
|
|
m_additionalDeviceInfo = QCoreApplication::translate(
|
|
|
|
"QtGui::StatusInfo", "Connected to %1 and %2 other devices", nullptr, deviceCount - static_cast<int>(deviceNames.size()))
|
|
|
|
.arg(deviceNames.join(QStringLiteral(", ")))
|
|
|
|
.arg(deviceCount - deviceNames.size());
|
2018-06-27 17:38:22 +02:00
|
|
|
} else if (deviceNames.size() == 2) {
|
2018-11-13 18:00:30 +01:00
|
|
|
m_additionalDeviceInfo = QCoreApplication::translate("QtGui::StatusInfo", "Connected to %1 and %2", nullptr, deviceCount)
|
2018-06-27 17:38:22 +02:00
|
|
|
.arg(deviceNames[0], deviceNames[1]);
|
|
|
|
} else if (deviceNames.size() == 1) {
|
2018-11-13 18:00:30 +01:00
|
|
|
m_additionalDeviceInfo = QCoreApplication::translate("QtGui::StatusInfo", "Connected to %1", nullptr, deviceCount).arg(deviceNames[0]);
|
2018-06-27 17:38:22 +02:00
|
|
|
}
|
2017-05-30 15:06:34 +02:00
|
|
|
}
|
2018-07-30 21:37:26 +02:00
|
|
|
|
|
|
|
recomputeAdditionalStatusText();
|
2017-04-25 00:50:30 +02:00
|
|
|
}
|
2018-07-30 21:37:26 +02:00
|
|
|
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|