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

Added a LineEdit to the plasmoid and a sendNewMessage slot to ConversationModel.

Also made the ListView auto-scroll
parent 249b2658
......@@ -23,12 +23,14 @@
#include <TelepathyQt4/TextChannel>
#include <KDebug>
#include "chat-widget.h"
class Conversation::ConversationPrivate
{
public:
ConversationModel* model;
Tp::AccountPtr account;
Tp::ContactPtr contact;
};
Conversation::Conversation ( Tp::TextChannelPtr channel, Tp::AccountPtr account ) :
......@@ -40,11 +42,16 @@ Conversation::Conversation ( Tp::TextChannelPtr channel, Tp::AccountPtr account
d->model->setTextChannel ( channel );
d->account = account;
d->contact = channel->targetContact();
connect(d->contact.constData(), SIGNAL(aliasChanged(QString)), SIGNAL(onNickChanged(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)));
}
Conversation::Conversation ( QObject* parent ) : QObject ( parent )
{
kError() << "Conversation should not be created directly. Use ConversationWater instead.";
kError() << "Conversation should not be created directly. Use ConversationWatcher instead.";
}
ConversationModel* Conversation::model() const
......@@ -52,6 +59,21 @@ ConversationModel* Conversation::model() const
return d->model;
}
KIcon Conversation::avatar() const
{
return KIcon(d->contact->avatarData().fileName);
}
QString Conversation::nick() const
{
return d->contact->alias();
}
KIcon Conversation::presenceIcon() const
{
return ChatWidget::iconForPresence(d->contact->presence().type());
}
Conversation::~Conversation()
{
kDebug();
......
......@@ -27,13 +27,19 @@
#include <TelepathyQt4/Account>
#include <TelepathyQt4/TextChannel>
#include "conversation-model.h"
#include <KIcon>
class ConversationModel;
class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject
{
Q_OBJECT
Q_PROPERTY(ConversationModel* model READ model NOTIFY modelChanged)
Q_PROPERTY(KIcon avatar READ avatar NOTIFY avatarChanged);
Q_PROPERTY(QString nick READ nick NOTIFY nickChanged);
Q_PROPERTY(KIcon presenceIcon READ presenceIcon NOTIFY presenceIconChanged);
public:
Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
Conversation(QObject* parent = 0);
......@@ -41,9 +47,22 @@ public:
ConversationModel* model() const;
KIcon avatar() const;
QString nick() const;
KIcon presenceIcon() 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 );
private:
class ConversationPrivate;
ConversationPrivate *d;
......
......@@ -62,6 +62,15 @@ Tp::TextChannelPtr ConversationModel::textChannel()
return d->textChannel;
}
bool ConversationModel::verifyPendingOperation ( Tp::PendingOperation* op )
{
bool success = !op->isError();
if(!success) {
kWarning() << op->errorName() + QLatin1Char(':') + op->errorMessage();
}
return success;
}
void ConversationModel::setupChannelSignals(Tp::TextChannelPtr channel)
{
QObject::connect(channel.constData(),
......@@ -80,7 +89,7 @@ void ConversationModel::setTextChannel(Tp::TextChannelPtr channel)
if(d->textChannel) {
removeChannelSignals(channel);
}
d->textChannel = channel;
d->textChannel = channel; //FIXME: check if channel is valid
textChannelChanged(channel);
}
......@@ -155,6 +164,19 @@ int ConversationModel::rowCount(const QModelIndex& parent) const
return d->messages.size();
}
Tp::PendingSendMessage* ConversationModel::sendNewMessage ( QString message )
{
Tp::PendingSendMessage* msg = 0;
if(message.isEmpty()) {
kWarning() << "Attempting to send empty string";
} else {
msg = d->textChannel->send(message);
connect(msg, SIGNAL(finished(Tp::PendingOperation*)), SLOT(verifyPendingOperation(Tp::PendingOperation*)));
}
return msg;
}
void ConversationModel::removeChannelSignals(Tp::TextChannelPtr channel)
{
QObject::disconnect(channel.constData(),
......
......@@ -56,9 +56,13 @@ public:
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);
......
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