This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathitemcontroller.cpp
118 lines (100 loc) · 4 KB
/
itemcontroller.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <QDBusPendingCall>
#include "iconproducer.h"
#include "appletstrings.h"
#include "itemcontroller.h"
ItemController::ItemController(QStandardItem* parent, const QString& path, const char* service, const QVariantMap& properties):
QObject(),
connmanObject(new ConnmanObject(path, service, properties)),
item(new QStandardItem())
{
connect(connmanObject, &ConnmanObject::PropertyChanged, this, &ItemController::onPropertyChanged);
parent->appendRow(item);
item->setData(QVariant::fromValue(this), WrapperRole);
item->setEditable(false);
}
ItemController::~ItemController()
{
item->parent()->removeRow(item->row());
connmanObject->deleteLater();
}
void ItemController::setOrder(int order)
{
item->setData(order, OrderRole);
}
void ItemController::onPropertyChanged(const QString& propertyName, const QDBusVariant& newValue)
{
update();
}
ServiceItemController::ServiceItemController(QStandardItem* parent, const QString& path, const QVariantMap& properties) :
ItemController(parent, path, "net.connman.Service", properties)
{
}
void ServiceItemController::update()
{
QString state = connmanObject->properties["State"].toString();
QString type = connmanObject->properties["Type"].toString();
QString name = connmanObject->properties["Name"].toString();
int strength = connmanObject->properties["Strength"].toInt();
item->setData(state == "online" ? name + ' ' + QChar(0x2713) : name, Qt::DisplayRole);
item->setData(state == "ready" || state == "online" ? QFont("", -1, QFont::Bold) : QVariant(), Qt::FontRole);
if (type == "wifi") {
item->setData(IconProducer::instance().wireless(strength), Qt::DecorationRole);
}
else if (state == "offline") {
item->setData(IconProducer::instance().disconnected(), Qt::DecorationRole);
}
else {
item->setData(IconProducer::instance().wiredConnected(), Qt::DecorationRole);
}
if (state == "association" || state == "configuration") {
if (item->hasChildren()) {
item->child(0, 0)->setData(string(state), Qt::DisplayRole);
}
else {
QStandardItem* stateItem = new QStandardItem(string(state));
stateItem->setData(IconProducer::instance().blanc(), Qt::DecorationRole);
stateItem->setData(QFont("", -1, -1, true), Qt::FontRole);
item->appendRow(stateItem);
}
}
else while (item->hasChildren()) {
item->removeRow(0);
}
}
void ServiceItemController::activate()
{
QString state = connmanObject->properties["State"].toString();
if (state == "idle" || state == "failure") {
connmanObject->asyncCall("Connect");
}
else if (state == "association" || state == "configuration" || state == "ready" || state == "online") {
connmanObject->asyncCall("Disconnect");
}
}
TechnologyItemController::TechnologyItemController(QStandardItem* parent, const QString& path, const QVariantMap& properties) :
ItemController(parent, path, "net.connman.Technology", properties)
{
}
void TechnologyItemController::update()
{
QString type = connmanObject->properties["Type"].toString();
bool powered = connmanObject->properties["Powered"].toBool();
QString name = connmanObject->properties["Name"].toString();
item->setData(name, Qt::DisplayRole);
if (type == "ethernet") {
item->setData(IconProducer::instance().wiredConnected(), Qt::DecorationRole);
}
else if (type == "wifi") {
item->setData(IconProducer::instance().wireless(80), Qt::DecorationRole);
}
else {
item->setData(IconProducer::instance().blanc(), Qt::DecorationRole);
}
item->setData(powered ? QVariant() : QFont("", -1, -1, true), Qt::FontRole);
item->setData(powered ? QVariant() : QColor("lightgrey"), Qt::ForegroundRole);
}
void TechnologyItemController::activate()
{
bool newPowered = !(connmanObject->properties["Powered"].toBool());
connmanObject->asyncCall("SetProperty", QVariant("Powered"), QVariant::fromValue(QDBusVariant(newPowered)));
}