TranscodeDialog: Append number to filename if it already exists
Fixes #1200
This commit is contained in:
parent
315073f9a7
commit
80067b806d
|
@ -232,9 +232,11 @@ void TranscodeDialog::Start() {
|
||||||
|
|
||||||
// Add jobs to the transcoder
|
// Add jobs to the transcoder
|
||||||
for (int i = 0; i < file_model->rowCount(); ++i) {
|
for (int i = 0; i < file_model->rowCount(); ++i) {
|
||||||
QString filename = file_model->index(i, 0).data(Qt::UserRole).toString();
|
const QString input_filepath = file_model->index(i, 0).data(Qt::UserRole).toString();
|
||||||
QString outfilename = GetOutputFileName(filename, preset);
|
if (input_filepath.isEmpty()) continue;
|
||||||
transcoder_->AddJob(filename, preset, outfilename);
|
const QString output_filepath = GetOutputFileName(input_filepath, preset);
|
||||||
|
if (output_filepath.isEmpty()) continue;
|
||||||
|
transcoder_->AddJob(input_filepath, preset, output_filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the progressbar
|
// Set up the progressbar
|
||||||
|
@ -439,17 +441,31 @@ QString TranscodeDialog::TrimPath(const QString &path) {
|
||||||
return path.section('/', -1, -1, QString::SectionSkipEmpty);
|
return path.section('/', -1, -1, QString::SectionSkipEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TranscodeDialog::GetOutputFileName(const QString &input, const TranscoderPreset &preset) const {
|
QString TranscodeDialog::GetOutputFileName(const QString &input_filepath, const TranscoderPreset &preset) const {
|
||||||
|
|
||||||
QString path = ui_->destination->itemData(ui_->destination->currentIndex()).toString();
|
QString destination_path = ui_->destination->itemData(ui_->destination->currentIndex()).toString();
|
||||||
if (path.isEmpty()) {
|
QString output_filepath;
|
||||||
|
if (destination_path.isEmpty()) {
|
||||||
// Keep the original path.
|
// Keep the original path.
|
||||||
return input.section('.', 0, -2) + '.' + preset.extension_;
|
output_filepath = input_filepath.section('.', 0, -2) + '.' + preset.extension_;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QString file_name = TrimPath(input);
|
QString filename = TrimPath(input_filepath);
|
||||||
file_name = file_name.section('.', 0, -2);
|
filename = filename.section('.', 0, -2);
|
||||||
return path + '/' + file_name + '.' + preset.extension_;
|
output_filepath = destination_path + '/' + filename + '.' + preset.extension_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (output_filepath.isEmpty()) return QString();
|
||||||
|
|
||||||
|
if (QFileInfo::exists(output_filepath)) {
|
||||||
|
QFileInfo fileinfo(output_filepath);
|
||||||
|
const QString original_filename = fileinfo.completeBaseName();
|
||||||
|
for (int i = 1; fileinfo.exists(); ++i) {
|
||||||
|
fileinfo.setFile(QString("%1/%2-%3.%4").arg(fileinfo.path(), original_filename).arg(i).arg(fileinfo.suffix()));
|
||||||
|
}
|
||||||
|
output_filepath = fileinfo.filePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return output_filepath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue