Commit 0e5931b7 authored by Lasath Fernando's avatar Lasath Fernando Committed by David Edmundson
Browse files

Made ConversationQueManager use d-pointers. Made MessagesModel Queable instead...

Made ConversationQueManager use d-pointers. Made MessagesModel Queable instead of Conversation, and updated the ui accordingly.
parent 58b79324
......@@ -20,16 +20,24 @@
#include "conversation-que-manager.h"
#include <KDebug>
void Queable::push()
class ConversationQueManager::ConversationQueManagerPrivate {
public:
QList<Queable*> que;
KAction* gloablAction;
};
void Queable::enqueSelf()
{
if(!m_queManager->que.contains(this)) {
m_queManager->que.append(this);
}
m_queManager->enque(this);
}
Queable::~Queable()
void Queable::removeSelfFromQue()
{
m_queManager->remove(this);
}
Queable::~Queable()
{
}
Queable::Queable(ConversationQueManager* que)
......@@ -51,23 +59,44 @@ ConversationQueManager* ConversationQueManager::instance()
return m_instance;
}
ConversationQueManager::ConversationQueManager(QObject* parent): QObject(parent)
ConversationQueManager::ConversationQueManager(QObject* parent):
QObject(parent),
d(new ConversationQueManagerPrivate)
{
kDebug();
//FIXME: think of a good name for this. What did Kopete call it?
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);
d->gloablAction = new KAction(this);
d->gloablAction->setObjectName(QLatin1String("next-unread-conversation"));
d->gloablAction->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_I)/*, KAction::ActiveShortcut | KAction::DefaultShortcut, KAction::NoAutoloading*/);
connect(m_gloablAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), SLOT(popConversation()));
connect(d->gloablAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), SLOT(dequeNext()));
}
void ConversationQueManager::popConversation()
void ConversationQueManager::dequeNext()
{
kDebug();
if(!que.isEmpty()) {
que.takeLast()->pop();
if(!d->que.isEmpty()) {
d->que.takeLast()->selfDequed();
}
}
void ConversationQueManager::enque(Queable* item)
{
if(!d->que.contains(item)) {
d->que.append(item);
}
}
void ConversationQueManager::remove(Queable* item)
{
if(d->que.contains(item)) {
d->que.removeAll(item);
}
}
\ No newline at end of file
}
ConversationQueManager::~ConversationQueManager()
{
delete d;
}
......@@ -24,32 +24,41 @@
#include <KAction>
class ConversationQueManager;
class Queable {
friend class ConversationQueManager;
public:
Queable(ConversationQueManager* que = 0);
private:
ConversationQueManager* m_queManager;
class Queable
{
friend class ConversationQueManager;
protected:
Queable(ConversationQueManager* que = 0);
virtual ~Queable();
void push();
virtual void pop() = 0;
void enqueSelf();
void removeSelfFromQue();
virtual void selfDequed() = 0;
private:
ConversationQueManager* m_queManager;
};
class ConversationQueManager : public QObject
{
Q_OBJECT
friend class Queable;
public:
static ConversationQueManager* instance();
void enque(Queable* item);
void remove(Queable* item);
public Q_SLOTS:
void dequeNext();
private:
QList<Queable*> que;
KAction* m_gloablAction;
explicit ConversationQueManager(QObject* parent = 0);
private Q_SLOTS:
void popConversation();
virtual ~ConversationQueManager();
class ConversationQueManagerPrivate;
ConversationQueManagerPrivate *d;
};
#endif // CONVERSATION_QUE_MANAGER_H
......@@ -33,7 +33,6 @@ public:
};
Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
Queable(),
d (new ConversationPrivate)
{
kDebug();
......@@ -43,7 +42,7 @@ Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
d->target = new ConversationTarget(channel->targetContact());
connect(model(), SIGNAL(unreadCountChanged(int)), SLOT(onUnreadMessagesChanged()));
// connect(model(), SIGNAL(unreadCountChanged(int)), SLOT(onUnreadMessagesChanged()));
// d->account = account;
}
......@@ -63,15 +62,15 @@ ConversationTarget* Conversation::target() const
return d->target;
}
void Conversation::onUnreadMessagesChanged()
{
push();
}
void Conversation::pop()
{
Q_EMIT popoutRequested();
}
// void Conversation::onUnreadMessagesChanged()
// {
// enqueSelf();
// }
//
// void Conversation::selfDequed()
// {
// Q_EMIT popoutRequested();
// }
Conversation::~Conversation()
{
......
......@@ -31,12 +31,13 @@
class ConversationTarget;
class MessagesModel;
class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject, public Queable
class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject
{
Q_OBJECT
Q_PROPERTY(MessagesModel* model READ model NOTIFY modelChanged);
Q_PROPERTY(ConversationTarget* target READ target NOTIFY targetChanged);
//TODO: rename this to messages
Q_PROPERTY(MessagesModel* model READ model NOTIFY modelChanged);
public:
Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
......@@ -50,11 +51,6 @@ public:
Q_SIGNALS:
void modelChanged(MessagesModel* newModel);
void targetChanged(ConversationTarget* target);
void popoutRequested();
private Q_SLOTS:
virtual void pop();
void onUnreadMessagesChanged();
private:
class ConversationPrivate;
......
......@@ -142,6 +142,7 @@ void MessagesModel::onMessageReceived(Tp::ReceivedMessage message)
if(d->visible) {
acknowledgeAllMessages();
} else {
enqueSelf();
Q_EMIT unreadCountChanged(unreadCount);
}
}
......@@ -243,9 +244,15 @@ void MessagesModel::acknowledgeAllMessages()
kDebug() << "Conversation Visible, Acknowledging " << que.size() << " messages.";
d->textChannel->acknowledge(que);
removeSelfFromQue();
Q_EMIT unreadCountChanged(que.size());
}
void MessagesModel::selfDequed()
{
Q_EMIT popoutRequested();
}
void MessagesModel::setVisibleToUser(bool visible)
{
kDebug() << visible;
......
......@@ -24,9 +24,10 @@
#include <QAbstractItemModel>
#include <TelepathyQt/TextChannel>
#include "conversation-que-manager.h"
class KDE_TELEPATHY_CHAT_EXPORT MessagesModel : public QAbstractListModel
class KDE_TELEPATHY_CHAT_EXPORT MessagesModel : public QAbstractListModel, public Queable
{
Q_OBJECT
Q_PROPERTY(bool visibleToUser READ isVisibleToUser WRITE setVisibleToUser NOTIFY visibleToUserChanged);
......@@ -65,7 +66,9 @@ public:
Q_SIGNALS:
void textChannelChanged(Tp::TextChannelPtr newChannel);
void visibleToUserChanged(bool visible);
//TODO: figure out how to check if unread messages have been acknowledged by something else
void unreadCountChanged(int unreadMesssagesCount);
void popoutRequested();
public Q_SLOTS:
Tp::PendingSendMessage* sendNewMessage(QString message);
......@@ -78,6 +81,7 @@ private Q_SLOTS:
private:
void setupChannelSignals(Tp::TextChannelPtr channel);
void removeChannelSignals(Tp::TextChannelPtr channel);
virtual void selfDequed();
class ConversationModelPrivate;
ConversationModelPrivate *d;
......
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