Remove unnecessary includes
[profile/ivi/ofono-qt.git] / lib / ofonosupplementaryservices.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 "ofonosupplementaryservices.h"
28
29 #define REQUEST_TIMEOUT 60000
30
31 OfonoSupplementaryServices::OfonoSupplementaryServices(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
32     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.SupplementaryServices", OfonoInterface::GetAllOnStartup, parent)
33 {
34
35     connect(this, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
36             this, SLOT(propertyChanged(const QString&, const QVariant&)));
37     QDBusConnection::systemBus().connect("org.ofono", path(), ifname(), 
38                                              "NotificationReceived",
39                                              this,
40                                              SIGNAL(notificationReceived(QString)));
41     QDBusConnection::systemBus().connect("org.ofono", path(), ifname(), 
42                                              "RequestReceived",
43                                              this,
44                                              SIGNAL(requestReceived(QString)));
45 }
46
47 OfonoSupplementaryServices::~OfonoSupplementaryServices()
48 {
49 }
50
51 void OfonoSupplementaryServices::requestInitiate(const QString &command)
52 {
53     QDBusMessage request;
54
55     request = QDBusMessage::createMethodCall("org.ofono",
56                                              path(), ifname(),
57                                              "Initiate");
58     request << command;
59
60     QDBusConnection::systemBus().callWithCallback(request, this,
61                                         SLOT(initiateResp(QString, QDBusVariant)),
62                                         SLOT(initiateErr(const QDBusError&)),
63                                         REQUEST_TIMEOUT);
64 }
65
66 void OfonoSupplementaryServices::requestRespond(const QString &reply)
67 {
68     QDBusMessage request;
69
70     request = QDBusMessage::createMethodCall("org.ofono",
71                                              path(), ifname(),
72                                              "Respond");
73     request << reply;
74
75     QDBusConnection::systemBus().callWithCallback(request, this,
76                                         SLOT(respondResp(QString)),
77                                         SLOT(respondErr(const QDBusError&)),
78                                         REQUEST_TIMEOUT);
79 }
80
81 void OfonoSupplementaryServices::requestCancel()
82 {
83     QDBusMessage request;
84
85     request = QDBusMessage::createMethodCall("org.ofono",
86                                              path(), ifname(),
87                                              "Cancel");
88
89     QDBusConnection::systemBus().callWithCallback(request, this,
90                                         SLOT(cancelResp(QString)),
91                                         SLOT(cancelErr(const QDBusError&)),
92                                         REQUEST_TIMEOUT);
93 }
94
95 QString OfonoSupplementaryServices::state() const
96 {
97     return properties()["State"].value<QString>();
98 }
99
100 void OfonoSupplementaryServices::propertyChanged(const QString& property, const QVariant& value)
101 {
102     if (property == "State") {  
103         emit stateChanged(value.value<QString>());
104     } 
105 }
106
107 void OfonoSupplementaryServices::initiateResp(QString message, QDBusVariant details)
108 {
109     const QDBusArgument argument = details.variant().value<QDBusArgument>();
110     if (message == "USSD") {
111         QString ussdResp;
112         argument >> ussdResp;
113         emit initiateUSSDComplete(ussdResp);
114     } else if (message == "CallBarring") {
115         QString ssOp, cbService;
116         QVariantMap cbMap;
117         argument.beginStructure();
118         argument >> ssOp >> cbService >> cbMap;
119         argument.endStructure();
120         emit barringComplete(ssOp, cbService, cbMap);
121     } else if (message == "CallForwarding") {
122         QString ssOp, cfService;
123         QVariantMap cfMap;
124         argument.beginStructure();
125         argument >> ssOp >> cfService >> cfMap;
126         argument.endStructure();
127         emit forwardingComplete(ssOp, cfService, cfMap);
128     } else if (message == "CallWaiting") {
129         QString ssOp;
130         QVariantMap cwMap;
131         argument.beginStructure();
132         argument >> ssOp >> cwMap;
133         argument.endStructure();
134         emit waitingComplete(ssOp, cwMap);
135     } else if (message == "CallingLinePresentation") {
136         QString ssOp, status;
137         argument.beginStructure();
138         argument >> ssOp >> status;
139         argument.endStructure();
140         emit callingLinePresentationComplete(ssOp, status);
141     } else if (message == "CalledLinePresentation") {
142         QString ssOp, status;
143         argument.beginStructure();
144         argument >> ssOp >> status;
145         argument.endStructure();
146         emit calledLinePresentationComplete(ssOp, status);
147     } else if (message == "CallingLineRestriction") {
148         QString ssOp, status;
149         argument.beginStructure();
150         argument >> ssOp >> status;
151         argument.endStructure();
152         emit callingLineRestrictionComplete(ssOp, status);
153     } else if (message == "CalledLineRestriction") {
154         QString ssOp, status;
155         argument.beginStructure();
156         argument >> ssOp >> status;
157         argument.endStructure();
158         emit calledLineRestrictionComplete(ssOp, status);
159     } 
160 }
161
162 void OfonoSupplementaryServices::initiateErr(QDBusError error)
163 {
164     qDebug() << "Initiate failed" << error;
165     m_errorName = error.name();
166     m_errorMessage = error.message();
167     emit initiateFailed();
168 }
169
170
171 void OfonoSupplementaryServices::respondResp(QString message)
172 {
173     emit respondComplete(TRUE, message);
174 }
175
176 void OfonoSupplementaryServices::respondErr(QDBusError error)
177 {
178     qDebug() << "Respond failed" << error;
179     m_errorName = error.name();
180     m_errorMessage = error.message();
181     emit respondComplete(FALSE, QString());
182 }
183
184 void OfonoSupplementaryServices::cancelResp()
185 {
186     emit cancelComplete(TRUE);
187 }
188
189 void OfonoSupplementaryServices::cancelErr(QDBusError error)
190 {
191     qDebug() << "Cancel failed" << error;
192     m_errorName = error.name();
193     m_errorMessage = error.message();
194     emit cancelComplete(FALSE);
195 }
196