Changeset View
Changeset View
Standalone View
Standalone View
src/fakenetwork/fakenetwork.cpp
Show All 40 Lines | 31 | FakeNetwork::FakeNetwork(QObject *parent) | |||
---|---|---|---|---|---|
41 | , m_wirelessEnabled(true) | 41 | , m_wirelessEnabled(true) | ||
42 | , m_wirelessHardwareEnabled(true) | 42 | , m_wirelessHardwareEnabled(true) | ||
43 | , m_wwanEnabled(true) | 43 | , m_wwanEnabled(true) | ||
44 | , m_wwanHardwareEnabled(true) | 44 | , m_wwanHardwareEnabled(true) | ||
45 | , m_activeConnectionsCounter(0) | 45 | , m_activeConnectionsCounter(0) | ||
46 | , m_deviceCounter(0) | 46 | , m_deviceCounter(0) | ||
47 | , m_settings(new Settings(this)) | 47 | , m_settings(new Settings(this)) | ||
48 | { | 48 | { | ||
49 | QDBusConnection::sessionBus().registerService(QLatin1Literal("org.kde.fakenetwork")); | 49 | registerService(); | ||
50 | QDBusConnection::sessionBus().registerObject(QLatin1Literal("/org/kde/fakenetwork"), this, QDBusConnection::ExportScriptableContents); | | |||
51 | QDBusConnection::sessionBus().registerObject(QLatin1Literal("/org/kde/fakenetwork/Settings"), m_settings, QDBusConnection::ExportScriptableContents); | | |||
52 | | ||||
53 | connect(m_settings, &Settings::connectionAdded, this, &FakeNetwork::onConnectionAdded); | 50 | connect(m_settings, &Settings::connectionAdded, this, &FakeNetwork::onConnectionAdded); | ||
54 | connect(m_settings, &Settings::connectionRemoved, this, &FakeNetwork::onConnectionRemoved); | 51 | connect(m_settings, &Settings::connectionRemoved, this, &FakeNetwork::onConnectionRemoved); | ||
55 | } | 52 | } | ||
56 | 53 | | |||
57 | FakeNetwork::~FakeNetwork() | 54 | FakeNetwork::~FakeNetwork() | ||
58 | { | 55 | { | ||
59 | Q_FOREACH (const QDBusObjectPath & devicePath, m_devices.keys()) { | 56 | unregisterService(); | ||
60 | QDBusConnection::sessionBus().unregisterObject(devicePath.path()); | | |||
61 | Q_EMIT DeviceRemoved(devicePath); | | |||
62 | } | | |||
63 | qDeleteAll(m_devices); | 57 | qDeleteAll(m_devices); | ||
64 | | ||||
65 | delete m_settings; | 58 | delete m_settings; | ||
66 | QDBusConnection::sessionBus().unregisterObject(QLatin1Literal("/org/kde/fakenetwork/Settings")); | | |||
67 | QDBusConnection::sessionBus().unregisterObject(QLatin1Literal("/org/kde/fakenetwork")); | | |||
68 | QDBusConnection::sessionBus().unregisterService(QLatin1Literal("org.kde.fakenetwork")); | | |||
69 | } | 59 | } | ||
70 | 60 | | |||
71 | QDBusObjectPath FakeNetwork::activatingConnection() const | 61 | QDBusObjectPath FakeNetwork::activatingConnection() const | ||
72 | { | 62 | { | ||
73 | return m_activatingConnection; | 63 | return m_activatingConnection; | ||
74 | } | 64 | } | ||
75 | 65 | | |||
76 | QList< QDBusObjectPath > FakeNetwork::activeConnections() const | 66 | QList< QDBusObjectPath > FakeNetwork::activeConnections() const | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | |||||
194 | 184 | | |||
195 | void FakeNetwork::removeDevice(Device *device) | 185 | void FakeNetwork::removeDevice(Device *device) | ||
196 | { | 186 | { | ||
197 | m_devices.remove(QDBusObjectPath(device->devicePath())); | 187 | m_devices.remove(QDBusObjectPath(device->devicePath())); | ||
198 | QDBusConnection::sessionBus().unregisterObject(device->devicePath()); | 188 | QDBusConnection::sessionBus().unregisterObject(device->devicePath()); | ||
199 | Q_EMIT DeviceRemoved(QDBusObjectPath(device->devicePath())); | 189 | Q_EMIT DeviceRemoved(QDBusObjectPath(device->devicePath())); | ||
200 | } | 190 | } | ||
201 | 191 | | |||
192 | void FakeNetwork::registerService() | ||||
193 | { | ||||
194 | QDBusConnection::sessionBus().registerService(QLatin1Literal("org.kde.fakenetwork")); | ||||
195 | QDBusConnection::sessionBus().registerObject(QLatin1Literal("/org/kde/fakenetwork"), this, QDBusConnection::ExportScriptableContents); | ||||
196 | QDBusConnection::sessionBus().registerObject(QLatin1Literal("/org/kde/fakenetwork/Settings"), m_settings, QDBusConnection::ExportScriptableContents); | ||||
197 | | ||||
198 | Q_FOREACH (const QDBusObjectPath & devicePath, m_devices.keys()) { | ||||
199 | QDBusConnection::sessionBus().registerObject(devicePath.path(), m_devices.value(devicePath), QDBusConnection::ExportScriptableContents); | ||||
200 | Q_EMIT DeviceAdded(devicePath); | ||||
201 | } | ||||
202 | } | ||||
203 | | ||||
204 | void FakeNetwork::unregisterService() | ||||
205 | { | ||||
206 | Q_FOREACH (const QDBusObjectPath & devicePath, m_devices.keys()) { | ||||
207 | QDBusConnection::sessionBus().unregisterObject(devicePath.path()); | ||||
208 | Q_EMIT DeviceRemoved(devicePath); | ||||
209 | } | ||||
210 | | ||||
211 | QDBusConnection::sessionBus().unregisterObject(QLatin1Literal("/org/kde/fakenetwork/Settings")); | ||||
212 | QDBusConnection::sessionBus().unregisterObject(QLatin1Literal("/org/kde/fakenetwork")); | ||||
213 | QDBusConnection::sessionBus().unregisterService(QLatin1Literal("org.kde.fakenetwork")); | ||||
214 | } | ||||
215 | | ||||
202 | QDBusObjectPath FakeNetwork::ActivateConnection(const QDBusObjectPath &connection, const QDBusObjectPath &device, const QDBusObjectPath &specific_object) | 216 | QDBusObjectPath FakeNetwork::ActivateConnection(const QDBusObjectPath &connection, const QDBusObjectPath &device, const QDBusObjectPath &specific_object) | ||
203 | { | 217 | { | ||
204 | ActiveConnection *newActiveConnection = new ActiveConnection(this); | 218 | ActiveConnection *newActiveConnection = new ActiveConnection(this); | ||
205 | QString newActiveConnectionPath = QString("/org/kde/fakenetwork/ActiveConnection/") + QString::number(m_activeConnectionsCounter++); | 219 | QString newActiveConnectionPath = QString("/org/kde/fakenetwork/ActiveConnection/") + QString::number(m_activeConnectionsCounter++); | ||
206 | m_activeConnections.insert(QDBusObjectPath(newActiveConnectionPath), newActiveConnection); | 220 | m_activeConnections.insert(QDBusObjectPath(newActiveConnectionPath), newActiveConnection); | ||
207 | QDBusConnection::sessionBus().registerObject(newActiveConnectionPath, newActiveConnection, QDBusConnection::ExportScriptableContents); | 221 | QDBusConnection::sessionBus().registerObject(newActiveConnectionPath, newActiveConnection, QDBusConnection::ExportScriptableContents); | ||
208 | 222 | | |||
209 | m_activatingConnection = QDBusObjectPath(newActiveConnectionPath); | 223 | m_activatingConnection = QDBusObjectPath(newActiveConnectionPath); | ||
▲ Show 20 Lines • Show All 246 Lines • Show Last 20 Lines |