Changeset View
Changeset View
Standalone View
Standalone View
libs/handler.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
56 | #include <KWindowSystem> | 56 | #include <KWindowSystem> | ||
57 | #include <KIconLoader> | 57 | #include <KIconLoader> | ||
58 | #include <KWallet> | 58 | #include <KWallet> | ||
59 | 59 | | |||
60 | #define AGENT_SERVICE "org.kde.kded5" | 60 | #define AGENT_SERVICE "org.kde.kded5" | ||
61 | #define AGENT_PATH "/modules/networkmanagement" | 61 | #define AGENT_PATH "/modules/networkmanagement" | ||
62 | #define AGENT_IFACE "org.kde.plasmanetworkmanagement" | 62 | #define AGENT_IFACE "org.kde.plasmanetworkmanagement" | ||
63 | 63 | | |||
64 | 64 | | |||
jgrulich: It doesn't need to be in namespace. | |||||
65 | Handler::Handler(QObject *parent) | 65 | Handler::Handler(QObject *parent) | ||
66 | : QObject(parent) | 66 | : QObject(parent) | ||
67 | , m_tmpWirelessEnabled(NetworkManager::isWirelessEnabled()) | 67 | , m_tmpWirelessEnabled(NetworkManager::isWirelessEnabled()) | ||
68 | , m_tmpWwanEnabled(NetworkManager::isWwanEnabled()) | 68 | , m_tmpWwanEnabled(NetworkManager::isWwanEnabled()) | ||
69 | { | 69 | { | ||
70 | initKdedModule(); | 70 | initKdedModule(); | ||
71 | QDBusConnection::sessionBus().connect(QStringLiteral(AGENT_SERVICE), | 71 | QDBusConnection::sessionBus().connect(QStringLiteral(AGENT_SERVICE), | ||
72 | QStringLiteral(AGENT_PATH), | 72 | QStringLiteral(AGENT_PATH), | ||
73 | QStringLiteral(AGENT_IFACE), | 73 | QStringLiteral(AGENT_IFACE), | ||
74 | QStringLiteral("registered"), | 74 | QStringLiteral("registered"), | ||
75 | this, SLOT(initKdedModule())); | 75 | this, SLOT(initKdedModule())); | ||
76 | | ||||
77 | // Interval (in ms) between attempts to scan for wifi networks | ||||
78 | m_wirelessScanRetryTimer.setInterval(2000); | ||||
79 | m_wirelessScanRetryTimer.setSingleShot(true); | ||||
76 | } | 80 | } | ||
77 | 81 | | |||
78 | Handler::~Handler() | 82 | Handler::~Handler() | ||
79 | { | 83 | { | ||
80 | } | 84 | } | ||
81 | 85 | | |||
82 | void Handler::activateConnection(const QString& connection, const QString& device, const QString& specificObject) | 86 | void Handler::activateConnection(const QString& connection, const QString& device, const QString& specificObject) | ||
83 | { | 87 | { | ||
▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Line(s) | |||||
403 | { | 407 | { | ||
404 | QDBusPendingReply<> reply = connection->update(map); | 408 | QDBusPendingReply<> reply = connection->update(map); | ||
405 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | 409 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||
406 | watcher->setProperty("action", UpdateConnection); | 410 | watcher->setProperty("action", UpdateConnection); | ||
407 | watcher->setProperty("connection", connection->name()); | 411 | watcher->setProperty("connection", connection->name()); | ||
408 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | 412 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | ||
409 | } | 413 | } | ||
410 | 414 | | |||
411 | void Handler::requestScan() | 415 | void Handler::requestScan(const QString &interface) | ||
412 | { | 416 | { | ||
413 | for (NetworkManager::Device::Ptr device : NetworkManager::networkInterfaces()) { | 417 | for (NetworkManager::Device::Ptr device : NetworkManager::networkInterfaces()) { | ||
414 | if (device->type() == NetworkManager::Device::Wifi) { | 418 | if (device->type() == NetworkManager::Device::Wifi) { | ||
415 | NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast<NetworkManager::WirelessDevice>(); | 419 | NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast<NetworkManager::WirelessDevice>(); | ||
416 | if (wifiDevice) { | 420 | if (wifiDevice) { | ||
421 | if (!interface.isEmpty() && interface != wifiDevice->interfaceName()) { | ||||
422 | continue; | ||||
423 | } | ||||
424 | qCDebug(PLASMA_NM) << "Requesting wifi scan on device" << wifiDevice->interfaceName(); | ||||
417 | QDBusPendingReply<> reply = wifiDevice->requestScan(); | 425 | QDBusPendingReply<> reply = wifiDevice->requestScan(); | ||
418 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | 426 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||
419 | watcher->setProperty("action", Handler::RequestScan); | 427 | watcher->setProperty("action", Handler::RequestScan); | ||
428 | watcher->setProperty("interface", wifiDevice->interfaceName()); | ||||
420 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | 429 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | ||
421 | } | 430 | } | ||
422 | } | 431 | } | ||
423 | } | 432 | } | ||
424 | } | 433 | } | ||
425 | 434 | | |||
435 | void Handler::scanRequestFailed(const QString &interface) | ||||
436 | { | ||||
437 | if (m_wirelessScanRetryTimer.isActive()) { | ||||
438 | return; | ||||
439 | } | ||||
440 | qCDebug(PLASMA_NM) << "Trying soon a new scan on" << interface; | ||||
441 | | ||||
This is Qt 5.12 only, Plasma 5.16 is going to depend on it so if you plan to you this, you should bump required Qt version. jgrulich: This is Qt 5.12 only, Plasma 5.16 is going to depend on it so if you plan to you this, you… | |||||
442 | emit wirelessScanTimerEnabled(false); | ||||
443 | | ||||
444 | auto retryAction = [this,interface]() { | ||||
445 | m_wirelessScanRetryTimer.disconnect(); | ||||
446 | requestScan(interface); | ||||
447 | }; | ||||
448 | connect(&m_wirelessScanRetryTimer, &QTimer::timeout, this, retryAction); | ||||
449 | m_wirelessScanRetryTimer.start(); | ||||
450 | } | ||||
451 | | ||||
426 | void Handler::initKdedModule() | 452 | void Handler::initKdedModule() | ||
427 | { | 453 | { | ||
428 | QDBusMessage initMsg = QDBusMessage::createMethodCall(QStringLiteral(AGENT_SERVICE), | 454 | QDBusMessage initMsg = QDBusMessage::createMethodCall(QStringLiteral(AGENT_SERVICE), | ||
429 | QStringLiteral(AGENT_PATH), | 455 | QStringLiteral(AGENT_PATH), | ||
430 | QStringLiteral(AGENT_IFACE), | 456 | QStringLiteral(AGENT_IFACE), | ||
431 | QStringLiteral("init")); | 457 | QStringLiteral("init")); | ||
432 | QDBusConnection::sessionBus().send(initMsg); | 458 | QDBusConnection::sessionBus().send(initMsg); | ||
433 | } | 459 | } | ||
Show All 21 Lines | 468 | switch (action) { | |||
455 | case Handler::DeactivateConnection: | 481 | case Handler::DeactivateConnection: | ||
456 | notification = new KNotification("FailedToDeactivateConnection", KNotification::CloseOnTimeout, this); | 482 | notification = new KNotification("FailedToDeactivateConnection", KNotification::CloseOnTimeout, this); | ||
457 | notification->setTitle(i18n("Failed to deactivate %1", watcher->property("connection").toString())); | 483 | notification->setTitle(i18n("Failed to deactivate %1", watcher->property("connection").toString())); | ||
458 | break; | 484 | break; | ||
459 | case Handler::RemoveConnection: | 485 | case Handler::RemoveConnection: | ||
460 | notification = new KNotification("FailedToRemoveConnection", KNotification::CloseOnTimeout, this); | 486 | notification = new KNotification("FailedToRemoveConnection", KNotification::CloseOnTimeout, this); | ||
461 | notification->setTitle(i18n("Failed to remove %1", watcher->property("connection").toString())); | 487 | notification->setTitle(i18n("Failed to remove %1", watcher->property("connection").toString())); | ||
462 | break; | 488 | break; | ||
463 | case Handler::RequestScan: | | |||
464 | /* INFO: Disabled for now as wifi scanning is now automatic | | |||
465 | notification = new KNotification("FailedToRequestScan", KNotification::CloseOnTimeout, this); | | |||
466 | notification->setTitle(i18n("Failed to request scan")); | | |||
467 | */ | | |||
468 | break; | | |||
469 | case Handler::UpdateConnection: | 489 | case Handler::UpdateConnection: | ||
470 | notification = new KNotification("FailedToUpdateConnection", KNotification::CloseOnTimeout, this); | 490 | notification = new KNotification("FailedToUpdateConnection", KNotification::CloseOnTimeout, this); | ||
471 | notification->setTitle(i18n("Failed to update connection %1", watcher->property("connection").toString())); | 491 | notification->setTitle(i18n("Failed to update connection %1", watcher->property("connection").toString())); | ||
472 | break; | 492 | break; | ||
493 | case Handler::RequestScan: | ||||
494 | { | ||||
495 | const QString interface = watcher->property("interface").toString(); | ||||
496 | qCDebug(PLASMA_NM) << "Wireless scan on" << interface << "failed:" << error; | ||||
497 | scanRequestFailed(interface); | ||||
498 | break; | ||||
499 | } | ||||
473 | default: | 500 | default: | ||
474 | break; | 501 | break; | ||
475 | } | 502 | } | ||
476 | 503 | | |||
477 | if (notification) { | 504 | if (notification) { | ||
478 | notification->setComponentName("networkmanagement"); | 505 | notification->setComponentName("networkmanagement"); | ||
479 | notification->setText(error); | 506 | notification->setText(error); | ||
480 | notification->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeHuge)); | 507 | notification->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeHuge)); | ||
Show All 11 Lines | 514 | switch (action) { | |||
492 | case Handler::RemoveConnection: | 519 | case Handler::RemoveConnection: | ||
493 | notification = new KNotification("ConnectionRemoved", KNotification::CloseOnTimeout, this); | 520 | notification = new KNotification("ConnectionRemoved", KNotification::CloseOnTimeout, this); | ||
494 | notification->setText(i18n("Connection %1 has been removed", watcher->property("connection").toString())); | 521 | notification->setText(i18n("Connection %1 has been removed", watcher->property("connection").toString())); | ||
495 | break; | 522 | break; | ||
496 | case Handler::UpdateConnection: | 523 | case Handler::UpdateConnection: | ||
497 | notification = new KNotification("ConnectionUpdated", KNotification::CloseOnTimeout, this); | 524 | notification = new KNotification("ConnectionUpdated", KNotification::CloseOnTimeout, this); | ||
498 | notification->setText(i18n("Connection %1 has been updated", watcher->property("connection").toString())); | 525 | notification->setText(i18n("Connection %1 has been updated", watcher->property("connection").toString())); | ||
499 | break; | 526 | break; | ||
527 | case Handler::RequestScan: | ||||
528 | qCDebug(PLASMA_NM) << "Wireless scan on" << watcher->property("interface").toString() << "succeeded"; | ||||
529 | emit wirelessScanTimerEnabled(true); | ||||
530 | break; | ||||
500 | default: | 531 | default: | ||
501 | break; | 532 | break; | ||
502 | } | 533 | } | ||
503 | 534 | | |||
504 | if (notification) { | 535 | if (notification) { | ||
505 | notification->setComponentName("networkmanagement"); | 536 | notification->setComponentName("networkmanagement"); | ||
506 | notification->setTitle(watcher->property("connection").toString()); | 537 | notification->setTitle(watcher->property("connection").toString()); | ||
507 | notification->setPixmap(QIcon::fromTheme("dialog-information").pixmap(KIconLoader::SizeHuge)); | 538 | notification->setPixmap(QIcon::fromTheme("dialog-information").pixmap(KIconLoader::SizeHuge)); | ||
Show All 16 Lines |
It doesn't need to be in namespace.