Message flags are now consistently used as Message::Flags rather than quint8.
[quassel.git] / src / client / messagemodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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) version 3.                                           *
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 MESSAGEMODEL_H_
22 #define MESSAGEMODEL_H_
23
24 #include <QAbstractItemModel>
25 #include <QDateTime>
26
27 #include "message.h"
28 #include "types.h"
29
30 class MessageItem;
31 class MsgId;
32
33 class MessageModel : public QAbstractItemModel {
34   Q_OBJECT
35
36   public:
37     enum MessageRoles {
38       MsgIdRole = Qt::UserRole,
39       BufferIdRole,
40       TypeRole,
41       FlagsRole,
42       TimestampRole,
43       UserRole
44     };
45
46     MessageModel(QObject *parent);
47     virtual ~MessageModel();
48
49     inline QModelIndex index(int row, int column, const QModelIndex &/*parent*/ = QModelIndex()) const { return createIndex(row, column); }
50     inline QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
51     inline int rowCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return _messageList.count(); }
52     inline int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 3; }
53
54     virtual QVariant data(const QModelIndex &index, int role) const;
55     virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
56
57     //virtual Qt::ItemFlags flags(const QModelIndex &index) const;
58
59     void insertMessage(const Message &);
60     void insertMessages(const QList<Message> &);
61
62   protected:
63     virtual MessageItem *createMessageItem(const Message &) = 0;
64
65   private:
66     QList<MessageItem *> _messageList;
67
68     int indexForId(MsgId);
69
70 };
71
72 class MessageItem {
73
74   public:
75     enum {
76       TimestampColumn, SenderColumn, TextColumn
77     };
78
79     MessageItem(const Message &);
80     virtual ~MessageItem();
81
82     virtual QVariant data(int column, int role) const;
83     virtual bool setData(int column, const QVariant &value, int role) = 0;
84
85   private:
86     QDateTime _timestamp;
87     MsgId _msgId;
88     BufferId _bufferId;
89     Message::Type _type;
90     Message::Flags _flags;
91 };
92
93 #endif