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 : OfonoInterface("/", "org.ofono.Modem", OfonoInterface::GetAllOnStartup, 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 connect(this, SIGNAL(propertyChanged(const QString&, const QVariant&)),
51 this, SLOT(propertyChanged(const QString&, const QVariant&)));
52 connect(this, SIGNAL(setPropertyFailed(const QString&)),
53 this, SLOT(setPropertyFailed(const QString&)));
54 setPath(finalModemPath);
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(modemPath())) {
108 m_isValid = m_mm->modems().contains(modemPath());
109 emit validityChanged(isValid());
111 if (!m_mm->modems().contains(modemPath())) {
112 if (m_selectionSetting == AutomaticSelect) {
113 QString modemPath = m_mm->modems().value(0);
114 if (modemPath.isEmpty()) {
118 emit modemPathChanged(modemPath);
119 } else if (m_selectionSetting == ManualSelect) {
123 // validity has changed
124 if (isValid() != m_mm->modems().contains(modemPath())) {
125 m_isValid = m_mm->modems().contains(modemPath());
126 emit validityChanged(isValid());
131 bool OfonoModem::isValid() const
136 QString OfonoModem::modemPath() const
141 bool OfonoModem::powered() const
143 return properties()["Powered"].value<bool>();
146 void OfonoModem::setPowered(bool powered)
148 setProperty("Powered", qVariantFromValue(powered));
151 bool OfonoModem::online() const
153 return properties()["Online"].value<bool>();
156 void OfonoModem::setOnline(bool online)
158 setProperty("Online", qVariantFromValue(online));
161 bool OfonoModem::emergency() const
163 return properties()["Emergency"].value<bool>();
166 QString OfonoModem::name() const
168 return properties()["Name"].value<QString>();
171 QString OfonoModem::manufacturer() const
173 return properties()["Manufacturer"].value<QString>();
176 QString OfonoModem::model() const
178 return properties()["Model"].value<QString>();
181 QString OfonoModem::revision() const
183 return properties()["Revision"].value<QString>();
186 QString OfonoModem::serial() const
188 return properties()["Serial"].value<QString>();
191 QStringList OfonoModem::features() const
193 return properties()["Features"].value<QStringList>();
196 QStringList OfonoModem::interfaces() const
198 return properties()["Interfaces"].value<QStringList>();