[telepathy-qt4/master] PendingChannelRequest: Added initial PendingChannelRequest class.

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


---
 TelepathyQt4/Makefile.am                 |    4 +
 TelepathyQt4/PendingChannelRequest       |   13 ++
 TelepathyQt4/pending-channel-request.cpp |  181 ++++++++++++++++++++++++++++++
 TelepathyQt4/pending-channel-request.h   |   75 ++++++++++++
 4 files changed, 273 insertions(+), 0 deletions(-)
 create mode 100644 TelepathyQt4/PendingChannelRequest
 create mode 100644 TelepathyQt4/pending-channel-request.cpp
 create mode 100644 TelepathyQt4/pending-channel-request.h

diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index c92870a..d7b69ea 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -81,6 +81,7 @@ libtelepathy_qt4_la_SOURCES = \
     optional-interface-factory.cpp \
     pending-account.cpp \
     pending-channel.cpp \
+    pending-channel-request.cpp \
     pending-connection.cpp \
     pending-contact-attributes.cpp \
     pending-contacts.cpp \
@@ -144,6 +145,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     _gen/file-transfer.moc.hpp \
     _gen/pending-account.moc.hpp \
     _gen/pending-channel.moc.hpp \
+    _gen/pending-channel-request.moc.hpp \
     _gen/pending-connection.moc.hpp \
     _gen/pending-contact-attributes.moc.hpp \
     _gen/pending-contacts.moc.hpp \
@@ -190,6 +192,7 @@ tpqt4include_HEADERS = \
     OptionalInterfaceFactory \
     PendingAccount \
     PendingChannel \
+    PendingChannelRequest \
     PendingConnection \
     PendingContacts \
     PendingContactAttributes \
@@ -283,6 +286,7 @@ tpqt4include_HEADERS = \
     optional-interface-factory.h \
     pending-account.h \
     pending-channel.h \
+    pending-channel-request.h \
     pending-connection.h \
     pending-contact-attributes.h \
     pending-contacts.h \
diff --git a/TelepathyQt4/PendingChannelRequest b/TelepathyQt4/PendingChannelRequest
new file mode 100644
index 0000000..862acc4
--- /dev/null
+++ b/TelepathyQt4/PendingChannelRequest
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_Client_PendingChannelRequest_HEADER_GUARD_
+#define _TelepathyQt4_Client_PendingChannelRequest_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/pending-channel-request.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/pending-channel-request.cpp b/TelepathyQt4/pending-channel-request.cpp
new file mode 100644
index 0000000..a40bda7
--- /dev/null
+++ b/TelepathyQt4/pending-channel-request.cpp
@@ -0,0 +1,181 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 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
+ */
+
+#include <TelepathyQt4/PendingChannelRequest>
+
+#include "TelepathyQt4/_gen/pending-channel-request.moc.hpp"
+
+#include "TelepathyQt4/debug-internal.h"
+
+#include <TelepathyQt4/ChannelDispatcher>
+#include <TelepathyQt4/ChannelRequest>
+#include <TelepathyQt4/PendingReady>
+
+/**
+ * \addtogroup clientsideproxies Client-side proxies
+ *
+ * Proxy objects representing remote service objects accessed via D-Bus.
+ *
+ * In addition to providing direct access to methods, signals and properties
+ * exported by the remote objects, some of these proxies offer features like
+ * automatic inspection of remote object capabilities, property tracking,
+ * backwards compatibility helpers for older services and other utilities.
+ */
+
+namespace Tp
+{
+
+struct PendingChannelRequest::Private
+{
+    Private(const QDBusConnection &dbusConnection)
+        : dbusConnection(dbusConnection)
+    {
+    }
+
+    QDBusConnection dbusConnection;
+    ChannelRequestPtr channelRequest;
+};
+
+/**
+ * \class PendingChannelRequest
+ * \ingroup clientconn
+ * \headerfile <TelepathyQt4/pending-channel-request.h> <TelepathyQt4/PendingChannelRequest>
+ *
+ * Class containing the parameters of and the reply to an asynchronous
+ * ChannelRequest request. Instances of this class cannot be constructed
+ * directly; the only way to get one is trough Account.
+ */
+
+/**
+ * Construct a new PendingChannelRequest object.
+ *
+ * \param dbusConnection QDBusConnection to use.
+ * \param accountObjectPath Account object path.
+ * \param requestedProperties A dictionary containing the desirable properties.
+ * \param userActionTime The time at which user action occurred, or QDateTime()
+ *                       if this channel request is for some reason not
+ *                       involving user action.
+ * \param preferredHandler Either the well-known bus name (starting with
+ *                         org.freedesktop.Telepathy.Client.) of the preferred
+ *                         handler for this channel, or an empty string to
+ *                         indicate that any handler would be acceptable.
+ * \param create Whether createChannel or ensureChannel should be called.
+ * \param parent Parent object
+ */
+PendingChannelRequest::PendingChannelRequest(const QDBusConnection &dbusConnection,
+        const QString &accountObjectPath,
+        const QVariantMap &requestedProperties,
+        const QDateTime &userActionTime,
+        const QString &preferredHandler,
+        bool create,
+        QObject *parent)
+    : PendingOperation(parent),
+      mPriv(new Private(dbusConnection))
+{
+    QString channelDispatcherObjectPath =
+        QString("/%1").arg(TELEPATHY_INTERFACE_CHANNEL_DISPATCHER);
+    channelDispatcherObjectPath.replace('.', '/');
+    Client::ChannelDispatcherInterface *channelDispatcherInterface =
+        new Client::ChannelDispatcherInterface(mPriv->dbusConnection,
+                TELEPATHY_INTERFACE_CHANNEL_DISPATCHER,
+                channelDispatcherObjectPath,
+                this);
+    QDBusPendingCallWatcher *watcher;
+    if (create) {
+        watcher = new QDBusPendingCallWatcher(
+                channelDispatcherInterface->CreateChannel(
+                    QDBusObjectPath(accountObjectPath),
+                    requestedProperties,
+                    userActionTime.isNull() ? 0 : userActionTime.toTime_t(),
+                    preferredHandler), this);
+    }
+    else {
+        watcher = new QDBusPendingCallWatcher(
+                channelDispatcherInterface->EnsureChannel(
+                    QDBusObjectPath(accountObjectPath),
+                    requestedProperties,
+                    userActionTime.isNull() ? 0 : userActionTime.toTime_t(),
+                    preferredHandler), this);
+    }
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher *)),
+            SLOT(onWatcherFinished(QDBusPendingCallWatcher *)));
+}
+
+/**
+ * Class destructor.
+ */
+PendingChannelRequest::~PendingChannelRequest()
+{
+    delete mPriv;
+}
+
+ChannelRequestPtr PendingChannelRequest::channelRequest() const
+{
+    if (!isFinished()) {
+        warning() << "PendingChannelRequest::channelRequest called before "
+            "finished, returning 0";
+        return ChannelRequestPtr();
+    } else if (!isValid()) {
+        warning() << "PendingChannelRequest::channelRequest called when "
+            "not valid, returning 0";
+        return ChannelRequestPtr();
+    }
+
+    return mPriv->channelRequest;
+}
+
+void PendingChannelRequest::onWatcherFinished(QDBusPendingCallWatcher *watcher)
+{
+    QDBusPendingReply<QDBusObjectPath> reply = *watcher;
+
+    if (!reply.isError()) {
+        QDBusObjectPath objectPath = reply.argumentAt<0>();
+        debug() << "Got reply to ChannelDispatcher.Ensure/CreateChannel "
+            "- object path:" << objectPath.path();
+
+        mPriv->channelRequest = ChannelRequest::create(mPriv->dbusConnection,
+                objectPath.path(), QVariantMap());
+        connect(mPriv->channelRequest->becomeReady(),
+                SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onChannelRequestReady(Tp::PendingOperation*)));
+    } else {
+        debug().nospace() << "Ensure/CreateChannel failed:" <<
+            reply.error().name() << ": " << reply.error().message();
+        setFinishedWithError(reply.error());
+    }
+
+    watcher->deleteLater();
+}
+
+void PendingChannelRequest::onChannelRequestReady(PendingOperation *op)
+{
+    if (op->isError()) {
+        debug().nospace() << "Unable to make ChannelRequest object ready:" <<
+            op->errorName() << ": " << op->errorMessage();
+        setFinishedWithError(op->errorName(), op->errorMessage());
+        return;
+    }
+
+    setFinished();
+}
+
+} // Tp
diff --git a/TelepathyQt4/pending-channel-request.h b/TelepathyQt4/pending-channel-request.h
new file mode 100644
index 0000000..d2517a9
--- /dev/null
+++ b/TelepathyQt4/pending-channel-request.h
@@ -0,0 +1,75 @@
+/*
+ * 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_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_pending_channel_request_h_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#error IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/Types>
+
+#include <QDateTime>
+#include <QString>
+#include <QVariantMap>
+
+class QDBusPendingCallWatcher;
+
+namespace Tp
+{
+
+class Account;
+
+class PendingChannelRequest : public PendingOperation
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(PendingChannelRequest)
+
+public:
+    ~PendingChannelRequest();
+
+    ChannelRequestPtr channelRequest() const;
+
+private Q_SLOTS:
+    void onWatcherFinished(QDBusPendingCallWatcher *watcher);
+    void onChannelRequestReady(Tp::PendingOperation *op);
+
+private:
+    friend class Account;
+
+    PendingChannelRequest(const QDBusConnection &dbusConnection,
+            const QString &accountObjectPath,
+            const QVariantMap &requestedProperties,
+            const QDateTime &userActionTime,
+            const QString &preferredHandler,
+            bool create,
+            QObject *parent);
+
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
+} // Tp
+
+#endif
-- 
1.5.6.5




More information about the telepathy-commits mailing list