activating a view pulls in needed backlog for the displayed buffers
[quassel.git] / src / client / backlogrequester.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef BACKLOGREQUESTER_H
22 #define BACKLOGREQUESTER_H
23
24 #include <QList>
25
26 #include "client.h"
27 #include "message.h"
28 #include "networkmodel.h"
29 #include "types.h"
30
31 class ClientBacklogManager;
32
33 class BacklogRequester {
34 public:
35   enum RequesterType {
36     InvalidRequester = 0,
37     PerBufferFixed,
38     PerBufferUnread,
39     GlobalUnread
40   };
41
42   BacklogRequester(bool buffering, RequesterType requesterType, ClientBacklogManager *backlogManger);
43   virtual inline ~BacklogRequester() {}
44
45   inline bool isBuffering() { return _isBuffering; }
46   inline RequesterType type() { return _requesterType; }
47   inline const QList<Message> &bufferedMessages() { return _bufferedMessages; }
48
49   inline int buffersWaiting() const { return _buffersWaiting.count(); }
50   inline int totalBuffers() const { return _totalBuffers; }
51   //! returns false if it was the last missing backlogpart
52   bool buffer(BufferId bufferId, const MessageList &messages);
53   
54   virtual void requestBacklog(const BufferIdList &bufferIds) = 0;
55   virtual inline void requestBacklog() { requestBacklog(allBufferIds()); }
56
57 protected:
58   BufferIdList allBufferIds() const;
59   inline void setWaitingBuffers(const QList<BufferId> &buffers) { setWaitingBuffers(buffers.toSet()); }
60   void setWaitingBuffers(const QSet<BufferId> &buffers);
61   void addWaitingBuffer(BufferId buffer);
62
63   ClientBacklogManager *backlogManager;
64
65 private:
66   bool _isBuffering;
67   RequesterType _requesterType;
68   MessageList _bufferedMessages;
69   int _totalBuffers;
70   QSet<BufferId> _buffersWaiting;
71 };
72
73 // ========================================
74 //  FIXED BACKLOG REQUESTER
75 // ========================================
76 class FixedBacklogRequester : public BacklogRequester {
77 public:
78   FixedBacklogRequester(ClientBacklogManager *backlogManager);
79   virtual void requestBacklog(const BufferIdList &bufferIds);
80
81 private:
82   int _backlogCount;
83 };
84
85 // ========================================
86 //  GLOBAL UNREAD BACKLOG REQUESTER
87 // ========================================
88 class GlobalUnreadBacklogRequester : public BacklogRequester {
89 public:
90   GlobalUnreadBacklogRequester(ClientBacklogManager *backlogManager);
91   virtual void requestBacklog();
92   virtual void requestBacklog(const BufferIdList &) {}
93
94 private:
95   int _limit;
96   int _additional;
97 };
98
99 // ========================================
100 //  PER BUFFER UNREAD BACKLOG REQUESTER
101 // ========================================
102 class PerBufferUnreadBacklogRequester : public BacklogRequester {
103 public:
104   PerBufferUnreadBacklogRequester(ClientBacklogManager *backlogManager);
105   virtual void requestBacklog(const BufferIdList &bufferIds);
106
107 private:
108   int _limit;
109   int _additional;
110 };
111
112 #endif //BACKLOGREQUESTER_H