+bool BufferViewFilter::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const {
+ int itemType = sourceModel()->data(source_left, NetworkModel::ItemTypeRole).toInt();
+ switch(itemType) {
+ case NetworkModel::NetworkItemType:
+ return networkLessThan(source_left, source_right);
+ case NetworkModel::BufferItemType:
+ return bufferLessThan(source_left, source_right);
+ default:
+ return QSortFilterProxyModel::lessThan(source_left, source_right);
+ }
+}
+
+bool BufferViewFilter::bufferLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const {
+ BufferId leftBufferId = sourceModel()->data(source_left, NetworkModel::BufferIdRole).value<BufferId>();
+ BufferId rightBufferId = sourceModel()->data(source_right, NetworkModel::BufferIdRole).value<BufferId>();
+ if(config()) {
+ return config()->bufferList().indexOf(leftBufferId) < config()->bufferList().indexOf(rightBufferId);
+ } else
+ return bufferIdLessThan(leftBufferId, rightBufferId);
+}
+
+bool BufferViewFilter::networkLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const {
+ NetworkId leftNetworkId = sourceModel()->data(source_left, NetworkModel::NetworkIdRole).value<NetworkId>();
+ NetworkId rightNetworkId = sourceModel()->data(source_right, NetworkModel::NetworkIdRole).value<NetworkId>();
+
+ if(config() && config()->sortAlphabetically())
+ return QSortFilterProxyModel::lessThan(source_left, source_right);
+ else
+ return leftNetworkId < rightNetworkId;
+}
+
+QVariant BufferViewFilter::data(const QModelIndex &index, int role) const {
+ if(role == Qt::ForegroundRole)
+ return foreground(index);
+ else
+ return QSortFilterProxyModel::data(index, role);
+}
+
+QVariant BufferViewFilter::foreground(const QModelIndex &index) const {
+ if(!index.data(NetworkModel::ItemActiveRole).toBool())
+ return _FgColorInactiveActivity;
+
+ Buffer::ActivityLevel activity = (Buffer::ActivityLevel)index.data(NetworkModel::BufferActivityRole).toInt();
+
+ if(activity & Buffer::Highlight)
+ return _FgColorHighlightActivity;
+ if(activity & Buffer::NewMessage)
+ return _FgColorNewMessageActivity;
+ if(activity & Buffer::OtherActivity)
+ return _FgColorOtherActivity;
+
+ 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 = Client::networkModel()->data(leftIndex, NetworkModel::BufferTypeRole).toInt();
+ int rightType = Client::networkModel()->data(rightIndex, NetworkModel::BufferTypeRole).toInt();