Commit 249b2658 authored by Lasath Fernando's avatar Lasath Fernando Committed by David Edmundson

Made the plasmoid work

The plasmoid seems to ignore the first message sent to it, but everthing else displays fine.
parent 8c087676
......@@ -34,6 +34,8 @@ public:
Conversation::Conversation ( Tp::TextChannelPtr channel, Tp::AccountPtr account ) :
d ( new ConversationPrivate )
{
kDebug();
d->model = new ConversationModel();
d->model->setTextChannel ( channel );
......@@ -45,13 +47,14 @@ Conversation::Conversation ( QObject* parent ) : QObject ( parent )
kError() << "Conversation should not be created directly. Use ConversationWater instead.";
}
const ConversationModel* Conversation::model() const
ConversationModel* Conversation::model() const
{
return d->model;
}
Conversation::~Conversation()
{
kDebug();
delete d->model;
}
......@@ -32,14 +32,14 @@ class ConversationModel;
class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject
{
Q_OBJECT
Q_PROPERTY(const ConversationModel* model READ model NOTIFY modelChanged)
Q_PROPERTY(ConversationModel* model READ model NOTIFY modelChanged)
public:
Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
Conversation(QObject* parent = 0);
virtual ~Conversation();
const ConversationModel* model() const;
ConversationModel* model() const;
Q_SIGNALS:
void modelChanged(ConversationModel* newModel);
......
......@@ -47,6 +47,14 @@ ConversationModel::ConversationModel(QObject* parent):
QAbstractListModel(parent),
d(new ConversationModelPrivate)
{
kDebug();
QHash<int, QByteArray> roles;
roles[UserRole] = "user";
roles[TextRole] = "text";
roles[TimeRole] = "time";
roles[TypeRole] = "type";
setRoleNames(roles);
}
Tp::TextChannelPtr ConversationModel::textChannel()
......@@ -58,19 +66,20 @@ void ConversationModel::setupChannelSignals(Tp::TextChannelPtr channel)
{
QObject::connect(channel.constData(),
SIGNAL(messageReceived(Tp::ReceivedMessage)),
SLOT(messageReceived(Tp::ReceivedMessage)));
SLOT(onMessageReceived(Tp::ReceivedMessage)));
QObject::connect(channel.constData(),
SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
SLOT(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
}
void ConversationModel::setTextChannel(Tp::TextChannelPtr channel)
{
kDebug();
setupChannelSignals(channel);
if(d->textChannel) {
removeChannelSignals(channel);
}
d->textChannel = channel;
textChannelChanged(channel);
......@@ -78,12 +87,13 @@ void ConversationModel::setTextChannel(Tp::TextChannelPtr channel)
void ConversationModel::onMessageReceived(Tp::ReceivedMessage message)
{
kDebug();
beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
MessageItem newMessage = {
message.sender()->alias(),
message.text(),
message.sent(),
message.received(),
MessageItem::Incoming
};
......@@ -110,6 +120,7 @@ void ConversationModel::onMessageSent(Tp::Message message, Tp::MessageSendingFla
QVariant ConversationModel::data(const QModelIndex& index, int role) const
{
kDebug();
QVariant result;
if(!index.isValid()) {
......@@ -138,8 +149,10 @@ QVariant ConversationModel::data(const QModelIndex& index, int role) const
int ConversationModel::rowCount(const QModelIndex& parent) const
{
kDebug() << "size =" << d->messages.size();
Q_UNUSED(parent);
return d->messages.count();
return d->messages.size();
}
void ConversationModel::removeChannelSignals(Tp::TextChannelPtr channel)
......@@ -156,4 +169,10 @@ void ConversationModel::removeChannelSignals(Tp::TextChannelPtr channel)
);
}
ConversationModel::~ConversationModel()
{
kDebug();
delete d;
}
#include "moc_conversation-model.cpp"
......@@ -38,6 +38,7 @@ Q_OBJECT
public:
ConversationModel(QObject* parent = 0);
virtual ~ConversationModel();
enum Roles {
UserRole = Qt::UserRole,
......
......@@ -60,8 +60,8 @@ public:
Q_ASSERT(textChannel);
Conversation con(textChannel, account);
m_parent->newConversation(&con);
Conversation *con = new Conversation(textChannel, account);
m_parent->newConversation(con);
}
ConversationClientObserver(ConversationWatcher *parent) :
......@@ -113,7 +113,6 @@ ConversationWatcher::ConversationWatcher() :
}
ConversationWatcher::~ConversationWatcher()
{
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment