connectivity.cpp
connectivityqt/connectivity.h
connectivityqt/internal/vpn-connection-list-model-parameters.h
connectivityqt/vpn-connections-list-model.h
dbus-types.h
NetworkingStatusInterface.h
NetworkingStatusPrivateInterface.h
QDebug
QDBusPendingCallWatcher
connectivity.moc
connectivity.moc
functional
QObject
QDBusObjectPath
NetworkingStatusPrivateInterface.h
QDBusPendingCallWatcher
dbus-types.h
connectivityqt/connectivity.h
connectivityqt/connectivity.cpp
connectivityqt/vpn-connection.h
QDebug
unity/util/DefinesPtrs.h
QDBusConnection
QAbstractItemModel
connectivityqt/vpn-connections-list-model.h
connectivityqt/internal/vpn-connection-list-model-parameters.h
QAbstractListModel
QStringList
NetworkingStatusInterface.h
memory
connectivityqt

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

    #include<connectivityqt/connectivity.h>
    #include<connectivityqt/internal/vpn-connection-list-model-parameters.h>
    #include<connectivityqt/vpn-connections-list-model.h>
    #include<dbus-types.h>
    #include<NetworkingStatusInterface.h>
    #include<NetworkingStatusPrivateInterface.h>

    #include<QDebug>
    #include<QDBusPendingCallWatcher>

    usingnamespacestd;

    namespaceconnectivityqt
    {

    classConnectivity::Priv:publicQObject
    {
    Q_OBJECT
    public:
    Priv(Connectivity&parent,constQDBusConnection&sessionConnection):
    p(parent),m_sessionConnection(sessionConnection)
    {
    }

    Connectivity&p;

    function<void(QObject*)>m_objectOwner;

    QDBusConnectionm_sessionConnection;

    internal::DBusPropertyCache::SPtrm_propertyCache;

    internal::DBusPropertyCache::SPtrm_writePropertyCache;

    shared_ptr<ComUbuntuConnectivity1NetworkingStatusInterface>m_readInterface;

    shared_ptr<ComUbuntuConnectivity1PrivateInterface>m_writeInterface;

    VpnConnectionsListModel::SPtrm_vpnConnectionsModel;

    staticQVector<Limitations>toLimitations(constQVariant&value)
    {
    autol=value.toStringList();
    QVector<Limitations>result;
    for(constauto&limit:l)
    {
    //FIXMEKNOWNTYPO
    if(limit=="bandwith")
    {
    result.push_back(Limitations::Bandwith);
    }
    }
    returnresult;
    }

    staticStatustoStatus(constQVariant&value)
    {
    autos=value.toString();

    if(s=="offline")
    {
    returnStatus::Offline;
    }
    elseif(s=="connecting")
    {
    returnStatus::Connecting;
    }
    elseif(s=="online")
    {
    returnStatus::Online;
    }

    returnStatus::Offline;
    }

    publicQ_SLOTS:
    voidinterfaceInitialized()
    {
    //Ifbothinterfaceshavebeeninitializedthenwe'regoodtogo
    if(p.isInitialized())
    {
    Q_EMITp.initialized();
    }
    }

    voidpropertyChanged(constQString&name,constQVariant&value)
    {
    if(name=="FlightMode")
    {
    Q_EMITp.flightModeUpdated(value.toBool());
    }
    elseif(name=="WifiEnabled")
    {
    Q_EMITp.wifiEnabledUpdated(value.toBool());
    }
    elseif(name=="FlightModeSwitchEnabled")
    {
    Q_EMITp.flightModeSwitchEnabledUpdated(value.toBool());
    }
    elseif(name=="WifiSwitchEnabled")
    {
    Q_EMITp.wifiSwitchEnabledUpdated(value.toBool());
    }
    elseif(name=="HotspotSwitchEnabled")
    {
    Q_EMITp.hotspotSwitchEnabledUpdated(value.toBool());
    }
    elseif(name=="Limitations")
    {
    autolimitations=toLimitations(value);
    Q_EMITp.limitationsUpdated(limitations);
    Q_EMITp.limitedBandwithUpdated(limitations.contains(Limitations::Bandwith));
    }
    elseif(name=="Status")
    {
    autostatus=toStatus(value);
    Q_EMITp.statusUpdated(status);
    Q_EMITp.onlineUpdated(status==Status::Online);
    }
    elseif(name=="ModemAvailable")
    {
    Q_EMITp.modemAvailableUpdated(value.toBool());
    }
    elseif(name=="HotspotEnabled")
    {
    Q_EMITp.hotspotEnabledUpdated(value.toBool());
    }
    elseif(name=="HotspotSsid")
    {
    Q_EMITp.hotspotSsidUpdated(value.toByteArray());
    }
    elseif(name=="HotspotPassword")
    {
    Q_EMITp.hotspotPasswordUpdated(value.toString());
    }
    elseif(name=="HotspotMode")
    {
    Q_EMITp.hotspotModeUpdated(value.toString());
    }
    elseif(name=="HotspotAuth")
    {
    Q_EMITp.hotspotAuthUpdated(value.toString());
    }
    elseif(name=="HotspotStored")
    {
    Q_EMITp.hotspotStoredUpdated(value.toBool());
    }
    }

    };

    voidConnectivity::registerMetaTypes()
    {
    DBusTypes::registerMetaTypes();

    qRegisterMetaType<connectivityqt::Connectivity::Limitations>("connectivityqt::Connectivity::Limitations");
    qRegisterMetaType<QVector<connectivityqt::Connectivity::Limitations>>("QVector<connectivityqt::Connectivity::Limitations>");
    qRegisterMetaType<connectivityqt::Connectivity::Status>("connectivityqt::Connectivity::Status");

    qRegisterMetaType<connectivityqt::VpnConnection*>("VpnConnection*");
    qRegisterMetaType<connectivityqt::VpnConnection::Type>("VpnConnection::Type");
    }

    Connectivity::Connectivity(constQDBusConnection&sessionConnection,QObject*parent):
    Connectivity(
    [](QObject*){},
    sessionConnection,
    parent
    )
    {
    }

    Connectivity::Connectivity(conststd::function<void(QObject*)>&objectOwner,
    constQDBusConnection&sessionConnection,
    QObject*parent):
    QObject(parent),d(newPriv(*this,sessionConnection))
    {
    d->m_objectOwner=objectOwner;

    d->m_readInterface=make_shared<
    ComUbuntuConnectivity1NetworkingStatusInterface>(
    DBusTypes::DBUS_NAME,DBusTypes::SERVICE_PATH,
    d->m_sessionConnection);

    d->m_writeInterface=make_shared<ComUbuntuConnectivity1PrivateInterface>(
    DBusTypes::DBUS_NAME,DBusTypes::PRIVATE_PATH,
    d->m_sessionConnection);

    d->m_writePropertyCache=make_shared<internal::DBusPropertyCache>(
    DBusTypes::DBUS_NAME,DBusTypes::PRIVATE_INTERFACE,
    DBusTypes::PRIVATE_PATH,sessionConnection);
    connect(d->m_writePropertyCache.get(),
    &internal::DBusPropertyCache::propertyChanged,d.get(),
    &Priv::propertyChanged);
    connect(d->m_writePropertyCache.get(),
    &internal::DBusPropertyCache::initialized,d.get(),
    &Connectivity::Priv::interfaceInitialized);

    d->m_propertyCache=make_shared<internal::DBusPropertyCache>(
    DBusTypes::DBUS_NAME,DBusTypes::SERVICE_INTERFACE,
    DBusTypes::SERVICE_PATH,sessionConnection);
    connect(d->m_propertyCache.get(),
    &internal::DBusPropertyCache::propertyChanged,d.get(),
    &Priv::propertyChanged);
    connect(d->m_propertyCache.get(),
    &internal::DBusPropertyCache::initialized,d.get(),
    &Connectivity::Priv::interfaceInitialized);

    connect(d->m_writeInterface.get(),
    &ComUbuntuConnectivity1PrivateInterface::ReportError,this,
    &Connectivity::reportError);
    }

    Connectivity::~Connectivity()
    {
    }

    boolConnectivity::flightMode()const
    {
    returnd->m_propertyCache->get("FlightMode").toBool();
    }

    boolConnectivity::wifiEnabled()const
    {
    returnd->m_propertyCache->get("WifiEnabled").toBool();
    }

    boolConnectivity::unstoppableOperationHappening()const
    {
    returnfalse;
    }

    boolConnectivity::flightModeSwitchEnabled()const
    {
    returnd->m_propertyCache->get("FlightModeSwitchEnabled").toBool();
    }

    boolConnectivity::wifiSwitchEnabled()const
    {
    returnd->m_propertyCache->get("WifiSwitchEnabled").toBool();
    }

    boolConnectivity::hotspotSwitchEnabled()const
    {
    returnd->m_propertyCache->get("HotspotSwitchEnabled").toBool();
    }

    QVector<Connectivity::Limitations>Connectivity::limitations()const
    {
    returnd->toLimitations(d->m_propertyCache->get("Limitations"));
    }

    Connectivity::StatusConnectivity::status()const
    {
    returnd->toStatus(d->m_propertyCache->get("Status"));
    }

    boolConnectivity::online()const
    {
    return(status()==Status::Online);
    }

    boolConnectivity::limitedBandwith()const
    {
    returnlimitations().contains(Limitations::Bandwith);
    }

    boolConnectivity::isInitialized()const
    {
    returnd->m_propertyCache->isInitialized()
    &&d->m_writePropertyCache->isInitialized();
    }

    voidConnectivity::setFlightMode(boolenabled)
    {
    d->m_writeInterface->SetFlightMode(enabled);

    //TODORemovethiswhenSDKswitchwidgetisn'tbroken
    d->m_propertyCache->setProperty("FlightMode",enabled);
    }

    voidConnectivity::setwifiEnabled(boolenabled)
    {
    d->m_writeInterface->SetWifiEnabled(enabled);

    //TODORemovethiswhenSDKswitchwidgetisn'tbroken
    d->m_propertyCache->setProperty("WifiEnabled",enabled);
    }

    QByteArrayConnectivity::hotspotSsid()const
    {
    returnd->m_propertyCache->get("HotspotSsid").toByteArray();
    }

    QStringConnectivity::hotspotPassword()const
    {
    returnd->m_writePropertyCache->get("HotspotPassword").toString();
    }

    boolConnectivity::modemAvailable()const
    {
    returnd->m_propertyCache->get("ModemAvailable").toBool();
    }

    boolConnectivity::hotspotEnabled()const
    {
    returnd->m_propertyCache->get("HotspotEnabled").toBool();
    }

    QStringConnectivity::hotspotMode()const
    {
    returnd->m_propertyCache->get("HotspotMode").toString();
    }

    QStringConnectivity::hotspotAuth()const
    {
    returnd->m_writePropertyCache->get("HotspotAuth").toString();
    }

    boolConnectivity::hotspotStored()const
    {
    returnd->m_propertyCache->get("HotspotStored").toBool();
    }

    voidConnectivity::setHotspotSsid(constQByteArray&ssid)
    {
    d->m_writeInterface->SetHotspotSsid(ssid);
    }

    voidConnectivity::setHotspotPassword(constQString&password)
    {
    d->m_writeInterface->SetHotspotPassword(password);
    }

    voidConnectivity::setHotspotEnabled(boolenabled)
    {
    d->m_writeInterface->SetHotspotEnabled(enabled);

    //TODORemovethiswhenSDKswitchwidgetisn'tbroken
    d->m_propertyCache->setProperty("HotspotEnabled",enabled);
    }

    voidConnectivity::setHotspotMode(constQString&mode)
    {
    d->m_writeInterface->SetHotspotMode(mode);
    }

    voidConnectivity::setHotspotAuth(constQString&auth)
    {
    d->m_writeInterface->SetHotspotAuth(auth);
    }

    QAbstractItemModel*Connectivity::vpnConnections()const
    {
    //Lazyinitialisation
    if(!d->m_vpnConnectionsModel)
    {
    d->m_vpnConnectionsModel=make_shared<VpnConnectionsListModel>(
    internal::VpnConnectionsListModelParameters{
    d->m_objectOwner,
    d->m_writeInterface,
    d->m_writePropertyCache});
    d->m_objectOwner(d->m_vpnConnectionsModel.get());
    }
    returnd->m_vpnConnectionsModel.get();
    }

    }

    #include"connectivity.moc"