strawberry-audio-player-win.../src/organize/organize.h

143 lines
3.8 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* 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
*/
#ifndef ORGANISE_H
#define ORGANISE_H
#include "config.h"
#include <memory>
#include <optional>
2018-02-27 18:06:05 +01:00
#include <QObject>
#include <QBasicTimer>
#include <QFileInfo>
2020-02-09 02:29:35 +01:00
#include <QSet>
#include <QList>
#include <QVector>
#include <QMap>
#include <QString>
#include <QStringList>
2018-02-27 18:06:05 +01:00
#include "core/song.h"
#include "organizeformat.h"
2020-02-09 02:29:35 +01:00
class QThread;
class QTimer;
class QTimerEvent;
2018-02-27 18:06:05 +01:00
class MusicStorage;
class TaskManager;
2019-01-06 16:48:23 +01:00
#ifdef HAVE_GSTREAMER
class Transcoder;
2019-01-06 16:48:23 +01:00
#endif
2018-02-27 18:06:05 +01:00
class Organize : public QObject {
2018-02-27 18:06:05 +01:00
Q_OBJECT
public:
struct NewSongInfo {
explicit NewSongInfo() : unique_filename_(false) {}
explicit NewSongInfo(const Song &song, const QString &new_filename, const bool unique_filename) : song_(song), new_filename_(new_filename), unique_filename_(unique_filename) {}
2018-02-27 18:06:05 +01:00
Song song_;
QString new_filename_;
bool unique_filename_;
2018-02-27 18:06:05 +01:00
};
2022-10-13 22:39:31 +02:00
using NewSongInfoList = QList<NewSongInfo>;
2018-02-27 18:06:05 +01:00
explicit Organize(TaskManager *task_manager, std::shared_ptr<MusicStorage> destination, const OrganizeFormat &format, const bool copy, const bool overwrite, const bool albumcover, const NewSongInfoList &songs, const bool eject_after, const QString &playlist = QString(), QObject *parent = nullptr);
~Organize() override;
2018-02-27 18:06:05 +01:00
static const int kBatchSize;
2019-01-06 16:48:23 +01:00
#ifdef HAVE_GSTREAMER
2018-02-27 18:06:05 +01:00
static const int kTranscodeProgressInterval;
2019-01-06 16:48:23 +01:00
#endif
2018-02-27 18:06:05 +01:00
void Start();
2019-01-24 19:20:10 +01:00
signals:
2021-01-26 16:48:04 +01:00
void Finished(QStringList files_with_errors, QStringList);
2018-02-27 18:06:05 +01:00
void FileCopied(int database_id);
void SongPathChanged(Song song, QFileInfo new_file, std::optional<int> new_collection_directory_id);
2018-02-27 18:06:05 +01:00
protected:
2020-06-15 21:55:05 +02:00
void timerEvent(QTimerEvent *e) override;
2018-02-27 18:06:05 +01:00
private slots:
void ProcessSomeFiles();
void FileTranscoded(const QString &input, const QString &output, bool success);
2021-06-20 19:04:08 +02:00
void LogLine(const QString &message);
2018-02-27 18:06:05 +01:00
private:
void SetSongProgress(float progress, bool transcoded = false);
void UpdateProgress();
2019-01-06 16:48:23 +01:00
#ifdef HAVE_GSTREAMER
2018-02-27 18:06:05 +01:00
Song::FileType CheckTranscode(Song::FileType original_type) const;
2019-01-06 16:48:23 +01:00
#endif
2018-02-27 18:06:05 +01:00
private:
struct Task {
2021-07-11 09:49:38 +02:00
explicit Task(const NewSongInfo &song_info = NewSongInfo())
2022-03-22 21:09:05 +01:00
: song_info_(song_info),
transcode_progress_(0.0) {}
2018-02-27 18:06:05 +01:00
NewSongInfo song_info_;
float transcode_progress_;
QString transcoded_filename_;
QString new_extension_;
Song::FileType new_filetype_;
};
QThread *thread_;
QThread *original_thread_;
TaskManager *task_manager_;
2019-01-06 16:48:23 +01:00
#ifdef HAVE_GSTREAMER
2018-02-27 18:06:05 +01:00
Transcoder *transcoder_;
2019-01-06 16:48:23 +01:00
#endif
QTimer *process_files_timer_;
2018-02-27 18:06:05 +01:00
std::shared_ptr<MusicStorage> destination_;
QList<Song::FileType> supported_filetypes_;
const OrganizeFormat format_;
2018-02-27 18:06:05 +01:00
const bool copy_;
const bool overwrite_;
const bool albumcover_;
2018-02-27 18:06:05 +01:00
const bool eject_after_;
2021-10-30 02:21:29 +02:00
quint64 task_count_;
const QString playlist_;
2018-02-27 18:06:05 +01:00
QBasicTimer transcode_progress_timer_;
QVector<Task> tasks_pending_;
2018-02-27 18:06:05 +01:00
QMap<QString, Task> tasks_transcoding_;
int tasks_complete_;
bool started_;
int task_id_;
int current_copy_progress_;
bool finished_;
2018-02-27 18:06:05 +01:00
QStringList files_with_errors_;
2019-01-24 19:20:10 +01:00
QStringList log_;
2018-02-27 18:06:05 +01:00
};
#endif // ORGANISE_H