+void BufferViewFilter::addBuffers(const QList<BufferId> &bufferIds) const
+{
+ if (!config())
+ return;
+
+ QList<BufferId> bufferList = config()->bufferList();
+ foreach(BufferId bufferId, bufferIds) {
+ if (bufferList.contains(bufferId))
+ continue;
+
+ int pos = bufferList.count();
+ bool lt;
+ for (int i = 0; i < bufferList.count(); i++) {
+ if (config() && config()->sortAlphabetically())
+ lt = bufferIdLessThan(bufferId, bufferList[i]);
+ else
+ lt = bufferId < config()->bufferList()[i];
+
+ if (lt) {
+ pos = i;
+ bufferList.insert(pos, bufferId);
+ break;
+ }
+ }
+ config()->requestAddBuffer(bufferId, pos);
+ }
+}
+
+
+bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const
+{
+ // no config -> "all buffers" -> accept everything
+ if (!config())
+ return true;
+
+ BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value<BufferId>();
+ Q_ASSERT(bufferId.isValid());
+
+ int activityLevel = sourceModel()->data(source_bufferIndex, NetworkModel::BufferActivityRole).toInt();
+
+ if (!config()->bufferList().contains(bufferId) && !_editMode) {
+ // add the buffer if...
+ if (config()->isInitialized()
+ && !config()->removedBuffers().contains(bufferId) // it hasn't been manually removed and either
+ && ((config()->addNewBuffersAutomatically() && !config()->temporarilyRemovedBuffers().contains(bufferId)) // is totally unknown to us (a new buffer)...
+ || (config()->temporarilyRemovedBuffers().contains(bufferId) && activityLevel > BufferInfo::OtherActivity))) { // or was just temporarily hidden and has a new message waiting for us.
+ addBuffer(bufferId);
+ }
+ // note: adding the buffer to the valid list does not temper with the following filters ("show only channels" and stuff)
+ return false;
+ }
+
+ if (config()->networkId().isValid() && config()->networkId() != sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value<NetworkId>())
+ return false;
+
+ int allowedBufferTypes = config()->allowedBufferTypes();
+ if (!config()->networkId().isValid())
+ allowedBufferTypes &= ~BufferInfo::StatusBuffer;
+ 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>())
+ return true;
+
+ if (config()->hideInactiveBuffers() && !sourceModel()->data(source_bufferIndex, NetworkModel::ItemActiveRole).toBool() && activityLevel <= BufferInfo::OtherActivity)
+ return false;
+
+ if (config()->minimumActivity() > activityLevel)
+ return false;
+