[telepathy-qt4/master] ConnectionManager: Make constructor protected and added public create method that returns a SharedPtr.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue Mar 31 11:12:01 PDT 2009


---
 TelepathyQt4/Client/account.cpp            |    8 ++++----
 TelepathyQt4/Client/connection-manager.cpp |   22 +++++++++++++++-------
 TelepathyQt4/Client/connection-manager.h   |   13 ++++++++-----
 examples/call/call-window.cpp              |    4 ++--
 examples/call/call-window.h                |    2 +-
 examples/roster/roster-window.cpp          |    2 +-
 examples/roster/roster-window.h            |    2 +-
 tests/dbus/cm-basics.cpp                   |    9 ++-------
 tests/pinocchio/cm-basics.cpp              |   22 ++--------------------
 9 files changed, 36 insertions(+), 48 deletions(-)

diff --git a/TelepathyQt4/Client/account.cpp b/TelepathyQt4/Client/account.cpp
index eb0f0ee..50990fe 100644
--- a/TelepathyQt4/Client/account.cpp
+++ b/TelepathyQt4/Client/account.cpp
@@ -92,7 +92,7 @@ struct Account::Private
     QString connectionObjectPath;
     QString normalizedName;
     Telepathy::Avatar avatar;
-    ConnectionManager *cm;
+    ConnectionManagerPtr cm;
     ProtocolInfo *protocolInfo;
     Telepathy::ConnectionStatus connectionStatus;
     Telepathy::ConnectionStatusReason connectionStatusReason;
@@ -759,11 +759,11 @@ void Account::Private::introspectAvatar(Account::Private *self)
 
 void Account::Private::introspectProtocolInfo(Account::Private *self)
 {
-    Q_ASSERT(self->cm == 0);
+    Q_ASSERT(!self->cm);
 
-    self->cm = new ConnectionManager(
+    self->cm = ConnectionManager::create(
             self->parent->dbusConnection(),
-            self->cmName, self->parent);
+            self->cmName);
     self->parent->connect(self->cm->becomeReady(),
             SIGNAL(finished(Telepathy::Client::PendingOperation *)),
             SLOT(onConnectionManagerReady(Telepathy::Client::PendingOperation *)));
diff --git a/TelepathyQt4/Client/connection-manager.cpp b/TelepathyQt4/Client/connection-manager.cpp
index 6c4e4e6..3b356ef 100644
--- a/TelepathyQt4/Client/connection-manager.cpp
+++ b/TelepathyQt4/Client/connection-manager.cpp
@@ -350,16 +350,25 @@ ProtocolInfo *ConnectionManager::Private::protocol(const QString &protocolName)
 
 const Feature ConnectionManager::FeatureCore = Feature(ConnectionManager::staticMetaObject.className(), 0, true);
 
+ConnectionManagerPtr ConnectionManager::create(const QString &name)
+{
+    return ConnectionManagerPtr(new ConnectionManager(name));
+}
+
+ConnectionManagerPtr ConnectionManager::create(const QDBusConnection &bus,
+        const QString &name)
+{
+    return ConnectionManagerPtr(new ConnectionManager(bus, name));
+}
+
 /**
  * Construct a new ConnectionManager object.
  *
  * \param name Name of the connection manager.
- * \param parent Object parent.
  */
-ConnectionManager::ConnectionManager(const QString &name, QObject *parent)
+ConnectionManager::ConnectionManager(const QString &name)
     : StatelessDBusProxy(QDBusConnection::sessionBus(),
-            Private::makeBusName(name), Private::makeObjectPath(name),
-            parent),
+            Private::makeBusName(name), Private::makeObjectPath(name)),
       OptionalInterfaceFactory<ConnectionManager>(this),
       ReadyObject(this, FeatureCore),
       mPriv(new Private(this, name))
@@ -371,12 +380,11 @@ ConnectionManager::ConnectionManager(const QString &name, QObject *parent)
  *
  * \param bus QDBusConnection to use.
  * \param name Name of the connection manager.
- * \param parent Object parent.
  */
 ConnectionManager::ConnectionManager(const QDBusConnection &bus,
-        const QString &name, QObject *parent)
+        const QString &name)
     : StatelessDBusProxy(bus, Private::makeBusName(name),
-            Private::makeObjectPath(name), parent),
+            Private::makeObjectPath(name)),
       OptionalInterfaceFactory<ConnectionManager>(this),
       ReadyObject(this, FeatureCore),
       mPriv(new Private(this, name))
diff --git a/TelepathyQt4/Client/connection-manager.h b/TelepathyQt4/Client/connection-manager.h
index 2c8854f..1826e43 100644
--- a/TelepathyQt4/Client/connection-manager.h
+++ b/TelepathyQt4/Client/connection-manager.h
@@ -128,9 +128,9 @@ class ConnectionManager : public StatelessDBusProxy,
 public:
     static const Feature FeatureCore;
 
-    ConnectionManager(const QString &name, QObject *parent = 0);
-    ConnectionManager(const QDBusConnection &bus,
-            const QString &name, QObject *parent = 0);
+    static ConnectionManagerPtr create(const QString &name);
+    static ConnectionManagerPtr create(const QDBusConnection &bus,
+            const QString &name);
 
     virtual ~ConnectionManager();
 
@@ -152,6 +152,9 @@ public:
     static PendingStringList *listNames(const QDBusConnection &bus = QDBusConnection::sessionBus());
 
 protected:
+    ConnectionManager(const QString &name);
+    ConnectionManager(const QDBusConnection &bus, const QString &name);
+
     ConnectionManagerInterface *baseInterface() const;
 
 private Q_SLOTS:
@@ -168,7 +171,7 @@ private:
     Private *mPriv;
 };
 
-}
-}
+} // Telepathy::Client
+} // Telepathy
 
 #endif
diff --git a/examples/call/call-window.cpp b/examples/call/call-window.cpp
index 7273c64..902e3fd 100644
--- a/examples/call/call-window.cpp
+++ b/examples/call/call-window.cpp
@@ -43,9 +43,9 @@ CallWindow::CallWindow(const QString &username, const QString &password,
       mUsername(username),
       mPassword(password)
 {
-    setWindowTitle("Roster");
+    setWindowTitle("Call");
 
-    mCM = new ConnectionManager("gabble", this);
+    mCM = ConnectionManager::create("gabble");
     connect(mCM->becomeReady(),
             SIGNAL(finished(Telepathy::Client::PendingOperation *)),
             SLOT(onCMReady(Telepathy::Client::PendingOperation *)));
diff --git a/examples/call/call-window.h b/examples/call/call-window.h
index c5a104e..8ebdca6 100644
--- a/examples/call/call-window.h
+++ b/examples/call/call-window.h
@@ -58,7 +58,7 @@ private Q_SLOTS:
 private:
     void setupGui();
 
-    Telepathy::Client::ConnectionManager *mCM;
+    Telepathy::Client::ConnectionManagerPtr mCM;
     Telepathy::Client::ConnectionPtr mConn;
     QString mUsername;
     QString mPassword;
diff --git a/examples/roster/roster-window.cpp b/examples/roster/roster-window.cpp
index 5fb29ad..d1d2ade 100644
--- a/examples/roster/roster-window.cpp
+++ b/examples/roster/roster-window.cpp
@@ -43,7 +43,7 @@ RosterWindow::RosterWindow(const QString &username, const QString &password,
 
     setupGui();
 
-    mCM = new ConnectionManager("gabble", this);
+    mCM = ConnectionManager::create("gabble");
     connect(mCM->becomeReady(),
             SIGNAL(finished(Telepathy::Client::PendingOperation *)),
             SLOT(onCMReady(Telepathy::Client::PendingOperation *)));
diff --git a/examples/roster/roster-window.h b/examples/roster/roster-window.h
index 7e05349..5be8e3e 100644
--- a/examples/roster/roster-window.h
+++ b/examples/roster/roster-window.h
@@ -55,7 +55,7 @@ private Q_SLOTS:
 private:
     void setupGui();
 
-    Telepathy::Client::ConnectionManager *mCM;
+    Telepathy::Client::ConnectionManagerPtr mCM;
     QList<Telepathy::Client::ConnectionPtr> mConns;
     QString mUsername;
     QString mPassword;
diff --git a/tests/dbus/cm-basics.cpp b/tests/dbus/cm-basics.cpp
index 6ae8289..db079aa 100644
--- a/tests/dbus/cm-basics.cpp
+++ b/tests/dbus/cm-basics.cpp
@@ -38,7 +38,7 @@ private Q_SLOTS:
 
 private:
     TpBaseConnectionManager *mCMService;
-    Telepathy::Client::ConnectionManager *mCM;
+    Telepathy::Client::ConnectionManagerPtr mCM;
 };
 
 void TestCmBasics::initTestCase()
@@ -66,7 +66,7 @@ void TestCmBasics::init()
 {
     initImpl();
 
-    mCM = new ConnectionManager("simple");
+    mCM = ConnectionManager::create("simple");
     QCOMPARE(mCM->isReady(), false);
 }
 
@@ -111,11 +111,6 @@ void TestCmBasics::testBasics()
 
 void TestCmBasics::cleanup()
 {
-    if (mCM) {
-        delete mCM;
-        mCM = 0;
-    }
-
     cleanupImpl();
 }
 
diff --git a/tests/pinocchio/cm-basics.cpp b/tests/pinocchio/cm-basics.cpp
index 794e759..5207cd5 100644
--- a/tests/pinocchio/cm-basics.cpp
+++ b/tests/pinocchio/cm-basics.cpp
@@ -17,10 +17,9 @@ class TestCmBasics : public PinocchioTest
     Q_OBJECT
 
 private:
-    Telepathy::Client::ConnectionManager* mCM;
+    Telepathy::Client::ConnectionManagerPtr mCM;
 
 protected Q_SLOTS:
-    void onCmReady(ConnectionManager*);
     void onListNames(Telepathy::Client::PendingOperation*);
 
 private Q_SLOTS:
@@ -48,19 +47,6 @@ void TestCmBasics::init()
     initImpl();
 }
 
-
-void TestCmBasics::onCmReady(ConnectionManager* it)
-{
-    if (mCM != it) {
-        qWarning() << "Got the wrong CM pointer";
-        mLoop->exit(1);
-        return;
-    }
-
-    mLoop->exit(0);
-}
-
-
 void TestCmBasics::onListNames(Telepathy::Client::PendingOperation *operation)
 {
     Telepathy::Client::PendingStringList *p = static_cast<Telepathy::Client::PendingStringList*>(operation);
@@ -77,7 +63,7 @@ void TestCmBasics::testBasics()
             SLOT(onListNames(Telepathy::Client::PendingOperation *)));
     QCOMPARE(mLoop->exec(), 0);
 
-    mCM = new ConnectionManager("pinocchio");
+    mCM = ConnectionManager::create("pinocchio");
     QCOMPARE(mCM->isReady(), false);
 
     connect(mCM->becomeReady(),
@@ -143,10 +129,6 @@ void TestCmBasics::testBasics()
 
 void TestCmBasics::cleanup()
 {
-    if (mCM != NULL) {
-        delete mCM;
-        mCM = NULL;
-    }
     cleanupImpl();
 }
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list