2017-04-25 00:50:30 +02:00
|
|
|
#include "./statusinfo.h"
|
|
|
|
|
|
|
|
#include "../../connector/syncthingconnection.h"
|
2017-05-30 15:06:34 +02:00
|
|
|
#include "../../connector/syncthingdev.h"
|
2017-10-05 00:08:46 +02:00
|
|
|
#include "../../connector/utils.h"
|
2017-04-25 00:50:30 +02:00
|
|
|
#include "../../model/syncthingicons.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QIcon>
|
2017-04-25 00:50:30 +02:00
|
|
|
|
|
|
|
using namespace Data;
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
StatusInfo::StatusInfo()
|
|
|
|
: m_statusText(QCoreApplication::translate("QtGui::StatusInfo", "Initializing ..."))
|
|
|
|
, m_statusIcon(&statusIcons().disconnected)
|
|
|
|
{
|
|
|
|
}
|
2017-04-25 00:50:30 +02:00
|
|
|
|
2017-10-05 00:08:46 +02:00
|
|
|
void StatusInfo::updateConnectionStatus(const SyncthingConnection &connection)
|
2017-04-25 00:50:30 +02:00
|
|
|
{
|
2017-05-01 03:34:43 +02:00
|
|
|
switch (connection.status()) {
|
2017-04-25 00:50:30 +02:00
|
|
|
case SyncthingStatus::Disconnected:
|
2017-05-01 03:34:43 +02:00
|
|
|
if (connection.autoReconnectInterval() > 0) {
|
2017-04-25 00:50:30 +02:00
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Not connected to Syncthing - trying to reconnect every %1 ms")
|
2017-05-01 03:34:43 +02:00
|
|
|
.arg(connection.autoReconnectInterval());
|
2017-04-25 00:50:30 +02:00
|
|
|
} else {
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Not connected to Syncthing");
|
|
|
|
}
|
|
|
|
m_statusIcon = &statusIcons().disconnected;
|
|
|
|
break;
|
|
|
|
case SyncthingStatus::Reconnecting:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Reconnecting ...");
|
|
|
|
m_statusIcon = &statusIcons().disconnected;
|
|
|
|
break;
|
|
|
|
default:
|
2017-05-01 03:34:43 +02:00
|
|
|
if (connection.hasOutOfSyncDirs()) {
|
|
|
|
switch (connection.status()) {
|
2017-04-25 00:50:30 +02:00
|
|
|
case SyncthingStatus::Synchronizing:
|
2017-05-01 03:34:43 +02:00
|
|
|
m_statusText
|
|
|
|
= QCoreApplication::translate("QtGui::StatusInfo", "Synchronization is ongoing but at least one directory is out of sync");
|
2017-04-25 00:50:30 +02:00
|
|
|
m_statusIcon = &statusIcons().errorSync;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "At least one directory is out of sync");
|
|
|
|
m_statusIcon = &statusIcons().error;
|
|
|
|
}
|
2017-05-01 03:34:43 +02:00
|
|
|
} else if (connection.hasUnreadNotifications()) {
|
2017-04-25 00:50:30 +02:00
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Notifications available");
|
|
|
|
m_statusIcon = &statusIcons().notify;
|
|
|
|
} 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");
|
|
|
|
m_statusIcon = &statusIcons().idling;
|
|
|
|
break;
|
|
|
|
case SyncthingStatus::Scanning:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Syncthing is scanning");
|
|
|
|
m_statusIcon = &statusIcons().scanninig;
|
|
|
|
break;
|
|
|
|
case SyncthingStatus::Paused:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "At least one device is paused");
|
|
|
|
m_statusIcon = &statusIcons().pause;
|
|
|
|
break;
|
|
|
|
case SyncthingStatus::Synchronizing:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Synchronization is ongoing");
|
|
|
|
m_statusIcon = &statusIcons().sync;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_statusText = QCoreApplication::translate("QtGui::StatusInfo", "Status is unknown");
|
|
|
|
m_statusIcon = &statusIcons().disconnected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 00:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatusInfo::updateConnectedDevices(const SyncthingConnection &connection)
|
|
|
|
{
|
2017-05-30 15:06:34 +02:00
|
|
|
switch (connection.status()) {
|
|
|
|
case SyncthingStatus::Idle:
|
|
|
|
case SyncthingStatus::OutOfSync:
|
|
|
|
case SyncthingStatus::Scanning:
|
|
|
|
case SyncthingStatus::Synchronizing:
|
2017-10-05 00:08:46 +02:00
|
|
|
if (const size_t connectedDevices = connection.connectedDevices()) {
|
2017-05-30 15:06:34 +02:00
|
|
|
m_additionalStatusText
|
2017-10-05 00:08:46 +02:00
|
|
|
= QCoreApplication::translate("QtGui::StatusInfo", "Conntected to %1 devices", nullptr, trQuandity(connectedDevices))
|
|
|
|
.arg(connectedDevices);
|
2017-05-30 15:06:34 +02:00
|
|
|
} else {
|
|
|
|
m_additionalStatusText = QCoreApplication::translate("QtGui::StatusInfo", "Not connected to other devices");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_additionalStatusText.clear();
|
|
|
|
}
|
2017-04-25 00:50:30 +02:00
|
|
|
}
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|