From a3c6487bfca7ce2b06d588ec4b7795d46359ad47 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Tue, 25 Aug 2009 22:29:10 +0200 Subject: [PATCH] Getting rid of empty/ghost server buffers --- src/uisupport/bufferviewfilter.cpp | 22 +++++++++++++++++++++- src/uisupport/bufferviewfilter.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index ec14de08..2af25157 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -47,6 +47,7 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * : QSortFilterProxyModel(model), _config(0), _sortOrder(Qt::AscendingOrder), + _showServerQueries(false), _editMode(false), _enableEditMode(tr("Show / Hide buffers"), this) { @@ -62,6 +63,9 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * _enableEditMode.setChecked(_editMode); connect(&_enableEditMode, SIGNAL(toggled(bool)), this, SLOT(enableEditMode(bool))); + BufferSettings defaultSettings; + defaultSettings.notify("ServerNoticesTarget", this, SLOT(showServerQueriesChanged())); + showServerQueriesChanged(); } void BufferViewFilter::setConfig(BufferViewConfig *config) { @@ -116,6 +120,16 @@ void BufferViewFilter::configInitialized() { emit configChanged(); } +void BufferViewFilter::showServerQueriesChanged() { + BufferSettings bufferSettings; + + bool showQueries = (bufferSettings.serverNoticesTarget() & BufferSettings::DefaultBuffer); + if(_showServerQueries != showQueries) { + _showServerQueries = showQueries; + invalidate(); + } +} + QList BufferViewFilter::actions(const QModelIndex &index) { Q_UNUSED(index) QList actionList; @@ -308,9 +322,14 @@ bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) int allowedBufferTypes = config()->allowedBufferTypes(); if(!config()->networkId().isValid()) allowedBufferTypes &= ~BufferInfo::StatusBuffer; - if(!(allowedBufferTypes & sourceModel()->data(source_bufferIndex, NetworkModel::BufferTypeRole).toInt())) + int bufferType = sourceModel()->data(source_bufferIndex, NetworkModel::BufferTypeRole).toInt(); + if(!(allowedBufferTypes & bufferType)) return false; + if(bufferType & BufferInfo::QueryBuffer && !_showServerQueries) { + return false; + } + // the following dynamic filters may not trigger if the buffer is currently selected. QModelIndex currentIndex = Client::bufferModel()->standardSelectionModel()->currentIndex(); if(bufferId == Client::bufferModel()->data(currentIndex, NetworkModel::BufferIdRole).value()) @@ -511,3 +530,4 @@ bool BufferViewFilter::bufferIdLessThan(const BufferId &left, const BufferId &ri return QString::compare(Client::networkModel()->data(leftIndex, Qt::DisplayRole).toString(), Client::networkModel()->data(rightIndex, Qt::DisplayRole).toString(), Qt::CaseInsensitive) < 0; } + diff --git a/src/uisupport/bufferviewfilter.h b/src/uisupport/bufferviewfilter.h index b20c860d..01812b9b 100644 --- a/src/uisupport/bufferviewfilter.h +++ b/src/uisupport/bufferviewfilter.h @@ -87,11 +87,13 @@ signals: private slots: void configInitialized(); void enableEditMode(bool enable); + void showServerQueriesChanged(); private: QPointer _config; Qt::SortOrder _sortOrder; + bool _showServerQueries; bool _editMode; QAction _enableEditMode; QSet _toAdd; -- 2.20.1