From ef12cc4010e853348474b4ea15c383dd596d4858 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 25 Apr 2008 00:23:52 +0000 Subject: [PATCH] Checking in WiP on the MessageModel. More cleanly separated code and compiling of new and old chatwidget (via #ifdef SPUTDEV). Allows me to b0rk code in the new files without breaking compiling for the non-SPUTDEV users. --- src/client/client.cpp | 20 ++++++++++--------- src/client/client.pri | 14 +++++++++---- src/client/messagemodel.cpp | 28 ++++++++++++++++++-------- src/client/messagemodel.h | 12 ++++++++---- src/client/quasselui.h | 3 +++ src/common/types.h | 1 + src/qtui/chatlinemodel.cpp | 36 ++++++++++++++++++++++++++++++++++ src/qtui/chatlinemodel.h | 39 +++++++++++++++++++++++++++++++++++++ src/qtui/mainwin.cpp | 2 ++ src/qtui/qtui.cpp | 12 ++++++++++++ src/qtui/qtui.h | 2 ++ src/qtui/qtui.pri | 12 ++++++++++-- 12 files changed, 154 insertions(+), 27 deletions(-) create mode 100644 src/qtui/chatlinemodel.cpp create mode 100644 src/qtui/chatlinemodel.h diff --git a/src/client/client.cpp b/src/client/client.cpp index 8d5e71b9..64092ddc 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -95,7 +95,7 @@ void Client::init() { _bufferModel = new BufferModel(_networkModel); #ifdef SPUTDEV - _messageModel = new MessageModel(this); + _messageModel = mainUi->createMessageModel(this); #endif SignalProxy *p = signalProxy(); @@ -435,6 +435,7 @@ void Client::networkDestroyed() { } } +#ifndef SPUTDEV void Client::recvMessage(const Message &message) { Message msg = message; Buffer *b; @@ -445,7 +446,6 @@ void Client::recvMessage(const Message &message) { // TODO: make redirected messages show up in the correct buffer! -#ifndef SPUTDEV if(msg.flags() & Message::Redirected) { BufferSettings bufferSettings; bool inStatus = bufferSettings.value("UserMessagesInStatusBuffer", QVariant(true)).toBool(); @@ -489,12 +489,8 @@ void Client::recvMessage(const Message &message) { b = buffer(msg.bufferInfo()); b->appendMsg(msg); } -#endif - //bufferModel()->updateBufferActivity(msg); - // monitor buffer goes away -#ifndef SPUTDEV if(msg.type() == Message::Plain || msg.type() == Message::Notice || msg.type() == Message::Action) { const Network *net = network(msg.bufferInfo().networkId()); QString networkName = net != 0 @@ -504,10 +500,16 @@ void Client::recvMessage(const Message &message) { Message mmsg = Message(msg.timestamp(), msg.bufferInfo(), msg.type(), msg.text(), sender, msg.flags()); monitorBuffer()->appendMsg(mmsg); } -#endif - emit messageReceived(msg); } +#else + +void Client::recvMessage(const Message &msg) { + + +} + +#endif /* SPUTDEV */ void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) { //recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg))); @@ -520,7 +522,6 @@ void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) { qWarning() << "Client::recvBacklogData(): received Backlog for unknown Buffer:" << bufferId; return; } -#endif if(msgs.isEmpty()) return; // no work to be done... @@ -541,6 +542,7 @@ void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) { if(!layoutTimer->isActive()) { layoutTimer->start(); } +#endif } void Client::layoutMsg() { diff --git a/src/client/client.pri b/src/client/client.pri index d16cec37..0945919b 100644 --- a/src/client/client.pri +++ b/src/client/client.pri @@ -1,7 +1,13 @@ DEPMOD = common QT_MOD = core network gui -SRCS += buffer.cpp buffersettings.cpp clientbacklogmanager.cpp treemodel.cpp networkmodel.cpp buffermodel.cpp client.cpp clientsettings.cpp clientsyncer.cpp \ - mappedselectionmodel.cpp selectionmodelsynchronizer.cpp -HDRS += buffer.h buffersettings.h clientbacklogmanager.h treemodel.h networkmodel.h buffermodel.h client.h clientsettings.h clientsyncer.h quasselui.h \ - mappedselectionmodel.h selectionmodelsynchronizer.h +SRCS += buffer.cpp buffersettings.cpp clientbacklogmanager.cpp treemodel.cpp networkmodel.cpp buffermodel.cpp \ + client.cpp clientsettings.cpp clientsyncer.cpp mappedselectionmodel.cpp selectionmodelsynchronizer.cpp +HDRS += buffer.h buffersettings.h clientbacklogmanager.h treemodel.h networkmodel.h buffermodel.h \ + client.h clientsettings.h clientsyncer.h quasselui.h mappedselectionmodel.h selectionmodelsynchronizer.h + +sputdev { + SRCS += messagemodel.cpp + HDRS += messagemodel.h +} + diff --git a/src/client/messagemodel.cpp b/src/client/messagemodel.cpp index 11cd0245..d53449e4 100644 --- a/src/client/messagemodel.cpp +++ b/src/client/messagemodel.cpp @@ -20,6 +20,8 @@ #include "messagemodel.h" +#include "message.h" + MessageModel::MessageModel(QObject *parent) : QAbstractItemModel(parent) { @@ -40,7 +42,7 @@ QVariant MessageModel::data(const QModelIndex &index, int role) const { bool MessageModel::setData(const QModelIndex &index, const QVariant &value, int role) { int row = index.row(); if(row < 0 || row >= _messageList.count()) return false; - if(_messageList[row]->setData(index.column(), role)) { + if(_messageList[row]->setData(index.column(), value, role)) { emit dataChanged(index, index); // FIXME make msg emit this (too) return true; } @@ -49,22 +51,32 @@ bool MessageModel::setData(const QModelIndex &index, const QVariant &value, int void MessageModel::insertMessage(const Message &msg) { MsgId id = msg.msgId(); + int idx = indexForId(id); qDebug() << "inserting at" << idx << msg.text(); MessageItem *item = createMessageItem(msg); - if(id > ) - + beginInsertRows(QModelIndex(), idx, idx); + _messageList.insert(idx, item); + endInsertRows(); +} + +void MessageModel::insertMessages(const QList &msglist) { + if(msglist.isEmpty()) return; + // FIXME make this more efficient by grouping msgs + foreach(Message msg, msglist) insertMessage(msg); + } // returns index of msg with given Id or of the next message after that (i.e., the index where we'd insert this msg) int MessageModel::indexForId(MsgId id) { - if(!_messageList.count() || id <= _messageList[0]->data(0, MsgIdRole).value()) return 0; + if(_messageList.isEmpty() || id <= _messageList[0]->data(0, MsgIdRole).value()) return 0; if(id > _messageList.last()->data(0, MsgIdRole).value()) return _messageList.count(); // binary search int start = 0; int end = _messageList.count()-1; - int idx; while(1) { - if(start == end) return start; - idx = (end + start) / 2; - + if(end - start == 1) return end; + int pivot = (end + start) / 2; + if(id <= _messageList[pivot]->data(0, MsgIdRole).value()) end = pivot; + else start = pivot; + } } /**********************************************************************************/ diff --git a/src/client/messagemodel.h b/src/client/messagemodel.h index 32e4438e..1a41f264 100644 --- a/src/client/messagemodel.h +++ b/src/client/messagemodel.h @@ -23,7 +23,9 @@ #include +class Message; class MessageItem; +class MsgId; class MessageModel : public QAbstractItemModel { Q_OBJECT @@ -41,10 +43,10 @@ class MessageModel : public QAbstractItemModel { MessageModel(QObject *parent); virtual ~MessageModel(); - inline QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const { return createIndex(row, column); } - inline QModelIndex parent(const QModelIndex &index) const { return QModelIndex(); } - inline int rowCount(const QModelIndex &parent = QModelIndex()) const { return _messageList.count(); } - inline int columnCount(const QModelIndex &parent = QModelIndex()) const { return 3; } + inline QModelIndex index(int row, int column, const QModelIndex &/*parent*/ = QModelIndex()) const { return createIndex(row, column); } + inline QModelIndex parent(const QModelIndex &) const { return QModelIndex(); } + inline int rowCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return _messageList.count(); } + inline int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 3; } virtual QVariant data(const QModelIndex &index, int role) const; virtual bool setData(const QModelIndex &index, const QVariant &value, int role); @@ -60,6 +62,8 @@ class MessageModel : public QAbstractItemModel { private: QList _messageList; + int indexForId(MsgId); + }; class MessageItem { diff --git a/src/client/quasselui.h b/src/client/quasselui.h index 747d8b81..bcb512be 100644 --- a/src/client/quasselui.h +++ b/src/client/quasselui.h @@ -24,6 +24,8 @@ #include #include "message.h" +class MessageModel; + class AbstractUiMsg { public: @@ -42,6 +44,7 @@ class AbstractUi : public QObject { public: virtual void init() {}; // called after the client is initialized + virtual MessageModel *createMessageModel(QObject *parent = 0) = 0; virtual AbstractUiMsg *layoutMsg(const Message &) = 0; protected slots: diff --git a/src/common/types.h b/src/common/types.h index 381c5d6b..0154247e 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -37,6 +37,7 @@ class SignedId { inline bool operator==(const SignedId &other) const { return id == other.id; } inline bool operator!=(const SignedId &other) const { return id != other.id; } inline bool operator<(const SignedId &other) const { return id < other.id; } + inline bool operator<=(const SignedId &other) const { return id <= other.id; } inline bool operator>(const SignedId &other) const { return id > other.id; } inline bool operator>=(const SignedId &other) const { return id >= other.id; } inline bool operator==(int i) const { return id == i; } diff --git a/src/qtui/chatlinemodel.cpp b/src/qtui/chatlinemodel.cpp new file mode 100644 index 00000000..9d640d82 --- /dev/null +++ b/src/qtui/chatlinemodel.cpp @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "chatlinemodel.h" + +ChatlineModel::ChatlineModel(QObject *parent) : MessageModel(parent) { + + +} + +ChatlineModel::~ChatlineModel() { + +} + + +MessageItem *ChatlineModel::createMessageItem(const Message &msg) { + return 0; + +} diff --git a/src/qtui/chatlinemodel.h b/src/qtui/chatlinemodel.h new file mode 100644 index 00000000..da4a5419 --- /dev/null +++ b/src/qtui/chatlinemodel.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef CHATLINEMODEL_H_ +#define CHATLINEMODEL_H_ + +#include "messagemodel.h" + +class ChatlineModel : public MessageModel { + Q_OBJECT + + public: + ChatlineModel(QObject *parent = 0); + virtual ~ChatlineModel(); + + protected: + virtual MessageItem *createMessageItem(const Message &); + +}; + +#endif + diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index e705654a..8c77f4ce 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -274,6 +274,7 @@ void MainWin::setupNickWidget() { } void MainWin::setupChatMonitor() { +#ifndef SPUTDEV VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this); dock->setObjectName("ChatMonitorDock"); @@ -292,6 +293,7 @@ void MainWin::setupChatMonitor() { addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical); ui.menuViews->addAction(dock->toggleViewAction()); +#endif /* SPUTDEV */ } void MainWin::setupInputWidget() { diff --git a/src/qtui/qtui.cpp b/src/qtui/qtui.cpp index a7993597..46c657ce 100644 --- a/src/qtui/qtui.cpp +++ b/src/qtui/qtui.cpp @@ -20,6 +20,9 @@ #include "qtui.h" +#ifdef SPUTDEV +# include "chatlinemodel.h" +#endif #include "mainwin.h" QtUiStyle *QtUi::_style; @@ -46,6 +49,15 @@ QtUiStyle *QtUi::style() { return _style; } +MessageModel *QtUi::createMessageModel(QObject *parent) { +#ifndef SPUTDEV + Q_UNUSED(parent) + return 0; +#else + return new ChatlineModel(parent); +#endif +} + AbstractUiMsg *QtUi::layoutMsg(const Message &msg) { return mainWin->layoutMsg(msg); } diff --git a/src/qtui/qtui.h b/src/qtui/qtui.h index f6f1db5b..bbe31f7d 100644 --- a/src/qtui/qtui.h +++ b/src/qtui/qtui.h @@ -25,6 +25,7 @@ #include "quasselui.h" class MainWin; +class MessageModel; //! This class encapsulates Quassel's Qt-based GUI. /** This is basically a wrapper around MainWin, which is necessary because we cannot derive MainWin @@ -37,6 +38,7 @@ class QtUi : public AbstractUi { QtUi(); ~QtUi(); //void init(); + MessageModel *createMessageModel(QObject *parent = 0); AbstractUiMsg *layoutMsg(const Message &); static QtUiStyle *style(); diff --git a/src/qtui/qtui.pri b/src/qtui/qtui.pri index 46b51e9f..7f01d413 100644 --- a/src/qtui/qtui.pri +++ b/src/qtui/qtui.pri @@ -1,16 +1,24 @@ DEPMOD = client common uisupport QT_MOD = core gui network -SRCS += aboutdlg.cpp bufferwidget.cpp chatitem.cpp chatline.cpp chatline-old.cpp chatscene.cpp chatview.cpp chatwidget.cpp \ +SRCS += aboutdlg.cpp bufferwidget.cpp chatline-old.cpp chatwidget.cpp \ coreconfigwizard.cpp coreconnectdlg.cpp configwizard.cpp debugconsole.cpp inputwidget.cpp \ mainwin.cpp nicklistwidget.cpp qtui.cpp qtuisettings.cpp qtuistyle.cpp settingsdlg.cpp settingspagedlg.cpp \ titlesetter.cpp topicbutton.cpp topicwidget.cpp verticaldock.cpp jumpkeyhandler.cpp -HDRS += aboutdlg.h bufferwidget.h chatitem.h chatline.h chatline-old.h chatscene.h chatview.h chatwidget.h \ +HDRS += aboutdlg.h bufferwidget.h chatline-old.h chatwidget.h \ coreconfigwizard.h configwizard.h debugconsole.h inputwidget.h \ coreconnectdlg.h mainwin.h nicklistwidget.h qtui.h qtuisettings.h qtuistyle.h settingsdlg.h settingspagedlg.h \ titlesetter.h topicbutton.h topicwidget.h verticaldock.h jumpkeyhandler.h +# new chatline model stuff +sputdev { + SRCS += chatitem.cpp chatline.cpp chatlinemodel.cpp chatscene.cpp chatview.cpp + HDRS += chatitem.h chatline.h chatlinemodel.h chatscene.h chatview.h + SRCS -= chatline-old.cpp chatwidget.cpp + HDRS -= chatline-old.h chatwidget.h +} + FORMNAMES = aboutdlg.ui mainwin.ui coreaccounteditdlg.ui coreconnectdlg.ui bufferviewwidget.ui bufferwidget.ui nicklistwidget.ui settingsdlg.ui \ settingspagedlg.ui topicwidget.ui debugconsole.ui inputwidget.ui \ coreconfigwizardintropage.ui coreconfigwizardadminuserpage.ui coreconfigwizardstorageselectionpage.ui coreconfigwizardsyncpage.ui -- 2.20.1