Added SMS support in ofono-qt
[profile/ivi/ofono-qt.git] / lib / ofonomodeminterface.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 "ofonomodeminterface.h"
28 #include "ofonomodem.h"
29 #include "ofonointerface.h"
30
31 OfonoModemInterface::OfonoModemInterface(OfonoModem::SelectionSetting modemSetting, const QString& modemPath, const QString& ifname, OfonoGetPropertySetting propertySetting, QObject *parent)
32     : QObject(parent)
33 {
34
35     m_m = new OfonoModem(modemSetting, modemPath, this);
36     connect(m_m, SIGNAL(validityChanged(bool)), this, SLOT(modemValidityChanged(bool)));
37     connect(m_m, SIGNAL(interfacesChanged(QStringList)), this, SLOT(interfacesChanged(QStringList)));
38
39     m_if = new OfonoInterface(m_m->path(), ifname, propertySetting, this);
40     connect(m_m, SIGNAL(pathChanged(QString)), m_if, SLOT(setPath(const QString&)));
41     m_isValid = checkValidity();
42 }
43
44 OfonoModemInterface::~OfonoModemInterface()
45 {
46 }
47
48 bool OfonoModemInterface::isValid() const
49 {
50     return m_isValid;
51 }
52
53 OfonoModem* OfonoModemInterface::modem() const
54 {
55     return m_m;
56 }
57
58 bool OfonoModemInterface::checkValidity()
59 {
60     return (m_m->isValid() && m_m->interfaces().contains(m_if->ifname()));
61 }
62
63 void OfonoModemInterface::updateValidity()
64 {
65     if (isValid() != checkValidity()) {
66         m_isValid = checkValidity();
67         emit validityChanged(isValid());
68     }
69 }
70
71 void OfonoModemInterface::modemValidityChanged(bool /*validity*/)
72 {
73     updateValidity();
74 }
75
76 void OfonoModemInterface::interfacesChanged(const QStringList& /*interfaces*/)
77 {
78     updateValidity();
79 }
80
81 QString OfonoModemInterface::path() const
82 {
83     return m_if->path();
84 }
85     
86 QString OfonoModemInterface::errorName() const
87 {
88     return m_if->errorName();
89 }
90
91 QString OfonoModemInterface::errorMessage() const
92 {
93     return m_if->errorMessage();
94 }
95