-
Notifications
You must be signed in to change notification settings - Fork 1
/
wirednetworkinterface.cpp
183 lines (145 loc) · 5.72 KB
/
wirednetworkinterface.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* This file is part of the KDE project
Copyright (C) 2008 Dario Freddi <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "wirednetworkinterface.h"
#include "wicddbusinterface.h"
#include "wicd-defines.h"
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
#include <QtCore/QProcess>
#include <KDebug>
class WicdWiredNetworkInterface::Private
{
public:
bool isActiveInterface;
QString uni;
int bitrate;
QString driver;
bool carrier;
Solid::Control::NetworkInterface::ConnectionState connection_state;
};
WicdWiredNetworkInterface::WicdWiredNetworkInterface(const QString &name)
: WicdNetworkInterface(name)
, d(new Private())
{
d->uni = uni();
recacheInformation();
QDBusConnection::systemBus().connect(WICD_DBUS_SERVICE, WICD_DAEMON_DBUS_PATH, WICD_DAEMON_DBUS_INTERFACE,
"StatusChanged", this, SLOT(refreshStatus()));
}
WicdWiredNetworkInterface::~WicdWiredNetworkInterface()
{
}
void WicdWiredNetworkInterface::recacheInformation()
{
//QDBusReply< QString > bitrater = WicdDbusInterface::instance()->wireless().call("GetCurrentBitrate", iwconfig);
QDBusReply< QString > interfacer = WicdDbusInterface::instance()->daemon().call("GetWiredInterface");
QDBusReply< bool > carrierr = WicdDbusInterface::instance()->wired().call("CheckPluggedIn");
QDBusReply< QString > cstater = WicdDbusInterface::instance()->wired().call("CheckWiredConnectingMessage");
if (interfacer.value() == d->uni) {
kDebug() << "Active interface";
if (d->carrier != carrierr.value()) {
d->carrier = carrierr.value();
emit carrierChanged(d->carrier);
}
Solid::Control::NetworkInterface::ConnectionState connection_state;
if (cstater.value() == "configuring_interface") {
connection_state = Solid::Control::NetworkInterface::Configuring;
} else if (cstater.value() == "validating_authentication") {
connection_state = Solid::Control::NetworkInterface::NeedAuth;
} else if (cstater.value() == "done") {
connection_state = Solid::Control::NetworkInterface::Activated;
} else if (cstater.value() == "interface_down") {
connection_state = Solid::Control::NetworkInterface::Disconnected;
} else if (cstater.value() == "running_dhcp" ||
cstater.value() == "setting_static_ip" ||
cstater.value() == "setting_broadcast_address") {
connection_state = Solid::Control::NetworkInterface::IPConfig;
} else if (cstater.value() == "interface_up") {
connection_state = Solid::Control::NetworkInterface::Preparing;
} else {
connection_state = Solid::Control::NetworkInterface::UnknownState;
}
if (connection_state != d->connection_state) {
connection_state = d->connection_state;
emit connectionStateChanged(d->connection_state);
}
} else {
if (d->carrier != false) {
d->carrier = false;
emit carrierChanged(d->carrier);
}
}
}
Solid::Control::NetworkInterface::ConnectionState WicdWiredNetworkInterface::connectionState() const
{
if (d->isActiveInterface) {
return d->connection_state;
} else {
return Solid::Control::NetworkInterface::Unavailable;
}
}
Solid::Control::NetworkInterface::Type WicdWiredNetworkInterface::type() const
{
return Solid::Control::NetworkInterface::Ieee8023;
}
bool WicdWiredNetworkInterface::isActive() const
{
return d->isActiveInterface;
}
Solid::Control::NetworkInterface::Capabilities WicdWiredNetworkInterface::capabilities() const
{
Solid::Control::NetworkInterface::Capabilities cap;
if (interfaceName() != "lo" || !interfaceName().contains("wmaster")) {
cap |= Solid::Control::NetworkInterface::IsManageable;
}
cap |= Solid::Control::NetworkInterface::SupportsCarrierDetect;
return cap;
}
QString WicdWiredNetworkInterface::driver() const
{
return QString();
}
QString WicdWiredNetworkInterface::hardwareAddress() const
{
// Let's parse ifconfig here
QProcess ifconfig;
ifconfig.start(QString("ifconfig %1").arg(uni()));
ifconfig.waitForFinished();
QString result = ifconfig.readAllStandardOutput();
QStringList lines = result.split('\n');
return lines.at(0).split("HWaddr ").at(1);
}
int WicdWiredNetworkInterface::bitRate() const
{
return d->bitrate;
}
bool WicdWiredNetworkInterface::carrier() const
{
return d->carrier;
}
bool WicdWiredNetworkInterface::activateConnection(const QString & connectionUni, const QVariantMap & connectionParameters)
{
Q_UNUSED(connectionUni)
Q_UNUSED(connectionParameters)
WicdDbusInterface::instance()->daemon().call("SetWiredInterface", interfaceName());
WicdDbusInterface::instance()->wired().call("ConnectWired");
return true;
}
bool WicdWiredNetworkInterface::deactivateConnection()
{
WicdDbusInterface::instance()->wired().call("DisconnectWired");
return true;
}
#include "wirednetworkinterface.moc"