Show this/own device always as first device
See https://github.com/Martchus/syncthingtray/issues/203
This commit is contained in:
parent
5fa69e4f5a
commit
f5795d45c2
|
@ -709,12 +709,18 @@ void SyncthingConnection::readDirs(const QJsonArray &dirs)
|
||||||
void SyncthingConnection::readDevs(const QJsonArray &devs)
|
void SyncthingConnection::readDevs(const QJsonArray &devs)
|
||||||
{
|
{
|
||||||
// store the new devs in a temporary list which is assigned to m_devs later
|
// store the new devs in a temporary list which is assigned to m_devs later
|
||||||
vector<SyncthingDev> newDevs;
|
auto newDevs = std::vector<SyncthingDev>();
|
||||||
newDevs.reserve(static_cast<size_t>(devs.size()));
|
newDevs.reserve(static_cast<std::size_t>(devs.size()));
|
||||||
|
auto *const thisDevice = addDevInfo(newDevs, m_myId);
|
||||||
|
thisDevice->id = m_myId;
|
||||||
|
thisDevice->status = SyncthingDevStatus::ThisDevice;
|
||||||
|
thisDevice->paused = false;
|
||||||
|
|
||||||
for (const QJsonValue &devVal : devs) {
|
for (const auto &devVal : devs) {
|
||||||
const QJsonObject devObj(devVal.toObject());
|
const auto devObj = devVal.toObject();
|
||||||
SyncthingDev *const devItem = addDevInfo(newDevs, devObj.value(QLatin1String("deviceID")).toString());
|
const auto deviceId = devObj.value(QLatin1String("deviceID")).toString();
|
||||||
|
const auto isThisDevice = deviceId == m_myId;
|
||||||
|
auto *const devItem = isThisDevice ? thisDevice : addDevInfo(newDevs, deviceId);
|
||||||
if (!devItem) {
|
if (!devItem) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -724,10 +730,7 @@ void SyncthingConnection::readDevs(const QJsonArray &devs)
|
||||||
devItem->compression = devObj.value(QLatin1String("compression")).toString();
|
devItem->compression = devObj.value(QLatin1String("compression")).toString();
|
||||||
devItem->certName = devObj.value(QLatin1String("certName")).toString();
|
devItem->certName = devObj.value(QLatin1String("certName")).toString();
|
||||||
devItem->introducer = devObj.value(QLatin1String("introducer")).toBool(false);
|
devItem->introducer = devObj.value(QLatin1String("introducer")).toBool(false);
|
||||||
if (devItem->id == m_myId) {
|
if (!isThisDevice) {
|
||||||
devItem->status = SyncthingDevStatus::ThisDevice;
|
|
||||||
devItem->paused = false;
|
|
||||||
} else {
|
|
||||||
devItem->status = SyncthingDevStatus::Unknown;
|
devItem->status = SyncthingDevStatus::Unknown;
|
||||||
devItem->paused = devObj.value(QLatin1String("paused")).toBool(devItem->paused);
|
devItem->paused = devObj.value(QLatin1String("paused")).toBool(devItem->paused);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ QHash<int, QByteArray> SyncthingDeviceModel::roleNames() const
|
||||||
{ Qt::DecorationRole, "statusIcon" },
|
{ Qt::DecorationRole, "statusIcon" },
|
||||||
{ DevicePaused, "paused" },
|
{ DevicePaused, "paused" },
|
||||||
{ IsOwnDevice, "isOwnDevice" },
|
{ IsOwnDevice, "isOwnDevice" },
|
||||||
|
{ IsPinned, "isPinned" },
|
||||||
{ DeviceStatusString, "statusString" },
|
{ DeviceStatusString, "statusString" },
|
||||||
{ DeviceStatusColor, "statusColor" },
|
{ DeviceStatusColor, "statusColor" },
|
||||||
{ DeviceId, "devId" },
|
{ DeviceId, "devId" },
|
||||||
|
@ -298,12 +299,13 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const
|
||||||
return devStatusColor(dev);
|
return devStatusColor(dev);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case IsPinned:
|
||||||
|
case IsOwnDevice:
|
||||||
|
return dev.status == SyncthingDevStatus::ThisDevice;
|
||||||
case DeviceStatus:
|
case DeviceStatus:
|
||||||
return static_cast<int>(dev.status);
|
return static_cast<int>(dev.status);
|
||||||
case DevicePaused:
|
case DevicePaused:
|
||||||
return dev.paused;
|
return dev.paused;
|
||||||
case IsOwnDevice:
|
|
||||||
return dev.status == SyncthingDevStatus::ThisDevice;
|
|
||||||
case DeviceStatusString:
|
case DeviceStatusString:
|
||||||
return devStatusString(dev);
|
return devStatusString(dev);
|
||||||
case DeviceStatusColor:
|
case DeviceStatusColor:
|
||||||
|
|
|
@ -15,7 +15,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDeviceModel : public SyncthingModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum SyncthingDeviceModelRole {
|
enum SyncthingDeviceModelRole {
|
||||||
DeviceStatus = Qt::UserRole + 1,
|
DeviceStatus = SyncthingModelUserRole + 1,
|
||||||
DevicePaused,
|
DevicePaused,
|
||||||
IsOwnDevice,
|
IsOwnDevice,
|
||||||
DeviceStatusString,
|
DeviceStatusString,
|
||||||
|
|
|
@ -15,7 +15,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDirectoryModel : public SyncthingModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum SyncthingDirectoryModelRole {
|
enum SyncthingDirectoryModelRole {
|
||||||
DirectoryStatus = Qt::UserRole + 1,
|
DirectoryStatus = SyncthingModelUserRole + 1,
|
||||||
DirectoryPaused,
|
DirectoryPaused,
|
||||||
DirectoryStatusString,
|
DirectoryStatusString,
|
||||||
DirectoryStatusColor,
|
DirectoryStatusColor,
|
||||||
|
|
|
@ -20,7 +20,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDownloadModel : public SyncthingModel
|
||||||
public:
|
public:
|
||||||
explicit SyncthingDownloadModel(SyncthingConnection &connection, QObject *parent = nullptr);
|
explicit SyncthingDownloadModel(SyncthingConnection &connection, QObject *parent = nullptr);
|
||||||
|
|
||||||
enum SyncthingDownloadModelRole { ItemPercentage = Qt::UserRole + 1, ItemProgressLabel, ItemPath };
|
enum SyncthingDownloadModelRole { ItemPercentage = SyncthingModelUserRole + 1, ItemProgressLabel, ItemPath };
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
|
@ -19,6 +19,11 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingModel : public QAbstractItemModel {
|
||||||
Q_PROPERTY(bool brightColors READ brightColors WRITE setBrightColors)
|
Q_PROPERTY(bool brightColors READ brightColors WRITE setBrightColors)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum SyncthingModelRole {
|
||||||
|
IsPinned = Qt::UserRole + 1,
|
||||||
|
SyncthingModelUserRole = Qt::UserRole + 100,
|
||||||
|
};
|
||||||
|
|
||||||
explicit SyncthingModel(SyncthingConnection &connection, QObject *parent = nullptr);
|
explicit SyncthingModel(SyncthingConnection &connection, QObject *parent = nullptr);
|
||||||
Data::SyncthingConnection *connection();
|
Data::SyncthingConnection *connection();
|
||||||
const Data::SyncthingConnection *connection() const;
|
const Data::SyncthingConnection *connection() const;
|
||||||
|
|
|
@ -23,7 +23,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingRecentChangesModel : public SyncthingM
|
||||||
Q_PROPERTY(int maxRows READ maxRows WRITE setMaxRows)
|
Q_PROPERTY(int maxRows READ maxRows WRITE setMaxRows)
|
||||||
public:
|
public:
|
||||||
enum SyncthingRecentChangesModelRole {
|
enum SyncthingRecentChangesModelRole {
|
||||||
Action = Qt::UserRole + 1,
|
Action = SyncthingModelUserRole + 1,
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
ModifiedBy,
|
ModifiedBy,
|
||||||
DirectoryId,
|
DirectoryId,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "./syncthingsortfiltermodel.h"
|
#include "./syncthingsortfiltermodel.h"
|
||||||
|
#include "./syncthingmodel.h"
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
@ -20,6 +21,12 @@ bool SyncthingSortFilterModel::lessThan(const QModelIndex &left, const QModelInd
|
||||||
if (m_behavior == SyncthingSortBehavior::KeepRawOrder || left.parent().isValid() || right.parent().isValid()) {
|
if (m_behavior == SyncthingSortBehavior::KeepRawOrder || left.parent().isValid() || right.parent().isValid()) {
|
||||||
return left.row() < right.row();
|
return left.row() < right.row();
|
||||||
}
|
}
|
||||||
|
// show pinned items before all other items
|
||||||
|
const auto leftPinned = left.data(SyncthingModel::IsPinned).toBool();
|
||||||
|
const auto rightPinned = right.data(SyncthingModel::IsPinned).toBool();
|
||||||
|
if (leftPinned != rightPinned) {
|
||||||
|
return leftPinned;
|
||||||
|
}
|
||||||
// use the default sorting for the top-level
|
// use the default sorting for the top-level
|
||||||
return QSortFilterProxyModel::lessThan(left, right);
|
return QSortFilterProxyModel::lessThan(left, right);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue