networking-status

# Networking Status

Applications needing to access the overall system networking status must access the ubuntu::connectivity::NetworkingStatus class. The class has properties for the networking status and connection limitations of the system networking.

Accessing the networking status from confined applications requires the connectivity policy group.

# Setup

Manager is accessed by including the appropriate header:

    #include<connectivityqt/connectivity.h>
    usingnamespaceconnectivityqt;

and then creating an instance of the NetworkingStatus:

    QScopedPointer<Connectivity>ns(newConnectivity());

# Networking Status

## Status

The status of the system networking can be accessed through the ubuntu::connectivity::NetworkingStatus::status property:

    //normalgetter
    if(ns->status()==Connectivity::Status::Online)
    {
    qDebug()<<"Weareonline.";
    }

    //Subscribetosystemnetworkingchanges
    QObject::connect(ns.data(),
    &Connectivity::statusUpdated,
    [](Connectivity::Statusvalue)
    {
    qDebug()<<"Systemnetworkingstatuschangedto:"+STATUS_MAP[value];
    });

## Limitations

The limitations can be accessed through the ubuntu::connectivity::NetworkingStatus::limitations property:

    //normalgetter
    if(ns->limitations().isEmpty())
    qDebug()<<"Nolimitations";

    //Subscribetolimitationchanges
    QObject::connect(ns.data(),
    &Connectivity::limitationsUpdated,
    [&ns](){
    if(ns->limitations().isEmpty())
    {
    qDebug()<<"Nolimitations.";
    return;
    }

    qDebug()<<"Limitations:";
    if(ns->limitations().contains(Connectivity::Limitations::Bandwith))
    {
    qDebug()<<"-Bandwith";
    }
    });

The complete example (found in examples/example_networking_status.cpp):

    /*
    *Copyright©2014CanonicalLtd.
    *
    *Thisprogramisfreesoftware:youcanredistributeitand/ormodifyit
    *underthetermsoftheGNULesserGeneralPublicLicenseversion3,
    *aspublishedbytheFreeSoftwareFoundation.
    *
    *Thisprogramisdistributedinthehopethatitwillbeuseful,
    *butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
    *MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
    *GNULesserGeneralPublicLicenseformoredetails.
    *
    *YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
    *alongwiththisprogram.Ifnot,see<http://www.gnu.org/licenses/>.
    *
    *Authors:
    *AnttiKaijanmäki<antti.kaijanmaki@canonical.com>
    */

    #include<QCoreApplication>
    #include<QScopedPointer>
    #include<QDebug>

    #include<connectivityqt/connectivity.h>
    usingnamespaceconnectivityqt;

    staticconstQMap<Connectivity::Status,QString>STATUS_MAP{
    {Connectivity::Status::Offline,"Offline"},
    {Connectivity::Status::Connecting,"Connecting"},
    {Connectivity::Status::Online,"Online"},
    };

    int
    main(intargc,char*argv[])
    {
    QCoreApplicationapp(argc,argv);

    QScopedPointer<Connectivity>ns(newConnectivity());

    //normalgetter
    if(ns->status()==Connectivity::Status::Online)
    {
    qDebug()<<"Weareonline.";
    }

    //Subscribetosystemnetworkingchanges
    QObject::connect(ns.data(),
    &Connectivity::statusUpdated,
    [](Connectivity::Statusvalue)
    {
    qDebug()<<"Systemnetworkingstatuschangedto:"+STATUS_MAP[value];
    });

    qDebug()<<"Systemnetworkingstatus:"+STATUS_MAP[ns->status()];

    //normalgetter
    if(ns->limitations().isEmpty())
    qDebug()<<"Nolimitations";

    //Subscribetolimitationchanges
    QObject::connect(ns.data(),
    &Connectivity::limitationsUpdated,
    [&ns](){
    if(ns->limitations().isEmpty())
    {
    qDebug()<<"Nolimitations.";
    return;
    }

    qDebug()<<"Limitations:";
    if(ns->limitations().contains(Connectivity::Limitations::Bandwith))
    {
    qDebug()<<"-Bandwith";
    }
    });

    app.exec();

    return0;
    }