Commit 2c72e644 authored by Lasath Fernando's avatar Lasath Fernando Committed by David Edmundson

Renamed all the classes for clarity.

Added a new ConversationTarget class, that just picks apart a Tp::ContactPtr
parent 6352f8af
/*
<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 "kdetelepathychat_export.h"
#include "conversation-target.h"
#include <TelepathyQt4/AvatarData>
#include <TelepathyQt4/Presence>
#include <KDebug>
class ConversationTarget::ConversationTargetPrivate
{
public:
Tp::ContactPtr contact;
};
ConversationTarget::ConversationTarget(Tp::ContactPtr contact) :
d(new ConversationTargetPrivate)
{
kDebug();
if (contact) {
setupContactSignals(contact);
}
d->contact = contact;
}
void ConversationTarget::setupContactSignals(Tp::ContactPtr contact)
{
connect(contact.constData(), SIGNAL(aliasChanged(QString)), SIGNAL(nickChanged(QString)));
connect(contact.constData(), SIGNAL(avatarDataChanged(Tp::AvatarData)), SLOT(onAvatarDataChanged(Tp::AvatarData)));
connect(contact.constData(), SIGNAL(presenceChanged(Tp::Presence)), SLOT(onPresenceChanged(Tp::Presence)));
}
QIcon ConversationTarget::avatar() const
{
return QIcon(d->contact->avatarData().fileName);
}
QString ConversationTarget::nick() const
{
return d->contact->alias();
}
QIcon ConversationTarget::presenceIcon() const
{
return ChatWidget::iconForPresence(d->contact->presence().type());
}
void ConversationTarget::onPresenceChanged(Tp::Presence)
{
Q_EMIT presenceIconChanged(presenceIcon());
}
void ConversationTarget::onAvatarDataChanged(Tp::AvatarData)
{
Q_EMIT avatarChanged(avatar());
}
Tp::ContactPtr ConversationTarget::contact() const
{
return d->contact;
}
void ConversationTarget::setContact(Tp::ContactPtr contact)
{
if (d->contact) {
removeContactSignals(d->contact);
}
d->contact = contact;
setupContactSignals(d->contact);
Q_EMIT contactChanged(contact);
}
void ConversationTarget::removeContactSignals(Tp::ContactPtr contact)
{
disconnect(contact.constData(), SIGNAL(aliasChanged(QString)), this, SIGNAL(nickChanged(QString)));
disconnect(contact.constData(), SIGNAL(avatarDataChanged(Tp::AvatarData)), this, SLOT(onAvatarDataChanged(Tp::AvatarData)));
disconnect(contact.constData(), SIGNAL(presenceChanged(Tp::Presence)), this, SLOT(onPresenceChanged(Tp::Presence)));
}
ConversationTarget::~ConversationTarget()
{
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 CONVERSATION_TARGET_H
#define CONVERSATION_TARGET_H
#include <QObject>
#include <TelepathyQt4/Contact>
#include "chat-widget.h"
#include "kdetelepathychat_export.h"
class KDE_TELEPATHY_CHAT_EXPORT ConversationTarget : public QObject
{
Q_OBJECT
Q_PROPERTY(QIcon avatar READ avatar NOTIFY avatarChanged);
Q_PROPERTY(QString nick READ nick NOTIFY nickChanged);
Q_PROPERTY(QIcon presenceIcon READ presenceIcon NOTIFY presenceIconChanged);
//turns out you can't have non QObjects as properties
// Q_PROPERTY(Tp::ContactPtr contact READ contact WRITE setContact NOTIFY contactChanged);
public:
ConversationTarget( Tp::ContactPtr contact = Tp::ContactPtr());
virtual ~ConversationTarget();
QIcon avatar() const;
QString nick() const;
QIcon presenceIcon() const;
Tp::ContactPtr contact() const;
void setContact(Tp::ContactPtr contact);
Q_SIGNALS:
void avatarChanged(QIcon avatar);
void nickChanged(QString nick);
void presenceIconChanged(QIcon icon);
void contactChanged(Tp::ContactPtr contact);
private Q_SLOTS:
void onAvatarDataChanged ( Tp::AvatarData );
void onPresenceChanged ( Tp::Presence );
private:
void setupContactSignals(Tp::ContactPtr contact);
void removeContactSignals(Tp::ContactPtr contact);
class ConversationTargetPrivate;
ConversationTargetPrivate *d;
};
#endif // CONVERSATION_TARGET_H
......@@ -19,73 +19,53 @@
#include "conversation.h"
#include "conversation-model.h"
#include "messages-model.h"
#include <TelepathyQt4/TextChannel>
#include <KDebug>
#include "chat-widget.h"
#include "conversation-target.h"
class Conversation::ConversationPrivate
{
public:
ConversationModel* model;
MessagesModel* model;
ConversationTarget* target;
Tp::AccountPtr account;
Tp::ContactPtr contact;
};
Conversation::Conversation ( Tp::TextChannelPtr channel, Tp::AccountPtr account ) :
d ( new ConversationPrivate )
Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
d (new ConversationPrivate)
{
kDebug();
d->model = new ConversationModel();
d->model->setTextChannel ( channel );
d->model = new MessagesModel();
d->model->setTextChannel(channel);
d->account = account;
d->contact = channel->targetContact();
d->target = new ConversationTarget(channel->targetContact());
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)));
d->account = account;
}
Conversation::Conversation ( QObject* parent ) : QObject ( parent )
Conversation::Conversation(QObject* parent) : QObject(parent)
{
kError() << "Conversation should not be created directly. Use ConversationWatcher instead.";
Q_ASSERT(false);
}
ConversationModel* Conversation::model() const
MessagesModel* Conversation::model() const
{
return d->model;
}
QIcon Conversation::avatar() const
{
return QIcon(d->contact->avatarData().fileName);
}
QString Conversation::nick() const
{
return d->contact->alias();
}
QIcon Conversation::presenceIcon() const
ConversationTarget* Conversation::target() const
{
return ChatWidget::iconForPresence(d->contact->presence().type());
return d->target;
}
Conversation::~Conversation()
{
kDebug();
delete d->model;
}
void Conversation::onPresenceChanged ( Tp::Presence )
{
Q_EMIT presenceIconChanged(presenceIcon());
}
void Conversation::onAvatarDataChanged ( Tp::AvatarData )
{
Q_EMIT avatarChanged(avatar());
delete d->target;
delete d;
}
......@@ -26,42 +26,31 @@
#include <QObject>
#include <TelepathyQt4/Account>
#include <TelepathyQt4/TextChannel>
#include "conversation-model.h"
// #include "conversation-model.h"
#include <KIcon>
#include "conversation-target.h"
class ConversationModel;
class ConversationTarget;
class MessagesModel;
class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject
{
Q_OBJECT
Q_PROPERTY(ConversationModel* model READ model NOTIFY modelChanged)
Q_PROPERTY(MessagesModel* model READ model NOTIFY modelChanged);
Q_PROPERTY(ConversationTarget* target READ target NOTIFY targetChanged);
Q_PROPERTY(QIcon avatar READ avatar NOTIFY avatarChanged);
Q_PROPERTY(QString nick READ nick NOTIFY nickChanged);
Q_PROPERTY(QIcon presenceIcon READ presenceIcon NOTIFY presenceIconChanged);
public:
Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
Conversation(QObject* parent = 0);
virtual ~Conversation();
ConversationModel* model() const;
QIcon avatar() const;
QString nick() const;
QIcon presenceIcon() const;
MessagesModel* model() const;
ConversationTarget* target() const;
Q_SIGNALS:
void modelChanged(ConversationModel* newModel);
void avatarChanged(QIcon avatar);
void nickChanged(QString nick);
void presenceIconChanged(QIcon icon);
private Q_SLOTS:
void onAvatarDataChanged ( Tp::AvatarData );
void onPresenceChanged ( Tp::Presence );
// void onAliasChanged ( Tp::AvatarData );
void modelChanged(MessagesModel* newModel);
void targetChanged(ConversationTarget* target);
private:
class ConversationPrivate;
......
......@@ -19,22 +19,24 @@
#include "conversations-model.h"
#include "conversation-watcher.h"
#include "conversation.h"
#include "telepathy-text-observer.h"
#include <KDebug>
class ConversationsModel::ConversationsModelPrivate
{
public:
ConversationWatcher watcher;
TelepathyTextObserver watcher;
QList<Conversation*> data;
};
QVariant ConversationsModel::data ( const QModelIndex& index, int role ) const
{
QVariant result();
QVariant result;
if(index.row() >= 0 && index.row() < d->data.count()) {
Q_ASSERT(role == ConversationRole);
return QVariant::fromValue<QObject*>(d->data[index.row()]);
result = QVariant::fromValue<QObject*>(d->data[index.row()]);
kDebug() << "returning value " << result;
}
return result;
}
......
......@@ -18,7 +18,7 @@
*/
#include "conversation-model.h"
#include "messages-model.h"
#include <KDebug>
#include <TelepathyQt4/ReceivedMessage>
......@@ -37,13 +37,13 @@ public:
} type;
};
class ConversationModel::ConversationModelPrivate {
class MessagesModel::ConversationModelPrivate {
public:
Tp::TextChannelPtr textChannel;
QList<MessageItem> messages;
};
ConversationModel::ConversationModel(QObject* parent):
MessagesModel::MessagesModel(QObject* parent):
QAbstractListModel(parent),
d(new ConversationModelPrivate)
{
......@@ -57,12 +57,12 @@ ConversationModel::ConversationModel(QObject* parent):
setRoleNames(roles);
}
Tp::TextChannelPtr ConversationModel::textChannel()
Tp::TextChannelPtr MessagesModel::textChannel()
{
return d->textChannel;
}
bool ConversationModel::verifyPendingOperation ( Tp::PendingOperation* op )
bool MessagesModel::verifyPendingOperation ( Tp::PendingOperation* op )
{
bool success = !op->isError();
if(!success) {
......@@ -71,7 +71,7 @@ bool ConversationModel::verifyPendingOperation ( Tp::PendingOperation* op )
return success;
}
void ConversationModel::setupChannelSignals(Tp::TextChannelPtr channel)
void MessagesModel::setupChannelSignals(Tp::TextChannelPtr channel)
{
QObject::connect(channel.constData(),
SIGNAL(messageReceived(Tp::ReceivedMessage)),
......@@ -81,7 +81,7 @@ void ConversationModel::setupChannelSignals(Tp::TextChannelPtr channel)
SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
}
void ConversationModel::setTextChannel(Tp::TextChannelPtr channel)
void MessagesModel::setTextChannel(Tp::TextChannelPtr channel)
{
kDebug();
setupChannelSignals(channel);
......@@ -94,7 +94,7 @@ void ConversationModel::setTextChannel(Tp::TextChannelPtr channel)
textChannelChanged(channel);
}
void ConversationModel::onMessageReceived(Tp::ReceivedMessage message)
void MessagesModel::onMessageReceived(Tp::ReceivedMessage message)
{
kDebug();
beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
......@@ -110,7 +110,7 @@ void ConversationModel::onMessageReceived(Tp::ReceivedMessage message)
endInsertRows();
}
void ConversationModel::onMessageSent(Tp::Message message, Tp::MessageSendingFlags flags, QString token)
void MessagesModel::onMessageSent(Tp::Message message, Tp::MessageSendingFlags flags, QString token)
{
Q_UNUSED(flags);
Q_UNUSED(token);
......@@ -127,7 +127,7 @@ void ConversationModel::onMessageSent(Tp::Message message, Tp::MessageSendingFla
endInsertRows();
}
QVariant ConversationModel::data(const QModelIndex& index, int role) const
QVariant MessagesModel::data(const QModelIndex& index, int role) const
{
kDebug();
QVariant result;
......@@ -156,7 +156,7 @@ QVariant ConversationModel::data(const QModelIndex& index, int role) const
return result;
}
int ConversationModel::rowCount(const QModelIndex& parent) const
int MessagesModel::rowCount(const QModelIndex& parent) const
{
kDebug() << "size =" << d->messages.size();
Q_UNUSED(parent);
......@@ -164,7 +164,7 @@ int ConversationModel::rowCount(const QModelIndex& parent) const
return d->messages.size();
}
Tp::PendingSendMessage* ConversationModel::sendNewMessage ( QString message )
Tp::PendingSendMessage* MessagesModel::sendNewMessage ( QString message )
{
Tp::PendingSendMessage* msg = 0;
if(message.isEmpty()) {
......@@ -177,7 +177,7 @@ Tp::PendingSendMessage* ConversationModel::sendNewMessage ( QString message )
return msg;
}
void ConversationModel::removeChannelSignals(Tp::TextChannelPtr channel)
void MessagesModel::removeChannelSignals(Tp::TextChannelPtr channel)
{
QObject::disconnect(channel.constData(),
SIGNAL(messageReceived(Tp::ReceivedMessage)),
......@@ -191,10 +191,10 @@ void ConversationModel::removeChannelSignals(Tp::TextChannelPtr channel)
);
}
ConversationModel::~ConversationModel()
MessagesModel::~MessagesModel()
{
kDebug();
delete d;
}
#include "moc_conversation-model.cpp"
#include "moc_messages-model.cpp"
/*
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2011 Lasath Fernando <kde@lasath.org>
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 CONVERSATION_MODEL_H
#define CONVERSATION_MODEL_H
#include "kdetelepathychat_export.h"
#include <QAbstractItemModel>
#include <TelepathyQt4/TextChannel>
class KDE_TELEPATHY_CHAT_EXPORT ConversationModel : public QAbstractListModel
{
Q_OBJECT
// Q_PROPERTY(Tp::TextChannelPtr textChannel
// READ textChannel
// WRITE setTextChannel
// NOTIFY textChannelChanged
// )
public:
ConversationModel(QObject* parent = 0);
virtual ~ConversationModel();
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);
public Q_SLOTS:
Tp::PendingSendMessage* sendNewMessage(QString message);
private Q_SLOTS:
void onMessageReceived(Tp::ReceivedMessage);
void onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString);
bool verifyPendingOperation(Tp::PendingOperation* op);
private:
void setupChannelSignals(Tp::TextChannelPtr channel);
void removeChannelSignals(Tp::TextChannelPtr channel);
class ConversationModelPrivate;
ConversationModelPrivate *d;
};
#endif // CONVERSATION_MODEL_H
......@@ -18,13 +18,13 @@
*/
#include "conversation-watcher.h"
#include "telepathy-text-observer.h"
#include "conversation.h"
#include <KDebug>
#include <TelepathyQt4/ChannelClassSpec>
#include <TelepathyQt4/TextChannel>
#include "conversation.h"
#include <TelepathyQt4/ClientRegistrar>
......@@ -35,7 +35,7 @@ static inline Tp::ChannelClassSpecList channelClassList()
<< Tp::ChannelClassSpec::textChatroom();
}
class ConversationWatcher::ConversationClientObserver :
class TelepathyTextObserver::ConversationClientObserver :
public Tp::AbstractClientObserver
{
public:
......@@ -64,17 +64,21 @@ public:
m_parent->newConversation(con);
}
ConversationClientObserver(ConversationWatcher *parent) :
ConversationClientObserver(TelepathyTextObserver
*parent) :
AbstractClientObserver(channelClassList()),
m_parent(parent)
{
}
ConversationWatcher *m_parent;
TelepathyTextObserver
*m_parent;
Tp::ClientRegistrarPtr registrar;
};
ConversationWatcher::ConversationWatcher() :
TelepathyTextObserver
::TelepathyTextObserver
() :
d(new ConversationClientObserver(this))
{
kDebug();
......@@ -113,8 +117,10 @@ ConversationWatcher::ConversationWatcher() :
}
ConversationWatcher::~ConversationWatcher()
TelepathyTextObserver
::~TelepathyTextObserver
()
{
}
#include "moc_conversation-watcher.cpp"
// #include "moc_conversation-watcher.cpp"
......@@ -18,21 +18,21 @@
*/
#ifndef CONVERSATION_WATCHER_H
#define CONVERSATION_WATCHER_H
#ifndef TELEPATHY_TEXT_OBSERVER_H
#define TELEPATHY_TEXT_OBSERVER_H
#include "kdetelepathychat_export.h"
#include <TelepathyQt4/AbstractClient>
class Conversation;
class KDE_TELEPATHY_CHAT_EXPORT ConversationWatcher : public QObject
class KDE_TELEPATHY_CHAT_EXPORT TelepathyTextObserver : public QObject
{
Q_OBJECT
public:
ConversationWatcher();
~ConversationWatcher();
TelepathyTextObserver();
~TelepathyTextObserver();
Q_SIGNALS:
void newConversation(Conversation *con);
......
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