[telepathy-qt4/master] PendingChannelRequest: Added helper cancel method.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Thu Jun 11 07:50:27 PDT 2009


---
 TelepathyQt4/Makefile.am                        |    2 +
 TelepathyQt4/pending-channel-request-internal.h |   68 +++++++++++++++++++++++
 TelepathyQt4/pending-channel-request.cpp        |   20 +++++++
 TelepathyQt4/pending-channel-request.h          |    2 +
 4 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100644 TelepathyQt4/pending-channel-request-internal.h

diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index d7b69ea..8ac3565 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -82,6 +82,7 @@ libtelepathy_qt4_la_SOURCES = \
     pending-account.cpp \
     pending-channel.cpp \
     pending-channel-request.cpp \
+    pending-channel-request-internal.h \
     pending-connection.cpp \
     pending-contact-attributes.cpp \
     pending-contacts.cpp \
@@ -146,6 +147,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     _gen/pending-account.moc.hpp \
     _gen/pending-channel.moc.hpp \
     _gen/pending-channel-request.moc.hpp \
+    _gen/pending-channel-request-internal.moc.hpp \
     _gen/pending-connection.moc.hpp \
     _gen/pending-contact-attributes.moc.hpp \
     _gen/pending-contacts.moc.hpp \
diff --git a/TelepathyQt4/pending-channel-request-internal.h b/TelepathyQt4/pending-channel-request-internal.h
new file mode 100644
index 0000000..b69beb3
--- /dev/null
+++ b/TelepathyQt4/pending-channel-request-internal.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _TelepathyQt4_cli_pending_channel_request_internal_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_pending_channel_request_internal_h_HEADER_GUARD_
+
+#include <TelepathyQt4/ChannelRequest>
+#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/Types>
+
+namespace Tp
+{
+
+class PendingChannelRequestCancelOperation : public PendingOperation
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(PendingChannelRequestCancelOperation)
+
+public:
+    PendingChannelRequestCancelOperation(
+            const ChannelRequestPtr &channelRequest)
+        : PendingOperation(channelRequest.data())
+    {
+        mPendingOperation = channelRequest->cancel();
+        connect(mPendingOperation,
+                SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onCancelOperationFinished(Tp::PendingOperation*)));
+    }
+
+    ~PendingChannelRequestCancelOperation()
+    {
+    }
+
+private Q_SLOTS:
+    void onCancelOperationFinished(Tp::PendingOperation *op)
+    {
+        if (op->isError()) {
+            setFinishedWithError(op->errorName(), op->errorMessage());
+            return;
+        }
+        setFinished();
+    }
+
+private:
+    PendingOperation *mPendingOperation;
+};
+
+} // Tp
+
+#endif
diff --git a/TelepathyQt4/pending-channel-request.cpp b/TelepathyQt4/pending-channel-request.cpp
index a40bda7..983fd7d 100644
--- a/TelepathyQt4/pending-channel-request.cpp
+++ b/TelepathyQt4/pending-channel-request.cpp
@@ -20,8 +20,10 @@
  */
 
 #include <TelepathyQt4/PendingChannelRequest>
+#include "TelepathyQt4/pending-channel-request-internal.h"
 
 #include "TelepathyQt4/_gen/pending-channel-request.moc.hpp"
+#include "TelepathyQt4/_gen/pending-channel-request-internal.moc.hpp"
 
 #include "TelepathyQt4/debug-internal.h"
 
@@ -143,6 +145,24 @@ ChannelRequestPtr PendingChannelRequest::channelRequest() const
     return mPriv->channelRequest;
 }
 
+PendingOperation *PendingChannelRequest::cancel()
+{
+    if (!isFinished()) {
+        warning() << "PendingChannelRequest::cancel called before "
+            "finished, returning 0";
+        return 0;
+    } else if (!isValid()) {
+        warning() << "PendingChannelRequest::cancel called when "
+            "not valid, returning 0";
+        return 0;
+    }
+
+    // PendingChannelRequestCancelOperation will hold a reference to
+    // ChannelRequest so it does not get deleted even if this PendingOperation
+    // gets deleted.
+    return new PendingChannelRequestCancelOperation(mPriv->channelRequest);
+}
+
 void PendingChannelRequest::onWatcherFinished(QDBusPendingCallWatcher *watcher)
 {
     QDBusPendingReply<QDBusObjectPath> reply = *watcher;
diff --git a/TelepathyQt4/pending-channel-request.h b/TelepathyQt4/pending-channel-request.h
index d2517a9..60aff18 100644
--- a/TelepathyQt4/pending-channel-request.h
+++ b/TelepathyQt4/pending-channel-request.h
@@ -50,6 +50,8 @@ public:
 
     ChannelRequestPtr channelRequest() const;
 
+    PendingOperation *cancel();
+
 private Q_SLOTS:
     void onWatcherFinished(QDBusPendingCallWatcher *watcher);
     void onChannelRequestReady(Tp::PendingOperation *op);
-- 
1.5.6.5




More information about the telepathy-commits mailing list