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)
|
||||
{
|
||||
// store the new devs in a temporary list which is assigned to m_devs later
|
||||
vector<SyncthingDev> newDevs;
|
||||
newDevs.reserve(static_cast<size_t>(devs.size()));
|
||||
auto newDevs = std::vector<SyncthingDev>();
|
||||
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) {
|
||||
const QJsonObject devObj(devVal.toObject());
|
||||
SyncthingDev *const devItem = addDevInfo(newDevs, devObj.value(QLatin1String("deviceID")).toString());
|
||||
for (const auto &devVal : devs) {
|
||||
const auto devObj = devVal.toObject();
|
||||
const auto deviceId = devObj.value(QLatin1String("deviceID")).toString();
|
||||
const auto isThisDevice = deviceId == m_myId;
|
||||
auto *const devItem = isThisDevice ? thisDevice : addDevInfo(newDevs, deviceId);
|
||||
if (!devItem) {
|
||||
continue;
|
||||
}
|
||||
|
@ -724,10 +730,7 @@ void SyncthingConnection::readDevs(const QJsonArray &devs)
|
|||
devItem->compression = devObj.value(QLatin1String("compression")).toString();
|
||||
devItem->certName = devObj.value(QLatin1String("certName")).toString();
|
||||
devItem->introducer = devObj.value(QLatin1String("introducer")).toBool(false);
|
||||
if (devItem->id == m_myId) {
|
||||
devItem->status = SyncthingDevStatus::ThisDevice;
|
||||
devItem->paused = false;
|
||||
} else {
|
||||
if (!isThisDevice) {
|
||||
devItem->status = SyncthingDevStatus::Unknown;
|
||||
devItem->paused = devObj.value(QLatin1String("paused")).toBool(devItem->paused);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ QHash<int, QByteArray> SyncthingDeviceModel::roleNames() const
|
|||
{ Qt::DecorationRole, "statusIcon" },
|
||||
{ DevicePaused, "paused" },
|
||||
{ IsOwnDevice, "isOwnDevice" },
|
||||
{ IsPinned, "isPinned" },
|
||||
{ DeviceStatusString, "statusString" },
|
||||
{ DeviceStatusColor, "statusColor" },
|
||||
{ DeviceId, "devId" },
|
||||
|
@ -298,12 +299,13 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const
|
|||
return devStatusColor(dev);
|
||||
}
|
||||
break;
|
||||
case IsPinned:
|
||||
case IsOwnDevice:
|
||||
return dev.status == SyncthingDevStatus::ThisDevice;
|
||||
case DeviceStatus:
|
||||
return static_cast<int>(dev.status);
|
||||
case DevicePaused:
|
||||
return dev.paused;
|
||||
case IsOwnDevice:
|
||||
return dev.status == SyncthingDevStatus::ThisDevice;
|
||||
case DeviceStatusString:
|
||||
return devStatusString(dev);
|
||||
case DeviceStatusColor:
|
||||
|
|
|
@ -15,7 +15,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDeviceModel : public SyncthingModel {
|
|||
Q_OBJECT
|
||||
public:
|
||||
enum SyncthingDeviceModelRole {
|
||||
DeviceStatus = Qt::UserRole + 1,
|
||||
DeviceStatus = SyncthingModelUserRole + 1,
|
||||
DevicePaused,
|
||||
IsOwnDevice,
|
||||
DeviceStatusString,
|
||||
|
|
|
@ -15,7 +15,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDirectoryModel : public SyncthingModel
|
|||
Q_OBJECT
|
||||
public:
|
||||
enum SyncthingDirectoryModelRole {
|
||||
DirectoryStatus = Qt::UserRole + 1,
|
||||
DirectoryStatus = SyncthingModelUserRole + 1,
|
||||
DirectoryPaused,
|
||||
DirectoryStatusString,
|
||||
DirectoryStatusColor,
|
||||
|
|
|
@ -20,7 +20,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDownloadModel : public SyncthingModel
|
|||
public:
|
||||
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:
|
||||
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)
|
||||
|
||||
public:
|
||||
enum SyncthingModelRole {
|
||||
IsPinned = Qt::UserRole + 1,
|
||||
SyncthingModelUserRole = Qt::UserRole + 100,
|
||||
};
|
||||
|
||||
explicit SyncthingModel(SyncthingConnection &connection, QObject *parent = nullptr);
|
||||
Data::SyncthingConnection *connection();
|
||||
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)
|
||||
public:
|
||||
enum SyncthingRecentChangesModelRole {
|
||||
Action = Qt::UserRole + 1,
|
||||
Action = SyncthingModelUserRole + 1,
|
||||
ActionIcon,
|
||||
ModifiedBy,
|
||||
DirectoryId,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "./syncthingsortfiltermodel.h"
|
||||
#include "./syncthingmodel.h"
|
||||
|
||||
#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()) {
|
||||
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
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue