[telepathy-qt4/master] TextChannel: 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 12:48:59 PDT 2009
---
TelepathyQt4/Client/message.cpp | 12 ++++++------
TelepathyQt4/Client/message.h | 6 ++++--
TelepathyQt4/Client/pending-channel.cpp | 5 ++---
TelepathyQt4/Client/text-channel.cpp | 13 +++++++++----
TelepathyQt4/Client/text-channel.h | 9 +++++++--
tests/dbus/text-chan.cpp | 20 ++++++++------------
6 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/TelepathyQt4/Client/message.cpp b/TelepathyQt4/Client/message.cpp
index 423cd8c..590ce2b 100644
--- a/TelepathyQt4/Client/message.cpp
+++ b/TelepathyQt4/Client/message.cpp
@@ -47,7 +47,7 @@ public:
bool forceNonText;
// for received messages only
- QPointer<TextChannel> textChannel;
+ WeakPtr<TextChannel> textChannel;
ContactPtr sender;
inline QVariant value(uint index, const char *key) const;
@@ -121,7 +121,7 @@ void Message::Private::clearSenderHandle()
/**
* \class Message
* \ingroup clientchannel
- * \headerfile TelepathyQt4/Client/text-channel.h <TelepathyQt4/Client/TextChannel>
+ * \headerfile <TelepathyQt4/Client/text-channel.h> <TelepathyQt4/Client/TextChannel>
*
* Object representing a message. These objects are implicitly shared, like
* QString.
@@ -423,7 +423,7 @@ MessagePartList Message::parts() const
/**
* \class ReceivedMessage
* \ingroup clientchannel
- * \headerfile TelepathyQt4/Client/text-channel.h <TelepathyQt4/Client/TextChannel>
+ * \headerfile <TelepathyQt4/Client/text-channel.h> <TelepathyQt4/Client/TextChannel>
*
* Subclass of Message, with additional information that's generally only
* available on received messages.
@@ -443,7 +443,7 @@ ReceivedMessage::ReceivedMessage()
* specification. This list must have length at least 1.
*/
ReceivedMessage::ReceivedMessage(const MessagePartList &parts,
- TextChannel *channel)
+ const TextChannelPtr &channel)
: Message(parts)
{
if (!mPriv->parts[0].contains(QLatin1String("message-received"))) {
@@ -539,9 +539,9 @@ bool ReceivedMessage::isRescued() const
return mPriv->getBoolean(0, "rescued", false);
}
-bool ReceivedMessage::isFromChannel(const TextChannel *channel) const
+bool ReceivedMessage::isFromChannel(const TextChannelPtr &channel) const
{
- return mPriv->textChannel == channel;
+ return TextChannelPtr(mPriv->textChannel) == channel;
}
uint ReceivedMessage::pendingId() const
diff --git a/TelepathyQt4/Client/message.h b/TelepathyQt4/Client/message.h
index b17da34..c6d8496 100644
--- a/TelepathyQt4/Client/message.h
+++ b/TelepathyQt4/Client/message.h
@@ -28,6 +28,7 @@
#include <QSharedDataPointer>
#include <TelepathyQt4/Client/Contact>
+#include <TelepathyQt4/Client/Types>
#include <TelepathyQt4/Constants>
#include <TelepathyQt4/Types>
@@ -104,11 +105,12 @@ public:
bool isScrollback() const;
bool isRescued() const;
- bool isFromChannel(const TextChannel *channel) const;
+ bool isFromChannel(const TextChannelPtr &channel) const;
private:
friend class TextChannel;
- ReceivedMessage(const MessagePartList &parts, TextChannel *channel);
+ ReceivedMessage(const MessagePartList &parts,
+ const TextChannelPtr &channel);
ReceivedMessage();
uint senderHandle() const;
uint pendingId() const;
diff --git a/TelepathyQt4/Client/pending-channel.cpp b/TelepathyQt4/Client/pending-channel.cpp
index 479c1d9..1dc8a0c 100644
--- a/TelepathyQt4/Client/pending-channel.cpp
+++ b/TelepathyQt4/Client/pending-channel.cpp
@@ -257,9 +257,8 @@ ChannelPtr PendingChannel::channel() const
}
if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) {
- mPriv->channel = ChannelPtr(
- new TextChannel(mPriv->connection.data(), mPriv->objectPath.path(),
- mPriv->immutableProperties));
+ mPriv->channel = TextChannel::create(mPriv->connection,
+ mPriv->objectPath.path(), mPriv->immutableProperties);
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
mPriv->channel = StreamedMediaChannel::create(mPriv->connection,
diff --git a/TelepathyQt4/Client/text-channel.cpp b/TelepathyQt4/Client/text-channel.cpp
index 8575eb5..bffe7e9 100644
--- a/TelepathyQt4/Client/text-channel.cpp
+++ b/TelepathyQt4/Client/text-channel.cpp
@@ -390,6 +390,13 @@ const Feature TextChannel::FeatureMessageSentSignal = Feature(TextChannel::stati
* circumstances in which this happens.
*/
+TextChannelPtr TextChannel::create(const ConnectionPtr &connection,
+ const QString &objectPath, const QVariantMap &immutableProperties)
+{
+ return TextChannelPtr(new TextChannel(connection, objectPath,
+ immutableProperties));
+}
+
/**
* Creates a TextChannel associated with the given object on the same service
* as the given connection.
@@ -400,12 +407,10 @@ const Feature TextChannel::FeatureMessageSentSignal = Feature(TextChannel::stati
* \param immutableProperties The immutable D-Bus properties of the channel
* (as announced in the NewChannels D-Bus signal), used to
* reduce D-Bus round trips
- * \param parent Passed to the parent class constructor.
*/
-TextChannel::TextChannel(Connection *connection,
+TextChannel::TextChannel(const ConnectionPtr &connection,
const QString &objectPath,
- const QVariantMap &immutableProperties,
- QObject *parent)
+ const QVariantMap &immutableProperties)
: Channel(connection, objectPath, immutableProperties),
mPriv(new Private(this))
{
diff --git a/TelepathyQt4/Client/text-channel.h b/TelepathyQt4/Client/text-channel.h
index 7045e5a..48c56e7 100644
--- a/TelepathyQt4/Client/text-channel.h
+++ b/TelepathyQt4/Client/text-channel.h
@@ -72,8 +72,9 @@ public:
static const Feature FeatureMessageCapabilities;
static const Feature FeatureMessageSentSignal;
- TextChannel(Connection *connection, const QString &objectPath,
- const QVariantMap &immutableProperties, QObject *parent = 0);
+ static TextChannelPtr create(const ConnectionPtr &connection,
+ const QString &objectPath, const QVariantMap &immutableProperties);
+
~TextChannel();
bool hasMessagesInterface() const;
@@ -115,6 +116,10 @@ Q_SIGNALS:
void pendingMessageRemoved(
const Telepathy::Client::ReceivedMessage &message);
+protected:
+ TextChannel(const ConnectionPtr &connection, const QString &objectPath,
+ const QVariantMap &immutableProperties);
+
private Q_SLOTS:
void onContactsFinished(Telepathy::Client::PendingOperation *);
void onAcknowledgePendingMessagesReply(QDBusPendingCallWatcher *);
diff --git a/tests/dbus/text-chan.cpp b/tests/dbus/text-chan.cpp
index 233b9e8..1292ee2 100644
--- a/tests/dbus/text-chan.cpp
+++ b/tests/dbus/text-chan.cpp
@@ -78,7 +78,7 @@ private:
ExampleEcho2Channel *mMessagesChanService;
ConnectionPtr mConn;
- TextChannel *mChan;
+ TextChannelPtr mChan;
QString mTextChanPath;
QString mMessagesChanPath;
QString mConnName;
@@ -194,8 +194,8 @@ void TestTextChan::init()
void TestTextChan::commonTest(bool withMessages)
{
- Q_ASSERT(mChan != 0);
- Channel *asChannel = mChan;
+ Q_ASSERT(mChan);
+ ChannelPtr asChannel = mChan;
QVERIFY(connect(asChannel->becomeReady(),
SIGNAL(finished(Telepathy::Client::PendingOperation *)),
@@ -211,16 +211,16 @@ void TestTextChan::commonTest(bool withMessages)
// early, so don't assert about that
QVERIFY(!mChan->isReady(features));
- QVERIFY(connect(mChan,
+ QVERIFY(connect(mChan.data(),
SIGNAL(messageReceived(const Telepathy::Client::ReceivedMessage &)),
SLOT(onMessageReceived(const Telepathy::Client::ReceivedMessage &))));
QCOMPARE(received.size(), 0);
- QVERIFY(connect(mChan,
+ QVERIFY(connect(mChan.data(),
SIGNAL(pendingMessageRemoved(const Telepathy::Client::ReceivedMessage &)),
SLOT(onMessageRemoved(const Telepathy::Client::ReceivedMessage &))));
QCOMPARE(removed.size(), 0);
- QVERIFY(connect(mChan,
+ QVERIFY(connect(mChan.data(),
SIGNAL(messageSent(const Telepathy::Client::Message &,
Telepathy::MessageSendingFlags,
const QString &)),
@@ -412,24 +412,20 @@ void TestTextChan::commonTest(bool withMessages)
void TestTextChan::testMessages()
{
- mChan = new TextChannel(mConn.data(), mMessagesChanPath, QVariantMap(), this);
+ mChan = TextChannel::create(mConn.data(), mMessagesChanPath, QVariantMap());
commonTest(true);
}
void TestTextChan::testLegacyText()
{
- mChan = new TextChannel(mConn.data(), mTextChanPath, QVariantMap(), this);
+ mChan = TextChannel::create(mConn.data(), mTextChanPath, QVariantMap());
commonTest(false);
}
void TestTextChan::cleanup()
{
- if (mChan != 0) {
- delete mChan;
- mChan = 0;
- }
received.clear();
removed.clear();
sent.clear();
--
1.5.6.5
More information about the telepathy-commits
mailing list