Fix license headers: Quassel IRC Team -> Quassel Project, 2007 -> 2008
[quassel.git] / src / client / nickmodel.h
index b49ebf1..4baa111 100644 (file)
@@ -1,11 +1,11 @@
 /***************************************************************************
- *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
  *   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.                                   *
+ *   (at your option) version 3.                                           *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
@@ -22,6 +22,7 @@
 #define _NICKMODEL_H_
 
 #include <QAbstractItemModel>
+#include <QSortFilterProxyModel>
 #include <QVector>
 
 class IrcChannel;
@@ -32,12 +33,14 @@ class IrcUser;
  *  levels, where the top-level items are the categories (such as Ops, Voiced etc), and the second-level items
  *  the actual nicks/users. Several roles are provided to access information about a nick.
  *
- *  Note that the nicks are not sorted in any way. Use a QSortFilterProxyModel to do that instead.
+ *  Note that the nicks are not sorted in any way. Use a FilteredNickModel instead.
  */
 class NickModel : public QAbstractItemModel {
   Q_OBJECT
 
   public:
+    enum NickModelRole { SortKeyRole = Qt::UserRole };
+
     NickModel(IrcChannel *channel = 0, QObject *parent = 0);
     virtual ~NickModel();
 
@@ -56,7 +59,7 @@ class NickModel : public QAbstractItemModel {
     int userCategory(IrcUser *) const;
 
   public slots:
-    void setIrcChannel(IrcChannel *);
+    void setIrcChannel(IrcChannel *chan = 0);
     void addUser(IrcUser *);
     void removeUser(IrcUser *);
     void removeUser(const QModelIndex &);
@@ -70,4 +73,23 @@ class NickModel : public QAbstractItemModel {
 
 };
 
+//! This ProxyModel can be used on top of a NickModel in order to provide a sorted nicklist and to hide unused categories.
+class FilteredNickModel : public QSortFilterProxyModel {
+  Q_OBJECT
+
+  public:
+    FilteredNickModel(QObject *parent = 0);
+    virtual ~FilteredNickModel();
+
+    virtual void setSourceModel(QAbstractItemModel *model);
+
+  private slots:
+    void sourceRowsInserted(const QModelIndex &, int, int);
+    void sourceRowsRemoved(const QModelIndex &, int, int);
+
+  protected:
+    virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+
+};
+
 #endif