X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fbuffersyncer.cpp;h=222f65bc8eb84ee44b87c821d4a51587944f494e;hp=816227fad658693f4ffce28daa1240db3f8b936e;hb=3eebe11329417e77038d860af3b6f35630f40450;hpb=7897b8623a42967511e31c68d5c102033a1dcdb9 diff --git a/src/common/buffersyncer.cpp b/src/common/buffersyncer.cpp index 816227fa..222f65bc 100644 --- a/src/common/buffersyncer.cpp +++ b/src/common/buffersyncer.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,16 +20,21 @@ #include "buffersyncer.h" +INIT_SYNCABLE_OBJECT(BufferSyncer) BufferSyncer::BufferSyncer(QObject *parent) : SyncableObject(parent) { } +BufferSyncer::BufferSyncer(const QHash &lastSeenMsg, const QHash &markerLines, QObject *parent) + : SyncableObject(parent), + _lastSeenMsg(lastSeenMsg), + _markerLines(markerLines) +{ +} MsgId BufferSyncer::lastSeenMsg(BufferId buffer) const { - if(_lastSeenMsg.contains(buffer)) - return _lastSeenMsg[buffer]; - return MsgId(); + return _lastSeenMsg.value(buffer, MsgId()); } bool BufferSyncer::setLastSeenMsg(BufferId buffer, const MsgId &msgId) { @@ -39,19 +44,37 @@ bool BufferSyncer::setLastSeenMsg(BufferId buffer, const MsgId &msgId) { const MsgId oldLastSeenMsg = lastSeenMsg(buffer); if(!oldLastSeenMsg.isValid() || oldLastSeenMsg < msgId) { _lastSeenMsg[buffer] = msgId; + SYNC(ARG(buffer), ARG(msgId)) emit lastSeenMsgSet(buffer, msgId); return true; } return false; } +MsgId BufferSyncer::markerLine(BufferId buffer) const { + return _markerLines.value(buffer, MsgId()); +} + +bool BufferSyncer::setMarkerLine(BufferId buffer, const MsgId &msgId) { + if(!msgId.isValid()) + return false; + + if(_markerLines.value(buffer) == msgId) + return false; + + _markerLines[buffer] = msgId; + SYNC(ARG(buffer), ARG(msgId)) + emit markerLineSet(buffer, msgId); + return true; +} + QVariantList BufferSyncer::initLastSeenMsg() const { QVariantList list; QHash::const_iterator iter = _lastSeenMsg.constBegin(); while(iter != _lastSeenMsg.constEnd()) { list << QVariant::fromValue(iter.key()) - << QVariant::fromValue(iter.value()); - iter++; + << QVariant::fromValue(iter.value()); + ++iter; } return list; } @@ -60,17 +83,43 @@ void BufferSyncer::initSetLastSeenMsg(const QVariantList &list) { _lastSeenMsg.clear(); Q_ASSERT(list.count() % 2 == 0); for(int i = 0; i < list.count(); i += 2) { - setLastSeenMsg(list[i].value(), list[i+1].value()); + setLastSeenMsg(list.at(i).value(), list.at(i+1).value()); + } +} + +QVariantList BufferSyncer::initMarkerLines() const { + QVariantList list; + QHash::const_iterator iter = _markerLines.constBegin(); + while(iter != _markerLines.constEnd()) { + list << QVariant::fromValue(iter.key()) + << QVariant::fromValue(iter.value()); + ++iter; + } + return list; +} + +void BufferSyncer::initSetMarkerLines(const QVariantList &list) { + _markerLines.clear(); + Q_ASSERT(list.count() % 2 == 0); + for(int i = 0; i < list.count(); i += 2) { + setMarkerLine(list.at(i).value(), list.at(i+1).value()); } } void BufferSyncer::removeBuffer(BufferId buffer) { - if(_lastSeenMsg.contains(buffer)) { + if(_lastSeenMsg.contains(buffer)) _lastSeenMsg.remove(buffer); - emit bufferRemoved(buffer); - } + if(_markerLines.contains(buffer)) + _markerLines.remove(buffer); + SYNC(ARG(buffer)) + emit bufferRemoved(buffer); } -// void BufferSyncer::renameBuffer(BufferId buffer, QString newName) { -// emit bufferRenamed(buffer, newName); -// } +void BufferSyncer::mergeBuffersPermanently(BufferId buffer1, BufferId buffer2) { + if(_lastSeenMsg.contains(buffer2)) + _lastSeenMsg.remove(buffer2); + if(_markerLines.contains(buffer2)) + _markerLines.remove(buffer2); + SYNC(ARG(buffer1), ARG(buffer2)) + emit buffersPermanentlyMerged(buffer1, buffer2); +}