1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
24 #include "buffersyncer.h"
26 #include "networkmodel.h"
27 #include "quasselui.h"
31 Buffer::Buffer(BufferInfo bufferid, QObject *parent)
33 _bufferInfo(bufferid),
35 _activityLevel(NoActivity)
40 BufferInfo Buffer::bufferInfo() const {
41 // still needed by the gui *sigh* to request the backlogs *sigh*
45 const QList<AbstractUiMsg *> &Buffer::contents() const {
49 void Buffer::appendMsg(const Message &msg) {
50 updateActivityLevel(msg);
51 AbstractUiMsg *m = Client::layoutMsg(msg);
52 layoutedMsgs.append(m);
56 void Buffer::prependMsg(const Message &msg) {
57 // check for duplicate first
58 if(!layoutedMsgs.isEmpty() && msg.msgId() >= layoutedMsgs.first()->msgId()) {
61 updateActivityLevel(msg);
62 layoutQueue.append(msg);
65 bool Buffer::layoutMsg() {
66 if(layoutQueue.isEmpty())
69 AbstractUiMsg *m = Client::layoutMsg(layoutQueue.takeFirst());
70 layoutedMsgs.prepend(m);
73 return !layoutQueue.isEmpty();
76 void Buffer::setVisible(bool visible) {
78 setActivityLevel(NoActivity);
79 //if(layoutedMsgs.isEmpty())
81 //setLastSeenMsg(layoutedMsgs.last()->msgId());
82 if(_lastRcvdMsg.msgId() > 0) setLastSeenMsg(_lastRcvdMsg.msgId());
83 //qDebug() << "setting last seen" << _lastRcvdMsg.msgId();
86 void Buffer::setLastSeenMsg(const MsgId &msgId) {
87 // qDebug() << "want to set lastSeen:" << bufferInfo() << seen << lastSeen();
88 const MsgId oldLastSeen = lastSeenMsg();
89 if(!oldLastSeen.isValid() || (msgId.isValid() && msgId > oldLastSeen)) {
90 //qDebug() << "setting:" << bufferInfo().bufferName() << seen;
92 Client::setBufferLastSeenMsg(bufferInfo().bufferId(), msgId);
93 //qDebug() << "setting lastSeen:" << bufferInfo() << lastSeen();
94 setActivityLevel(NoActivity);
98 void Buffer::setActivityLevel(ActivityLevel level) {
99 _activityLevel = level;
100 if(bufferInfo().bufferId() > 0) {
101 Client::networkModel()->setBufferActivity(bufferInfo(), level);
102 //qDebug() << "setting level:" << bufferInfo() << lastSeen() << level;
106 void Buffer::updateActivityLevel(const Message &msg) {
107 // FIXME dirty hack to allow the lastSeen stuff to continue to work
108 // will be made much nicer once Buffer dies, I hope...
109 if(msg.msgId() > _lastRcvdMsg.msgId()) _lastRcvdMsg = msg;
114 if(msg.flags() & Message::Self) // don't update activity for our own messages
117 if(lastSeenMsg().isValid() && lastSeenMsg() >= msg.msgId())
120 ActivityLevel level = activityLevel() | OtherActivity;
121 if(msg.type() & (Message::Plain | Message::Notice | Message::Action))
124 if(msg.flags() & Message::Highlight)
127 if(level != activityLevel())
128 setActivityLevel(level);