Search code examples
qtwifi

Distinguish between open and password locked available WiFi networks


I am working on some application using Qt 5.7.0 GCC 64bit on Linux workstation 4.4.0-36-generic #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux which among other things shows available WiFi networks from selection, the core code is here:

void UeWiFiDiscoveryTask::run()
{
    QList<QNetworkConfiguration> networksList=this->ueNetworkConfigurationManager()->allConfigurations();
    QList<UeWiFiNetworkRecord*> wifiList=QList<UeWiFiNetworkRecord*>();

    foreach(QNetworkConfiguration network,
            networksList)
    {
        if(network.isValid()&&network.bearerType()==QNetworkConfiguration::BearerWLAN&&network.state()==QNetworkConfiguration::Discovered)
        {
            qDebug() << Q_FUNC_INFO
                     << network.state();

            wifiList.append(new UeWiFiNetworkRecord(new QImage(":/images/testWifi.jpg"),
                                                    network.name()));

            emit this->ueSignalWiFiFound(*wifiList.last());
        }   // if
    }   // foreach

    emit this->ueSignalWiFiDiscoveryFinished(wifiList);
}   // run

The code runs on separated thread and it works perfectly. However, I am reading Qt Bearer Management docs and I cannot find the way, how to distinguish between Free WiFi and encrypted/protected WiFi. How do I add such functionality?

P.S.: I am aware this is how-to question and I am ready to gain some negative points, however, I've been reading the docs for several days and I am lost!


Solution

  • Assuming this is a system with NetworkManager then QNetworkConfiguration::identifier() will return the D-Bus ObjectPath of the NetworkManager configuration item.

    I.e. you could use QtDBus to call the org.freedesktop.NetworkManager.Settings.Connection.GetSettings() method on that object which I think should include the information you are looking for