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