ModemManagerQt

call.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Aleksander Morgado <aleksander@aleksander.es>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "call.h"
8#include "call_p.h"
9#include "mmdebug_p.h"
10
11#ifdef MMQT_STATIC
12#include "dbus/fakedbus.h"
13#else
14#include "dbus/dbus.h"
15#endif
16
17#include <ModemManager/ModemManager.h>
18
19ModemManager::CallPrivate::CallPrivate(const QString &path, Call *q)
20#ifdef MMQT_STATIC
21 : callIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
22#else
23 : callIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
24#endif
25 , q_ptr(q)
26{
27 if (callIface.isValid()) {
28 uni = path;
29 state = (MMCallState)callIface.state();
30 stateReason = (MMCallStateReason)callIface.stateReason();
31 direction = (MMCallDirection)callIface.direction();
32 number = callIface.number();
33 }
34}
35
36ModemManager::Call::Call(const QString &path, QObject *parent)
37 : QObject(parent)
38 , d_ptr(new CallPrivate(path, this))
39{
40 Q_D(Call);
41
42 qRegisterMetaType<MMCallState>();
43 qRegisterMetaType<MMCallStateReason>();
44 qRegisterMetaType<MMCallDirection>();
45
46#ifdef MMQT_STATIC
48 path,
49 QLatin1String(DBUS_INTERFACE_PROPS),
50 QStringLiteral("PropertiesChanged"),
51 d,
52 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
53#else
55 path,
56 QLatin1String(DBUS_INTERFACE_PROPS),
57 QStringLiteral("PropertiesChanged"),
58 d,
59 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
60#endif
61
62 connect(&d->callIface, &OrgFreedesktopModemManager1CallInterface::StateChanged, d, &CallPrivate::onStateChanged);
63 connect(&d->callIface, &OrgFreedesktopModemManager1CallInterface::DtmfReceived, d, &CallPrivate::onDtmfReceived);
64}
65
66ModemManager::Call::~Call()
67{
68 delete d_ptr;
69}
70
71QString ModemManager::Call::uni() const
72{
73 Q_D(const Call);
74 return d->uni;
75}
76
78{
79 Q_D(Call);
80 return d->callIface.Start();
81}
82
84{
85 Q_D(Call);
86 return d->callIface.Accept();
87}
88
90{
91 Q_D(Call);
92 return d->callIface.Hangup();
93}
94
96{
97 Q_D(Call);
98 return d->callIface.SendDtmf(dtmf);
99}
100
101MMCallState ModemManager::Call::state() const
102{
103 Q_D(const Call);
104 return d->state;
105}
106
107MMCallStateReason ModemManager::Call::stateReason() const
108{
109 Q_D(const Call);
110 return d->stateReason;
111}
112
113MMCallDirection ModemManager::Call::direction() const
114{
115 Q_D(const Call);
116 return d->direction;
117}
118
120{
121 Q_D(const Call);
122 return d->number;
123}
124
126{
127 Q_D(Call);
128 d->callIface.setTimeout(timeout);
129}
130
132{
133 Q_D(const Call);
134 return d->callIface.timeout();
135}
136
137void ModemManager::CallPrivate::onStateChanged(int oldState, int newState, uint reason)
138{
139 Q_Q(Call);
140 state = (MMCallState)newState;
141 stateReason = (MMCallStateReason)reason;
142 Q_EMIT q->stateChanged((MMCallState)oldState, (MMCallState)newState, (MMCallStateReason)reason);
143}
144
145void ModemManager::CallPrivate::onDtmfReceived(const QString &dtmf)
146{
147 Q_Q(Call);
148 Q_EMIT q->dtmfReceived(dtmf);
149}
150
151void ModemManager::CallPrivate::onPropertiesChanged(const QString &interfaceName,
152 const QVariantMap &changedProperties,
153 const QStringList &invalidatedProperties)
154{
155 Q_UNUSED(invalidatedProperties);
156 Q_Q(Call);
157
158 if (interfaceName == QLatin1String(MMQT_DBUS_INTERFACE_CALL)) {
159 QVariantMap::const_iterator it = changedProperties.constFind(QLatin1String(MM_CALL_PROPERTY_NUMBER));
160 if (it != changedProperties.constEnd()) {
161 number = it->toString();
162 Q_EMIT q->numberChanged(number);
163 }
164 }
165}
166
167#include "moc_call.cpp"
168#include "moc_call_p.cpp"
Provides an interface to manipulate and control a call.
Definition call.h:29
MMCallStateReason stateReason() const
This method returns the reason for the call state change.
Definition call.cpp:107
QDBusPendingReply start()
Start a call.
Definition call.cpp:77
QDBusPendingReply sendDtmf(const QString &dtmf)
Send DTMF.
Definition call.cpp:95
QString number() const
This method returns the remote phone number.
Definition call.cpp:119
MMCallState state() const
This method returns the state of the call.
Definition call.cpp:101
QDBusPendingReply hangup()
Hangup a call.
Definition call.cpp:89
MMCallDirection direction() const
This method returns the direction of the call.
Definition call.cpp:113
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
Definition call.cpp:131
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
Definition call.cpp:125
QDBusPendingReply accept()
Accept a call.
Definition call.cpp:83
KIOCORE_EXPORT QString number(KIO::filesize_t size)
QString path(const QString &relativePath)
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QString number(double n, char format, int precision)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.