mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
mmplugin: Make calls nonblocking to not freeze UI when called
replaces the blocking `reply.waitForFinished` calls with QCoro asynchronous await calls.
This commit is contained in:
parent
64a81e5918
commit
6e0dca9702
3 changed files with 31 additions and 32 deletions
|
|
@ -14,6 +14,7 @@ target_link_libraries(ppc-mmqmlplugin PRIVATE
|
||||||
KF6::NetworkManagerQt
|
KF6::NetworkManagerQt
|
||||||
KF6::CoreAddons
|
KF6::CoreAddons
|
||||||
KF6::I18n
|
KF6::I18n
|
||||||
|
QCoro::DBus
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <NetworkManagerQt/Manager>
|
#include <NetworkManagerQt/Manager>
|
||||||
#include <NetworkManagerQt/Settings>
|
#include <NetworkManagerQt/Settings>
|
||||||
#include <NetworkManagerQt/Utils>
|
#include <NetworkManagerQt/Utils>
|
||||||
|
#include <QDBusReply>
|
||||||
|
|
||||||
#include <KUser>
|
#include <KUser>
|
||||||
|
|
||||||
|
|
@ -197,11 +198,11 @@ void SignalIndicator::refreshProfiles()
|
||||||
Q_EMIT profileListChanged();
|
Q_EMIT profileListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalIndicator::activateProfile(const QString &connectionUni)
|
QCoro::Task<void> SignalIndicator::activateProfile(const QString &connectionUni)
|
||||||
{
|
{
|
||||||
if (!m_nmModem) {
|
if (!m_nmModem) {
|
||||||
qWarning() << "Cannot activate profile since there is no NetworkManager modem";
|
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 << ".";
|
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) {
|
if (!con) {
|
||||||
qDebug() << QStringLiteral("Connection") << connectionUni << QStringLiteral("not found.");
|
qDebug() << QStringLiteral("Connection") << connectionUni << QStringLiteral("not found.");
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// activate connection manually
|
// activate connection manually
|
||||||
// despite the documentation saying otherwise, activateConnection seems to need the DBus path, not uuid of the connection
|
// 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(), {});
|
QDBusReply<QDBusObjectPath> reply = co_await NetworkManager::activateConnection(con->path(), m_nmModem->uni(), {});
|
||||||
reply.waitForFinished();
|
if (!reply.isValid()) {
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << QStringLiteral("Error activating connection:") << reply.error().message();
|
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) {
|
if (!m_nmModem) {
|
||||||
qWarning() << "Cannot add profile since there is no NetworkManager modem";
|
qWarning() << "Cannot add profile since there is no NetworkManager modem";
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Gsm)};
|
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Gsm)};
|
||||||
|
|
@ -255,31 +255,29 @@ void SignalIndicator::addProfile(const QString &name, const QString &apn, const
|
||||||
|
|
||||||
gsmSetting->setInitialized(true);
|
gsmSetting->setInitialized(true);
|
||||||
|
|
||||||
QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::addAndActivateConnection(settings->toMap(), m_nmModem->uni(), {});
|
QDBusReply<QDBusObjectPath> reply = co_await NetworkManager::addAndActivateConnection(settings->toMap(), m_nmModem->uni(), {});
|
||||||
reply.waitForFinished();
|
if (!reply.isValid()) {
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "Error adding connection:" << reply.error().message();
|
qWarning() << "Error adding connection:" << reply.error().message();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Successfully added a new connection" << name << "with APN" << apn << ".";
|
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);
|
NetworkManager::Connection::Ptr con = NetworkManager::findConnectionByUuid(connectionUni);
|
||||||
if (!con) {
|
if (!con) {
|
||||||
qWarning() << "Could not find connection" << connectionUni << "to update!";
|
qWarning() << "Could not find connection" << connectionUni << "to update!";
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusPendingReply reply = con->remove();
|
QDBusPendingReply reply = co_await con->remove();
|
||||||
reply.waitForFinished();
|
if (!reply.isValid()) {
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "Error removing connection" << reply.error().message();
|
qWarning() << "Error removing connection" << reply.error().message();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalIndicator::updateProfile(const QString &connectionUni,
|
QCoro::Task<void> SignalIndicator::updateProfile(const QString &connectionUni,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const QString &apn,
|
const QString &apn,
|
||||||
const QString &username,
|
const QString &username,
|
||||||
|
|
@ -289,13 +287,13 @@ void SignalIndicator::updateProfile(const QString &connectionUni,
|
||||||
NetworkManager::Connection::Ptr con = NetworkManager::findConnectionByUuid(connectionUni);
|
NetworkManager::Connection::Ptr con = NetworkManager::findConnectionByUuid(connectionUni);
|
||||||
if (!con) {
|
if (!con) {
|
||||||
qWarning() << "Could not find connection" << connectionUni << "to update!";
|
qWarning() << "Could not find connection" << connectionUni << "to update!";
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkManager::ConnectionSettings::Ptr conSettings = con->settings();
|
NetworkManager::ConnectionSettings::Ptr conSettings = con->settings();
|
||||||
if (!conSettings) {
|
if (!conSettings) {
|
||||||
qWarning() << "Could not find connection settings for" << connectionUni << "to update!";
|
qWarning() << "Could not find connection settings for" << connectionUni << "to update!";
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
conSettings->setId(name);
|
conSettings->setId(name);
|
||||||
|
|
@ -309,9 +307,8 @@ void SignalIndicator::updateProfile(const QString &connectionUni,
|
||||||
|
|
||||||
gsmSetting->setInitialized(true);
|
gsmSetting->setInitialized(true);
|
||||||
|
|
||||||
QDBusPendingReply reply = con->update(conSettings->toMap());
|
QDBusPendingReply reply = co_await con->update(conSettings->toMap());
|
||||||
reply.waitForFinished();
|
if (!reply.isValid()) {
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "Error updating connection settings for" << connectionUni << ":" << reply.error().message() << ".";
|
qWarning() << "Error updating connection settings for" << connectionUni << ":" << reply.error().message() << ".";
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Successfully updated connection settings" << connectionUni << ".";
|
qDebug() << "Successfully updated connection settings" << connectionUni << ".";
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <NetworkManagerQt/Connection>
|
#include <NetworkManagerQt/Connection>
|
||||||
#include <NetworkManagerQt/ModemDevice>
|
#include <NetworkManagerQt/ModemDevice>
|
||||||
|
#include <QCoroDBusPendingReply>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <qqmlregistration.h>
|
#include <qqmlregistration.h>
|
||||||
|
|
@ -53,10 +54,10 @@ public:
|
||||||
// connection profiles
|
// connection profiles
|
||||||
QList<ProfileSettings *> &profileList();
|
QList<ProfileSettings *> &profileList();
|
||||||
void refreshProfiles();
|
void refreshProfiles();
|
||||||
Q_INVOKABLE void activateProfile(const QString &connectionUni);
|
Q_INVOKABLE QCoro::Task<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 QCoro::Task<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 QCoro::Task<void> removeProfile(const QString &connectionUni);
|
||||||
Q_INVOKABLE void updateProfile(const QString &connectionUni,
|
Q_INVOKABLE QCoro::Task<void> updateProfile(const QString &connectionUni,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const QString &apn,
|
const QString &apn,
|
||||||
const QString &username,
|
const QString &username,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue