mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kutils: rework KNetworkManager connections management to enable/disable all
use case? what will happen if network status changes while plasma folderview applet is showing a folder Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
91368392ee
commit
40e0c3f167
2 changed files with 61 additions and 83 deletions
|
@ -35,15 +35,15 @@
|
||||||
|
|
||||||
typedef QMap<QString,QVariant> ConnmanPropertiesType;
|
typedef QMap<QString,QVariant> ConnmanPropertiesType;
|
||||||
|
|
||||||
struct ConnmanServicesType
|
struct ConnmanServiceType
|
||||||
{
|
{
|
||||||
QDBusObjectPath service_object;
|
QDBusObjectPath service_object;
|
||||||
QVariantMap service_dict;
|
QVariantMap service_dict;
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(ConnmanServicesType);
|
Q_DECLARE_METATYPE(ConnmanServiceType);
|
||||||
Q_DECLARE_METATYPE(QList<ConnmanServicesType>);
|
Q_DECLARE_METATYPE(QList<ConnmanServiceType>);
|
||||||
|
|
||||||
QDBusArgument& operator<<(QDBusArgument &argument, const ConnmanServicesType &connmanservice)
|
QDBusArgument& operator<<(QDBusArgument &argument, const ConnmanServiceType &connmanservice)
|
||||||
{
|
{
|
||||||
argument.beginStructure();
|
argument.beginStructure();
|
||||||
argument << connmanservice.service_object;
|
argument << connmanservice.service_object;
|
||||||
|
@ -52,7 +52,7 @@ QDBusArgument& operator<<(QDBusArgument &argument, const ConnmanServicesType &co
|
||||||
return argument;
|
return argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QDBusArgument& operator>>(const QDBusArgument &argument, ConnmanServicesType &connmanservice)
|
const QDBusArgument& operator>>(const QDBusArgument &argument, ConnmanServiceType &connmanservice)
|
||||||
{
|
{
|
||||||
argument.beginStructure();
|
argument.beginStructure();
|
||||||
argument >> connmanservice.service_object;
|
argument >> connmanservice.service_object;
|
||||||
|
@ -70,8 +70,7 @@ public:
|
||||||
~KNetworkManagerPrivate();
|
~KNetworkManagerPrivate();
|
||||||
|
|
||||||
KNetworkManager::KNetworkStatus status() const;
|
KNetworkManager::KNetworkStatus status() const;
|
||||||
QList<KNetworkConnection> connections() const;
|
bool enable(const bool enable);
|
||||||
bool enable(const QString &name, const bool enable);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QObject reimplementation
|
// QObject reimplementation
|
||||||
|
@ -108,8 +107,8 @@ KNetworkManagerPrivate::KNetworkManagerPrivate(KNetworkManager *parent)
|
||||||
);
|
);
|
||||||
} else if (m_cm.isValid()) {
|
} else if (m_cm.isValid()) {
|
||||||
kDebug() << "Using net.connman";
|
kDebug() << "Using net.connman";
|
||||||
qDBusRegisterMetaType<ConnmanServicesType>();
|
qDBusRegisterMetaType<ConnmanServiceType>();
|
||||||
qDBusRegisterMetaType<QList<ConnmanServicesType>>();
|
qDBusRegisterMetaType<QList<ConnmanServiceType>>();
|
||||||
connect(
|
connect(
|
||||||
&m_cm, SIGNAL(PropertyChanged(QString,QDBusVariant)),
|
&m_cm, SIGNAL(PropertyChanged(QString,QDBusVariant)),
|
||||||
this, SLOT(cmStateChanged(QString,QDBusVariant))
|
this, SLOT(cmStateChanged(QString,QDBusVariant))
|
||||||
|
@ -206,60 +205,61 @@ KNetworkManager::KNetworkStatus KNetworkManagerPrivate::status() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<KNetworkConnection> KNetworkManagerPrivate::connections() const
|
bool KNetworkManagerPrivate::enable(const bool enable)
|
||||||
{
|
{
|
||||||
QList<KNetworkConnection> result;
|
if (m_nm.isValid()) {
|
||||||
if (!m_cm.isValid()) {
|
bool result = false;
|
||||||
kDebug() << "Connection management not supported";
|
QDBusReply<void> nmenablereply = m_nm.call("Enable", enable);
|
||||||
|
result = nmenablereply.isValid();
|
||||||
|
if (!result) {
|
||||||
|
kWarning() << "Invalid org.freedesktop.NetworkManager reply" << nmenablereply.error();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (enable) {
|
||||||
|
kDebug() << "Done enabling org.freedesktop.NetworkManager connections" << result;
|
||||||
|
} else {
|
||||||
|
kDebug() << "Done disabling org.freedesktop.NetworkManager connections" << result;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
QDBusReply<QList<ConnmanServicesType>> cmreply = m_cm.call("GetServices");
|
|
||||||
if (!cmreply.isValid()) {
|
|
||||||
kWarning() << "Invalid reply" << cmreply.error();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
const QList<ConnmanServicesType> cmvalue = cmreply.value();
|
|
||||||
foreach (const ConnmanServicesType &cmservice, cmvalue) {
|
|
||||||
KNetworkConnection knetworkconnection;
|
|
||||||
knetworkconnection.name = cmservice.service_dict.value(QLatin1String("Name")).toString();
|
|
||||||
knetworkconnection.dbuspath = cmservice.service_object.path();
|
|
||||||
result.append(knetworkconnection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KNetworkManagerPrivate::enable(const QString &name, const bool enable)
|
if (m_cm.isValid()) {
|
||||||
{
|
bool result = false;
|
||||||
bool result = false;
|
QDBusReply<QList<ConnmanServiceType>> cmservicesreply = m_cm.call("GetServices");
|
||||||
if (!m_cm.isValid()) {
|
if (!cmservicesreply.isValid()) {
|
||||||
kDebug() << "Connection management not supported";
|
kWarning() << "Invalid net.connman reply" << cmservicesreply.error();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
bool foundit = false;
|
const QList<ConnmanServiceType> cmservicesvalue = cmservicesreply.value();
|
||||||
foreach (const KNetworkConnection &knetworkconnection, connections()) {
|
foreach (const ConnmanServiceType &cmservice, cmservicesvalue) {
|
||||||
if (knetworkconnection.name == name) {
|
const QString cmservicename = cmservice.service_dict.value(QLatin1String("Name")).toString();
|
||||||
foundit = true;
|
|
||||||
QDBusInterface cmserviceinterface(
|
QDBusInterface cmserviceinterface(
|
||||||
"net.connman", knetworkconnection.dbuspath, "net.connman.Service",
|
"net.connman", cmservice.service_object.path(), "net.connman.Service",
|
||||||
QDBusConnection::systemBus()
|
QDBusConnection::systemBus()
|
||||||
);
|
);
|
||||||
QDBusReply<void> cmreply;
|
QDBusReply<void> cmservicereply;
|
||||||
if (enable) {
|
if (enable) {
|
||||||
cmreply = cmserviceinterface.call("Connect");
|
kDebug() << "Enabling net.connman service" << cmservicename;
|
||||||
|
cmservicereply = cmserviceinterface.call("Connect");
|
||||||
} else {
|
} else {
|
||||||
cmreply = cmserviceinterface.call("Disconnect");
|
kDebug() << "Disabling net.connman service" << cmservicename;
|
||||||
|
cmservicereply = cmserviceinterface.call("Disconnect");
|
||||||
}
|
}
|
||||||
result = cmreply.isValid();
|
result |= cmservicereply.isValid();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
kWarning() << "Invalid net.connman.Service reply" << cmreply.error();
|
kWarning() << "Invalid net.connman.Service reply" << cmservicereply.error();
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (enable) {
|
||||||
|
kDebug() << "Done enabling net.connman services" << result;
|
||||||
|
} else {
|
||||||
|
kDebug() << "Done disabling net.connman services" << result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (!foundit) {
|
|
||||||
kWarning() << "net.connman connection not found" << name;
|
kDebug() << "Connection management not supported";
|
||||||
}
|
return false;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KNetworkManagerPrivate::timerEvent(QTimerEvent *event)
|
void KNetworkManagerPrivate::timerEvent(QTimerEvent *event)
|
||||||
|
@ -305,11 +305,7 @@ KNetworkManager::KNetworkManager(QObject *parent)
|
||||||
d(new KNetworkManagerPrivate(this))
|
d(new KNetworkManagerPrivate(this))
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
foreach (const KNetworkConnection &knetworkconnection, connections()) {
|
qDebug() << Q_FUNC_INFO << isSupported() << enable(false) << enable(true);
|
||||||
qDebug() << Q_FUNC_INFO << knetworkconnection.name << knetworkconnection.dbuspath;
|
|
||||||
}
|
|
||||||
enable("Wired", false);
|
|
||||||
enable("Wired", true);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,14 +319,9 @@ KNetworkManager::KNetworkStatus KNetworkManager::status() const
|
||||||
return d->status();
|
return d->status();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<KNetworkConnection> KNetworkManager::connections() const
|
bool KNetworkManager::enable(const bool enable)
|
||||||
{
|
{
|
||||||
return d->connections();
|
return d->enable(enable);
|
||||||
}
|
|
||||||
|
|
||||||
bool KNetworkManager::enable(const QString &name, const bool enable)
|
|
||||||
{
|
|
||||||
return d->enable(name, enable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KNetworkManager::isSupported()
|
bool KNetworkManager::isSupported()
|
||||||
|
@ -341,8 +332,13 @@ bool KNetworkManager::isSupported()
|
||||||
kDebug() << "Null system D-Bus connection interface";
|
kDebug() << "Null system D-Bus connection interface";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QDBusReply<bool> dbusreply = dbusinterface->isServiceRegistered("net.connman");
|
QDBusReply<bool> dbusreply = dbusinterface->isServiceRegistered("org.freedesktop.NetworkManager");
|
||||||
return dbusreply.value();
|
bool result = dbusreply.value();
|
||||||
|
if (!result) {
|
||||||
|
dbusreply = dbusinterface->isServiceRegistered("net.connman");
|
||||||
|
result = dbusreply.value();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_knetworkmanager.cpp"
|
#include "moc_knetworkmanager.cpp"
|
||||||
|
|
|
@ -24,19 +24,6 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
|
||||||
/*!
|
|
||||||
Structure that holds information about network connection.
|
|
||||||
|
|
||||||
@ingroup Types
|
|
||||||
@since 4.23
|
|
||||||
@see KNetworkManager
|
|
||||||
*/
|
|
||||||
struct KNetworkConnection
|
|
||||||
{
|
|
||||||
QString name;
|
|
||||||
QString dbuspath; // internal
|
|
||||||
};
|
|
||||||
|
|
||||||
class KNetworkManagerPrivate;
|
class KNetworkManagerPrivate;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -69,14 +56,9 @@ public:
|
||||||
KNetworkStatus status() const;
|
KNetworkStatus status() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief Returns the current network connections
|
@brief Enables or disables all network connections
|
||||||
*/
|
*/
|
||||||
QList<KNetworkConnection> connections() const;
|
bool enable(const bool enable);
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief Enables or disables the network connection named @p name
|
|
||||||
*/
|
|
||||||
bool enable(const QString &name, const bool enable);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief Returns @p true if network management is supported on this host,
|
@brief Returns @p true if network management is supported on this host,
|
||||||
|
|
Loading…
Add table
Reference in a new issue