networksession.cpp 3.47 KB
Newer Older
Lorn Potter's avatar
Lorn Potter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright © 2012, Jolla Ltd
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */

#include "networksession.h"
#include "sessionagent.h"

NetworkSession::NetworkSession(QObject *parent) :
    QObject(parent),
    m_sessionAgent(0),
    m_path("/ConnmanQmlSessionAgent")
{
18
    createSession();
Lorn Potter's avatar
Lorn Potter committed
19 20 21 22 23 24
}

NetworkSession::~NetworkSession()
{
}

25
void NetworkSession::createSession()
Lorn Potter's avatar
Lorn Potter committed
26 27 28
{
    if (m_path.isEmpty())
        return;
Pekka Vuorela's avatar
Pekka Vuorela committed
29 30

    delete m_sessionAgent;
Lorn Potter's avatar
Lorn Potter committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    m_sessionAgent = new SessionAgent(m_path ,this);
    connect(m_sessionAgent,SIGNAL(settingsUpdated(QVariantMap)),
            this,SLOT(sessionSettingsUpdated(QVariantMap)));
}

QString NetworkSession::state() const
{
    return settingsMap.value("State").toString();
}

QString NetworkSession::name() const
{
    return settingsMap.value("Name").toString();
}

QString NetworkSession::bearer() const
{
    return settingsMap.value("Bearer").toString();
}

QString NetworkSession::sessionInterface() const
{
    return settingsMap.value("Interface").toString();
}

QVariantMap NetworkSession::ipv4() const
{
58
    return qdbus_cast<QVariantMap>(settingsMap.value("IPv4"));
Lorn Potter's avatar
Lorn Potter committed
59 60 61 62
}

QVariantMap NetworkSession::ipv6() const
{
63
    return qdbus_cast<QVariantMap>(settingsMap.value("IPv6"));
Lorn Potter's avatar
Lorn Potter committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77
}

QStringList NetworkSession::allowedBearers() const
{
    return settingsMap.value("AllowedBearers").toStringList();
}

QString NetworkSession::connectionType() const
{
    return settingsMap.value("ConnectionType").toString();
}

void NetworkSession::setAllowedBearers(const QStringList &bearers)
{
78
    settingsMap.insert("AllowedBearers", qVariantFromValue(bearers));
Lorn Potter's avatar
Lorn Potter committed
79 80 81 82 83
    m_sessionAgent->setAllowedBearers(bearers);
}

void NetworkSession::setConnectionType(const QString &type)
{
84
    settingsMap.insert("ConnectionType", qVariantFromValue(type));
Lorn Potter's avatar
Lorn Potter committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    m_sessionAgent->setConnectionType(type);
}

void NetworkSession::requestDestroy()
{
    m_sessionAgent->requestDestroy();
}

void NetworkSession::requestConnect()
{
    m_sessionAgent->requestConnect();
}

void NetworkSession::requestDisconnect()
{
    m_sessionAgent->requestDisconnect();
}

void NetworkSession::sessionSettingsUpdated(const QVariantMap &settings)
{
105
    for (const QString &name : settings.keys()) {
Lorn Potter's avatar
Lorn Potter committed
106
        settingsMap.insert(name,settings[name]);
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

        if (name == QLatin1String("State")) {
            Q_EMIT stateChanged(settings[name].toString());
        } else if (name == QLatin1String("Name")) {
            Q_EMIT nameChanged(settings[name].toString());
        } else if (name == QLatin1String("Bearer")) {
            Q_EMIT bearerChanged(settings[name].toString());
        } else if (name == QLatin1String("Interface")) {
            Q_EMIT sessionInterfaceChanged(settings[name].toString());
        } else if (name == QLatin1String("IPv4")) {
            Q_EMIT ipv4Changed(ipv4());
        } else if (name == QLatin1String("IPv6")) {
            Q_EMIT ipv6Changed(ipv6());
        } else if (name == QLatin1String("AllowedBearers")) {
            Q_EMIT allowedBearersChanged(allowedBearers());
        } else if (name == QLatin1String("ConnectionType")) {
            Q_EMIT connectionTypeChanged(settings[name].toString());
        }
Lorn Potter's avatar
Lorn Potter committed
125 126 127 128 129 130 131 132 133 134 135
    }
    Q_EMIT settingsChanged(settings);
}

QString NetworkSession::path() const
{
    return m_path;
}

void NetworkSession::setPath(const QString &path)
{
136 137 138 139
    if (path != m_path) {
        m_path = path;
        createSession();
    }
Lorn Potter's avatar
Lorn Potter committed
140
}