[Telepathy-commits] [telepathy-qt4/master] Added ConnectionManager::requestConnection support.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Fri Jan 16 11:43:43 PST 2009


---
 TelepathyQt4/Client/PendingConnection      |   13 +++
 TelepathyQt4/Client/connection-manager.cpp |   19 ++++
 TelepathyQt4/Client/connection-manager.h   |    5 +
 TelepathyQt4/Client/pending-connection.cpp |  150 ++++++++++++++++++++++++++++
 TelepathyQt4/Client/pending-connection.h   |   71 +++++++++++++
 TelepathyQt4/Makefile.am                   |    4 +
 6 files changed, 262 insertions(+), 0 deletions(-)
 create mode 100644 TelepathyQt4/Client/PendingConnection
 create mode 100644 TelepathyQt4/Client/pending-connection.cpp
 create mode 100644 TelepathyQt4/Client/pending-connection.h

diff --git a/TelepathyQt4/Client/PendingConnection b/TelepathyQt4/Client/PendingConnection
new file mode 100644
index 0000000..01d69d4
--- /dev/null
+++ b/TelepathyQt4/Client/PendingConnection
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_Client_PendingConnection_HEADER_GUARD_
+#define _TelepathyQt4_Client_PendingConnection_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/Client/pending-connection.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/Client/connection-manager.cpp b/TelepathyQt4/Client/connection-manager.cpp
index c209760..e0bf291 100644
--- a/TelepathyQt4/Client/connection-manager.cpp
+++ b/TelepathyQt4/Client/connection-manager.cpp
@@ -30,6 +30,7 @@
 #include "TelepathyQt4/debug-internal.h"
 
 #include <TelepathyQt4/Client/DBus>
+#include <TelepathyQt4/Client/PendingConnection>
 #include <TelepathyQt4/Client/PendingSuccess>
 #include <TelepathyQt4/Constants>
 #include <TelepathyQt4/ManagerFile>
@@ -424,6 +425,24 @@ const ProtocolInfoList &ConnectionManager::protocols() const
 }
 
 /**
+ * Request a Connection object representing a given account on a given protocol
+ * with the given parameters.
+ *
+ * Return a pending operation representing the Connection object which will
+ * succeed when the connection has been created or fail if an error occurred.
+ *
+ * \param protocol Name of the protocol to create the account for.
+ * \param parameters Account parameters.
+ * \return A PendingOperation which will emit PendingConnection::finished when
+ *         the account has been created of failed its creation process.
+ */
+PendingConnection *ConnectionManager::requestConnection(const QString &protocol,
+        const QVariantMap &parameters)
+{
+    return new PendingConnection(this, protocol, parameters);
+}
+
+/**
  * \fn DBus::propertiesInterface *ConnectionManager::propertiesInterface() const
  *
  * Convenience function for getting a Properties interface proxy. The
diff --git a/TelepathyQt4/Client/connection-manager.h b/TelepathyQt4/Client/connection-manager.h
index d8d9225..c444cef 100644
--- a/TelepathyQt4/Client/connection-manager.h
+++ b/TelepathyQt4/Client/connection-manager.h
@@ -38,6 +38,7 @@ namespace Telepathy
 namespace Client
 {
 
+class PendingConnection;
 class PendingOperation;
 class PendingStringList;
 class ProtocolParameter;
@@ -130,6 +131,9 @@ public:
     QStringList supportedProtocols() const;
     const ProtocolInfoList &protocols() const;
 
+    PendingConnection *requestConnection(const QString &protocol,
+            const QVariantMap &parameters);
+
     inline DBus::PropertiesInterface *propertiesInterface() const
     {
         return OptionalInterfaceFactory::interface<DBus::PropertiesInterface>(
@@ -162,6 +166,7 @@ private:
 
     struct Private;
     friend struct Private;
+    friend class PendingConnection;
     Private *mPriv;
 };
 
diff --git a/TelepathyQt4/Client/pending-connection.cpp b/TelepathyQt4/Client/pending-connection.cpp
new file mode 100644
index 0000000..7858b0f
--- /dev/null
+++ b/TelepathyQt4/Client/pending-connection.cpp
@@ -0,0 +1,150 @@
+/*
+ * 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/Client/PendingConnection>
+
+#include "TelepathyQt4/Client/_gen/pending-connection.moc.hpp"
+
+#include "TelepathyQt4/debug-internal.h"
+
+#include <TelepathyQt4/Client/ConnectionManager>
+#include <TelepathyQt4/Client/Connection>
+
+#include <QDBusObjectPath>
+#include <QDBusPendingCallWatcher>
+#include <QDBusPendingReply>
+
+/**
+ * \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 Telepathy
+{
+namespace Client
+{
+
+struct PendingConnection::Private
+{
+    Private(ConnectionManager *manager) :
+        manager(manager),
+        connection(0)
+    {
+    }
+
+    ConnectionManager *manager;
+    Connection *connection;
+};
+
+/**
+ * \class PendingConnection
+ * \ingroup clientconnection
+ * \headerfile <TelepathyQt4/Client/pending-connection.h> <TelepathyQt4/Client/PendingConnection>
+ *
+ * Class containing the parameters of and the reply to an asynchronous connection
+ * request. Instances of this class cannot be constructed directly; the only
+ * way to get one is via ConnectionManager.
+ */
+
+/**
+ * Construct a PendingConnection object.
+ *
+ * \param manager ConnectionManager to use.
+ * \param protocol Name of the protocol to create the connection for.
+ * \param parameters Connection parameters.
+ */
+PendingConnection::PendingConnection(ConnectionManager *manager,
+        const QString &protocol, const QVariantMap &parameters)
+    : PendingOperation(manager),
+      mPriv(new Private(manager))
+{
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
+            manager->baseInterface()->RequestConnection(protocol,
+                parameters), this);
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher *)),
+            SLOT(onCallFinished(QDBusPendingCallWatcher *)));
+}
+
+/**
+ * Class destructor.
+ */
+PendingConnection::~PendingConnection()
+{
+    delete mPriv;
+}
+
+/**
+ * Return the ConnectionManager object through which the request was made.
+ *
+ * \return Connection Manager object.
+ */
+ConnectionManager *PendingConnection::manager() const
+{
+    return qobject_cast<ConnectionManager *>(parent());
+}
+
+/**
+ * Returns the newly created Connection object.
+ *
+ * \return Connection object.
+ */
+Connection *PendingConnection::connection() const
+{
+    if (!isFinished()) {
+        warning() <<
+            "PendingConnection::connection called before finished, returning 0";
+        return 0;
+    }
+
+    return mPriv->connection;
+}
+
+void PendingConnection::onCallFinished(QDBusPendingCallWatcher *watcher)
+{
+    QDBusPendingReply<QString, QDBusObjectPath> reply = *watcher;
+
+    if (!reply.isError()) {
+        debug() << "Got reply to ConnectionManager.CreateConnection";
+        QString serviceName = reply.argumentAt<0>();
+        QDBusObjectPath objectPath = reply.argumentAt<1>();
+        debug() << "Creating connection for objectPath: " << objectPath.path();
+        mPriv->connection = new Connection(mPriv->manager->dbusConnection(),
+                serviceName, objectPath.path(), mPriv->manager);
+        setFinished();
+    } else {
+        debug().nospace() <<
+            "CreateConnection failed: " <<
+            reply.error().name() << ": " << reply.error().message();
+        setFinishedWithError(reply.error());
+    }
+
+    watcher->deleteLater();
+}
+
+} // Telepathy::Client
+} // Telepathy
diff --git a/TelepathyQt4/Client/pending-connection.h b/TelepathyQt4/Client/pending-connection.h
new file mode 100644
index 0000000..1b48da2
--- /dev/null
+++ b/TelepathyQt4/Client/pending-connection.h
@@ -0,0 +1,71 @@
+/*
+ * 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
+ */
+
+#ifndef _TelepathyQt4_cli_pending_connection_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_pending_connection_h_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#error IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/Client/PendingOperation>
+
+#include <QString>
+#include <QVariantMap>
+
+class QDBusPendingCallWatcher;
+
+namespace Telepathy
+{
+namespace Client
+{
+
+class ConnectionManager;
+class Connection;
+
+class PendingConnection : public PendingOperation
+{
+    Q_OBJECT
+
+public:
+    ~PendingConnection();
+
+    ConnectionManager *manager() const;
+    Connection *connection() const;
+
+private Q_SLOTS:
+    void onCallFinished(QDBusPendingCallWatcher *watcher);
+
+private:
+    Q_DISABLE_COPY(PendingConnection);
+    PendingConnection(ConnectionManager *manager,
+            const QString &protocol, const QVariantMap &parameters);
+
+    struct Private;
+    friend struct Private;
+    friend class ConnectionManager;
+    Private *mPriv;
+};
+
+} // Telepathy::Client
+} // Telepathy
+
+#endif
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index 906ab6c..55c32e3 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -48,6 +48,7 @@ libtelepathy_qt4_la_SOURCES = \
     Client/media-stream-handler.cpp \
     Client/optional-interface-factory.cpp \
     Client/pending-channel.cpp \
+    Client/pending-connection.cpp \
     Client/pending-operation.cpp \
     Client/pending-string-list.cpp \
     Client/properties.cpp \
@@ -85,6 +86,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     Client/_gen/connection-manager.moc.hpp \
     Client/_gen/connection-manager-internal.moc.hpp \
     Client/_gen/dbus-proxy.moc.hpp \
+    Client/_gen/pending-connection.moc.hpp \
     Client/_gen/pending-channel.moc.hpp \
     Client/_gen/pending-operation.moc.hpp \
     Client/_gen/pending-string-list.moc.hpp \
@@ -114,6 +116,7 @@ tpqt4clientinclude_HEADERS = \
     Client/MediaStreamHandler \
     Client/OptionalInterfaceFactory \
     Client/PendingChannel \
+    Client/PendingConnection \
     Client/PendingFailure \
     Client/PendingOperation \
     Client/PendingSuccess \
@@ -164,6 +167,7 @@ tpqt4clientinclude_HEADERS = \
     Client/media-stream-handler.h \
     Client/optional-interface-factory.h \
     Client/pending-channel.h \
+    Client/pending-connection.h \
     Client/pending-operation.h \
     Client/pending-string-list.h \
     Client/properties.h \
-- 
1.5.6.5




More information about the Telepathy-commits mailing list