Merge PR #28: Add CheckConnectivity method and verify connectivity on state changed
commit
c623f50adb
|
|
@ -592,6 +592,24 @@ bool NetworkManager::enableWireless(bool enabled)
|
|||
return m_networkManagerInterface->setProperty("WirelessEnabled", enabled);
|
||||
}
|
||||
|
||||
void NetworkManager::checkConnectivity()
|
||||
{
|
||||
// Get network devices
|
||||
qCDebug(dcNetworkManager()) << "Checking connectivity ...";
|
||||
QDBusMessage query = m_networkManagerInterface->call("CheckConnectivity");
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (query.arguments().isEmpty())
|
||||
return;
|
||||
|
||||
NetworkManagerConnectivityState state = static_cast<NetworkManagerConnectivityState>(query.arguments().at(0).toUInt());
|
||||
qCDebug(dcNetworkManager()) << "Checked connectevitiy state successfully:" << query.arguments().at(0).toUInt() << state;
|
||||
setConnectivityState(state);
|
||||
}
|
||||
|
||||
void NetworkManager::init()
|
||||
{
|
||||
qCDebug(dcNetworkManager()) << "Initializing network manager";
|
||||
|
|
@ -635,7 +653,11 @@ void NetworkManager::init()
|
|||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::networkManagerPathString(), NetworkManagerUtils::networkManagerServiceString(), "StateChanged", this, SLOT(onStateChanged(uint)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::networkManagerPathString(), NetworkManagerUtils::networkManagerServiceString(), "DeviceAdded", this, SLOT(onDeviceAdded(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::networkManagerPathString(), NetworkManagerUtils::networkManagerServiceString(), "DeviceRemoved", this, SLOT(onDeviceRemoved(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::networkManagerPathString(), NetworkManagerUtils::networkManagerServiceString(), "PropertiesChanged", this, SLOT(onPropertiesChanged(QVariantMap)));
|
||||
|
||||
// Networkmanager < 1.2.0 uses custom signal instead of the standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::networkManagerPathString(), NetworkManagerUtils::networkManagerServiceString(), "PropertiesChanged", this, SLOT(processProperties(QVariantMap)));
|
||||
// Networkmanager >= 1.2.0 uses standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::networkManagerPathString(), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
|
||||
|
||||
// Load network devices
|
||||
loadDevices();
|
||||
|
|
@ -766,6 +788,7 @@ void NetworkManager::setState(const NetworkManager::NetworkManagerState &state)
|
|||
qCDebug(dcNetworkManager()) << "State changed:" << networkManagerStateToString(state);
|
||||
m_state = state;
|
||||
emit stateChanged(m_state);
|
||||
checkConnectivity();
|
||||
}
|
||||
|
||||
void NetworkManager::onServiceRegistered()
|
||||
|
|
@ -780,7 +803,7 @@ void NetworkManager::onServiceUnregistered()
|
|||
deinit();
|
||||
}
|
||||
|
||||
void NetworkManager::onStateChanged(const uint &state)
|
||||
void NetworkManager::onStateChanged(uint state)
|
||||
{
|
||||
setState(static_cast<NetworkManagerState>(state));
|
||||
}
|
||||
|
|
@ -856,7 +879,15 @@ void NetworkManager::onDeviceRemoved(const QDBusObjectPath &deviceObjectPath)
|
|||
networkDevice->deleteLater();
|
||||
}
|
||||
|
||||
void NetworkManager::onPropertiesChanged(const QVariantMap &properties)
|
||||
void NetworkManager::onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
||||
{
|
||||
Q_UNUSED(interface)
|
||||
Q_UNUSED(invalidatedProperties)
|
||||
//qCDebug(dcNetworkManager()) << "NetworkManager: Properties changed" << interface << changedProperties << invalidatedProperties;
|
||||
processProperties(changedProperties);
|
||||
}
|
||||
|
||||
void NetworkManager::processProperties(const QVariantMap &properties)
|
||||
{
|
||||
if (properties.contains("Version"))
|
||||
setVersion(properties.value("Version").toString());
|
||||
|
|
|
|||
|
|
@ -134,6 +134,8 @@ public:
|
|||
bool wirelessEnabled() const;
|
||||
bool enableWireless(bool enabled);
|
||||
|
||||
void checkConnectivity();
|
||||
|
||||
private:
|
||||
QDBusServiceWatcher *m_serviceWatcher = nullptr;
|
||||
QDBusInterface *m_networkManagerInterface = nullptr;
|
||||
|
|
@ -187,10 +189,11 @@ private slots:
|
|||
void onServiceRegistered();
|
||||
void onServiceUnregistered();
|
||||
|
||||
void onStateChanged(const uint &state);
|
||||
void onStateChanged(uint state);
|
||||
void onDeviceAdded(const QDBusObjectPath &deviceObjectPath);
|
||||
void onDeviceRemoved(const QDBusObjectPath &deviceObjectPath);
|
||||
void onPropertiesChanged(const QVariantMap &properties);
|
||||
void onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
|
||||
void processProperties(const QVariantMap &properties);
|
||||
|
||||
void onWirelessDeviceChanged();
|
||||
void onWiredDeviceChanged();
|
||||
|
|
|
|||
|
|
@ -60,7 +60,10 @@ NetworkSettings::NetworkSettings(QObject *parent) :
|
|||
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::settingsPathString(), NetworkManagerUtils::settingsInterfaceString(), "NewConnection", this, SLOT(connectionAdded(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::settingsPathString(), NetworkManagerUtils::settingsInterfaceString(), "ConnectionRemoved", this, SLOT(connectionRemoved(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::settingsPathString(), NetworkManagerUtils::settingsInterfaceString(), "PropertiesChanged", this, SLOT(propertiesChanged(QVariantMap)));
|
||||
// Networkmanager < 1.2.0 uses custom signal instead of the standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::settingsPathString(), NetworkManagerUtils::settingsInterfaceString(), "PropertiesChanged", this, SLOT(processProperties(QVariantMap)));
|
||||
// Networkmanager >= 1.2.0 uses standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), NetworkManagerUtils::settingsPathString(), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
|
||||
}
|
||||
|
||||
/*! Add the given \a settings to this \l{NetworkSettings}. Returns the dbus object path from the new settings. */
|
||||
|
|
@ -121,9 +124,17 @@ void NetworkSettings::connectionRemoved(const QDBusObjectPath &objectPath)
|
|||
connection->deleteLater();
|
||||
}
|
||||
|
||||
void NetworkSettings::propertiesChanged(const QVariantMap &properties)
|
||||
void NetworkSettings::onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
||||
{
|
||||
Q_UNUSED(interface)
|
||||
Q_UNUSED(invalidatedProperties)
|
||||
//qCDebug(dcNetworkManager()) << "Settins: Properties changed" << interface << changedProperties << invalidatedProperties;
|
||||
processProperties(changedProperties);
|
||||
}
|
||||
|
||||
void NetworkSettings::processProperties(const QVariantMap &properties)
|
||||
{
|
||||
Q_UNUSED(properties)
|
||||
// TODO: handle settings changes
|
||||
//qCDebug(dcNetworkManager()) << "Settins: properties changed" << properties;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ private:
|
|||
private slots:
|
||||
void connectionAdded(const QDBusObjectPath &objectPath);
|
||||
void connectionRemoved(const QDBusObjectPath &objectPath);
|
||||
void propertiesChanged(const QVariantMap &properties);
|
||||
void onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
|
||||
void processProperties(const QVariantMap &properties);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ WiredNetworkDevice::WiredNetworkDevice(const QDBusObjectPath &objectPath, QObjec
|
|||
m_bitRate = m_wiredInterface->property("Bitrate").toInt();
|
||||
m_pluggedIn = m_wiredInterface->property("Carrier").toBool();
|
||||
|
||||
// Networkmanager < 1.2.0 uses custom signal instead of the standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wiredInterfaceString(), "PropertiesChanged", this, SLOT(processProperties(QVariantMap)));
|
||||
// Networkmanager >= 1.2.0 uses standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(propertiesChanged(QString, QVariantMap, QStringList)));
|
||||
}
|
||||
|
||||
|
|
@ -83,12 +86,18 @@ bool WiredNetworkDevice::pluggedIn() const
|
|||
return m_pluggedIn;
|
||||
}
|
||||
|
||||
void WiredNetworkDevice::propertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties)
|
||||
void WiredNetworkDevice::onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
||||
{
|
||||
Q_UNUSED(interface_name)
|
||||
Q_UNUSED(invalidated_properties)
|
||||
if (changed_properties.contains("Carrier")) {
|
||||
m_pluggedIn = changed_properties.value("Carrier").toBool();
|
||||
Q_UNUSED(interfaceName)
|
||||
Q_UNUSED(invalidatedProperties)
|
||||
//qCDebug(dcNetworkManager()) << "WiredNetworkDevice: Properties changed" << interface << changedProperties << invalidatedProperties;
|
||||
processProperties(changedProperties);
|
||||
}
|
||||
|
||||
void WiredNetworkDevice::processProperties(const QVariantMap &properties)
|
||||
{
|
||||
if (properties.contains("Carrier")) {
|
||||
m_pluggedIn = properties.value("Carrier").toBool();
|
||||
emit pluggedInChanged(m_pluggedIn);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ signals:
|
|||
void pluggedInChanged(bool pluggedIn);
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties);
|
||||
void onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
|
||||
void processProperties(const QVariantMap &properties);
|
||||
|
||||
private:
|
||||
QDBusInterface *m_wiredInterface = nullptr;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,10 @@ WirelessAccessPoint::WirelessAccessPoint(const QDBusObjectPath &objectPath, QObj
|
|||
qCDebug(dcNetworkManager()) << ssid() << "RSN flags:" << m_rsnFlags;
|
||||
qCDebug(dcNetworkManager()) << ssid() << "Capabilities:" << m_capabilities;
|
||||
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), objectPath.path(), NetworkManagerUtils::accessPointInterfaceString(), "PropertiesChanged", this, SLOT(onPropertiesChanged(QVariantMap)));
|
||||
// Networkmanager < 1.2.0 uses custom signal instead of the standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::accessPointInterfaceString(), "PropertiesChanged", this, SLOT(processProperties(QVariantMap)));
|
||||
// Networkmanager >= 1.2.0 uses standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), objectPath.path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path of this \l{WirelessAccessPoint}. */
|
||||
|
|
@ -153,6 +156,20 @@ void WirelessAccessPoint::setIsProtected(bool isProtected)
|
|||
m_isProtected = isProtected;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
||||
{
|
||||
Q_UNUSED(interface)
|
||||
Q_UNUSED(invalidatedProperties)
|
||||
//qCDebug(dcNetworkManager()) << "WirelessAccessPoint: Properties changed" << interface << changedProperties << invalidatedProperties;
|
||||
processProperties(changedProperties);
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::processProperties(const QVariantMap &properties)
|
||||
{
|
||||
if (properties.contains("Strength"))
|
||||
setSignalStrength(properties.value("Strength").toInt());
|
||||
}
|
||||
|
||||
/*! Returns true if this \l{WirelessAccessPoint} is password protected. */
|
||||
bool WirelessAccessPoint::isProtected() const
|
||||
{
|
||||
|
|
@ -186,13 +203,6 @@ WirelessAccessPoint::ApSecurityModes WirelessAccessPoint::rsnFlags() const
|
|||
return m_rsnFlags;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::onPropertiesChanged(const QVariantMap &properties)
|
||||
{
|
||||
if (properties.contains("Strength"))
|
||||
setSignalStrength(properties.value("Strength").toInt());
|
||||
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, WirelessAccessPoint *accessPoint)
|
||||
{
|
||||
debug.nospace() << "AccessPoint(" << accessPoint->signalStrength() << "%, "
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ signals:
|
|||
void signalStrengthChanged();
|
||||
|
||||
private slots:
|
||||
void onPropertiesChanged(const QVariantMap &properties);
|
||||
void onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
|
||||
void processProperties(const QVariantMap &properties);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -83,9 +83,9 @@ WirelessNetworkDevice::WirelessNetworkDevice(const QDBusObjectPath &objectPath,
|
|||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wirelessInterfaceString(), "AccessPointAdded", this, SLOT(accessPointAdded(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wirelessInterfaceString(), "AccessPointRemoved", this, SLOT(accessPointRemoved(QDBusObjectPath)));
|
||||
// org.freedesktop.NetworkManager.Device.Wireless.PropertiesChanged(QVariantMap) is used in older versions of NetworkManager instead of the standard D-Bus properties changed signal
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wirelessInterfaceString(), "PropertiesChanged", this, SLOT(propertiesChanged(QVariantMap)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wirelessInterfaceString(), "PropertiesChanged", this, SLOT(processProperties(QVariantMap)));
|
||||
// Newer versions of NetworkManager dropped the other and switched to the D-Bus standard PropertiesChanged
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(propertiesChanged(QString, QVariantMap, QStringList)));
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
|
||||
|
||||
readAccessPoints();
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ void WirelessNetworkDevice::accessPointRemoved(const QDBusObjectPath &objectPath
|
|||
accessPoint->deleteLater();
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::propertiesChanged(const QVariantMap &properties)
|
||||
void WirelessNetworkDevice::processProperties(const QVariantMap &properties)
|
||||
{
|
||||
//qCDebug(dcNetworkManager()) << "WirelessNetworkDevice: Property changed" << properties;
|
||||
|
||||
|
|
@ -249,11 +249,12 @@ void WirelessNetworkDevice::propertiesChanged(const QVariantMap &properties)
|
|||
emit deviceChanged();
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::propertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties)
|
||||
void WirelessNetworkDevice::onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
||||
{
|
||||
Q_UNUSED(interface_name)
|
||||
Q_UNUSED(invalidated_properties)
|
||||
propertiesChanged(changed_properties);
|
||||
Q_UNUSED(interface)
|
||||
Q_UNUSED(invalidatedProperties)
|
||||
//qCDebug(dcNetworkManager()) << "WirelessNetworkDevice: Properties changed" << interface << changedProperties << invalidatedProperties;
|
||||
processProperties(changedProperties);
|
||||
}
|
||||
|
||||
/*! Writes the given \a device to the given to \a debug. \sa WirelessNetworkDevice, */
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ signals:
|
|||
private slots:
|
||||
void accessPointAdded(const QDBusObjectPath &objectPath);
|
||||
void accessPointRemoved(const QDBusObjectPath &objectPath);
|
||||
void propertiesChanged(const QVariantMap &properties);
|
||||
void propertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties);
|
||||
void processProperties(const QVariantMap &properties);
|
||||
void onPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
|
||||
|
||||
private:
|
||||
QDBusInterface *m_wirelessInterface = nullptr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue