Krazy/EBN: fix i18n warnings
[kphotoalbum.git] / ImageManager / ThumbnailStorage.h
blob368863c06c4bbc53a9df4316c0b904db823d16f9
1 /* Copyright (C) 2008 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.
19 #ifndef THUMBNAIL_STORAGE_H
20 #define THUMBNAIL_STORAGE_H
22 #include <qmap.h>
23 #include <qstring.h>
24 #include <QMutex>
25 #include <QSet>
26 class QImage;
28 namespace ImageManager {
30 /**
31 * Interface of a backend to store thumbnails.
32 * Implementations of ThumbnailStorage must be thread save.
34 class ThumbnailStorage {
35 public:
36 virtual ~ThumbnailStorage() {}
38 /** Store an image under the given key. Returns success. */
39 virtual bool store(const QString& key, const QImage& image) = 0;
41 /**
42 * Tries to retrieve an image stored under the given key. On success,
43 * returns 'true' and fills in the image.
45 virtual bool retrieve(const QString& key, QImage* image) = 0;
47 /**
48 * Remove an image under the given key from the storage.
50 virtual void remove(const QString& key) = 0;
52 /**
53 * Check if the thumbnail with the given key exists. Use if you don't
54 * want to load the thumbnail but check if you would need go generate it.
56 virtual bool exists(const QString& key) = 0;
60 /**
61 * Default implementation of the ThumbnailStorage. It stores images
62 * in ~/.thumbnails/${key}.${imageFormat}.
64 class FileThumbnailStorage : public ThumbnailStorage {
65 public:
66 /**
67 * construct a FileThumbnailStorage. Store the images in the given
68 * "imageFormat", which can be 'png', 'ppm', 'jpg'. The 'png' format
69 * would be the standard format to be compatible with other
70 * applications (see <http://jens.triq.net/thumbnail-spec/>), but turns
71 * out that the 'ppm' format seems to be much faster.
72 * If "imageFormat" is NULL, we fall back to 'ppm' as default.
74 FileThumbnailStorage(const QString & imageFormat);
76 virtual bool store(const QString& key, const QImage& image);
77 virtual bool retrieve(const QString& key, QImage* image);
78 virtual void remove(const QString& key);
79 virtual bool exists(const QString& key);
81 private:
82 QString keyToPath(const QString& key);
83 QMutex _cacheLock;
84 QSet<QString> _existenceCache;
85 QString _imageFormat;
88 // If Filesystem-IO makes trouble, we could consider implementing a
89 // store in BerkeleyDB or SQLite...
91 #ifdef TESTING_MEMORY_THUMBNAIL_CACHING
92 class MemoryThumbnailStorage : public ThumbnailStorage {
93 public:
94 MemoryThumbnailStorage(const char* imageFormat);
95 virtual bool store(const QString& key, const QImage& image);
96 virtual bool retrieve(const QString& key, QImage* image);
97 virtual void remove(const QString&) {}
98 virtual bool exists(const QString& key);
100 private:
101 typedef QMap<QString, QByteArray> ImageCache;
102 // TODO: add mutex, if tested in multiple threads
103 ImageCache _cache;
104 const char* const _imageFormat;
106 #endif
108 } // end namespace ImageManager
110 #endif /* THUMBNAIL_STORAGE_H */