Make sure process files isn't again called after finishing
This commit is contained in:
@@ -27,6 +27,8 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QList>
|
||||||
|
#include <QVector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
@@ -58,6 +60,7 @@ Organize::Organize(TaskManager *task_manager, std::shared_ptr<MusicStorage> dest
|
|||||||
#ifdef HAVE_GSTREAMER
|
#ifdef HAVE_GSTREAMER
|
||||||
transcoder_(new Transcoder(this)),
|
transcoder_(new Transcoder(this)),
|
||||||
#endif
|
#endif
|
||||||
|
process_files_timer_(new QTimer(this)),
|
||||||
destination_(destination),
|
destination_(destination),
|
||||||
format_(format),
|
format_(format),
|
||||||
copy_(copy),
|
copy_(copy),
|
||||||
@@ -70,10 +73,15 @@ Organize::Organize(TaskManager *task_manager, std::shared_ptr<MusicStorage> dest
|
|||||||
tasks_complete_(0),
|
tasks_complete_(0),
|
||||||
started_(false),
|
started_(false),
|
||||||
task_id_(0),
|
task_id_(0),
|
||||||
current_copy_progress_(0){
|
current_copy_progress_(0),
|
||||||
|
finished_(false) {
|
||||||
|
|
||||||
original_thread_ = thread();
|
original_thread_ = thread();
|
||||||
|
|
||||||
|
process_files_timer_->setSingleShot(true);
|
||||||
|
process_files_timer_->setInterval(100);
|
||||||
|
QObject::connect(process_files_timer_, &QTimer::timeout, this, &Organize::ProcessSomeFiles);
|
||||||
|
|
||||||
for (const NewSongInfo &song_info : songs_info) {
|
for (const NewSongInfo &song_info : songs_info) {
|
||||||
tasks_pending_ << Task(song_info);
|
tasks_pending_ << Task(song_info);
|
||||||
}
|
}
|
||||||
@@ -108,10 +116,14 @@ void Organize::Start() {
|
|||||||
|
|
||||||
void Organize::ProcessSomeFiles() {
|
void Organize::ProcessSomeFiles() {
|
||||||
|
|
||||||
|
if (finished_) return;
|
||||||
|
|
||||||
if (!started_) {
|
if (!started_) {
|
||||||
if (!destination_->StartCopy(&supported_filetypes_)) {
|
if (!destination_->StartCopy(&supported_filetypes_)) {
|
||||||
// Failed to start - mark everything as failed :(
|
// Failed to start - mark everything as failed :(
|
||||||
for (const Task &task : tasks_pending_) files_with_errors_ << task.song_info_.song_.url().toLocalFile();
|
for (const Task &task : tasks_pending_) {
|
||||||
|
files_with_errors_ << task.song_info_.song_.url().toLocalFile();
|
||||||
|
}
|
||||||
tasks_pending_.clear();
|
tasks_pending_.clear();
|
||||||
}
|
}
|
||||||
started_ = true;
|
started_ = true;
|
||||||
@@ -143,6 +155,7 @@ void Organize::ProcessSomeFiles() {
|
|||||||
|
|
||||||
// Stop this thread
|
// Stop this thread
|
||||||
thread_->quit();
|
thread_->quit();
|
||||||
|
finished_ = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +270,10 @@ void Organize::ProcessSomeFiles() {
|
|||||||
}
|
}
|
||||||
SetSongProgress(0);
|
SetSongProgress(0);
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &Organize::ProcessSomeFiles);
|
if (!process_files_timer_->isActive()) {
|
||||||
|
process_files_timer_->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +321,8 @@ void Organize::UpdateProgress() {
|
|||||||
#ifdef HAVE_GSTREAMER
|
#ifdef HAVE_GSTREAMER
|
||||||
// Update transcoding progress
|
// Update transcoding progress
|
||||||
QMap<QString, float> transcode_progress = transcoder_->GetProgress();
|
QMap<QString, float> transcode_progress = transcoder_->GetProgress();
|
||||||
for (const QString &filename : transcode_progress.keys()) {
|
QStringList filenames = transcode_progress.keys();
|
||||||
|
for (const QString &filename : filenames) {
|
||||||
if (!tasks_transcoding_.contains(filename)) continue;
|
if (!tasks_transcoding_.contains(filename)) continue;
|
||||||
tasks_transcoding_[filename].transcode_progress_ = transcode_progress[filename];
|
tasks_transcoding_[filename].transcode_progress_ = transcode_progress[filename];
|
||||||
}
|
}
|
||||||
@@ -319,7 +336,8 @@ void Organize::UpdateProgress() {
|
|||||||
progress += qBound(0, static_cast<int>(task.transcode_progress_ * 50), 50);
|
progress += qBound(0, static_cast<int>(task.transcode_progress_ * 50), 50);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_GSTREAMER
|
#ifdef HAVE_GSTREAMER
|
||||||
for (const Task &task : tasks_transcoding_.values()) {
|
QList<Task> tasks_transcoding = tasks_transcoding_.values();
|
||||||
|
for (const Task &task : tasks_transcoding) {
|
||||||
progress += qBound(0, static_cast<int>(task.transcode_progress_ * 50), 50);
|
progress += qBound(0, static_cast<int>(task.transcode_progress_ * 50), 50);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -345,7 +363,10 @@ void Organize::FileTranscoded(const QString &input, const QString &output, bool
|
|||||||
else {
|
else {
|
||||||
tasks_pending_ << task;
|
tasks_pending_ << task;
|
||||||
}
|
}
|
||||||
QTimer::singleShot(0, this, &Organize::ProcessSomeFiles);
|
|
||||||
|
if (!process_files_timer_->isActive()) {
|
||||||
|
process_files_timer_->start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QVector>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
#include "organizeformat.h"
|
#include "organizeformat.h"
|
||||||
|
|
||||||
class QThread;
|
class QThread;
|
||||||
|
class QTimer;
|
||||||
class QTimerEvent;
|
class QTimerEvent;
|
||||||
|
|
||||||
class MusicStorage;
|
class MusicStorage;
|
||||||
@@ -108,6 +110,7 @@ class Organize : public QObject {
|
|||||||
#ifdef HAVE_GSTREAMER
|
#ifdef HAVE_GSTREAMER
|
||||||
Transcoder *transcoder_;
|
Transcoder *transcoder_;
|
||||||
#endif
|
#endif
|
||||||
|
QTimer *process_files_timer_;
|
||||||
std::shared_ptr<MusicStorage> destination_;
|
std::shared_ptr<MusicStorage> destination_;
|
||||||
QList<Song::FileType> supported_filetypes_;
|
QList<Song::FileType> supported_filetypes_;
|
||||||
|
|
||||||
@@ -121,7 +124,7 @@ class Organize : public QObject {
|
|||||||
const QString playlist_;
|
const QString playlist_;
|
||||||
|
|
||||||
QBasicTimer transcode_progress_timer_;
|
QBasicTimer transcode_progress_timer_;
|
||||||
QList<Task> tasks_pending_;
|
QVector<Task> tasks_pending_;
|
||||||
QMap<QString, Task> tasks_transcoding_;
|
QMap<QString, Task> tasks_transcoding_;
|
||||||
int tasks_complete_;
|
int tasks_complete_;
|
||||||
|
|
||||||
@@ -129,6 +132,7 @@ class Organize : public QObject {
|
|||||||
|
|
||||||
int task_id_;
|
int task_id_;
|
||||||
int current_copy_progress_;
|
int current_copy_progress_;
|
||||||
|
bool finished_;
|
||||||
|
|
||||||
QStringList files_with_errors_;
|
QStringList files_with_errors_;
|
||||||
QStringList log_;
|
QStringList log_;
|
||||||
|
|||||||
Reference in New Issue
Block a user