[telepathy-qt4/master] AccountManager: 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 08:06:16 PDT 2009
---
TelepathyQt4/Client/account-manager.cpp | 22 ++++++++++++++--------
TelepathyQt4/Client/account-manager.h | 7 +++++--
examples/accounts/account-item.cpp | 4 ++--
examples/accounts/account-item.h | 3 ++-
examples/accounts/accounts-window.cpp | 4 ++--
examples/accounts/accounts-window.h | 5 +++--
tests/dbus/account-basics.cpp | 9 ++-------
7 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/TelepathyQt4/Client/account-manager.cpp b/TelepathyQt4/Client/account-manager.cpp
index 899e5ee..da7a2bd 100644
--- a/TelepathyQt4/Client/account-manager.cpp
+++ b/TelepathyQt4/Client/account-manager.cpp
@@ -151,15 +151,23 @@ void AccountManager::Private::setAccountPaths(QSet<QString> &set,
const Feature AccountManager::FeatureCore = Feature(AccountManager::staticMetaObject.className(), 0, true);
+AccountManagerPtr AccountManager::create()
+{
+ return AccountManagerPtr(new AccountManager());
+}
+
+AccountManagerPtr AccountManager::create(const QDBusConnection &bus)
+{
+ return AccountManagerPtr(new AccountManager(bus));
+}
+
/**
* Construct a new AccountManager object.
- *
- * \param parent Object parent.
*/
-AccountManager::AccountManager(QObject* parent)
+AccountManager::AccountManager()
: StatelessDBusProxy(QDBusConnection::sessionBus(),
QLatin1String(TELEPATHY_ACCOUNT_MANAGER_BUS_NAME),
- QLatin1String(TELEPATHY_ACCOUNT_MANAGER_OBJECT_PATH), parent),
+ QLatin1String(TELEPATHY_ACCOUNT_MANAGER_OBJECT_PATH)),
OptionalInterfaceFactory<AccountManager>(this),
ReadyObject(this, FeatureCore),
mPriv(new Private(this))
@@ -170,13 +178,11 @@ AccountManager::AccountManager(QObject* parent)
* Construct a new AccountManager object.
*
* \param bus QDBusConnection to use.
- * \param parent Object parent.
*/
-AccountManager::AccountManager(const QDBusConnection& bus,
- QObject* parent)
+AccountManager::AccountManager(const QDBusConnection& bus)
: StatelessDBusProxy(bus,
QLatin1String(TELEPATHY_ACCOUNT_MANAGER_BUS_NAME),
- QLatin1String(TELEPATHY_ACCOUNT_MANAGER_OBJECT_PATH), parent),
+ QLatin1String(TELEPATHY_ACCOUNT_MANAGER_OBJECT_PATH)),
OptionalInterfaceFactory<AccountManager>(this),
ReadyObject(this, FeatureCore),
mPriv(new Private(this))
diff --git a/TelepathyQt4/Client/account-manager.h b/TelepathyQt4/Client/account-manager.h
index 1e54903..b961c92 100644
--- a/TelepathyQt4/Client/account-manager.h
+++ b/TelepathyQt4/Client/account-manager.h
@@ -62,8 +62,8 @@ class AccountManager : public StatelessDBusProxy,
public:
static const Feature FeatureCore;
- AccountManager(QObject *parent = 0);
- AccountManager(const QDBusConnection &bus, QObject *parent = 0);
+ static AccountManagerPtr create();
+ static AccountManagerPtr create(const QDBusConnection &bus);
virtual ~AccountManager();
@@ -97,6 +97,9 @@ Q_SIGNALS:
void accountValidityChanged(const QString &path, bool valid);
protected:
+ AccountManager();
+ AccountManager(const QDBusConnection &bus);
+
AccountManagerInterface *baseInterface() const;
private Q_SLOTS:
diff --git a/examples/accounts/account-item.cpp b/examples/accounts/account-item.cpp
index 995de00..d896014 100644
--- a/examples/accounts/account-item.cpp
+++ b/examples/accounts/account-item.cpp
@@ -28,10 +28,10 @@
#include <QComboBox>
#include <QTableWidget>
-AccountItem::AccountItem(Telepathy::Client::AccountManager *am,
+AccountItem::AccountItem(Telepathy::Client::AccountManagerPtr am,
const QString &objectPath, QTableWidget *table, int row, QObject *parent)
: QObject(parent),
- acc(new Telepathy::Client::Account(am, objectPath, this)),
+ acc(new Telepathy::Client::Account(am.data(), objectPath, this)),
mTable(table),
mRow(row)
{
diff --git a/examples/accounts/account-item.h b/examples/accounts/account-item.h
index 225f2dd..66e2fa0 100644
--- a/examples/accounts/account-item.h
+++ b/examples/accounts/account-item.h
@@ -23,6 +23,7 @@
#include <TelepathyQt4/Types>
#include <TelepathyQt4/Client/Account>
+#include <TelepathyQt4/Client/Types>
#include <QString>
@@ -57,7 +58,7 @@ public:
};
Q_ENUMS(Columns)
- AccountItem(Telepathy::Client::AccountManager *am, const QString &objectPath,
+ AccountItem(Telepathy::Client::AccountManagerPtr am, const QString &objectPath,
QTableWidget *table, int row, QObject *parent = 0);
virtual ~AccountItem();
diff --git a/examples/accounts/accounts-window.cpp b/examples/accounts/accounts-window.cpp
index 70c18e3..abbe4ba 100644
--- a/examples/accounts/accounts-window.cpp
+++ b/examples/accounts/accounts-window.cpp
@@ -41,11 +41,11 @@ AccountsWindow::AccountsWindow(QWidget *parent)
{
setupGui();
- mAM = new Telepathy::Client::AccountManager(this);
+ mAM = Telepathy::Client::AccountManager::create();
connect(mAM->becomeReady(),
SIGNAL(finished(Telepathy::Client::PendingOperation *)),
SLOT(onAMReady(Telepathy::Client::PendingOperation *)));
- connect(mAM,
+ connect(mAM.data(),
SIGNAL(accountCreated(const QString &)),
SLOT(onAccountCreated(const QString &)));
}
diff --git a/examples/accounts/accounts-window.h b/examples/accounts/accounts-window.h
index 88d1ccd..cdf741b 100644
--- a/examples/accounts/accounts-window.h
+++ b/examples/accounts/accounts-window.h
@@ -23,9 +23,10 @@
#include <QMainWindow>
+#include <TelepathyQt4/Client/Types>
+
namespace Telepathy {
namespace Client {
-class AccountManager;
class PendingOperation;
}
}
@@ -48,7 +49,7 @@ private Q_SLOTS:
private:
void setupGui();
- Telepathy::Client::AccountManager *mAM;
+ Telepathy::Client::AccountManagerPtr mAM;
QTableWidget *mTable;
};
diff --git a/tests/dbus/account-basics.cpp b/tests/dbus/account-basics.cpp
index 613537e..5af89cc 100644
--- a/tests/dbus/account-basics.cpp
+++ b/tests/dbus/account-basics.cpp
@@ -36,7 +36,7 @@ private Q_SLOTS:
void cleanupTestCase();
private:
- AccountManager *mAM;
+ AccountManagerPtr mAM;
};
void TestAccountBasics::onAvatarChanged(const Telepathy::Avatar &avatar)
@@ -51,7 +51,7 @@ void TestAccountBasics::initTestCase()
{
initTestCaseImpl();
- mAM = new AccountManager();
+ mAM = AccountManager::create();
QCOMPARE(mAM->isReady(), false);
}
@@ -179,11 +179,6 @@ void TestAccountBasics::cleanup()
void TestAccountBasics::cleanupTestCase()
{
- if (mAM) {
- delete mAM;
- mAM = 0;
- }
-
cleanupTestCaseImpl();
}
--
1.5.6.5
More information about the telepathy-commits
mailing list