@ -202,7 +202,7 @@ void WifiManager::connect(const QByteArray &ssid, const QString &username, const
nm_settings . call ( " AddConnection " , QVariant : : fromValue ( connection ) ) ;
}
void WifiManager : : deactivateConnection ( const QString & ssid ) {
void WifiManager : : deactivateConnectionBySsid ( const QString & ssid ) {
for ( QDBusObjectPath active_connection_raw : get_active_connections ( ) ) {
QString active_connection = active_connection_raw . path ( ) ;
QDBusInterface nm ( NM_DBUS_SERVICE , active_connection , NM_DBUS_INTERFACE_PROPERTIES , bus ) ;
@ -212,14 +212,18 @@ void WifiManager::deactivateConnection(const QString &ssid) {
if ( pth . path ( ) ! = " " & & pth . path ( ) ! = " / " ) {
QString Ssid = get_property ( pth . path ( ) , " Ssid " ) ;
if ( Ssid = = ssid ) {
QDBusInterface nm2 ( NM_DBUS_SERVICE , NM_DBUS_PATH , NM_DBUS_INTERFACE , bus ) ;
nm2 . setTimeout ( DBUS_TIMEOUT ) ;
nm2 . call ( " DeactivateConnection " , QVariant : : fromValue ( active_connection_raw ) ) ;
deactivateConnection ( active_connection_raw ) ;
}
}
}
}
void WifiManager : : deactivateConnection ( const QDBusObjectPath & path ) {
QDBusInterface nm2 ( NM_DBUS_SERVICE , NM_DBUS_PATH , NM_DBUS_INTERFACE , bus ) ;
nm2 . setTimeout ( DBUS_TIMEOUT ) ;
nm2 . call ( " DeactivateConnection " , QVariant : : fromValue ( path ) ) ;
}
QVector < QDBusObjectPath > WifiManager : : get_active_connections ( ) {
QDBusInterface nm ( NM_DBUS_SERVICE , NM_DBUS_PATH , NM_DBUS_INTERFACE_PROPERTIES , bus ) ;
nm . setTimeout ( DBUS_TIMEOUT ) ;
@ -250,11 +254,14 @@ void WifiManager::forgetConnection(const QString &ssid) {
}
}
bool WifiManager : : isWirelessAdapter ( const QDBusObjectPath & path ) {
uint WifiManager : : getAdapterType ( const QDBusObjectPath & path ) {
QDBusInterface device_props ( NM_DBUS_SERVICE , path . path ( ) , NM_DBUS_INTERFACE_PROPERTIES , bus ) ;
device_props . setTimeout ( DBUS_TIMEOUT ) ;
const uint deviceType = get_response < uint > ( device_props . call ( " Get " , NM_DBUS_INTERFACE_DEVICE , " DeviceType " ) ) ;
return deviceType = = NM_DEVICE_TYPE_WIFI ;
return get_response < uint > ( device_props . call ( " Get " , NM_DBUS_INTERFACE_DEVICE , " DeviceType " ) ) ;
}
bool WifiManager : : isWirelessAdapter ( const QDBusObjectPath & path ) {
return getAdapterType ( path ) = = NM_DEVICE_TYPE_WIFI ;
}
void WifiManager : : requestScan ( ) {
@ -288,13 +295,13 @@ unsigned int WifiManager::get_ap_strength(const QString &network_path) {
return get_response < unsigned int > ( response ) ;
}
QString WifiManager : : getAdapter ( ) {
QString WifiManager : : getAdapter ( const uint adapter_type ) {
QDBusInterface nm ( NM_DBUS_SERVICE , NM_DBUS_PATH , NM_DBUS_INTERFACE , bus ) ;
nm . setTimeout ( DBUS_TIMEOUT ) ;
const QDBusReply < QList < QDBusObjectPath > > & response = nm . call ( " GetDevices " ) ;
for ( const QDBusObjectPath & path : response . value ( ) ) {
if ( isWirelessAdapter ( path ) ) {
if ( getAdapterType ( path ) = = adapter_type ) {
return path . path ( ) ;
}
}
@ -352,7 +359,7 @@ void WifiManager::newConnection(const QDBusObjectPath &path) {
void WifiManager : : disconnect ( ) {
if ( activeAp ! = " " & & activeAp ! = " / " ) {
deactivateConnection ( get_property ( activeAp , " Ssid " ) ) ;
deactivateConnectionBySsid ( get_property ( activeAp , " Ssid " ) ) ;
}
}
@ -381,7 +388,7 @@ void WifiManager::initConnections() {
if ( settings . value ( " connection " ) . value ( " type " ) = = " 802-11-wireless " ) {
knownConnections [ path ] = settings . value ( " 802-11-wireless " ) . value ( " ssid " ) . toString ( ) ;
} else if ( path . path ( ) ! = " / " ) {
lteConnectionPath = path . path ( ) ;
lteConnectionPath = path ;
}
}
}
@ -396,6 +403,15 @@ void WifiManager::activateWifiConnection(const QString &ssid) {
}
}
void WifiManager : : activateModemConnection ( const QDBusObjectPath & path ) {
QString modem = getAdapter ( NM_DEVICE_TYPE_MODEM ) ;
if ( ! path . path ( ) . isEmpty ( ) & & ! modem . isEmpty ( ) ) {
QDBusInterface nm3 ( NM_DBUS_SERVICE , NM_DBUS_PATH , NM_DBUS_INTERFACE , bus ) ;
nm3 . setTimeout ( DBUS_TIMEOUT ) ;
nm3 . call ( " ActivateConnection " , QVariant : : fromValue ( path ) , QVariant : : fromValue ( QDBusObjectPath ( modem ) ) , QVariant : : fromValue ( QDBusObjectPath ( " / " ) ) ) ;
}
}
// function matches tici/hardware.py
NetworkType WifiManager : : currentNetworkType ( ) {
QDBusInterface nm ( NM_DBUS_SERVICE , NM_DBUS_PATH , NM_DBUS_INTERFACE_PROPERTIES , bus ) ;
@ -423,15 +439,37 @@ NetworkType WifiManager::currentNetworkType() {
return NetworkType : : NONE ;
}
void WifiManager : : setRoamingEnabled ( bool roaming ) {
if ( ! lteConnectionPath . isEmpty ( ) ) {
QDBusInterface nm ( NM_DBUS_SERVICE , lteConnectionPath , NM_DBUS_INTERFACE_SETTINGS_CONNECTION , bus ) ;
void WifiManager : : updateGsmSettings ( bool roaming , QString apn ) {
if ( ! lteConnectionPath . path ( ) . isEmpty ( ) ) {
QDBusInterface nm ( NM_DBUS_SERVICE , lteConnectionPath . path ( ) , NM_DBUS_INTERFACE_SETTINGS_CONNECTION , bus ) ;
nm . setTimeout ( DBUS_TIMEOUT ) ;
bool changes = false ;
bool auto_config = apn . isEmpty ( ) ;
Connection settings = QDBusReply < Connection > ( nm . call ( " GetSettings " ) ) . value ( ) ;
if ( settings . value ( " gsm " ) . value ( " auto-config " ) . toBool ( ) ! = auto_config ) {
qWarning ( ) < < " Changing gsm.auto-config to " < < auto_config ;
settings [ " gsm " ] [ " auto-config " ] = auto_config ;
changes = true ;
}
if ( settings . value ( " gsm " ) . value ( " apn " ) . toString ( ) ! = apn ) {
qWarning ( ) < < " Changing gsm.apn to " < < apn ;
settings [ " gsm " ] [ " apn " ] = apn ;
changes = true ;
}
if ( settings . value ( " gsm " ) . value ( " home-only " ) . toBool ( ) = = roaming ) {
qWarning ( ) < < " Changing gsm.home-only to " < < ! roaming ;
settings [ " gsm " ] [ " home-only " ] = ! roaming ;
changes = true ;
}
if ( changes ) {
nm . call ( " UpdateUnsaved " , QVariant : : fromValue ( settings ) ) ; // update is temporary
deactivateConnection ( lteConnectionPath ) ;
activateModemConnection ( lteConnectionPath ) ;
}
}
}
@ -476,7 +514,7 @@ void WifiManager::setTetheringEnabled(bool enabled) {
}
activateWifiConnection ( tethering_ssid ) ;
} else {
deactivateConnection ( tethering_ssid ) ;
deactivateConnectionBySsid ( tethering_ssid ) ;
}
}