Getting rid of empty/ghost server buffers
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 25 Aug 2009 20:29:10 +0000 (22:29 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 25 Aug 2009 20:29:23 +0000 (22:29 +0200)
src/uisupport/bufferviewfilter.cpp
src/uisupport/bufferviewfilter.h

index ec14de0..2af2515 100644 (file)
@@ -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<QAction *> BufferViewFilter::actions(const QModelIndex &index) {
   Q_UNUSED(index)
   QList<QAction *> 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<BufferId>())
@@ -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;
 }
 
+
index b20c860..01812b9 100644 (file)
@@ -87,11 +87,13 @@ signals:
 private slots:
   void configInitialized();
   void enableEditMode(bool enable);
+  void showServerQueriesChanged();
 
 private:
   QPointer<BufferViewConfig> _config;
   Qt::SortOrder _sortOrder;
 
+  bool _showServerQueries;
   bool _editMode;
   QAction _enableEditMode;
   QSet<BufferId> _toAdd;