--- /dev/null
+TEMPLATE = subdirs
+SUBDIRS += libconnman-qt test plugin
+CONFIG += ordered
+
--- /dev/null
+/*
+ * 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<QVariantMap> 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<QVariantMap> 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);
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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()
+{
+}
+
--- /dev/null
+/*
+ * 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 <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * 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<QVariantMap> GetProperties()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
+ }
+
+ inline QDBusPendingReply<> SetProperty(const QString &in0, const QDBusVariant &in1)
+ {
+ QList<QVariant> 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
--- /dev/null
+/* -*- 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 <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QMetaType>
+#include <QtDBus/QtDBus>
+
+typedef QMap<QString, QString> StringMap;
+Q_DECLARE_METATYPE ( StringMap );
+
+inline void registerCommonDataTypes() {
+ qDBusRegisterMetaType<StringMap >();
+}
+
+#endif //COMMONDBUSTYPES_H
--- /dev/null
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="net.connman.Clock">
+ <method name="GetProperties">
+ <arg type="a{sv}" direction="out"/>
+ <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
+ </method>
+ <method name="SetProperty">
+ <arg type="s" direction="in"/>
+ <arg type="v" direction="in"/>
+ </method>
+ <signal name="PropertyChanged">
+ <arg type="s"/>
+ <arg type="v"/>
+ </signal>
+ </interface>
+</node>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<node name="/Manager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
+ <interface name="net.connman.Manager">
+
+ <method name="GetProperties" tp:name-for-bindings="Get_Properties">
+ <arg name="properties" type="a{sv}" direction="out"/>
+ <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
+ </method>
+
+ <method name="SetProperty" tp:name-for-bindings="Set_Property">
+ <arg name="name" type="s"/>
+ <arg name="value" type="v"/>
+ </method>
+
+ <method name="RequestScan" tp:name-for-bindings="Request_Scan">
+ <arg name="type" type="s"/>
+ </method>
+
+ <method name="EnableTechnology" tp:name-for-bindings="Enable_Technology">
+ <arg name="type" type="s"/>
+ </method>
+
+ <method name="DisableTechnology" tp:name-for-bindings="Disable_Technology">
+ <arg name="type" type="s"/>
+ </method>
+
+ <method name="ConnectService" tp:name-for-bindings="Connect_Service">
+ <arg name="network" type="a{sv}"/>
+ <arg name="service" type="o" direction="out" />
+ <annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="QVariantMap"/>
+ </method>
+
+ <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed">
+ <arg name="name" type="s"/>
+ <arg name="value" type="v"/>
+ </signal>
+
+ </interface>
+</node>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
+ <interface name="net.connman.Service">
+
+ <method name="GetProperties" tp:name-for-bindings="Get_Properties">
+ <arg name="properties" type="a{sv}" direction="out"/>
+ <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
+ </method>
+
+ <method name="SetProperty" tp:name-for-bindings="Set_Property">
+ <arg name="name" type="s"/>
+ <arg name="value" type="v"/>
+ </method>
+
+ <method name="ClearProperty" tp:name-for-bindings="Clear_Property">
+ <arg name="name" type="s" />
+ </method>
+
+ <method name="Connect" tp:name-for-bindings="Connect" />
+
+ <method name="Disconnect" tp:name-for-bindings="Disconnect" />
+
+ <method name="Remove" tp:name-for-bindings="Remove" />
+
+ <method name="MoveBefore" tp:name-for-bindings="Move_Before">
+ <arg name="service" type="o"/>
+ </method>
+
+ <method name="MoveAfter" tp:name-for-bindings="Move_After">
+ <arg name="service" type="o"/>
+ </method>
+
+ <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed">
+ <arg name="name" type="s"/>
+ <arg name="value" type="v"/>
+ </signal>
+
+ </interface>
+</node>
--- /dev/null
+/* -*- 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 <QString>
+
+#define STR(qstring) qstring.toLatin1().constData()
+
+ #include <QtDebug>
+ #define MDEBUG(...) qDebug(__VA_ARGS__)
+ #define MWARNING(...) qWarning(__VA_ARGS__)
+ #define MCRITICAL(...) qCritical(__VA__ARGS__)
+
+#endif //DEBUG_H
--- /dev/null
+#-*-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
--- /dev/null
+/* -*- 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 <QVariant>
+
+//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<QVariantMap> 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<void> reply =
+ m_service->SetProperty("Passphrase", QDBusVariant(QVariant(passphrase)));
+ reply.waitForFinished(); //FIXME: BAD
+ if (reply.isError()) {
+ qDebug()<<"got error from setProperty: "<<reply.error().message();
+ //throw -1; //FIXME: don't throw
+ }
+
+}
+
+void NetworkItemModel::setIpv4(const IPv4Type &ipv4)
+{
+ Q_ASSERT(m_service);
+
+
+ StringMap dict;
+ Q_ASSERT(!ipv4.Method.isEmpty());
+ dict.insert("Method", ipv4.Method);
+ if (ipv4.Method != "dhcp") {
+ //FIXME: what do to if address and such are empty!?!
+ dict.insert("Address", ipv4.Address);
+ dict.insert("Netmask", ipv4.Netmask);
+ dict.insert("Gateway", ipv4.Gateway);
+ }
+ QVariant variant = qVariantFromValue(dict);
+ QDBusPendingReply<void> 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<void> 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<QVariantMap> reply = *call;
+ if (reply.isError()) {
+ qDebug("getPropertiesReply is error!");
+ QDBusError error = reply.error();
+ qDebug("service: %s", STR(servicePath()));
+ qDebug()<<QString("type: %1 name: %2 message: %3").
+ arg(QDBusError::errorString(error.type()))
+ .arg(error.name())
+ .arg(error.message());
+ return;
+ }
+ qDebug()<<"getPropertiesReply";
+ QVariantMap properties = reply.value();
+ //although it seems dangerous as some of these properties are not
+ //present, grabbing them is not, because QMap will insert the
+ //default value into the map if it isn't present. That's "" for
+ //strings and 0 for ints/bools
+
+ m_name = qdbus_cast<QString>(properties[Name]);
+ nameChanged(m_name);
+ m_type = qdbus_cast<QString>(properties[Type]);
+ typeChanged(m_type);
+ m_mode= qdbus_cast<QString>(properties[Mode]);
+
+ QStringList sec = qdbus_cast<QStringList>(properties[Security]);
+
+ if(sec.count() > 0)
+ {
+ m_security = sec.at(0);
+ securityChanged(m_security);
+ }
+
+ m_passphraseRequired = qdbus_cast<bool>(properties[PassphraseRequired]);
+ m_passphrase = qdbus_cast<QString>(properties[Passphrase]);
+ passphraseChanged(m_passphrase);
+ m_strength = qdbus_cast<int>(properties[Strength]);
+ strengthChanged(m_strength);
+ m_state = state(qdbus_cast<QString>(properties[State]));
+ _setIpv4(qdbus_cast<QVariantMap>(properties[IPv4Normal]));
+ m_nameservers = qdbus_cast<QStringList>(properties[Nameservers]);
+ m_deviceAddress = qdbus_cast<QVariantMap>(properties["Ethernet"])["Address"].toString();
+ m_apn = qdbus_cast<QString>(properties[APN]);
+ m_error = qdbus_cast<QString>(properties["Error"]);
+ errorChanged();
+ m_setupRequired = qdbus_cast<bool>(properties[SetupRequired]);
+ emit propertyChanged("","");
+}
+
+void NetworkItemModel::propertyChanged(const QString &name,
+ const QDBusVariant &value)
+{
+ qDebug()<<"NetworkItemModel: property "<<STR(name)<<" changed: "<<value.variant();
+ if (name == State) {
+ m_state = state(value.variant().toString());
+ stateChanged(m_state);
+ } else if (name == Name) {
+ m_name = (value.variant().toString());
+ nameChanged(m_name);
+ } else if (name == Type) {
+ m_type = (value.variant().toString());
+ typeChanged(m_type);
+ } else if (name == Mode) {
+ m_mode = (value.variant().toString());
+ } else if (name == Security) {
+ QStringList sec = qdbus_cast<QStringList>(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<QVariantMap>(value.variant()));
+ } else if (name == Nameservers) {
+ m_nameservers = (value.variant().toStringList());
+ } else if (name == "Ethernet") {
+ m_deviceAddress = (qdbus_cast<QVariantMap>(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<void> reply = *call;
+ if (reply.isError()) {
+ qDebug()<<"not continuing because of error in setProperty!"<<reply.error().message();
+ m_error = reply.error().message();
+ errorChanged();
+ } else {
+ QDBusPendingReply<void> 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<void> reply = *call;
+ if (reply.isError()) {
+ qDebug("not continuing because of error in disconnect!");
+ } else {
+ QDBusPendingReply<void> 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<void> reply = *call;
+ if (reply.isError()) {
+ qDebug("error calling connect!");
+ } else {
+ qDebug("connect finished without error");
+ }
+}
+
--- /dev/null
+/* -*- 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 <QString>
+#include <QObject>
+
+//#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
+
--- /dev/null
+/* -*- 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<int, QByteArray> roles;
+
+ QMetaObject properties = NetworkItemModel::staticMetaObject;
+ int i=0;
+ for(; i<properties.propertyCount();i++)
+ {
+ roles[i]=properties.property(i).name();
+ }
+
+ roles[++i] = "networkitemmodel";
+ roles[++i] = "defaultRoute";
+
+ setRoleNames(roles);
+}
+
+NetworkListModel::~NetworkListModel()
+{
+}
+
+int NetworkListModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return m_networkManager->networks().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*>((QObject*)shadowList[index.row()]);
+ }
+ else if(roleName == "defaultRoute")
+ {
+ return m_networkManager->defaultRoute() == shadowList[index.row()];
+ }
+
+ for(int i=0; i<object.propertyCount(); i++)
+ {
+ if(object.property(i).name() == roleName)
+ {
+ return object.property(i).read(shadowList[index.row()]);
+ }
+ }
+
+ return QVariant();
+}
+
+void NetworkListModel::setProperty(const int &index, QString property, const QVariant &value)
+{
+ m_networkManager->setProperty(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));
+}
--- /dev/null
+/* -*- 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 <QAbstractTableModel>
+#include <QtDBus>
+
+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<NetworkItemModel*> shadowList;
+
+private:
+ Q_DISABLE_COPY(NetworkListModel);
+};
+
+#endif //NETWORKLISTMODEL_H
--- /dev/null
+/* -*- 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<object.propertyCount(); i++)
+ {
+ if(object.property(i).name() == roleName)
+ {
+ //emit dataChanged(index.row(),index.row());
+ qDebug()<<"changing value of: "<<roleName<< " to "<<value;
+ object.property(i).write(m_networks[index],value);
+ break;
+ }
+ }
+
+}
+
+void NetworkManager::enableTechnology(const QString &technology)
+{
+ // qDebug("enabling technology \"%s\"", STR(technology));
+ QDBusReply<void> reply = m_manager->EnableTechnology(technology);
+ if(reply.error().isValid())
+ {
+ qDebug()<<reply.error().message();
+ enabledTechnologiesChanged(enabledTechnologies());
+ }
+}
+
+void NetworkManager::disableTechnology(const QString &technology)
+{
+ // qDebug("disenabling technology \"%s\"", STR(technology));
+ m_manager->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<QDBusObjectPath> 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: "<<name<<" not found";
+}
+
+const QStringList NetworkManager::availableTechnologies() const
+{
+ return qdbus_cast<QStringList>
+ (m_propertiesCache[NetworkManager::availTechs]);
+}
+
+const QStringList NetworkManager::enabledTechnologies() const
+{
+ return qdbus_cast<QStringList>
+ (m_propertiesCache[NetworkManager::enablTechs]);
+}
+
+const QStringList NetworkManager::connectedTechnologies() const
+{
+ return qdbus_cast<QStringList>
+ (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<QVariantMap> 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<QVariantMap> reply = *call;
+ if (reply.isError())
+ {
+ qDebug()<<"Error getPropertiesReply: "<<reply.error().message();
+ disconnectFromConnman();
+ //TODO set up timer to reconnect in a bit
+ QTimer::singleShot(10000,this,SLOT(connectToConnman()));
+ }
+ else
+ {
+ ///reset everything just in case:
+ int count = m_networks.count();
+ m_networks.clear();
+
+ if(count > 0)
+ networksRemoved(0, count);
+
+ m_propertiesCache = reply.value();
+ QList<QDBusObjectPath> services = qdbus_cast<QList<QDBusObjectPath> >(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<QDBusObjectPath> 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<QDBusObjectPath> new_services =
+ qdbus_cast<QList<QDBusObjectPath> >(value.variant());
+ int num_new = new_services.count();
+ qDebug()<<"number of services: "<<num_new;
+ for (int i = 0; i < num_new; i++)
+ {
+ QDBusObjectPath path(new_services[i]);
+ int j = findNetworkItemModel(path);
+ if (-1 == j)
+ {
+ //beginInsertRows(QModelIndex(), i, i);
+ NetworkItemModel *pNIM = new NetworkItemModel(path.path());
+ connect(pNIM,SIGNAL(propertyChanged(QString, QVariant)),this,SLOT(itemPropertyChanged(QString, QVariant)));
+ connect(pNIM,SIGNAL(stateChanged(NetworkItemModel::StateType)),
+ this,SLOT(itemStateChanged(NetworkItemModel::StateType)));
+ m_networks.insert(i, pNIM);
+ //endInsertRows();
+ networksAdded(i, i);
+ countChanged(m_networks.count());
+ }
+ else
+ {
+ if (i != j)
+ { //only move if from and to aren't the same
+ //beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
+ NetworkItemModel *pNIM = m_networks[j];
+ Q_ASSERT(pNIM);
+ m_networks.remove(j);
+ m_networks.insert(i, pNIM);
+ //endMoveRows();
+ networksMoved(j,j,i);
+
+ ///We may not need this here:
+ countChanged(m_networks.count());
+ }
+ }
+
+ }
+ int num_old = m_networks.count();
+ if (num_old > 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<const char *> &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<NetworkItemModel*>(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<NetworkItemModel*>(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<NetworkItemModel*>(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<QStringList>
+ (m_propertiesCache[NetworkManager::availTechs]);
+ const QStringList enabledTechnologies = qdbus_cast<QStringList>
+ (m_propertiesCache[NetworkManager::enablTechs]);
+ const QStringList connectedTechnologies = qdbus_cast<QStringList>
+ (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<void> 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();
+}
--- /dev/null
+/* -*- 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 <QAbstractTableModel>
+#include <QtDBus>
+
+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<NetworkItemModel*> 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<NetworkItemModel*> 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<NetworkItemModel*> 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<const char *> &members);
+ void itemPropertyChanged(QString name, QVariant value);
+ void countChangedSlot(int newCount);
+ void itemStateChanged(NetworkItemModel::StateType);
+private:
+ Q_DISABLE_COPY(NetworkManager);
+};
+
+#endif //NETWORKLISTMODEL_H
--- /dev/null
+#!/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."
+}
--- /dev/null
+%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
+
--- /dev/null
+/*
+ * 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 <networklist.h>
+#include <networkitem.h>
+#include <clockmodel.h>
+
+
+void Components::registerTypes(const char *uri)
+{
+ qmlRegisterType<NetworkListModel>(uri,0,1,"NetworkListModel");
+ qmlRegisterType<NetworkItemModel>(uri,0,1,"NetworkItemModel");
+ qmlRegisterType<ClockModel>(uri,0,1,"ClockModel");
+}
+
+void Components::initializeEngine(QDeclarativeEngine *engine, const char *uri)
+{
+ Q_UNUSED(uri);
+ Q_UNUSED(engine);
+}
+
+Q_EXPORT_PLUGIN(Components);
--- /dev/null
+/*
+ * 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 <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
+
+class Components : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+
+public:
+ void registerTypes(const char *uri);
+ void initializeEngine(QDeclarativeEngine *engine, const char *uri);
+};
+
+#endif // COMPONENTS_H
--- /dev/null
+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
--- /dev/null
+plugin ConnmanQtDeclarative
--- /dev/null
+#include <QApplication>
+#include <QWidget>
+#include <QDeclarativeView>
+#include <QDeclarativeContext>
+#include <qdeclarative.h>
+
+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();
+}
--- /dev/null
+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
+ }
+ }
+ }
+}
--- /dev/null
+#-------------------------------------------------
+#
+# 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