-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevicemanager.cpp
101 lines (79 loc) · 3.16 KB
/
devicemanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "devicemanager.h"
#include <QStandardItemModel>
#include <projectexplorer/devicesupport/devicemanager.h>
#include "remotedevconstants.h"
using namespace RemoteDev::Internal;
DeviceManager::DeviceManager(QObject *parent) :
QObject(parent),
m_devices(new QStandardItemModel(0, Constants::DEV_COLUMNS_COUNT, this))
{}
void DeviceManager::startDeviceSync()
{
auto deviceMgr = ProjectExplorer::DeviceManager::instance();
connect(deviceMgr, &ProjectExplorer::DeviceManager::deviceAdded,
this, &DeviceManager::onDeviceAdded);
connect(deviceMgr, &ProjectExplorer::DeviceManager::deviceUpdated,
this, &DeviceManager::onDeviceUpdated);
connect(deviceMgr, &ProjectExplorer::DeviceManager::deviceRemoved,
this, &DeviceManager::onDeviceRemoved);
connect(deviceMgr, &ProjectExplorer::DeviceManager::deviceListReplaced,
this, &DeviceManager::onDeviceListReplaced);
// FIXME: should I handle &ProjectExplorer::DeviceManager::updated?
onDeviceListReplaced();
}
QStandardItemModel *DeviceManager::devices() const
{
return m_devices;
}
void DeviceManager::onDeviceAdded(Core::Id id)
{
auto device = ProjectExplorer::DeviceManager::instance()->find(id);
if (! device.isNull()) {
m_devices->appendRow({ createNameItem(device), createIdItem(device) });
}
}
void DeviceManager::onDeviceUpdated(Core::Id id)
{
auto device = ProjectExplorer::DeviceManager::instance()->find(id);
if (! device.isNull()) {
auto items = m_devices->findItems(id.toString(),
Qt::MatchExactly, Constants::DEV_ID_COLUMN);
// FIXME: give warning if more than one found
if (items.count() > 0) {
m_devices->setItem(items.at(0)->row(), Constants::DEV_NAME_COLUMN,
createNameItem(device));
m_devices->setItem(items.at(0)->row(), Constants::DEV_ID_COLUMN,
createIdItem(device));
}
}
}
void DeviceManager::onDeviceRemoved(Core::Id id)
{
auto items = m_devices->findItems(id.toString(),
Qt::MatchExactly, Constants::DEV_ID_COLUMN);
// FIXME: give warning if more than one found
if (items.count() > 0) {
m_devices->removeRow(items.at(0)->row());
}
}
// bulk update or initialization
void DeviceManager::onDeviceListReplaced()
{
auto deviceMgr = ProjectExplorer::DeviceManager::instance();
m_devices->setRowCount(0); // clear only data items
for (int i = 0; i < deviceMgr->deviceCount(); i++) {
auto device = deviceMgr->deviceAt(i);
// FIXME: do I need check device.sshParameters?
m_devices->appendRow({ createNameItem(device), createIdItem(device) });
}
}
QStandardItem *DeviceManager::createNameItem(ProjectExplorer::IDevice::ConstPtr device)
{
return new QStandardItem(device->displayName());
}
QStandardItem *DeviceManager::createIdItem(ProjectExplorer::IDevice::ConstPtr device)
{
auto idItem = new QStandardItem(device->id().toString()); // string needed for lookup
idItem->setData(device->id().toSetting(), RemoteDev::Constants::DEV_ID_ROLE);
return idItem;
}