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 184 185
|
From 6e0dca97028b8c269510904e3f4eafdb12f400d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luis=20B=C3=BCchi?= <luis.buechi@server23.cc>
Date: Fri, 25 Apr 2025 10:12:10 +0200
Subject: [PATCH] mmplugin: Make calls nonblocking to not freeze UI when called
replaces the blocking `reply.waitForFinished` calls with QCoro asynchronous await calls.
---
components/mmplugin/CMakeLists.txt | 1 +
components/mmplugin/signalindicator.cpp | 53 ++++++++++++-------------
components/mmplugin/signalindicator.h | 9 +++--
3 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/components/mmplugin/CMakeLists.txt b/components/mmplugin/CMakeLists.txt
index ec4fb882b..9b739fbb4 100644
--- a/components/mmplugin/CMakeLists.txt
+++ b/components/mmplugin/CMakeLists.txt
@@ -14,6 +14,7 @@ target_link_libraries(ppc-mmqmlplugin PRIVATE
KF6::NetworkManagerQt
KF6::CoreAddons
KF6::I18n
+ QCoro::DBus
)
diff --git a/components/mmplugin/signalindicator.cpp b/components/mmplugin/signalindicator.cpp
index 226d733b4..0ff27e092 100644
--- a/components/mmplugin/signalindicator.cpp
+++ b/components/mmplugin/signalindicator.cpp
@@ -8,6 +8,7 @@
#include <NetworkManagerQt/Manager>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/Utils>
+#include <QDBusReply>
#include <KUser>
@@ -197,11 +198,11 @@ void SignalIndicator::refreshProfiles()
Q_EMIT profileListChanged();
}
-void SignalIndicator::activateProfile(const QString &connectionUni)
+QCoro::Task<void> SignalIndicator::activateProfile(const QString &connectionUni)
{
if (!m_nmModem) {
qWarning() << "Cannot activate profile since there is no NetworkManager modem";
- return;
+ co_return;
}
qDebug() << QStringLiteral("Activating profile on modem") << m_nmModem->uni() << QStringLiteral("for connection") << connectionUni << ".";
@@ -220,24 +221,23 @@ void SignalIndicator::activateProfile(const QString &connectionUni)
if (!con) {
qDebug() << QStringLiteral("Connection") << connectionUni << QStringLiteral("not found.");
- return;
+ co_return;
}
// activate connection manually
// despite the documentation saying otherwise, activateConnection seems to need the DBus path, not uuid of the connection
- QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::activateConnection(con->path(), m_nmModem->uni(), {});
- reply.waitForFinished();
- if (reply.isError()) {
+ QDBusReply<QDBusObjectPath> reply = co_await NetworkManager::activateConnection(con->path(), m_nmModem->uni(), {});
+ if (!reply.isValid()) {
qWarning() << QStringLiteral("Error activating connection:") << reply.error().message();
- return;
+ co_return;
}
}
-void SignalIndicator::addProfile(const QString &name, const QString &apn, const QString &username, const QString &password, const QString &networkType)
+QCoro::Task<void> SignalIndicator::addProfile(const QString &name, const QString &apn, const QString &username, const QString &password, const QString &networkType)
{
if (!m_nmModem) {
qWarning() << "Cannot add profile since there is no NetworkManager modem";
- return;
+ co_return;
}
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Gsm)};
@@ -255,47 +255,45 @@ void SignalIndicator::addProfile(const QString &name, const QString &apn, const
gsmSetting->setInitialized(true);
- QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::addAndActivateConnection(settings->toMap(), m_nmModem->uni(), {});
- reply.waitForFinished();
- if (reply.isError()) {
+ QDBusReply<QDBusObjectPath> reply = co_await NetworkManager::addAndActivateConnection(settings->toMap(), m_nmModem->uni(), {});
+ if (!reply.isValid()) {
qWarning() << "Error adding connection:" << reply.error().message();
} else {
qDebug() << "Successfully added a new connection" << name << "with APN" << apn << ".";
}
}
-void SignalIndicator::removeProfile(const QString &connectionUni)
+QCoro::Task<void> SignalIndicator::removeProfile(const QString &connectionUni)
{
NetworkManager::Connection::Ptr con = NetworkManager::findConnectionByUuid(connectionUni);
if (!con) {
qWarning() << "Could not find connection" << connectionUni << "to update!";
- return;
+ co_return;
}
- QDBusPendingReply reply = con->remove();
- reply.waitForFinished();
- if (reply.isError()) {
+ QDBusPendingReply reply = co_await con->remove();
+ if (!reply.isValid()) {
qWarning() << "Error removing connection" << reply.error().message();
}
}
-void SignalIndicator::updateProfile(const QString &connectionUni,
- const QString &name,
- const QString &apn,
- const QString &username,
- const QString &password,
- const QString &networkType)
+QCoro::Task<void> SignalIndicator::updateProfile(const QString &connectionUni,
+ const QString &name,
+ const QString &apn,
+ const QString &username,
+ const QString &password,
+ const QString &networkType)
{
NetworkManager::Connection::Ptr con = NetworkManager::findConnectionByUuid(connectionUni);
if (!con) {
qWarning() << "Could not find connection" << connectionUni << "to update!";
- return;
+ co_return;
}
NetworkManager::ConnectionSettings::Ptr conSettings = con->settings();
if (!conSettings) {
qWarning() << "Could not find connection settings for" << connectionUni << "to update!";
- return;
+ co_return;
}
conSettings->setId(name);
@@ -309,9 +307,8 @@ void SignalIndicator::updateProfile(const QString &connectionUni,
gsmSetting->setInitialized(true);
- QDBusPendingReply reply = con->update(conSettings->toMap());
- reply.waitForFinished();
- if (reply.isError()) {
+ QDBusPendingReply reply = co_await con->update(conSettings->toMap());
+ if (!reply.isValid()) {
qWarning() << "Error updating connection settings for" << connectionUni << ":" << reply.error().message() << ".";
} else {
qDebug() << "Successfully updated connection settings" << connectionUni << ".";
diff --git a/components/mmplugin/signalindicator.h b/components/mmplugin/signalindicator.h
index b17ba7834..77af2cda9 100644
--- a/components/mmplugin/signalindicator.h
+++ b/components/mmplugin/signalindicator.h
@@ -9,6 +9,7 @@
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ModemDevice>
+#include <QCoroDBusPendingReply>
#include <QObject>
#include <qqmlregistration.h>
@@ -53,10 +54,10 @@ public:
// connection profiles
QList<ProfileSettings *> &profileList();
void refreshProfiles();
- Q_INVOKABLE void activateProfile(const QString &connectionUni);
- Q_INVOKABLE void addProfile(const QString &name, const QString &apn, const QString &username, const QString &password, const QString &networkType);
- Q_INVOKABLE void removeProfile(const QString &connectionUni);
- Q_INVOKABLE void updateProfile(const QString &connectionUni,
+ Q_INVOKABLE QCoro::Task<void> activateProfile(const QString &connectionUni);
+ Q_INVOKABLE QCoro::Task<void> addProfile(const QString &name, const QString &apn, const QString &username, const QString &password, const QString &networkType);
+ Q_INVOKABLE QCoro::Task<void> removeProfile(const QString &connectionUni);
+ Q_INVOKABLE QCoro::Task<void> updateProfile(const QString &connectionUni,
const QString &name,
const QString &apn,
const QString &username,
--
GitLab
|