Commit 6352f8af authored by Lasath Fernando's avatar Lasath Fernando Committed by David Edmundson

Created a ConversationsModel class that contains a list of Active Conversations.

Changed plasmoid to display said list.
parent 2e062a5d
......@@ -44,7 +44,7 @@ Conversation::Conversation ( Tp::TextChannelPtr channel, Tp::AccountPtr account
d->account = account;
d->contact = channel->targetContact();
connect(d->contact.constData(), SIGNAL(aliasChanged(QString)), SIGNAL(onNickChanged(QString)));
connect(d->contact.constData(), SIGNAL(aliasChanged(QString)), SIGNAL(nickChanged(QString)));
connect(d->contact.constData(), SIGNAL(avatarDataChanged(Tp::AvatarData)), SLOT(onAvatarDataChanged(Tp::AvatarData)));
connect(d->contact.constData(), SIGNAL(presenceChanged(Tp::Presence)), SLOT(onPresenceChanged(Tp::Presence)));
}
......@@ -59,9 +59,9 @@ ConversationModel* Conversation::model() const
return d->model;
}
KIcon Conversation::avatar() const
QIcon Conversation::avatar() const
{
return KIcon(d->contact->avatarData().fileName);
return QIcon(d->contact->avatarData().fileName);
}
QString Conversation::nick() const
......@@ -69,7 +69,7 @@ QString Conversation::nick() const
return d->contact->alias();
}
KIcon Conversation::presenceIcon() const
QIcon Conversation::presenceIcon() const
{
return ChatWidget::iconForPresence(d->contact->presence().type());
}
......@@ -80,3 +80,12 @@ Conversation::~Conversation()
delete d->model;
}
void Conversation::onPresenceChanged ( Tp::Presence )
{
Q_EMIT presenceIconChanged(presenceIcon());
}
void Conversation::onAvatarDataChanged ( Tp::AvatarData )
{
Q_EMIT avatarChanged(avatar());
}
......@@ -36,9 +36,9 @@ Q_OBJECT
Q_PROPERTY(ConversationModel* model READ model NOTIFY modelChanged)
Q_PROPERTY(KIcon avatar READ avatar NOTIFY avatarChanged);
Q_PROPERTY(QIcon avatar READ avatar NOTIFY avatarChanged);
Q_PROPERTY(QString nick READ nick NOTIFY nickChanged);
Q_PROPERTY(KIcon presenceIcon READ presenceIcon NOTIFY presenceIconChanged);
Q_PROPERTY(QIcon presenceIcon READ presenceIcon NOTIFY presenceIconChanged);
public:
Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
......@@ -47,9 +47,9 @@ public:
ConversationModel* model() const;
KIcon avatar() const;
QIcon avatar() const;
QString nick() const;
KIcon presenceIcon() const;
QIcon presenceIcon() const;
Q_SIGNALS:
void modelChanged(ConversationModel* newModel);
......@@ -61,7 +61,7 @@ Q_SIGNALS:
private Q_SLOTS:
void onAvatarDataChanged ( Tp::AvatarData );
void onPresenceChanged ( Tp::Presence );
void onAliasChanged ( Tp::AvatarData );
// void onAliasChanged ( Tp::AvatarData );
private:
class ConversationPrivate;
......
/*
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2011 <copyright holder> <email>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "conversations-model.h"
#include "conversation-watcher.h"
#include "conversation.h"
class ConversationsModel::ConversationsModelPrivate
{
public:
ConversationWatcher watcher;
QList<Conversation*> data;
};
QVariant ConversationsModel::data ( const QModelIndex& index, int role ) const
{
QVariant result();
if(index.row() >= 0 && index.row() < d->data.count()) {
Q_ASSERT(role == ConversationRole);
return QVariant::fromValue<QObject*>(d->data[index.row()]);
}
return result;
}
int ConversationsModel::rowCount ( const QModelIndex& parent ) const
{
return d->data.count();
}
ConversationsModel::ConversationsModel() :
d(new ConversationsModelPrivate)
{
QHash<int, QByteArray> roles;
roles[ConversationRole] = "conversation";
setRoleNames(roles);
QObject::connect(&d->watcher, SIGNAL(newConversation(Conversation*)), SLOT(onInconmingConversation(Conversation*)));
}
void ConversationsModel::onInconmingConversation ( Conversation* convo )
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
d->data.append(convo);
endInsertRows();
}
ConversationsModel::~ConversationsModel()
{
delete d;
}
/*
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2011 <copyright holder> <email>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CONVERSATIONS_MODEL_H
#define CONVERSATIONS_MODEL_H
#include <QAbstractListModel>
#include "kdetelepathychat_export.h"
class Conversation;
class KDE_TELEPATHY_CHAT_EXPORT ConversationsModel : public QAbstractListModel
{
Q_OBJECT
public:
ConversationsModel();
virtual ~ConversationsModel();
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
enum role {
ConversationRole = Qt::UserRole
};
private:
class ConversationsModelPrivate;
ConversationsModelPrivate* d;
private Q_SLOTS:
void onInconmingConversation(Conversation *convo);
};
#endif // CONVERSATIONS_MODEL_H
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