[Telepathy-commits] [telepathy-qt4/master] Channel: Make PendingChannel return a QSharedPointer<Channel> instead of Channel *.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Fri Feb 13 10:02:45 PST 2009
---
TelepathyQt4/Client/pending-channel.cpp | 41 ++++++++++++++++++-------------
TelepathyQt4/Client/pending-channel.h | 5 ++-
tests/dbus/chan-basics.cpp | 8 ++----
tests/dbus/chan-group.cpp | 9 +++----
tests/dbus/conn-requests.cpp | 4 +-
5 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/TelepathyQt4/Client/pending-channel.cpp b/TelepathyQt4/Client/pending-channel.cpp
index 326514a..a6d4741 100644
--- a/TelepathyQt4/Client/pending-channel.cpp
+++ b/TelepathyQt4/Client/pending-channel.cpp
@@ -57,6 +57,7 @@ struct PendingChannel::Private
uint handle;
QDBusObjectPath objectPath;
QVariantMap immutableProperties;
+ QSharedPointer<Channel> channel;
};
/**
@@ -236,42 +237,48 @@ QVariantMap PendingChannel::immutableProperties() const
* \param parent Passed to the Channel constructor.
* \return Pointer to the new Channel object, 0 if an error occurred.
*/
-Channel *PendingChannel::channel(QObject *parent) const
+QSharedPointer<Channel> PendingChannel::channel() const
{
if (!isFinished()) {
warning() << "PendingChannel::channel called before finished, returning 0";
- return 0;
- }
- else if (!isValid()) {
+ return QSharedPointer<Channel>();
+ } else if (!isValid()) {
warning() << "PendingChannel::channel called when not valid, returning 0";
- return 0;
+ return QSharedPointer<Channel>();
}
- Channel *channel;
+ if (mPriv->channel) {
+ return mPriv->channel;
+ }
if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) {
- channel = new TextChannel(connection(), mPriv->objectPath.path(),
- mPriv->immutableProperties, parent);
+ mPriv->channel = QSharedPointer<Channel>(
+ new TextChannel(connection(), mPriv->objectPath.path(),
+ mPriv->immutableProperties));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
- channel = new StreamedMediaChannel(connection(),
- mPriv->objectPath.path(), mPriv->immutableProperties, parent);
+ mPriv->channel = QSharedPointer<Channel>(
+ new StreamedMediaChannel(connection(), mPriv->objectPath.path(),
+ mPriv->immutableProperties));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_ROOM_LIST) {
- channel = new RoomList(connection(), mPriv->objectPath.path(),
- mPriv->immutableProperties, parent);
+ mPriv->channel = QSharedPointer<Channel>(
+ new RoomList(connection(), mPriv->objectPath.path(),
+ mPriv->immutableProperties));
}
// FIXME: update spec so we can do this properly
else if (channelType() == "org.freedesktop.Telepathy.Channel.Type.FileTransfer") {
- channel = new FileTransfer(connection(), mPriv->objectPath.path(),
- mPriv->immutableProperties, parent);
+ mPriv->channel = QSharedPointer<Channel>(
+ new FileTransfer(connection(), mPriv->objectPath.path(),
+ mPriv->immutableProperties));
}
else {
// ContactList, old-style Tubes, or a future channel type
- channel = new Channel(connection(), mPriv->objectPath.path(),
- mPriv->immutableProperties, parent);
+ mPriv->channel = QSharedPointer<Channel>(
+ new Channel(connection(), mPriv->objectPath.path(),
+ mPriv->immutableProperties));
}
- return channel;
+ return mPriv->channel;
}
void PendingChannel::onCallCreateChannelFinished(QDBusPendingCallWatcher *watcher)
diff --git a/TelepathyQt4/Client/pending-channel.h b/TelepathyQt4/Client/pending-channel.h
index 6de1b5a..17a9119 100644
--- a/TelepathyQt4/Client/pending-channel.h
+++ b/TelepathyQt4/Client/pending-channel.h
@@ -26,8 +26,10 @@
#error IN_TELEPATHY_QT4_HEADER
#endif
+#include <TelepathyQt4/Client/Channel>
#include <TelepathyQt4/Client/PendingOperation>
+#include <QSharedPointer>
#include <QString>
#include <QVariantMap>
@@ -38,7 +40,6 @@ namespace Telepathy
namespace Client
{
-class Channel;
class Connection;
class PendingChannel : public PendingOperation
@@ -61,7 +62,7 @@ public:
QVariantMap immutableProperties() const;
- Channel *channel(QObject *parent = 0) const;
+ QSharedPointer<Channel> channel() const;
private Q_SLOTS:
void onCallCreateChannelFinished(QDBusPendingCallWatcher *watcher);
diff --git a/tests/dbus/chan-basics.cpp b/tests/dbus/chan-basics.cpp
index ef37b08..5f6a843 100644
--- a/tests/dbus/chan-basics.cpp
+++ b/tests/dbus/chan-basics.cpp
@@ -50,7 +50,7 @@ private:
QString mConnName, mConnPath;
ExampleEcho2Connection *mConnService;
Connection *mConn;
- Channel *mChan;
+ QSharedPointer<Channel> mChan;
QString mChanObjectPath;
uint mHandle;
};
@@ -279,8 +279,7 @@ void TestChanBasics::testCreateChannel()
QCOMPARE(ids, QStringList() <<
"me at example.com" << "alice");
- delete mChan;
- mChan = 0;
+ mChan.clear();
}
}
@@ -324,8 +323,7 @@ void TestChanBasics::testEnsureChannel()
QCOMPARE(mLoop->exec(), 0);
QCOMPARE(mChan->isValid(), false);
- delete mChan;
- mChan = 0;
+ mChan.clear();
}
}
diff --git a/tests/dbus/chan-group.cpp b/tests/dbus/chan-group.cpp
index c26b4c4..887ab93 100644
--- a/tests/dbus/chan-group.cpp
+++ b/tests/dbus/chan-group.cpp
@@ -65,7 +65,7 @@ private:
QString mConnName, mConnPath;
ExampleCSHConnection *mConnService;
Connection *mConn;
- Channel *mChan;
+ QSharedPointer<Channel> mChan;
QString mChanObjectPath;
uint mRoomNumber;
ReferencedHandles mRoomHandles;
@@ -386,7 +386,7 @@ void TestChanGroup::doTestCreateChannel()
QCOMPARE(mChan->initiatorContact().isNull(), true);
QCOMPARE(mChan->groupSelfContact()->id(), QString("me@#room%1").arg(mRoomNumber));
- QVERIFY(connect(mChan,
+ QVERIFY(connect(mChan.data(),
SIGNAL(groupFlagsChanged(uint, uint, uint)),
SLOT(onChannelGroupFlagsChanged(uint, uint, uint))));
@@ -400,7 +400,7 @@ void TestChanGroup::doTestCreateChannel()
debugContacts();
- QVERIFY(connect(mChan,
+ QVERIFY(connect(mChan.data(),
SIGNAL(groupMembersChanged(
const QList<QSharedPointer<Contact> > &,
const QList<QSharedPointer<Contact> > &,
@@ -526,8 +526,7 @@ void TestChanGroup::doTestCreateChannel()
expectedIds.sort();
checkExpectedIds(mChan->groupContacts(), expectedIds);
- delete mChan;
- mChan = 0;
+ mChan.clear();
}
void TestChanGroup::cleanup()
diff --git a/tests/dbus/conn-requests.cpp b/tests/dbus/conn-requests.cpp
index a077c16..399b1a5 100644
--- a/tests/dbus/conn-requests.cpp
+++ b/tests/dbus/conn-requests.cpp
@@ -131,7 +131,7 @@ void TestConnRequests::expectCreateChannelFinished(PendingOperation* op)
}
PendingChannel *pc = qobject_cast<PendingChannel*>(op);
- Channel *chan = pc->channel();
+ QSharedPointer<Channel> chan = pc->channel();
mChanObjectPath = chan->objectPath();
mLoop->exit(0);
}
@@ -158,7 +158,7 @@ void TestConnRequests::expectEnsureChannelFinished(PendingOperation* op)
}
PendingChannel *pc = qobject_cast<PendingChannel*>(op);
- Channel *chan = pc->channel();
+ QSharedPointer<Channel> chan = pc->channel();
QCOMPARE(pc->yours(), false);
QCOMPARE(chan->objectPath(), mChanObjectPath);
mLoop->exit(0);
--
1.5.6.5
More information about the telepathy-commits
mailing list