cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / client / backlogrequester.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2022 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 <set>
24
25 #include <QList>
26
27 #include "client.h"
28 #include "message.h"
29 #include "networkmodel.h"
30 #include "types.h"
31
32 class ClientBacklogManager;
33
34 class BacklogRequester
35 {
36 public:
37     enum RequesterType
38     {
39         InvalidRequester = 0,
40         PerBufferFixed,
41         PerBufferUnread,
42         AsNeeded,              ///< Only request backlog on cores without Feature::BufferActivitySync
43         GlobalUnread
44     };
45
46     BacklogRequester(bool buffering, RequesterType requesterType, ClientBacklogManager* backlogManger);
47     virtual ~BacklogRequester() = default;
48
49     inline bool isBuffering() { return _isBuffering; }
50     inline RequesterType type() { return _requesterType; }
51     inline const QList<Message>& bufferedMessages() { return _bufferedMessages; }
52
53     inline int buffersWaiting() const { return int(_buffersWaiting.size()); }
54     inline int totalBuffers() const { return _totalBuffers; }
55
56     bool buffer(BufferId bufferId, const MessageList& messages);  //! returns false if it was the last missing backlogpart
57
58     virtual void requestBacklog(const BufferIdList& bufferIds) = 0;
59     virtual inline void requestInitialBacklog() { requestBacklog(allBufferIds()); }
60
61     virtual void flushBuffer();
62
63 protected:
64     BufferIdList allBufferIds() const;
65     void setWaitingBuffers(const BufferIdList& buffers);
66
67     ClientBacklogManager* backlogManager;
68
69 private:
70     bool _isBuffering;
71     RequesterType _requesterType;
72     MessageList _bufferedMessages;
73     int _totalBuffers;
74     std::set<BufferId> _buffersWaiting;
75 };
76
77 // ========================================
78 //  FIXED BACKLOG REQUESTER
79 // ========================================
80 class FixedBacklogRequester : public BacklogRequester
81 {
82 public:
83     FixedBacklogRequester(ClientBacklogManager* backlogManager);
84     void requestBacklog(const BufferIdList& bufferIds) override;
85
86 private:
87     int _backlogCount;
88 };
89
90 // ========================================
91 //  GLOBAL UNREAD BACKLOG REQUESTER
92 // ========================================
93 class GlobalUnreadBacklogRequester : public BacklogRequester
94 {
95 public:
96     GlobalUnreadBacklogRequester(ClientBacklogManager* backlogManager);
97     void requestInitialBacklog() override;
98     void requestBacklog(const BufferIdList&) override {}
99
100 private:
101     int _limit;
102     int _additional;
103 };
104
105 // ========================================
106 //  PER BUFFER UNREAD BACKLOG REQUESTER
107 // ========================================
108 class PerBufferUnreadBacklogRequester : public BacklogRequester
109 {
110 public:
111     PerBufferUnreadBacklogRequester(ClientBacklogManager* backlogManager);
112     void requestBacklog(const BufferIdList& bufferIds) override;
113
114 private:
115     int _limit;
116     int _additional;
117 };
118
119 // ========================================
120 //  AS NEEDED BACKLOG REQUESTER
121 // ========================================
122 /**
123  * Backlog requester that only fetches initial backlog when the core doesn't support buffer activity
124  * tracking
125  */
126 class AsNeededBacklogRequester : public BacklogRequester
127 {
128 public:
129     AsNeededBacklogRequester(ClientBacklogManager* backlogManager);
130     void requestBacklog(const BufferIdList& bufferIds) override;
131
132 private:
133     int _legacyBacklogCount;
134 };