Changeset View
Changeset View
Standalone View
Standalone View
core/daemon.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 72 | else { | |||
---|---|---|---|---|---|
73 | d->mLinkProviders.insert(new LanLinkProvider()); | 73 | d->mLinkProviders.insert(new LanLinkProvider()); | ||
74 | #ifdef KDECONNECT_BLUETOOTH | 74 | #ifdef KDECONNECT_BLUETOOTH | ||
75 | d->mLinkProviders.insert(new BluetoothLinkProvider()); | 75 | d->mLinkProviders.insert(new BluetoothLinkProvider()); | ||
76 | #endif | 76 | #endif | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | //Read remebered paired devices | 79 | //Read remebered paired devices | ||
80 | const QStringList& list = KdeConnectConfig::instance()->trustedDevices(); | 80 | const QStringList& list = KdeConnectConfig::instance()->trustedDevices(); | ||
81 | Q_FOREACH (const QString& id, list) { | 81 | for (const QString& id : list) { | ||
82 | addDevice(new Device(this, id)); | 82 | addDevice(new Device(this, id)); | ||
83 | } | 83 | } | ||
84 | 84 | | |||
85 | //Listen to new devices | 85 | //Listen to new devices | ||
86 | Q_FOREACH (LinkProvider* a, d->mLinkProviders) { | 86 | for (LinkProvider* a : qAsConst(d->mLinkProviders)) { | ||
87 | connect(a, &LinkProvider::onConnectionReceived, | 87 | connect(a, &LinkProvider::onConnectionReceived, | ||
88 | this, &Daemon::onNewDeviceLink); | 88 | this, &Daemon::onNewDeviceLink); | ||
89 | a->onStart(); | 89 | a->onStart(); | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | //Register on DBus | 92 | //Register on DBus | ||
93 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect")); | 93 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect")); | ||
94 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents); | 94 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents); | ||
Show All 27 Lines | |||||
122 | { | 122 | { | ||
123 | d->mDevices.remove(device->id()); | 123 | d->mDevices.remove(device->id()); | ||
124 | device->deleteLater(); | 124 | device->deleteLater(); | ||
125 | Q_EMIT deviceRemoved(device->id()); | 125 | Q_EMIT deviceRemoved(device->id()); | ||
126 | } | 126 | } | ||
127 | 127 | | |||
128 | void Daemon::cleanDevices() | 128 | void Daemon::cleanDevices() | ||
129 | { | 129 | { | ||
130 | Q_FOREACH (Device* device, d->mDevices) { | 130 | for (Device* device : qAsConst(d->mDevices)) { | ||
131 | if (device->isTrusted()) { | 131 | if (device->isTrusted()) { | ||
132 | continue; | 132 | continue; | ||
133 | } | 133 | } | ||
134 | device->cleanUnneededLinks(); | 134 | device->cleanUnneededLinks(); | ||
135 | //If there are no links remaining | 135 | //If there are no links remaining | ||
136 | if (!device->isReachable()) { | 136 | if (!device->isReachable()) { | ||
137 | removeDevice(device); | 137 | removeDevice(device); | ||
138 | } | 138 | } | ||
139 | } | 139 | } | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | void Daemon::forceOnNetworkChange() | 142 | void Daemon::forceOnNetworkChange() | ||
143 | { | 143 | { | ||
144 | qCDebug(KDECONNECT_CORE) << "Sending onNetworkChange to " << d->mLinkProviders.size() << " LinkProviders"; | 144 | qCDebug(KDECONNECT_CORE) << "Sending onNetworkChange to " << d->mLinkProviders.size() << " LinkProviders"; | ||
145 | Q_FOREACH (LinkProvider* a, d->mLinkProviders) { | 145 | for (LinkProvider* a : qAsConst(d->mLinkProviders)) { | ||
146 | a->onNetworkChange(); | 146 | a->onNetworkChange(); | ||
147 | } | 147 | } | ||
148 | } | 148 | } | ||
149 | 149 | | |||
150 | Device*Daemon::getDevice(const QString& deviceId) | 150 | Device*Daemon::getDevice(const QString& deviceId) | ||
151 | { | 151 | { | ||
152 | Q_FOREACH (Device* device, d->mDevices) { | 152 | for (Device* device : qAsConst(d->mDevices)) { | ||
153 | if (device->id() == deviceId) { | 153 | if (device->id() == deviceId) { | ||
154 | return device; | 154 | return device; | ||
155 | } | 155 | } | ||
156 | } | 156 | } | ||
157 | return Q_NULLPTR; | 157 | return Q_NULLPTR; | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | QStringList Daemon::devices(bool onlyReachable, bool onlyTrusted) const | 160 | QStringList Daemon::devices(bool onlyReachable, bool onlyTrusted) const | ||
161 | { | 161 | { | ||
162 | QStringList ret; | 162 | QStringList ret; | ||
163 | Q_FOREACH (Device* device, d->mDevices) { | 163 | for (Device* device : qAsConst(d->mDevices)) { | ||
164 | if (onlyReachable && !device->isReachable()) continue; | 164 | if (onlyReachable && !device->isReachable()) continue; | ||
165 | if (onlyTrusted && !device->isTrusted()) continue; | 165 | if (onlyTrusted && !device->isTrusted()) continue; | ||
166 | ret.append(device->id()); | 166 | ret.append(device->id()); | ||
167 | } | 167 | } | ||
168 | return ret; | 168 | return ret; | ||
169 | } | 169 | } | ||
170 | 170 | | |||
171 | void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl) | 171 | void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl) | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
239 | 239 | | |||
240 | bool Daemon::isDiscoveringDevices() const | 240 | bool Daemon::isDiscoveringDevices() const | ||
241 | { | 241 | { | ||
242 | return !d->mDiscoveryModeAcquisitions.isEmpty(); | 242 | return !d->mDiscoveryModeAcquisitions.isEmpty(); | ||
243 | } | 243 | } | ||
244 | 244 | | |||
245 | QString Daemon::deviceIdByName(const QString &name) const | 245 | QString Daemon::deviceIdByName(const QString &name) const | ||
246 | { | 246 | { | ||
247 | Q_FOREACH (Device* d, d->mDevices) { | 247 | for (Device* device : qAsConst(d->mDevices)) { | ||
248 | if (d->name() == name && d->isTrusted()) | 248 | if (device->name() == name && device->isTrusted()) | ||
249 | return d->id(); | 249 | return device->id(); | ||
250 | } | 250 | } | ||
251 | return {}; | 251 | return {}; | ||
252 | } | 252 | } | ||
253 | 253 | | |||
254 | void Daemon::addDevice(Device* device) | 254 | void Daemon::addDevice(Device* device) | ||
255 | { | 255 | { | ||
256 | const QString id = device->id(); | 256 | const QString id = device->id(); | ||
257 | connect(device, &Device::reachableChanged, this, &Daemon::onDeviceStatusChanged); | 257 | connect(device, &Device::reachableChanged, this, &Daemon::onDeviceStatusChanged); | ||
Show All 30 Lines |