diff options
-rw-r--r-- | core/imagedownloader.cpp | 28 | ||||
-rw-r--r-- | core/imagedownloader.h | 4 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDivePhotos.cpp | 25 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDivePhotos.h | 2 |
4 files changed, 52 insertions, 7 deletions
diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp index 1d82c50c5..0c72f3381 100644 --- a/core/imagedownloader.cpp +++ b/core/imagedownloader.cpp @@ -184,6 +184,23 @@ static void addThumbnailToCache(const QImage &thumbnail, const QString &picture_ file.commit(); } +void Thumbnailer::recalculate(QString filename) +{ + auto res = getHashedImage(filename, true); + + // If we couldn't load the image from disk -> leave old thumbnail. + // The case "load from web" is a bit inconsistent: it will call into processItem() later + // and therefore a "broken" image symbol may be shown. + if (res.second || res.first.isNull()) + return; + QImage thumbnail = res.first; + addThumbnailToCache(thumbnail, filename); + + QMutexLocker l(&lock); + emit thumbnailChanged(filename, thumbnail); + workingOn.remove(filename); +} + void Thumbnailer::processItem(QString filename, bool tryDownload) { QImage thumbnail = getThumbnailFromCache(filename); @@ -236,6 +253,17 @@ QImage Thumbnailer::fetchThumbnail(PictureEntry &entry) return dummyImage; } +void Thumbnailer::calculateThumbnails(const QVector<QString> &filenames) +{ + QMutexLocker l(&lock); + for (const QString &filename: filenames) { + if (!workingOn.contains(filename)) { + workingOn.insert(filename, + QtConcurrent::run(&pool, [this, filename]() { recalculate(filename); })); + } + } +} + void Thumbnailer::clearWorkQueue() { QMutexLocker l(&lock); diff --git a/core/imagedownloader.h b/core/imagedownloader.h index 22ef8f5eb..d91dbcaad 100644 --- a/core/imagedownloader.h +++ b/core/imagedownloader.h @@ -34,6 +34,9 @@ public: // via a signal later. QImage fetchThumbnail(PictureEntry &entry); + // Schedule multiple thumbnails for forced recalculation + void calculateThumbnails(const QVector<QString> &filenames); + // If we change dive, clear all unfinished thumbnail creations void clearWorkQueue(); static int maxThumbnailSize(); @@ -46,6 +49,7 @@ signals: void thumbnailChanged(QString filename, QImage thumbnail); private: Thumbnailer(); + void recalculate(QString filename); void processItem(QString filename, bool tryDownload); mutable QMutex lock; diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.cpp b/desktop-widgets/tab-widgets/TabDivePhotos.cpp index 1a5d233e5..c01820777 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.cpp +++ b/desktop-widgets/tab-widgets/TabDivePhotos.cpp @@ -54,27 +54,38 @@ void TabDivePhotos::contextMenuEvent(QContextMenuEvent *event) popup.addSeparator(); popup.addAction(tr("Delete selected images"), this, SLOT(removeSelectedPhotos())); popup.addAction(tr("Delete all images"), this, SLOT(removeAllPhotos())); + popup.addAction(tr("Recalculate selected thumbnails"), this, SLOT(recalculateSelectedThumbnails())); popup.exec(event->globalPos()); event->accept(); } -void TabDivePhotos::removeSelectedPhotos() +QVector<QString> TabDivePhotos::getSelectedFilenames() const { + QVector<QString> selectedPhotos; if (!ui->photosView->selectionModel()->hasSelection()) - return; - QModelIndexList indexes = ui->photosView->selectionModel()->selectedRows(); + return selectedPhotos; + QModelIndexList indexes = ui->photosView->selectionModel()->selectedRows(); if (indexes.count() == 0) indexes = ui->photosView->selectionModel()->selectedIndexes(); - QVector<QString> photosToDelete; - photosToDelete.reserve(indexes.count()); + selectedPhotos.reserve(indexes.count()); for (const auto &photo: indexes) { if (photo.isValid()) { QString fileUrl = photo.data(Qt::DisplayPropertyRole).toString(); if (!fileUrl.isEmpty()) - photosToDelete.push_back(fileUrl); + selectedPhotos.push_back(fileUrl); } } - DivePictureModel::instance()->removePictures(photosToDelete); + return selectedPhotos; +} + +void TabDivePhotos::removeSelectedPhotos() +{ + DivePictureModel::instance()->removePictures(getSelectedFilenames()); +} + +void TabDivePhotos::recalculateSelectedThumbnails() +{ + Thumbnailer::instance()->calculateThumbnails(getSelectedFilenames()); } //TODO: This looks overly wrong. We shouldn't call MainWindow to retrieve the DiveList to add Images. diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.h b/desktop-widgets/tab-widgets/TabDivePhotos.h index e2e7aa05c..a752fef19 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.h +++ b/desktop-widgets/tab-widgets/TabDivePhotos.h @@ -26,11 +26,13 @@ private slots: void addPhotosFromURL(); void removeAllPhotos(); void removeSelectedPhotos(); + void recalculateSelectedThumbnails(); void changeZoomLevel(int delta); private: Ui::TabDivePhotos *ui; DivePictureModel *divePictureModel; + QVector<QString> getSelectedFilenames() const; }; #endif |