Hydra 0.20
hydra.src/desktop/ThumbCache.h
00001 
00002 /*
00003  * Copyright (c) 2010 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_HYDRADESKTOP_THUMBCACHE_H__
00009 #define __INCLUDED_HYDRADESKTOP_THUMBCACHE_H__
00010 
00011 #include <list>
00012 #include <map>
00013 #include <set>
00014 
00015 #include <QPixmap>
00016 #include <QMutex>
00017 
00018 #include <desktop/ImageCache.h>
00019 #include <desktop/LoadCache.h>
00020 
00021 namespace desktop
00022 {
00023   class ThreadedThumbCache;
00024 
00025   class FileList; //fwd
00026 };
00027 
00028 
00029 /**
00030  * A ThumbCache that queues background threads to fill in any missing
00031  * thumbnails.
00032  *
00033  * @author Aleksander Demko
00034  */ 
00035 class desktop::ThreadedThumbCache
00036 {
00037   public:
00038     /// constructor
00039     ThreadedThumbCache(void);
00040     // destructor
00041     ~ThreadedThumbCache();
00042 
00043     /// signals all the jobs to die quickly
00044     void flushJobs(void);
00045 
00046     /// check if this pixmap is in the cache
00047     /// done need the fullfilename (for now) as its all hash/rotateCode based
00048     bool containsPixmap(/*const QString &fullfilename,*/ const QString &hash, int rotateCode, int windoww, int windowh);
00049 
00050     /// returns a cached pixmap
00051     /// if one needs to be generated, it does so via a background thread while immediatly returning a null ptr
00052     /// rotate code can be -1 if "not specified"
00053     desktop::cache_ptr<QPixmap> getPixmap(const QString &fullfilename, const QString &hash, int rotateCode, int windoww, int windowh, FileList *fileList = 0, int indexOfFile = -1);
00054 
00055   private:
00056     void workerFunc(QString fullfilename, QString thumbName, QString hash, int rotateCode, int windoww, int windowh,
00057         FileList *fileList, int indexOfFile);
00058     void mainFunc(QString fullfilename, QString thumbName, QImage img, FileList *fileList, int indexOfFile);
00059 
00060   private:
00061     // all access to the member variables and parent functions are protected
00062     // by this mutex
00063 
00064     LoadCacheBase<QPixmap> dm_cache;
00065 
00066     QMutex dm_pendingjobs_lock;
00067     std::set<QString> dm_pendingjobs;
00068 };
00069 
00070 #endif
00071 
 All Classes Namespaces Functions Variables