1 /***************************************************************************
2 * Copyright (C) 2005-2019 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 ***************************************************************************/
21 #ifndef BACKLOGREQUESTER_H
22 #define BACKLOGREQUESTER_H
28 #include "networkmodel.h"
31 class ClientBacklogManager;
33 class BacklogRequester
44 BacklogRequester(bool buffering, RequesterType requesterType, ClientBacklogManager* backlogManger);
45 virtual ~BacklogRequester() = default;
47 inline bool isBuffering() { return _isBuffering; }
48 inline RequesterType type() { return _requesterType; }
49 inline const QList<Message>& bufferedMessages() { return _bufferedMessages; }
51 inline int buffersWaiting() const { return _buffersWaiting.count(); }
52 inline int totalBuffers() const { return _totalBuffers; }
54 bool buffer(BufferId bufferId, const MessageList& messages); //! returns false if it was the last missing backlogpart
56 virtual void requestBacklog(const BufferIdList& bufferIds) = 0;
57 virtual inline void requestInitialBacklog() { requestBacklog(allBufferIds()); }
59 virtual void flushBuffer();
62 BufferIdList allBufferIds() const;
63 inline void setWaitingBuffers(const QList<BufferId>& buffers) { setWaitingBuffers(buffers.toSet()); }
64 void setWaitingBuffers(const QSet<BufferId>& buffers);
65 void addWaitingBuffer(BufferId buffer);
67 ClientBacklogManager* backlogManager;
71 RequesterType _requesterType;
72 MessageList _bufferedMessages;
74 QSet<BufferId> _buffersWaiting;
77 // ========================================
78 // FIXED BACKLOG REQUESTER
79 // ========================================
80 class FixedBacklogRequester : public BacklogRequester
83 FixedBacklogRequester(ClientBacklogManager* backlogManager);
84 void requestBacklog(const BufferIdList& bufferIds) override;
90 // ========================================
91 // GLOBAL UNREAD BACKLOG REQUESTER
92 // ========================================
93 class GlobalUnreadBacklogRequester : public BacklogRequester
96 GlobalUnreadBacklogRequester(ClientBacklogManager* backlogManager);
97 void requestInitialBacklog() override;
98 void requestBacklog(const BufferIdList&) override {}
105 // ========================================
106 // PER BUFFER UNREAD BACKLOG REQUESTER
107 // ========================================
108 class PerBufferUnreadBacklogRequester : public BacklogRequester
111 PerBufferUnreadBacklogRequester(ClientBacklogManager* backlogManager);
112 void requestBacklog(const BufferIdList& bufferIds) override;
119 #endif // BACKLOGREQUESTER_H