From c8af34af2f50db95fac3ea8fa1dbc86c78bc43c1 Mon Sep 17 00:00:00 2001 From: irrenhaus3 Date: Wed, 26 Jul 2017 12:48:25 +0200 Subject: [PATCH] Respect build options in export dialogs (#3714) * Respect build options in ExportProjectDialog * Use QItem user data instead of hard ordering to identify export format in ExportProjectDialog * For compatibility with QVariant, ExportFileFormats is now explicitly an int. * Don't break out of format identifier loop prematurely in Song export. --- include/ProjectRenderer.h | 2 +- src/core/Song.cpp | 7 ++-- src/gui/ExportProjectDialog.cpp | 64 +++++++++++++++------------------ 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/include/ProjectRenderer.h b/include/ProjectRenderer.h index 15d043e51..543eb43c3 100644 --- a/include/ProjectRenderer.h +++ b/include/ProjectRenderer.h @@ -35,7 +35,7 @@ class ProjectRenderer : public QThread { Q_OBJECT public: - enum ExportFileFormats + enum ExportFileFormats: int { WaveFile, OggFile, diff --git a/src/core/Song.cpp b/src/core/Song.cpp index f40616e21..782845399 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -1328,10 +1328,11 @@ void Song::exportProject( bool multiExport ) efd.setFileMode( FileDialog::AnyFile ); int idx = 0; QStringList types; - while( ProjectRenderer::fileEncodeDevices[idx].m_fileFormat != ProjectRenderer::NumFileFormats && - ProjectRenderer::fileEncodeDevices[idx].isAvailable()) + while( ProjectRenderer::fileEncodeDevices[idx].m_fileFormat != ProjectRenderer::NumFileFormats) { - types << tr( ProjectRenderer::fileEncodeDevices[idx].m_description ); + if(ProjectRenderer::fileEncodeDevices[idx].isAvailable()) { + types << tr(ProjectRenderer::fileEncodeDevices[idx].m_description); + } ++idx; } efd.setNameFilters( types ); diff --git a/src/gui/ExportProjectDialog.cpp b/src/gui/ExportProjectDialog.cpp index 83c7883cc..0bd815010 100644 --- a/src/gui/ExportProjectDialog.cpp +++ b/src/gui/ExportProjectDialog.cpp @@ -65,7 +65,9 @@ ExportProjectDialog::ExportProjectDialog( const QString & _file_name, // add to combo box fileFormatCB->addItem( ProjectRenderer::tr( - ProjectRenderer::fileEncodeDevices[i].m_description ) ); + ProjectRenderer::fileEncodeDevices[i].m_description ), + QVariant(ProjectRenderer::fileEncodeDevices[i].m_fileFormat) // format tag; later used for identification + ); // if this is our extension, select it if( QString::compare( renderExt, fileExt, @@ -187,29 +189,16 @@ void ExportProjectDialog::startExport() } -ProjectRenderer::ExportFileFormats convertIndexToExportFileFormat(int index) -{ - switch (index) - { - case 0: - return ProjectRenderer::WaveFile; - case 1: - return ProjectRenderer::OggFile; - case 2: - return ProjectRenderer::MP3File; - default: - Q_ASSERT(false); - break; - } - - return ProjectRenderer::NumFileFormats; -} - - void ExportProjectDialog::onFileFormatChanged(int index) { - ProjectRenderer::ExportFileFormats exportFormat = - convertIndexToExportFileFormat(index); + // Extract the format tag from the currently selected item, + // and adjust the UI properly. + QVariant format_tag = fileFormatCB->itemData(index); + bool successful_conversion = false; + auto exportFormat = static_cast( + format_tag.toInt(&successful_conversion) + ); + Q_ASSERT(successful_conversion); bool stereoModeVisible = exportFormat == ProjectRenderer::MP3File; @@ -236,28 +225,31 @@ void ExportProjectDialog::startBtnClicked() { m_ft = ProjectRenderer::NumFileFormats; + //Get file format from current menu selection. + bool successful_conversion = false; + QVariant tag = fileFormatCB->itemData(fileFormatCB->currentIndex()); + m_ft = static_cast(tag.toInt(&successful_conversion)); + + if( !successful_conversion ) + { + QMessageBox::information( this, tr( "Error" ), + tr( "Error while determining file-encoder device. " + "Please try to choose a different output " + "format." ) ); + reject(); + return; + } + + // Find proper file extension. for( int i = 0; i < ProjectRenderer::NumFileFormats; ++i ) { - if( fileFormatCB->currentText() == - ProjectRenderer::tr( - ProjectRenderer::fileEncodeDevices[i].m_description ) ) + if (m_ft == ProjectRenderer::fileEncodeDevices[i].m_fileFormat) { - m_ft = ProjectRenderer::fileEncodeDevices[i].m_fileFormat; m_fileExtension = QString( QLatin1String( ProjectRenderer::fileEncodeDevices[i].m_extension ) ); break; } } - if( m_ft == ProjectRenderer::NumFileFormats ) - { - QMessageBox::information( this, tr( "Error" ), - tr( "Error while determining file-encoder device. " - "Please try to choose a different output " - "format." ) ); - reject(); - return; - } - startButton->setEnabled( false ); progressBar->setEnabled( true );