9#include "pendingcall.h"
10#include "bluezqt_dbustypes.h"
12#include "obexfiletransferentry.h"
13#include "obextransfer.h"
14#include "obextransfer_p.h"
16#include <QDBusPendingCallWatcher>
31#define FROM_BLUEZ_ERROR(string, value) \
32 if (errorName == QLatin1String(string)) { \
56#undef FROM_BLUEZ_ERROR
61class PendingCallPrivate :
public QObject
64 explicit PendingCallPrivate(PendingCall *
parent);
78 void emitDelayedFinished();
79 void emitInternalError(
const QString &errorText);
87 PendingCall::ReturnType m_type;
91PendingCallPrivate::PendingCallPrivate(PendingCall *parent)
95 , m_type(PendingCall::ReturnVoid)
103 case PendingCall::ReturnVoid:
104 processVoidReply(*call);
107 case PendingCall::ReturnUint32:
108 processUint32Reply(*call);
111 case PendingCall::ReturnString:
112 processStringReply(*call);
115 case PendingCall::ReturnStringList:
116 processStringListReply(*call);
119 case PendingCall::ReturnObjectPath:
120 processObjectPathReply(*call);
123 case PendingCall::ReturnFileTransferList:
124 processFileTransferListReply(*call);
127 case PendingCall::ReturnTransferWithProperties:
128 processTransferWithPropertiesReply(*call);
131 case PendingCall::ReturnByteArray:
132 processByteArrayReply(*call);
142 processError(reply.
error());
147 processError(reply.
error());
149 m_value.append(reply.
value());
155 processError(reply.
error());
157 m_value.append(reply.
value());
163 processError(reply.
error());
165 m_value.append(reply.
value());
171 processError(reply.
error());
179 processError(reply.
error());
183 const auto maps = reply.
value();
184 for (
const QVariantMap &map : maps) {
185 items.
append(ObexFileTransferEntry(map));
193 processError(reply.
error());
198 ObexTransferPtr transfer = ObexTransferPtr(
new ObexTransfer(reply.
argumentAt<0>().path(), reply.
argumentAt<1>()));
199 transfer->d->q = transfer.toWeakRef();
200 transfer->d->m_suspendable =
true;
206 processError(reply.
error());
212void PendingCallPrivate::processError(
const QDBusError &error)
214 if (
error.isValid()) {
215 qCWarning(BLUEZQT) <<
"PendingCall Error:" <<
error.message();
216 m_error = nameToError(
error.name());
217 m_errorText =
error.message();
221void PendingCallPrivate::emitFinished()
223 m_watcher->deleteLater();
225 Q_EMIT q->finished(q);
229void PendingCallPrivate::emitDelayedFinished()
231 Q_ASSERT(qobject_cast<QTimer *>(sender()));
233 Q_EMIT q->finished(q);
234 static_cast<QTimer *
>(sender())->deleteLater();
237void PendingCallPrivate::emitInternalError(
const QString &errorText)
239 qCWarning(BLUEZQT) <<
"PendingCall Internal error:" << errorText;
240 m_error = PendingCall::InternalError;
241 m_errorText = errorText;
247 processReply(watcher);
253 , d(new PendingCallPrivate(this))
255 qDBusRegisterMetaType<QVariantMapList>();
263PendingCall::PendingCall(PendingCall::Error error,
const QString &errorText,
QObject *parent)
265 , d(new PendingCallPrivate(this))
268 d->m_errorText = errorText;
278 , d(new PendingCallPrivate(this))
280 qDBusRegisterMetaType<QVariantMapList>();
284 externalProcessor(watcher, std::bind(&PendingCallPrivate::processError, d.get(), std::placeholders::_1), &d->m_value);
289PendingCall::~PendingCall() =
default;
293 if (d->m_value.isEmpty()) {
296 return d->m_value.first();
299QVariantList PendingCall::values()
const
304int PendingCall::error()
const
311 return d->m_errorText;
314bool PendingCall::isFinished()
const
317 return d->m_watcher->isFinished();
322void PendingCall::waitForFinished()
325 d->m_watcher->waitForFinished();
331 return d->m_userData;
334void PendingCall::setUserData(
const QVariant &userData)
336 d->m_userData = userData;
341#include "moc_pendingcall.cpp"
@ DoesNotExist
Indicates that an agent, service or pairing operation does not exists.
@ AlreadyExists
Indicates that an agent or pairing record already exists.
@ NotSupported
Indicates that the action is not supported.
@ ConnectionAttemptFailed
Indicates that the connection attempt have failed.
@ NotPermitted
Indicates that the action is not permitted (e.g.
@ ConnectFailed
Indicates that the connection to the device have failed.
@ NotReady
Indicates that the device is not ready.
@ AuthenticationCanceled
Indicates that the authentication was canceled.
@ AuthenticationTimeout
Indicates that the authentication timed out.
@ InvalidLength
Indicates that the data provided generates a data packet which is too long.
@ AuthenticationRejected
Indicates that the authentication was rejected.
@ Failed
Indicates that the action have failed.
@ InvalidArguments
Indicates that invalid arguments were passed.
@ AlreadyConnected
Indicates that the device is already connected.
@ UnknownError
Indicates an unknown error.
@ DBusError
Indicates an error with D-Bus.
@ NotAuthorized
Indicates that the caller is not authorized to do the action.
@ Rejected
Indicates that the action was rejected.
@ Canceled
Indicates that the action was canceled.
@ NotConnected
Indicates that the device is not connected.
@ AuthenticationFailed
Indicates that the authentication have failed.
Type type(const QSqlDatabase &db)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QString name(StandardShortcut id)
void finished(QDBusPendingCallWatcher *self)
QVariant argumentAt(int index) const const
QDBusError error() const const
bool isError() const const
typename Select< 0 >::Type value() const const
void append(QList< T > &&value)
void reserve(qsizetype size)
QObject * parent() const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setSingleShot(bool singleShot)
QVariant fromValue(T &&value)