Skip to content

Commit

Permalink
Fix abortion of previous images' loading (fix #1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Aug 7, 2018
1 parent 1530b53 commit 0de9670
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions gui/src/viewer/zoom-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,35 +1143,32 @@ void ZoomWindow::load(const QSharedPointer<Image> &image)
if (isVisible())
{ showThumbnail(); }

// Preload gallery images
// Preload and abort next and previous images
const int preload = m_settings->value("preload", 0).toInt();
if (preload > 0)
QSet<int> preloaded;
const int index = m_images.indexOf(m_image);
for (int i = index - preload - 1; i <= index + preload + 1; ++i)
{
QSet<int> preloaded;
const int index = m_images.indexOf(m_image);
for (int i = index - preload - 1; i <= index + preload + 1; ++i)
{
bool forAbort = i == index - preload - 1 || i == index + preload + 1;
int pos = (i + m_images.count()) % m_images.count();
if (pos < 0 || pos == index || pos > m_images.count() || preloaded.contains(pos))
continue;

QSharedPointer<Image> img = m_images[pos];
bool downloaderExists = m_imageDownloaders.contains(img);
if (downloaderExists && forAbort)
m_imageDownloaders[img]->abort();
if (downloaderExists || forAbort || (!img->savePath().isEmpty() && QFile::exists(img->savePath())))
continue;

preloaded.insert(pos);
log(QStringLiteral("Preloading data for image #%1").arg(pos));
m_images[pos]->loadDetails();

const QString fn = QUuid::createUuid().toString().mid(1, 36) + ".%ext%";
auto dwl = new ImageDownloader(img, fn, m_profile->tempPath(), 1, false, false, this);
m_imageDownloaders.insert(img, dwl);
dwl->save();
}
bool forAbort = i == index - preload - 1 || i == index + preload + 1;
int pos = (i + m_images.count()) % m_images.count();
if (pos < 0 || pos == index || pos > m_images.count() || preloaded.contains(pos))
continue;

QSharedPointer<Image> img = m_images[pos];
bool downloaderExists = m_imageDownloaders.contains(img);
if (downloaderExists && forAbort)
m_imageDownloaders[img]->abort();
if (downloaderExists || forAbort || (!img->savePath().isEmpty() && QFile::exists(img->savePath())))
continue;

preloaded.insert(pos);
log(QStringLiteral("Preloading data for image #%1").arg(pos));
m_images[pos]->loadDetails();

const QString fn = QUuid::createUuid().toString().mid(1, 36) + ".%ext%";
auto dwl = new ImageDownloader(img, fn, m_profile->tempPath(), 1, false, false, this);
m_imageDownloaders.insert(img, dwl);
dwl->save();
}

// Reset buttons
Expand Down

0 comments on commit 0de9670

Please sign in to comment.