1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-01-29 16:49:27 +01:00

TranscodeDialog: update to optionally preserve directory structure

This commit is contained in:
Kyle Hopkins 2025-01-04 11:12:00 -08:00 committed by Jonas Kvinge
parent 24af1be666
commit 8fcee4511d
3 changed files with 54 additions and 5 deletions

View File

@ -233,8 +233,11 @@ void TranscodeDialog::Start() {
// Add jobs to the transcoder
for (int i = 0; i < file_model->rowCount(); ++i) {
const QString input_filepath = file_model->index(i, 0).data(Qt::UserRole).toString();
const QString input_import_dir = ui_->preserve_dir_structure->isChecked() ? file_model->index(i, 2).data(Qt::UserRole).toString() : ""_L1;
if (input_filepath.isEmpty()) continue;
const QString output_filepath = GetOutputFileName(input_filepath, preset);
const QString output_filepath = GetOutputFileName(input_filepath, input_import_dir, preset);
if (output_filepath.isEmpty()) continue;
transcoder_->AddJob(input_filepath, preset, output_filepath);
}
@ -351,7 +354,7 @@ void TranscodeDialog::Import() {
filenames << files.next();
}
SetFilenames(filenames);
SetImportFilenames(filenames, path);
last_import_dir_ = path;
Settings s;
@ -373,6 +376,20 @@ void TranscodeDialog::SetFilenames(const QStringList &filenames) {
}
void TranscodeDialog::SetImportFilenames(const QStringList &filenames, const QString &import_dir) {
for (const QString &filename : filenames) {
QString name = filename.section(u'/', -1, -1);
QString path = filename.section(u'/', 0, -2);
QString output_dir = filename.section(u'/', import_dir.count(u'/'), -2);
QTreeWidgetItem *item = new QTreeWidgetItem(ui_->files, QStringList() << name << path << output_dir);
item->setData(0, Qt::UserRole, filename);
item->setData(2, Qt::UserRole, output_dir);
}
}
void TranscodeDialog::Remove() { qDeleteAll(ui_->files->selectedItems()); }
void TranscodeDialog::LogLine(const QString &message) {
@ -436,7 +453,16 @@ QString TranscodeDialog::TrimPath(const QString &path) {
return path.section(u'/', -1, -1, QString::SectionSkipEmpty);
}
QString TranscodeDialog::GetOutputFileName(const QString &input_filepath, const TranscoderPreset &preset) const {
void TranscodeDialog::CreatePathIfNotExists(const QString &path) {
const QDir dir(path);
if (!dir.exists()) {
dir.mkpath("."_L1);
}
}
QString TranscodeDialog::GetOutputFileName(const QString &input_filepath, const QString &input_import_dir, const TranscoderPreset &preset) const {
QString destination_path = ui_->destination->itemData(ui_->destination->currentIndex()).toString();
QString output_filepath;
@ -447,7 +473,16 @@ QString TranscodeDialog::GetOutputFileName(const QString &input_filepath, const
else {
QString filename = TrimPath(input_filepath);
filename = filename.section(u'.', 0, -2);
output_filepath = destination_path + QLatin1Char('/') + filename + QLatin1Char('.') + preset.extension_;
// If checkbox for preserving import directory structure is checked validate the path exists
if (ui_->preserve_dir_structure->isChecked()) {
QString path_to_validate = destination_path + u'/' + input_import_dir + u'/';
output_filepath = path_to_validate + filename + u'.' + preset.extension_;
CreatePathIfNotExists(path_to_validate);
}
// Otherwise no modifications to the output path
else {
output_filepath = destination_path + u'/' + filename + u'.' + preset.extension_;
}
}
if (output_filepath.isEmpty()) return QString();

View File

@ -49,6 +49,7 @@ class TranscodeDialog : public QDialog {
~TranscodeDialog() override;
void SetFilenames(const QStringList &filenames);
void SetImportFilenames(const QStringList &filenames, const QString &path);
protected:
void showEvent(QShowEvent *e) override;
@ -62,7 +63,8 @@ class TranscodeDialog : public QDialog {
void UpdateStatusText();
void UpdateProgress();
static QString TrimPath(const QString &path);
QString GetOutputFileName(const QString &input, const TranscoderPreset &preset) const;
static void CreatePathIfNotExists(const QString &path);
QString GetOutputFileName(const QString &input, const QString &input_import_dir, const TranscoderPreset &preset) const;
private Q_SLOTS:
void Add();

View File

@ -57,6 +57,11 @@
<string>Directory</string>
</property>
</column>
<column>
<property name="text">
<string>Import Directory</string>
</property>
</column>
</widget>
</item>
<item>
@ -165,6 +170,13 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="preserve_dir_structure">
<property name="text">
<string>Preserve directory structure in output directory (import only)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>