[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:20:46 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=c23e3d6
The following commit has been merged in the master branch:
commit c23e3d6519f750b14748a5fb599bc4b098ed1ec0
Author: Lasath Fernando <kde at lasath.org>
Date: Fri Nov 11 11:13:05 2011 +1100
Implemented data retrival for MessageModel.
---
lib/conversation-model.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++++-
lib/conversation-model.h | 44 ++++++++++++++--
2 files changed, 161 insertions(+), 6 deletions(-)
diff --git a/lib/conversation-model.cpp b/lib/conversation-model.cpp
index 6e47931..569d608 100644
--- a/lib/conversation-model.cpp
+++ b/lib/conversation-model.cpp
@@ -20,18 +20,139 @@
#include "conversation-model.h"
-ConversationModel::ConversationModel(QObject* parent): QAbstractListModel(parent)
+#include <KDebug>
+#include <TelepathyQt4/ReceivedMessage>
+
+struct MessageItem {
+ QString user;
+ QString text;
+ QDateTime time;
+
+ //FIXME : replace with Tp::ChannelTextMessageType
+ enum MessageType {
+ Incoming,
+ Outgoing,
+ Status
+ } type;
+};
+
+class ConversationModel::ConversationModelPrivate {
+public:
+ Tp::TextChannelPtr textChannel;
+ QList<MessageItem> messages;
+};
+
+ConversationModel::ConversationModel(QObject* parent):
+ QAbstractListModel(parent),
+ d(new ConversationModelPrivate)
+{
+}
+
+Tp::TextChannelPtr ConversationModel::textChannel()
+{
+ return d->textChannel;
+}
+
+void ConversationModel::setupChannelSignals(Tp::TextChannelPtr channel)
+{
+ QObject::connect(channel.constData(),
+ SIGNAL(messageReceived(Tp::ReceivedMessage)),
+ SLOT(messageReceived(Tp::ReceivedMessage)));
+ QObject::connect(channel.constData(),
+ SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
+ SLOT(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
+}
+
+void ConversationModel::setTextChannel(Tp::TextChannelPtr channel)
+{
+ setupChannelSignals(channel);
+ if(d->textChannel) {
+ removeChannelSignals(channel);
+ }
+
+ d->textChannel = channel; //NOTE : is it necessary to delete the old one?
+
+ textChannelChanged(channel);
+}
+
+void ConversationModel::onMessageReceived(Tp::ReceivedMessage message)
+{
+ beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
+
+ MessageItem newMessage = {
+ message.sender()->alias(),
+ message.text(),
+ message.sent(),
+ MessageItem::Incoming
+ };
+
+ d->messages.append(newMessage);
+ endInsertRows();
+}
+
+void ConversationModel::onMessageSent(Tp::Message message, Tp::MessageSendingFlags flags, QString token)
{
+ Q_UNUSED(flags);
+ Q_UNUSED(token);
+ beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
+ MessageItem newMessage = {
+ tr("Me"),
+ message.text(),
+ message.sent(),
+ MessageItem::Outgoing
+ };
+
+ d->messages.append(newMessage);
+ endInsertRows();
}
QVariant ConversationModel::data(const QModelIndex& index, int role) const
{
+ QVariant result;
+
+ if(!index.isValid()) {
+ kError() << "Attempting to access data at invalid index (" << index << ")";
+ } else {
+ MessageItem* requestedData = &d->messages[index.row()];
+ switch(role) {
+ case UserRole:
+ result = requestedData->user;
+ break;
+ case TextRole:
+ result = requestedData->text;
+ break;
+ case TypeRole:
+ result = requestedData->type;
+ break;
+ case TimeRole:
+ result = requestedData->time;
+ break;
+ };
+ }
+
+ return result;
}
int ConversationModel::rowCount(const QModelIndex& parent) const
{
+ Q_UNUSED(parent);
+ return d->messages.count();
+}
+void ConversationModel::removeChannelSignals(Tp::TextChannelPtr channel)
+{
+ QObject::disconnect(channel.constData(),
+ SIGNAL(messageReceived(Tp::ReceivedMessage)),
+ this,
+ SLOT(onMessageReceived(Tp::ReceivedMessage))
+ );
+ QObject::disconnect(channel.constData(),
+ SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
+ this,
+ SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString))
+ );
}
+#include "moc_conversation-model.cpp"
diff --git a/lib/conversation-model.h b/lib/conversation-model.h
index b6f8ce1..0706378 100644
--- a/lib/conversation-model.h
+++ b/lib/conversation-model.h
@@ -18,19 +18,53 @@
*/
-#ifndef CONVERSATIONMODEL_H
-#define CONVERSATIONMODEL_H
+#ifndef CONVERSATION_MODEL_H
+#define CONVERSATION_MODEL_H
+
+#include "kdetelepathychat_export.h"
#include <QAbstractItemModel>
+#include <TelepathyQt4/TextChannel>
-class ConversationModel : public QAbstractListModel
+class KDE_TELEPATHY_CHAT_EXPORT ConversationModel : public QAbstractListModel
{
+Q_OBJECT
+// Q_PROPERTY(Tp::TextChannelPtr textChannel
+// READ textChannel
+// WRITE setTextChannel
+// NOTIFY textChannelChanged
+// )
public:
- explicit ConversationModel(QObject* parent = 0);
+ ConversationModel(QObject* parent = 0);
+
+ enum Roles {
+ UserRole = Qt::UserRole,
+ TextRole,
+ TypeRole,
+ TimeRole
+ };
+
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
+
+ Tp::TextChannelPtr textChannel();
+ void setTextChannel(Tp::TextChannelPtr channel);
+
+Q_SIGNALS:
+ void textChannelChanged(Tp::TextChannelPtr newChannel);
+
+private Q_SLOTS:
+ void onMessageReceived(Tp::ReceivedMessage);
+ void onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString);
+
+private:
+ void setupChannelSignals(Tp::TextChannelPtr channel);
+ void removeChannelSignals(Tp::TextChannelPtr channel);
+
+ class ConversationModelPrivate;
+ ConversationModelPrivate *d;
};
-#endif // CONVERSATIONMODEL_H
+#endif // CONVERSATION_MODEL_H
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list