+QVariant BufferViewFilter::foreground(const QModelIndex &index) const {
+ if(config() && config()->disableDecoration())
+ return _FgColorNoActivity;
+
+ BufferInfo::ActivityLevel activity = (BufferInfo::ActivityLevel)index.data(NetworkModel::BufferActivityRole).toInt();
+
+ if(activity & BufferInfo::Highlight)
+ return _FgColorHighlightActivity;
+ if(activity & BufferInfo::NewMessage)
+ return _FgColorNewMessageActivity;
+ if(activity & BufferInfo::OtherActivity)
+ return _FgColorOtherActivity;
+
+ if(!index.data(NetworkModel::ItemActiveRole).toBool() || index.data(NetworkModel::UserAwayRole).toBool())
+ return _FgColorInactiveActivity;
+
+ return _FgColorNoActivity;
+}
+
+void BufferViewFilter::checkPreviousCurrentForRemoval(const QModelIndex ¤t, const QModelIndex &previous) {
+ Q_UNUSED(current);
+ if(previous.isValid())
+ QCoreApplication::postEvent(this, new CheckRemovalEvent(previous));
+}
+
+void BufferViewFilter::customEvent(QEvent *event) {
+ if(event->type() != QEvent::User)
+ return;
+
+ CheckRemovalEvent *removalEvent = static_cast<CheckRemovalEvent *>(event);
+ checkItemForRemoval(removalEvent->index);
+
+ event->accept();
+}
+
+void BufferViewFilter::checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+ QModelIndex source_topLeft = mapToSource(topLeft);
+ QModelIndex source_bottomRight = mapToSource(bottomRight);
+ emit _dataChanged(source_topLeft, source_bottomRight);
+}
+
+// ******************************
+// Helper
+// ******************************
+bool bufferIdLessThan(const BufferId &left, const BufferId &right) {
+ Q_CHECK_PTR(Client::networkModel());
+ if(!Client::networkModel())
+ return true;
+
+ QModelIndex leftIndex = Client::networkModel()->bufferIndex(left);
+ QModelIndex rightIndex = Client::networkModel()->bufferIndex(right);
+
+ int leftType = leftIndex.data(NetworkModel::BufferTypeRole).toInt();
+ int rightType = rightIndex.data(NetworkModel::BufferTypeRole).toInt();
+
+ if(leftType != rightType)
+ return leftType < rightType;
+ else
+ return QString::compare(leftIndex.data(Qt::DisplayRole).toString(), rightIndex.data(Qt::DisplayRole).toString(), Qt::CaseInsensitive) < 0;