2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
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.
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.
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
24 #include <QtDBus/QtDBus>
25 #include <QtCore/QObject>
27 #include "ofonomodem.h"
28 #include "ofonointerface.h"
29 #include "ofonomodemmanager.h"
31 OfonoModem::OfonoModem(SelectionSetting setting, const QString &modemPath, QObject *parent)
32 : QObject(parent), m_selectionSetting(setting)
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)));
39 QString finalModemPath;
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;
47 if (finalModemPath.isEmpty()) {
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);
58 OfonoModem::~OfonoModem()
62 void OfonoModem::propertyChanged(const QString& property, const QVariant& value)
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>());
86 void OfonoModem::setPropertyFailed(const QString& property)
88 if (property == "Online")
89 emit setOnlineFailed();
90 else if (property == "Powered")
91 emit setPoweredFailed();
94 void OfonoModem::modemAdded(const QString& /*modem*/)
99 void OfonoModem::modemRemoved(const QString& /*modem*/)
104 void OfonoModem::modemsChanged()
106 // validity has changed
107 if (isValid() != m_mm->modems().contains(path())) {
108 m_isValid = m_mm->modems().contains(path());
109 emit validityChanged(isValid());
111 if (!m_mm->modems().contains(path())) {
112 if (m_selectionSetting == AutomaticSelect) {
113 QString modemPath = m_mm->modems().value(0);
114 if (modemPath.isEmpty()) {
117 m_if->setPath(modemPath);
118 emit pathChanged(modemPath);
119 } else if (m_selectionSetting == ManualSelect) {
123 // validity has changed
124 if (isValid() != m_mm->modems().contains(path())) {
125 m_isValid = m_mm->modems().contains(path());
126 emit validityChanged(isValid());
131 bool OfonoModem::isValid() const
136 QString OfonoModem::path() const
141 QString OfonoModem::errorName() const
143 return m_if->errorMessage();
146 QString OfonoModem::errorMessage() const
148 return m_if->errorMessage();
151 bool OfonoModem::powered() const
153 return m_if->properties()["Powered"].value<bool>();
156 void OfonoModem::setPowered(bool powered)
158 m_if->setProperty("Powered", qVariantFromValue(powered));
161 bool OfonoModem::online() const
163 return m_if->properties()["Online"].value<bool>();
166 void OfonoModem::setOnline(bool online)
168 m_if->setProperty("Online", qVariantFromValue(online));
171 bool OfonoModem::emergency() const
173 return m_if->properties()["Emergency"].value<bool>();
176 QString OfonoModem::name() const
178 return m_if->properties()["Name"].value<QString>();
181 QString OfonoModem::manufacturer() const
183 return m_if->properties()["Manufacturer"].value<QString>();
186 QString OfonoModem::model() const
188 return m_if->properties()["Model"].value<QString>();
191 QString OfonoModem::revision() const
193 return m_if->properties()["Revision"].value<QString>();
196 QString OfonoModem::serial() const
198 return m_if->properties()["Serial"].value<QString>();
201 QStringList OfonoModem::features() const
203 return m_if->properties()["Features"].value<QStringList>();
206 QStringList OfonoModem::interfaces() const
208 return m_if->properties()["Interfaces"].value<QStringList>();