[telepathy-qt4/master] ChannelRequest: Added ChannelRequest high-level class.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue May 19 06:49:08 PDT 2009


---
 TelepathyQt4/ChannelRequest          |   13 ++
 TelepathyQt4/ChannelRequestInterface |   13 ++
 TelepathyQt4/Makefile.am             |   14 ++
 TelepathyQt4/channel-request.cpp     |  310 ++++++++++++++++++++++++++++++++++
 TelepathyQt4/channel-request.h       |  122 +++++++++++++
 TelepathyQt4/channel-request.xml     |    9 +
 TelepathyQt4/stable-interfaces.xml   |    1 +
 TelepathyQt4/types.h                 |    2 +
 8 files changed, 484 insertions(+), 0 deletions(-)
 create mode 100644 TelepathyQt4/ChannelRequest
 create mode 100644 TelepathyQt4/ChannelRequestInterface
 create mode 100644 TelepathyQt4/channel-request.cpp
 create mode 100644 TelepathyQt4/channel-request.h
 create mode 100644 TelepathyQt4/channel-request.xml

diff --git a/TelepathyQt4/ChannelRequest b/TelepathyQt4/ChannelRequest
new file mode 100644
index 0000000..9fb2379
--- /dev/null
+++ b/TelepathyQt4/ChannelRequest
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_Client_ChannelRequest_HEADER_GUARD_
+#define _TelepathyQt4_Client_ChannelRequest_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/channel-request.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/ChannelRequestInterface b/TelepathyQt4/ChannelRequestInterface
new file mode 100644
index 0000000..cfa2d2d
--- /dev/null
+++ b/TelepathyQt4/ChannelRequestInterface
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_Client_ChannelRequestInterface_HEADER_GUARD_
+#define _TelepathyQt4_Client_ChannelRequestInterface_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/channel-request.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index fc29170..965c76f 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -18,6 +18,7 @@ EXTRA_DIST = \
     account-manager.xml \
     async-model.dox \
     channel.xml \
+    channel-request.xml \
     connection.xml \
     connection-manager.xml \
     dbus.xml \
@@ -49,6 +50,7 @@ libtelepathy_qt4_la_SOURCES = \
     account.cpp \
     account-manager.cpp \
     channel.cpp \
+    channel-request.cpp \
     client-registrar.cpp \
     client-registrar-internal.h \
     connection.cpp \
@@ -95,6 +97,8 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     _gen/cli-account-manager.moc.hpp \
     _gen/cli-channel-body.hpp \
     _gen/cli-channel.moc.hpp \
+    _gen/cli-channel-request-body.hpp \
+    _gen/cli-channel-request.moc.hpp \
     _gen/cli-connection-body.hpp \
     _gen/cli-connection.moc.hpp \
     _gen/cli-connection-manager-body.hpp \
@@ -113,6 +117,8 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     _gen/account.moc.hpp \
     _gen/account-manager.moc.hpp \
     _gen/channel.moc.hpp \
+    _gen/channel-request.moc.hpp \
+    _gen/client-registrar.moc.hpp \
     _gen/client-registrar-internal.moc.hpp \
     _gen/connection.moc.hpp \
     _gen/connection-manager.moc.hpp \
@@ -145,6 +151,7 @@ tpqt4include_HEADERS = \
     Account \
     AccountManager \
     Channel \
+    ChannelRequest \
     ClientRegistrar \
     Connection \
     ConnectionManager \
@@ -200,6 +207,7 @@ tpqt4include_HEADERS = \
     ChannelInterfaceHoldInterface \
     ChannelInterfaceMediaSignallingInterface \
     ChannelInterfacePasswordInterface \
+    ChannelRequestInterface \
     ChannelTypeContactListInterface \
     ChannelTypeRoomListInterface \
     ChannelTypeStreamedMediaInterface \
@@ -226,6 +234,7 @@ tpqt4include_HEADERS = \
     account.h \
     account-manager.h \
     channel.h \
+    channel-request.h \
     client-registrar.h \
     connection.h \
     connection-manager.h \
@@ -268,6 +277,7 @@ nodist_geninclude_HEADERS = \
     _gen/cli-account.h \
     _gen/cli-account-manager.h \
     _gen/cli-channel.h \
+    _gen/cli-channel-request.h \
     _gen/cli-connection.h \
     _gen/cli-connection-manager.h \
     _gen/cli-dbus.h \
@@ -366,6 +376,10 @@ _gen/cli-%.h _gen/cli-%-body.hpp: _gen/spec-%.xml \
 			group='clientchannel'; \
 			prettyinclude='Channel'; \
 			mainiface='--mainiface=Tp::Client::ChannelInterface';; \
+		channel-request) \
+			group='clientchannelrequest'; \
+			prettyinclude='ChannelRequest'; \
+			mainiface='--mainiface=Tp::Client::ChannelRequestInterface';; \
 		account) \
 			group='clientaccount'; \
 			prettyinclude='AccountManager'; \
diff --git a/TelepathyQt4/channel-request.cpp b/TelepathyQt4/channel-request.cpp
new file mode 100644
index 0000000..abc3d0d
--- /dev/null
+++ b/TelepathyQt4/channel-request.cpp
@@ -0,0 +1,310 @@
+/*
+ * 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/ChannelRequest>
+
+#include "TelepathyQt4/_gen/cli-channel-request-body.hpp"
+#include "TelepathyQt4/_gen/cli-channel-request.moc.hpp"
+#include "TelepathyQt4/_gen/channel-request.moc.hpp"
+
+#include "TelepathyQt4/debug-internal.h"
+
+#include <TelepathyQt4/Account>
+#include <TelepathyQt4/PendingFailure>
+#include <TelepathyQt4/PendingReady>
+#include <TelepathyQt4/PendingVoidMethodCall>
+
+#include <QDateTime>
+
+/**
+ * \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.
+ */
+
+/**
+ * \defgroup clientchannelrequest ChannelRequest proxies
+ * \ingroup clientsideproxies
+ *
+ * Proxy objects representing remote Telepathy Channel Requests and their
+ * optional interfaces.
+ */
+
+namespace Tp
+{
+
+struct ChannelRequest::Private
+{
+    Private(ChannelRequest *parent);
+    ~Private();
+
+    static void introspectMain(Private *self);
+
+    // Public object
+    ChannelRequest *parent;
+
+    // Instance of generated interface class
+    Client::ChannelRequestInterface *baseInterface;
+
+    // Optional interface proxies
+    Client::DBus::PropertiesInterface *properties;
+
+    ReadinessHelper *readinessHelper;
+
+    // Introspection
+    QStringList interfaces;
+    AccountPtr account;
+    QDateTime userActionTime;
+    QString preferredHandler;
+    QualifiedPropertyValueMapList requests;
+};
+
+ChannelRequest::Private::Private(ChannelRequest *parent)
+    : parent(parent),
+      baseInterface(new Client::ChannelRequestInterface(
+                    parent->dbusConnection(), parent->busName(),
+                    parent->objectPath(), parent)),
+      properties(0),
+      readinessHelper(parent->readinessHelper())
+{
+    debug() << "Creating new ChannelRequest:" << parent->objectPath();
+
+    ReadinessHelper::Introspectables introspectables;
+
+    // As ChannelRequest does not have predefined statuses let's simulate one (0)
+    ReadinessHelper::Introspectable introspectableCore(
+        QSet<uint>() << 0,                                           // makesSenseForStatuses
+        Features(),                                                  // dependsOnFeatures
+        QStringList(),                                               // dependsOnInterfaces
+        (ReadinessHelper::IntrospectFunc) &Private::introspectMain,
+        this);
+    introspectables[FeatureCore] = introspectableCore;
+
+    readinessHelper->addIntrospectables(introspectables);
+    readinessHelper->becomeReady(Features() << FeatureCore);
+}
+
+ChannelRequest::Private::~Private()
+{
+}
+
+void ChannelRequest::Private::introspectMain(ChannelRequest::Private *self)
+{
+    if (!self->properties) {
+        self->properties = self->parent->propertiesInterface();
+        Q_ASSERT(self->properties != 0);
+    }
+
+    connect(self->baseInterface,
+            SIGNAL(failed(const QString &, const QString &)),
+            self->parent,
+            SIGNAL(failed(const QString &, const QString &)));
+    connect(self->baseInterface,
+            SIGNAL(Succeeded()),
+            self->parent,
+            SIGNAL(succeeded()));
+
+    debug() << "Calling Properties::GetAll(ChannelRequest)";
+    QDBusPendingCallWatcher *watcher =
+        new QDBusPendingCallWatcher(
+                self->properties->GetAll(TELEPATHY_INTERFACE_CHANNEL_REQUEST),
+                self->parent);
+    self->parent->connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher*)),
+            SLOT(gotMainProperties(QDBusPendingCallWatcher*)));
+}
+
+/**
+ * \class ChannelRequest
+ * \ingroup clientchannelrequest
+ * \headerfile <TelepathyQt4/channel-request.h> <TelepathyQt4/ChannelRequest>
+ *
+ * High-level proxy object for accessing remote Telepathy ChannelRequest objects.
+ */
+
+const Feature ChannelRequest::FeatureCore = Feature(ChannelRequest::staticMetaObject.className(), 0, true);
+
+ChannelRequestPtr ChannelRequest::create(const QString &objectPath,
+        const QVariantMap &immutableProperties)
+{
+    return ChannelRequestPtr(new ChannelRequest(objectPath,
+                immutableProperties));
+}
+
+ChannelRequestPtr ChannelRequest::create(const QDBusConnection &bus,
+        const QString &objectPath, const QVariantMap &immutableProperties)
+{
+    return ChannelRequestPtr(new ChannelRequest(bus, objectPath,
+                immutableProperties));
+}
+
+ChannelRequest::ChannelRequest(const QString &objectPath,
+        const QVariantMap &immutableProperties)
+    : StatefulDBusProxy(QDBusConnection::sessionBus(),
+            "org.freedesktop.Telepathy.ChannelDispatcher",
+            objectPath),
+      OptionalInterfaceFactory<ChannelRequest>(this),
+      ReadyObject(this, FeatureCore),
+      mPriv(new Private(this))
+{
+    // FIXME: remember the immutableProperties, and use them to reduce the
+    // number of D-Bus calls we need to make (but we should make at least
+    // one, to check that the channel request does in fact exist)
+}
+
+ChannelRequest::ChannelRequest(const QDBusConnection &bus,
+        const QString &objectPath, const QVariantMap &immutableProperties)
+    : StatefulDBusProxy(bus,
+            "org.freedesktop.Telepathy.ChannelDispatcher",
+            objectPath),
+      OptionalInterfaceFactory<ChannelRequest>(this),
+      ReadyObject(this, FeatureCore),
+      mPriv(new Private(this))
+{
+    // FIXME: remember the immutableProperties, and use them to reduce the
+    // number of D-Bus calls we need to make (but we should make at least
+    // one, to check that the channel request does in fact exist)
+}
+
+/**
+ * Class destructor.
+ */
+ChannelRequest::~ChannelRequest()
+{
+    delete mPriv;
+}
+
+QStringList ChannelRequest::interfaces() const
+{
+    if (!isReady()) {
+        warning() << "ChannelRequest::interfaces() used channel request not ready";
+    }
+    return mPriv->interfaces;
+}
+
+AccountPtr ChannelRequest::account() const
+{
+    if (!isReady()) {
+        warning() << "ChannelRequest::account() used channel request not ready";
+    }
+    return mPriv->account;
+}
+
+QDateTime ChannelRequest::userActionTime() const
+{
+    if (!isReady()) {
+        warning() << "ChannelRequest::userActionTime() used channel request not ready";
+    }
+    return mPriv->userActionTime;
+}
+
+QString ChannelRequest::preferredHandler() const
+{
+    if (!isReady()) {
+        warning() << "ChannelRequest::preferredHandler() used channel request not ready";
+    }
+    return mPriv->preferredHandler;
+}
+
+QualifiedPropertyValueMapList ChannelRequest::requests() const
+{
+    if (!isReady()) {
+        warning() << "ChannelRequest::requests() used channel request not ready";
+    }
+    return mPriv->requests;
+}
+
+PendingOperation *ChannelRequest::cancel()
+{
+    if (!isReady()) {
+        return new PendingFailure(this, TELEPATHY_ERROR_NOT_AVAILABLE,
+                "ChannelRequest not ready");
+    }
+
+    return new PendingVoidMethodCall(this, mPriv->baseInterface->Cancel());
+}
+
+/**
+ * Get the ChannelRequestInterface for this ChannelRequest class. This method is
+ * protected since the convenience methods provided by this class should
+ * always be used instead of the interface by users of the class.
+ *
+ * \return A pointer to the existing ChannelRequestInterface for this
+ *         ChannelRequest
+ */
+Client::ChannelRequestInterface *ChannelRequest::baseInterface() const
+{
+    return mPriv->baseInterface;
+}
+
+void ChannelRequest::gotMainProperties(QDBusPendingCallWatcher *watcher)
+{
+    QDBusPendingReply<QVariantMap> reply = *watcher;
+    QVariantMap props;
+
+    if (!reply.isError()) {
+        debug() << "Got reply to Properties::GetAll(ChannelRequest)";
+        props = reply.value();
+
+        mPriv->interfaces = qdbus_cast<QStringList>(props["Interfaces"]);
+
+        QString accountObjectPath = qdbus_cast<QString>(props["Account"]);
+        mPriv->account = Account::create(
+                TELEPATHY_ACCOUNT_MANAGER_BUS_NAME,
+                accountObjectPath);
+        connect(mPriv->account->becomeReady(),
+                SIGNAL(finished(Tp::PendingOperation *)),
+                SLOT(onAccountReady(Tp::PendingOperation *)));
+
+        // FIXME: Telepathy supports 64-bit time_t, but Qt only does so on
+        // ILP64 systems (e.g. sparc64, but not x86_64). If QDateTime
+        // gains a fromTimestamp64 method, we should use it instead.
+        uint stamp = (uint) qdbus_cast<qlonglong>(props["UserActionTime"]);
+        if (stamp != 0) {
+            mPriv->userActionTime = QDateTime::fromTime_t(stamp);
+        }
+
+        mPriv->preferredHandler = qdbus_cast<QString>(props["PreferredHandler"]);
+        mPriv->requests = qdbus_cast<QualifiedPropertyValueMapList>(props["Requests"]);
+    }
+    else {
+        mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, false, reply.error());
+        warning().nospace() << "Properties::GetAll(ChannelRequest) failed with "
+            << reply.error().name() << ": " << reply.error().message();
+    }
+}
+
+void ChannelRequest::onAccountReady(PendingOperation *op)
+{
+    if (op->isError()) {
+        mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, false,
+                op->errorName(), op->errorMessage());
+        return;
+    }
+    mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, true);
+}
+
+} // Tp
diff --git a/TelepathyQt4/channel-request.h b/TelepathyQt4/channel-request.h
new file mode 100644
index 0000000..752ba20
--- /dev/null
+++ b/TelepathyQt4/channel-request.h
@@ -0,0 +1,122 @@
+/*
+ * 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_channel_request_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_channel_request_h_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#error IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/_gen/cli-channel-request.h>
+
+#include <TelepathyQt4/Constants>
+#include <TelepathyQt4/DBus>
+#include <TelepathyQt4/DBusProxy>
+#include <TelepathyQt4/Feature>
+#include <TelepathyQt4/OptionalInterfaceFactory>
+#include <TelepathyQt4/ReadinessHelper>
+#include <TelepathyQt4/ReadyObject>
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/SharedPtr>
+
+#include <QString>
+#include <QStringList>
+#include <QVariantMap>
+
+namespace Tp
+{
+
+class PendingOperation;
+
+class ChannelRequest : public StatefulDBusProxy,
+                       private OptionalInterfaceFactory<ChannelRequest>,
+                       public ReadyObject,
+                       public RefCounted
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(ChannelRequest)
+
+public:
+    static const Feature FeatureCore;
+
+    static ChannelRequestPtr create(const QString &objectPath,
+            const QVariantMap &immutableProperties);
+    static ChannelRequestPtr create(const QDBusConnection &bus,
+            const QString &objectPath, const QVariantMap &immutableProperties);
+
+    ~ChannelRequest();
+
+    QStringList interfaces() const;
+
+    AccountPtr account() const;
+
+    QDateTime userActionTime() const;
+
+    QString preferredHandler() const;
+
+    QualifiedPropertyValueMapList requests() const;
+
+    PendingOperation *cancel();
+
+    template <class Interface>
+    inline Interface *optionalInterface(
+            InterfaceSupportedChecking check = CheckInterfaceSupported) const
+    {
+        // Check for the remote object supporting the interface
+        QString name(Interface::staticInterfaceName());
+        if (check == CheckInterfaceSupported && !interfaces().contains(name))
+            return 0;
+
+        // If present or forced, delegate to OptionalInterfaceFactory
+        return OptionalInterfaceFactory<ChannelRequest>::interface<Interface>();
+    }
+
+    inline Client::DBus::PropertiesInterface *propertiesInterface() const
+    {
+        return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
+    }
+
+Q_SIGNALS:
+    void failed(const QString &errorName, const QString &errorMessage);
+    void succeeded();
+
+protected:
+    ChannelRequest(const QString &objectPath,
+            const QVariantMap &immutableProperties);
+    ChannelRequest(const QDBusConnection &bus,
+            const QString &objectPath, const QVariantMap &immutableProperties);
+
+    Client::ChannelRequestInterface *baseInterface() const;
+
+private Q_SLOTS:
+    void gotMainProperties(QDBusPendingCallWatcher *watcher);
+    void onAccountReady(Tp::PendingOperation *op);
+
+private:
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
+} // Tp
+
+#endif
diff --git a/TelepathyQt4/channel-request.xml b/TelepathyQt4/channel-request.xml
new file mode 100644
index 0000000..f673742
--- /dev/null
+++ b/TelepathyQt4/channel-request.xml
@@ -0,0 +1,9 @@
+<tp:spec
+  xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
+  xmlns:xi="http://www.w3.org/2001/XInclude">
+
+<tp:title>Channel Dispatcher interfaces</tp:title>
+
+<xi:include href="../spec/Channel_Request.xml"/>
+
+</tp:spec>
diff --git a/TelepathyQt4/stable-interfaces.xml b/TelepathyQt4/stable-interfaces.xml
index 831a1ba..cb71339 100644
--- a/TelepathyQt4/stable-interfaces.xml
+++ b/TelepathyQt4/stable-interfaces.xml
@@ -8,6 +8,7 @@
 <xi:include href="connection-manager.xml"/>
 <xi:include href="connection.xml"/>
 <xi:include href="channel.xml"/>
+<xi:include href="channel-request.xml"/>
 <xi:include href="media-session-handler.xml"/>
 <xi:include href="media-stream-handler.xml"/>
 <xi:include href="dbus.xml"/>
diff --git a/TelepathyQt4/types.h b/TelepathyQt4/types.h
index d78b1bd..2a68c70 100644
--- a/TelepathyQt4/types.h
+++ b/TelepathyQt4/types.h
@@ -37,6 +37,7 @@ class AbstractClient;
 class Account;
 class AccountManager;
 class Channel;
+class ChannelRequest;
 class ClientRegistrar;
 class Connection;
 class ConnectionManager;
@@ -50,6 +51,7 @@ typedef SharedPtr<AbstractClient> AbstractClientPtr;
 typedef SharedPtr<Account> AccountPtr;
 typedef SharedPtr<AccountManager> AccountManagerPtr;
 typedef SharedPtr<Channel> ChannelPtr;
+typedef SharedPtr<ChannelRequest> ChannelRequestPtr;
 typedef SharedPtr<ClientRegistrar> ClientRegistrarPtr;
 typedef SharedPtr<Connection> ConnectionPtr;
 typedef SharedPtr<ConnectionManager> ConnectionManagerPtr;
-- 
1.5.6.5




More information about the telepathy-commits mailing list