diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ include(ECMSetupVersion) include(ECMGenerateHeaders) -include(ECMAddQch) +# include(ECMAddQch) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") diff --git a/src/activeconnection.h b/src/activeconnection.h --- a/src/activeconnection.h +++ b/src/activeconnection.h @@ -58,6 +58,25 @@ Deactivating, /**< The connection is being torn down and cleaned up */ Deactivated /**< The connection is no longer active */ }; + + enum StateChangeReason { + UnknownReason = 0, /**< The reason for the VPN connection state change is unknown.*/ + NoneReason, /**< No reason was given for the VPN connection state change. */ + UserDisconnectedReason, /**< The VPN connection changed state because the user disconnected it. */ + DeviceDisconnectedReason, /**< The VPN connection changed state because the device it was using was disconnected. */ + ServiceStoppedReason, /**< The service providing the VPN connection was stopped. */ + IpConfigInvalidReason, /**< The IP config of the VPN connection was invalid. */ + ConnectTimeoutReason, /**< The connection attempt to the VPN service timed out. */ + ServiceStartTimeoutReason, /**< A timeout occurred while starting the service providing the VPN connection. */ + ServiceStartFailedReason, /**< Starting the service starting the service providing the VPN connection failed. */ + NoSecretsReason, /**< Necessary secrets for the VPN connection were not provided. */ + LoginFailedReason, /**< Authentication to the VPN server failed. */ + ConnectionRemovedReason, /**< The connection was deleted from settings. */ + DependencyFailedReason, /**< Master connection of this connection failed to activate. */ + DeviceRealizeFailedReason, /**< Could not create the software device link. */ + DeviceRemovedReason /** < The device this connection depended on disappeared. */ + }; + /** * Creates a new ActiveConnection object. * @@ -196,9 +215,16 @@ void specificObjectChanged(const QString &path); /** * The @p state changed + * FIXME: remove this on API/ABI change + * @deprecated keeping only for backward compatibility, there is new signal below with additional reason property */ void stateChanged(NetworkManager::ActiveConnection::State state); /** + * This signal is emitted when the connection @p state has changed + * FIXME rename back to stateChanged on API/ABI change + */ + void stateChangedWithReason(NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::StateChangeReason reason); + /** * The VPN property changed. */ void vpnChanged(bool isVpn); diff --git a/src/activeconnection.cpp b/src/activeconnection.cpp --- a/src/activeconnection.cpp +++ b/src/activeconnection.cpp @@ -55,6 +55,11 @@ return (NetworkManager::ActiveConnection::State)state; } +NetworkManager::ActiveConnection::StateChangeReason NetworkManager::ActiveConnectionPrivate::convertActiveConnectionStateReason(uint reason) +{ + return static_cast(reason); +} + NetworkManager::ActiveConnection::ActiveConnection(const QString &path, QObject *parent) : QObject(parent), d_ptr(new ActiveConnectionPrivate(path, this)) { @@ -79,6 +84,10 @@ connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::PropertiesChanged, d, &ActiveConnectionPrivate::propertiesChanged); #endif +#if NM_CHECK_VERSION(1, 8, 0) + connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::StateChanged, d, &ActiveConnectionPrivate::stateChanged); +#endif + #ifndef NMQT_STATIC /* * Workaround: Re-check connection state before we watch changes in case it gets changed too quickly @@ -102,6 +111,10 @@ #endif #endif +#if NM_CHECK_VERSION(1, 8, 0) + connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::StateChanged, d, &ActiveConnectionPrivate::stateChanged); +#endif + #ifdef NMQT_STATIC connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::PropertiesChanged, d, &ActiveConnectionPrivate::propertiesChanged); #endif @@ -282,7 +295,9 @@ watcher->deleteLater(); if (property == QLatin1String("State")) { state = NetworkManager::ActiveConnectionPrivate::convertActiveConnectionState(iface.state()); + // FIXME keeping for backward compatibility Q_EMIT q->stateChanged(state); + Q_EMIT q->stateChangedWithReason(state, ActiveConnection::UnknownReason); } if (property == QLatin1String("Ip4Config")) { ipV4ConfigPath = iface.ip4Config().path(); @@ -310,6 +325,16 @@ } } +void NetworkManager::ActiveConnectionPrivate::stateChanged(uint newState, uint reason) +{ + Q_Q(ActiveConnection); + + state = NetworkManager::ActiveConnectionPrivate::convertActiveConnectionState(newState); + NetworkManager::ActiveConnection::StateChangeReason stateChangeReason = NetworkManager::ActiveConnectionPrivate::convertActiveConnectionStateReason(reason); + Q_EMIT q->stateChanged(state); + Q_EMIT q->stateChangedWithReason(state, stateChangeReason); +} + void NetworkManager::ActiveConnectionPrivate::propertiesChanged(const QVariantMap &properties) { // qCDebug(NMQT) << Q_FUNC_INFO << properties; @@ -398,7 +423,11 @@ Q_EMIT q->specificObjectChanged(specificObject); } else if (property == QLatin1String("State")) { state = NetworkManager::ActiveConnectionPrivate::convertActiveConnectionState(value.toUInt()); +#if !NM_CHECK_VERSION(1, 8, 0) + // FIXME keeping for backward compatibility, do not emit state changed as there is additional signal for changed state Q_EMIT q->stateChanged(state); + Q_EMIT q->stateChangedReason(state, ActiveConnection::UnknownReason); +#endif } else if (property == QLatin1String("Vpn")) { vpn = value.toBool(); Q_EMIT q->vpnChanged(vpn); diff --git a/src/activeconnection_p.h b/src/activeconnection_p.h --- a/src/activeconnection_p.h +++ b/src/activeconnection_p.h @@ -34,6 +34,7 @@ explicit ActiveConnectionPrivate(const QString &, ActiveConnection *q); virtual ~ActiveConnectionPrivate(); static NetworkManager::ActiveConnection::State convertActiveConnectionState(uint); + static NetworkManager::ActiveConnection::StateChangeReason convertActiveConnectionStateReason(uint); NetworkManager::Connection::Ptr connection; QString path; bool default4; @@ -76,6 +77,7 @@ private Q_SLOTS: void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void stateChanged(uint new_state, uint reason); }; } diff --git a/src/fakenetwork/activeconnection.h b/src/fakenetwork/activeconnection.h --- a/src/fakenetwork/activeconnection.h +++ b/src/fakenetwork/activeconnection.h @@ -91,6 +91,7 @@ Q_SIGNALS: Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + Q_SCRIPTABLE void StateChanged(uint state, uint reason); private: QDBusObjectPath m_connection; diff --git a/src/fakenetwork/fakenetwork.cpp b/src/fakenetwork/fakenetwork.cpp --- a/src/fakenetwork/fakenetwork.cpp +++ b/src/fakenetwork/fakenetwork.cpp @@ -269,6 +269,12 @@ QDBusMessage message = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), QLatin1Literal("org.kde.fakenetwork.Connection.Active"), QLatin1Literal("PropertiesChanged")); message << activeConnectionMap; QDBusConnection::sessionBus().send(message); + +#if NM_CHECK_VERSION(1, 8, 0) + QDBusMessage message2 = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), QLatin1Literal("org.kde.fakenetwork.Connection.Active"), QLatin1Literal("StateChanged")); + message2 << activeConnection->state() << (uint) 0; // Unknown reason; + QDBusConnection::sessionBus().send(message2); +#endif } // TODO: set dhcp4Config, dhcp6Config, ip4Config, ip6Config // IP Interface is usually same as interface @@ -327,6 +333,12 @@ message << activeConnectionMap; QDBusConnection::sessionBus().send(message); +#if NM_CHECK_VERSION(1, 8, 0) + QDBusMessage message2 = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), QLatin1Literal("org.kde.fakenetwork.Connection.Active"), QLatin1Literal("StateChanged")); + message2 << activeConnection->state() << (uint) 0; // Unknown reason; + QDBusConnection::sessionBus().send(message2); +#endif + Device *device = m_devices.value(activeConnection->devices().first()); if (device) { m_deactivatedDevice = device->devicePath(); @@ -365,6 +377,12 @@ message << activeConnectionMap; QDBusConnection::sessionBus().send(message); +#if NM_CHECK_VERSION(1, 8, 0) + QDBusMessage message2 = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), QLatin1Literal("org.kde.fakenetwork.Connection.Active"), QLatin1Literal("StateChanged")); + message2 << activeConnection->state() << (uint) 0; // Unknown reason; + QDBusConnection::sessionBus().send(message2); +#endif + removeActiveConnection(QDBusObjectPath(activeConnection->activeConnectionPath())); } diff --git a/src/vpnconnection.h b/src/vpnconnection.h --- a/src/vpnconnection.h +++ b/src/vpnconnection.h @@ -72,7 +72,10 @@ ServiceStartFailedReason, /**< Starting the service starting the service providing the VPN connection failed. */ NoSecretsReason, /**< Necessary secrets for the VPN connection were not provided. */ LoginFailedReason, /**< Authentication to the VPN server failed. */ - ConnectionRemovedReason /**< The connection was deleted from settings. */ + ConnectionRemovedReason, /**< The connection was deleted from settings. */ + DependencyFailedReason, /**< Master connection of this connection failed to activate. */ + DeviceRealizeFailedReason, /**< Could not create the software device link. */ + DeviceRemoved /** < The device this connection depended on disappeared. */ }; /**