From 6e730881746fbf91addc4529d25584c7ad46d27c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 13 Aug 2022 15:06:04 +0200 Subject: [PATCH] GUI: mux: optionally add one tab per dropped directory & add directory's files in it Implements #3371. --- NEWS.md | 4 + .../forms/main_window/preferences_dialog.ui | 43 +++-- .../forms/merge/adding_directories_dialog.ui | 173 ++++++++++++++++++ .../main_window/preferences_dialog.cpp | 26 +++ .../main_window/preferences_dialog.h | 1 + .../merge/adding_directories_dialog.cpp | 67 +++++++ .../merge/adding_directories_dialog.h | 33 ++++ .../merge/file_identification_pack.h | 2 +- src/mkvtoolnix-gui/merge/tool.cpp | 131 ++++++++++++- src/mkvtoolnix-gui/merge/tool.h | 3 + src/mkvtoolnix-gui/mkvtoolnix-gui.pro | 1 + src/mkvtoolnix-gui/util/file.cpp | 37 ---- src/mkvtoolnix-gui/util/file.h | 2 - src/mkvtoolnix-gui/util/settings.cpp | 9 + src/mkvtoolnix-gui/util/settings.h | 10 + src/mkvtoolnix-gui/util/settings_names.h | 1 + 16 files changed, 487 insertions(+), 56 deletions(-) create mode 100644 src/mkvtoolnix-gui/forms/merge/adding_directories_dialog.ui create mode 100644 src/mkvtoolnix-gui/merge/adding_directories_dialog.cpp create mode 100644 src/mkvtoolnix-gui/merge/adding_directories_dialog.h diff --git a/NEWS.md b/NEWS.md index c3226fa7c..bec6de9a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,10 @@ only want to relocate the preferences INI file, you can store the desired file name for the INI file in `MKVTOOLNIX_GUI_CONFIG_FILE`. Implements #3382. +* MKVToolNix GUI: when adding directories via drag & drop/copy & paste the GUI + will now offer the user the option to create one multiplex settings tab per + directory & adding all files from that directory to the corresponding, newly + created tab. Implements #3371. ## Bug fixes diff --git a/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui b/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui index a9cb9ef06..fd9f8cc0f 100644 --- a/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui +++ b/src/mkvtoolnix-gui/forms/main_window/preferences_dialog.ui @@ -727,8 +727,18 @@ - - + + + + When adding files via &drag && drop/copy && paste: + + + cbMDragAndDropFilesPolicy + + + + + 0 @@ -747,18 +757,28 @@ - - - - When adding files via &drag && drop/copy && paste: - - - cbMDragAndDropFilesPolicy + + + + + 0 + 0 + - - + + + + When adding d&irectories via drag && drop/copy && paste: + + + cbMDragAndDropDirectoriesPolicy + + + + + 0 @@ -2632,6 +2652,7 @@ pbMBrowseMediaInfoExe cbMAddingAppendingFilesPolicy cbMDragAndDropFilesPolicy + cbMDragAndDropDirectoriesPolicy cbMAlwaysCreateSettingsForVideoFiles cbMSortFilesTracksByTypeWhenAdding cbMReconstructSequencesWhenAdding diff --git a/src/mkvtoolnix-gui/forms/merge/adding_directories_dialog.ui b/src/mkvtoolnix-gui/forms/merge/adding_directories_dialog.ui new file mode 100644 index 000000000..b55b3e076 --- /dev/null +++ b/src/mkvtoolnix-gui/forms/merge/adding_directories_dialog.ui @@ -0,0 +1,173 @@ + + + mtx::gui::Merge::AddingDirectoriesDialog + + + + 0 + 0 + 691 + 232 + + + + Adding directories via drag & drop or copy & paste + + + + + + + 600 + 0 + + + + Adding directories via drag & drop or copy & paste + + + true + + + + + + + Qt::Horizontal + + + + + + + You've dragged & dropped or copied & pasted at least one directory. There are several ways to handle them: + + + true + + + + + + + text + + + Qt::RichText + + + true + + + + + + + &Handle all files from all directories as a single list of files + + + + + + + &Create a new multiplex settings tab for each directory + + + + + + + Qt::Horizontal + + + + + + + Alwa&ys use the action selected above and don't ask again + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + rbFlat + rbAddEachDirectoryToNew + cbAlwaysUseThisDecision + + + + + buttonBox + accepted() + mtx::gui::Merge::AddingDirectoriesDialog + accept() + + + 521 + 310 + + + 157 + 274 + + + + + buttonBox + rejected() + mtx::gui::Merge::AddingDirectoriesDialog + reject() + + + 588 + 316 + + + 286 + 274 + + + + + diff --git a/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp b/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp index f98063cd8..82378ee9c 100644 --- a/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp +++ b/src/mkvtoolnix-gui/main_window/preferences_dialog.cpp @@ -19,6 +19,7 @@ #include "mkvtoolnix-gui/main_window/preferences_dialog.h" #include "mkvtoolnix-gui/main_window/prefs_language_shortcut_dialog.h" #include "mkvtoolnix-gui/main_window/prefs_run_program_widget.h" +#include "mkvtoolnix-gui/merge/adding_directories_dialog.h" #include "mkvtoolnix-gui/merge/additional_command_line_options_dialog.h" #include "mkvtoolnix-gui/merge/source_file.h" #include "mkvtoolnix-gui/util/container.h" @@ -123,6 +124,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, setupEnableMuxingTracksByType(); setupEnableMuxingTracksByLanguage(); setupMergeAddingAppendingFilesPolicy(); + setupMergeAddingAppendingDirectoriesPolicy(); setupMergeWarnMissingAudioTrack(); setupMergePredefinedItems(); setupTrackPropertiesLayout(); @@ -429,6 +431,16 @@ PreferencesDialog::setupToolTips() { .arg(QY("The default is to always add all the files to the current multiplex settings.")) .arg(QY("The GUI can also ask the user what to do each time, e.g. appending them instead of adding them, or creating new multiplex settings and adding them to those."))); + QString fullText; + + for (auto const &text : Merge::AddingDirectoriesDialog::optionDescriptions()) + fullText += Q("
  • %1
  • ").arg(text.toHtmlEscaped()); + + Util::setToolTip(ui->cbMDragAndDropDirectoriesPolicy, + Q("

    %1

      %2
    ") + .arg(QY("When the user drags & drops directories from an external application onto the multiplex tool the GUI can take different actions.")) + .arg(fullText)); + Util::setToolTip(ui->cbMWarnMissingAudioTrack, QY("The GUI can ask for confirmation when you're about to create a file without audio tracks in it.")); Util::setToolTip(ui->cbMDeriveAudioTrackLanguageFromFileName, @@ -778,6 +790,19 @@ PreferencesDialog::setupMergeAddingAppendingFilesPolicy() { ui->cbMAlwaysCreateSettingsForVideoFiles->setChecked(m_cfg.m_mergeAlwaysCreateNewSettingsForVideoFiles); } +void +PreferencesDialog::setupMergeAddingAppendingDirectoriesPolicy() { + ui->cbMDragAndDropDirectoriesPolicy->addItem(QY("Always ask the user"), static_cast(Util::Settings::MergeAddingDirectoriesPolicy::Ask)); + ui->cbMDragAndDropDirectoriesPolicy->addItem(QY("Handle all files from all directories as a single list of files"), static_cast(Util::Settings::MergeAddingDirectoriesPolicy::Flat)); + ui->cbMDragAndDropDirectoriesPolicy->addItem(QY("Create a new multiplex settings tab for each directory"), static_cast(Util::Settings::MergeAddingDirectoriesPolicy::AddEachDirectoryToNew)); + + Util::setComboBoxIndexIf(ui->cbMDragAndDropDirectoriesPolicy, [this](QString const &, QVariant const &data) { + return data.isValid() && (static_cast(data.toInt()) == m_cfg.m_mergeDragAndDropDirectoriesPolicy); + }); + + Util::fixComboBoxViewWidth(*ui->cbMDragAndDropDirectoriesPolicy); +} + void PreferencesDialog::setupMergeWarnMissingAudioTrack() { ui->cbMWarnMissingAudioTrack->addItem(QY("Never"), static_cast(Util::Settings::MergeMissingAudioTrackPolicy::Never)); @@ -1094,6 +1119,7 @@ PreferencesDialog::save() { m_cfg.m_mergeEnableDialogNormGainRemoval = ui->cbMEnableDialogNormGainRemoval->isChecked(); m_cfg.m_mergeAddingAppendingFilesPolicy = static_cast(ui->cbMAddingAppendingFilesPolicy->currentData().toInt()); m_cfg.m_mergeDragAndDropFilesPolicy = static_cast(ui->cbMDragAndDropFilesPolicy->currentData().toInt()); + m_cfg.m_mergeDragAndDropDirectoriesPolicy = static_cast(ui->cbMDragAndDropDirectoriesPolicy->currentData().toInt()); m_cfg.m_mergeAlwaysCreateNewSettingsForVideoFiles = ui->cbMAlwaysCreateSettingsForVideoFiles->isChecked(); m_cfg.m_mergeSortFilesTracksByTypeWhenAdding = ui->cbMSortFilesTracksByTypeWhenAdding->isChecked(); m_cfg.m_mergeReconstructSequencesWhenAdding = ui->cbMReconstructSequencesWhenAdding->isChecked(); diff --git a/src/mkvtoolnix-gui/main_window/preferences_dialog.h b/src/mkvtoolnix-gui/main_window/preferences_dialog.h index b49f8e594..923ce9e5a 100644 --- a/src/mkvtoolnix-gui/main_window/preferences_dialog.h +++ b/src/mkvtoolnix-gui/main_window/preferences_dialog.h @@ -118,6 +118,7 @@ protected: void setupEnableMuxingTracksByType(); void setupEnableMuxingTracksByLanguage(); void setupMergeAddingAppendingFilesPolicy(); + void setupMergeAddingAppendingDirectoriesPolicy(); void setupMergeWarnMissingAudioTrack(); void setupMergePredefinedItems(); void setupHeaderEditorDroppedFilesPolicy(); diff --git a/src/mkvtoolnix-gui/merge/adding_directories_dialog.cpp b/src/mkvtoolnix-gui/merge/adding_directories_dialog.cpp new file mode 100644 index 000000000..2f14dd339 --- /dev/null +++ b/src/mkvtoolnix-gui/merge/adding_directories_dialog.cpp @@ -0,0 +1,67 @@ +#include "common/common_pch.h" + +#include +#include + +#include "common/qt.h" +#include "mkvtoolnix-gui/forms/merge/adding_directories_dialog.h" +#include "mkvtoolnix-gui/merge/adding_directories_dialog.h" +#include "mkvtoolnix-gui/merge/tab.h" + +namespace mtx::gui::Merge { + +using namespace mtx::gui; + +AddingDirectoriesDialog::AddingDirectoriesDialog(QWidget *parent, + Util::Settings::MergeAddingDirectoriesPolicy decision) + : QDialog{parent} + , ui{new Ui::AddingDirectoriesDialog} +{ + // Setup UI controls. + ui->setupUi(this); + + if (decision == Util::Settings::MergeAddingDirectoriesPolicy::AddEachDirectoryToNew) + ui->rbAddEachDirectoryToNew->setChecked(true); + else + ui->rbFlat->setChecked(true); + + QString fullText; + + for (auto const &text : optionDescriptions()) + fullText += Q("
  • %1
  • ").arg(text.toHtmlEscaped()); + + ui->lOptions->setText(Q("
      %1
    ").arg(fullText)); + + adjustSize(); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AddingDirectoriesDialog::accept); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &AddingDirectoriesDialog::reject); +} + +AddingDirectoriesDialog::~AddingDirectoriesDialog() { +} + +QStringList +AddingDirectoriesDialog::optionDescriptions() { + QStringList texts; + + texts << QY("The program can collect all files from all directories in a single list. What happens with that list is determined by how dragging & dropping/copying & pasting files is configured."); + texts << QY("For each directory a new multiplex settings tab can be created. All files from that directory will be added to this new tab. The configuration about dragging & dropping/copying & pasting files is ignored in this case."); + + return texts; +} + +Util::Settings::MergeAddingDirectoriesPolicy +AddingDirectoriesDialog::decision() + const { + return ui->rbFlat->isChecked() ? Util::Settings::MergeAddingDirectoriesPolicy::Flat + : Util::Settings::MergeAddingDirectoriesPolicy::AddEachDirectoryToNew; +} + +bool +AddingDirectoriesDialog::alwaysUseThisDecision() + const { + return ui->cbAlwaysUseThisDecision->isEnabled() && ui->cbAlwaysUseThisDecision->isChecked(); +} + +} diff --git a/src/mkvtoolnix-gui/merge/adding_directories_dialog.h b/src/mkvtoolnix-gui/merge/adding_directories_dialog.h new file mode 100644 index 000000000..4d90f7adb --- /dev/null +++ b/src/mkvtoolnix-gui/merge/adding_directories_dialog.h @@ -0,0 +1,33 @@ +#pragma once + +#include "common/common_pch.h" + +#include + +#include "mkvtoolnix-gui/util/settings.h" + +namespace mtx::gui::Merge { + +class Tab; + +namespace Ui { +class AddingDirectoriesDialog; +} + +class AddingDirectoriesDialog : public QDialog { + Q_OBJECT +protected: + std::unique_ptr ui; + +public: + explicit AddingDirectoriesDialog(QWidget *parent, Util::Settings::MergeAddingDirectoriesPolicy decision); + ~AddingDirectoriesDialog(); + + Util::Settings::MergeAddingDirectoriesPolicy decision() const; + bool alwaysUseThisDecision() const; + +public: + static QStringList optionDescriptions(); +}; + +} diff --git a/src/mkvtoolnix-gui/merge/file_identification_pack.h b/src/mkvtoolnix-gui/merge/file_identification_pack.h index f37160c7a..74fb949f2 100644 --- a/src/mkvtoolnix-gui/merge/file_identification_pack.h +++ b/src/mkvtoolnix-gui/merge/file_identification_pack.h @@ -12,7 +12,7 @@ using SourceFilePtr = std::shared_ptr; struct IdentificationPack { enum class FileType { Regular, Chapters, Tags, SegmentInfo }; - enum class AddMode { UserChoice, Add, Append }; + enum class AddMode { UserChoice, Add, Append, AddDontAsk }; struct IdentifiedFile { FileType m_type{FileType::Regular}; diff --git a/src/mkvtoolnix-gui/merge/tool.cpp b/src/mkvtoolnix-gui/merge/tool.cpp index 3376a351e..81264eeb5 100644 --- a/src/mkvtoolnix-gui/merge/tool.cpp +++ b/src/mkvtoolnix-gui/merge/tool.cpp @@ -1,6 +1,8 @@ #include "common/common_pch.h" #include +#include +#include #include #include #include @@ -9,6 +11,7 @@ #include #include "common/bluray/util.h" +#include "common/fs_sys_helpers.h" #include "common/path.h" #include "common/qt.h" #include "mkvtoolnix-gui/app.h" @@ -16,6 +19,7 @@ #include "mkvtoolnix-gui/forms/main_window/main_window.h" #include "mkvtoolnix-gui/jobs/tool.h" #include "mkvtoolnix-gui/merge/adding_appending_files_dialog.h" +#include "mkvtoolnix-gui/merge/adding_directories_dialog.h" #include "mkvtoolnix-gui/merge/ask_scan_for_playlists_dialog.h" #include "mkvtoolnix-gui/merge/file_identification_thread.h" #include "mkvtoolnix-gui/merge/file_identification_pack.h" @@ -45,6 +49,53 @@ qHash(std::filesystem::path const &path) { namespace mtx::gui::Merge { +namespace { + +struct ResolvedDirectories { + using Dir = std::pair; + QVector m_directories; + QStringList m_files; +}; + +ResolvedDirectories +resolveDirectoriesToContainedFilesAndDirectories(QStringList const &namesToCheck) { + ResolvedDirectories resolvedDirs; + + for (auto const &nameToCheck : namesToCheck) { + auto info = QFileInfo{nameToCheck}; + if (!info.exists()) + continue; + + if (info.isFile()) { + resolvedDirs.m_files << nameToCheck; + continue; + } + + if (!info.isDir()) + continue; + + QStringList newFileNames; + QDirIterator it{nameToCheck, QDirIterator::Subdirectories}; + + while (it.hasNext()) { + it.next(); + info = it.fileInfo(); + + if (info.isFile()) + newFileNames << info.absoluteFilePath(); + } + + newFileNames.sort(Qt::CaseInsensitive); + + if (!newFileNames.isEmpty()) + resolvedDirs.m_directories << std::make_pair(nameToCheck, newFileNames); + } + + return resolvedDirs; +} + +} + using namespace mtx::gui; class ToolPrivate { @@ -710,10 +761,12 @@ Tool::handleIdentifiedSourceFiles(IdentificationPack &pack) { retrieveDiscInformationForPlaylists(identifiedSourceFiles); if ( (pack.m_addMode == IdentificationPack::AddMode::Append) + || (pack.m_addMode == IdentificationPack::AddMode::AddDontAsk) || ( (identifiedSourceFiles.count() == 1) && ( tab->isEmpty() || (pack.m_addMode == IdentificationPack::AddMode::Add)))) { - tab->addOrAppendIdentifiedFiles(identifiedSourceFiles, pack.m_sourceFileIdx, pack.m_addMode); + auto addMode = pack.m_addMode == IdentificationPack::AddMode::AddDontAsk ? IdentificationPack::AddMode::Add : pack.m_addMode; + tab->addOrAppendIdentifiedFiles(identifiedSourceFiles, pack.m_sourceFileIdx, addMode); return; } @@ -796,11 +849,34 @@ Tool::handleIdentifiedFiles(IdentificationPack identifiedFiles) { handleIdentifiedSourceFiles(identifiedFiles); } +std::optional +Tool::determineAddingDirectoriesPolicy() { + auto &settings = Util::Settings::get(); + auto policy = settings.m_mergeDragAndDropDirectoriesPolicy; + + if (policy != Util::Settings::MergeAddingDirectoriesPolicy::Ask) + return policy; + + AddingDirectoriesDialog dlg{this, policy}; + + if (!dlg.exec()) + return {}; + + policy = dlg.decision(); + + if (dlg.alwaysUseThisDecision()) { + settings.m_mergeDragAndDropDirectoriesPolicy = policy; + settings.save(); + } + + return policy; +} + void -Tool::identifyMultipleFiles(QStringList const &fileNamesToIdentify, - Qt::MouseButtons mouseButtons) { - auto &p = *p_func(); - auto fileNames = Util::replaceDirectoriesByContainedFiles(fileNamesToIdentify); +Tool::addFileIdentificationPack(QStringList const &fileNames, + IdentificationPack::AddMode addMode, + Qt::MouseButtons mouseButtons) { + auto &p = *p_func(); if (fileNames.isEmpty()) return; @@ -808,11 +884,56 @@ Tool::identifyMultipleFiles(QStringList const &fileNamesToIdentify, IdentificationPack pack; pack.m_tabId = reinterpret_cast(currentTab()); pack.m_fileNames = fileNames; + pack.m_addMode = addMode; pack.m_mouseButtons = mouseButtons; + qDebug() << "tabId" << pack.m_tabId << pack.m_fileNames; + p.identifier->worker().addPackToIdentify(pack); } +void +Tool::identifyMultipleFiles(QStringList const &fileNamesToIdentify, + Qt::MouseButtons mouseButtons) { + auto resolvedDirs = resolveDirectoriesToContainedFilesAndDirectories(fileNamesToIdentify); + + if (resolvedDirs.m_files.isEmpty() && resolvedDirs.m_directories.isEmpty()) + return; + + if (resolvedDirs.m_directories.isEmpty()) { + addFileIdentificationPack(resolvedDirs.m_files, IdentificationPack::AddMode::UserChoice, mouseButtons); + return; + } + + auto policyOpt = determineAddingDirectoriesPolicy(); + + if (!policyOpt) + return; + + auto policy = *policyOpt; + + if (policy == Util::Settings::MergeAddingDirectoriesPolicy::Flat) { + auto fileNames = resolvedDirs.m_files; + + for (auto const &dir : resolvedDirs.m_directories) + fileNames += dir.second; + + addFileIdentificationPack(fileNames, IdentificationPack::AddMode::UserChoice, mouseButtons); + return; + } + + if (!currentTab()) + appendNewTab(); + + addFileIdentificationPack(resolvedDirs.m_files, IdentificationPack::AddMode::UserChoice, mouseButtons); + + // Util::Settings::MergeAddingDirectoriesPolicy::AddEachDirectoryToNew + for (auto const &dir : resolvedDirs.m_directories) { + appendNewTab(); + addFileIdentificationPack(dir.second, IdentificationPack::AddMode::AddDontAsk, mouseButtons); + } +} + void Tool::fileIdentificationStarted() { p_func()->ui->overlordWidget->setEnabled(false); diff --git a/src/mkvtoolnix-gui/merge/tool.h b/src/mkvtoolnix-gui/merge/tool.h index f9729e3fa..9ec51e757 100644 --- a/src/mkvtoolnix-gui/merge/tool.h +++ b/src/mkvtoolnix-gui/merge/tool.h @@ -5,6 +5,7 @@ #include "mkvtoolnix-gui/main_window/tool_base.h" #include "mkvtoolnix-gui/merge/file_identification_thread.h" #include "mkvtoolnix-gui/merge/source_file.h" +#include "mkvtoolnix-gui/util/settings.h" class QDragEnterEvent; class QDragMoveEvent; @@ -105,6 +106,8 @@ protected: virtual void enableCopyMenuActions(); virtual void showMergeWidget(); + virtual std::optional determineAddingDirectoriesPolicy(); + virtual void addFileIdentificationPack(QStringList const &fileNames, IdentificationPack::AddMode addMode, Qt::MouseButtons mouseButtons); virtual QStringList fileNamesFromClipboard() const; virtual void dragEnterEvent(QDragEnterEvent *event) override; diff --git a/src/mkvtoolnix-gui/mkvtoolnix-gui.pro b/src/mkvtoolnix-gui/mkvtoolnix-gui.pro index 9dc89f3db..f6f4ae6fe 100644 --- a/src/mkvtoolnix-gui/mkvtoolnix-gui.pro +++ b/src/mkvtoolnix-gui/mkvtoolnix-gui.pro @@ -40,6 +40,7 @@ FORMS += \ forms/main_window/select_character_set_dialog.ui \ forms/main_window/status_bar_progress_widget.ui \ forms/merge/adding_appending_files_dialog.ui \ + forms/merge/adding_directories_dialog.ui \ forms/merge/additional_command_line_options_dialog.ui \ forms/merge/ask_scan_for_playlists_dialog.ui \ forms/merge/command_line_dialog.ui \ diff --git a/src/mkvtoolnix-gui/util/file.cpp b/src/mkvtoolnix-gui/util/file.cpp index 4ec526122..1695d5b6d 100644 --- a/src/mkvtoolnix-gui/util/file.cpp +++ b/src/mkvtoolnix-gui/util/file.cpp @@ -1,8 +1,6 @@ #include "common/common_pch.h" #include -#include -#include #include #include #include @@ -90,41 +88,6 @@ replaceInvalidFileNameCharacters(QString fileName) { return fileName; } -QStringList -replaceDirectoriesByContainedFiles(QStringList const &namesToCheck) { - QStringList fileNames; - - for (auto const &nameToCheck : namesToCheck) { - auto info = QFileInfo{nameToCheck}; - if (!info.exists()) - continue; - - if (info.isFile()) { - fileNames << nameToCheck; - continue; - } - - if (!info.isDir()) - continue; - - QStringList newFileNames; - QDirIterator it{nameToCheck, QDirIterator::Subdirectories}; - - while (it.hasNext()) { - it.next(); - info = it.fileInfo(); - - if (info.isFile()) - newFileNames << info.absoluteFilePath(); - } - - newFileNames.sort(Qt::CaseInsensitive); - fileNames += newFileNames; - } - - return fileNames; -} - QString detectMIMEType(QString const &fileName) { auto mimeType = ::mtx::mime::guess_type_for_file(to_utf8(fileName)); diff --git a/src/mkvtoolnix-gui/util/file.h b/src/mkvtoolnix-gui/util/file.h index 7f370129d..c3817de2d 100644 --- a/src/mkvtoolnix-gui/util/file.h +++ b/src/mkvtoolnix-gui/util/file.h @@ -20,8 +20,6 @@ QUrl pathToFileUrl(QString const &path); QString removeInvalidPathCharacters(QString fileName); QString replaceInvalidFileNameCharacters(QString fileName); -QStringList replaceDirectoriesByContainedFiles(QStringList const &namesToCheck); - QString detectMIMEType(QString const &fileName); } diff --git a/src/mkvtoolnix-gui/util/settings.cpp b/src/mkvtoolnix-gui/util/settings.cpp index 359d46c79..99f5f9ff4 100644 --- a/src/mkvtoolnix-gui/util/settings.cpp +++ b/src/mkvtoolnix-gui/util/settings.cpp @@ -547,6 +547,7 @@ Settings::load() { m_mergeAddingAppendingFilesPolicy = static_cast(reg.value(s_valMergeAddingAppendingFilesPolicy, static_cast(MergeAddingAppendingFilesPolicy::Ask)).toInt()); m_mergeLastAddingAppendingDecision = static_cast(reg.value(s_valMergeLastAddingAppendingDecision, static_cast(MergeAddingAppendingFilesPolicy::Add)).toInt()); m_mergeDragAndDropFilesPolicy = static_cast(reg.value(s_valMergeDragAndDropFilesPolicy, static_cast(MergeAddingAppendingFilesPolicy::Ask)).toInt()); + m_mergeDragAndDropDirectoriesPolicy = toMergeAddingDirectoriesPolicy(reg.value(s_valMergeDragAndDropDirectoriesPolicy, static_cast(MergeAddingDirectoriesPolicy::Ask)).toInt()); m_mergeLastDragAndDropFilesDecision = static_cast(reg.value(s_valMergeLastDragAndDropFilesDecision, static_cast(MergeAddingAppendingFilesPolicy::Add)).toInt()); m_mergeWarnMissingAudioTrack = static_cast(reg.value(s_valMergeWarnMissingAudioTrack, static_cast(MergeMissingAudioTrackPolicy::IfAudioTrackPresent)).toInt()); m_headerEditorDroppedFilesPolicy = static_cast(reg.value(s_valHeaderEditorDroppedFilesPolicy, static_cast(HeaderEditorDroppedFilesPolicy::Ask)).toInt()); @@ -987,6 +988,7 @@ Settings::save() reg.setValue(s_valMergeAddingAppendingFilesPolicy, static_cast(m_mergeAddingAppendingFilesPolicy)); reg.setValue(s_valMergeLastAddingAppendingDecision, static_cast(m_mergeLastAddingAppendingDecision)); reg.setValue(s_valMergeDragAndDropFilesPolicy, static_cast(m_mergeDragAndDropFilesPolicy)); + reg.setValue(s_valMergeDragAndDropDirectoriesPolicy, static_cast(m_mergeDragAndDropDirectoriesPolicy)); reg.setValue(s_valMergeLastDragAndDropFilesDecision, static_cast(m_mergeLastDragAndDropFilesDecision)); reg.setValue(s_valMergeWarnMissingAudioTrack, static_cast(m_mergeWarnMissingAudioTrack)); reg.setValue(s_valHeaderEditorDroppedFilesPolicy, static_cast(m_headerEditorDroppedFilesPolicy)); @@ -1405,4 +1407,11 @@ Settings::nthFileColor(int idx) return s_additionalColors.at(idx); } +Settings::MergeAddingDirectoriesPolicy +Settings::toMergeAddingDirectoriesPolicy(int value) { + return value == static_cast(MergeAddingDirectoriesPolicy::Flat) ? MergeAddingDirectoriesPolicy::Flat + : value == static_cast(MergeAddingDirectoriesPolicy::AddEachDirectoryToNew) ? MergeAddingDirectoriesPolicy::AddEachDirectoryToNew + : MergeAddingDirectoriesPolicy::Ask; +} + } diff --git a/src/mkvtoolnix-gui/util/settings.h b/src/mkvtoolnix-gui/util/settings.h index 1fc16a1e7..60dc3bbef 100644 --- a/src/mkvtoolnix-gui/util/settings.h +++ b/src/mkvtoolnix-gui/util/settings.h @@ -113,6 +113,13 @@ public: }; Q_ENUM(MergeAddingAppendingFilesPolicy); + enum class MergeAddingDirectoriesPolicy { + Ask, + Flat, + AddEachDirectoryToNew, + }; + Q_ENUM(MergeAddingDirectoriesPolicy); + enum class HeaderEditorDroppedFilesPolicy { Ask, Open, @@ -190,6 +197,7 @@ public: bool m_mergeEnableDialogNormGainRemoval, m_mergeAddBlurayCovers, m_mergeAttachmentsAlwaysSkipForExistingName; ClearMergeSettingsAction m_clearMergeSettings; MergeAddingAppendingFilesPolicy m_mergeDragAndDropFilesPolicy, m_mergeLastDragAndDropFilesDecision, m_mergeAddingAppendingFilesPolicy, m_mergeLastAddingAppendingDecision; + MergeAddingDirectoriesPolicy m_mergeDragAndDropDirectoriesPolicy; bool m_mergeAlwaysCreateNewSettingsForVideoFiles, m_mergeSortFilesTracksByTypeWhenAdding, m_mergeReconstructSequencesWhenAdding; HeaderEditorDroppedFilesPolicy m_headerEditorDroppedFilesPolicy; bool m_headerEditorDateTimeInUTC; @@ -315,6 +323,8 @@ public: static QString defaultBoundaryCharsForDerivingLanguageFromFileName(); static QVector defaultFileColors(); + + static MergeAddingDirectoriesPolicy toMergeAddingDirectoriesPolicy(int value); }; } diff --git a/src/mkvtoolnix-gui/util/settings_names.h b/src/mkvtoolnix-gui/util/settings_names.h index f13216b9f..8a0cd80ff 100644 --- a/src/mkvtoolnix-gui/util/settings_names.h +++ b/src/mkvtoolnix-gui/util/settings_names.h @@ -74,6 +74,7 @@ char const * const s_valMergeAlwaysAddDroppedFiles = "mergeAlways char const * const s_valMergeAlwaysCreateNewSettingsForVideoFiles = "mergeAlwaysCreateNewSettingsForVideoFiles"; char const * const s_valMergeAlwaysShowOutputFileControls = "mergeAlwaysShowOutputFileControls"; char const * const s_valMergeAttachmentsAlwaysSkipForExistingName = "mergeAttachmentsAlwaysSkipForExistingName"; +char const * const s_valMergeDragAndDropDirectoriesPolicy = "mergeDragAndDropDirectoriesPolicy"; char const * const s_valMergeDragAndDropFilesPolicy = "mergeDragAndDropFilesPolicy"; char const * const s_valMergeEnableDialogNormGainRemoval = "mergeEnableDialogNormGainRemoval"; char const * const s_valMergeFileColors = "mergeFileColors";