2010-06-24 20:33:38 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-11-02 19:36:21 +01:00
|
|
|
Copyright 2010, David Sansome <davidsansome@gmail.com>
|
|
|
|
Copyright 2014, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
2010-06-24 20:33:38 +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/>.
|
|
|
|
*/
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#ifndef CORE_ORGANISE_H_
|
|
|
|
#define CORE_ORGANISE_H_
|
2010-06-24 20:33:38 +02:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2010-08-30 13:36:40 +02:00
|
|
|
#include <QBasicTimer>
|
2010-06-24 20:33:38 +02:00
|
|
|
#include <QObject>
|
2010-08-29 21:22:21 +02:00
|
|
|
#include <QTemporaryFile>
|
2010-06-24 20:33:38 +02:00
|
|
|
|
|
|
|
#include "organiseformat.h"
|
2010-08-29 21:22:21 +02:00
|
|
|
#include "transcoder/transcoder.h"
|
2010-06-24 20:33:38 +02:00
|
|
|
|
2010-07-19 21:56:29 +02:00
|
|
|
class MusicStorage;
|
2010-06-24 20:33:38 +02:00
|
|
|
class TaskManager;
|
|
|
|
|
|
|
|
class Organise : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-02 19:28:45 +01:00
|
|
|
struct NewSongInfo {
|
2014-02-07 16:34:20 +01:00
|
|
|
NewSongInfo(const Song& song = Song(),
|
|
|
|
const QString& new_filename = QString())
|
|
|
|
: song_(song), new_filename_(new_filename) {}
|
2014-02-02 19:28:45 +01:00
|
|
|
Song song_;
|
|
|
|
QString new_filename_;
|
|
|
|
};
|
|
|
|
typedef QList<NewSongInfo> NewSongInfoList;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
Organise(TaskManager* task_manager, std::shared_ptr<MusicStorage> destination,
|
2014-11-02 21:37:15 +01:00
|
|
|
const OrganiseFormat& format, bool copy, bool overwrite,
|
|
|
|
bool mark_as_listened, const NewSongInfoList& songs,
|
|
|
|
bool eject_after);
|
2010-06-24 20:33:38 +02:00
|
|
|
|
|
|
|
static const int kBatchSize;
|
2010-08-30 13:36:40 +02:00
|
|
|
static const int kTranscodeProgressInterval;
|
2010-06-24 20:33:38 +02:00
|
|
|
|
|
|
|
void Start();
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
signals:
|
2010-08-14 13:51:50 +02:00
|
|
|
void Finished(const QStringList& files_with_errors);
|
2014-11-05 17:35:14 +01:00
|
|
|
void FileCopied(int database_id);
|
2010-08-14 13:51:50 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2010-08-30 13:36:40 +02:00
|
|
|
void timerEvent(QTimerEvent* e);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2010-06-24 20:33:38 +02:00
|
|
|
void ProcessSomeFiles();
|
2014-11-13 22:31:49 +01:00
|
|
|
void FileTranscoded(const QString& input, const QString& output, bool success);
|
2010-08-29 21:22:21 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-08-30 13:36:40 +02:00
|
|
|
void SetSongProgress(float progress, bool transcoded = false);
|
2010-08-28 23:55:30 +02:00
|
|
|
void UpdateProgress();
|
2010-08-29 21:22:21 +02:00
|
|
|
Song::FileType CheckTranscode(Song::FileType original_type) const;
|
2010-06-24 20:33:38 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-08-29 21:22:21 +02:00
|
|
|
struct Task {
|
2014-02-02 19:28:45 +01:00
|
|
|
explicit Task(const NewSongInfo& song_info = NewSongInfo())
|
2014-02-07 16:34:20 +01:00
|
|
|
: song_info_(song_info), transcode_progress_(0.0) {}
|
2010-08-29 21:22:21 +02:00
|
|
|
|
2014-02-02 19:28:45 +01:00
|
|
|
NewSongInfo song_info_;
|
2010-08-30 13:36:40 +02:00
|
|
|
|
|
|
|
float transcode_progress_;
|
2010-08-29 21:22:21 +02:00
|
|
|
QString transcoded_filename_;
|
|
|
|
QString new_extension_;
|
|
|
|
Song::FileType new_filetype_;
|
|
|
|
};
|
|
|
|
|
2010-06-24 20:33:38 +02:00
|
|
|
QThread* thread_;
|
|
|
|
QThread* original_thread_;
|
|
|
|
TaskManager* task_manager_;
|
2010-08-29 21:22:21 +02:00
|
|
|
Transcoder* transcoder_;
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<MusicStorage> destination_;
|
2010-08-29 21:22:21 +02:00
|
|
|
QList<Song::FileType> supported_filetypes_;
|
2010-06-24 20:33:38 +02:00
|
|
|
|
2010-06-24 20:59:09 +02:00
|
|
|
const OrganiseFormat format_;
|
|
|
|
const bool copy_;
|
|
|
|
const bool overwrite_;
|
2014-10-30 03:41:15 +01:00
|
|
|
const bool mark_as_listened_;
|
2010-07-25 11:52:29 +02:00
|
|
|
const bool eject_after_;
|
2010-08-29 21:22:21 +02:00
|
|
|
int task_count_;
|
|
|
|
|
2010-08-30 13:36:40 +02:00
|
|
|
QBasicTimer transcode_progress_timer_;
|
2010-08-29 21:22:21 +02:00
|
|
|
QTemporaryFile transcode_temp_name_;
|
|
|
|
int transcode_suffix_;
|
|
|
|
|
|
|
|
QList<Task> tasks_pending_;
|
|
|
|
QMap<QString, Task> tasks_transcoding_;
|
2010-08-30 13:36:40 +02:00
|
|
|
int tasks_complete_;
|
2010-06-24 20:33:38 +02:00
|
|
|
|
2010-07-24 18:58:14 +02:00
|
|
|
bool started_;
|
|
|
|
|
2010-06-24 20:33:38 +02:00
|
|
|
int task_id_;
|
2010-08-30 13:36:40 +02:00
|
|
|
int current_copy_progress_;
|
2010-08-10 21:42:43 +02:00
|
|
|
|
|
|
|
QStringList files_with_errors_;
|
2010-06-24 20:33:38 +02:00
|
|
|
};
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#endif // CORE_ORGANISE_H_
|