1 /* Copyright (C) 2008-2009 Henner Zeller <h.zeller@acm.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 #ifndef THUMBNAILVIEW_THUMBNAILCACHE_H
19 #define THUMBNAILVIEW_THUMBNAILCACHE_H
27 #include "DB/Result.h"
28 #include "ImageManager/ImageClient.h"
36 namespace ThumbnailView
{
39 * A cache for thumbnails that supports automatic pre-warming.
41 * This is a wrapper around QPixmapCache for the raw store/retrieve
42 * functionality. In addition to that, given a current displayed page
43 * out of a list of images, it attempts to pre-warm the cache with the
44 * thumbnails of the surrounding pages if possible. The sequence of pre-loading
45 * is scheduled according to the observed scroll direction.
47 class ThumbnailCache
: public QObject
, public ImageManager::ImageClient
{
53 * Find the pixmap for the given ResultId. If found, return 'true' and
54 * insert found pixmap into result. Result must not be NULL.
56 bool find(const DB::ResultId
& id
, QPixmap
*result
) const;
58 /** insert the pixmap for the given Media ID */
59 void insert(const DB::ResultId
& id
, const QPixmap
& pix
);
61 /** clear the cache */
65 * set the hot area of thumbnails currently displayed. The values
66 * denote a range in the display list.
67 * The Cache uses this to decide what images not to throw away and
68 * what images to preload.
70 void setHotArea(int from
, int to
);
72 /** Set information about the thumbnails to be displayed.
73 * TODO: view and cache should share a model */
74 void setDisplayList(const DB::Result
& displayList
);
75 void setThumbnailSize(const QSize
& thumbSize
);
78 bool thumbnailStillNeeded(const QString
& fileName
) const;
81 // ImageManager interface. The callback just puts the resulting image
83 virtual void pixmapLoaded( const QString
& fileName
,
84 const QSize
& size
, const QSize
& fullSize
,
85 int angle
, const QImage
& image
,
89 void slotAsyncCacheWarming();
92 static QString
thumbnailPixmapCacheKey(const DB::ResultId
& id
);
95 * Warm the cache for the given range by requesting it.
96 * Including 'from', exlcuding 'to'.
98 void requestRange(int from
, int to
);
100 DB::Result _displayList
;
102 int _hotFrom
, _hotTo
;
104 QTimer
* _asyncWarmingTimer
;
106 mutable QMutex _requestedImagesLock
;
107 typedef QHash
<QString
, DB::ResultId
> RequestedMap
;
108 RequestedMap _requestedImages
;
112 #endif /* THUMBNAILVIEW_THUMBNAILCACHE_H */