Adding CallVolume interface support in ofono-qt Bindings Signed-off-by: Arun Ravindra...
[profile/ivi/ofono-qt.git] / lib / ofonomodem.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <QtDBus/QtDBus>
25 #include <QtCore/QObject>
26
27 #include "ofonomodem.h"
28 #include "ofonointerface.h"
29 #include "ofonomodemmanager.h"
30
31 OfonoModem::OfonoModem(SelectionSetting setting, const QString &modemPath, QObject *parent)
32         : QObject(parent), m_selectionSetting(setting)
33 {
34     
35     m_mm = new OfonoModemManager(this);
36     connect(m_mm, SIGNAL(modemAdded(QString)), this, SLOT(modemAdded(QString)));
37     connect(m_mm, SIGNAL(modemRemoved(QString)), this, SLOT(modemRemoved(QString)));
38
39     QString finalModemPath;
40
41     if (setting == AutomaticSelect)
42         finalModemPath = m_mm->modems().value(0);
43     else if (setting == ManualSelect)
44         if (m_mm->modems().contains(modemPath))
45             finalModemPath = modemPath;
46     
47     if (finalModemPath.isEmpty()) {
48         finalModemPath = "/";
49     } 
50     m_if = new OfonoInterface(finalModemPath, "org.ofono.Modem", OfonoGetAllOnStartup, this);
51     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
52             this, SLOT(propertyChanged(const QString&, const QVariant&)));
53     connect(m_if, SIGNAL(setPropertyFailed(const QString&)), 
54             this, SLOT(setPropertyFailed(const QString&)));
55     m_isValid = m_mm->modems().contains(finalModemPath);
56 }
57
58 OfonoModem::~OfonoModem()
59 {
60 }
61
62 void OfonoModem::propertyChanged(const QString& property, const QVariant& value)
63 {
64     if (property == "Online")
65         emit onlineChanged(value.value<bool>());
66     else if (property == "Powered")
67         emit poweredChanged(value.value<bool>());
68     else if (property == "Emergency")
69         emit emergencyChanged(value.value<bool>());
70     else if (property == "Name")
71         emit nameChanged(value.value<QString>());
72     else if (property == "Manufacturer")
73         emit manufacturerChanged(value.value<QString>());
74     else if (property == "Model")
75         emit modelChanged(value.value<QString>());
76     else if (property == "Revision")
77         emit revisionChanged(value.value<QString>());
78     else if (property == "Serial")
79         emit serialChanged(value.value<QString>());
80     else if (property == "Features")
81         emit featuresChanged(value.value<QStringList>());
82     else if (property == "Interfaces")
83         emit interfacesChanged(value.value<QStringList>());
84 }
85
86 void OfonoModem::setPropertyFailed(const QString& property)
87 {
88     if (property == "Online")
89         emit setOnlineFailed();
90     else if (property == "Powered")
91         emit setPoweredFailed();
92 }
93
94 void OfonoModem::modemAdded(const QString& /*modem*/)
95 {
96     modemsChanged();
97 }
98
99 void OfonoModem::modemRemoved(const QString& /*modem*/)
100 {
101     modemsChanged();
102 }
103
104 void OfonoModem::modemsChanged()
105 {
106     // validity has changed
107     if (isValid() != m_mm->modems().contains(path())) {
108         m_isValid = m_mm->modems().contains(path());
109         emit validityChanged(isValid());
110     }
111     if (!m_mm->modems().contains(path())) {
112         if (m_selectionSetting == AutomaticSelect) {
113             QString modemPath = m_mm->modems().value(0);
114             if (modemPath.isEmpty()) {
115                 modemPath = "/";
116             }
117             m_if->setPath(modemPath);
118             emit pathChanged(modemPath);
119         } else if (m_selectionSetting == ManualSelect) {
120             m_if->setPath("/");
121         }
122     }
123     // validity has changed
124     if (isValid() != m_mm->modems().contains(path())) {
125         m_isValid = m_mm->modems().contains(path());
126         emit validityChanged(isValid());
127     }
128 }
129
130
131 bool OfonoModem::isValid() const
132 {
133     return m_isValid;
134 }
135
136 QString OfonoModem::path() const
137 {
138     return m_if->path();
139 }
140
141 QString OfonoModem::errorName() const
142 {
143     return m_if->errorMessage();
144 }
145
146 QString OfonoModem::errorMessage() const
147 {
148     return m_if->errorMessage();
149 }
150
151 bool OfonoModem::powered() const
152 {
153     return m_if->properties()["Powered"].value<bool>();
154 }
155
156 void OfonoModem::setPowered(bool powered)
157 {
158     m_if->setProperty("Powered", qVariantFromValue(powered));
159 }
160
161 bool OfonoModem::online() const
162 {
163     return m_if->properties()["Online"].value<bool>();
164 }
165
166 void OfonoModem::setOnline(bool online)
167 {
168     m_if->setProperty("Online", qVariantFromValue(online));
169 }
170
171 bool OfonoModem::emergency() const
172 {
173     return m_if->properties()["Emergency"].value<bool>();
174 }
175
176 QString OfonoModem::name() const
177 {
178     return m_if->properties()["Name"].value<QString>();
179 }
180
181 QString OfonoModem::manufacturer() const
182 {
183     return m_if->properties()["Manufacturer"].value<QString>();
184 }
185
186 QString OfonoModem::model() const
187 {
188     return m_if->properties()["Model"].value<QString>();
189 }
190
191 QString OfonoModem::revision() const
192 {
193     return m_if->properties()["Revision"].value<QString>();
194 }
195
196 QString OfonoModem::serial() const
197 {
198     return m_if->properties()["Serial"].value<QString>();
199 }
200
201 QStringList OfonoModem::features() const
202 {
203     return m_if->properties()["Features"].value<QStringList>();
204 }
205
206 QStringList OfonoModem::interfaces() const
207 {
208     return m_if->properties()["Interfaces"].value<QStringList>();
209 }
210
211