~ken-vandine/libqofono/0.90-suggests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/****************************************************************************
**
** Copyright (C) 2013-2015 Jolla Ltd.
** Contact: lorn.potter@jollamobile.com
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/

#include "qofonosupplementaryservices.h"
#include "ofono_supplementary_services_interface.h"

#define SUPER QOfonoModemInterface

QOfonoSupplementaryServices::QOfonoSupplementaryServices(QObject *parent) :
    SUPER(OfonoSupplementaryServices::staticInterfaceName(), parent)
{
}

QOfonoSupplementaryServices::~QOfonoSupplementaryServices()
{
}

QDBusAbstractInterface *QOfonoSupplementaryServices::createDbusInterface(const QString &path)
{
    QDBusAbstractInterface *iface = new OfonoSupplementaryServices("org.ofono", path, QDBusConnection::systemBus(), this);

    connect(iface, SIGNAL(NotificationReceived(QString)), this, SIGNAL(notificationReceived(QString)));
    connect(iface, SIGNAL(RequestReceived(QString)), this, SIGNAL(requestReceived(QString)));

    return iface;
}

void QOfonoSupplementaryServices::initiate(const QString &command)
{
    OfonoSupplementaryServices *iface = (OfonoSupplementaryServices*)dbusInterface();
    if (iface) {
        connect(new QDBusPendingCallWatcher(iface->Initiate(command), iface),
            SIGNAL(finished(QDBusPendingCallWatcher*)),
            SLOT(initiateResponseReceived(QDBusPendingCallWatcher*)));
    }
}

void QOfonoSupplementaryServices::respond(const QString &command)
{
    OfonoSupplementaryServices *iface = (OfonoSupplementaryServices*)dbusInterface();
    if (iface) {
        connect(new QDBusPendingCallWatcher(iface->Respond(command), iface),
            SIGNAL(finished(QDBusPendingCallWatcher*)),
            SLOT(respondResponseReceived(QDBusPendingCallWatcher*)));
    }
}

void QOfonoSupplementaryServices::cancel()
{
    OfonoSupplementaryServices *iface = (OfonoSupplementaryServices*)dbusInterface();
    if (iface) {
        connect(new QDBusPendingCallWatcher(iface->Cancel(), iface),
            SIGNAL(finished(QDBusPendingCallWatcher*)),
            SLOT(cancelResponseReceived(QDBusPendingCallWatcher*)));
    }
}

void QOfonoSupplementaryServices::propertyChanged(const QString &property, const QVariant &value)
{
    SUPER::propertyChanged(property, value);
    if (property == QLatin1String("State")) {
        Q_EMIT stateChanged(value.value<QString>());
    }
}

QString QOfonoSupplementaryServices::state() const
{
    return getString("State");
}

void QOfonoSupplementaryServices::initiateResponseReceived(QDBusPendingCallWatcher *call)
{
    call->deleteLater();
    QDBusPendingReply<QString, QDBusVariant> reply = *call;
    if (reply.isError()) {
        emit initiateFailed();
        return;
    }

    QString type = reply.value();
    if (type == QLatin1String("USSD")) {
        QString resp = qvariant_cast<QDBusVariant>(reply.argumentAt(1)).variant().toString();
        emit ussdResponse(resp);
    } else {
        QVariant val = qvariant_cast<QDBusVariant>(reply.argumentAt(1)).variant();
        const QDBusArgument arg = qvariant_cast<QDBusArgument>(val);

        if (type == QLatin1String("CallBarring")) {
            QString ss_op;
            QString cb_service;
            QVariantMap cb_dict;
            arg.beginStructure();
            arg >> ss_op >> cb_service >> cb_dict;
            arg.endStructure();
            emit callBarringResponse(ss_op, cb_service, cb_dict);
        } else if (type == QLatin1String("CallForwarding")) {
            QString ss_op;
            QString cf_service;
            QVariantMap cf_dict;
            arg.beginStructure();
            arg >> ss_op >> cf_service >> cf_dict;
            arg.endStructure();
            emit callForwardingResponse(ss_op, cf_service, cf_dict);
        } else if (type == QLatin1String("CallWaiting")) {
            QString ss_op;
            QVariantMap cw_dict;
            arg.beginStructure();
            arg >> ss_op >> cw_dict;
            arg.endStructure();
            emit callWaitingResponse(ss_op, cw_dict);
        } else if (type == QLatin1String("CallingLinePresentation")) {
            QString ss_op;
            QString status;
            arg.beginStructure();
            arg >> ss_op >> status;
            arg.endStructure();
            emit callingLinePresentationResponse(ss_op, status);
        } else if (type == QLatin1String("ConnectedLinePresentation")) {
            QString ss_op;
            QString status;
            arg.beginStructure();
            arg >> ss_op >> status;
            arg.endStructure();
            emit connectedLinePresentationResponse(ss_op, status);
        } else if (type == QLatin1String("CallingLineRestriction")) {
            QString ss_op;
            QString status;
            arg.beginStructure();
            arg >> ss_op >> status;
            arg.endStructure();
            emit callingLineRestrictionResponse(ss_op, status);
        } else if (type == QLatin1String("ConnectedLineRestriction")) {
            QString ss_op;
            QString status;
            arg.beginStructure();
            arg >> ss_op >> status;
            arg.endStructure();
            emit connectedLineRestrictionResponse(ss_op, status);
        } else {
            emit initiateFailed();
        }
    }
}

void QOfonoSupplementaryServices::respondResponseReceived(QDBusPendingCallWatcher *call)
{
    call->deleteLater();
    QDBusPendingReply<QString> reply = *call;
    Q_EMIT respondComplete(!reply.isError(), reply.value());
}

void QOfonoSupplementaryServices::cancelResponseReceived(QDBusPendingCallWatcher *call)
{
    call->deleteLater();
    QDBusPendingReply<> reply = *call;
    Q_EMIT cancelComplete(!reply.isError());
}

QString QOfonoSupplementaryServices::modemPath() const
{
    return SUPER::modemPath();
}

void QOfonoSupplementaryServices::setModemPath(const QString &path)
{
    SUPER::setModemPath(path);
}

bool QOfonoSupplementaryServices::isValid() const
{
    return SUPER::isValid();
}