From: Marcus Eggenberger Date: Tue, 12 Aug 2008 15:10:37 +0000 (+0200) Subject: Continuing my personal crusade against Buffer. X-Git-Tag: 0.3.0~61 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=533eaaeda64759c01daa624365b8fc63eeba5ccf Continuing my personal crusade against Buffer. - activity changes are now handled purely in the NetworkModel - Sput: I can only hope for you that there are no conflicts with your local repo :) --- diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index ecb34ddb..f6651ae4 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -21,6 +21,7 @@ set(SOURCES messagemodel.cpp mappedselectionmodel.cpp networkmodel.cpp + quasselui.cpp selectionmodelsynchronizer.cpp treemodel.cpp) diff --git a/src/client/abstractmessageprocessor.cpp b/src/client/abstractmessageprocessor.cpp index 0f692af8..89ce4f01 100644 --- a/src/client/abstractmessageprocessor.cpp +++ b/src/client/abstractmessageprocessor.cpp @@ -22,12 +22,11 @@ #include "client.h" -AbstractMessageProcessor::AbstractMessageProcessor(QObject *parent) : QObject(parent) { - - - +AbstractMessageProcessor::AbstractMessageProcessor(QObject *parent) + : QObject(parent) +{ } -void AbstractMessageProcessor::postProcess(Message &msg) { - Client::buffer(msg.bufferInfo())->updateActivityLevel(msg); -} +// void AbstractMessageProcessor::postProcess(Message &msg) { +// Client::buffer(msg.bufferInfo())->updateActivityLevel(msg); +// } diff --git a/src/client/abstractmessageprocessor.h b/src/client/abstractmessageprocessor.h index ecbca380..50247a86 100644 --- a/src/client/abstractmessageprocessor.h +++ b/src/client/abstractmessageprocessor.h @@ -21,7 +21,9 @@ #ifndef ABSTRACTMESSAGEPROCESSOR_H_ #define ABSTRACTMESSAGEPROCESSOR_H_ +#include "client.h" #include "message.h" +#include "networkmodel.h" class AbstractMessageProcessor : public QObject { Q_OBJECT @@ -38,7 +40,7 @@ class AbstractMessageProcessor : public QObject { void progressUpdated(int value, int maximum); protected: - void postProcess(Message &msg); + inline void postProcess(Message &msg) { Client::networkModel()->updateBufferActivity(msg); } }; diff --git a/src/client/buffer.cpp b/src/client/buffer.cpp index df786396..9108d690 100644 --- a/src/client/buffer.cpp +++ b/src/client/buffer.cpp @@ -30,11 +30,8 @@ Buffer::Buffer(BufferInfo bufferid, QObject *parent) : QObject(parent), - _bufferInfo(bufferid), - _isVisible(false), - _activityLevel(NoActivity) + _bufferInfo(bufferid) { - } BufferInfo Buffer::bufferInfo() const { @@ -42,49 +39,3 @@ BufferInfo Buffer::bufferInfo() const { return _bufferInfo; } -void Buffer::setVisible(bool visible) { - _isVisible = visible; - setActivityLevel(NoActivity); - if(_lastRcvdMsg.msgId() > 0) setLastSeenMsg(_lastRcvdMsg.msgId()); -} - -void Buffer::setLastSeenMsg(const MsgId &msgId) { - const MsgId oldLastSeen = lastSeenMsg(); - if(!oldLastSeen.isValid() || (msgId.isValid() && msgId > oldLastSeen)) { - _lastSeenMsg = msgId; - Client::setBufferLastSeenMsg(bufferInfo().bufferId(), msgId); - setActivityLevel(NoActivity); - } -} - -void Buffer::setActivityLevel(ActivityLevel level) { - _activityLevel = level; - if(bufferInfo().bufferId() > 0) { - Client::networkModel()->setBufferActivity(bufferInfo(), level); - } -} - -void Buffer::updateActivityLevel(const Message &msg) { - // FIXME dirty hack to allow the lastSeen stuff to continue to work - // will be made much nicer once Buffer dies, I hope... - if(msg.msgId() > _lastRcvdMsg.msgId()) _lastRcvdMsg = msg; - - if(isVisible()) - return; - - if(msg.flags() & Message::Self) // don't update activity for our own messages - return; - - if(lastSeenMsg().isValid() && lastSeenMsg() >= msg.msgId()) - return; - - ActivityLevel level = activityLevel() | OtherActivity; - if(msg.type() & (Message::Plain | Message::Notice | Message::Action)) - level |= NewMessage; - - if(msg.flags() & Message::Highlight) - level |= Highlight; - - if(level != activityLevel()) - setActivityLevel(level); -} diff --git a/src/client/buffer.h b/src/client/buffer.h index 72a30f11..84f34a39 100644 --- a/src/client/buffer.h +++ b/src/client/buffer.h @@ -49,23 +49,9 @@ public: Buffer(BufferInfo, QObject *parent = 0); BufferInfo bufferInfo() const; - inline bool isVisible() const { return _isVisible; } - inline MsgId lastSeenMsg() const { return _lastSeenMsg; } - inline ActivityLevel activityLevel() const { return _activityLevel; } - -public slots: - void setVisible(bool visible); - void setLastSeenMsg(const MsgId &msgId); - void setActivityLevel(ActivityLevel level); - void updateActivityLevel(const Message &msg); private: BufferInfo _bufferInfo; - bool _isVisible; - MsgId _lastSeenMsg; - Message _lastRcvdMsg; - ActivityLevel _activityLevel; - }; Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel) diff --git a/src/client/buffermodel.cpp b/src/client/buffermodel.cpp index a03ae5bd..594dc83d 100644 --- a/src/client/buffermodel.cpp +++ b/src/client/buffermodel.cpp @@ -61,10 +61,6 @@ void BufferModel::synchronizeView(QAbstractItemView *view) { view->setSelectionModel(mappedSelectionModel); } -QModelIndex BufferModel::currentIndex() { - return standardSelectionModel()->currentIndex(); -} - void BufferModel::setCurrentIndex(const QModelIndex &newCurrent) { _selectionModelSynchronizer.selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Current); _selectionModelSynchronizer.selectionModel()->select(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); diff --git a/src/client/buffermodel.h b/src/client/buffermodel.h index 7bd3fc9e..4794afeb 100644 --- a/src/client/buffermodel.h +++ b/src/client/buffermodel.h @@ -45,7 +45,7 @@ public: void synchronizeSelectionModel(MappedSelectionModel *selectionModel); void synchronizeView(QAbstractItemView *view); - QModelIndex currentIndex(); + inline QModelIndex currentIndex() { return standardSelectionModel()->currentIndex(); } void setCurrentIndex(const QModelIndex &newCurrent); private slots: diff --git a/src/client/client.cpp b/src/client/client.cpp index faddce72..7cf25c10 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -77,7 +77,6 @@ Client::Client(QObject *parent) _connectedToCore(false), _syncedToCore(false) { - _monitorBuffer = new Buffer(BufferInfo(), this); _signalProxy->synchronize(_ircListHelper); connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)), @@ -309,7 +308,7 @@ void Client::setSyncedToCore() { // create buffersyncer Q_ASSERT(!_bufferSyncer); _bufferSyncer = new BufferSyncer(this); - connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), this, SLOT(updateLastSeenMsg(BufferId, MsgId))); + connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), _networkModel, SLOT(setLastSeenMsgId(BufferId, MsgId))); connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId))); connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString))); signalProxy()->synchronize(bufferSyncer()); @@ -458,15 +457,6 @@ void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) { //qDebug() << "processed" << msgs.count() << "backlog lines in" << start.msecsTo(QTime::currentTime()); } -void Client::updateLastSeenMsg(BufferId id, const MsgId &msgId) { - Buffer *b = buffer(id); - if(!b) { - qWarning() << "Client::updateLastSeen(): Unknown buffer" << id; - return; - } - b->setLastSeenMsg(msgId); -} - void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) { if(!bufferSyncer()) return; diff --git a/src/client/client.h b/src/client/client.h index 112a6a26..d8a2b4c9 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -66,7 +66,6 @@ public: static QList buffers(); static Buffer *buffer(BufferId bufferUid); static Buffer *buffer(BufferInfo); - static inline Buffer *monitorBuffer() { return instance()->_monitorBuffer; } static QList networkIds(); static const Network * network(NetworkId); @@ -178,7 +177,6 @@ private slots: void recvStatusMsg(QString network, QString message); void receiveBacklog(BufferId bufferId, const QVariantList &msgs); void updateBufferInfo(BufferInfo); - void updateLastSeenMsg(BufferId id, const MsgId &msgId); void bufferDestroyed(); void networkDestroyed(); @@ -228,8 +226,6 @@ private: QHash _networks; QHash _identities; - Buffer *_monitorBuffer; - static AccountId _currentCoreAccount; friend class ClientSyncer; diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 777e809a..793f5ae5 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -23,6 +23,7 @@ #include #include "bufferinfo.h" +#include "buffermodel.h" #include "client.h" #include "signalproxy.h" #include "network.h" @@ -185,10 +186,27 @@ void BufferItem::setActivityLevel(Buffer::ActivityLevel level) { } } -void BufferItem::updateActivityLevel(Buffer::ActivityLevel level) { - Buffer::ActivityLevel oldActivity = _activity; - _activity |= level; - if(oldActivity != _activity) +//void BufferItem::updateActivityLevel(Buffer::ActivityLevel level) { +void BufferItem::updateActivityLevel(const Message &msg) { + if(isCurrentBuffer()) + return; + + if(msg.flags() & Message::Self) // don't update activity for our own messages + return; + + if(lastSeenMsgId() >= msg.msgId()) + return; + + Buffer::ActivityLevel oldLevel = activityLevel(); + + _activity |= Buffer::OtherActivity; + if(msg.type() & (Message::Plain | Message::Notice | Message::Action)) + _activity |= Buffer::NewMessage; + + if(msg.flags() & Message::Highlight) + _activity |= Buffer::Highlight; + + if(oldLevel != _activity) emit dataChanged(); } @@ -230,33 +248,15 @@ void BufferItem::setBufferName(const QString &name) { emit dataChanged(0); } +bool BufferItem::isCurrentBuffer() const { + return _bufferInfo.bufferId() == Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value(); +} + QString BufferItem::toolTip(int column) const { Q_UNUSED(column); return tr("

%1 - %2

").arg(bufferInfo().bufferId().toInt()).arg(bufferName()); } -/* -void BufferItem::setLastMsgInsert(QDateTime msgDate) { - if(msgDate.isValid() && msgDate > _lastMsgInsert) - _lastMsgInsert = msgDate; -} -*/ -/* -// FIXME emit dataChanged() -bool BufferItem::setLastSeen() { - if(_lastSeen > _lastMsgInsert) - return false; - - _lastSeen = _lastMsgInsert; - BufferSettings(bufferInfo().bufferId()).setLastSeen(_lastSeen); - return true; -} - -QDateTime BufferItem::lastSeen() { - return _lastSeen; -} -*/ - /***************************************** * StatusBufferItem *****************************************/ @@ -721,13 +721,6 @@ bool NetworkModel::isBufferIndex(const QModelIndex &index) const { return index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType; } -/* -Buffer *NetworkModel::getBufferByIndex(const QModelIndex &index) const { - BufferItem *item = static_cast(index.internalPointer()); - return Client::instance()->buffer(item->id()); -} -*/ - int NetworkModel::networkRow(NetworkId networkId) { NetworkItem *netItem = 0; for(int i = 0; i < rootItem->childCount(); i++) { @@ -780,28 +773,17 @@ QModelIndex NetworkModel::bufferIndex(BufferId bufferId) { return indexByItem(_bufferItemCache[bufferId]); } -BufferItem *NetworkModel::findBufferItem(const BufferInfo &bufferInfo) { - NetworkItem *netItem = findNetworkItem(bufferInfo.networkId()); - if(!netItem) - return 0; - - BufferItem *bufferItem = netItem->findBufferItem(bufferInfo); - return bufferItem; -} - BufferItem *NetworkModel::findBufferItem(BufferId bufferId) { - NetworkItem *netItem; - BufferItem *bufferItem; - - for(int i = 0; i < rootItem->childCount(); i++) { - netItem = qobject_cast(rootItem->child(i)); - if((bufferItem = netItem->findBufferItem(bufferId))) - return bufferItem; - } - return 0; + if(_bufferItemCache.contains(bufferId)) + return _bufferItemCache[bufferId]; + else + return 0; } BufferItem *NetworkModel::bufferItem(const BufferInfo &bufferInfo) { + if(_bufferItemCache.contains(bufferInfo.bufferId())) + return _bufferItemCache[bufferInfo.bufferId()]; + NetworkItem *netItem = networkItem(bufferInfo.networkId()); return netItem->bufferItem(bufferInfo); } @@ -912,37 +894,38 @@ void NetworkModel::bufferUpdated(BufferInfo bufferInfo) { } void NetworkModel::removeBuffer(BufferId bufferId) { + BufferItem *buffItem = findBufferItem(bufferId); + if(!buffItem) + return; + + buffItem->parent()->removeChild(buffItem); +} + +void NetworkModel::setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId) { BufferItem *bufferItem = findBufferItem(bufferId); - if(bufferItem) - bufferItem->parent()->removeChild(bufferItem); + if(!bufferItem) { + qDebug() << "NetworkModel::setLastSeenMsgId(): buffer is unknown:" << bufferId; + return; + } + bufferItem->setLastSeenMsgId(msgId); } -/* void NetworkModel::updateBufferActivity(const Message &msg) { - BufferItem *buff = bufferItem(msg.bufferInfo()); - Q_ASSERT(buff); - - buff->setLastMsgInsert(msg.timestamp()); - - if(buff->lastSeen() >= msg.timestamp()) + BufferItem *bufferItem = findBufferItem(msg.bufferInfo()); + if(!bufferItem) { + qDebug() << "NetworkModel::updateBufferActivity(): buffer is unknown:" << msg.bufferInfo(); return; - - BufferItem::ActivityLevel level = BufferItem::OtherActivity; - if(msg.type() == Message::Plain || msg.type() == Message::Notice) - level |= BufferItem::NewMessage; - - if(msg.flags() & Message::Highlight) - level |= BufferItem::Highlight; - - bufferItem(msg.bufferInfo())->updateActivity(level); + } + bufferItem->updateActivityLevel(msg); } -*/ -void NetworkModel::setBufferActivity(const BufferInfo &info, Buffer::ActivityLevel level) { - BufferItem *buff = bufferItem(info); - Q_ASSERT(buff); - - buff->setActivityLevel(level); +void NetworkModel::setBufferActivity(const BufferId &bufferId, Buffer::ActivityLevel level) { + BufferItem *bufferItem = findBufferItem(bufferId); + if(!bufferItem) { + qDebug() << "NetworkModel::setBufferActivity(): buffer is unknown:" << bufferId; + return; + } + bufferItem->setActivityLevel(level); } const Network *NetworkModel::networkByIndex(const QModelIndex &index) const { @@ -954,8 +937,6 @@ const Network *NetworkModel::networkByIndex(const QModelIndex &index) const { return Client::network(networkId); } - - void NetworkModel::checkForRemovedBuffers(const QModelIndex &parent, int start, int end) { if(parent.data(ItemTypeRole) != NetworkItemType) return; diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index 07b21902..c564d7e6 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -108,14 +108,14 @@ public: virtual inline bool isActive() const { return qobject_cast(parent())->isActive(); } + inline const MsgId &lastSeenMsgId() const { return _lastSeenMsgId; } + inline void setLastSeenMsgId(const MsgId &msgId) { _lastSeenMsgId = msgId; } inline Buffer::ActivityLevel activityLevel() const { return _activity; } void setActivityLevel(Buffer::ActivityLevel level); - void updateActivityLevel(Buffer::ActivityLevel level); - - void setLastMsgInsert(QDateTime msgDate); - bool setLastSeen(); - QDateTime lastSeen(); + //void updateActivityLevel(Buffer::ActivityLevel level); + void updateActivityLevel(const Message &msg); + bool isCurrentBuffer() const; virtual QString toolTip(int column) const; public slots: @@ -124,6 +124,7 @@ public slots: private: BufferInfo _bufferInfo; Buffer::ActivityLevel _activity; + MsgId _lastSeenMsgId; }; /***************************************** @@ -296,6 +297,7 @@ public: Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const; QString bufferName(BufferId bufferId); + MsgId lastSeenMsgId(BufferId BufferId); NetworkId networkId(BufferId bufferId); QString networkName(BufferId bufferId); BufferInfo::Type bufferType(BufferId bufferId); @@ -303,7 +305,9 @@ public: public slots: void bufferUpdated(BufferInfo bufferInfo); void removeBuffer(BufferId bufferId); - void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity); + void setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId); + void setBufferActivity(const BufferId &bufferId, Buffer::ActivityLevel activity); + void updateBufferActivity(const Message &msg); void networkRemoved(const NetworkId &networkId); private slots: @@ -314,7 +318,7 @@ private: int networkRow(NetworkId networkId); NetworkItem *findNetworkItem(NetworkId networkId); NetworkItem *networkItem(NetworkId networkId); - BufferItem *findBufferItem(const BufferInfo &bufferInfo); + inline BufferItem *findBufferItem(const BufferInfo &bufferInfo) { return findBufferItem(bufferInfo.bufferId()); } BufferItem *findBufferItem(BufferId bufferId); BufferItem *bufferItem(const BufferInfo &bufferInfo); diff --git a/src/client/quasselui.cpp b/src/client/quasselui.cpp new file mode 100644 index 00000000..6e0e0aa2 --- /dev/null +++ b/src/client/quasselui.cpp @@ -0,0 +1,23 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * 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 "quasselui.h" + +bool AbstractUi::_visible = false; diff --git a/src/client/quasselui.h b/src/client/quasselui.h index a278deff..dac64be7 100644 --- a/src/client/quasselui.h +++ b/src/client/quasselui.h @@ -18,8 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _QUASSELUI_H_ -#define _QUASSELUI_H_ +#ifndef QUASSELUI_H +#define QUASSELUI_H #include #include "message.h" @@ -35,6 +35,9 @@ class AbstractUi : public QObject { virtual MessageModel *createMessageModel(QObject *parent) = 0; virtual AbstractMessageProcessor *createMessageProcessor(QObject *parent) = 0; + inline static bool isVisible() { return _visible; } + inline static void setVisible(bool visible) { _visible = visible; } + protected slots: virtual void connectedToCore() {} virtual void disconnectedFromCore() {} @@ -43,6 +46,8 @@ class AbstractUi : public QObject { void connectToCore(const QVariantMap &connInfo); void disconnectFromCore(); +private: + static bool _visible; }; #endif diff --git a/src/qtui/bufferwidget.cpp b/src/qtui/bufferwidget.cpp index c1e992dc..a18a18c9 100644 --- a/src/qtui/bufferwidget.cpp +++ b/src/qtui/bufferwidget.cpp @@ -29,10 +29,6 @@ BufferWidget::BufferWidget(QWidget *parent) : AbstractBufferContainer(parent) { ui.setupUi(this); } -BufferWidget::~BufferWidget() { - -} - AbstractChatView *BufferWidget::createChatView(BufferId id) { ChatView *chatView; chatView = new ChatView(Client::buffer(id), this); diff --git a/src/qtui/bufferwidget.h b/src/qtui/bufferwidget.h index 4d9bf564..e2876ada 100644 --- a/src/qtui/bufferwidget.h +++ b/src/qtui/bufferwidget.h @@ -30,7 +30,6 @@ class BufferWidget : public AbstractBufferContainer { public: BufferWidget(QWidget *parent); - virtual ~BufferWidget(); protected: virtual AbstractChatView *createChatView(BufferId); diff --git a/src/qtui/chatline.cpp b/src/qtui/chatline.cpp index 0e4df226..3e7167bc 100644 --- a/src/qtui/chatline.cpp +++ b/src/qtui/chatline.cpp @@ -23,8 +23,11 @@ #include #include "bufferinfo.h" +#include "buffersyncer.h" +#include "client.h" #include "chatitem.h" #include "chatline.h" +#include "messagemodel.h" #include "qtui.h" ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent) @@ -106,6 +109,12 @@ void ChatLine::setHighlighted(bool highlighted) { } void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { +// const QAbstractItemModel *model_ = model(); +// if(model_ && row() > 0) { +// MsgId msgId = model_->data(model_->index(row() - 1, 0), MessageModel::MsgIdRole).value(); +// BufferId bufferId = model_->data(model_->index(row() - 1, 0), MessageModel::BufferIdRole).value(); +// qDebug() << msgId; +// } if(_selection & Highlighted) { painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor())); } diff --git a/src/qtui/chatline.h b/src/qtui/chatline.h index 724be7dc..15805cc6 100644 --- a/src/qtui/chatline.h +++ b/src/qtui/chatline.h @@ -35,6 +35,8 @@ class ChatLine : public QGraphicsItem { inline int row() { return _row; } inline void setRow(int row) { _row = row; } + inline const QAbstractItemModel *model() const { return chatScene() ? chatScene()->model() : 0; } + inline ChatScene *chatScene() const { return qobject_cast(scene()); } inline qreal width() const { return _width; } inline qreal height() const { return _height; } ChatItem &item(ChatLineModel::ColumnType); diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index aeac420b..9ac7974d 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -23,7 +23,6 @@ #include #include -#include "buffer.h" #include "chatitem.h" #include "chatline.h" #include "chatlinemodelitem.h" diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index c69f0e12..f44e20bd 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -28,7 +28,6 @@ #include "types.h" class AbstractUiMsg; -class Buffer; class BufferId; class ChatItem; class ChatLine; diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index dbddaaa7..6e40c099 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -102,3 +102,15 @@ void ChatView::verticalScrollbarChanged(int newPos) { scene()->setIsFetchingBacklog(vbar->value() == vbar->minimum()); } } + +MsgId ChatView::lastMsgId() const { + if(!scene()) + return MsgId(); + + QAbstractItemModel *model = scene()->model(); + if(!model || model->rowCount() == 0) + return MsgId(); + + + return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value(); +} diff --git a/src/qtui/chatview.h b/src/qtui/chatview.h index 6da995e8..244b5f4b 100644 --- a/src/qtui/chatview.h +++ b/src/qtui/chatview.h @@ -38,6 +38,7 @@ public: ChatView(MessageFilter *, QWidget *parent = 0); ChatView(Buffer *, QWidget *parent = 0); + virtual MsgId lastMsgId() const; inline ChatScene *scene() const { return _scene; } public slots: diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 080e78f5..28c94d13 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -32,7 +32,6 @@ class Buffer; class BufferViewConfig; class MsgProcessorStatusWidget; -class QtUi; class Message; class NickListWidget; @@ -44,115 +43,115 @@ class NickListWidget; class MainWin : public QMainWindow { Q_OBJECT - public: - MainWin(QWidget *parent = 0); - virtual ~MainWin(); +public: + MainWin(QWidget *parent = 0); + virtual ~MainWin(); - void init(); - void addBufferView(BufferViewConfig *config = 0); + void init(); + void addBufferView(BufferViewConfig *config = 0); - void displayTrayIconMessage(const QString &title, const QString &message); + void displayTrayIconMessage(const QString &title, const QString &message); #ifdef HAVE_DBUS - void sendDesktopNotification(const QString &title, const QString &message); + void sendDesktopNotification(const QString &title, const QString &message); #endif - virtual bool event(QEvent *event); - - public slots: - void setTrayIconActivity(bool active = false); - - protected: - void closeEvent(QCloseEvent *event); - virtual void changeEvent(QEvent *event); - - protected slots: - void connectedToCore(); - void setConnectedState(); - void updateLagIndicator(int lag); - void securedConnection(); - void disconnectedFromCore(); - void setDisconnectedState(); - void systrayActivated( QSystemTrayIcon::ActivationReason ); - - private slots: - void addBufferView(int bufferViewConfigId); - void removeBufferView(int bufferViewConfigId); - void messagesInserted(const QModelIndex &parent, int start, int end); - void showChannelList(NetworkId netId = NetworkId()); - void showCoreInfoDlg(); - void showSettingsDlg(); - void on_actionEditNetworks_triggered(); - void on_actionManageViews_triggered(); - void on_actionLockDockPositions_toggled(bool lock); - void showAboutDlg(); - void on_actionDebugNetworkModel_triggered(bool); - - void showCoreConnectionDlg(bool autoConnect = false); - - void clientNetworkCreated(NetworkId); - void clientNetworkRemoved(NetworkId); - void clientNetworkUpdated(); - void connectOrDisconnectFromNet(); - - void makeTrayIconBlink(); - void saveStatusBarStatus(bool enabled); - - void loadLayout(); - void saveLayout(); - + virtual bool event(QEvent *event); + +public slots: + void setTrayIconActivity(bool active = false); + +protected: + void closeEvent(QCloseEvent *event); + virtual void changeEvent(QEvent *event); + +protected slots: + void connectedToCore(); + void setConnectedState(); + void updateLagIndicator(int lag); + void securedConnection(); + void disconnectedFromCore(); + void setDisconnectedState(); + void systrayActivated( QSystemTrayIcon::ActivationReason ); + +private slots: + void addBufferView(int bufferViewConfigId); + void removeBufferView(int bufferViewConfigId); + void messagesInserted(const QModelIndex &parent, int start, int end); + void showChannelList(NetworkId netId = NetworkId()); + void showCoreInfoDlg(); + void showSettingsDlg(); + void on_actionEditNetworks_triggered(); + void on_actionManageViews_triggered(); + void on_actionLockDockPositions_toggled(bool lock); + void showAboutDlg(); + void on_actionDebugNetworkModel_triggered(bool); + + void showCoreConnectionDlg(bool autoConnect = false); + + void clientNetworkCreated(NetworkId); + void clientNetworkRemoved(NetworkId); + void clientNetworkUpdated(); + void connectOrDisconnectFromNet(); + + void makeTrayIconBlink(); + void saveStatusBarStatus(bool enabled); + + void loadLayout(); + void saveLayout(); + #ifdef HAVE_DBUS - void desktopNotificationClosed(uint id, uint reason); - void desktopNotificationInvoked(uint id, const QString & action); + void desktopNotificationClosed(uint id, uint reason); + void desktopNotificationInvoked(uint id, const QString & action); #endif - - signals: - void connectToCore(const QVariantMap &connInfo); - void disconnectFromCore(); - void requestBacklog(BufferInfo, QVariant, QVariant); - - private: - Ui::MainWin ui; - - QMenu *systrayMenu; - QLabel *coreLagLabel; - QLabel *sslLabel; - MsgProcessorStatusWidget *msgProcessorStatusWidget; - - TitleSetter _titleSetter; - - void setupMenus(); - void setupViews(); - void setupNickWidget(); - void setupChatMonitor(); - void setupInputWidget(); - void setupTopicWidget(); - void setupStatusBar(); - void setupSystray(); - - void toggleVisibility(); - - void enableMenus(); - - QSystemTrayIcon *systray; - QIcon activeTrayIcon; - QIcon onlineTrayIcon; - QIcon offlineTrayIcon; - bool trayIconActive; - QTimer *timer; - - BufferId currentBuffer; - QString currentProfile; - - QList _netViews; - NickListWidget *nickListWidget; - + +signals: + void connectToCore(const QVariantMap &connInfo); + void disconnectFromCore(); + void requestBacklog(BufferInfo, QVariant, QVariant); + +private: + Ui::MainWin ui; + + QMenu *systrayMenu; + QLabel *coreLagLabel; + QLabel *sslLabel; + MsgProcessorStatusWidget *msgProcessorStatusWidget; + + TitleSetter _titleSetter; + + void setupMenus(); + void setupViews(); + void setupNickWidget(); + void setupChatMonitor(); + void setupInputWidget(); + void setupTopicWidget(); + void setupStatusBar(); + void setupSystray(); + + void toggleVisibility(); + + void enableMenus(); + + QSystemTrayIcon *systray; + QIcon activeTrayIcon; + QIcon onlineTrayIcon; + QIcon offlineTrayIcon; + bool trayIconActive; + QTimer *timer; + + BufferId currentBuffer; + QString currentProfile; + + QList _netViews; + NickListWidget *nickListWidget; + #ifdef HAVE_DBUS - org::freedesktop::Notifications *desktopNotifications; - quint32 notificationId; + org::freedesktop::Notifications *desktopNotifications; + quint32 notificationId; #endif - - friend class QtUi; + + friend class QtUi; }; #endif diff --git a/src/uisupport/abstractbuffercontainer.cpp b/src/uisupport/abstractbuffercontainer.cpp index a12b0315..e6b1f14f 100644 --- a/src/uisupport/abstractbuffercontainer.cpp +++ b/src/uisupport/abstractbuffercontainer.cpp @@ -19,7 +19,6 @@ ***************************************************************************/ #include "abstractbuffercontainer.h" -#include "buffer.h" #include "client.h" #include "networkmodel.h" @@ -32,7 +31,6 @@ AbstractBufferContainer::AbstractBufferContainer(QWidget *parent) AbstractBufferContainer::~AbstractBufferContainer() { } - void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { Q_ASSERT(model()); if(!parent.isValid()) { @@ -60,7 +58,6 @@ void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, in } void AbstractBufferContainer::removeBuffer(BufferId bufferId) { - if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false); if(!_chatViews.contains(bufferId)) return; @@ -78,26 +75,24 @@ void AbstractBufferContainer::currentChanged(const QModelIndex ¤t, const Q } void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) { - AbstractChatView *chatView = 0; - Buffer *prevBuffer = Client::buffer(currentBuffer()); - if(prevBuffer) prevBuffer->setVisible(false); + BufferId prevBufferId = currentBuffer(); + if(prevBufferId.isValid() && _chatViews.contains(prevBufferId)) { + Client::setBufferLastSeenMsg(prevBufferId, _chatViews[prevBufferId]->lastMsgId()); + } - Buffer *buf; - if(!bufferId.isValid() || !(buf = Client::buffer(bufferId))) { - if(bufferId.isValid()) - qWarning() << "AbstractBufferContainer::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId; + if(!bufferId.isValid()) { + qWarning() << "AbstractBufferContainer::setBuffer(BufferId): invalid BufferId:" << bufferId; _currentBuffer = 0; showChatView(0); return; } - if(_chatViews.contains(bufferId)) { - chatView = _chatViews[bufferId]; - } else { - chatView = createChatView(bufferId); - _chatViews[bufferId] = chatView; - } + + if(!_chatViews.contains(bufferId)) + _chatViews[bufferId] = createChatView(bufferId); + _currentBuffer = bufferId; showChatView(bufferId); - buf->setVisible(true); + Client::networkModel()->setBufferActivity(bufferId, Buffer::NoActivity); + Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId()); setFocus(); } diff --git a/src/uisupport/abstractbuffercontainer.h b/src/uisupport/abstractbuffercontainer.h index bf8a34c7..0e466277 100644 --- a/src/uisupport/abstractbuffercontainer.h +++ b/src/uisupport/abstractbuffercontainer.h @@ -75,7 +75,7 @@ class AbstractChatView { public: virtual ~AbstractChatView() {}; - + virtual MsgId lastMsgId() const = 0; }; #endif