Merging r780:786 from trunk to branches/0.3. Plus some work-in-progress.
[quassel.git] / src / client / messagemodel.cpp
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 #include "messagemodel.h"
22
23 MessageModel::MessageModel(QObject *parent) : QAbstractItemModel(parent) {
24   
25   
26   
27 }
28
29 MessageModel::~MessageModel() {
30   
31   
32 }
33
34 QVariant MessageModel::data(const QModelIndex &index, int role) const {
35   int row = index.row();
36   if(row < 0 || row >= _messageList.count()) return QVariant();
37   return _messageList[row]->data(index.column(), role);
38 }
39
40 bool MessageModel::setData(const QModelIndex &index, const QVariant &value, int role) {
41   int row = index.row();
42   if(row < 0 || row >= _messageList.count()) return false;
43   if(_messageList[row]->setData(index.column(), role)) {
44     emit dataChanged(index, index); // FIXME make msg emit this (too)
45     return true;
46   }
47   return false;
48 }
49
50 void MessageModel::insertMessage(const Message &msg) {
51   MsgId id = msg.msgId();
52   MessageItem *item = createMessageItem(msg);
53   if(id > )
54     
55 }
56
57 // returns index of msg with given Id or of the next message after that (i.e., the index where we'd insert this msg)
58 int MessageModel::indexForId(MsgId id) {
59   if(!_messageList.count() || id <= _messageList[0]->data(0, MsgIdRole).value<MsgId>()) return 0;
60   if(id > _messageList.last()->data(0, MsgIdRole).value<MsgId>()) return _messageList.count();
61   // binary search
62   int start = 0; int end = _messageList.count()-1;
63   int idx;
64   while(1) {
65     if(start == end) return start;
66     idx = (end + start) / 2;
67     
68 }
69
70 /**********************************************************************************/
71