diff options
author | Gustavo Pichorim Boiko <gustavo.boiko@collabora.co.uk> | 2011-05-04 06:58:08 -0700 |
---|---|---|
committer | Gustavo Pichorim Boiko <gustavo.boiko@collabora.co.uk> | 2011-05-04 06:58:08 -0700 |
commit | 5537a7cfd36c0860f72ba6a1190dd0b9e837fe12 (patch) | |
tree | 22ae307f2802c2995f7d3d42c052fed1657157ea | |
parent | 8c76132524320f9c375c668e865e8d3574109b27 (diff) | |
parent | 0ea58d1d47fa7cefdab1e244e0b83c67d5c220d4 (diff) |
Merge remote branch 'mbatle/pendingmessages'
Reviewed by: Gustavo Pichorim Boiko <gustavo.boiko@collabora.co.uk>
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/session-conversation-model.cpp | 56 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/session-conversation-model.h | 6 |
3 files changed, 49 insertions, 14 deletions
@@ -5,6 +5,7 @@ The "..." release. Enhancements: * Implement removeRows method in AbstractConversationModel + * Keep count of unread/missed messages in SessionConversationModel * ... Fixes: diff --git a/TelepathyQt4Yell/Models/session-conversation-model.cpp b/TelepathyQt4Yell/Models/session-conversation-model.cpp index 87e577a..7af29bf 100644 --- a/TelepathyQt4Yell/Models/session-conversation-model.cpp +++ b/TelepathyQt4Yell/Models/session-conversation-model.cpp @@ -41,12 +41,16 @@ struct TELEPATHY_QT4_YELL_MODELS_NO_EXPORT SessionConversationModel::Private { Private(const Tp::ContactPtr &self, const Tp::TextChannelPtr &channel) : mSelf(self), - mChannel(channel) + mChannel(channel), + mChannelQueueConnected(false), + mNumPendingMessages(0) { } Tp::ContactPtr mSelf; Tp::TextChannelPtr mChannel; + bool mChannelQueueConnected; + int mNumPendingMessages; }; SessionConversationModel::SessionConversationModel(const Tp::ContactPtr &self, const Tp::TextChannelPtr &channel, QObject *parent) @@ -54,6 +58,9 @@ SessionConversationModel::SessionConversationModel(const Tp::ContactPtr &self, c mPriv(new Private(self,channel)) { connect(mPriv->mChannel.data(), + SIGNAL(messageReceived(Tp::ReceivedMessage)), + SLOT(onMessageReceived(Tp::ReceivedMessage))); + connect(mPriv->mChannel.data(), SIGNAL(chatStateChanged(Tp::ContactPtr,Tp::ChannelChatState)), SLOT(onChatStateChanged(Tp::ContactPtr,Tp::ChannelChatState))); } @@ -87,14 +94,18 @@ Tp::ContactPtr SessionConversationModel::selfContact() const void SessionConversationModel::onMessageReceived(const Tp::ReceivedMessage &message) { - // TODO: For the moment skip if the message is a delivery report - // Later they could be used to report status on sent messages - if (message.messageType() != Tp::ChannelTextMessageTypeDeliveryReport) { - TextEventItem *item = new TextEventItem(message.sender(), mPriv->mSelf, - message.sent(), message.text(), message.messageType(), this); - addItem(item); + if (mPriv->mChannelQueueConnected) { + // TODO: For the moment skip if the message is a delivery report + // Later they could be used to report status on sent messages + if (message.messageType() != Tp::ChannelTextMessageTypeDeliveryReport) { + TextEventItem *item = new TextEventItem(message.sender(), mPriv->mSelf, + message.sent(), message.text(), message.messageType(), this); + addItem(item); + } + mPriv->mChannel->acknowledge(QList<Tp::ReceivedMessage>() << message); + } else { + emit numPendingMessagesChanged(); } - mPriv->mChannel->acknowledge(QList<Tp::ReceivedMessage>() << message); } void SessionConversationModel::onChatStateChanged(const Tp::ContactPtr &contact, Tp::ChannelChatState state) @@ -118,8 +129,7 @@ void SessionConversationModel::onChatStateChanged(const Tp::ContactPtr &contact, */ void SessionConversationModel::disconnectChannelQueue() { - disconnect(mPriv->mChannel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)), - this, SLOT(onMessageReceived(Tp::ReceivedMessage))); + mPriv->mChannelQueueConnected = false; } /** @@ -127,16 +137,34 @@ void SessionConversationModel::disconnectChannelQueue() */ void SessionConversationModel::connectChannelQueue() { - // reconnect the signal - connect(mPriv->mChannel.data(), - SIGNAL(messageReceived(Tp::ReceivedMessage)), - SLOT(onMessageReceived(Tp::ReceivedMessage))); + mPriv->mChannelQueueConnected = true; // flush the queue and enter all messages into the model // display messages already in queue + bool messagesReceived = false; foreach (Tp::ReceivedMessage message, mPriv->mChannel->messageQueue()) { onMessageReceived(message); + messagesReceived = true; } + + if (messagesReceived) { + qDebug() << "emiting numPendingMessagesChanged"; + emit numPendingMessagesChanged(); + } +} + +Q_INVOKABLE bool SessionConversationModel::channelQueueConnected() const +{ + return mPriv->mChannelQueueConnected; +} + +int SessionConversationModel::numPendingMessages() const +{ + if (!mPriv->mChannelQueueConnected && !mPriv->mChannel.isNull()) { + return mPriv->mChannel->messageQueue().count(); + } + + return 0; } } diff --git a/TelepathyQt4Yell/Models/session-conversation-model.h b/TelepathyQt4Yell/Models/session-conversation-model.h index 2a8acdd..e84a551 100644 --- a/TelepathyQt4Yell/Models/session-conversation-model.h +++ b/TelepathyQt4Yell/Models/session-conversation-model.h @@ -42,6 +42,7 @@ class TELEPATHY_QT4_YELL_MODELS_EXPORT SessionConversationModel : public Abstrac { Q_OBJECT Q_DISABLE_COPY(SessionConversationModel) + Q_PROPERTY(int numPendingMessages READ numPendingMessages NOTIFY numPendingMessagesChanged) public: explicit SessionConversationModel(const Tp::ContactPtr &self, const Tp::TextChannelPtr &channel, QObject *parent = 0); @@ -50,9 +51,14 @@ public: Q_INVOKABLE void sendMessage(const QString &text); Q_INVOKABLE void disconnectChannelQueue(); Q_INVOKABLE void connectChannelQueue(); + Q_INVOKABLE bool channelQueueConnected() const; + int numPendingMessages() const; Tp::ContactPtr selfContact() const; +Q_SIGNALS: + void numPendingMessagesChanged(); + protected Q_SLOTS: virtual void onChatStateChanged(const Tp::ContactPtr &contact, Tp::ChannelChatState state); |