core: Track upgrade step within schema version
[quassel.git] / src / core / corebuffersyncer.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #pragma once
22
23 #include "buffersyncer.h"
24
25 class CoreSession;
26
27 class CoreBufferSyncer : public BufferSyncer
28 {
29     Q_OBJECT
30
31 public:
32     explicit CoreBufferSyncer(CoreSession* parent);
33
34 public slots:
35     void requestSetLastSeenMsg(BufferId buffer, const MsgId& msgId) override;
36     void requestSetMarkerLine(BufferId buffer, const MsgId& msgId) override;
37
38     inline void requestRemoveBuffer(BufferId buffer) override { removeBuffer(buffer); }
39     void removeBuffer(BufferId bufferId) override;
40
41     void addBufferActivity(const Message& message)
42     {
43         auto oldActivity = activity(message.bufferId());
44         if (!oldActivity.testFlag(message.type())) {
45             setBufferActivity(message.bufferId(), (int)(oldActivity | message.type()));
46         }
47     }
48
49     void addCoreHighlight(const Message& message)
50     {
51         auto oldHighlightCount = highlightCount(message.bufferId());
52         if (message.flags().testFlag(Message::Flag::Highlight) && !message.flags().testFlag(Message::Flag::Self)) {
53             setHighlightCount(message.bufferId(), oldHighlightCount + 1);
54         }
55     }
56
57     void setBufferActivity(BufferId buffer, int activity) override;
58
59     void setHighlightCount(BufferId buffer, int highlightCount) override;
60
61     inline void requestRenameBuffer(BufferId buffer, QString newName) override { renameBuffer(buffer, newName); }
62     void renameBuffer(BufferId buffer, QString newName) override;
63
64     inline void requestMergeBuffersPermanently(BufferId buffer1, BufferId buffer2) override { mergeBuffersPermanently(buffer1, buffer2); }
65     void mergeBuffersPermanently(BufferId buffer1, BufferId buffer2) override;
66
67     void requestPurgeBufferIds() override;
68
69     inline void requestMarkBufferAsRead(BufferId buffer) override
70     {
71         int activity = Message::Types();
72         setBufferActivity(buffer, activity);
73         setHighlightCount(buffer, 0);
74         markBufferAsRead(buffer);
75     }
76
77     void storeDirtyIds();
78
79 protected:
80     void customEvent(QEvent* event) override;
81
82 private:
83     CoreSession* _coreSession;
84     bool _purgeBuffers;
85
86     QSet<BufferId> dirtyLastSeenBuffers;
87     QSet<BufferId> dirtyMarkerLineBuffers;
88     QSet<BufferId> dirtyActivities;
89     QSet<BufferId> dirtyHighlights;
90
91     void purgeBufferIds();
92 };