giving the message model the control over the dynamic backlog requests
[quassel.git] / src / client / backlogrequester.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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 #include "backlogrequester.h"
22
23 #include <QObject>
24
25 #include "clientbacklogmanager.h"
26
27 BacklogRequester::BacklogRequester(bool buffering, ClientBacklogManager *backlogManager)
28   : backlogManager(backlogManager),
29     _isBuffering(buffering)
30 {
31   Q_ASSERT(backlogManager);
32 }
33
34 bool BacklogRequester::buffer(BufferId bufferId, const MessageList &messages) {
35   _bufferedMessages << messages;
36   _buffersWaiting.remove(bufferId);
37   return !_buffersWaiting.isEmpty();
38 }
39
40 // ========================================
41 //  FIXED BACKLOG REQUESTER
42 // ========================================
43 FixedBacklogRequester::FixedBacklogRequester(ClientBacklogManager *backlogManager)
44   : BacklogRequester(true, backlogManager),
45     _backlogCount(500)
46 {
47 }
48
49 void FixedBacklogRequester::requestBacklog() {
50   QList<BufferId> allBuffers = allBufferIds();
51   setWaitingBuffers(allBuffers);
52   backlogManager->emitMessagesRequested(QObject::tr("Requesting a total of up to %1 backlog messages for %2 buffers").arg(_backlogCount * allBuffers.count()).arg(allBuffers.count()));
53   foreach(BufferId bufferId, allBuffers) {
54     backlogManager->requestBacklog(bufferId, _backlogCount, -1);
55   }
56 }