Add GPL header to mpris script
[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
52   bool buffer(BufferId bufferId, const MessageList &messages); //! returns false if it was the last missing backlogpart
53
54   virtual void requestBacklog(const BufferIdList &bufferIds) = 0;
55   virtual inline void requestInitialBacklog() { requestBacklog(allBufferIds()); }
56
57   virtual void flushBuffer();
58
59 protected:
60   BufferIdList allBufferIds() const;
61   inline void setWaitingBuffers(const QList<BufferId> &buffers) { setWaitingBuffers(buffers.toSet()); }
62   void setWaitingBuffers(const QSet<BufferId> &buffers);
63   void addWaitingBuffer(BufferId buffer);
64
65   ClientBacklogManager *backlogManager;
66
67 private:
68   bool _isBuffering;
69   RequesterType _requesterType;
70   MessageList _bufferedMessages;
71   int _totalBuffers;
72   QSet<BufferId> _buffersWaiting;
73 };
74
75 // ========================================
76 //  FIXED BACKLOG REQUESTER
77 // ========================================
78 class FixedBacklogRequester : public BacklogRequester {
79 public:
80   FixedBacklogRequester(ClientBacklogManager *backlogManager);
81   virtual void requestBacklog(const BufferIdList &bufferIds);
82
83 private:
84   int _backlogCount;
85 };
86
87 // ========================================
88 //  GLOBAL UNREAD BACKLOG REQUESTER
89 // ========================================
90 class GlobalUnreadBacklogRequester : public BacklogRequester {
91 public:
92   GlobalUnreadBacklogRequester(ClientBacklogManager *backlogManager);
93   virtual void requestInitialBacklog();
94   virtual void requestBacklog(const BufferIdList &) {}
95
96 private:
97   int _limit;
98   int _additional;
99 };
100
101 // ========================================
102 //  PER BUFFER UNREAD BACKLOG REQUESTER
103 // ========================================
104 class PerBufferUnreadBacklogRequester : public BacklogRequester {
105 public:
106   PerBufferUnreadBacklogRequester(ClientBacklogManager *backlogManager);
107   virtual void requestBacklog(const BufferIdList &bufferIds);
108
109 private:
110   int _limit;
111   int _additional;
112 };
113
114 #endif //BACKLOGREQUESTER_H