~ken-vandine/ubuntu/wily/libqofono/libqofono-0.79

« back to all changes in this revision

Viewing changes to src/qofonomtksettings.cpp

  • Committer: Ken VanDine
  • Author(s): Ken VanDine, Jonas Drange
  • Date: 2015-05-21 20:16:51 UTC
  • Revision ID: ken.vandine@canonical.com-20150521201651-boa8e4wvl26l369h
Tags: 0.70-0ubuntu4
[ Jonas Drange ]
* debian/patches/connman-resetcontexts.patch
  - Added bindings to Ofono's reset context API (LP: #1338758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2014 Canonical Ltd.
 
4
** Contact: jonas.drange@canonical.com
 
5
**
 
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.
 
13
**
 
14
****************************************************************************/
 
15
 
 
16
#include "qofonomtksettings.h"
 
17
#include "dbus/ofonomtksettings.h"
 
18
 
 
19
class QOfonoMtkSettingsPrivate
 
20
{
 
21
public:
 
22
    QOfonoMtkSettingsPrivate();
 
23
    QString modemPath;
 
24
    OfonoMtkSettings *mtkSettings;
 
25
    QVariantMap properties;
 
26
 
 
27
};
 
28
 
 
29
QOfonoMtkSettingsPrivate::QOfonoMtkSettingsPrivate() :
 
30
    modemPath(QString())
 
31
  , mtkSettings(0)
 
32
{
 
33
}
 
34
 
 
35
QOfonoMtkSettings::QOfonoMtkSettings(QObject *parent) :
 
36
    QObject(parent)
 
37
  , d_ptr(new QOfonoMtkSettingsPrivate)
 
38
{
 
39
}
 
40
 
 
41
QOfonoMtkSettings::~QOfonoMtkSettings()
 
42
{
 
43
    delete d_ptr;
 
44
}
 
45
 
 
46
void QOfonoMtkSettings::setModemPath(const QString &path)
 
47
{
 
48
    if (path == d_ptr->modemPath ||
 
49
            path.isEmpty())
 
50
        return;
 
51
 
 
52
    QStringList removedProperties = d_ptr->properties.keys();
 
53
 
 
54
    delete d_ptr->mtkSettings;
 
55
    d_ptr->mtkSettings = new OfonoMtkSettings("org.ofono", path, QDBusConnection::systemBus(),this);
 
56
 
 
57
    if (d_ptr->mtkSettings->isValid()) {
 
58
        d_ptr->modemPath = path;
 
59
 
 
60
        connect(d_ptr->mtkSettings,SIGNAL(PropertyChanged(QString,QDBusVariant)),
 
61
                this,SLOT(propertyChanged(QString,QDBusVariant)));
 
62
 
 
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());
 
68
        }
 
69
 
 
70
        Q_EMIT modemPathChanged(path);
 
71
    }
 
72
 
 
73
    foreach (const QString &p, removedProperties)
 
74
        updateProperty(p, QVariant());
 
75
}
 
76
 
 
77
QString QOfonoMtkSettings::modemPath() const
 
78
{
 
79
    return d_ptr->modemPath;
 
80
}
 
81
 
 
82
 
 
83
void QOfonoMtkSettings::propertyChanged(const QString& property, const QDBusVariant& dbusvalue)
 
84
{
 
85
    updateProperty(property, dbusvalue.variant());
 
86
}
 
87
 
 
88
void QOfonoMtkSettings::updateProperty(const QString &property, const QVariant &value)
 
89
{
 
90
    if (d_ptr->properties.value(property) == value)
 
91
        return;
 
92
 
 
93
    if (value.isValid())
 
94
        d_ptr->properties.insert(property, value);
 
95
    else
 
96
        d_ptr->properties.remove(property);
 
97
 
 
98
    if (property == QLatin1String("Has3G")) {
 
99
        Q_EMIT has3GChanged(value.value<bool>());
 
100
    }
 
101
}
 
102
 
 
103
bool QOfonoMtkSettings::has3G() const
 
104
{
 
105
    return d_ptr->properties["Has3G"].value<bool>();
 
106
}
 
107
 
 
108
void QOfonoMtkSettings::setHas3G(bool has3G)
 
109
{
 
110
    // We do not allow this property to be set to false
 
111
    if (!has3G)
 
112
        return;
 
113
 
 
114
    if (d_ptr->mtkSettings)
 
115
        d_ptr->mtkSettings->SetProperty("Has3G", QDBusVariant(has3G));
 
116
}
 
117
 
 
118
bool QOfonoMtkSettings::isValid() const
 
119
{
 
120
    return d_ptr->mtkSettings->isValid();
 
121
}