[Telepathy-commits] [telepathy-qt4/master] Added ConnectionManager::listNames method.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue Jan 6 10:31:51 PST 2009


Added ConnectionManager::listNames method that will list all CMs.
---
 TelepathyQt4/Client/connection-manager-internal.h |   60 +++++++++++++++++
 TelepathyQt4/Client/connection-manager.cpp        |   71 +++++++++++++++++++++
 TelepathyQt4/Client/connection-manager.h          |    3 +
 TelepathyQt4/Makefile.am                          |    1 +
 4 files changed, 135 insertions(+), 0 deletions(-)
 create mode 100644 TelepathyQt4/Client/connection-manager-internal.h

diff --git a/TelepathyQt4/Client/connection-manager-internal.h b/TelepathyQt4/Client/connection-manager-internal.h
new file mode 100644
index 0000000..0714629
--- /dev/null
+++ b/TelepathyQt4/Client/connection-manager-internal.h
@@ -0,0 +1,60 @@
+/*
+ * 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_manager_internal_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_connection_manager_internal_h_HEADER_GUARD_
+
+#include <TelepathyQt4/Client/PendingStringList>
+
+#include <QDBusConnection>
+#include <QLatin1String>
+#include <QQueue>
+
+namespace Telepathy
+{
+namespace Client
+{
+
+class ConnectionManagerPendingNames : public PendingStringList
+{
+    Q_OBJECT
+
+public:
+    ConnectionManagerPendingNames(const QDBusConnection &bus);
+    ~ConnectionManagerPendingNames() {};
+
+private Q_SLOTS:
+    void onCallFinished(QDBusPendingCallWatcher *);
+    void continueProcessing();
+
+private:
+    void invokeMethod(const QLatin1String &method);
+    void parseResult(const QStringList &names);
+
+    QQueue<QLatin1String> mMethodsQueue;
+    QStringList mResult;
+    QDBusConnection mBus;
+};
+
+} // Telepathy::Client
+} // Telepathy
+
+#endif
diff --git a/TelepathyQt4/Client/connection-manager.cpp b/TelepathyQt4/Client/connection-manager.cpp
index 7fc98ff..b884d50 100644
--- a/TelepathyQt4/Client/connection-manager.cpp
+++ b/TelepathyQt4/Client/connection-manager.cpp
@@ -20,8 +20,10 @@
  */
 
 #include <TelepathyQt4/Client/ConnectionManager>
+#include "connection-manager-internal.h"
 
 #include "connection-manager.moc.hpp"
+#include "connection-manager-internal.moc.hpp"
 
 #include "TelepathyQt4/_gen/cli-connection-manager-body.hpp"
 #include "TelepathyQt4/_gen/cli-connection-manager.moc.hpp"
@@ -33,6 +35,7 @@
 #include <TelepathyQt4/ManagerFile>
 #include <TelepathyQt4/Types>
 
+#include <QDBusConnectionInterface>
 #include <QQueue>
 #include <QStringList>
 #include <QTimer>
@@ -197,6 +200,68 @@ ConnectionManager::Private::PendingReady::PendingReady(ConnectionManager *parent
 }
 
 
+ConnectionManagerPendingNames::ConnectionManagerPendingNames(const QDBusConnection &bus)
+    : PendingStringList(),
+      mBus(bus)
+{
+    mMethodsQueue.enqueue(QLatin1String("ListNames"));
+    mMethodsQueue.enqueue(QLatin1String("ListActivatableNames"));
+    QTimer::singleShot(0, this, SLOT(continueProcessing()));
+}
+
+
+void ConnectionManagerPendingNames::onCallFinished(QDBusPendingCallWatcher *watcher)
+{
+    QDBusPendingReply<QStringList> reply = *watcher;
+
+    if (!reply.isError()) {
+        parseResult(reply.value());
+        continueProcessing();
+    } else {
+        warning() << "Failure: error " << reply.error().name() <<
+            ": " << reply.error().message();
+        setFinishedWithError(reply.error());
+    }
+
+    watcher->deleteLater();
+}
+
+
+void ConnectionManagerPendingNames::continueProcessing()
+{
+    if (!mMethodsQueue.isEmpty()) {
+        QLatin1String method = mMethodsQueue.dequeue();
+        invokeMethod(method);
+    }
+    else {
+        debug() << "Success: list" << mResult;
+        setResult(mResult);
+        setFinished();
+    }
+}
+
+
+void ConnectionManagerPendingNames::invokeMethod(const QLatin1String &method)
+{
+    QDBusPendingCall call = mBus.interface()->asyncCallWithArgumentList(
+                method, QList<QVariant>());
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher *)),
+            SLOT(onCallFinished(QDBusPendingCallWatcher *)));
+}
+
+
+void ConnectionManagerPendingNames::parseResult(const QStringList &names)
+{
+    Q_FOREACH (const QString name, names) {
+        if (name.startsWith("org.freedesktop.Telepathy.ConnectionManager.")) {
+            mResult << name.right(name.length() - 44);
+        }
+    }
+}
+
+
 ConnectionManager::Private::Private(ConnectionManager *parent)
     : parent(parent),
       baseInterface(new ConnectionManagerInterface(parent->dbusConnection(),
@@ -395,6 +460,12 @@ PendingOperation *ConnectionManager::becomeReady()
 }
 
 
+PendingStringList *ConnectionManager::listNames(const QDBusConnection &bus)
+{
+    return new ConnectionManagerPendingNames(bus);
+}
+
+
 ConnectionManagerInterface* ConnectionManager::baseInterface() const
 {
     return mPriv->baseInterface;
diff --git a/TelepathyQt4/Client/connection-manager.h b/TelepathyQt4/Client/connection-manager.h
index a7ea653..e8e3c67 100644
--- a/TelepathyQt4/Client/connection-manager.h
+++ b/TelepathyQt4/Client/connection-manager.h
@@ -57,6 +57,7 @@ namespace Client
 {
 
 class PendingOperation;
+class PendingStringList;
 class ProtocolParameter;
 class ProtocolInfo;
 
@@ -226,6 +227,8 @@ public:
      */
     PendingOperation *becomeReady();
 
+    static PendingStringList *listNames(const QDBusConnection &bus = QDBusConnection::sessionBus());
+
 Q_SIGNALS:
     // FIXME: do we need this if we have becomeReady()?
     void ready(ConnectionManager*);
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index bbd20ca..2cc89bd 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -78,6 +78,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     Client/channel.moc.hpp \
     Client/connection.moc.hpp \
     Client/connection-manager.moc.hpp \
+    Client/connection-manager-internal.moc.hpp \
     Client/dbus-proxy.moc.hpp \
     Client/pending-channel.moc.hpp \
     Client/pending-operation.moc.hpp \
-- 
1.5.6.5




More information about the Telepathy-commits mailing list