qa: Avoid deprecation warnings for QList/QSet conversions
[quassel.git] / src / client / backlogrequester.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 <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         GlobalUnread
43     };
44
45     BacklogRequester(bool buffering, RequesterType requesterType, ClientBacklogManager* backlogManger);
46     virtual ~BacklogRequester() = default;
47
48     inline bool isBuffering() { return _isBuffering; }
49     inline RequesterType type() { return _requesterType; }
50     inline const QList<Message>& bufferedMessages() { return _bufferedMessages; }
51
52     inline int buffersWaiting() const { return int(_buffersWaiting.size()); }
53     inline int totalBuffers() const { return _totalBuffers; }
54
55     bool buffer(BufferId bufferId, const MessageList& messages);  //! returns false if it was the last missing backlogpart
56
57     virtual void requestBacklog(const BufferIdList& bufferIds) = 0;
58     virtual inline void requestInitialBacklog() { requestBacklog(allBufferIds()); }
59
60     virtual void flushBuffer();
61
62 protected:
63     BufferIdList allBufferIds() const;
64     void setWaitingBuffers(const BufferIdList& buffers);
65
66     ClientBacklogManager* backlogManager;
67
68 private:
69     bool _isBuffering;
70     RequesterType _requesterType;
71     MessageList _bufferedMessages;
72     int _totalBuffers;
73     std::set<BufferId> _buffersWaiting;
74 };
75
76 // ========================================
77 //  FIXED BACKLOG REQUESTER
78 // ========================================
79 class FixedBacklogRequester : public BacklogRequester
80 {
81 public:
82     FixedBacklogRequester(ClientBacklogManager* backlogManager);
83     void requestBacklog(const BufferIdList& bufferIds) override;
84
85 private:
86     int _backlogCount;
87 };
88
89 // ========================================
90 //  GLOBAL UNREAD BACKLOG REQUESTER
91 // ========================================
92 class GlobalUnreadBacklogRequester : public BacklogRequester
93 {
94 public:
95     GlobalUnreadBacklogRequester(ClientBacklogManager* backlogManager);
96     void requestInitialBacklog() override;
97     void requestBacklog(const BufferIdList&) override {}
98
99 private:
100     int _limit;
101     int _additional;
102 };
103
104 // ========================================
105 //  PER BUFFER UNREAD BACKLOG REQUESTER
106 // ========================================
107 class PerBufferUnreadBacklogRequester : public BacklogRequester
108 {
109 public:
110     PerBufferUnreadBacklogRequester(ClientBacklogManager* backlogManager);
111     void requestBacklog(const BufferIdList& bufferIds) override;
112
113 private:
114     int _limit;
115     int _additional;
116 };