adapting the backlogmanagers to the new storage api
[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 "backlogsettings.h"
26 #include "clientbacklogmanager.h"
27
28 BacklogRequester::BacklogRequester(bool buffering, ClientBacklogManager *backlogManager)
29   : backlogManager(backlogManager),
30     _isBuffering(buffering)
31 {
32   Q_ASSERT(backlogManager);
33 }
34
35 bool BacklogRequester::buffer(BufferId bufferId, const MessageList &messages) {
36   _bufferedMessages << messages;
37   _buffersWaiting.remove(bufferId);
38   return !_buffersWaiting.isEmpty();
39 }
40
41 // ========================================
42 //  FIXED BACKLOG REQUESTER
43 // ========================================
44 FixedBacklogRequester::FixedBacklogRequester(ClientBacklogManager *backlogManager)
45   : BacklogRequester(true, backlogManager)
46 {
47   BacklogSettings backlogSettings;
48   _backlogCount = backlogSettings.fixedBacklogAmount();
49 }
50
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);
57   }
58 }