diff options
author | Olli Salli <ollisal@gmail.com> | 2010-12-30 20:41:50 +0200 |
---|---|---|
committer | Olli Salli <ollisal@gmail.com> | 2010-12-31 16:35:01 +0200 |
commit | 37b8e3197c7455c79df6d83810bfdc2e612bc5a1 (patch) | |
tree | aaa23f79b57a3efd30a8fd2a889cac90468adbd5 | |
parent | 484fa9bf1d9aa5cc1ad77a757196f938f355568c (diff) |
Add Channel::requestLeave for gracefully leaving channels
-rw-r--r-- | TelepathyQt4/channel.cpp | 46 | ||||
-rw-r--r-- | TelepathyQt4/channel.h | 2 |
2 files changed, 48 insertions, 0 deletions
diff --git a/TelepathyQt4/channel.cpp b/TelepathyQt4/channel.cpp index dd2d5562..a8c815c6 100644 --- a/TelepathyQt4/channel.cpp +++ b/TelepathyQt4/channel.cpp @@ -1556,6 +1556,52 @@ PendingOperation *Channel::requestClose() } /** + * Start an asynchronous request to leave this channel as gracefully as possible. + * + * If leaving any more gracefully is not possible, this will revert to the same as requestClose. In + * particular, this will be the case for channels with no Group interface + * (TP_QT4_IFACE_CHANNEL_INTERFACE_GROUP not in the list returned by interfaces()). + * + * The returned PendingOperation object will signal the success or failure + * of this request; under normal circumstances, it can be expected to + * succeed. + * + * A message and a reason may be provided along with the request, which will be sent to the server + * if supported, which is indicated by ChannelGroupFlagMessageDepart and/or + * ChannelGroupFlagMessageReject. + * + * \param message The message, which can be blank if desired. + * \param reason A reason for leaving. + * \return A PendingOperation, which will emit PendingOperation::finished + * when the call has finished. + */ +PendingOperation *Channel::requestLeave(const QString &message, ChannelGroupChangeReason reason) +{ + // Leaving a channel does not make sense if it is already closed, + // just silently Return. + if (!isValid()) { + return new PendingSuccess(ChannelPtr(this)); + } + + if (!isReady(Channel::FeatureCore)) { + return new PendingFailure(TP_QT4_ERROR_NOT_AVAILABLE, + QLatin1String("Channel::FeatureCore must be ready to leave a channel"), + ChannelPtr(this)); + } + + if (!interfaces().contains(TP_QT4_IFACE_CHANNEL_INTERFACE_GROUP)) { + return requestClose(); + } + + // TODO: use PendingLeave which handles errors correctly by falling back to Close + return new PendingVoid(mPriv->group->RemoveMembersWithReason( + UIntList() << mPriv->groupSelfHandle, + message, + reason), + ChannelPtr(this)); +} + +/** * \name Group interface * * Cached access to state of the group interface on the associated remote diff --git a/TelepathyQt4/channel.h b/TelepathyQt4/channel.h index eb10e581..f638b025 100644 --- a/TelepathyQt4/channel.h +++ b/TelepathyQt4/channel.h @@ -75,6 +75,8 @@ public: ContactPtr initiatorContact() const; PendingOperation *requestClose(); + PendingOperation *requestLeave(const QString &message = QString(), + ChannelGroupChangeReason reason = ChannelGroupChangeReasonNone); ChannelGroupFlags groupFlags() const; |