2016-08-25 00:45:32 +02:00
|
|
|
#include "./syncthingdevicemodel.h"
|
2016-11-08 19:42:50 +01:00
|
|
|
#include "./colors.h"
|
2017-05-01 03:34:43 +02:00
|
|
|
#include "./syncthingicons.h"
|
2016-09-30 23:55:25 +02:00
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingconnection.h>
|
|
|
|
#include <syncthingconnector/utils.h>
|
2016-09-01 16:34:30 +02:00
|
|
|
|
2018-08-04 20:34:24 +02:00
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
|
|
|
|
2019-04-10 18:25:41 +02:00
|
|
|
#include <QStringBuilder>
|
|
|
|
|
2017-09-17 21:48:41 +02:00
|
|
|
using namespace std;
|
2019-06-10 22:48:26 +02:00
|
|
|
using namespace CppUtilities;
|
2016-08-25 00:45:32 +02:00
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
SyncthingDeviceModel::SyncthingDeviceModel(SyncthingConnection &connection, QObject *parent)
|
|
|
|
: SyncthingModel(connection, parent)
|
|
|
|
, m_devs(connection.devInfo())
|
2016-08-25 00:45:32 +02:00
|
|
|
{
|
2016-08-26 16:43:53 +02:00
|
|
|
connect(&m_connection, &SyncthingConnection::devStatusChanged, this, &SyncthingDeviceModel::devStatusChanged);
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 23:55:05 +02:00
|
|
|
QHash<int, QByteArray> SyncthingDeviceModel::roleNames() const
|
|
|
|
{
|
2018-11-03 21:47:30 +01:00
|
|
|
const static QHash<int, QByteArray> roles{
|
|
|
|
{ Qt::DisplayRole, "name" },
|
|
|
|
{ DeviceStatus, "status" },
|
|
|
|
{ Qt::DecorationRole, "statusIcon" },
|
|
|
|
{ DevicePaused, "paused" },
|
2023-09-16 23:09:10 +02:00
|
|
|
{ IsThisDevice, "isThisDevice" },
|
2023-09-16 23:07:00 +02:00
|
|
|
{ IsPinned, "isPinned" },
|
2018-11-03 21:47:30 +01:00
|
|
|
{ DeviceStatusString, "statusString" },
|
|
|
|
{ DeviceStatusColor, "statusColor" },
|
|
|
|
{ DeviceId, "devId" },
|
|
|
|
{ DeviceDetail, "detail" },
|
2019-02-27 20:41:50 +01:00
|
|
|
{ DeviceDetailIcon, "detailIcon" },
|
2018-11-03 21:47:30 +01:00
|
|
|
};
|
2017-08-29 23:55:05 +02:00
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
2017-09-11 23:44:19 +02:00
|
|
|
const QVector<int> &SyncthingDeviceModel::colorRoles() const
|
|
|
|
{
|
2019-02-27 20:41:50 +01:00
|
|
|
static const QVector<int> colorRoles({ Qt::DecorationRole, Qt::ForegroundRole, DeviceStatusColor, DeviceDetailIcon });
|
2017-09-11 23:44:19 +02:00
|
|
|
return colorRoles;
|
|
|
|
}
|
|
|
|
|
2016-08-25 00:45:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief Returns the device info for the spcified \a index. The returned object is not persistent.
|
|
|
|
*/
|
|
|
|
const SyncthingDev *SyncthingDeviceModel::devInfo(const QModelIndex &index) const
|
|
|
|
{
|
2017-05-01 03:34:43 +02:00
|
|
|
return (index.parent().isValid() ? devInfo(index.parent())
|
|
|
|
: (static_cast<size_t>(index.row()) < m_devs.size() ? &m_devs[static_cast<size_t>(index.row())] : nullptr));
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex SyncthingDeviceModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
2017-05-01 03:34:43 +02:00
|
|
|
if (!parent.isValid()) {
|
2016-08-25 00:45:32 +02:00
|
|
|
// top-level: all dev IDs
|
2017-05-01 03:34:43 +02:00
|
|
|
if (row < rowCount(parent)) {
|
2016-09-06 22:55:49 +02:00
|
|
|
return createIndex(row, column, static_cast<quintptr>(-1));
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2017-05-01 03:34:43 +02:00
|
|
|
} else if (!parent.parent().isValid()) {
|
2016-08-25 00:45:32 +02:00
|
|
|
// dev-level: dev attributes
|
2017-05-01 03:34:43 +02:00
|
|
|
if (row < rowCount(parent)) {
|
2016-09-06 22:55:49 +02:00
|
|
|
return createIndex(row, column, static_cast<quintptr>(parent.row()));
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex SyncthingDeviceModel::parent(const QModelIndex &child) const
|
|
|
|
{
|
2016-09-06 22:55:49 +02:00
|
|
|
return child.internalId() != static_cast<quintptr>(-1) ? index(static_cast<int>(child.internalId()), 0, QModelIndex()) : QModelIndex();
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SyncthingDeviceModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
2017-05-01 03:34:43 +02:00
|
|
|
switch (orientation) {
|
2016-08-25 00:45:32 +02:00
|
|
|
case Qt::Horizontal:
|
2017-05-01 03:34:43 +02:00
|
|
|
switch (role) {
|
2016-08-25 00:45:32 +02:00
|
|
|
case Qt::DisplayRole:
|
2017-05-01 03:34:43 +02:00
|
|
|
switch (section) {
|
|
|
|
case 0:
|
|
|
|
return tr("ID");
|
|
|
|
case 1:
|
|
|
|
return tr("Status");
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-05-01 03:34:43 +02:00
|
|
|
default:;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-05-01 03:34:43 +02:00
|
|
|
default:;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2019-02-16 01:06:08 +01:00
|
|
|
if (!index.isValid()) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
if (index.parent().isValid()) {
|
|
|
|
// dir attributes
|
|
|
|
if (static_cast<size_t>(index.parent().row()) >= m_devs.size()) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
2023-05-11 23:44:10 +02:00
|
|
|
const auto &dev = m_devs[static_cast<size_t>(index.parent().row())];
|
2023-05-11 23:47:04 +02:00
|
|
|
const auto row = !dev.isConnected() && index.row() >= 2 ? index.row() + 2 : index.row();
|
2019-02-16 01:06:08 +01:00
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
case Qt::EditRole:
|
|
|
|
if (index.column() == 0) {
|
|
|
|
// attribute names
|
2023-05-11 23:44:10 +02:00
|
|
|
switch (row) {
|
2019-02-16 01:06:08 +01:00
|
|
|
case 0:
|
|
|
|
return tr("ID");
|
|
|
|
case 1:
|
2019-04-10 18:25:41 +02:00
|
|
|
return tr("Address");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 2:
|
2023-05-11 23:44:10 +02:00
|
|
|
return tr("Connection type");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 3:
|
2023-05-11 23:44:10 +02:00
|
|
|
return tr("Last seen");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 4:
|
2023-05-11 23:44:10 +02:00
|
|
|
return tr("Compression");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 5:
|
2023-05-11 23:44:10 +02:00
|
|
|
return tr("Certificate");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 6:
|
2023-05-11 23:44:10 +02:00
|
|
|
return tr("Introducer");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 7:
|
2023-05-11 23:44:10 +02:00
|
|
|
return tr("Incoming traffic");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 8:
|
2023-05-11 23:44:10 +02:00
|
|
|
return tr("Outgoing traffic");
|
|
|
|
case 9:
|
2019-02-16 01:06:08 +01:00
|
|
|
return tr("Version");
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2019-02-16 01:06:08 +01:00
|
|
|
break;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2019-06-12 21:00:49 +02:00
|
|
|
[[fallthrough]];
|
2019-02-16 01:06:08 +01:00
|
|
|
case DeviceDetail:
|
|
|
|
if (index.column() == 1 || role == DeviceDetail) {
|
|
|
|
// attribute values
|
2023-05-11 23:44:10 +02:00
|
|
|
switch (row) {
|
2017-05-01 03:34:43 +02:00
|
|
|
case 0:
|
2019-02-16 01:06:08 +01:00
|
|
|
return dev.id;
|
2016-08-25 00:45:32 +02:00
|
|
|
case 1:
|
2019-04-10 18:25:41 +02:00
|
|
|
if (dev.connectionAddress.isEmpty()) {
|
|
|
|
return dev.addresses.join(QStringLiteral(", "));
|
|
|
|
} else {
|
|
|
|
return QVariant(
|
|
|
|
dev.connectionAddress % QStringLiteral(" (") % dev.addresses.join(QStringLiteral(", ")) % QStringLiteral(")"));
|
|
|
|
}
|
2019-02-16 01:06:08 +01:00
|
|
|
case 2:
|
2023-05-11 23:44:10 +02:00
|
|
|
if (!dev.connectionType.isEmpty()) {
|
2023-05-18 23:50:27 +02:00
|
|
|
return QVariant(
|
|
|
|
dev.connectionType % QStringLiteral(" (") % (dev.connectionLocal ? tr("local") : tr("remote")) % QStringLiteral(")"));
|
2023-05-11 23:44:10 +02:00
|
|
|
} else {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
case 3:
|
2023-09-16 22:19:04 +02:00
|
|
|
return dev.lastSeen.isNull() ? tr("unknown or this device")
|
2019-02-16 01:06:08 +01:00
|
|
|
: QString::fromLatin1(dev.lastSeen.toString(DateTimeOutputFormat::DateAndTime, true).data());
|
|
|
|
case 4:
|
2023-05-11 23:44:10 +02:00
|
|
|
return dev.compression;
|
2019-02-16 01:06:08 +01:00
|
|
|
case 5:
|
2023-05-11 23:44:10 +02:00
|
|
|
return dev.certName.isEmpty() ? tr("none") : dev.certName;
|
2019-02-16 01:06:08 +01:00
|
|
|
case 6:
|
2023-05-11 23:44:10 +02:00
|
|
|
return dev.introducer ? tr("yes") : tr("no");
|
2019-02-16 01:06:08 +01:00
|
|
|
case 7:
|
2023-05-11 23:44:10 +02:00
|
|
|
return QString::fromStdString(dataSizeToString(dev.totalIncomingTraffic));
|
2019-02-16 01:06:08 +01:00
|
|
|
case 8:
|
2023-05-11 23:44:10 +02:00
|
|
|
return QString::fromStdString(dataSizeToString(dev.totalOutgoingTraffic));
|
|
|
|
case 9:
|
2019-02-16 01:06:08 +01:00
|
|
|
return dev.clientVersion;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2019-02-16 01:06:08 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-02-27 20:41:50 +01:00
|
|
|
case Qt::DecorationRole:
|
|
|
|
case DeviceDetailIcon:
|
|
|
|
if (index.column() == 0) {
|
|
|
|
// attribute icons
|
2021-10-16 21:20:12 +02:00
|
|
|
const auto &icons = commonForkAwesomeIcons();
|
2023-05-11 23:44:10 +02:00
|
|
|
switch (row) {
|
2019-02-27 20:41:50 +01:00
|
|
|
case 0:
|
|
|
|
return icons.hashtag;
|
|
|
|
case 1:
|
|
|
|
return icons.link;
|
|
|
|
case 2:
|
2023-05-11 23:44:10 +02:00
|
|
|
return icons.exchange;
|
2019-02-27 20:41:50 +01:00
|
|
|
case 3:
|
2023-05-11 23:44:10 +02:00
|
|
|
return icons.eye;
|
2019-02-27 20:41:50 +01:00
|
|
|
case 4:
|
2023-05-11 23:44:10 +02:00
|
|
|
return icons.fileArchive;
|
2019-02-27 20:41:50 +01:00
|
|
|
case 5:
|
2023-05-11 23:44:10 +02:00
|
|
|
return icons.certificate;
|
2019-02-27 20:41:50 +01:00
|
|
|
case 6:
|
2023-05-11 23:44:10 +02:00
|
|
|
return icons.networkWired;
|
2019-02-27 20:41:50 +01:00
|
|
|
case 7:
|
2023-05-11 23:44:10 +02:00
|
|
|
return icons.cloudDownloadAlt;
|
2019-02-27 20:41:50 +01:00
|
|
|
case 8:
|
2023-05-11 23:44:10 +02:00
|
|
|
return icons.cloudUploadAlt;
|
|
|
|
case 9:
|
2019-02-27 20:41:50 +01:00
|
|
|
return icons.tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-02-16 01:06:08 +01:00
|
|
|
case Qt::ForegroundRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case 1:
|
2023-05-11 23:44:10 +02:00
|
|
|
switch (row) {
|
|
|
|
case 3:
|
2019-02-16 01:06:08 +01:00
|
|
|
if (dev.lastSeen.isNull()) {
|
|
|
|
return Colors::gray(m_brightColors);
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-05-11 23:44:10 +02:00
|
|
|
case 5:
|
2019-02-16 01:06:08 +01:00
|
|
|
if (dev.certName.isEmpty()) {
|
|
|
|
return Colors::gray(m_brightColors);
|
|
|
|
}
|
2017-05-01 03:34:43 +02:00
|
|
|
break;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2019-02-16 01:06:08 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case 1:
|
2023-05-11 23:44:10 +02:00
|
|
|
switch (row) {
|
2019-04-10 18:25:41 +02:00
|
|
|
case 1:
|
|
|
|
if (!dev.connectionType.isEmpty()) {
|
|
|
|
return dev.connectionType;
|
|
|
|
}
|
|
|
|
break;
|
2023-05-11 23:44:10 +02:00
|
|
|
case 3:
|
2019-02-16 01:06:08 +01:00
|
|
|
if (!dev.lastSeen.isNull()) {
|
|
|
|
return agoString(dev.lastSeen);
|
|
|
|
}
|
2017-05-01 03:34:43 +02:00
|
|
|
break;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
2019-02-16 01:06:08 +01:00
|
|
|
break;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<size_t>(index.row()) >= m_devs.size()) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
// dir IDs and status
|
|
|
|
const SyncthingDev &dev = m_devs[static_cast<size_t>(index.row())];
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
case Qt::EditRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case 0:
|
|
|
|
return dev.name.isEmpty() ? dev.id : dev.name;
|
|
|
|
case 1:
|
|
|
|
return devStatusString(dev);
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
2021-03-20 22:39:40 +01:00
|
|
|
break;
|
2019-02-16 01:06:08 +01:00
|
|
|
case Qt::DecorationRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case 0:
|
|
|
|
if (dev.paused) {
|
|
|
|
return statusIcons().pause;
|
|
|
|
} else {
|
|
|
|
switch (dev.status) {
|
|
|
|
case SyncthingDevStatus::Unknown:
|
|
|
|
case SyncthingDevStatus::Disconnected:
|
|
|
|
return statusIcons().disconnected;
|
2023-09-16 22:28:35 +02:00
|
|
|
case SyncthingDevStatus::ThisDevice:
|
2019-02-16 01:06:08 +01:00
|
|
|
case SyncthingDevStatus::Idle:
|
|
|
|
return statusIcons().idling;
|
|
|
|
case SyncthingDevStatus::Synchronizing:
|
|
|
|
return statusIcons().sync;
|
|
|
|
case SyncthingDevStatus::OutOfSync:
|
|
|
|
case SyncthingDevStatus::Rejected:
|
|
|
|
return statusIcons().error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Qt::TextAlignmentRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return static_cast<int>(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Qt::ForegroundRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return devStatusColor(dev);
|
|
|
|
}
|
|
|
|
break;
|
2023-09-16 23:07:00 +02:00
|
|
|
case IsPinned:
|
2023-09-16 23:09:10 +02:00
|
|
|
case IsThisDevice:
|
2023-09-16 23:07:00 +02:00
|
|
|
return dev.status == SyncthingDevStatus::ThisDevice;
|
2019-02-16 01:06:08 +01:00
|
|
|
case DeviceStatus:
|
|
|
|
return static_cast<int>(dev.status);
|
|
|
|
case DevicePaused:
|
|
|
|
return dev.paused;
|
|
|
|
case DeviceStatusString:
|
|
|
|
return devStatusString(dev);
|
|
|
|
case DeviceStatusColor:
|
|
|
|
return devStatusColor(dev);
|
|
|
|
case DeviceId:
|
|
|
|
return dev.id;
|
|
|
|
default:;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SyncthingDeviceModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
2019-05-04 22:10:37 +02:00
|
|
|
Q_UNUSED(index)
|
|
|
|
Q_UNUSED(value)
|
|
|
|
Q_UNUSED(role)
|
|
|
|
return false;
|
2016-08-25 00:45:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int SyncthingDeviceModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2017-05-01 03:34:43 +02:00
|
|
|
if (!parent.isValid()) {
|
2016-09-06 22:55:49 +02:00
|
|
|
return static_cast<int>(m_devs.size());
|
2017-05-01 03:34:43 +02:00
|
|
|
} else if (!parent.parent().isValid()) {
|
2023-05-11 23:47:04 +02:00
|
|
|
// hide connection type, last seen and everything after introducer (eg. traffic) unless connected
|
2018-08-04 20:34:24 +02:00
|
|
|
const auto *const dev(devInfo(parent));
|
2023-05-11 23:47:04 +02:00
|
|
|
return dev && dev->isConnected() ? 10 : 5;
|
2016-08-25 00:45:32 +02:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int SyncthingDeviceModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2017-05-01 03:34:43 +02:00
|
|
|
if (!parent.isValid()) {
|
2016-08-25 00:45:32 +02:00
|
|
|
return 2; // name/id, status
|
2017-05-01 03:34:43 +02:00
|
|
|
} else if (!parent.parent().isValid()) {
|
2016-08-25 00:45:32 +02:00
|
|
|
return 2; // field name and value
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 16:43:53 +02:00
|
|
|
void SyncthingDeviceModel::devStatusChanged(const SyncthingDev &, int index)
|
|
|
|
{
|
|
|
|
const QModelIndex modelIndex1(this->index(index, 0, QModelIndex()));
|
2023-09-16 23:09:10 +02:00
|
|
|
static const QVector<int> modelRoles1({ Qt::DisplayRole, Qt::EditRole, Qt::DecorationRole, DevicePaused, DeviceStatus, DeviceStatusString,
|
|
|
|
DeviceStatusColor, DeviceId, IsThisDevice, IsPinned });
|
2017-08-29 23:55:05 +02:00
|
|
|
emit dataChanged(modelIndex1, modelIndex1, modelRoles1);
|
2016-08-26 16:43:53 +02:00
|
|
|
const QModelIndex modelIndex2(this->index(index, 1, QModelIndex()));
|
2018-07-22 21:08:28 +02:00
|
|
|
static const QVector<int> modelRoles2({ Qt::DisplayRole, Qt::EditRole, Qt::ForegroundRole });
|
2017-08-29 23:55:05 +02:00
|
|
|
emit dataChanged(modelIndex2, modelIndex2, modelRoles2);
|
2018-07-22 21:08:28 +02:00
|
|
|
static const QVector<int> modelRoles3({ Qt::DisplayRole, Qt::EditRole, Qt::ToolTipRole });
|
2017-09-05 00:22:52 +02:00
|
|
|
emit dataChanged(this->index(0, 1, modelIndex1), this->index(5, 1, modelIndex1), modelRoles3);
|
2018-07-22 21:08:28 +02:00
|
|
|
static const QVector<int> modelRoles4({ Qt::DisplayRole, Qt::EditRole, DeviceDetail });
|
2017-09-05 00:22:52 +02:00
|
|
|
emit dataChanged(this->index(0, 0, modelIndex1), this->index(5, 0, modelIndex1), modelRoles4);
|
2017-08-29 23:55:05 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 21:51:55 +02:00
|
|
|
void SyncthingDeviceModel::handleStatusIconsChanged()
|
|
|
|
{
|
2021-10-16 21:20:12 +02:00
|
|
|
invalidateTopLevelIndicies(QVector<int>({ Qt::DecorationRole }));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingDeviceModel::handleForkAwesomeIconsChanged()
|
|
|
|
{
|
|
|
|
invalidateNestedIndicies(QVector<int>({ Qt::DecorationRole, DeviceDetailIcon }));
|
2019-05-19 21:51:55 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 23:55:05 +02:00
|
|
|
QString SyncthingDeviceModel::devStatusString(const SyncthingDev &dev)
|
|
|
|
{
|
|
|
|
if (dev.paused) {
|
|
|
|
return tr("Paused");
|
|
|
|
}
|
|
|
|
switch (dev.status) {
|
|
|
|
case SyncthingDevStatus::Unknown:
|
|
|
|
return tr("Unknown status");
|
2023-09-16 22:28:35 +02:00
|
|
|
case SyncthingDevStatus::ThisDevice:
|
2023-09-16 23:20:28 +02:00
|
|
|
return tr("This device");
|
2017-08-29 23:55:05 +02:00
|
|
|
case SyncthingDevStatus::Idle:
|
|
|
|
return tr("Idle");
|
|
|
|
case SyncthingDevStatus::Disconnected:
|
|
|
|
return tr("Disconnected");
|
|
|
|
case SyncthingDevStatus::Synchronizing:
|
2020-03-01 22:04:49 +01:00
|
|
|
return dev.overallCompletion.needed.bytes > 0 ? tr("Synchronizing (%1 %, %2)")
|
2020-12-17 12:58:46 +01:00
|
|
|
.arg(static_cast<int>(dev.overallCompletion.percentage))
|
2020-03-01 22:04:49 +01:00
|
|
|
.arg(QString::fromStdString(dataSizeToString(dev.overallCompletion.needed.bytes)))
|
|
|
|
: tr("Synchronizing");
|
2017-08-29 23:55:05 +02:00
|
|
|
case SyncthingDevStatus::OutOfSync:
|
|
|
|
return tr("Out of sync");
|
|
|
|
case SyncthingDevStatus::Rejected:
|
|
|
|
return tr("Rejected");
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2017-09-01 17:13:01 +02:00
|
|
|
QVariant SyncthingDeviceModel::devStatusColor(const SyncthingDev &dev) const
|
2017-08-29 23:55:05 +02:00
|
|
|
{
|
|
|
|
if (dev.paused) {
|
2017-09-01 17:13:01 +02:00
|
|
|
return QVariant();
|
2017-08-29 23:55:05 +02:00
|
|
|
}
|
|
|
|
switch (dev.status) {
|
|
|
|
case SyncthingDevStatus::Unknown:
|
|
|
|
break;
|
|
|
|
case SyncthingDevStatus::Disconnected:
|
|
|
|
break;
|
2023-09-16 22:28:35 +02:00
|
|
|
case SyncthingDevStatus::ThisDevice:
|
2017-08-29 23:55:05 +02:00
|
|
|
case SyncthingDevStatus::Idle:
|
|
|
|
return Colors::green(m_brightColors);
|
|
|
|
case SyncthingDevStatus::Synchronizing:
|
|
|
|
return Colors::blue(m_brightColors);
|
|
|
|
case SyncthingDevStatus::OutOfSync:
|
|
|
|
case SyncthingDevStatus::Rejected:
|
|
|
|
return Colors::red(m_brightColors);
|
|
|
|
}
|
2017-09-01 17:13:01 +02:00
|
|
|
return QVariant();
|
2016-08-26 16:43:53 +02:00
|
|
|
}
|
|
|
|
|
2016-08-25 00:45:32 +02:00
|
|
|
} // namespace Data
|