diff options
author | Arno <am@disconnect.de> | 2013-04-11 07:19:51 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-04-11 07:19:51 +0200 |
commit | a39b9bb410593edf105be3ce808b6bfd94f95cde (patch) | |
tree | 4566c8f01b3071d9758a376307ee290b681f8965 /framecache.cpp | |
parent | d71c97f56f4eb35a8918b9741fe6bfd6417a3b5c (diff) | |
download | SheMov-a39b9bb410593edf105be3ce808b6bfd94f95cde.tar.gz SheMov-a39b9bb410593edf105be3ce808b6bfd94f95cde.tar.bz2 SheMov-a39b9bb410593edf105be3ce808b6bfd94f95cde.zip |
Fix frame cacheDir
Get rid of the cache file. Instead, generate the cache on startup. The
cache was never written since it was turned into a thread. Because of
that I wrote a cleanup function, but surprisingly it didn't have much
impact on the startup time, so I dropped the cache file.
Also, fix destructor of SmGlobals. Call deleteLater on all Q_OBJECTS,
and of course, some header cleanup.
Diffstat (limited to 'framecache.cpp')
-rw-r--r-- | framecache.cpp | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/framecache.cpp b/framecache.cpp index ef5329a..e6fceaa 100644 --- a/framecache.cpp +++ b/framecache.cpp @@ -26,9 +26,7 @@ FrameCache::FrameCache(QObject *parent) : QObject(parent){ mGenerator = new FrameCacheGenerator(this); mGenerator->init(mSemFree, mSemUsed, mCacheMx, mDataQueue, mFrameCache); mGenerator->readConfig(); - mGenerator->readCache(); - mCacheFile = mGenerator->cacheFile(); - mMagic = mGenerator->magic(); + rebuild(); mGenerator->start(); QSettings s; mWhen = s.value("ui/grabframe", "00:00:00").toString(); @@ -36,14 +34,6 @@ FrameCache::FrameCache(QObject *parent) : QObject(parent){ FrameCache::~FrameCache(){ mGenerator->exit(); - QFile outfile(mCacheFile); - outfile.open(QIODevice::WriteOnly | QIODevice::Truncate); - QDataStream ds(&outfile); - ds << (qint32)mMagic; - for(QHash<QPair<QString, QString>, QString>::const_iterator it = mFrameCache->constBegin(); it != mFrameCache->constEnd(); ++it){ - ds << it.key().first << it.key().second << it.value(); - } - outfile.close(); } const QPixmap FrameCache::entry(const QString &sourcePath, const QString &when){ @@ -80,7 +70,27 @@ const QString FrameCache::entryPath(const QString &sourcePath, const QString &wh return mFrameCache->value(data); } -FrameCacheGenerator::FrameCacheGenerator(QObject *parent) : QThread(parent), mMagic(0xDEADBEEF), mCacheSubDir(".frameCache"), mCacheFileName("cache") {} +void FrameCache::rebuild(){ + QMutexLocker l(mCacheMx); + QDir cdir(mGenerator->cacheDir()); + QFileInfoList files = cdir.entryInfoList(QDir::Files); + mFrameCache->clear(); + foreach(QFileInfo fi, files){ + QString base = fi.fileName(); + base.chop(fi.suffix().size() + 1); // basename doesn't work, b/c we have filenames w spaces + base.chop(7); //remove temp. extension + QString when = base.right(8); + base.chop(9); //remove when + _, leaving the orig. filename + QPair<QString, QString> key = qMakePair<QString, QString>(base, when); + if(mFrameCache->contains(key)){ + QFile::remove(fi.absoluteFilePath()); + }else{ + mFrameCache->insert(key, fi.absoluteFilePath()); + } + } +} + +FrameCacheGenerator::FrameCacheGenerator(QObject *parent) : QThread(parent), mCacheSubDir(".frameCache"), mCacheFileName("cache") {} void FrameCacheGenerator::init(QSemaphore *set, QSemaphore *get, QMutex *cachemx, QQueue<QPair<QString, QString> > *data, QHash<QPair<QString, QString>, QString> *cache){ mSemFree = set; @@ -106,28 +116,6 @@ void FrameCacheGenerator::readConfig(){ mFfMpegPath = s.value("paths/ffmpeg").toString(); } -void FrameCacheGenerator::readCache(){ - QFile cache(mCacheFile); - cache.open(QIODevice::ReadOnly); - QDataStream ds(&cache); - qint32 magic; - ds >> magic; - if(magic != mMagic){ - return; - } - while(!ds.atEnd()){ - QString source, pos, cacheFile; - ds >> source >> pos >> cacheFile; - QFileInfo fi(cacheFile); - if(fi.size() == 0){ - QFile::remove(fi.absoluteFilePath()); - continue; - } - QPair<QString, QString> pair(source, pos); - mFrameCache->insert(pair, cacheFile); - } -} - void FrameCacheGenerator::run(){ forever{ mSemUsed->acquire(); |