1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel IRC Team *
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 ***************************************************************************/
21 #include "buffersyncer.h"
23 BufferSyncer::BufferSyncer(QObject *parent)
24 : SyncableObject(parent)
29 MsgId BufferSyncer::lastSeenMsg(BufferId buffer) const {
30 if(_lastSeenMsg.contains(buffer))
31 return _lastSeenMsg[buffer];
35 bool BufferSyncer::setLastSeenMsg(BufferId buffer, const MsgId &msgId) {
39 const MsgId oldLastSeenMsg = lastSeenMsg(buffer);
40 if(!oldLastSeenMsg.isValid() || oldLastSeenMsg < msgId) {
41 _lastSeenMsg[buffer] = msgId;
42 emit lastSeenMsgSet(buffer, msgId);
48 QVariantList BufferSyncer::initLastSeenMsg() const {
50 QHash<BufferId, MsgId>::const_iterator iter = _lastSeenMsg.constBegin();
51 while(iter != _lastSeenMsg.constEnd()) {
52 list << QVariant::fromValue<BufferId>(iter.key())
53 << QVariant::fromValue<MsgId>(iter.value());
59 void BufferSyncer::initSetLastSeenMsg(const QVariantList &list) {
61 Q_ASSERT(list.count() % 2 == 0);
62 for(int i = 0; i < list.count(); i += 2) {
63 setLastSeenMsg(list[i].value<BufferId>(), list[i+1].value<MsgId>());
67 void BufferSyncer::requestSetLastSeenMsg(BufferId buffer, const MsgId &msgId) {
68 if(setLastSeenMsg(buffer, msgId))
69 emit setLastSeenMsgRequested(buffer, msgId);
73 void BufferSyncer::requestRemoveBuffer(BufferId buffer) {
74 emit removeBufferRequested(buffer);
77 void BufferSyncer::removeBuffer(BufferId buffer) {
78 if(_lastSeenMsg.contains(buffer))
79 _lastSeenMsg.remove(buffer);
80 emit bufferRemoved(buffer);
83 void BufferSyncer::renameBuffer(BufferId buffer, QString newName) {
84 emit bufferRenamed(buffer, newName);