commit 8f71ba98d1ac5dcbdb0f7e191f8bf8f72a925898
Author: Jonas G. Drange <jonas.drange@canonical.com>
Date:   Thu Nov 20 17:01:17 CET 2014

    add mtk (mediatek) settings binding which allows consumer
    to set which modem to allow 3G communication

Index: libqofono-ubuntu/plugin/qofonodeclarativeplugin.cpp
===================================================================
--- libqofono-ubuntu.orig/plugin/qofonodeclarativeplugin.cpp
+++ libqofono-ubuntu/plugin/qofonodeclarativeplugin.cpp
@@ -34,6 +34,7 @@
 #include "qofonomessage.h"
 #include "qofonomessagemanager.h"
 #include "qofonomessagewaiting.h"
+#include "qofonomtksettings.h"
 
 #include "qofonosimmanager.h"
 
@@ -87,6 +88,7 @@ void QOfonoDeclarativePlugin::registerTy
     qmlRegisterType<QOfonoMessage>(uri,major,minor,"OfonoMessage");
     qmlRegisterType<QOfonoMessageManager>(uri,major,minor,"OfonoMessageManager");
     qmlRegisterType<QOfonoMessageWaiting>(uri,major,minor,"OfonoMessageWaiting");
+    qmlRegisterType<QOfonoMtkSettings>(uri,0,2,"OfonoMtkSettings");
 
     qmlRegisterType<QOfonoSimManager>(uri,major,minor,"OfonoSimManager");
 
Index: libqofono-ubuntu/src/dbus/ofono_mtk_settings.xml
===================================================================
--- /dev/null
+++ libqofono-ubuntu/src/dbus/ofono_mtk_settings.xml
@@ -0,0 +1,18 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="">
+	<interface name="org.ofono.MtkSettings">
+		<method name="GetProperties">
+			<arg type="a{sv}" direction="out"/>
+            <annotation name="org.qtproject.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>
Index: libqofono-ubuntu/src/dbus/ofonomtksettings.cpp
===================================================================
--- /dev/null
+++ libqofono-ubuntu/src/dbus/ofonomtksettings.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -c OfonoMtkSettings -p ofonomtksettings -N ofono_mtk_settings.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc 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 "ofonomtksettings.h"
+
+/*
+ * Implementation of interface class OfonoMtkSettings
+ */
+
+OfonoMtkSettings::OfonoMtkSettings(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+    : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+OfonoMtkSettings::~OfonoMtkSettings()
+{
+}
+
Index: libqofono-ubuntu/src/dbus/ofonomtksettings.h
===================================================================
--- /dev/null
+++ libqofono-ubuntu/src/dbus/ofonomtksettings.h
@@ -0,0 +1,56 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.8
+ * Command line was: qdbusxml2cpp -c OfonoMtkSettings -p ofonomtksettings -N ofono_mtk_settings.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#ifndef OFONOMTKSETTINGS_H_1416404986
+#define OFONOMTKSETTINGS_H_1416404986
+
+#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 org.ofono.MtkSettings
+ */
+class OfonoMtkSettings: public QDBusAbstractInterface
+{
+    Q_OBJECT
+public:
+    static inline const char *staticInterfaceName()
+    { return "org.ofono.MtkSettings"; }
+
+public:
+    OfonoMtkSettings(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+    ~OfonoMtkSettings();
+
+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 << QVariant::fromValue(in0) << QVariant::fromValue(in1);
+        return asyncCallWithArgumentList(QLatin1String("SetProperty"), argumentList);
+    }
+
+Q_SIGNALS: // SIGNALS
+    void PropertyChanged(const QString &in0, const QDBusVariant &in1);
+};
+
+#endif
Index: libqofono-ubuntu/src/qofonomtksettings.cpp
===================================================================
--- /dev/null
+++ libqofono-ubuntu/src/qofonomtksettings.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Canonical Ltd.
+** Contact: jonas.drange@canonical.com
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+****************************************************************************/
+
+#include "qofonomtksettings.h"
+#include "dbus/ofonomtksettings.h"
+
+class QOfonoMtkSettingsPrivate
+{
+public:
+    QOfonoMtkSettingsPrivate();
+    QString modemPath;
+    OfonoMtkSettings *mtkSettings;
+    QVariantMap properties;
+
+};
+
+QOfonoMtkSettingsPrivate::QOfonoMtkSettingsPrivate() :
+    modemPath(QString())
+  , mtkSettings(0)
+{
+}
+
+QOfonoMtkSettings::QOfonoMtkSettings(QObject *parent) :
+    QObject(parent)
+  , d_ptr(new QOfonoMtkSettingsPrivate)
+{
+}
+
+QOfonoMtkSettings::~QOfonoMtkSettings()
+{
+    delete d_ptr;
+}
+
+void QOfonoMtkSettings::setModemPath(const QString &path)
+{
+    if (path == d_ptr->modemPath ||
+            path.isEmpty())
+        return;
+
+    QStringList removedProperties = d_ptr->properties.keys();
+
+    delete d_ptr->mtkSettings;
+    d_ptr->mtkSettings = new OfonoMtkSettings("org.ofono", path, QDBusConnection::systemBus(),this);
+
+    if (d_ptr->mtkSettings->isValid()) {
+        d_ptr->modemPath = path;
+
+        connect(d_ptr->mtkSettings,SIGNAL(PropertyChanged(QString,QDBusVariant)),
+                this,SLOT(propertyChanged(QString,QDBusVariant)));
+
+        QVariantMap properties = d_ptr->mtkSettings->GetProperties().value();
+        for (QVariantMap::ConstIterator it = properties.constBegin();
+             it != properties.constEnd(); ++it) {
+            updateProperty(it.key(), it.value());
+            removedProperties.removeOne(it.key());
+        }
+
+        Q_EMIT modemPathChanged(path);
+    }
+
+    foreach (const QString &p, removedProperties)
+        updateProperty(p, QVariant());
+}
+
+QString QOfonoMtkSettings::modemPath() const
+{
+    return d_ptr->modemPath;
+}
+
+
+void QOfonoMtkSettings::propertyChanged(const QString& property, const QDBusVariant& dbusvalue)
+{
+    updateProperty(property, dbusvalue.variant());
+}
+
+void QOfonoMtkSettings::updateProperty(const QString &property, const QVariant &value)
+{
+    if (d_ptr->properties.value(property) == value)
+        return;
+
+    if (value.isValid())
+        d_ptr->properties.insert(property, value);
+    else
+        d_ptr->properties.remove(property);
+
+    if (property == QLatin1String("Has3G")) {
+        Q_EMIT has3GChanged(value.value<bool>());
+    }
+}
+
+bool QOfonoMtkSettings::has3G() const
+{
+    return d_ptr->properties["Has3G"].value<bool>();
+}
+
+void QOfonoMtkSettings::setHas3G(bool has3G)
+{
+    // We do not allow this property to be set to false
+    if (!has3G)
+        return;
+
+    if (d_ptr->mtkSettings)
+        d_ptr->mtkSettings->SetProperty("Has3G", QDBusVariant(has3G));
+}
+
+bool QOfonoMtkSettings::isValid() const
+{
+    return d_ptr->mtkSettings->isValid();
+}
Index: libqofono-ubuntu/src/qofonomtksettings.h
===================================================================
--- /dev/null
+++ libqofono-ubuntu/src/qofonomtksettings.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Canonical Ltd.
+** Contact: jonas.drange@canonical.com
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+****************************************************************************/
+
+#ifndef QOFONOMtkSettings_H
+#define QOFONOMtkSettings_H
+
+#include <QObject>
+#include <QDBusVariant>
+
+#include "qofono_global.h"
+//! This class is used to access ofono mtk (MediaTek) settings API
+/*!
+ * The API is documented in
+ * https://github.com/rilmodem/ofono/blob/master/doc/mtk-settings-api.txt
+ */
+
+class QOfonoMtkSettingsPrivate;
+class QOFONOSHARED_EXPORT QOfonoMtkSettings : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(QString modemPath READ modemPath WRITE setModemPath NOTIFY modemPathChanged)
+    Q_PROPERTY(bool has3G READ has3G WRITE setHas3G NOTIFY has3GChanged)
+
+public:
+    explicit QOfonoMtkSettings(QObject *parent = 0);
+    ~QOfonoMtkSettings();
+
+    QString modemPath() const;
+    void setModemPath(const QString &path);
+
+    bool has3G() const;
+    void setHas3G(bool has3G);
+
+    bool isValid() const;
+Q_SIGNALS:
+    void has3GChanged(bool has3G);
+    void modemPathChanged(const QString &path);
+
+public slots:
+
+private:
+    void updateProperty(const QString &property, const QVariant &value);
+
+    QOfonoMtkSettingsPrivate *d_ptr;
+private slots:
+    void propertyChanged(const QString &property,const QDBusVariant &value);
+};
+
+#endif // QOFONOMtkSettings_H
Index: libqofono-ubuntu/src/src.pro
===================================================================
--- libqofono-ubuntu.orig/src/src.pro
+++ libqofono-ubuntu/src/src.pro
@@ -48,6 +48,7 @@ XML_FILES += \
     dbus/ofono_message_manager.xml \
     dbus/ofono_messagewaiting.xml \
     dbus/ofono_modem.xml \
+    dbus/ofono_mtk_settings.xml \
     dbus/ofono_network_operator.xml \
     dbus/ofono_network_registration.xml \
     dbus/ofono_phonebook.xml \
@@ -93,6 +94,7 @@ SOURCES += \
     qofonomessage.cpp \
     qofonomessagemanager.cpp \
     qofonomessagewaiting.cpp \
+    qofonomtksettings.cpp \
     qofonosimmanager.cpp \
     qofonosimwatcher.cpp \
     qofonophonebook.cpp \
@@ -133,6 +135,7 @@ PUBLIC_HEADERS += \
     qofonomessage.h \
     qofonomessagemanager.h \
     qofonomessagewaiting.h \
+    qofonomtksettings.h \
     qofonosimmanager.h \
     qofonosimwatcher.h \
     qofonophonebook.h \
@@ -261,6 +264,11 @@ ofono_modem.files = dbus/ofono_modem.xml
 ofono_modem.header_flags = -N -c OfonoModem
 ofono_modem.source_flags = -N -c OfonoModem
 
+DBUS_INTERFACES += ofono_mtk_settings
+ofono_mtk_settings.files = dbus/ofono_mtk_settings.xml
+ofono_mtk_settings.header_flags = -N -c OfonoMtkSettings
+ofono_mtk_settings.source_flags = -N -c OfonoMtkSettings
+
 DBUS_INTERFACES += ofono_network_operator
 ofono_network_operator.files = dbus/ofono_network_operator.xml
 ofono_network_operator.header_flags = -N -c OfonoNetworkOperator
Index: libqofono-ubuntu/test/auto/tests/tests.pro
===================================================================
--- libqofono-ubuntu.orig/test/auto/tests/tests.pro
+++ libqofono-ubuntu/test/auto/tests/tests.pro
@@ -11,6 +11,7 @@ SUBDIRS += \
     tst_qofonosimmanager.pro \
     tst_qofonomessagewaiting.pro \
     tst_qofonomessagemanager.pro \
+    tst_qofonomtksettings.pro \
     tst_qofonoradiosettings.pro \
     tst_qofonocallbarring.pro \
     tst_qofonocallforwarding.pro \
Index: libqofono-ubuntu/test/auto/tests/tst_qofonomtksettings.cpp
===================================================================
--- /dev/null
+++ libqofono-ubuntu/test/auto/tests/tst_qofonomtksettings.cpp
@@ -0,0 +1,61 @@
+/*
+ *
+ * Copyright (C) 2014 Canonical Ltd.
+ * Contact: Jonas G. Drange <jonas.drange@canonical.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <QtTest/QtTest>
+#include <QtCore/QObject>
+
+#include "../../../src/qofonomtksettings.h"
+
+#include <QtDebug>
+
+class TestQOfonoMtkSettings : public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void initTestCase()
+    {
+        m = new QOfonoMtkSettings(this);
+        m->setModemPath("/phonesim");
+        QCOMPARE(m->isValid(), true);
+
+        QEXPECT_FAIL("", "mtk settings is not supported by phonesim", Abort);
+        QVERIFY(false);
+    }
+
+    void testQOfonoMtkSettings()
+    {
+        QSignalSpy has3G(m, SIGNAL(has3GChanged(bool)));
+
+        qDebug() << "has3G():" << m->has3G();
+    }
+
+    void cleanupTestCase()
+    {
+
+    }
+
+private:
+    QOfonoMtkSettings *m;
+};
+
+QTEST_MAIN(TestQOfonoMtkSettings)
+#include "tst_qofonomtksettings.moc"
Index: libqofono-ubuntu/test/auto/tests/tst_qofonomtksettings.pro
===================================================================
--- /dev/null
+++ libqofono-ubuntu/test/auto/tests/tst_qofonomtksettings.pro
@@ -0,0 +1,2 @@
+include(testcase.pri)
+SOURCES += tst_qofonomtksettings.cpp
