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