Permalink
Browse files

Make the ThumbGenerator thread actually abort

When you exit mythgallery, it deletes the ThumbGenerator, which causes it to
wait for completion.  As the inner code was never checking for an abort,
sometimes this would take a very long time, especially when dealing with
RAW format pictures.

Now, when cancel() is called, a flag is set that is checked in the inner
loops to cause a more immediate exit.

Fixes #10185
  • Loading branch information...
1 parent 3925c2c commit 3b83dbd6de293f1f5844675ff20da17a78e3a5ff @Beirdo Beirdo committed Jan 3, 2012
@@ -52,7 +52,7 @@ QEvent::Type ThumbGenEvent::kEventType =
ThumbGenerator::ThumbGenerator(QObject *parent, int w, int h) :
MThread("ThumbGenerator"), m_parent(parent),
- m_isGallery(false), m_width(w), m_height(h)
+ m_isGallery(false), m_width(w), m_height(h), m_cancel(false)
{
}
@@ -89,16 +89,17 @@ void ThumbGenerator::cancel()
{
m_mutex.lock();
m_fileList.clear();
+ m_cancel = true;
m_mutex.unlock();
}
void ThumbGenerator::run()
{
RunProlog();
- while (moreWork())
+ m_cancel = false;
+ while (moreWork() && !m_cancel)
{
-
QString file, dir;
bool isGallery;
@@ -119,7 +120,6 @@ void ThumbGenerator::run()
if (isGallery)
{
-
if (fileInfo.isDir())
isGallery = checkGalleryDir(fileInfo);
else
@@ -128,7 +128,6 @@ void ThumbGenerator::run()
if (!isGallery)
{
-
QString cachePath = QString("%1%2.jpg").arg(getThumbcacheDir(dir))
.arg(file);
QFileInfo cacheInfo(cachePath);
@@ -238,50 +237,39 @@ void ThumbGenerator::loadDir(QImage& image, const QFileInfo& fi)
dir.setFilter(QDir::Files);
QFileInfoList list = dir.entryInfoList();
- QFileInfoList::const_iterator it = list.begin();
- const QFileInfo *f;
- bool found = false;
- while (it != list.end())
+ for (QFileInfoList::const_iterator it = list.begin();
+ it != list.end() && !m_cancel; ++it)
{
- f = &(*it);
+ const QFileInfo *f = &(*it);
QImageReader testread(f->absoluteFilePath());
if (testread.canRead())
{
- found = true;
- break;
+ loadFile(image, *f);
+ return;
}
- ++it;
}
- if (found)
- {
- loadFile(image, *f);
+ // If we are supposed to cancel, don't recurse into subdirs, just quit
+ if (m_cancel)
return;
- }
- else
- {
- // if we didn't find the image yet
- // go into subdirs and keep looking
- dir.setFilter(QDir::Dirs);
- QFileInfoList dirlist = dir.entryInfoList();
- if (dirlist.isEmpty())
- return;
-
- QFileInfoList::const_iterator it = dirlist.begin();
- const QFileInfo *f;
- while (it != dirlist.end() && image.isNull() )
- {
+ // if we didn't find the image yet
+ // go into subdirs and keep looking
+ dir.setFilter(QDir::Dirs);
+ QFileInfoList dirlist = dir.entryInfoList();
+ if (dirlist.isEmpty())
+ return;
- f = &(*it);
- ++it;
+ for (QFileInfoList::const_iterator it = dirlist.begin();
+ it != dirlist.end() && image.isNull() && !m_cancel; ++it)
+ {
+ const QFileInfo *f = &(*it);
- if (f->fileName() == "." || f->fileName() == "..")
- continue;
+ if (f->fileName() == "." || f->fileName() == "..")
+ continue;
- loadDir(image, *f);
- }
+ loadDir(image, *f);
}
}
@@ -357,28 +345,28 @@ QString ThumbGenerator::getThumbcacheDir(const QString& inDir)
QString galleryDir = gCoreContext->GetSetting("GalleryDir");
// For directory "/my/images/january", this function either returns
- // "/my/images/january/.thumbcache" or "~/.mythtv/mythgallery/january/.thumbcache"
+ // "/my/images/january/.thumbcache" or
+ // "~/.mythtv/mythgallery/january/.thumbcache"
QString aPath = inDir + QString("/.thumbcache/");
QDir dir(aPath);
if (gCoreContext->GetNumSetting("GalleryThumbnailLocation") &&
- !dir.exists() &&
- inDir.startsWith(galleryDir))
+ !dir.exists() && inDir.startsWith(galleryDir))
{
dir.mkpath(aPath);
}
if (!gCoreContext->GetNumSetting("GalleryThumbnailLocation") ||
- !dir.exists() ||
- !inDir.startsWith(galleryDir))
+ !dir.exists() || !inDir.startsWith(galleryDir))
{
// Arrive here if storing thumbs in home dir,
// OR failed to create thumb dir in gallery pics location
int prefixLen = galleryDir.length();
QString location = "";
if (prefixLen < inDir.length())
- location = QString("%1/").arg(inDir.right(inDir.length() - prefixLen));
+ location = QString("%1/")
+ .arg(inDir.right(inDir.length() - prefixLen));
aPath = QString("%1/MythGallery/%2").arg(GetConfDir())
- .arg(location);
+ .arg(location);
dir.setPath(aPath);
dir.mkpath(aPath);
}
@@ -78,8 +78,9 @@ class ThumbGenerator : public MThread
bool m_isGallery;
QStringList m_fileList;
QMutex m_mutex;
- int m_width, m_height;
-
+ int m_width;
+ int m_height;
+ bool m_cancel;
};
#endif /* THUMBGENERATOR_H */

0 comments on commit 3b83dbd

Please sign in to comment.