The nicklist is back! We now have a NickModel that can be attached to an IrcChannel
[quassel.git] / src / client / nickmodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _NICKMODEL_H_
22 #define _NICKMODEL_H_
23
24 #include <QAbstractItemModel>
25 #include <QVector>
26
27 class IrcChannel;
28 class IrcUser;
29
30 //! Represents the IrcUsers in a given IrcChannel.
31 /** This model is a wrapper around the nicks/IrcUsers stored in an IrcChannel. It provides a tree with two,
32  *  levels, where the top-level items are the categories (such as Ops, Voiced etc), and the second-level items
33  *  the actual nicks/users. Several roles are provided to access information about a nick.
34  *
35  *  Note that the nicks are not sorted in any way. Use a QSortFilterProxyModel to do that instead.
36  */
37 class NickModel : public QAbstractItemModel {
38   Q_OBJECT
39
40   public:
41     NickModel(IrcChannel *channel = 0, QObject *parent = 0);
42     virtual ~NickModel();
43
44     virtual QModelIndex index(int row, int col, const QModelIndex &parent) const;
45     virtual QModelIndex parent(const QModelIndex &index) const;
46     virtual int rowCount(const QModelIndex &) const;
47     virtual int columnCount(const QModelIndex &) const;
48     virtual QVariant data(const QModelIndex &, int role) const;
49     virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
50
51     IrcChannel *ircChannel() const;
52
53     QModelIndex indexOfUser(IrcUser *) const;
54     int categoryFromModes(const QString &modes) const;
55     int categoryFromIndex(const QModelIndex &index) const;
56     int userCategory(IrcUser *) const;
57
58   public slots:
59     void setIrcChannel(IrcChannel *);
60     void addUser(IrcUser *);
61     void removeUser(IrcUser *);
62     void removeUser(const QModelIndex &);
63     void renameUser(IrcUser *);
64     void changeUserModes(IrcUser *);
65
66   private:
67
68     IrcChannel *_ircChannel;
69     QVector<QList<IrcUser *> > users;
70
71 };
72
73 #endif