X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fbuffersyncer.cpp;h=05f337db7dd16b8c19d4715eb8402221a7f42f0d;hp=3392403f1dcf0b13bec51d38ca183a8449e7b139;hb=921e54680da16fcf2adb7a90506875aceb6633a4;hpb=558260f52de5a9b1364f5672ace17554efc10a74 diff --git a/src/common/buffersyncer.cpp b/src/common/buffersyncer.cpp index 3392403f..05f337db 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-2015 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,69 +15,132 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "buffersyncer.h" +INIT_SYNCABLE_OBJECT(BufferSyncer) BufferSyncer::BufferSyncer(QObject *parent) - : SyncableObject(parent) + : SyncableObject(parent) { } -BufferSyncer::BufferSyncer(const QHash &lastSeenMsg, QObject *parent) - : SyncableObject(parent), - _lastSeenMsg(lastSeenMsg) + +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(); + +MsgId BufferSyncer::lastSeenMsg(BufferId buffer) const +{ + return _lastSeenMsg.value(buffer, MsgId()); } -bool BufferSyncer::setLastSeenMsg(BufferId buffer, const MsgId &msgId) { - if(!msgId.isValid()) + +bool BufferSyncer::setLastSeenMsg(BufferId buffer, const MsgId &msgId) +{ + if (!msgId.isValid()) + return false; + + 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; - const MsgId oldLastSeenMsg = lastSeenMsg(buffer); - if(!oldLastSeenMsg.isValid() || oldLastSeenMsg < msgId) { - _lastSeenMsg[buffer] = msgId; - emit lastSeenMsgSet(buffer, msgId); + _markerLines[buffer] = msgId; + SYNC(ARG(buffer), ARG(msgId)) + emit markerLineSet(buffer, msgId); return true; - } - return false; } -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++; - } - return list; + +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; + } + return list; } -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()); - } + +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.at(i).value(), list.at(i+1).value()); + } } -void BufferSyncer::removeBuffer(BufferId buffer) { - if(_lastSeenMsg.contains(buffer)) - _lastSeenMsg.remove(buffer); - emit bufferRemoved(buffer); + +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::mergeBuffersPermanently(BufferId buffer1, BufferId buffer2) { - if(_lastSeenMsg.contains(buffer2)) - _lastSeenMsg.remove(buffer2); - emit buffersPermanentlyMerged(buffer1, buffer2); +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)) + _lastSeenMsg.remove(buffer); + if (_markerLines.contains(buffer)) + _markerLines.remove(buffer); + SYNC(ARG(buffer)) + emit bufferRemoved(buffer); +} + + +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); }