Krazy/EBN: fix i18n warnings
[kphotoalbum.git] / ImageManager / RequestQueue.cpp
blob9b17a4346f9b66170fde3e711c19db7b2fee4502
1 /* Copyright (C) 2003-2006 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #include "RequestQueue.h"
19 #include "ImageRequest.h"
21 bool ImageManager::RequestQueue::addRequest( ImageRequest* request )
23 if ( _uniquePending.contains( request ) ) {
24 // We have this very same request already in the queue. Ignore this one.
25 delete request;
26 return false;
29 _queues[ request->priority() ].enqueue( request );
30 _uniquePending.insert( request );
32 if ( request->client() )
33 _activeRequests.insert( request );
35 return true;
38 ImageManager::ImageRequest* ImageManager::RequestQueue::popNext()
40 QueueType::iterator it = _queues.end(); // _queues is initialized to non-zero size
41 do {
42 --it;
43 while ( ! it->empty() ) {
44 ImageRequest* request = it->dequeue();
46 if ( ! request->stillNeeded() ) {
47 removeRequest( request );
48 delete request;
49 } else {
50 _uniquePending.remove( request );
51 return request;
54 } while ( it != _queues.begin() );
56 return NULL;
59 void ImageManager::RequestQueue::cancelRequests( ImageClient* client, StopAction action )
61 // remove from active map
62 for( QSet<ImageRequest*>::const_iterator it = _activeRequests.begin(); it != _activeRequests.end(); ) {
63 ImageRequest* request = *it;
64 ++it; // We need to increase it before removing the element.
65 if ( client == request->client() && ( action == StopAll || ( request->priority() < ThumbnailVisible ) ) ) {
66 _activeRequests.remove( request );
67 // active requests are not deleted - they might already have been
68 // popNext()ed and are being processed. They will be deleted
69 // in Manger::customEvent().
73 for ( QueueType::iterator qit = _queues.begin(); qit != _queues.end(); ++qit ) {
74 for ( QQueue<ImageRequest*>::iterator it = qit->begin(); it != qit->end(); /* no increment here */) {
75 ImageRequest* request = *it;
76 if ( request->client() == client && ( action == StopAll || request->priority() < ThumbnailVisible ) ) {
77 it = qit->erase( it );
78 _uniquePending.remove( request );
79 delete request;
80 } else {
81 ++it;
87 bool ImageManager::RequestQueue::isRequestStillValid( ImageRequest* request )
89 return _activeRequests.contains( request );
92 void ImageManager::RequestQueue::removeRequest( ImageRequest* request )
94 _activeRequests.remove( request );
95 _uniquePending.remove( request );
98 ImageManager::RequestQueue::RequestQueue()
100 for ( int i = 0; i < LastPriority; ++i )
101 _queues.append( QQueue<ImageRequest*>() );
105 #include "RequestQueue.moc"