[telepathy-qt4/master] ContactManager: Return ConnectionPtr on connection() method.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Mar 31 14:53:48 PDT 2009
---
TelepathyQt4/Client/connection.cpp | 9 ++++++++-
TelepathyQt4/Client/contact-manager.cpp | 26 +++++++++++++++++---------
TelepathyQt4/Client/contact-manager.h | 4 ++--
TelepathyQt4/Client/pending-contacts.cpp | 12 ++++++------
examples/call/call-handler.cpp | 2 +-
tests/dbus/contacts.cpp | 2 +-
6 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index 081c027..64cfdfb 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -167,7 +167,7 @@ Connection::Private::Private(Connection *parent)
selfHandle(0),
contactListsChannelsReady(0),
handleContext(0),
- contactManager(new ContactManager(parent))
+ contactManager(0)
{
ReadinessHelper::Introspectables introspectables;
@@ -289,6 +289,10 @@ void Connection::Private::init()
void Connection::Private::introspectMain(Connection::Private *self)
{
+ if (!self->contactManager) {
+ self->contactManager = new ContactManager(self->parent);
+ }
+
// Introspecting the main interface is currently just calling
// GetInterfaces(), but it might include other stuff in the future if we
// gain GetAll-able properties on the connection
@@ -1342,6 +1346,9 @@ QStringList Connection::contactAttributeInterfaces() const
ContactManager *Connection::contactManager() const
{
+ if (!isReady()) {
+ return 0;
+ }
return mPriv->contactManager;
}
diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index 759156a..520cff4 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -67,7 +67,12 @@ namespace Client
struct ContactManager::Private
{
- Connection *conn;
+ Private(const ConnectionPtr &connection) :
+ connection(connection)
+ {
+ }
+
+ WeakPtr<Connection> connection;
QMap<uint, QWeakPointer<Contact> > contacts;
QMap<Contact::Feature, bool> tracking;
@@ -85,9 +90,9 @@ struct ContactManager::Private
void updateContactsPresenceState();
};
-Connection *ContactManager::connection() const
+ConnectionPtr ContactManager::connection() const
{
- return mPriv->conn;
+ return mPriv->connection;
}
namespace
@@ -111,13 +116,14 @@ QString featureToInterface(Contact::Feature feature)
QSet<Contact::Feature> ContactManager::supportedFeatures() const
{
+
if (mPriv->supportedFeatures.isEmpty() &&
- mPriv->conn->interfaces().contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS)) {
+ connection()->interfaces().contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS)) {
QList<Contact::Feature> allFeatures = QList<Contact::Feature>()
<< Contact::FeatureAlias
<< Contact::FeatureAvatarToken
<< Contact::FeatureSimplePresence;
- QStringList interfaces = mPriv->conn->contactAttributeInterfaces();
+ QStringList interfaces = connection()->contactAttributeInterfaces();
foreach (Contact::Feature feature, allFeatures) {
if (interfaces.contains(featureToInterface(feature))) {
mPriv->supportedFeatures.insert(feature);
@@ -687,10 +693,10 @@ void ContactManager::onDenyChannelMembersChanged(
}
}
-ContactManager::ContactManager(Connection *parent)
- : QObject(parent), mPriv(new Private)
+ContactManager::ContactManager(const ConnectionPtr &connection)
+ : QObject(connection.data()),
+ mPriv(new Private(connection))
{
- mPriv->conn = parent;
}
ContactManager::~ContactManager()
@@ -804,9 +810,11 @@ ContactPtr ContactManager::lookupContactByHandle(uint handle)
void ContactManager::Private::ensureTracking(Contact::Feature feature)
{
- if (tracking[feature])
+ if (tracking[feature]) {
return;
+ }
+ ConnectionPtr conn(connection);
switch (feature) {
case Contact::FeatureAlias:
QObject::connect(
diff --git a/TelepathyQt4/Client/contact-manager.h b/TelepathyQt4/Client/contact-manager.h
index 23bfd61..92614be 100644
--- a/TelepathyQt4/Client/contact-manager.h
+++ b/TelepathyQt4/Client/contact-manager.h
@@ -51,7 +51,7 @@ class ContactManager : public QObject
public:
- Connection *connection() const;
+ ConnectionPtr connection() const;
QSet<Contact::Feature> supportedFeatures() const;
@@ -154,7 +154,7 @@ class ContactManager : public QObject
ChannelPtr channel;
};
- ContactManager(Connection *parent);
+ ContactManager(const ConnectionPtr &parent);
~ContactManager();
ContactPtr ensureContact(const ReferencedHandles &handle,
diff --git a/TelepathyQt4/Client/pending-contacts.cpp b/TelepathyQt4/Client/pending-contacts.cpp
index e583191..f2871ca 100644
--- a/TelepathyQt4/Client/pending-contacts.cpp
+++ b/TelepathyQt4/Client/pending-contacts.cpp
@@ -277,8 +277,8 @@ void PendingContacts::onReferenceHandlesFinished(PendingOperation *operation)
ReferencedHandles validHandles = pendingHandles->handles();
UIntList invalidHandles = pendingHandles->invalidHandles();
- Connection *conn = mPriv->manager->connection();
- mPriv->handlesToInspect = ReferencedHandles(conn, HandleTypeContact, UIntList());
+ ConnectionPtr conn = mPriv->manager->connection();
+ mPriv->handlesToInspect = ReferencedHandles(conn.data(), HandleTypeContact, UIntList());
foreach (uint handle, mPriv->handles) {
if (!mPriv->satisfyingContacts.contains(handle)) {
int indexInValid = validHandles.indexOf(handle);
@@ -334,11 +334,11 @@ void PendingContacts::onInspectHandlesFinished(QDBusPendingCallWatcher *watcher)
QStringList names = reply.value();
int i = 0;
- Connection *conn = mPriv->manager->connection();
+ ConnectionPtr conn = mPriv->manager->connection();
foreach (uint handle, mPriv->handlesToInspect) {
QVariantMap handleAttributes;
handleAttributes.insert(TELEPATHY_INTERFACE_CONNECTION "/contact-id", names[i++]);
- ReferencedHandles referencedHandle(conn, HandleTypeContact,
+ ReferencedHandles referencedHandle(conn.data(), HandleTypeContact,
UIntList() << handle);
mPriv->satisfyingContacts.insert(handle, manager()->ensureContact(referencedHandle,
features(), handleAttributes));
@@ -361,7 +361,7 @@ PendingContacts::PendingContacts(ContactManager *manager,
debug() << " Fetching" << interfaces.size() << "interfaces for"
<< otherContacts.size() << "contacts";
- Connection *conn = manager->connection();
+ ConnectionPtr conn = manager->connection();
if (conn->interfaces().contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS)) {
debug() << " Building contacts using contact attributes";
PendingContactAttributes *attributes =
@@ -389,7 +389,7 @@ PendingContacts::PendingContacts(ContactManager *manager,
const QStringList &identifiers, const QSet<Contact::Feature> &features)
: PendingOperation(manager), mPriv(new Private(manager, identifiers, features))
{
- Connection *conn = manager->connection();
+ ConnectionPtr conn = manager->connection();
PendingHandles *handles = conn->requestHandles(HandleTypeContact, identifiers);
connect(handles,
diff --git a/examples/call/call-handler.cpp b/examples/call/call-handler.cpp
index abae6a1..c05e9a7 100644
--- a/examples/call/call-handler.cpp
+++ b/examples/call/call-handler.cpp
@@ -60,7 +60,7 @@ void CallHandler::addOutgoingCall(const ContactPtr &contact)
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
contact->handle()[0]);
- Connection *conn = contact->manager()->connection();
+ ConnectionPtr conn = contact->manager()->connection();
connect(conn->ensureChannel(request),
SIGNAL(finished(Telepathy::Client::PendingOperation*)),
SLOT(onOutgoingChannelCreated(Telepathy::Client::PendingOperation*)));
diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
index e077474..deb4287 100644
--- a/tests/dbus/contacts.cpp
+++ b/tests/dbus/contacts.cpp
@@ -185,7 +185,7 @@ void TestContacts::init()
void TestContacts::testSupport()
{
- QCOMPARE(mConn->contactManager()->connection(), mConn.data());
+ QCOMPARE(mConn->contactManager()->connection(), mConn);
QVERIFY(!mConn->contactAttributeInterfaces().isEmpty());
--
1.5.6.5
More information about the telepathy-commits
mailing list