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(QString modemId, QObject *parent)
32 : OfonoInterface("/", "org.ofono.Modem", OfonoInterface::GetAllOnStartup, parent)
34 m_mm = new OfonoModemManager(this);
35 connect(m_mm, SIGNAL(modemAdded(QString)), this, SLOT(modemAdded(QString)));
36 connect(m_mm, SIGNAL(modemRemoved(QString)), this, SLOT(modemRemoved(QString)));
38 if (modemId.isEmpty())
43 if (m_autoChoose == true)
44 modemId = m_mm->modems().value(0);
46 if (modemId.isEmpty()) {
49 connect(this, SIGNAL(propertyChanged(const QString&, const QVariant&)),
50 this, SLOT(propertyChanged(const QString&, const QVariant&)));
51 connect(this, SIGNAL(setPropertyFailed(const QString&)),
52 this, SLOT(setPropertyFailed(const QString&)));
54 m_isValid = m_mm->modems().contains(modemId);
57 OfonoModem::~OfonoModem()
61 void OfonoModem::propertyChanged(const QString& property, const QVariant& value)
63 if (property == "Online")
64 emit onlineChanged(value.value<bool>());
65 else if (property == "Powered")
66 emit poweredChanged(value.value<bool>());
67 else if (property == "Emergency")
68 emit emergencyChanged(value.value<bool>());
69 else if (property == "Name")
70 emit nameChanged(value.value<QString>());
71 else if (property == "Manufacturer")
72 emit manufacturerChanged(value.value<QString>());
73 else if (property == "Model")
74 emit modelChanged(value.value<QString>());
75 else if (property == "Revision")
76 emit revisionChanged(value.value<QString>());
77 else if (property == "Serial")
78 emit serialChanged(value.value<QString>());
79 else if (property == "Features")
80 emit featuresChanged(value.value<QStringList>());
81 else if (property == "Interfaces")
82 emit interfacesChanged(value.value<QStringList>());
85 void OfonoModem::setPropertyFailed(const QString& property)
87 if (property == "Online")
88 emit setOnlineFailed();
89 else if (property == "Powered")
90 emit setPoweredFailed();
93 void OfonoModem::modemAdded(QString /*modem*/)
98 void OfonoModem::modemRemoved(QString /*modem*/)
103 void OfonoModem::modemsChanged()
105 // validity has changed
106 if (isValid() != m_mm->modems().contains(modemId())) {
107 m_isValid = m_mm->modems().contains(modemId());
108 emit validityChanged(isValid());
110 if (!m_mm->modems().contains(modemId())) {
111 if (m_autoChoose == true) {
112 QString modemId = m_mm->modems().value(0);
113 if (modemId.isEmpty()) {
117 emit modemIdChanged(modemId);
120 // validity has changed
121 if (isValid() != m_mm->modems().contains(modemId())) {
122 m_isValid = m_mm->modems().contains(modemId());
123 emit validityChanged(isValid());
128 bool OfonoModem::isValid() const
133 QString OfonoModem::modemId() const
138 bool OfonoModem::powered() const
140 return properties()["Powered"].value<bool>();
143 void OfonoModem::setPowered(bool powered)
145 setProperty("Powered", qVariantFromValue(powered));
148 bool OfonoModem::online() const
150 return properties()["Online"].value<bool>();
153 void OfonoModem::setOnline(bool online)
155 setProperty("Online", qVariantFromValue(online));
158 bool OfonoModem::emergency() const
160 return properties()["Emergency"].value<bool>();
163 QString OfonoModem::name() const
165 return properties()["Name"].value<QString>();
168 QString OfonoModem::manufacturer() const
170 return properties()["Manufacturer"].value<QString>();
173 QString OfonoModem::model() const
175 return properties()["Model"].value<QString>();
178 QString OfonoModem::revision() const
180 return properties()["Revision"].value<QString>();
183 QString OfonoModem::serial() const
185 return properties()["Serial"].value<QString>();
188 QStringList OfonoModem::features() const
190 return properties()["Features"].value<QStringList>();
193 QStringList OfonoModem::interfaces() const
195 return properties()["Interfaces"].value<QStringList>();