[Telepathy-commits] [telepathy-qt4/master] Connection: Added features param to requestConnection.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Mon Jan 26 13:08:54 PST 2009


Added features param to requestConnect, the returned PendingOperation will only
finish when the connection is ready with features.
---
 TelepathyQt4/Client/connection-internal.h |   52 +++++++++++++++++++++++++++++
 TelepathyQt4/Client/connection.cpp        |   42 +++++++++++++++++++++--
 TelepathyQt4/Client/connection.h          |    4 ++-
 TelepathyQt4/Makefile.am                  |    2 +
 4 files changed, 96 insertions(+), 4 deletions(-)
 create mode 100644 TelepathyQt4/Client/connection-internal.h

diff --git a/TelepathyQt4/Client/connection-internal.h b/TelepathyQt4/Client/connection-internal.h
new file mode 100644
index 0000000..9dff267
--- /dev/null
+++ b/TelepathyQt4/Client/connection-internal.h
@@ -0,0 +1,52 @@
+/*
+ * 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_connection_internal_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_connection_internal_h_HEADER_GUARD_
+
+#include <TelepathyQt4/Client/Connection>
+
+#include <TelepathyQt4/Client/PendingOperation>
+
+namespace Telepathy
+{
+namespace Client
+{
+
+class Connection::PendingConnect : public PendingOperation
+{
+    Q_OBJECT
+
+public:
+    PendingConnect(Connection *parent, Connection::Features features);
+
+private Q_SLOTS:
+    void onConnectReply(QDBusPendingCallWatcher *);
+    void onBecomeReadyReply(Telepathy::Client::PendingOperation *);
+
+private:
+    Connection::Features features;
+};
+
+} // Telepathy::Client
+} // Telepathy
+
+#endif
diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index c39e936..06317c4 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -20,10 +20,12 @@
  */
 
 #include <TelepathyQt4/Client/Connection>
+#include "TelepathyQt4/Client/connection-internal.h"
 
-#include "TelepathyQt4/Client/_gen/connection.moc.hpp"
 #include "TelepathyQt4/_gen/cli-connection.moc.hpp"
 #include "TelepathyQt4/_gen/cli-connection-body.hpp"
+#include "TelepathyQt4/Client/_gen/connection.moc.hpp"
+#include "TelepathyQt4/Client/_gen/connection-internal.moc.hpp"
 
 #include "TelepathyQt4/debug-internal.h"
 
@@ -432,6 +434,40 @@ void Connection::Private::changeSelfPresence(const Telepathy::SimplePresence &pr
     parent->emit selfPresenceChanged(presence);
 }
 
+Connection::PendingConnect::PendingConnect(Connection *parent, Connection::Features features)
+    : PendingOperation(parent),
+      features(features)
+{
+    QDBusPendingCall call = parent->baseInterface()->Connect();
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, parent);
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher*)),
+            this,
+            SLOT(onConnectReply(QDBusPendingCallWatcher*)));
+}
+
+void Connection::PendingConnect::onConnectReply(QDBusPendingCallWatcher *watcher)
+{
+    if (watcher->isError()) {
+        setFinishedWithError(watcher->error());
+    }
+    else {
+        connect(qobject_cast<Connection*>(parent())->becomeReady(features),
+                SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+                SLOT(onBecomeReadyReply(Telepathy::Client::PendingOperation*)));
+    }
+}
+
+void Connection::PendingConnect::onBecomeReadyReply(Telepathy::Client::PendingOperation *op)
+{
+    if (op->isError()) {
+        setFinishedWithError(op->errorName(), op->errorMessage());
+    }
+    else {
+        setFinished();
+    }
+}
+
 QMap<QPair<QString, QString>, Connection::Private::HandleContext*> Connection::Private::handleContexts;
 QMutex Connection::Private::handleContextsLock;
 
@@ -1348,9 +1384,9 @@ PendingOperation *Connection::becomeReady(Features requestedFeatures)
  * \return A %PendingOperation, which will emit finished when the
  *         request finishes.
  */
-PendingOperation *Connection::requestConnect()
+PendingOperation *Connection::requestConnect(Connection::Features features)
 {
-    return new PendingVoidMethodCall(this, baseInterface()->Connect());
+    return new PendingConnect(this, features);
 }
 
 /**
diff --git a/TelepathyQt4/Client/connection.h b/TelepathyQt4/Client/connection.h
index f2c3d9f..2e41ef0 100644
--- a/TelepathyQt4/Client/connection.h
+++ b/TelepathyQt4/Client/connection.h
@@ -151,7 +151,7 @@ public:
 
     PendingChannel *ensureChannel(const QVariantMap &request);
 
-    PendingOperation *requestConnect();
+    PendingOperation *requestConnect(Features features = 0);
 
     PendingOperation *requestDisconnect();
 
@@ -193,8 +193,10 @@ private:
     void handleRequestLanded(uint type);
 
     struct Private;
+    class PendingConnect;
     friend struct Private;
     friend class PendingChannel;
+    friend class PendingConnect;
     friend class PendingHandles;
     friend class ReferencedHandles;
     Private *mPriv;
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index 3488b3d..85a4ed9 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -41,6 +41,7 @@ libtelepathy_qt4_la_SOURCES = \
     Client/channel.cpp \
     Client/connection.cpp \
     Client/connection-manager.cpp \
+    Client/connection-internal.h \
     Client/connection-manager-internal.h \
     Client/dbus.cpp \
     Client/dbus-proxy.cpp \
@@ -88,6 +89,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     Client/_gen/channel.moc.hpp \
     Client/_gen/connection.moc.hpp \
     Client/_gen/connection-manager.moc.hpp \
+    Client/_gen/connection-internal.moc.hpp \
     Client/_gen/connection-manager-internal.moc.hpp \
     Client/_gen/dbus-proxy.moc.hpp \
     Client/_gen/pending-account.moc.hpp \
-- 
1.5.6.5




More information about the Telepathy-commits mailing list