561c9b7b342729452babbde13d4abb38d213c32b
[quassel.git] / src / qmlui / qmlmessagemodelitem.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2010 by the Quassel Project                        *
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 "qmlchatline.h"
22 #include "qmlmessagemodel.h"
23 #include "qmlmessagemodelitem.h"
24 #include "uistyle.h"
25
26 QmlMessageModelItem::QmlMessageModelItem(const Message &msg)
27   : MessageModelItem(),
28     _styledMsg(msg)
29 {
30   if(!msg.sender().contains('!'))
31     _styledMsg.setFlags(msg.flags() |= Message::ServerMsg);
32 }
33
34 QVariant QmlMessageModelItem::data(int column, int role) const {
35   QVariant variant;
36   switch(role) {
37   case QmlMessageModel::ChatLineDataRole: {
38     QmlChatLine::Data data;
39     data.timestamp.text = _styledMsg.decoratedTimestamp();
40     data.timestamp.formats = UiStyle::FormatList() << qMakePair((quint16)0, (quint32)UiStyle::formatType(_styledMsg.type()) | UiStyle::Timestamp);
41     data.sender.text = _styledMsg.decoratedSender();
42     data.sender.formats = UiStyle::FormatList() << qMakePair((quint16)0, (quint32)UiStyle::formatType(_styledMsg.type()) | UiStyle::Sender);
43     data.contents.text = _styledMsg.plainContents();
44     data.contents.formats = _styledMsg.contentsFormatList();
45     return QVariant::fromValue<QmlChatLine::Data>(data);
46   }
47   default:
48     break;
49   }
50   if(!variant.isValid())
51     return MessageModelItem::data(column, role);
52   return variant;
53 }