if it compiles it should fix the new missing query issue :)
[quassel.git] / src / uisupport / bufferviewfilter.cpp
index 57a6661..6bd6565 100644 (file)
@@ -47,8 +47,9 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig *
   : QSortFilterProxyModel(model),
     _config(0),
     _sortOrder(Qt::AscendingOrder),
+    _showServerQueries(false),
     _editMode(false),
-    _enableEditMode(tr("Show / Hide buffers"), this)
+    _enableEditMode(tr("Show / Hide Chats"), this)
 {
   setConfig(config);
   setSourceModel(model);
@@ -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) {
@@ -94,18 +98,19 @@ void BufferViewFilter::configInitialized() {
   if(!config())
     return;
 
-  connect(config(), SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(allowedBufferTypesSet(int)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(minimumActivitySet(int)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(bufferListSet()), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(bufferMoved(const BufferId &, int)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(invalidate()));
-  connect(config(), SIGNAL(bufferPermanentlyRemoved(const BufferId &)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(configChanged()), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(allowedBufferTypesSet(int)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(minimumActivitySet(int)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(bufferListSet()), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(bufferMoved(const BufferId &, int)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(invalidate()));
+//   connect(config(), SIGNAL(bufferPermanentlyRemoved(const BufferId &)), this, SLOT(invalidate()));
 
   disconnect(config(), SIGNAL(initDone()), this, SLOT(configInitialized()));
 
@@ -115,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;
@@ -307,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 && sourceModel()->data(source_bufferIndex, Qt::DisplayRole).toString().contains('.')) {
+    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>())
@@ -510,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;
 }
 
+