2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QThreadPool>
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "core/song.h"
|
2020-02-09 02:29:35 +01:00
|
|
|
#include "albumcoverexport.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "albumcoverexporter.h"
|
|
|
|
#include "coverexportrunnable.h"
|
|
|
|
|
|
|
|
const int AlbumCoverExporter::kMaxConcurrentRequests = 3;
|
|
|
|
|
|
|
|
AlbumCoverExporter::AlbumCoverExporter(QObject *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
thread_pool_(new QThreadPool(this)),
|
|
|
|
exported_(0),
|
|
|
|
skipped_(0),
|
|
|
|
all_(0) {
|
|
|
|
thread_pool_->setMaxThreadCount(kMaxConcurrentRequests);
|
|
|
|
}
|
|
|
|
|
2021-06-12 20:53:23 +02:00
|
|
|
void AlbumCoverExporter::SetDialogResult(const AlbumCoverExport::DialogResult &dialog_result) {
|
2018-02-27 18:06:05 +01:00
|
|
|
dialog_result_ = dialog_result;
|
|
|
|
}
|
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
void AlbumCoverExporter::AddExportRequest(const Song &song) {
|
2018-02-27 18:06:05 +01:00
|
|
|
requests_.append(new CoverExportRunnable(dialog_result_, song));
|
|
|
|
all_ = requests_.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::Cancel() { requests_.clear(); }
|
|
|
|
|
|
|
|
void AlbumCoverExporter::StartExporting() {
|
|
|
|
exported_ = 0;
|
|
|
|
skipped_ = 0;
|
|
|
|
AddJobsToPool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::AddJobsToPool() {
|
|
|
|
|
|
|
|
while (!requests_.isEmpty() && thread_pool_->activeThreadCount() < thread_pool_->maxThreadCount()) {
|
|
|
|
CoverExportRunnable *runnable = requests_.dequeue();
|
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
QObject::connect(runnable, &CoverExportRunnable::CoverExported, this, &AlbumCoverExporter::CoverExported);
|
|
|
|
QObject::connect(runnable, &CoverExportRunnable::CoverSkipped, this, &AlbumCoverExporter::CoverSkipped);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
thread_pool_->start(runnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::CoverExported() {
|
|
|
|
exported_++;
|
|
|
|
emit AlbumCoversExportUpdate(exported_, skipped_, all_);
|
|
|
|
AddJobsToPool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::CoverSkipped() {
|
|
|
|
skipped_++;
|
|
|
|
emit AlbumCoversExportUpdate(exported_, skipped_, all_);
|
|
|
|
AddJobsToPool();
|
|
|
|
}
|