Commit 58b79324 authored by Lasath Fernando's avatar Lasath Fernando Committed by David Edmundson
Browse files

Made Conversation inherit Queable and made the chat plasmoid in QML to get it to popout properly.

parent 7df64f2b
/*
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2012 <copyright holder> <email>
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
......@@ -19,22 +18,25 @@
#include "conversation-que-manager.h"
#include <KDebug>
Queable::Queable(ConversationQueManager* que)
void Queable::push()
{
if(que) {
m_queManager = que;
} else {
m_queManager = ConversationQueManager::instance();
if(!m_queManager->que.contains(this)) {
m_queManager->que.append(this);
}
}
void Queable::push()
Queable::~Queable()
{
if(!m_queManager->que.contains(this)) {
m_queManager->que.append(this);
}
Queable::Queable(ConversationQueManager* que)
: m_queManager(que)
{
if(!que) {
m_queManager = ConversationQueManager::instance();
}
}
......@@ -43,7 +45,7 @@ ConversationQueManager* ConversationQueManager::instance()
static ConversationQueManager* m_instance = 0;
if(!m_instance) {
m_instance = ConversationQueManager();
m_instance = new ConversationQueManager();
}
return m_instance;
......@@ -51,15 +53,20 @@ ConversationQueManager* ConversationQueManager::instance()
ConversationQueManager::ConversationQueManager(QObject* parent): QObject(parent)
{
kDebug();
//FIXME: think of a good name for this. What did Kopete call it?
m_gloablAction = new KAction("cycle-unread-conversations");
m_gloablAction->setGlobalShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_I);
m_gloablAction = new KAction(this);
m_gloablAction->setObjectName(QLatin1String("next-unread-conversation"));
m_gloablAction->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_J), KAction::ActiveShortcut | KAction::DefaultShortcut, KAction::NoAutoloading);
connect(m_gloablAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), SLOT(popConversation()));
}
void ConversationQueManager::popConversation()
{
kDebug();
if(!que.isEmpty()) {
que.takeLast()->pop();
}
......
/*
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2012 <copyright holder> <email>
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
......@@ -24,21 +23,24 @@
#include <QtCore/QObject>
#include <KAction>
class ConversationQueManager;
class Queable {
friend class ConversationQueManager;
public:
explicit Queable(ConversationQueManager* que = 0);
Queable(ConversationQueManager* que = 0);
private:
ConversationQueManager* m_queManager;
protected:
virtual ~Queable();
void push();
virtual void pop() = 0;
};
class ConversationQueManager : public QObject
{
Q_OBJECT
friend class Queable;
public:
static ConversationQueManager* instance();
......
......@@ -29,10 +29,11 @@ class Conversation::ConversationPrivate
public:
MessagesModel* model;
ConversationTarget* target;
Tp::AccountPtr account;
// Tp::AccountPtr account;
};
Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
Queable(),
d (new ConversationPrivate)
{
kDebug();
......@@ -42,7 +43,8 @@ Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
d->target = new ConversationTarget(channel->targetContact());
d->account = account;
connect(model(), SIGNAL(unreadCountChanged(int)), SLOT(onUnreadMessagesChanged()));
// d->account = account;
}
Conversation::Conversation(QObject* parent) : QObject(parent)
......@@ -61,6 +63,16 @@ ConversationTarget* Conversation::target() const
return d->target;
}
void Conversation::onUnreadMessagesChanged()
{
push();
}
void Conversation::pop()
{
Q_EMIT popoutRequested();
}
Conversation::~Conversation()
{
kDebug();
......
......@@ -27,10 +27,11 @@
#include <TelepathyQt/TextChannel>
// #include "conversation-model.h"
#include <KIcon>
#include "conversation-que-manager.h"
class ConversationTarget;
class MessagesModel;
class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject
class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject, public Queable
{
Q_OBJECT
......@@ -49,6 +50,11 @@ public:
Q_SIGNALS:
void modelChanged(MessagesModel* newModel);
void targetChanged(ConversationTarget* target);
void popoutRequested();
private Q_SLOTS:
virtual void pop();
void onUnreadMessagesChanged();
private:
class ConversationPrivate;
......
......@@ -37,7 +37,7 @@ public:
} type;
MessageItem(QString user, QString text, QDateTime time, MessageType type, QString messageId)
: user(user), text(text), time(time), type(type), id(messageId)
: user(user), text(text), time(time), id(messageId), type(type)
{
if(this->text.endsWith(QLatin1String("\n"))) {
this->text.chop(1);
......@@ -252,7 +252,7 @@ void MessagesModel::setVisibleToUser(bool visible)
if(d->visible != visible) {
d->visible = visible;
Q_EMIT visibleToUserChanged(visible);
Q_EMIT visibleToUserChanged(d->visible);
}
if(visible) {
......@@ -276,6 +276,9 @@ void MessagesModel::printallmessages()
Q_FOREACH(MessageItem msg, d->messages) {
kDebug() << msg.text;
}
beginResetModel();
d->messages.clear();
endResetModel();
}
#include "moc_messages-model.cpp"
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