Skip to content

Commit

Permalink
Respect build options in export dialogs (LMMS#3714)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
irrenhaus3 authored and PhysSong committed Jul 27, 2017
1 parent 913449b commit dfe8c49
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/ProjectRenderer.h
Expand Up @@ -35,7 +35,7 @@ class ProjectRenderer : public QThread
{
Q_OBJECT
public:
enum ExportFileFormats
enum ExportFileFormats: int
{
WaveFile,
OggFile,
Expand Down
7 changes: 4 additions & 3 deletions src/core/Song.cpp
Expand Up @@ -1337,10 +1337,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 );
Expand Down
64 changes: 28 additions & 36 deletions src/gui/ExportProjectDialog.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ProjectRenderer::ExportFileFormats>(
format_tag.toInt(&successful_conversion)
);
Q_ASSERT(successful_conversion);

bool stereoModeVisible = exportFormat == ProjectRenderer::MP3File;

Expand All @@ -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<ProjectRenderer::ExportFileFormats>(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 );

Expand Down

0 comments on commit dfe8c49

Please sign in to comment.