8#include <QtDBus/QDBusConnection>
9#include <QtDBus/QDBusError>
10#include <QtDBus/QDBusInterface>
11#include <QtDBus/QDBusMessage>
12#include <QtDBus/QDBusReply>
13#include <QtDBus/QDBusPendingCallWatcher>
14#include <QtDBus/QDBusObjectPath>
15#include <QtDBus/QDBusPendingCall>
17#define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
19#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager"
21#define NM_DBUS_PATH "/org/freedesktop/NetworkManager"
22#define NM_DBUS_INTERFACE NM_DBUS_SERVICE
23#define NM_CONNECTION_DBUS_INTERFACE NM_DBUS_SERVICE ".Connection.Active"
24#define NM_DEVICE_DBUS_INTERFACE NM_DBUS_SERVICE ".Device"
55 propertyMap = propsReply.
value();
81 if (propertyMap.
contains(
"Connectivity"))
94 if (devicePaths.isEmpty())
103std::optional<QDBusObjectPath> QNetworkManagerInterface::primaryConnectionDevicePath()
const
105 auto it = propertyMap.
constFind(u
"PrimaryConnection"_s);
106 if (
it != propertyMap.
cend())
113 if (
const auto path = primaryConnectionDevicePath())
114 return extractDeviceType(*
path);
120 if (
const auto path = primaryConnectionDevicePath())
121 return extractDeviceMetered(*
path);
125auto QNetworkManagerInterface::extractDeviceType(
const QDBusObjectPath &devicePath)
const
130 return NM_DEVICE_TYPE_UNKNOWN;
131 if (!primaryDevice->isValid())
132 return NM_DEVICE_TYPE_UNKNOWN;
135 return NM_DEVICE_TYPE_UNKNOWN;
136 return static_cast<NMDeviceType
>(
deviceType.toUInt());
139auto QNetworkManagerInterface::extractDeviceMetered(
const QDBusObjectPath &devicePath)
const
144 return NM_METERED_UNKNOWN;
145 if (!primaryDevice->isValid())
146 return NM_METERED_UNKNOWN;
147 const QVariant metered = primaryDevice->property(
"Metered");
149 return NM_METERED_UNKNOWN;
150 return static_cast<NMMetered
>(metered.
toUInt());
153void QNetworkManagerInterface::setProperties(
const QString &interfaceName,
161 bool valueChanged =
true;
164 if (
it != propertyMap.
end() &&
it.key() ==
i.key()) {
165 valueChanged = (
it.value() !=
i.value());
172 if (
i.key() ==
"State"_L1) {
175 }
else if (
i.key() ==
"Connectivity"_L1) {
178 }
else if (
i.key() ==
"PrimaryConnection"_L1) {
182 }
else if (
i.key() ==
"Metered"_L1) {
191#include "moc_qnetworkmanagerservice.cpp"
QDBusMessage callWithArgumentList(QDBus::CallMode mode, const QString &method, const QList< QVariant > &args)
Places a call to the remote method specified by method on this interface, using args as arguments.
bool isValid() const
Returns true if this is a valid reference to a remote object.
static QDBusConnection systemBus()
Returns a QDBusConnection object opened with the system bus.
bool disconnect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
Disconnects the signal specified by the service, path, interface and name parameters from the slot sl...
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
Connects the signal specified by the service, path, interface and name parameters to the slot slot in...
QString message() const
Returns the message that the callee associated with this error.
QString path() const
Returns this object path.
Select< 0 >::Type value() const
Returns the first argument in this reply, cast to type Types[0] (the first template parameter of this...
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
const_iterator cend() const
const_iterator cbegin() const
const_iterator constFind(const Key &key) const
iterator lowerBound(const Key &key)
QNetworkManagerInterfaceBase(QObject *parent=nullptr)
static bool networkManagerAvailable()
void stateChanged(NMState)
NMConnectivityState connectivityState() const
void meteredChanged(NMMetered)
void connectivityChanged(NMConnectivityState)
QNetworkManagerInterface(QObject *parent=nullptr)
NMDeviceType deviceType() const
void deviceTypeChanged(NMDeviceType)
@ NM_CONNECTIVITY_UNKNOWN
~QNetworkManagerInterface()
NMMetered meteredState() const
QVariant property(const char *name) const
Returns the value of the object's name property.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
uint toUInt(bool *ok=nullptr) const
Returns the variant as an unsigned int if the variant has userType() \l QMetaType::UInt,...
QMap< QString, QString > map
[6]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
DBusConnection * connection
#define NM_DEVICE_DBUS_INTERFACE
#define NM_DBUS_INTERFACE
static std::optional< QDBusInterface > getPrimaryDevice(const QDBusObjectPath &devicePath)
#define DBUS_PROPERTIES_INTERFACE
#define NM_CONNECTION_DBUS_INTERFACE
GLsizei const GLchar *const * path
static QInputDevice::DeviceType deviceType(const UINT cursorType)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent