Skip to content

Commit 2263a64

Browse files
committed
BaseConnection: Changed API (createChannel(), ensureChannel()).
Refactored out excess of createChannel()/ensureChannel() signatures. Fixed "Requested" property for the created channel.
1 parent 0a8d52d commit 2263a64

File tree

2 files changed

+34
-66
lines changed

2 files changed

+34
-66
lines changed

TelepathyQt/base-connection.cpp

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,14 @@ void BaseConnection::Adaptee::requestChannel(const QString &type, uint handleTyp
147147
{
148148
debug() << "BaseConnection::Adaptee::requestChannel (deprecated)";
149149
DBusError error;
150+
151+
QVariantMap request;
152+
request[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")] = type;
153+
request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")] = handleType;
154+
request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")] = handle;
155+
150156
bool yours;
151-
BaseChannelPtr channel = mConnection->ensureChannel(type,
152-
handleType,
153-
handle,
154-
yours,
155-
selfHandle(),
156-
suppressHandler,
157-
QVariantMap(),
158-
&error);
157+
BaseChannelPtr channel = mConnection->ensureChannel(request, yours, suppressHandler, &error);
159158
if (error.isValid() || !channel) {
160159
context->setFinishedWithError(error.name(), error.message());
161160
return;
@@ -285,13 +284,7 @@ void BaseConnection::setCreateChannelCallback(const CreateChannelCallback &cb)
285284
mPriv->createChannelCB = cb;
286285
}
287286

288-
Tp::BaseChannelPtr BaseConnection::createChannel(const QString &channelType,
289-
uint targetHandleType,
290-
uint targetHandle,
291-
uint initiatorHandle,
292-
bool suppressHandler,
293-
const QVariantMap &request,
294-
DBusError *error)
287+
Tp::BaseChannelPtr BaseConnection::createChannel(const QVariantMap &request, bool suppressHandler, DBusError *error)
295288
{
296289
if (!mPriv->createChannelCB.isValid()) {
297290
error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
@@ -302,36 +295,40 @@ Tp::BaseChannelPtr BaseConnection::createChannel(const QString &channelType,
302295
return BaseChannelPtr();
303296
}
304297

305-
BaseChannelPtr channel = mPriv->createChannelCB(channelType, targetHandleType, targetHandle, request, error);
298+
BaseChannelPtr channel = mPriv->createChannelCB(request, error);
306299
if (error->isValid())
307300
return BaseChannelPtr();
308301

309302
QString targetID;
310-
if (targetHandle != 0) {
311-
QStringList list = mPriv->inspectHandlesCB(targetHandleType, UIntList() << targetHandle, error);
303+
if (channel->targetHandle() != 0) {
304+
QStringList list = mPriv->inspectHandlesCB(channel->targetHandleType(), UIntList() << channel->targetHandle(), error);
312305
if (error->isValid()) {
313-
debug() << "BaseConnection::createChannel: could not resolve handle " << targetHandle;
306+
debug() << "BaseConnection::createChannel: could not resolve handle " << channel->targetHandle();
314307
return BaseChannelPtr();
315308
} else {
316309
debug() << "BaseConnection::createChannel: found targetID " << *list.begin();
317310
targetID = *list.begin();
318311
}
319312
}
313+
314+
if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".InitiatorHandle"))) {
315+
channel->setInitiatorHandle(request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".InitiatorHandle")).toUInt());
316+
}
317+
320318
QString initiatorID;
321-
if (initiatorHandle != 0) {
322-
QStringList list = mPriv->inspectHandlesCB(HandleTypeContact, UIntList() << initiatorHandle, error);
319+
if (channel->initiatorHandle() != 0) {
320+
QStringList list = mPriv->inspectHandlesCB(HandleTypeContact, UIntList() << channel->initiatorHandle(), error);
323321
if (error->isValid()) {
324-
debug() << "BaseConnection::createChannel: could not resolve handle " << initiatorHandle;
322+
debug() << "BaseConnection::createChannel: could not resolve handle " << channel->initiatorHandle();
325323
return BaseChannelPtr();
326324
} else {
327325
debug() << "BaseConnection::createChannel: found initiatorID " << *list.begin();
328326
initiatorID = *list.begin();
329327
}
330328
}
331-
channel->setInitiatorHandle(initiatorHandle);
332329
channel->setInitiatorID(initiatorID);
333330
channel->setTargetID(targetID);
334-
channel->setRequested(suppressHandler);
331+
channel->setRequested(request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".Requested"), suppressHandler).toBool());
335332

336333
channel->registerObject(error);
337334
if (error->isValid())
@@ -403,12 +400,12 @@ Tp::ChannelDetailsList BaseConnection::channelsDetails()
403400
return list;
404401
}
405402

406-
BaseChannelPtr BaseConnection::ensureChannel(const QString &channelType, uint targetHandleType,
407-
uint targetHandle, bool &yours, uint initiatorHandle,
408-
bool suppressHandler,
409-
const QVariantMap &request,
410-
DBusError* error)
403+
Tp::BaseChannelPtr BaseConnection::ensureChannel(const QVariantMap &request, bool &yours, bool suppressHandler, DBusError *error)
411404
{
405+
const QString channelType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")).toString();
406+
uint targetHandleType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")).toUInt();
407+
uint targetHandle = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")).toUInt();
408+
412409
foreach(BaseChannelPtr channel, mPriv->channels) {
413410
if (channel->channelType() == channelType
414411
&& channel->targetHandleType() == targetHandleType
@@ -417,8 +414,9 @@ BaseChannelPtr BaseConnection::ensureChannel(const QString &channelType, uint ta
417414
return channel;
418415
}
419416
}
417+
420418
yours = true;
421-
return createChannel(channelType, targetHandleType, targetHandle, initiatorHandle, suppressHandler, request, error);
419+
return createChannel(request, suppressHandler, error);
422420
}
423421

424422
void BaseConnection::addChannel(BaseChannelPtr channel)
@@ -765,28 +763,8 @@ void BaseConnectionRequestsInterface::ensureChannel(const QVariantMap &request,
765763
return;
766764
}
767765

768-
QString channelType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")].toString();
769-
uint targetHandleType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")].toUInt();
770-
uint targetHandle;
771-
if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")))
772-
targetHandle = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")].toUInt();
773-
else {
774-
QString targetID = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetID")].toString();
775-
Tp::UIntList list = mPriv->connection->requestHandles(targetHandleType, QStringList() << targetID, error);
776-
if (error->isValid()) {
777-
warning() << "BBaseConnectionRequestsInterface::ensureChannel: could not resolve ID " << targetID;
778-
return;
779-
}
780-
targetHandle = *list.begin();
781-
}
766+
BaseChannelPtr channel = mPriv->connection->ensureChannel(request, yours, /* suppressHandler */ true, error);
782767

783-
bool suppressHandler = true;
784-
BaseChannelPtr channel = mPriv->connection->ensureChannel(channelType, targetHandleType,
785-
targetHandle, yours,
786-
mPriv->connection->selfHandle(),
787-
suppressHandler,
788-
request,
789-
error);
790768
if (error->isValid())
791769
return;
792770

@@ -803,25 +781,15 @@ void BaseConnectionRequestsInterface::createChannel(const QVariantMap &request,
803781
return;
804782
}
805783

806-
QString channelType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")].toString();
807-
uint targetHandleType = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")].toUInt();
808-
uint targetHandle = request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")].toUInt();
784+
BaseChannelPtr channel = mPriv->connection->createChannel(request, /* yours */ false, error);
809785

810-
bool suppressHandler = true;
811-
BaseChannelPtr channel = mPriv->connection->createChannel(channelType, targetHandleType,
812-
targetHandle,
813-
mPriv->connection->selfHandle(),
814-
suppressHandler,
815-
request,
816-
error);
817786
if (error->isValid())
818787
return;
819788

820789
objectPath = QDBusObjectPath(channel->objectPath());
821790
details = channel->details().properties;
822791
}
823792

824-
825793
// Conn.I.Contacts
826794
BaseConnectionContactsInterface::Adaptee::Adaptee(BaseConnectionContactsInterface *interface)
827795
: QObject(interface),

TelepathyQt/base-connection.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ class TP_QT_EXPORT BaseConnection : public DBusService
8282

8383
void setStatus(uint newStatus, uint reason);
8484

85-
typedef Callback5<BaseChannelPtr, const QString&, uint, uint, const QVariantMap&, DBusError*> CreateChannelCallback;
85+
typedef Callback2<BaseChannelPtr, const QVariantMap &, DBusError*> CreateChannelCallback;
8686
void setCreateChannelCallback(const CreateChannelCallback &cb);
87-
Tp::BaseChannelPtr createChannel(const QString &channelType, uint targetHandleType, uint targetHandle, uint initiatorHandle, bool suppressHandler, const QVariantMap &request, DBusError *error);
87+
BaseChannelPtr createChannel(const QVariantMap &request, bool suppressHandler, DBusError *error);
8888

8989
typedef Callback3<UIntList, uint, const QStringList&, DBusError*> RequestHandlesCallback;
9090
void setRequestHandlesCallback(const RequestHandlesCallback &cb);
@@ -105,8 +105,8 @@ class TP_QT_EXPORT BaseConnection : public DBusService
105105
Tp::ChannelInfoList channelsInfo();
106106
Tp::ChannelDetailsList channelsDetails();
107107

108-
BaseChannelPtr ensureChannel(const QString &channelType, uint targetHandleType,
109-
uint targetHandle, bool &yours, uint initiatorHandle, bool suppressHandler, const QVariantMap &request, DBusError *error);
108+
BaseChannelPtr ensureChannel(const QVariantMap &request, bool &yours, bool suppressHandler, DBusError *error);
109+
110110
void addChannel(BaseChannelPtr channel);
111111

112112
QList<AbstractConnectionInterfacePtr> interfaces() const;

0 commit comments

Comments
 (0)