2013-05-06 21:22:05 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-12-26 13:34:53 +01:00
|
|
|
Copyright 2013, Andreas <asfa194@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
2013-05-06 21:22:05 +02:00
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "albumcoverexporter.h"
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QThreadPool>
|
|
|
|
|
2014-12-26 14:57:02 +01:00
|
|
|
#include "coverexportrunnable.h"
|
|
|
|
#include "core/song.h"
|
|
|
|
|
2013-05-06 21:22:05 +02:00
|
|
|
const int AlbumCoverExporter::kMaxConcurrentRequests = 3;
|
|
|
|
|
|
|
|
AlbumCoverExporter::AlbumCoverExporter(QObject* parent)
|
|
|
|
: QObject(parent),
|
|
|
|
thread_pool_(new QThreadPool(this)),
|
|
|
|
exported_(0),
|
|
|
|
skipped_(0),
|
2014-02-07 16:34:20 +01:00
|
|
|
all_(0) {
|
2013-05-06 21:22:05 +02:00
|
|
|
thread_pool_->setMaxThreadCount(kMaxConcurrentRequests);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void AlbumCoverExporter::SetDialogResult(
|
|
|
|
const AlbumCoverExport::DialogResult& dialog_result) {
|
2013-05-06 21:22:05 +02:00
|
|
|
dialog_result_ = dialog_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::AddExportRequest(Song song) {
|
|
|
|
requests_.append(new CoverExportRunnable(dialog_result_, song));
|
|
|
|
all_ = requests_.count();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void AlbumCoverExporter::Cancel() { requests_.clear(); }
|
2013-05-06 21:22:05 +02:00
|
|
|
|
|
|
|
void AlbumCoverExporter::StartExporting() {
|
|
|
|
exported_ = 0;
|
|
|
|
skipped_ = 0;
|
|
|
|
AddJobsToPool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::AddJobsToPool() {
|
2014-02-07 16:34:20 +01:00
|
|
|
while (!requests_.isEmpty() &&
|
|
|
|
thread_pool_->activeThreadCount() < thread_pool_->maxThreadCount()) {
|
2013-05-06 21:22:05 +02:00
|
|
|
CoverExportRunnable* runnable = requests_.dequeue();
|
|
|
|
|
|
|
|
connect(runnable, SIGNAL(CoverExported()), SLOT(CoverExported()));
|
|
|
|
connect(runnable, SIGNAL(CoverSkipped()), SLOT(CoverSkipped()));
|
|
|
|
|
|
|
|
thread_pool_->start(runnable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::CoverExported() {
|
|
|
|
exported_++;
|
|
|
|
emit AlbumCoversExportUpdate(exported_, skipped_, all_);
|
|
|
|
AddJobsToPool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlbumCoverExporter::CoverSkipped() {
|
|
|
|
skipped_++;
|
|
|
|
emit AlbumCoversExportUpdate(exported_, skipped_, all_);
|
|
|
|
AddJobsToPool();
|
|
|
|
}
|