1 /***************************************************************************
2 * Copyright (C) 2005-08 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "backlogrequester.h"
25 #include "backlogsettings.h"
26 #include "clientbacklogmanager.h"
28 BacklogRequester::BacklogRequester(bool buffering, ClientBacklogManager *backlogManager)
29 : backlogManager(backlogManager),
30 _isBuffering(buffering)
32 Q_ASSERT(backlogManager);
35 bool BacklogRequester::buffer(BufferId bufferId, const MessageList &messages) {
36 _bufferedMessages << messages;
37 _buffersWaiting.remove(bufferId);
38 return !_buffersWaiting.isEmpty();
41 // ========================================
42 // FIXED BACKLOG REQUESTER
43 // ========================================
44 FixedBacklogRequester::FixedBacklogRequester(ClientBacklogManager *backlogManager)
45 : BacklogRequester(true, backlogManager)
47 BacklogSettings backlogSettings;
48 _backlogCount = backlogSettings.fixedBacklogAmount();
51 void FixedBacklogRequester::requestBacklog() {
52 QList<BufferId> allBuffers = allBufferIds();
53 setWaitingBuffers(allBuffers);
54 backlogManager->emitMessagesRequested(QObject::tr("Requesting a total of up to %1 backlog messages for %2 buffers").arg(_backlogCount * allBuffers.count()).arg(allBuffers.count()));
55 foreach(BufferId bufferId, allBuffers) {
56 backlogManager->requestBacklog(bufferId, -1, -1, _backlogCount);
60 // ========================================
61 // GLOBAL UNREAD BACKLOG REQUESTER
62 // ========================================
63 GlobalUnreadBacklogRequester::GlobalUnreadBacklogRequester(ClientBacklogManager *backlogManager)
64 : BacklogRequester(false, backlogManager)
66 BacklogSettings backlogSettings;
67 _limit = backlogSettings.globalUnreadBacklogLimit();
68 _additional = backlogSettings.globalUnreadBacklogAdditional();
71 void GlobalUnreadBacklogRequester::requestBacklog() {
72 MsgId oldestUnreadMessage;
73 foreach(BufferId bufferId, allBufferIds()) {
74 MsgId msgId = Client::networkModel()->lastSeenMsgId(bufferId);
75 if(!oldestUnreadMessage.isValid() || oldestUnreadMessage > msgId)
76 oldestUnreadMessage = msgId;
78 backlogManager->emitMessagesRequested(QObject::tr("Requesting up to %1 of all unread backlog messages (plus additional %2)").arg(_limit).arg(_additional));
79 backlogManager->requestBacklogAll(oldestUnreadMessage, -1, _limit, _additional);
82 // ========================================
83 // PER BUFFER UNREAD BACKLOG REQUESTER
84 // ========================================
85 PerBufferUnreadBacklogRequester::PerBufferUnreadBacklogRequester(ClientBacklogManager *backlogManager)
86 : BacklogRequester(true, backlogManager)
88 BacklogSettings backlogSettings;
89 _limit = backlogSettings.perBufferUnreadBacklogLimit();
90 _additional = backlogSettings.perBufferUnreadBacklogAdditional();
93 void PerBufferUnreadBacklogRequester::requestBacklog() {
94 QList<BufferId> allBuffers = allBufferIds();
95 setWaitingBuffers(allBuffers);
96 backlogManager->emitMessagesRequested(QObject::tr("Requesting a total of up to %1 unread backlog messages for %2 buffers").arg((_limit + _additional) * allBuffers.count()).arg(allBuffers.count()));
97 foreach(BufferId bufferId, allBuffers) {
98 backlogManager->requestBacklog(bufferId, Client::networkModel()->lastSeenMsgId(bufferId), -1, _limit, _additional);