2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
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.
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.
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
24 #include <QtCore/QObject>
25 #include <QtDBus/QtDBus>
26 #include "ofonocallbarring.h"
28 #define SET_PROPERTY_TIMEOUT 300000
30 OfonoCallBarring::OfonoCallBarring(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
31 : OfonoModemInterface(modemSetting, modemPath, "org.ofono.CallBarring", OfonoInterface::GetAllOnFirstRequest, parent)
33 connect(this, SIGNAL(propertyChanged(const QString&, const QVariant&)),
34 this, SLOT(propertyChanged(const QString&, const QVariant&)));
35 connect(this, SIGNAL(setPropertyFailed(const QString&)),
36 this, SLOT(setPropertyFailed(const QString&)));
37 connect(this, SIGNAL(requestPropertyComplete(bool, const QString&, const QVariant&)),
38 this, SLOT(requestPropertyComplete(bool, const QString&, const QVariant&)));
39 QDBusConnection::systemBus().connect("org.ofono", path(), ifname(),
40 "IncomingBarringInEffect",
42 SIGNAL(incomingBarringInEffect()));
43 QDBusConnection::systemBus().connect("org.ofono", path(), ifname(),
44 "OutgoingBarringInEffect",
46 SIGNAL(outgoingBarringInEffect()));
47 m_pendingProperty = QString();
50 OfonoCallBarring::~OfonoCallBarring()
54 void OfonoCallBarring::setProperty(const QString& name,
55 const QVariant& property,
56 const QString& password)
58 if (m_pendingProperty.length() > 0) {
59 // FIXME: should indicate that a setProperty is already in progress
60 m_errorName = QString();
61 m_errorMessage = QString("Operation already in progress");
62 emit setPropertyFailed(name);
69 request = QDBusMessage::createMethodCall("org.ofono",
72 request.setArguments(QList<QVariant>()
74 << QVariant::fromValue(QDBusVariant(property))
75 << QVariant(password));
77 bool result = QDBusConnection::systemBus().callWithCallback(request, this,
78 SLOT(setPropertyResp()),
79 SLOT(setPropertyErr(const QDBusError&)),
80 SET_PROPERTY_TIMEOUT);
82 // FIXME: should indicate that sending a message failed
83 m_errorName = QString();
84 m_errorMessage = QString("DBUS sending failed");
85 emit setPropertyFailed(name);
88 m_pendingProperty = name;
93 void OfonoCallBarring::setPropertyResp()
95 m_pendingProperty = QString();
96 // emit nothing; we will get a PropertyChanged signal
99 void OfonoCallBarring::setPropertyErr(const QDBusError& error)
101 QString prop = m_pendingProperty;
102 m_errorName = error.name();
103 m_errorMessage = error.message();
104 m_pendingProperty = QString();
105 emit setPropertyFailed(prop);
109 void OfonoCallBarring::requestChangePassword(const QString &old_password,
110 const QString &new_password)
112 QDBusMessage request;
114 request = QDBusMessage::createMethodCall("org.ofono",
117 request << old_password << new_password;
119 QDBusConnection::systemBus().callWithCallback(request, this,
120 SLOT(changePasswordResp()),
121 SLOT(changePasswordErr(const QDBusError&)));
124 void OfonoCallBarring::requestDisableAll(const QString &password)
126 QDBusMessage request;
128 request = QDBusMessage::createMethodCall("org.ofono",
133 QDBusConnection::systemBus().callWithCallback(request, this,
134 SLOT(disableAllResp()),
135 SLOT(disableAllErr(const QDBusError&)));
138 void OfonoCallBarring::requestDisableAllIncoming(const QString &password)
140 QDBusMessage request;
142 request = QDBusMessage::createMethodCall("org.ofono",
144 "DisableAllIncoming");
147 QDBusConnection::systemBus().callWithCallback(request, this,
148 SLOT(disableAllIncomingResp()),
149 SLOT(disableAllIncomingErr(const QDBusError&)));
152 void OfonoCallBarring::requestDisableAllOutgoing(const QString &password)
154 QDBusMessage request;
156 request = QDBusMessage::createMethodCall("org.ofono",
158 "DisableAllOutgoing");
161 QDBusConnection::systemBus().callWithCallback(request, this,
162 SLOT(disableAllOutgoingResp()),
163 SLOT(disableAllOutgoingErr(const QDBusError&)));
167 void OfonoCallBarring::requestVoiceIncoming()
169 requestProperty("VoiceIncoming");
172 void OfonoCallBarring::setVoiceIncoming(const QString &barrings, const QString &password)
174 setProperty("VoiceIncoming", qVariantFromValue(barrings), password);
177 void OfonoCallBarring::requestVoiceOutgoing()
179 requestProperty("VoiceOutgoing");
182 void OfonoCallBarring::setVoiceOutgoing(const QString &barrings, const QString &password)
184 setProperty("VoiceOutgoing", qVariantFromValue(barrings), password);
187 void OfonoCallBarring::propertyChanged(const QString& property, const QVariant& value)
189 if (property == "VoiceIncoming") {
190 emit voiceIncomingChanged(value.value<QString>());
191 } else if (property == "VoiceOutgoing") {
192 emit voiceOutgoingChanged(value.value<QString>());
196 void OfonoCallBarring::setPropertyFailed(const QString& property)
198 if (property == "VoiceIncoming") {
199 emit setVoiceIncomingFailed();
200 } else if (property == "VoiceOutgoing") {
201 emit setVoiceOutgoingFailed();
205 void OfonoCallBarring::requestPropertyComplete(bool success, const QString& property, const QVariant& value)
207 if (property == "VoiceIncoming") {
208 success ? emit voiceIncomingComplete(true, value.value<QString>()) : emit voiceIncomingComplete(false, QString());
209 } else if (property == "VoiceOutgoing") {
210 success ? emit voiceOutgoingComplete(true, value.value<QString>()) : emit voiceOutgoingComplete(false, QString());
214 void OfonoCallBarring::changePasswordResp()
216 emit changePasswordComplete(TRUE);
219 void OfonoCallBarring::changePasswordErr(QDBusError error)
221 qDebug() << "ChangePassword failed" << error;
222 m_errorName = error.name();
223 m_errorMessage = error.message();
224 emit changePasswordComplete(FALSE);
227 void OfonoCallBarring::disableAllResp()
229 emit disableAllComplete(TRUE);
232 void OfonoCallBarring::disableAllErr(QDBusError error)
234 qDebug() << "DisableAll failed" << error;
235 m_errorName = error.name();
236 m_errorMessage = error.message();
237 emit disableAllComplete(FALSE);
240 void OfonoCallBarring::disableAllIncomingResp()
242 emit disableAllIncomingComplete(TRUE);
245 void OfonoCallBarring::disableAllIncomingErr(QDBusError error)
247 qDebug() << "DisableAllIncoming failed" << error;
248 m_errorName = error.name();
249 m_errorMessage = error.message();
250 emit disableAllIncomingComplete(FALSE);
253 void OfonoCallBarring::disableAllOutgoingResp()
255 emit disableAllOutgoingComplete(TRUE);
258 void OfonoCallBarring::disableAllOutgoingErr(QDBusError error)
260 qDebug() << "DisableAllOutgoing failed" << error;
261 m_errorName = error.name();
262 m_errorMessage = error.message();
263 emit disableAllOutgoingComplete(FALSE);