forgot to add 6 files... -.-
authorMarcus Eggenberger <egs@quassel-irc.org>
Wed, 20 Jun 2007 13:50:33 +0000 (13:50 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Wed, 20 Jun 2007 13:50:33 +0000 (13:50 +0000)
src/client/buffertreemodel.cpp [new file with mode: 0644]
src/client/buffertreemodel.h [new file with mode: 0644]
src/client/treemodel.cpp [new file with mode: 0644]
src/client/treemodel.h [new file with mode: 0644]
src/qtgui/bufferviewfilter.cpp [new file with mode: 0644]
src/qtgui/bufferviewfilter.h [new file with mode: 0644]

diff --git a/src/client/buffertreemodel.cpp b/src/client/buffertreemodel.cpp
new file mode 100644 (file)
index 0000000..7030547
--- /dev/null
@@ -0,0 +1,243 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "global.h"
+#include "buffertreemodel.h"
+
+/*****************************************
+*  Fancy Buffer Items
+*****************************************/
+BufferTreeItem::BufferTreeItem(Buffer *buffer, TreeItem *parent) : TreeItem(parent) {
+  buf = buffer;
+  activity = Buffer::NoActivity;
+}
+
+void BufferTreeItem::setActivity(const Buffer::ActivityLevel &level) {
+  activity = level;
+}
+
+QString BufferTreeItem::text(int column) const {
+  switch(column) {
+    case 0:
+      return buf->displayName();
+    case 1:
+      return buf->networkName();
+    default:
+      return QString();
+  }
+}
+
+QColor BufferTreeItem::foreground(int column) const {
+  // for the time beeing we ignore the column :)
+  if(activity & Buffer::Highlight) {
+    return QColor(Qt::red);
+  } else if(activity & Buffer::NewMessage) {
+    return QColor(Qt::darkYellow);
+  } else if(activity & Buffer::OtherActivity) {
+    return QColor(Qt::darkGreen);
+  } else {
+    if(buf->isActive())
+      return QColor(Qt::black);
+    else
+      return QColor(Qt::gray);
+  }
+}
+
+
+QVariant BufferTreeItem::data(int column, int role) const {
+  switch(role) {
+    case Qt::DisplayRole:
+      return text(column);
+    case Qt::ForegroundRole:
+      return foreground(column);
+    case BufferTreeModel::BufferTypeRole:
+      return buf->bufferType();
+    case BufferTreeModel::BufferActiveRole:
+      return buf->isActive();
+    default:
+      return QVariant();
+  }
+}
+
+/*****************************************
+ * BufferTreeModel
+ *****************************************/
+BufferTreeModel::BufferTreeModel(QObject *parent) : TreeModel(BufferTreeModel::defaultHeader(), parent) {
+  connect(this, SIGNAL(fakeUserInput(BufferId, QString)), ClientProxy::instance(), SLOT(gsUserInput(BufferId, QString)));
+}
+
+QList<QVariant >BufferTreeModel::defaultHeader() {
+  QList<QVariant> data;
+  data << tr("Buffer") << tr("Network");
+  return data;
+}
+
+
+Qt::ItemFlags BufferTreeModel::flags(const QModelIndex &index) const {
+  if(!index.isValid())
+    return 0;
+
+  // I think this is pretty ugly..
+  if(isBufferIndex(index)) {
+    Buffer *buffer = getBufferByIndex(index);
+    if(buffer->bufferType() == Buffer::QueryBuffer)
+      return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
+    else
+      return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+  } else {
+    return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; 
+  }
+}
+
+bool BufferTreeModel::isBufferIndex(const QModelIndex &index) const {
+  return parent(index) != QModelIndex();
+}
+
+Buffer *BufferTreeModel::getBufferByIndex(const QModelIndex &index) const {
+  BufferTreeItem *item = static_cast<BufferTreeItem *>(index.internalPointer());
+  return item->buffer();
+}
+
+QModelIndex BufferTreeModel::getOrCreateNetworkItemIndex(Buffer *buffer) {
+  QString net = buffer->networkName();
+  
+  if(networkItem.contains(net)) {
+    return index(networkItem[net]->row(), 0);
+  } else {
+    QList<QVariant> data;
+    data << net << "";
+    
+    int nextRow = rootItem->childCount();
+    
+    beginInsertRows(QModelIndex(), nextRow, nextRow);
+    rootItem->appendChild(new TreeItem(data, rootItem));
+    endInsertRows();
+    
+    networkItem[net] = rootItem->child(nextRow);
+    return index(nextRow, 0);
+  }
+}
+
+QModelIndex BufferTreeModel::getOrCreateBufferItemIndex(Buffer *buffer) {
+  QModelIndex networkItemIndex = getOrCreateNetworkItemIndex(buffer);
+  
+  if(bufferItem.contains(buffer)) {
+    return index(bufferItem[buffer]->row(), 0, networkItemIndex);
+  } else {
+    // first we determine the parent of the new Item
+    TreeItem *networkItem = static_cast<TreeItem*>(networkItemIndex.internalPointer());
+
+    int nextRow = networkItem->childCount();
+
+    beginInsertRows(networkItemIndex, nextRow, nextRow);
+    networkItem->appendChild(new BufferTreeItem(buffer, networkItem));
+    endInsertRows();
+
+    bufferItem[buffer] = static_cast<BufferTreeItem *>(networkItem->child(nextRow));
+    return index(nextRow, 0, networkItemIndex);
+  }
+}
+
+QStringList BufferTreeModel::mimeTypes() const {
+  QStringList types;
+  types << "application/Quassel/BufferItem/row"
+    << "application/Quassel/BufferItem/network";
+  return types;
+}
+
+QMimeData *BufferTreeModel::mimeData(const QModelIndexList &indexes) const {
+  QMimeData *mimeData = new QMimeData();
+
+  QModelIndex index = indexes.first();
+  
+  mimeData->setData("application/Quassel/BufferItem/row", QByteArray::number(index.row()));
+  mimeData->setData("application/Quassel/BufferItem/network", getBufferByIndex(index)->networkName().toUtf8());
+  return mimeData;
+}
+
+bool BufferTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) {
+  int sourcerow = data->data("application/Quassel/BufferItem/row").toInt();
+  QString network = QString::fromUtf8(data->data("application/Quassel/BufferItem/network"));
+  
+  if(!networkItem.contains(network))
+    return false;
+
+  if(!isBufferIndex(parent)) // dropping at a network -> no merging needed
+    return false;
+
+  Buffer *sourceBuffer = static_cast<BufferTreeItem *>(networkItem[network]->child(sourcerow))->buffer();
+  Buffer *targetBuffer = getBufferByIndex(parent);
+  
+  if(sourceBuffer == targetBuffer) // we won't merge with ourself :)
+    return false;
+  
+  /*
+  if(QMessageBox::warning(static_cast<QWidget *>(QObject::parent()),
+                          tr("Merge Buffers?"),
+                          tr("Do you really want to merge the following Buffers?<br />%1.%2<br />%3.%4").arg(sourceBuffer->networkName()).arg(sourceBuffer->bufferName()).arg(targetBuffer->networkName()).arg(targetBuffer->bufferName()),
+                          QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
+    return false;
+
+  */
+  qDebug() << "merging" << sourceBuffer->bufferName() << "with" << targetBuffer->bufferName();
+  bufferItem.remove(getBufferByIndex(parent));
+  removeRow(parent.row(), BufferTreeModel::parent(parent));
+  
+  return true;
+}
+
+void BufferTreeModel::bufferUpdated(Buffer *buffer) {
+  QModelIndex itemindex = getOrCreateBufferItemIndex(buffer);
+  emit invalidateFilter();
+  emit dataChanged(itemindex, itemindex);
+}
+
+// This Slot indicates that the user has selected a different buffer in the gui
+void BufferTreeModel::changeCurrent(const QModelIndex &current, const QModelIndex &previous) {
+  if(isBufferIndex(current)) {
+    currentBuffer = getBufferByIndex(current);
+    bufferActivity(Buffer::NoActivity, currentBuffer);
+    emit bufferSelected(currentBuffer);
+    emit updateSelection(current, QItemSelectionModel::ClearAndSelect);
+  }
+}
+
+// we received a double click on a buffer, so we're going to join it
+void BufferTreeModel::doubleClickReceived(const QModelIndex &clicked) {
+  if(isBufferIndex(clicked)) {
+    Buffer *buffer = getBufferByIndex(clicked);
+    if(!buffer->isStatusBuffer()) 
+      emit fakeUserInput(buffer->bufferId(), QString("/join " + buffer->bufferName()));
+  }
+    
+}
+
+void BufferTreeModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buffer) {
+  if(bufferItem.contains(buffer) and buffer != currentBuffer)
+    bufferItem[buffer]->setActivity(level);
+  else
+    bufferItem[buffer]->setActivity(Buffer::NoActivity);
+  bufferUpdated(buffer);
+}
+
+void BufferTreeModel::selectBuffer(Buffer *buffer) {
+  QModelIndex index = getOrCreateBufferItemIndex(buffer);
+  emit updateSelection(index, QItemSelectionModel::ClearAndSelect);
+}
diff --git a/src/client/buffertreemodel.h b/src/client/buffertreemodel.h
new file mode 100644 (file)
index 0000000..0848c8f
--- /dev/null
@@ -0,0 +1,99 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef _BUFFERTREEMODEL_H_
+#define _BUFFERTREEMODEL_H_
+
+#include <QtCore>
+
+#include "treemodel.h"
+#include "buffer.h"
+#include "clientproxy.h"
+
+/*****************************************
+ *  Fancy Buffer Items
+ *****************************************/
+class BufferTreeItem : public TreeItem{
+  Q_OBJECT
+  
+public:
+  BufferTreeItem(Buffer *, TreeItem *parent = 0);
+  QVariant data(int column, int role) const;
+  Buffer *buffer() const { return buf; }
+  void setActivity(const Buffer::ActivityLevel &);
+  
+protected:
+  QString text(int column) const;
+  QColor foreground(int column) const;
+  
+  Buffer *buf;
+  Buffer::ActivityLevel activity;
+};
+
+
+/*****************************************
+ * BufferTreeModel
+ *****************************************/
+class BufferTreeModel : public TreeModel {
+  Q_OBJECT
+  
+public:
+  enum  myRoles {
+    BufferTypeRole = Qt::UserRole,
+    BufferActiveRole
+  };
+  
+  //BufferTreeModel(const QList<QVariant> &, QObject *parent = 0);
+  BufferTreeModel(QObject *parent = 0);
+  static QList<QVariant> defaultHeader();
+
+  virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+  
+//  void clearActivity(Buffer *buffer);
+  
+public slots:
+  void bufferUpdated(Buffer *);    
+  void changeCurrent(const QModelIndex &, const QModelIndex &);
+  void selectBuffer(Buffer *buffer);
+  void doubleClickReceived(const QModelIndex &);
+  void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
+  
+signals:
+  void bufferSelected(Buffer *);
+  void invalidateFilter();
+  void fakeUserInput(BufferId, QString);
+  void updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags);
+    
+private:
+  bool isBufferIndex(const QModelIndex &) const;
+  Buffer *getBufferByIndex(const QModelIndex &) const;
+  QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
+  QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
+
+  QStringList mimeTypes() const;
+  QMimeData *mimeData(const QModelIndexList &) const;
+  bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
+  
+  QHash<QString, TreeItem*> networkItem;
+  QHash<Buffer *, BufferTreeItem*> bufferItem;
+  Buffer *currentBuffer;
+};
+
+#endif
diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp
new file mode 100644 (file)
index 0000000..3f26449
--- /dev/null
@@ -0,0 +1,171 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "global.h"
+#include "treemodel.h"
+
+/*****************************************
+ *  Buffer Items stored in the Tree Model
+ *****************************************/
+TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) : QObject(parent) {
+  itemData = data;
+  parentItem = parent;
+}
+
+TreeItem::TreeItem(TreeItem *parent) {
+  itemData = QList<QVariant>();
+  parentItem = parent;
+}
+
+TreeItem::~TreeItem() {
+  qDeleteAll(childItems);
+}
+
+void TreeItem::appendChild(TreeItem *item) {
+  childItems.append(item);
+}
+
+void TreeItem::removeChild(int row) {
+  childItems.removeAt(row);
+}
+
+TreeItem *TreeItem::child(int row) {
+  return childItems.value(row);
+}
+
+int TreeItem::childCount() const {
+  return childItems.count();
+}
+
+int TreeItem::row() const {
+  if(parentItem)
+    return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
+  else
+    return 0;
+}
+
+TreeItem *TreeItem::parent() {
+  return parentItem;
+}
+
+int TreeItem::columnCount() const {
+  return itemData.count();
+}
+
+QVariant TreeItem::data(int column, int role) const {
+  if(role == Qt::DisplayRole and column < itemData.count())
+    return itemData[column];
+  else
+    return QVariant();
+}
+
+
+/*****************************************
+ * TreeModel
+ *****************************************/
+TreeModel::TreeModel(const QList<QVariant> &data, QObject *parent) : QAbstractItemModel(parent) {
+  rootItem = new TreeItem(data, 0);
+}
+
+TreeModel::~TreeModel() {
+  delete rootItem;
+}
+
+QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const {
+  if(!hasIndex(row, column, parent))
+    return QModelIndex();
+  
+  TreeItem *parentItem;
+  
+  if(!parent.isValid())
+    parentItem = rootItem;
+  else
+    parentItem = static_cast<TreeItem*>(parent.internalPointer());
+  
+  TreeItem *childItem = parentItem->child(row);
+  if(childItem)
+    return createIndex(row, column, childItem);
+  else
+    return QModelIndex();
+}
+
+QModelIndex TreeModel::parent(const QModelIndex &index) const {
+  if(!index.isValid())
+    return QModelIndex();
+  
+  TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
+  TreeItem *parentItem = childItem->parent();
+  
+  if(parentItem == rootItem)
+    return QModelIndex();
+  
+  return createIndex(parentItem->row(), 0, parentItem);
+}
+
+int TreeModel::rowCount(const QModelIndex &parent) const {
+  TreeItem *parentItem;
+  if(parent.column() > 0)
+    return 0;
+  
+  if(!parent.isValid())
+    parentItem = rootItem;
+  else
+    parentItem = static_cast<TreeItem*>(parent.internalPointer());
+  
+  return parentItem->childCount();
+}
+
+int TreeModel::columnCount(const QModelIndex &parent) const {
+  if(parent.isValid())
+    return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
+  else
+    return rootItem->columnCount();
+}
+
+QVariant TreeModel::data(const QModelIndex &index, int role) const {
+  if(!index.isValid())
+    return QVariant();
+
+  TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
+  return item->data(index.column(), role);
+}
+
+Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const {
+  if(!index.isValid())
+    return 0;
+  else
+    return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+
+QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const {
+  if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
+    return rootItem->data(section, role);
+  else
+    return QVariant();
+}
+
+bool TreeModel::removeRow(int row, const QModelIndex &parent) {
+  beginRemoveRows(parent, row, row);
+  TreeItem *item = static_cast<TreeItem*>(parent.internalPointer());
+  item->removeChild(row);
+  endRemoveRows();
+  return true;
+}
+
diff --git a/src/client/treemodel.h b/src/client/treemodel.h
new file mode 100644 (file)
index 0000000..a403984
--- /dev/null
@@ -0,0 +1,78 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef _TREEMODEL_H_
+#define _TREEMODEL_H_
+
+#include <QtCore>
+
+/*****************************************
+ *  general item used in the Tree Model
+ *****************************************/
+class TreeItem : public QObject {
+  Q_OBJECT
+  
+public:
+  TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
+  TreeItem(TreeItem *parent = 0);
+  virtual ~TreeItem();
+  
+  void appendChild(TreeItem *child);
+  void removeChild(int row);
+                   
+  TreeItem *child(int row);
+  int childCount() const;
+  int columnCount() const;
+  virtual QVariant data(int column, int role) const;
+  int row() const;
+  TreeItem *parent();
+    
+protected:
+  QList<TreeItem*> childItems;
+  TreeItem *parentItem;
+  QList<QVariant> itemData;
+};
+
+
+/*****************************************
+ * TreeModel
+ *****************************************/
+class TreeModel : public QAbstractItemModel {
+  Q_OBJECT
+  
+public:
+  TreeModel(const QList<QVariant> &, QObject *parent = 0);
+  virtual ~TreeModel();
+  
+  QVariant data(const QModelIndex &index, int role) const;
+  virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+  QModelIndex parent(const QModelIndex &index) const;
+  int rowCount(const QModelIndex &parent = QModelIndex()) const;
+  int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+protected:
+  bool removeRow(int row, const QModelIndex &parent = QModelIndex());
+  
+  TreeItem *rootItem;
+};
+
+#endif
diff --git a/src/qtgui/bufferviewfilter.cpp b/src/qtgui/bufferviewfilter.cpp
new file mode 100644 (file)
index 0000000..caa1fb3
--- /dev/null
@@ -0,0 +1,72 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "bufferviewfilter.h"
+
+/*****************************************
+* The Filter for the Tree View
+*****************************************/
+BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, Modes filtermode, QStringList nets, QObject *parent) : QSortFilterProxyModel(parent) {
+  setSourceModel(model);
+  mode = filtermode;
+  networks = nets;
+  
+  connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidateMe()));
+  connect(model, SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)), this, SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
+    
+  connect(this, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), model, SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
+  connect(this, SIGNAL(doubleClicked(const QModelIndex &)), model, SLOT(doubleClickReceived(const QModelIndex &)));
+}
+
+void BufferViewFilter::invalidateMe() {
+  invalidateFilter();
+}
+
+void BufferViewFilter::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
+  emit updateSelection(mapFromSource(index), command);
+}
+
+void BufferViewFilter::changeCurrent(const QModelIndex &current, const QModelIndex &previous) {
+  emit currentChanged(mapToSource(current), mapToSource(previous));
+}
+
+void BufferViewFilter::doubleClickReceived(const QModelIndex &clicked) {
+  emit doubleClicked(mapToSource(clicked));
+}
+
+bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
+  QModelIndex child = source_parent.child(source_row, 0);
+  if(!child.isValid())
+    return true; // can't imagine this case but true sounds good :)
+
+  Buffer::Type bufferType = (Buffer::Type) child.data(BufferTreeModel::BufferTypeRole).toInt();
+  if((mode & NoChannels) && bufferType == Buffer::ChannelBuffer) return false;
+  if((mode & NoQueries) && bufferType == Buffer::QueryBuffer) return false;
+  if((mode & NoServers) && bufferType == Buffer::ServerBuffer) return false;
+
+  bool isActive = child.data(BufferTreeModel::BufferActiveRole).toBool();
+  if((mode & NoActive) && isActive) return false;
+  if((mode & NoInactive) && !isActive) return false;
+
+  QString net = child.data(Qt::DisplayRole).toString();
+  if((mode & SomeNets) && !networks.contains(net)) return false;
+    
+  return true;
+}
diff --git a/src/qtgui/bufferviewfilter.h b/src/qtgui/bufferviewfilter.h
new file mode 100644 (file)
index 0000000..36c0707
--- /dev/null
@@ -0,0 +1,68 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef _BUFFERVIEWFILTER_H_
+#define _BUFFERVIEWFILTER_H_
+
+#include <QFlags>
+#include "buffer.h"
+#include "buffertreemodel.h"
+
+/*****************************************
+ * Buffer View Filter
+ *****************************************/
+class BufferViewFilter : public QSortFilterProxyModel {
+  Q_OBJECT
+  
+public:
+  enum Mode {
+    NoActive = 0x01,
+    NoInactive = 0x02,
+    SomeNets = 0x04,
+    AllNets = 0x08,
+    NoChannels = 0x10,
+    NoQueries = 0x20,
+    NoServers = 0x40
+  };
+  Q_DECLARE_FLAGS(Modes, Mode)
+
+  BufferViewFilter(QAbstractItemModel *model, Modes mode, QStringList nets, QObject *parent = 0);
+  
+public slots:
+  void invalidateMe();
+  void changeCurrent(const QModelIndex &, const QModelIndex &);
+  void doubleClickReceived(const QModelIndex &);
+  void select(const QModelIndex &, QItemSelectionModel::SelectionFlags);
+  
+signals:
+  void currentChanged(const QModelIndex &, const QModelIndex &);
+  void doubleClicked(const QModelIndex &);
+  void updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags);
+  
+private:
+  bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+
+  Modes mode;
+  QStringList networks;
+};
+Q_DECLARE_OPERATORS_FOR_FLAGS(BufferViewFilter::Modes)    
+
+#endif
+