From 5e59a516a3b183a6b3205ce51597e1f85fd32ed2 Mon Sep 17 00:00:00 2001 From: Prajwal Mohan Date: Fri, 27 Apr 2012 15:46:33 -0700 Subject: [PATCH] Initial Import --- connman-qt.pro | 4 + libconnman-qt/clockmodel.cpp | 171 ++++++++++++ libconnman-qt/clockmodel.h | 64 +++++ libconnman-qt/clockproxy.cpp | 26 ++ libconnman-qt/clockproxy.h | 61 +++++ libconnman-qt/commondbustypes.h | 26 ++ libconnman-qt/connman-clock.xml | 18 ++ libconnman-qt/connman-manager.xml | 39 +++ libconnman-qt/connman-service.xml | 39 +++ libconnman-qt/debug.h | 22 ++ libconnman-qt/libconnman-qt.pro | 44 ++++ libconnman-qt/networkitem.cpp | 541 ++++++++++++++++++++++++++++++++++++++ libconnman-qt/networkitem.h | 192 ++++++++++++++ libconnman-qt/networklist.cpp | 215 +++++++++++++++ libconnman-qt/networklist.h | 96 +++++++ libconnman-qt/networkmanager.cpp | 503 +++++++++++++++++++++++++++++++++++ libconnman-qt/networkmanager.h | 127 +++++++++ makedist | 53 ++++ packaging/connman-qt.spec | 135 ++++++++++ plugin/components.cpp | 29 ++ plugin/components.h | 24 ++ plugin/plugin.pro | 15 ++ plugin/qmldir | 1 + test/main.cpp | 19 ++ test/main.qml | 128 +++++++++ test/test.pro | 28 ++ 26 files changed, 2620 insertions(+) create mode 100644 connman-qt.pro create mode 100644 libconnman-qt/clockmodel.cpp create mode 100644 libconnman-qt/clockmodel.h create mode 100644 libconnman-qt/clockproxy.cpp create mode 100644 libconnman-qt/clockproxy.h create mode 100644 libconnman-qt/commondbustypes.h create mode 100644 libconnman-qt/connman-clock.xml create mode 100644 libconnman-qt/connman-manager.xml create mode 100644 libconnman-qt/connman-service.xml create mode 100644 libconnman-qt/debug.h create mode 100644 libconnman-qt/libconnman-qt.pro create mode 100644 libconnman-qt/networkitem.cpp create mode 100644 libconnman-qt/networkitem.h create mode 100644 libconnman-qt/networklist.cpp create mode 100644 libconnman-qt/networklist.h create mode 100644 libconnman-qt/networkmanager.cpp create mode 100644 libconnman-qt/networkmanager.h create mode 100755 makedist create mode 100644 packaging/connman-qt.spec create mode 100644 plugin/components.cpp create mode 100644 plugin/components.h create mode 100644 plugin/plugin.pro create mode 100644 plugin/qmldir create mode 100644 test/main.cpp create mode 100644 test/main.qml create mode 100644 test/test.pro diff --git a/connman-qt.pro b/connman-qt.pro new file mode 100644 index 0000000..7d9ec99 --- /dev/null +++ b/connman-qt.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS += libconnman-qt test plugin +CONFIG += ordered + diff --git a/libconnman-qt/clockmodel.cpp b/libconnman-qt/clockmodel.cpp new file mode 100644 index 0000000..cb738e1 --- /dev/null +++ b/libconnman-qt/clockmodel.cpp @@ -0,0 +1,171 @@ +/* + * Copyright © 2010, Intel Corporation. + * + * 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 "clockmodel.h" + +#define CONNMAN_SERVICE "net.connman" +#define CONNMAN_CLOCK_INTERFACE CONNMAN_SERVICE ".Clock" + +#define SET_CONNMAN_PROPERTY(key, val) \ + if (!mClockProxy) { \ + qCritical("ClockModel: SetProperty: not connected to connman"); \ + } else { \ + QDBusPendingReply<> reply = mClockProxy->SetProperty(key, QDBusVariant(val)); \ + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); \ + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), \ + this, SLOT(setPropertyFinished(QDBusPendingCallWatcher*))); \ + } + +ClockModel::ClockModel() : + mClockProxy(0) +{ + QTimer::singleShot(0,this,SLOT(connectToConnman())); +} + +void ClockModel::connectToConnman() +{ + if (mClockProxy && mClockProxy->isValid()) + return; + + mClockProxy = new ClockProxy(CONNMAN_SERVICE, "/", QDBusConnection::systemBus(), this); + + if (!mClockProxy->isValid()) { + qCritical("ClockModel: unable to connect to connman"); + delete mClockProxy; + mClockProxy = NULL; + return; + } + + QDBusPendingReply reply = mClockProxy->GetProperties(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, + SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(getPropertiesFinished(QDBusPendingCallWatcher*))); + + connect(mClockProxy, + SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), + this, + SLOT(propertyChanged(const QString&, const QDBusVariant&))); +} + +void ClockModel::getPropertiesFinished(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply reply = *call; + if (reply.isError()) { + qCritical() << "ClockModel: getProperties: " << reply.error().name() << reply.error().message(); + } else { + QVariantMap properties = reply.value(); + + Q_ASSERT(properties.contains("Timezone")); + Q_ASSERT(properties.value("Timezone").type() == QVariant::String); + mTimezone = properties.value("Timezone").toString(); + emit timezoneChanged(); + + Q_ASSERT(properties.contains("TimezoneUpdates")); + Q_ASSERT(properties.value("TimezoneUpdates").type() == QVariant::String); + mTimezoneUpdates = properties.value("TimezoneUpdates").toString(); + emit timezoneUpdatesChanged(); + + Q_ASSERT(properties.contains("TimeUpdates")); + Q_ASSERT(properties.value("TimeUpdates").type() == QVariant::String); + mTimeUpdates = properties.value("TimeUpdates").toString(); + emit timeUpdatesChanged(); + + Q_ASSERT(properties.contains("Timeservers")); + Q_ASSERT(properties.value("Timeservers").type() == QVariant::StringList); + mTimeservers = properties.value("Timeservers").toStringList(); + emit timeserversChanged(); + } + call->deleteLater(); +} + +void ClockModel::setPropertyFinished(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply<> reply = *call; + if (reply.isError()) { + qCritical() << "ClockModel: setProperty: " << reply.error().name() << reply.error().message(); + } + call->deleteLater(); +} + +void ClockModel::propertyChanged(const QString &name, const QDBusVariant &value) +{ + if (name == "Timezone") { + Q_ASSERT(value.variant().type() == QVariant::String); + mTimezone = value.variant().toString(); + emit timezoneChanged(); + } else if (name == "TimezoneUpdates") { + Q_ASSERT(value.variant().type() == QVariant::String); + mTimezoneUpdates = value.variant().toString(); + emit timezoneUpdatesChanged(); + } else if (name == "TimeUpdates") { + Q_ASSERT(value.variant().type() == QVariant::String); + mTimeUpdates = value.variant().toString(); + emit timeUpdatesChanged(); + } else if (name == "Timeservers") { + Q_ASSERT(value.variant().type() == QVariant::StringList); + mTimeservers = value.variant().toStringList(); + emit timeserversChanged(); + } +} + +QString ClockModel::timezone() const +{ + return mTimezone; +} + +void ClockModel::setTimezone(const QString &val) +{ + SET_CONNMAN_PROPERTY("Timezone", val); +} + +QString ClockModel::timezoneUpdates() const +{ + return mTimezoneUpdates; +} + +void ClockModel::setTimezoneUpdates(const QString &val) +{ + SET_CONNMAN_PROPERTY("TimezoneUpdates", val); +} + +QString ClockModel::timeUpdates() const +{ + return mTimeUpdates; +} + +void ClockModel::setTimeUpdates(const QString &val) +{ + SET_CONNMAN_PROPERTY("TimeUpdates", val); +} + +QStringList ClockModel::timeservers() const +{ + return mTimeservers; +} + +void ClockModel::setTimeservers(const QStringList &val) +{ + SET_CONNMAN_PROPERTY("Timeservers", val); +} + +void ClockModel::setDate(QDate date) +{ + QDateTime toDate(date, QTime::currentTime()); + quint64 secsSinceEpoch = (quint64)toDate.toTime_t(); + SET_CONNMAN_PROPERTY("Time", secsSinceEpoch); +} + +void ClockModel::setTime(QTime time) +{ + QDateTime toDate(QDate::currentDate(), time); + quint64 secsSinceEpoch = (quint64)toDate.toTime_t(); + SET_CONNMAN_PROPERTY("Time", secsSinceEpoch); +} diff --git a/libconnman-qt/clockmodel.h b/libconnman-qt/clockmodel.h new file mode 100644 index 0000000..5ee7e12 --- /dev/null +++ b/libconnman-qt/clockmodel.h @@ -0,0 +1,64 @@ +/* + * Copyright © 2010, Intel Corporation. + * + * 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 + * + */ + +#ifndef CLOCKMODEL_H +#define CLOCKMODEL_H + +#include "clockproxy.h" + +class ClockModel : public QObject { + Q_OBJECT; + + Q_PROPERTY(QString timezone READ timezone WRITE setTimezone NOTIFY timezoneChanged); + Q_PROPERTY(QString timezoneUpdates READ timezoneUpdates WRITE setTimezoneUpdates NOTIFY timezoneUpdatesChanged); + Q_PROPERTY(QString timeUpdates READ timeUpdates WRITE setTimeUpdates NOTIFY timeUpdatesChanged); + Q_PROPERTY(QStringList timeservers READ timeservers WRITE setTimeservers NOTIFY timeserversChanged); + +public: + ClockModel(); + +public slots: + QString timezone() const; + void setTimezone(const QString &val); + QString timezoneUpdates() const; + void setTimezoneUpdates(const QString &val); + QString timeUpdates() const; + void setTimeUpdates(const QString &val); + QStringList timeservers() const; + void setTimeservers(const QStringList &val); + + void setDate(QDate date); + void setTime(QTime time); + + // helper function for Timepicker + QTime time(QString h, QString m) { return QTime(h.toInt(), m.toInt()); } + +signals: + void timezoneChanged(); + void timezoneUpdatesChanged(); + void timeUpdatesChanged(); + void timeserversChanged(); + +private slots: + void connectToConnman(); + void getPropertiesFinished(QDBusPendingCallWatcher*); + void setPropertyFinished(QDBusPendingCallWatcher*); + void propertyChanged(const QString&, const QDBusVariant&); + +private: + ClockProxy *mClockProxy; + QString mTimezone; + QString mTimezoneUpdates; + QString mTimeUpdates; + QStringList mTimeservers; + + Q_DISABLE_COPY(ClockModel); +}; + +#endif diff --git a/libconnman-qt/clockproxy.cpp b/libconnman-qt/clockproxy.cpp new file mode 100644 index 0000000..96fa59c --- /dev/null +++ b/libconnman-qt/clockproxy.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -c ClockProxy connman-clock.xml -p clockproxy + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "clockproxy.h" + +/* + * Implementation of interface class ClockProxy + */ + +ClockProxy::ClockProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +ClockProxy::~ClockProxy() +{ +} + diff --git a/libconnman-qt/clockproxy.h b/libconnman-qt/clockproxy.h new file mode 100644 index 0000000..518b585 --- /dev/null +++ b/libconnman-qt/clockproxy.h @@ -0,0 +1,61 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -c ClockProxy connman-clock.xml -p clockproxy + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef CLOCKPROXY_H_1307042690 +#define CLOCKPROXY_H_1307042690 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface net.connman.Clock + */ +class ClockProxy: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "net.connman.Clock"; } + +public: + ClockProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~ClockProxy(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply GetProperties() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + } + + inline QDBusPendingReply<> SetProperty(const QString &in0, const QDBusVariant &in1) + { + QList argumentList; + argumentList << qVariantFromValue(in0) << qVariantFromValue(in1); + return asyncCallWithArgumentList(QLatin1String("SetProperty"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void PropertyChanged(const QString &in0, const QDBusVariant &in1); +}; + +namespace net { + namespace connman { + typedef ::ClockProxy Clock; + } +} +#endif diff --git a/libconnman-qt/commondbustypes.h b/libconnman-qt/commondbustypes.h new file mode 100644 index 0000000..0322b06 --- /dev/null +++ b/libconnman-qt/commondbustypes.h @@ -0,0 +1,26 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 + * + */ + +#ifndef COMMONDBUSTYPES_H +#define COMMONDBUSTYPES_H + +#include +#include +#include +#include + +typedef QMap StringMap; +Q_DECLARE_METATYPE ( StringMap ); + +inline void registerCommonDataTypes() { + qDBusRegisterMetaType(); +} + +#endif //COMMONDBUSTYPES_H diff --git a/libconnman-qt/connman-clock.xml b/libconnman-qt/connman-clock.xml new file mode 100644 index 0000000..10cec3a --- /dev/null +++ b/libconnman-qt/connman-clock.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/libconnman-qt/connman-manager.xml b/libconnman-qt/connman-manager.xml new file mode 100644 index 0000000..5c7e60d --- /dev/null +++ b/libconnman-qt/connman-manager.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libconnman-qt/connman-service.xml b/libconnman-qt/connman-service.xml new file mode 100644 index 0000000..243d88e --- /dev/null +++ b/libconnman-qt/connman-service.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libconnman-qt/debug.h b/libconnman-qt/debug.h new file mode 100644 index 0000000..a8d9f0b --- /dev/null +++ b/libconnman-qt/debug.h @@ -0,0 +1,22 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 + * + */ +#ifndef DEBUG_H +#define DEBUG_H + +#include + +#define STR(qstring) qstring.toLatin1().constData() + + #include + #define MDEBUG(...) qDebug(__VA_ARGS__) + #define MWARNING(...) qWarning(__VA_ARGS__) + #define MCRITICAL(...) qCritical(__VA__ARGS__) + +#endif //DEBUG_H diff --git a/libconnman-qt/libconnman-qt.pro b/libconnman-qt/libconnman-qt.pro new file mode 100644 index 0000000..bb746fe --- /dev/null +++ b/libconnman-qt/libconnman-qt.pro @@ -0,0 +1,44 @@ +#-*-Shell-Script-*- + +TEMPLATE = lib +VERSION=0.1.4 +CONFIG += qt \ + debug +QT += dbus +TARGET = $$qtLibraryTarget(connman-qt4) +isEmpty(PREFIX) { + PREFIX=/usr +} +target.path = $$INSTALL_ROOT$$PREFIX/lib + +system(qdbusxml2cpp -c Manager -p manager -N connman-manager.xml) +system(qdbusxml2cpp -c Service -p service -N connman-service.xml) + +HEADERS += manager.h \ + service.h \ + networkitem.h \ + networklist.h \ + networkmanager.h \ + commondbustypes.h \ + clockproxy.h \ + clockmodel.h + +headers.files = manager.h service.h networkitem.h \ + networklist.h commondbustypes.h clockproxy.h clockmodel.h networkmanager.h +headers.path = $$INSTALL_ROOT$$PREFIX/include/connman-qt + +CONFIG += create_pc create_prl +QMAKE_PKGCONFIG_DESCRIPTION = Qt Connman Library +QMAKE_PKGCONFIG_INCDIR = $$headers.path +pkgconfig.path = $$INSTALL_ROOT$$PREFIX/lib/pkgconfig +pkgconfig.files = connman-qt4.pc + +SOURCES += networkitem.cpp \ + networklist.cpp \ + networkmanager.cpp \ + manager.cpp \ + service.cpp \ + clockproxy.cpp \ + clockmodel.cpp + +INSTALLS += target headers pkgconfig diff --git a/libconnman-qt/networkitem.cpp b/libconnman-qt/networkitem.cpp new file mode 100644 index 0000000..ee92181 --- /dev/null +++ b/libconnman-qt/networkitem.cpp @@ -0,0 +1,541 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 "networkitem.h" +#include "debug.h" +#include "commondbustypes.h" + +#include + +//FIXME: could reuse these static strings for getProperties and popertyChanged +const char* const NetworkItemModel::Name = "Name"; +const char* const NetworkItemModel::Security = "Security"; +const char* const NetworkItemModel::Strength = "Strength"; +const char* const NetworkItemModel::State = "State"; +const char* const NetworkItemModel::Type = "Type"; +const char* const NetworkItemModel::PassphraseRequired = "PassphraseRequired"; +const char* const NetworkItemModel::Passphrase = "Passphrase"; +const char* const NetworkItemModel::IPv4 = "IPv4.Configuration"; +const char* const NetworkItemModel::IPv4Normal = "IPv4"; +const char* const NetworkItemModel::Nameservers = "Nameservers"; +const char* const NetworkItemModel::DeviceAddress = "DeviceAddress"; +const char* const NetworkItemModel::Mode = "Mode"; +const char* const NetworkItemModel::APN = "APN"; +const char* const NetworkItemModel::SetupRequired = "SetupRequired"; +///todo: not hooked up: +const char* const NetworkItemModel::LoginRequired = "LoginRequired"; + +int NetworkItemModel::instances = 0; +int NetworkItemModel::idCounter = 0; + +NetworkItemModel::NetworkItemModel(const QString &path, QObject *parent) : + id(idCounter), + m_service(NULL), + m_getPropertiesWatcher(NULL), + m_setPropertyWatcher(NULL), + m_disconnectWatcher(NULL), + m_connectWatcher(NULL), + m_state(StateNone), + m_strength(0), + m_passphraseRequired(false) +{ + registerCommonDataTypes(); + + setParent(parent); + instances++; + idCounter++; + m_servicePath = path; + if (!path.isEmpty()) { + m_service = new Service("net.connman", path, + QDBusConnection::systemBus(), + this); + if (!m_service->isValid()) { + qDebug("service %s is invalid!", STR(path)); + throw -1; //FIXME + } + QDBusPendingReply reply = m_service->GetProperties(); + m_getPropertiesWatcher = new QDBusPendingCallWatcher(reply, this); + connect(m_getPropertiesWatcher, + SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(getPropertiesReply(QDBusPendingCallWatcher*))); + + connect(m_service, + SIGNAL(PropertyChanged(const QString&, + const QDBusVariant &)), + this, + SLOT(propertyChanged(const QString&, + const QDBusVariant &))); + + } + + + //this is an attempt to avoid having lots of networks show in the + //list with no type. The thought process is that the filter is + //matching on empty strings. It doesn't appear to work in the + //nothing in the list except one thing problem. But other problems + //haven't been tried + m_type = "????"; +} + +NetworkItemModel::~NetworkItemModel() +{ + instances--; + qDebug("destructing instance %d. There are %d models around", id, instances); +} + + +void NetworkItemModel::connectService() +{ +#ifdef PRETEND + qDebug("connectService pretending"); +#else + qDebug("connectService FOR REAL"); + m_service->Connect(); +#endif +} + +void NetworkItemModel::disconnectService() +{ +#ifdef PRETEND + qDebug("disconnectService pretending"); +#else + qDebug("disconnectService FOR REAL"); + m_service->Disconnect(); +#endif +} + +void NetworkItemModel::removeService() +{ +#ifdef PRETEND + qDebug("removeService pretending"); +#else + qDebug("removeService FOR REAL"); + m_service->Remove(); +#endif +} + +void NetworkItemModel::moveBefore(NetworkItemModel *other) +{ + m_service->MoveBefore(QDBusObjectPath(other->servicePath())); +} + +void NetworkItemModel::moveAfter(NetworkItemModel *other) +{ + m_service->MoveAfter(QDBusObjectPath(other->servicePath())); +} + +const QString& NetworkItemModel::name() const +{ + return m_name; +} + +const QString& NetworkItemModel::security() const +{ + return m_security; +} + +const NetworkItemModel::StateType& NetworkItemModel::state() const +{ + return m_state; +} + +const int& NetworkItemModel::strength() const +{ + return m_strength; +} + +const QString& NetworkItemModel::type() const +{ + return m_type; +} + +const bool& NetworkItemModel::passphraseRequired() const +{ + return m_passphraseRequired; +} + +const QString& NetworkItemModel::passphrase() const +{ + return m_passphrase; +} + +const NetworkItemModel::IPv4Type& NetworkItemModel::ipv4() const +{ + return m_ipv4; +} + +const QString& NetworkItemModel::mode() const +{ + return m_mode; +} + +const QString NetworkItemModel::ipv4address() const +{ + return ipv4().Address; +} + +const QString NetworkItemModel::ipv4netmask() const +{ + return ipv4().Netmask; +} + +const QString NetworkItemModel::ipv4gateway() const +{ + return ipv4().Gateway; +} + +const QString NetworkItemModel::ipv4method() const +{ + return ipv4().Method; +} + +const bool& NetworkItemModel::setupRequired() const +{ + return m_setupRequired; +} + +const QString NetworkItemModel::apn() const +{ + return m_apn; +} + +const QString NetworkItemModel::error() const +{ + return m_error; +} + +void NetworkItemModel::setPassphrase(const QString &passphrase) +{ + Q_ASSERT(m_service); + QDBusPendingReply reply = + m_service->SetProperty("Passphrase", QDBusVariant(QVariant(passphrase))); + reply.waitForFinished(); //FIXME: BAD + if (reply.isError()) { + qDebug()<<"got error from setProperty: "< reply = + m_service->SetProperty(QString(IPv4), QDBusVariant(variant)); + if (m_setPropertyWatcher) { + delete m_setPropertyWatcher; + } + m_setPropertyWatcher = new QDBusPendingCallWatcher(reply, this); + connect(m_setPropertyWatcher, + SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(setPropertyFinished(QDBusPendingCallWatcher*))); +} + +void NetworkItemModel::setApn(QString value) +{ + Q_ASSERT(m_service); + + m_service->SetProperty(APN, QDBusVariant(QVariant(value))); +} + +const QString& NetworkItemModel::servicePath() const +{ + return m_servicePath; +} + +const QStringList& NetworkItemModel::nameservers() const +{ + return m_nameservers; +} + +const QString& NetworkItemModel::deviceAddress() const +{ + return m_deviceAddress; +} + +void NetworkItemModel::setNameservers(const QStringList &nameservers) +{ + Q_ASSERT(m_service); + + if (!isListEqual(m_nameservers, nameservers)) { + QVariant variant = qVariantFromValue(nameservers); + QDBusPendingReply reply = + m_service->SetProperty(Nameservers, QDBusVariant(variant)); + //I hate to wait here, but I'm not sure what else to do + reply.waitForFinished(); + if (reply.isError()) { + qDebug("got error from setProperty"); + throw -1; //FIXME: don't throw + } + } +} + +void NetworkItemModel::setIpv4Address(QString v) +{ + m_ipv4.Address = v; + setIpv4(m_ipv4); +} + +void NetworkItemModel::setIpv4Netmask(QString v ) +{ + m_ipv4.Netmask = v; + setIpv4(m_ipv4); +} + +void NetworkItemModel::setIpv4Gateway(QString v) +{ + m_ipv4.Gateway = v; + setIpv4(m_ipv4); +} + +void NetworkItemModel::setIpv4Method(QString v) +{ + m_ipv4.Method = v; + setIpv4(m_ipv4); +} + +NetworkItemModel::StateType NetworkItemModel::state(const QString &state) +{ + NetworkItemModel::StateType _state; + if (state == "idle") { + _state = StateIdle; + } else if (state == "failure") { + _state = StateFailure; + } else if (state == "association") { + _state = StateAssociation; + } else if (state == "configuration") { + _state = StateConfiguration; + } else if (state == "ready") { + _state = StateReady; + } else if (state == "online") { + _state = StateOnline; + } else { + _state = StateNone; + qDebug("setting to to STATE_NONE because of unknown state returned: \"%s\"", STR(state)); + } + + return _state; +} + +//This sets the m_ipv4 with data. It does not set the data on the +//Service object +void NetworkItemModel::_setIpv4(const QVariantMap &ipv4) +{ + bool modified = false; + QString string; + + string = ipv4["Method"].toString(); + // qDebug("Method: %s", STR(string)); + if (m_ipv4.Method != string) { + m_ipv4.Method = string; + modified = true; + methodChanged(); + } + string = ipv4["Address"].toString(); + //qDebug("Address: %s", STR(string)); + if (m_ipv4.Address != string) { + m_ipv4.Address = string; + modified = true; + addressChanged(); + } + string = ipv4["Netmask"].toString(); + //qDebug("Netmask: %s", STR(string)); + if (m_ipv4.Netmask != string) { + m_ipv4.Netmask = string; + modified = true; + netmaskChanged(); + } + string = ipv4["Gateway"].toString(); + // qDebug("Gateway: %s", STR(string)); + if (m_ipv4.Gateway != string) { + m_ipv4.Gateway = string; + modified = true; + gatewayChanged(); + } +} + +bool NetworkItemModel::isListEqual(const QStringList &a, const QStringList &b) const +{ + if (a.count() != b.count()) { + return false; + } + for (int i=0; i < a.count(); i++) { + if (a.at(i) != b.at(i)) { + return false; + } + } + return true; +} + + + +void NetworkItemModel::getPropertiesReply(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug("getPropertiesReply is error!"); + QDBusError error = reply.error(); + qDebug("service: %s", STR(servicePath())); + qDebug()<(properties[Name]); + nameChanged(m_name); + m_type = qdbus_cast(properties[Type]); + typeChanged(m_type); + m_mode= qdbus_cast(properties[Mode]); + + QStringList sec = qdbus_cast(properties[Security]); + + if(sec.count() > 0) + { + m_security = sec.at(0); + securityChanged(m_security); + } + + m_passphraseRequired = qdbus_cast(properties[PassphraseRequired]); + m_passphrase = qdbus_cast(properties[Passphrase]); + passphraseChanged(m_passphrase); + m_strength = qdbus_cast(properties[Strength]); + strengthChanged(m_strength); + m_state = state(qdbus_cast(properties[State])); + _setIpv4(qdbus_cast(properties[IPv4Normal])); + m_nameservers = qdbus_cast(properties[Nameservers]); + m_deviceAddress = qdbus_cast(properties["Ethernet"])["Address"].toString(); + m_apn = qdbus_cast(properties[APN]); + m_error = qdbus_cast(properties["Error"]); + errorChanged(); + m_setupRequired = qdbus_cast(properties[SetupRequired]); + emit propertyChanged("",""); +} + +void NetworkItemModel::propertyChanged(const QString &name, + const QDBusVariant &value) +{ + qDebug()<<"NetworkItemModel: property "<(value.variant()); + + if(sec.count() > 0) + { + m_security = sec.at(0); + securityChanged(m_security); + } + } else if (name == PassphraseRequired) { + m_passphraseRequired = (value.variant().toBool()); + } else if (name == Passphrase) { + m_passphrase = (value.variant().toString()); + passphraseChanged(m_passphrase); + } else if (name == Strength) { + m_strength = (value.variant().toInt()); + strengthChanged(m_strength); + } else if (name == IPv4 || name == IPv4Normal) { + _setIpv4(qdbus_cast(value.variant())); + } else if (name == Nameservers) { + m_nameservers = (value.variant().toStringList()); + } else if (name == "Ethernet") { + m_deviceAddress = (qdbus_cast(value.variant())["Address"].toString()); + } else if (name == SetupRequired) { + m_setupRequired = value.variant().toBool(); + setupRequiredChanged(m_setupRequired); + } else if (name == APN) { + m_apn = value.variant().toString(); + } else if (name == "Error") { + m_error = value.variant().toString(); + errorChanged(); + } else { + qDebug("We don't do anything with property: %s", STR(name)); + } + + emit propertyChanged(name,value.variant()); +} + +void NetworkItemModel::setPropertyFinished(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug()<<"not continuing because of error in setProperty!"< nextReply = m_service->Disconnect(); + if (m_setPropertyWatcher) { + delete m_setPropertyWatcher; + } + m_setPropertyWatcher = new QDBusPendingCallWatcher(nextReply, this); + connect(m_setPropertyWatcher, + SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(disconnectFinished(QDBusPendingCallWatcher*))); + } +} + +void NetworkItemModel::disconnectFinished(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug("not continuing because of error in disconnect!"); + } else { + QDBusPendingReply nextReply = m_service->Connect(); + if (m_setPropertyWatcher) { + delete m_setPropertyWatcher; + } + m_disconnectWatcher = new QDBusPendingCallWatcher(nextReply, this); + connect(m_disconnectWatcher, + SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(connectFinished(QDBusPendingCallWatcher*))); + } +} + +void NetworkItemModel::connectFinished(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug("error calling connect!"); + } else { + qDebug("connect finished without error"); + } +} + diff --git a/libconnman-qt/networkitem.h b/libconnman-qt/networkitem.h new file mode 100644 index 0000000..b23da8a --- /dev/null +++ b/libconnman-qt/networkitem.h @@ -0,0 +1,192 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 + * + */ +#ifndef NETWORKITEMMODEL_H +#define NETWORKITEMMODEL_H + +#include "service.h" +#include "commondbustypes.h" + +#include +#include + +//#define PRETEND 1 + + + +class NetworkItemModel : public QObject +{ + Q_OBJECT + + public: + enum StateType { + StateNone = 0, + StateIdle, + StateFailure, + StateAssociation, + StateConfiguration, + StateReady, + StateOnline, + }; + + struct IPv4Type + { + QString Method; + QString Address; + QString Netmask; + QString Gateway; + }; + + public: + NetworkItemModel(const QString &path = QString(), QObject *parent = 0); + virtual ~NetworkItemModel(); + + public: + /* property names */ + static const char* const Name; + static const char* const Security; + static const char* const State; + static const char* const Strength; + static const char* const Type; + static const char* const PassphraseRequired; + static const char* const Passphrase; + static const char* const IPv4; + static const char* const IPv4Normal; + static const char* const Nameservers; + static const char* const DeviceAddress; + static const char* const Mode; + static const char* const SetupRequired; + static const char* const APN; + static const char* const LoginRequired; + + /* property definitions */ + Q_PROPERTY(QString name READ name NOTIFY nameChanged); + Q_PROPERTY(QString security READ security NOTIFY securityChanged); + Q_PROPERTY(StateType state READ state NOTIFY stateChanged); + Q_PROPERTY(int strength READ strength NOTIFY strengthChanged); + Q_PROPERTY(QString type READ type NOTIFY typeChanged); + Q_PROPERTY(QString mode READ mode); + Q_PROPERTY(bool passphraseRequired READ passphraseRequired); + Q_PROPERTY(QString passphrase READ passphrase WRITE setPassphrase NOTIFY passphraseChanged); + Q_PROPERTY(IPv4Type ipv4 READ ipv4 WRITE setIpv4); + Q_PROPERTY(QStringList nameservers READ nameservers WRITE setNameservers); + Q_PROPERTY(QString deviceAddress READ deviceAddress); + Q_PROPERTY(QString ipaddress READ ipv4address WRITE setIpv4Address NOTIFY addressChanged); + Q_PROPERTY(QString netmask READ ipv4netmask WRITE setIpv4Netmask NOTIFY netmaskChanged); + Q_PROPERTY(QString method READ ipv4method WRITE setIpv4Method NOTIFY methodChanged); + Q_PROPERTY(QString gateway READ ipv4gateway WRITE setIpv4Gateway NOTIFY gatewayChanged); + Q_PROPERTY(bool setupRequired READ setupRequired NOTIFY setupRequiredChanged) + Q_PROPERTY(QString apn READ apn WRITE setApn) + Q_PROPERTY(QString error READ error NOTIFY errorChanged) + Q_ENUMS(StateType) + + /* property getters */ + const QString& name() const; + const QString& security() const; + const StateType& state() const; + const int& strength() const; + const QString& type() const; + const bool& passphraseRequired() const; + const QString &passphrase() const; + // const QVariantMap &ipv4() const; + const IPv4Type &ipv4() const; + const QStringList &nameservers() const; + const QString &deviceAddress() const; + const QString &mode() const; + const QString ipv4address() const; + const QString ipv4netmask() const; + const QString ipv4gateway() const; + const QString ipv4method() const; + const bool& setupRequired() const; + const QString error() const; + const QString apn() const; + + /* property setters */ + //These actually set the property on the underlying service object. + void setPassphrase(const QString &passphrase); + void setIpv4(const IPv4Type &ipv4); + void setNameservers(const QStringList &nameservers); + + void setIpv4Address(QString); + void setIpv4Netmask(QString); + void setIpv4Gateway(QString); + void setIpv4Method(QString); + void setApn(QString); + + /* debug */ + int id; + static int instances; + static int idCounter; + + const QString& servicePath() const; + + public slots: + void connectService(); + void disconnectService(); + void removeService(); + void moveBefore(NetworkItemModel* other); + void moveAfter(NetworkItemModel* other); + +signals: + void propertyChanged(QString name, QVariant value); + void nameChanged(QString newname); + void securityChanged(QString security); + void setupRequiredChanged(bool setupRequired); + void stateChanged(NetworkItemModel::StateType newstate); + void passphraseChanged(QString newPassphrase); + void typeChanged(QString newType); + void strengthChanged(int newStrength); + void methodChanged(); + void addressChanged(); + void netmaskChanged(); + void gatewayChanged(); + void errorChanged(); + + private: + bool isListEqual(const QStringList &a, const QStringList &b) const; + StateType state(const QString &); + void _setIpv4(const QVariantMap &ipv4); + + QString m_servicePath; + Service *m_service; + QDBusPendingCallWatcher *m_getPropertiesWatcher; + QDBusPendingCallWatcher *m_setPropertyWatcher; + QDBusPendingCallWatcher *m_disconnectWatcher; + QDBusPendingCallWatcher *m_connectWatcher; + + QString m_name; + QString m_security; + StateType m_state; + int m_strength; + QString m_type; /* should be enum ?? */ + bool m_passphraseRequired; + QString m_passphrase; + IPv4Type m_ipv4; + QStringList m_nameservers; + QString m_deviceAddress; + QString m_mode; + bool m_setupRequired; + QString m_apn; + QString m_error; + +private slots: + void getPropertiesReply(QDBusPendingCallWatcher *call); + void propertyChanged(const QString &name, + const QDBusVariant &value); + + //These are all due to MBC#1070 + void setPropertyFinished(QDBusPendingCallWatcher *call); + void disconnectFinished(QDBusPendingCallWatcher *call); + void connectFinished(QDBusPendingCallWatcher *call); +}; + +Q_DECLARE_METATYPE(NetworkItemModel::IPv4Type); + +#endif //NETWORKITEMMODEL_H + diff --git a/libconnman-qt/networklist.cpp b/libconnman-qt/networklist.cpp new file mode 100644 index 0000000..f19af49 --- /dev/null +++ b/libconnman-qt/networklist.cpp @@ -0,0 +1,215 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 "networklist.h" +#include "debug.h" + +NetworkListModel::NetworkListModel(QObject* parent) + : QAbstractListModel(parent) +{ + m_networkManager = NetworkManagerFactory::createInstance(); + + connect(m_networkManager,SIGNAL(networksAdded(int,int)),this,SLOT(networksAdded(int,int))); + connect(m_networkManager,SIGNAL(networksMoved(int,int,int)),this,SLOT(networksMoved(int,int,int))); + connect(m_networkManager,SIGNAL(networksRemoved(int,int)),this,SLOT(networksRemoved(int,int))); + connect(m_networkManager,SIGNAL(networkChanged(int)),this,SLOT(networkChanged(int))); + + connect(m_networkManager,SIGNAL(technologiesChanged(QStringList,QStringList,QStringList)), + this, SIGNAL(technologiesChanged(QStringList,QStringList,QStringList))); + connect(m_networkManager,SIGNAL(availableTechnologiesChanged(QStringList)), + this, SIGNAL(availableTechnologiesChanged(QStringList))); + connect(m_networkManager,SIGNAL(enabledTechnologiesChanged(QStringList)), + this,SIGNAL(enabledTechnologiesChanged(QStringList))); + connect(m_networkManager,SIGNAL(connectedTechnologiesChanged(QStringList)), + this,SIGNAL(connectedTechnologiesChanged(QStringList))); + connect(m_networkManager,SIGNAL(offlineModeChanged(bool)), + this,SIGNAL(offlineModeChanged(bool))); + connect(m_networkManager,SIGNAL(defaultTechnologyChanged(QString)), + this,SIGNAL(defaultTechnologyChanged(QString))); + connect(m_networkManager,SIGNAL(stateChanged(QString)), + this,SIGNAL(stateChanged(QString))); + connect(m_networkManager,SIGNAL(countChanged(int)),this,SIGNAL(countChanged(int))); + connect(m_networkManager,SIGNAL(defaultRouteChanged(NetworkItemModel*)), + this,SIGNAL(defaultRouteChanged(NetworkItemModel*))); + connect(m_networkManager,SIGNAL(connectedNetworkItemsChanged()), + this,SIGNAL(connectedNetworkItemsChanged())); + + if(m_networkManager->networks().count()); + networksAdded(0, m_networkManager->networks().count()); + + QHash roles; + + QMetaObject properties = NetworkItemModel::staticMetaObject; + int i=0; + for(; inetworks().size(); +} + +int NetworkListModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 1; +} + +QVariant NetworkListModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + return QVariant(); +} + + +QVariant NetworkListModel::data(const QModelIndex &index, int role) const +{ + //qDebug("NetworkListModel::data"); + + + QString roleName = roleNames()[role]; + QMetaObject object = NetworkItemModel::staticMetaObject; + + if(!(index.isValid() && index.row() < shadowList.size())) + return QVariant(); + if(roleName == "networkitemmodel") + { + return QVariant::fromValue((QObject*)shadowList[index.row()]); + } + else if(roleName == "defaultRoute") + { + return m_networkManager->defaultRoute() == shadowList[index.row()]; + } + + for(int i=0; isetProperty(index, property, value); +} + +void NetworkListModel::enableTechnology(const QString &technology) +{ + m_networkManager->enableTechnology(technology); +} + +void NetworkListModel::disableTechnology(const QString &technology) +{ + m_networkManager->disableTechnology(technology); +} + +NetworkItemModel* NetworkListModel::service(QString name) +{ + return m_networkManager->service(name); +} + +void NetworkListModel::connectService(const QString &name, const QString &security, + const QString &passphrase) +{ + m_networkManager->connectService(name, security,passphrase); +} + +void NetworkListModel::connectService(const QString &name) +{ + m_networkManager->connectService(name); +} + +const QStringList NetworkListModel::availableTechnologies() const +{ + return m_networkManager->availableTechnologies(); +} + +const QStringList NetworkListModel::enabledTechnologies() const +{ + return m_networkManager->enabledTechnologies(); +} + +const QStringList NetworkListModel::connectedTechnologies() const +{ + return m_networkManager->connectedTechnologies(); +} + +void NetworkListModel::setDefaultRoute(NetworkItemModel *item) +{ + m_networkManager->setDefaultRoute(item); +} + +void NetworkListModel::requestScan() +{ + m_networkManager->requestScan(); +} + +void NetworkListModel::setOfflineMode(const bool &offlineMode) +{ + m_networkManager->setOfflineMode(offlineMode); +} + +bool NetworkListModel::offlineMode() const +{ + return m_networkManager->offlineMode(); +} + +QString NetworkListModel::defaultTechnology() const +{ + return m_networkManager->defaultTechnology(); +} + +QString NetworkListModel::state() const +{ + return m_networkManager->state(); +} + +void NetworkListModel::networksAdded(int from, int to) +{ + beginInsertRows(QModelIndex(), from, to); + + shadowList = m_networkManager->networks(); + + endInsertRows(); +} + +void NetworkListModel::networksMoved(int from, int to, int to2) +{ + beginMoveRows(QModelIndex(), from, to, QModelIndex(), to2); + shadowList = m_networkManager->networks(); + endMoveRows(); +} + +void NetworkListModel::networksRemoved(int from, int to) +{ + beginRemoveRows(QModelIndex(), from, to); + shadowList = m_networkManager->networks(); + endRemoveRows(); +} + +void NetworkListModel::networkChanged(int index) +{ + dataChanged(createIndex(index,0),createIndex(index,0)); +} diff --git a/libconnman-qt/networklist.h b/libconnman-qt/networklist.h new file mode 100644 index 0000000..b9b050f --- /dev/null +++ b/libconnman-qt/networklist.h @@ -0,0 +1,96 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 + * + */ +#ifndef NETWORKLISTMODEL_H +#define NETWORKLISTMODEL_H + +#include "networkitem.h" +#include "networkmanager.h" + +#include +#include + +class QDBusServiceWatcher; + +class NetworkListModel : public QAbstractListModel +{ + Q_OBJECT; + + Q_PROPERTY(bool offlineMode READ offlineMode WRITE setOfflineMode NOTIFY offlineModeChanged); + Q_PROPERTY(QString defaultTechnology READ defaultTechnology NOTIFY defaultTechnologyChanged); + Q_PROPERTY(QString state READ state NOTIFY stateChanged); + Q_PROPERTY(int count READ rowCount NOTIFY countChanged); + Q_PROPERTY(QStringList availableTechnologies READ availableTechnologies NOTIFY availableTechnologiesChanged); + Q_PROPERTY(QStringList enabledTechnologies READ enabledTechnologies NOTIFY enabledTechnologiesChanged); + Q_PROPERTY(QStringList connectedTechnologies READ connectedTechnologies NOTIFY connectedTechnologiesChanged); + Q_PROPERTY(NetworkItemModel* defaultRoute READ defaultRoute WRITE setDefaultRoute NOTIFY defaultRouteChanged); + + +public: + NetworkListModel(QObject* parent=0); + virtual ~NetworkListModel(); + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + QVariant data(const QModelIndex &index, int role) const; + + const QStringList availableTechnologies() const; + const QStringList enabledTechnologies() const; + const QStringList connectedTechnologies() const; + + NetworkItemModel* defaultRoute() const { return m_networkManager->defaultRoute(); } + + void setDefaultRoute(NetworkItemModel* item); + + + +public slots: + NetworkItemModel* service(QString name); + + void connectService(const QString &name, const QString &security, + const QString &passphrase); + void connectService(const QString &name); + void setProperty(const int &index, QString property, const QVariant &value); + void requestScan(); + bool offlineMode() const; + void setOfflineMode(const bool &offlineMode); + void enableTechnology(const QString &technology); + void disableTechnology(const QString &technology); + QString defaultTechnology() const; + QString state() const; + + void networksAdded(int from, int to); + void networksMoved(int from, int to, int to2); + void networksRemoved(int from, int to); + void networkChanged(int index); + +signals: + void technologiesChanged(const QStringList &availableTechnologies, + const QStringList &enabledTechnologies, + const QStringList &connectedTechnologies); + void availableTechnologiesChanged(const QStringList); + void enabledTechnologiesChanged(const QStringList); + void connectedTechnologiesChanged(const QStringList); + + void offlineModeChanged(bool offlineMode); + void defaultTechnologyChanged(const QString &defaultTechnology); + void stateChanged(const QString &state); + void countChanged(int newCount); + void defaultRouteChanged(NetworkItemModel* item); + void connectedNetworkItemsChanged(); + +private: + NetworkManager* m_networkManager; + QList shadowList; + +private: + Q_DISABLE_COPY(NetworkListModel); +}; + +#endif //NETWORKLISTMODEL_H diff --git a/libconnman-qt/networkmanager.cpp b/libconnman-qt/networkmanager.cpp new file mode 100644 index 0000000..aeb5ca7 --- /dev/null +++ b/libconnman-qt/networkmanager.cpp @@ -0,0 +1,503 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 "networkmanager.h" +#include "debug.h" + +static NetworkManager* staticInstance = NULL; + +NetworkManager* NetworkManagerFactory::createInstance() +{ + if(!staticInstance) + staticInstance = new NetworkManager; + + return staticInstance; +} + + + +const QString NetworkManager::availTechs("AvailableTechnologies"); +const QString NetworkManager::enablTechs("EnabledTechnologies"); +const QString NetworkManager::connTechs("ConnectedTechnologies"); +const QString NetworkManager::OfflineMode("OfflineMode"); +const QString NetworkManager::DefaultTechnology("DefaultTechnology"); +const QString NetworkManager::State("State"); + +NetworkManager::NetworkManager(QObject* parent) + : QObject(parent), + m_manager(NULL), + m_getPropertiesWatcher(NULL), + m_connectServiceWatcher(NULL), + watcher(NULL), + m_defaultRoute(NULL) +{ + m_headerData.append("NetworkItemModel"); + m_headerData.append("Type"); + connectToConnman(); + + connect(this,SIGNAL(countChanged(int)),this,SLOT(countChangedSlot(int))); +} + +NetworkManager::~NetworkManager() +{ +} + +void NetworkManager::setProperty(const int &index, QString property, const QVariant &value) +{ + QString roleName = property; + QMetaObject object = NetworkItemModel::staticMetaObject; + + for(int i=0; i reply = m_manager->EnableTechnology(technology); + if(reply.error().isValid()) + { + qDebug()<DisableTechnology(technology); +} + +NetworkItemModel* NetworkManager::service(QString name) +{ + foreach(NetworkItemModel* item, m_networks) + { + if(item->name() == name) + { + return item; + } + } + + return NULL; +} + +void NetworkManager::connectService(const QString &name, const QString &security, + const QString &passphrase) +{ + if(!m_manager) + { + connectToConnman(); + return; + } + + qDebug("name: %s", STR(name)); + qDebug("security: %s", STR(security)); + qDebug("passphrase: %s", STR(passphrase)); + + QVariantMap dict; + dict.insert(QString("Type"), QVariant(QString("wifi"))); + dict.insert(QString("SSID"), QVariant(name)); + dict.insert(QString("Mode"), QVariant(QString("managed"))); + dict.insert(QString("Security"), QVariant(security)); + if (security != QString("none") && security != "ieee8021x") { + dict.insert(QString("Passphrase"), QVariant(passphrase)); + } + + QDBusPendingReply reply = m_manager->ConnectService(dict); + m_connectServiceWatcher = new QDBusPendingCallWatcher(reply, m_manager); + connect(m_connectServiceWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(connectServiceReply(QDBusPendingCallWatcher*))); +} + +void NetworkManager::connectService(const QString &name) +{ + foreach(NetworkItemModel* item, m_networks) + { + if(item->name() == name) + { + item->connectService(); + return; + } + } + qDebug()<<"NetworkListModel::connectService(): service with name: "< + (m_propertiesCache[NetworkManager::availTechs]); +} + +const QStringList NetworkManager::enabledTechnologies() const +{ + return qdbus_cast + (m_propertiesCache[NetworkManager::enablTechs]); +} + +const QStringList NetworkManager::connectedTechnologies() const +{ + return qdbus_cast + (m_propertiesCache[NetworkManager::connTechs]); +} + +void NetworkManager::setDefaultRoute(NetworkItemModel *item) +{ + if(m_networks.count() > 0 && (item->state() == NetworkItemModel::StateReady || item->state() == NetworkItemModel::StateOnline)) + { + NetworkItemModel * topservice = m_networks.at(0); + + item->moveBefore(topservice); + } +} + +void NetworkManager::connectToConnman(QString) +{ + if(!watcher) { + watcher = new QDBusServiceWatcher("net.connman",QDBusConnection::systemBus(), + QDBusServiceWatcher::WatchForRegistration | + QDBusServiceWatcher::WatchForUnregistration,this); + + connect(watcher,SIGNAL(serviceRegistered(QString)),this,SLOT(connectToConnman(QString))); + connect(watcher,SIGNAL(serviceUnregistered(QString)),this,SLOT(disconnectFromConnman(QString))); + } + + disconnectFromConnman(); + m_manager = new Manager("net.connman", "/", + QDBusConnection::systemBus(), + this); + if (!m_manager->isValid()) { + //This shouldn't happen + qDebug("manager is invalid. connman may not be running or is invalid"); + //QTimer::singleShot(10000,this,SLOT(connectToConnman())); + delete m_manager; + m_manager = NULL; + } else { + QDBusPendingReply reply = m_manager->GetProperties(); + m_getPropertiesWatcher = new QDBusPendingCallWatcher(reply, m_manager); + connect(m_getPropertiesWatcher, + SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(getPropertiesReply(QDBusPendingCallWatcher*))); + + } +} + +void NetworkManager::disconnectFromConnman(QString) +{ + if (m_manager) { + delete m_manager; //we think that m_getPropertiesWatcher will be + //deleted due to m_manager getting deleted + + m_manager = NULL; + int count = m_networks.count(); + m_networks.clear(); + networksRemoved(0, count); + } +} + +void NetworkManager::getPropertiesReply(QDBusPendingCallWatcher *call) +{ + Q_ASSERT(call); + QDBusPendingReply reply = *call; + if (reply.isError()) + { + qDebug()<<"Error getPropertiesReply: "< 0) + networksRemoved(0, count); + + m_propertiesCache = reply.value(); + QList services = qdbus_cast >(m_propertiesCache["Services"]); + //beginInsertRows(QModelIndex(), 0, services.count()-1); + + foreach (QDBusObjectPath p, services) + { + // qDebug()<< QString("service path:\t%1").arg(p.path()); + NetworkItemModel *pNIM = new NetworkItemModel(p.path(), this); + connect(pNIM,SIGNAL(propertyChanged(QString, QVariant)),this,SLOT(itemPropertyChanged(QString, QVariant))); + connect(pNIM,SIGNAL(stateChanged(NetworkItemModel::StateType)), + this,SLOT(itemStateChanged(NetworkItemModel::StateType))); + itemStateChanged(pNIM->state()); + m_networks.append(pNIM); + } + //endInsertRows(); + networksAdded(0,services.count() - 1); + connect(m_manager, + SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), + this, + SLOT(propertyChanged(const QString&, const QDBusVariant&))); + emitTechnologiesChanged(); + emit defaultTechnologyChanged(m_propertiesCache[DefaultTechnology].toString()); + emit stateChanged(m_propertiesCache[State].toString()); + } +} + +void NetworkManager::connectServiceReply(QDBusPendingCallWatcher *call) +{ + Q_ASSERT(call); + QDBusPendingReply reply = *call; + if (reply.isError()) { + QDBusError error = reply.error(); + qDebug("ERROR!"); + qDebug("message: %s", STR(error.message())); + qDebug("name: %s", STR(error.name())); + qDebug("error type: %s", STR(QDBusError::errorString(error.type()))); + } else { + QDBusObjectPath p = reply.value(); + // qDebug("object path: %s", STR(p.path())); + } +} + +void NetworkManager::propertyChanged(const QString &name, + const QDBusVariant &value) +{ + qDebug("NetworkListModel: Property \"%s\" changed", STR(name)); + m_propertiesCache[name] = value.variant(); + + if (name == NetworkManager::availTechs || + name == NetworkManager::enablTechs || + name == NetworkManager::connTechs) + { + emitTechnologiesChanged(); + } + else if (name == DefaultTechnology) { + emit defaultTechnologyChanged(m_propertiesCache[DefaultTechnology].toString()); + } + else if (name == State) { + emit stateChanged(m_propertiesCache[State].toString()); + } + else if (name == "Services") + { + QList new_services = + qdbus_cast >(value.variant()); + int num_new = new_services.count(); + qDebug()<<"number of services: "< num_new) + { + //DCP_CRITICAL(QString("num old: %1 num new: %2").arg(num_old).arg(num_new).toAscii()); + //DCP_CRITICAL(QString("we have %1 networks to remove").arg(num_old - num_new).toAscii()); + //beginRemoveRows(QModelIndex(), num_new, num_old - 1); + + for (int i = num_new; i < num_old; i++) + { + //DCP_CRITICAL(QString("removing network %1").arg(m_networks[i]->servicePath()).toAscii()); + // m_networks[i]->decreaseReferenceCount(); + m_networks[i]->deleteLater(); + } + m_networks.remove(num_new, num_old - num_new); + + networksRemoved(num_new, num_old - 1); + + countChanged(m_networks.count()); + } + } + else if (name == OfflineMode) + { + m_propertiesCache[OfflineMode] = value.variant(); + emit offlineModeChanged(m_propertiesCache[OfflineMode].toBool()); + } +} + + void NetworkManager::networkItemModified(const QList &members) + { + //this is a gross hack to keep from doing things again and again we + //only really care for the sake of the model when the type changes + //the type changes as a result from the initial getProperties call + //on the service object after we get the service object paths from + //the Manager in getProperties + if (members.contains(NetworkItemModel::Type)) + { + int row = m_networks.indexOf(qobject_cast(sender())); + if(row == -1) + { + qDebug()<<"caught property changed signal for network item not in our list"; + return; + } + networkChanged(row); + } + } + + void NetworkManager::itemPropertyChanged(QString name, QVariant value) + { + int row = m_networks.indexOf(qobject_cast(sender())); + if(row == -1) + { + //Q_ASSERT(0); + qDebug()<<"caught property changed signal for network item not in our list"; + return; + } + // qDebug()<<"Properties changed for "<< m_networks[row]->name(); + networkChanged(row); + } + + void NetworkManager::countChangedSlot(int newCount) + { + if(newCount > 0) + { + NetworkItemModel* tempItem = m_networks.at(0); + if(tempItem != m_defaultRoute && + (tempItem->state() == NetworkItemModel::StateReady || + tempItem->state() == NetworkItemModel::StateOnline)) + { + m_defaultRoute = m_networks.at(0); + defaultRouteChanged(m_defaultRoute); + } + } + else + { + m_defaultRoute = NULL; + defaultRouteChanged(m_defaultRoute); + } + } + + void NetworkManager::itemStateChanged(NetworkItemModel::StateType itemState) + { + connectedNetworkItemsChanged(); + + NetworkItemModel* item = qobject_cast(sender()); + if(m_networks.count() && item == m_networks.at(0) ) + { + if(itemState == NetworkItemModel::StateReady || + itemState == NetworkItemModel::StateOnline) + { + m_defaultRoute = m_networks.at(0); + } + else + { + m_defaultRoute = NULL; + } + defaultRouteChanged(m_defaultRoute); + } + } + +int NetworkManager::findNetworkItemModel(const QDBusObjectPath &path) const +{ + for (int i= 0; i < m_networks.count(); i++) + { + if (m_networks[i]->servicePath() == path.path()) return i; + } + return -1; +} + + void NetworkManager::emitTechnologiesChanged() + { + const QStringList availableTechnologies = qdbus_cast + (m_propertiesCache[NetworkManager::availTechs]); + const QStringList enabledTechnologies = qdbus_cast + (m_propertiesCache[NetworkManager::enablTechs]); + const QStringList connectedTechnologies = qdbus_cast + (m_propertiesCache[NetworkManager::connTechs]); + // qDebug() << availTechs << ": " << m_propertiesCache[NetworkManager::availTechs]; + // qDebug() << enablTechs << ": " << m_propertiesCache[NetworkManager::enablTechs]; + // qDebug() << connTechs << ": " << m_propertiesCache[NetworkManager::connTechs]; + emit technologiesChanged(availableTechnologies, + enabledTechnologies, + connectedTechnologies); + + availableTechnologiesChanged(availableTechnologies); + enabledTechnologiesChanged(enabledTechnologies); + connectedTechnologiesChanged(connectedTechnologies); + countChanged(m_networks.count()); + } + + +void NetworkManager::requestScan() +{ + if (!m_manager) return; + const QString wifi("wifi"); + m_manager->RequestScan(wifi); + //FIXME: error returns, etc +} + +void NetworkManager::setOfflineMode(const bool &offlineMode) +{ + if(!m_manager) return; + + QDBusPendingReply reply = + m_manager->SetProperty(OfflineMode, QDBusVariant(QVariant(offlineMode))); + + +#if 0 //It is fundamentally broken to wait here and it doesn't even do + //anything but crash the app + reply.waitForFinished(); + if (reply.isError()) { + qDebug("got error from setProperty"); + throw -1; + } +#endif +} + +bool NetworkManager::offlineMode() const +{ + return m_propertiesCache[OfflineMode].toBool(); +} + +QString NetworkManager::defaultTechnology() const +{ + return m_propertiesCache[DefaultTechnology].toString(); +} + +QString NetworkManager::state() const +{ + return m_propertiesCache[State].toString(); +} diff --git a/libconnman-qt/networkmanager.h b/libconnman-qt/networkmanager.h new file mode 100644 index 0000000..58dd492 --- /dev/null +++ b/libconnman-qt/networkmanager.h @@ -0,0 +1,127 @@ +/* -*- Mode: C++ -*- + * meegotouchcp-connman - connectivity plugin for duicontrolpanel + * Copyright © 2010, Intel Corporation. + * + * 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 + * + */ +#ifndef NETWORKMANAGER_H +#define NETWORKMANAGER_H + +#include "networkitem.h" +#include "manager.h" + +#include +#include + +class QDBusServiceWatcher; +class NetworkManager; + +class NetworkManagerFactory +{ +public: + NetworkManagerFactory() {} + + static NetworkManager* createInstance(); +}; + + +class NetworkManager : public QObject +{ + Q_OBJECT; + + Q_PROPERTY(bool offlineMode READ offlineMode WRITE setOfflineMode NOTIFY offlineModeChanged); + Q_PROPERTY(QString defaultTechnology READ defaultTechnology NOTIFY defaultTechnologyChanged); + Q_PROPERTY(QString state READ state NOTIFY stateChanged); + Q_PROPERTY(QStringList availableTechnologies READ availableTechnologies NOTIFY availableTechnologiesChanged); + Q_PROPERTY(QStringList enabledTechnologies READ enabledTechnologies NOTIFY enabledTechnologiesChanged); + Q_PROPERTY(QStringList connectedTechnologies READ connectedTechnologies NOTIFY connectedTechnologiesChanged); + Q_PROPERTY(NetworkItemModel* defaultRoute READ defaultRoute WRITE setDefaultRoute NOTIFY defaultRouteChanged); + Q_PROPERTY(QList networks READ networks NOTIFY countChanged) + +public: + NetworkManager(QObject* parent=0); + virtual ~NetworkManager(); + + const QStringList availableTechnologies() const; + const QStringList enabledTechnologies() const; + const QStringList connectedTechnologies() const; + + NetworkItemModel* defaultRoute() const { return m_defaultRoute; } + + void setDefaultRoute(NetworkItemModel* item); + + QList networks() { return m_networks.toList(); } + +public slots: + NetworkItemModel* service(QString name); + + void connectService(const QString &name, const QString &security, + const QString &passphrase); + void connectService(const QString &name); + void setProperty(const int &index, QString property, const QVariant &value); + void requestScan(); + bool offlineMode() const; + void setOfflineMode(const bool &offlineMode); + void enableTechnology(const QString &technology); + void disableTechnology(const QString &technology); + QString defaultTechnology() const; + QString state() const; + +signals: + void technologiesChanged(const QStringList &availableTechnologies, + const QStringList &enabledTechnologies, + const QStringList &connectedTechnologies); + void availableTechnologiesChanged(const QStringList); + void enabledTechnologiesChanged(const QStringList); + void connectedTechnologiesChanged(const QStringList); + + void offlineModeChanged(bool offlineMode); + void defaultTechnologyChanged(const QString &defaultTechnology); + void stateChanged(const QString &state); + void countChanged(int newCount); + void defaultRouteChanged(NetworkItemModel* item); + void connectedNetworkItemsChanged(); + + void networksAdded(int from, int to); + void networksMoved(int from, int to, int to2); + void networksRemoved(int from, int to); + void networkChanged(int index); + +private: + int findNetworkItemModel(const QDBusObjectPath &path) const; + void emitTechnologiesChanged(); + + Manager *m_manager; + QDBusPendingCallWatcher *m_getPropertiesWatcher; + QDBusPendingCallWatcher *m_connectServiceWatcher; + QVariantMap m_propertiesCache; + QVector m_networks; + QStringList m_headerData; + static const QString availTechs; + static const QString enablTechs; + static const QString connTechs; + static const QString OfflineMode; + static const QString DefaultTechnology; + static const QString State; + NetworkItemModel* m_defaultRoute; + QDBusServiceWatcher *watcher; + +private slots: + void connectToConnman(QString = ""); + void disconnectFromConnman(QString = ""); + void getPropertiesReply(QDBusPendingCallWatcher *call); + void connectServiceReply(QDBusPendingCallWatcher *call); + void propertyChanged(const QString &name, + const QDBusVariant &value); + void networkItemModified(const QList &members); + void itemPropertyChanged(QString name, QVariant value); + void countChangedSlot(int newCount); + void itemStateChanged(NetworkItemModel::StateType); +private: + Q_DISABLE_COPY(NetworkManager); +}; + +#endif //NETWORKLISTMODEL_H diff --git a/makedist b/makedist new file mode 100755 index 0000000..e970bae --- /dev/null +++ b/makedist @@ -0,0 +1,53 @@ +#!/bin/bash + + + + +# Determine project name based on current directory +#PROJECT=$(basename $PWD) +PROJECT=connman-qt + +# NOTE: Don't like this? Then uncomment one of the following as appropriate +# +# Just set it explictly to whatever you like: +# PROJECT=libseaside +# +# Parse it from any Qt *.pro or *.pri files in CWD: +# PROJECT=$(grep -E "TARGET ?= ?" *.pr[io]|cut -d' ' -f3) + +while getopts ht: o +do case $o in + h) head=1;; + t) TAG="$OPTARG";; + ?) printf >&2 "Usage: $0 [-h] [-t TAG]\n" + exit 2;; + esac +done + +# Grab most recent tag from git unless TAG is set +if [ -z "$TAG" ] ; then + TAG=$(git describe --tags --abbrev=0) +fi + +# Parse out just the version number +#PARTS=(${TAG//-/ }) +#VERSION=${PARTS[1]} +VERSION=${TAG} + +# Set name of toplevel directory for the archive +PREFIX="${PROJECT}-${VERSION}/" + +# Set name of resulting release archive file +ARCHIVE=${PROJECT}-${VERSION}.tar.bz2 + +[ -e ${ARCHIVE} ] && rm -rf ${ARCHIVE} && echo "Removed: ${ARCHIVE}" + +if [ ! -z "$head" ] ; then + TAG="HEAD" +fi + +git archive --format=tar --prefix=${PREFIX} $TAG | bzip2 -c -- > ${ARCHIVE} && { + echo "Created: ${ARCHIVE}" +} || { + echo "Creation of release archive ${ARCHIVE} failed. Reason unknown." +} diff --git a/packaging/connman-qt.spec b/packaging/connman-qt.spec new file mode 100644 index 0000000..6634540 --- /dev/null +++ b/packaging/connman-qt.spec @@ -0,0 +1,135 @@ +%define buildwayland 1 +%if %{buildwayland} +%define backend -wayland +%else +%define backend -xlib +%endif + +Name: connman-qt%{backend} +Summary: qt bindings for connman +Version: 0.1.4 +Release: 1 +Group: System/GUI/Other +License: Apache License +URL: http://www.meego.com +Source0: connman-qt-%{version}.tar.bz2 +Requires: connman-qt%{backend}-declarative +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: pkgconfig(QtCore%{backend}) +BuildRequires: pkgconfig(QtDBus%{backend}) +BuildRequires: pkgconfig(QtOpenGL%{backend}) +BuildRequires: pkgconfig(QtGui%{backend}) +BuildRequires: pkgconfig(dbus-1) +BuildRequires: doxygen + +%description +This is a library for working with connman using Qt + + + +%package tests +Summary: tests for connman-qt +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +Requires: connman-qt%{backend}-declarative + +%description tests +This package contains the test applications for testing libconnman-qt + + +%package declarative +Summary: Declarative plugin for Qt Quick for connman-qt +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +Requires: connman-qt%{backend} + +%description declarative +This package contains the files necessary to develop +applications using libconnman-qt + + +%package devel +Summary: Development files for connman-qt +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +This package contains the files necessary to develop +applications using libconnman-qt + + + +%prep +%setup -q -n connman-qt-%{version} + +# >> setup +# << setup + +%build +# >> build pre +export PATH=$PATH:/usr/lib/qt4/bin +qmake install_prefix=/usr +# << build pre + +%qmake + +make %{?jobs:-j%jobs} + +# >> build post +# << build post +%install +rm -rf %{buildroot} +# >> install pre +export INSTALL_ROOT=%{buildroot} +# << install pre +%qmake_install + +# >> install post +# << install post + + + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + + + + + + + + + + +%files +%defattr(-,root,root,-) +%{_libdir}/libconnman-qt4.so.* +# >> files +# << files + + +%files tests +%defattr(-,root,root,-) +%{_usr}/lib/libconnman-qt4/test +# >> files tests +# << files tests + +%files declarative +%defattr(-,root,root,-) +%{_usr}/lib/qt4/imports/Connman/Qt +# >> files declarative +# << files declarative + +%files devel +%defattr(-,root,root,-) +%{_usr}/include/connman-qt +%{_usr}/lib/pkgconfig/connman-qt4.pc +%{_usr}/lib/connman-qt4.pc +%{_usr}/lib/libconnman-qt4.prl +%{_usr}/lib/libconnman-qt4.so +# >> files devel +# << files devel + diff --git a/plugin/components.cpp b/plugin/components.cpp new file mode 100644 index 0000000..4964d94 --- /dev/null +++ b/plugin/components.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2011 Intel Corporation. + * + * 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 "components.h" + +#include +#include +#include + + +void Components::registerTypes(const char *uri) +{ + qmlRegisterType(uri,0,1,"NetworkListModel"); + qmlRegisterType(uri,0,1,"NetworkItemModel"); + qmlRegisterType(uri,0,1,"ClockModel"); +} + +void Components::initializeEngine(QDeclarativeEngine *engine, const char *uri) +{ + Q_UNUSED(uri); + Q_UNUSED(engine); +} + +Q_EXPORT_PLUGIN(Components); diff --git a/plugin/components.h b/plugin/components.h new file mode 100644 index 0000000..5e3813b --- /dev/null +++ b/plugin/components.h @@ -0,0 +1,24 @@ +/* + * Copyright 2011 Intel Corporation. + * + * 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 + */ + +#ifndef COMPONENTS_H +#define COMPONENTS_H + +#include +#include + +class Components : public QDeclarativeExtensionPlugin +{ + Q_OBJECT + +public: + void registerTypes(const char *uri); + void initializeEngine(QDeclarativeEngine *engine, const char *uri); +}; + +#endif // COMPONENTS_H diff --git a/plugin/plugin.pro b/plugin/plugin.pro new file mode 100644 index 0000000..93d73b2 --- /dev/null +++ b/plugin/plugin.pro @@ -0,0 +1,15 @@ +TARGET=ConnmanQtDeclarative +TEMPLATE = lib +QT += declarative dbus +CONFIG += plugin +SOURCES = components.cpp +HEADERS = components.h + +INCLUDEPATH += ../libconnman-qt +LIBS += -L../libconnman-qt -lconnman-qt4 + +target.path = $$[QT_INSTALL_IMPORTS]/Connman/Qt +qmldir.files += qmldir +qmldir.path = $$[QT_INSTALL_IMPORTS]/Connman/Qt + +INSTALLS += target qmldir diff --git a/plugin/qmldir b/plugin/qmldir new file mode 100644 index 0000000..7eb6af0 --- /dev/null +++ b/plugin/qmldir @@ -0,0 +1 @@ +plugin ConnmanQtDeclarative diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..121a14d --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QDeclarativeView *view = new QDeclarativeView; + + view->setSource(QUrl::fromLocalFile("main.qml")); + view->setGeometry(0,0,800,480); + view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + view->show(); + + return a.exec(); +} diff --git a/test/main.qml b/test/main.qml new file mode 100644 index 0000000..0d71301 --- /dev/null +++ b/test/main.qml @@ -0,0 +1,128 @@ +import Qt 4.7 +import MeeGo.Connman 0.1 + +Item { + //anchors.fill: parent + width: 800 + height: 480 + + NetworkListModel { + id: networkListModel + } + ClockModel { + id: clockModel + } + + Column { + + Text { text: "Timezone: " + clockModel.timezone } + Row { + TextInput { + id: timezoneEntry + width: 200 + height: 40 + text: clockModel.timezone + } + Rectangle { + id: setButton + width: 40 + height: 40 + color: "grey" + Text { anchors.centerIn: parent; text: "Set" } + MouseArea { + anchors.fill: parent + onClicked: { + clockModel.timezone = timezoneEntry.text + } + } + } + } + Rectangle { + id: updatesButton + property string mode: clockModel.timezoneUpdates + width: 180 + height: 50 + color: mode == "auto" ? "blue" : "red" + Text { + anchors.centerIn: parent + text: "TimezoneUpdates: " + updatesButton.mode + } + MouseArea { + anchors.fill: parent + onClicked: { + if (updatesButton.mode == "auto") + clockModel.timezoneUpdates = "manual"; + else + clockModel.timezoneUpdates = "auto"; + } + } + } + Rectangle { + id: button + property bool airplane: networkListModel.offlineMode + width: 100 + height: 50 + color: button.airplane ? "blue":"red" + + Text { + anchors.centerIn: parent + text: "offline: " + button.airplane + } + + MouseArea { + anchors.fill: parent + onClicked: { + networkListModel.offlineMode = !button.airplane + } + } + } + + Row { + height: 50 + spacing: 10 + Text { text: "available technologies" } + Repeater { + model: networkListModel.availableTechnologies + delegate: Text { + text: modelData + height: 50 + } + } + } + + Row { + height: 50 + spacing: 10 + Text { text: "enabled technologies" } + Repeater { + model: networkListModel.enabledTechnologies + delegate: Text { + text: modelData + height: 50 + } + } + } + + Row { + height: 50 + spacing: 10 + Text { text: "connected technologies" } + Repeater { + model: networkListModel.connectedTechnologies + delegate: Text { + text: modelData + height: 50 + } + } + } + + ListView { + height: 600 + width: parent.width + model: networkListModel + delegate: Text { + text: name + " " + type + } + } + } +} diff --git a/test/test.pro b/test/test.pro new file mode 100644 index 0000000..c576b22 --- /dev/null +++ b/test/test.pro @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-10-12T13:49:46 +# +#------------------------------------------------- + +QT += core declarative gui + +TARGET = testconnman-qt +CONFIG += console +CONFIG -= app_bundle + +OTHER_FILES += *.qml + +TEMPLATE = app + + +SOURCES += main.cpp + +HEADERS += + +target.path = $$INSTALL_ROOT/usr/lib/libconnman-qt4/test + +qml.files = $$OTHER_FILES +qml.path = $$target.path + + +INSTALLS += target qml -- 2.7.4