Update CallForwarding class to match latest oFono
[profile/ivi/ofono-qt.git] / lib / ofonocallforwarding.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 <alex.kanavin@gmail.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 <QtCore/QObject>
25 #include <QtDBus/QtDBus>
26 #include "ofonocallforwarding.h"
27 #include "ofonointerface.h"
28
29
30 OfonoCallForwarding::OfonoCallForwarding(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
31     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.CallForwarding", OfonoGetAllOnFirstRequest, parent)
32 {
33     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
34             this, SLOT(propertyChanged(const QString&, const QVariant&)));
35     connect(m_if, SIGNAL(setPropertyFailed(const QString&)), 
36             this, SLOT(setPropertyFailed(const QString&)));
37     connect(m_if, SIGNAL(requestPropertyComplete(bool, const QString&, const QVariant&)),
38             this, SLOT(requestPropertyComplete(bool, const QString&, const QVariant&)));
39 }
40
41 OfonoCallForwarding::~OfonoCallForwarding()
42 {
43 }
44
45
46 void OfonoCallForwarding::disableAll(const QString &type)
47 {
48     QDBusMessage request;
49
50     request = QDBusMessage::createMethodCall("org.ofono",
51                                              path(), m_if->ifname(),
52                                              "DisableAll");
53     request << type;
54
55     QDBusConnection::systemBus().callWithCallback(request, this,
56                                         SLOT(disableAllResp()),
57                                         SLOT(disableAllErr(const QDBusError&)));
58 }
59
60
61 void OfonoCallForwarding::requestVoiceUnconditional()
62 {
63     m_if->requestProperty("VoiceUnconditional");
64 }
65
66 void OfonoCallForwarding::setVoiceUnconditional(const QString &property)
67 {
68     m_if->setProperty("VoiceUnconditional", qVariantFromValue(property));
69 }
70
71 void OfonoCallForwarding::requestVoiceBusy()
72 {
73     m_if->requestProperty("VoiceBusy");
74 }
75
76 void OfonoCallForwarding::setVoiceBusy(const QString &property)
77 {
78     return m_if->setProperty("VoiceBusy", qVariantFromValue(property));
79 }
80
81 void OfonoCallForwarding::requestVoiceNoReply()
82 {
83     m_if->requestProperty("VoiceNoReply");
84 }
85
86 void OfonoCallForwarding::setVoiceNoReply(const QString &property)
87 {
88     return m_if->setProperty("VoiceNoReply", qVariantFromValue(property));
89 }
90
91 void OfonoCallForwarding::requestVoiceNoReplyTimeout()
92 {
93     m_if->requestProperty("VoiceNoReplyTimeout");
94 }
95
96 void OfonoCallForwarding::setVoiceNoReplyTimeout(ushort timeout)
97 {
98     return m_if->setProperty("VoiceNoReplyTimeout", qVariantFromValue(timeout));
99 }
100
101 void OfonoCallForwarding::requestVoiceNotReachable()
102 {
103     m_if->requestProperty("VoiceNotReachable");
104 }
105
106 void OfonoCallForwarding::setVoiceNotReachable(const QString &property)
107 {
108     return m_if->setProperty("VoiceNotReachable", qVariantFromValue(property));
109 }
110
111 void OfonoCallForwarding::requestForwardingFlagOnSim()
112 {
113     m_if->requestProperty("ForwardingFlagOnSim");
114 }
115
116 void OfonoCallForwarding::propertyChanged(const QString& property, const QVariant& value)
117 {
118     if (property == "VoiceUnconditional") {     
119         emit voiceUnconditionalChanged(value.value<QString>());
120     } else  if (property == "VoiceBusy") {      
121         emit voiceBusyChanged(value.value<QString>());
122     } else  if (property == "VoiceNoReply") {   
123         emit voiceNoReplyChanged(value.value<QString>());
124     } else  if (property == "VoiceNoReplyTimeout") {    
125         emit voiceNoReplyTimeoutChanged(value.value<ushort>());
126     } else  if (property == "VoiceNotReachable") {      
127         emit voiceNotReachableChanged(value.value<QString>());
128     } else  if (property == "ForwardingFlagOnSim") {    
129         emit forwardingFlagOnSimChanged(value.value<bool>());
130     }
131 }
132
133 void OfonoCallForwarding::setPropertyFailed(const QString& property)
134 {
135     if (property == "VoiceUnconditional") {     
136         emit setVoiceUnconditionalFailed();
137     } else  if (property == "VoiceBusy") {      
138         emit setVoiceBusyFailed();
139     } else  if (property == "VoiceNoReply") {   
140         emit setVoiceNoReplyFailed();
141     } else  if (property == "VoiceNoReplyTimeout") {    
142         emit setVoiceNoReplyTimeoutFailed();
143     } else  if (property == "VoiceNotReachable") {      
144         emit setVoiceNotReachableFailed();
145     }
146 }
147
148 void OfonoCallForwarding::requestPropertyComplete(bool success, const QString& property, const QVariant& value)
149 {
150     if (property == "VoiceUnconditional") {     
151         emit voiceUnconditionalComplete(success, value.value<QString>());
152     } else if (property == "VoiceBusy") {       
153         emit voiceBusyComplete(success, value.value<QString>());
154     } else if (property == "VoiceNoReply") {    
155         emit voiceNoReplyComplete(success, value.value<QString>());
156     } else if (property == "VoiceNoReplyTimeout") {
157         emit voiceNoReplyTimeoutComplete(success, value.value<ushort>());
158     } else if (property == "VoiceNotReachable") {
159         emit voiceNotReachableComplete(success, value.value<QString>());
160     } else if (property == "ForwardingFlagOnSim") {
161         emit forwardingFlagOnSimComplete(success, value.value<bool>());
162     }
163 }
164
165 void OfonoCallForwarding::disableAllResp()
166 {
167     emit disableAllComplete(TRUE);
168 }
169
170 void OfonoCallForwarding::disableAllErr(QDBusError error)
171 {
172     m_if->setError(error.name(), error.message());
173     emit disableAllComplete(FALSE);
174 }
175