1
/****************************************************************************
3
** Copyright (C) 2014 Canonical Ltd.
4
** Contact: jonas.drange@canonical.com
6
** GNU Lesser General Public License Usage
7
** Alternatively, this file may be used under the terms of the GNU Lesser
8
** General Public License version 2.1 as published by the Free Software
9
** Foundation and appearing in the file LICENSE.LGPL included in the
10
** packaging of this file. Please review the following information to
11
** ensure the GNU Lesser General Public License version 2.1 requirements
12
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
14
****************************************************************************/
16
#include "qofonomtksettings.h"
17
#include "dbus/ofonomtksettings.h"
19
class QOfonoMtkSettingsPrivate
22
QOfonoMtkSettingsPrivate();
24
OfonoMtkSettings *mtkSettings;
25
QVariantMap properties;
29
QOfonoMtkSettingsPrivate::QOfonoMtkSettingsPrivate() :
35
QOfonoMtkSettings::QOfonoMtkSettings(QObject *parent) :
37
, d_ptr(new QOfonoMtkSettingsPrivate)
41
QOfonoMtkSettings::~QOfonoMtkSettings()
46
void QOfonoMtkSettings::setModemPath(const QString &path)
48
if (path == d_ptr->modemPath ||
52
QStringList removedProperties = d_ptr->properties.keys();
54
delete d_ptr->mtkSettings;
55
d_ptr->mtkSettings = new OfonoMtkSettings("org.ofono", path, QDBusConnection::systemBus(),this);
57
if (d_ptr->mtkSettings->isValid()) {
58
d_ptr->modemPath = path;
60
connect(d_ptr->mtkSettings,SIGNAL(PropertyChanged(QString,QDBusVariant)),
61
this,SLOT(propertyChanged(QString,QDBusVariant)));
63
QVariantMap properties = d_ptr->mtkSettings->GetProperties().value();
64
for (QVariantMap::ConstIterator it = properties.constBegin();
65
it != properties.constEnd(); ++it) {
66
updateProperty(it.key(), it.value());
67
removedProperties.removeOne(it.key());
70
Q_EMIT modemPathChanged(path);
73
foreach (const QString &p, removedProperties)
74
updateProperty(p, QVariant());
77
QString QOfonoMtkSettings::modemPath() const
79
return d_ptr->modemPath;
83
void QOfonoMtkSettings::propertyChanged(const QString& property, const QDBusVariant& dbusvalue)
85
updateProperty(property, dbusvalue.variant());
88
void QOfonoMtkSettings::updateProperty(const QString &property, const QVariant &value)
90
if (d_ptr->properties.value(property) == value)
94
d_ptr->properties.insert(property, value);
96
d_ptr->properties.remove(property);
98
if (property == QLatin1String("Has3G")) {
99
Q_EMIT has3GChanged(value.value<bool>());
103
bool QOfonoMtkSettings::has3G() const
105
return d_ptr->properties["Has3G"].value<bool>();
108
void QOfonoMtkSettings::setHas3G(bool has3G)
110
// We do not allow this property to be set to false
114
if (d_ptr->mtkSettings)
115
d_ptr->mtkSettings->SetProperty("Has3G", QDBusVariant(has3G));
118
bool QOfonoMtkSettings::isValid() const
120
return d_ptr->mtkSettings->isValid();