1 /***************************************************************************
2 * Copyright (C) 2005-2020 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include "common-export.h"
26 #include "syncableobject.h"
29 class COMMON_EXPORT BufferSyncer : public SyncableObject
35 explicit BufferSyncer(QObject* parent);
36 explicit BufferSyncer(QHash<BufferId, MsgId> lastMsg,
37 QHash<BufferId, MsgId> lastSeenMsg,
38 QHash<BufferId, MsgId> markerLines,
39 QHash<BufferId, Message::Types> activities,
40 QHash<BufferId, int> highlightCounts,
43 MsgId lastSeenMsg(BufferId buffer) const;
44 MsgId lastMsg(BufferId buffer) const;
45 MsgId markerLine(BufferId buffer) const;
46 Message::Types activity(BufferId buffer) const;
47 int highlightCount(BufferId buffer) const;
49 void markActivitiesChanged()
51 for (auto buffer : _bufferActivities.keys()) {
52 emit bufferActivityChanged(buffer, activity(buffer));
56 void markHighlightCountsChanged()
58 for (auto buffer : _highlightCounts.keys()) {
59 emit highlightCountChanged(buffer, highlightCount(buffer));
64 QVariantList initLastMsg() const;
65 void initSetLastMsg(const QVariantList&);
67 QVariantList initLastSeenMsg() const;
68 void initSetLastSeenMsg(const QVariantList&);
70 QVariantList initMarkerLines() const;
71 void initSetMarkerLines(const QVariantList&);
73 QVariantList initActivities() const;
74 void initSetActivities(const QVariantList&);
76 QVariantList initHighlightCounts() const;
77 void initSetHighlightCounts(const QVariantList&);
79 virtual inline void setLastMsg(BufferId buffer, const MsgId& msgId)
81 SYNC(ARG(buffer), ARG(msgId));
82 _lastMsg[buffer] = msgId;
83 emit lastMsgSet(buffer, msgId);
86 virtual inline void requestSetLastSeenMsg(BufferId buffer, const MsgId& msgId) { REQUEST(ARG(buffer), ARG(msgId)) }
87 virtual inline void requestSetMarkerLine(BufferId buffer, const MsgId& msgId)
89 REQUEST(ARG(buffer), ARG(msgId)) setMarkerLine(buffer, msgId);
92 virtual inline void setBufferActivity(BufferId buffer, int activity)
94 auto flags = Message::Types(activity);
95 SYNC(ARG(buffer), ARG(activity));
96 _bufferActivities[buffer] = flags;
97 emit bufferActivityChanged(buffer, flags);
100 virtual inline void setHighlightCount(BufferId buffer, int count)
102 SYNC(ARG(buffer), ARG(count));
103 _highlightCounts[buffer] = count;
104 emit highlightCountChanged(buffer, count);
107 virtual inline void requestRemoveBuffer(BufferId buffer) { REQUEST(ARG(buffer)) }
108 virtual void removeBuffer(BufferId buffer);
110 virtual inline void requestRenameBuffer(BufferId buffer, QString newName) { REQUEST(ARG(buffer), ARG(newName)) }
111 virtual inline void renameBuffer(BufferId buffer, QString newName)
113 SYNC(ARG(buffer), ARG(newName)) emit bufferRenamed(buffer, newName);
116 virtual inline void requestMergeBuffersPermanently(BufferId buffer1, BufferId buffer2) { emit REQUEST(ARG(buffer1), ARG(buffer2)) }
117 virtual void mergeBuffersPermanently(BufferId buffer1, BufferId buffer2);
119 virtual inline void requestPurgeBufferIds() { REQUEST(NO_ARG); }
121 virtual inline void requestMarkBufferAsRead(BufferId buffer) { REQUEST(ARG(buffer)) emit bufferMarkedAsRead(buffer); }
122 virtual inline void markBufferAsRead(BufferId buffer) { SYNC(ARG(buffer)) emit bufferMarkedAsRead(buffer); }
125 void lastMsgSet(BufferId buffer, const MsgId& msgId);
126 void lastSeenMsgSet(BufferId buffer, const MsgId& msgId);
127 void markerLineSet(BufferId buffer, const MsgId& msgId);
128 void bufferRemoved(BufferId buffer);
129 void bufferRenamed(BufferId buffer, QString newName);
130 void buffersPermanentlyMerged(BufferId buffer1, BufferId buffer2);
131 void bufferMarkedAsRead(BufferId buffer);
132 void bufferActivityChanged(BufferId, Message::Types);
133 void highlightCountChanged(BufferId, int);
136 bool setLastSeenMsg(BufferId buffer, const MsgId& msgId);
137 bool setMarkerLine(BufferId buffer, const MsgId& msgId);
140 inline QList<BufferId> lastBufferIds() const { return _lastMsg.keys(); }
141 inline QList<BufferId> lastSeenBufferIds() const { return _lastSeenMsg.keys(); }
142 inline QList<BufferId> markerLineBufferIds() const { return _markerLines.keys(); }
143 inline QHash<BufferId, MsgId> markerLines() const { return _markerLines; }
146 QHash<BufferId, MsgId> _lastMsg;
147 QHash<BufferId, MsgId> _lastSeenMsg;
148 QHash<BufferId, MsgId> _markerLines;
149 QHash<BufferId, Message::Types> _bufferActivities;
150 QHash<BufferId, int> _highlightCounts;