From 063c53017f95d2952ccc4c78bb275c05e2756ebf Mon Sep 17 00:00:00 2001 From: lordmulder Date: Tue, 14 Dec 2010 01:25:13 +0100 Subject: [PATCH] Added an option to prepend the source file's relative path to the output file's path. This might be useful when converting a lot of files at once that originate from different source folders. --- gui/MainWindow.ui | 61 ++++++++++++++++++++++++++++++++--- src/Config.h | 2 +- src/Dialog_MainWindow.cpp | 11 +++++++ src/Dialog_MainWindow.h | 1 + src/Dialog_Processing.cpp | 10 ++++-- src/Model_Settings.cpp | 2 ++ src/Model_Settings.h | 1 + src/Thread_Initialization.cpp | 52 ++++++++++++++++++++++++++--- src/Thread_Process.cpp | 13 +++++++- src/Thread_Process.h | 3 +- 10 files changed, 142 insertions(+), 14 deletions(-) diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index fcc2c07f..fa2e5f31 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -362,11 +362,38 @@ - - - Save output files to the same location where the input file is located - - + + + + + Save output files to the same location where the input file is located + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 15 + 20 + + + + + + + + Prepend relative source file path to output file + + + + @@ -1443,6 +1470,14 @@ + + + + + + + + @@ -1733,5 +1768,21 @@ + + saveToSourceFolderCheckBox + toggled(bool) + prependRelativePathCheckBox + setDisabled(bool) + + + 70 + 79 + + + 70 + 79 + + + diff --git a/src/Config.h b/src/Config.h index eaff0afb..1d7b9988 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 0 -#define VER_LAMEXP_BUILD 149 +#define VER_LAMEXP_BUILD 151 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 1a015b48..706ac889 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -156,6 +156,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S outputFolderView->setMouseTracking(false); outputFolderView->setContextMenuPolicy(Qt::CustomContextMenu); while(saveToSourceFolderCheckBox->isChecked() != m_settings->outputToSourceDir()) saveToSourceFolderCheckBox->click(); + prependRelativePathCheckBox->setChecked(m_settings->prependRelativeSourcePath()); connect(outputFolderView, SIGNAL(clicked(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex))); connect(outputFolderView, SIGNAL(activated(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex))); connect(outputFolderView, SIGNAL(entered(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex))); @@ -166,6 +167,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S connect(buttonGotoDesktop, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked())); connect(buttonGotoMusic, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked())); connect(saveToSourceFolderCheckBox, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged())); + connect(prependRelativePathCheckBox, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged())); m_outputFolderContextMenu = new QMenu(); QAction *showFolderContextAction = m_outputFolderContextMenu->addAction(QIcon(":/icons/zoom.png"), "Browse Selected Folder"); connect(outputFolderView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(outputFolderContextMenu(QPoint))); @@ -1258,6 +1260,15 @@ void MainWindow::saveToSourceFolderChanged(void) m_settings->outputToSourceDir(saveToSourceFolderCheckBox->isChecked()); } +/* + * Prepend relative source file path to output file name changed + */ +void MainWindow::prependRelativePathChanged(void) +{ + m_settings->prependRelativeSourcePath(prependRelativePathCheckBox->isChecked()); +} + + /* * Restore the override cursor */ diff --git a/src/Dialog_MainWindow.h b/src/Dialog_MainWindow.h index fd6580cb..58cb71b9 100644 --- a/src/Dialog_MainWindow.h +++ b/src/Dialog_MainWindow.h @@ -79,6 +79,7 @@ private slots: void metaTagsEnabledChanged(void); void playlistEnabledChanged(void); void saveToSourceFolderChanged(void); + void prependRelativePathChanged(void); void restoreCursor(void); void sourceFilesContextMenu(const QPoint &pos); void previewContextActionTriggered(void); diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 83dc226c..af1697c7 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -450,7 +450,13 @@ void ProcessingDialog::startNextJob(void) throw "Unsupported encoder!"; } - ProcessThread *thread = new ProcessThread(currentFile, (m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath(): m_settings->outputDir()), encoder); + ProcessThread *thread = new ProcessThread + ( + currentFile, + (m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath(): m_settings->outputDir()), + encoder, + m_settings->prependRelativeSourcePath() + ); m_threadList.append(thread); m_allJobs.append(thread->getId()); @@ -498,7 +504,7 @@ void ProcessingDialog::writePlayList(void) { if(!m_succeededJobs.contains(m_allJobs.at(i))) continue; - playList.write(QFileInfo(m_playList.value(m_allJobs.at(i), "N/A")).fileName().toUtf8().constData()); + playList.write(QDir::toNativeSeparators(QDir(m_settings->outputDir()).relativeFilePath(m_playList.value(m_allJobs.at(i), "N/A"))).toUtf8().constData()); playList.write("\r\n"); } playList.close(); diff --git a/src/Model_Settings.cpp b/src/Model_Settings.cpp index abb03175..deebff9a 100644 --- a/src/Model_Settings.cpp +++ b/src/Model_Settings.cpp @@ -38,6 +38,7 @@ static const char *g_settingsId_compressionRCMode = "Compression/RCMode"; static const char *g_settingsId_compressionBitrate = "Compression/Bitrate"; static const char *g_settingsId_outputDir = "OutputDirectory/SelectedPath"; static const char *g_settingsId_outputToSourceDir = "OutputDirectory/OutputToSourceFolder"; +static const char *g_settingsId_prependRelativeSourcePath = "OutputDirectory/PrependRelativeSourcePath"; static const char *g_settingsId_writeMetaTags = "Flags/WriteMetaTags"; static const char *g_settingsId_createPlaylist = "Flags/AutoCreatePlaylist"; static const char *g_settingsId_autoUpdateLastCheck = "AutoUpdate/LastCheck"; @@ -121,6 +122,7 @@ MAKE_OPTION1(compressionRCMode, 0) MAKE_OPTION1(compressionBitrate, 7) MAKE_OPTION2(outputDir, QString()) MAKE_OPTION3(outputToSourceDir, false) +MAKE_OPTION3(prependRelativeSourcePath, false) MAKE_OPTION3(writeMetaTags, true) MAKE_OPTION3(createPlaylist, true) MAKE_OPTION2(autoUpdateLastCheck, "Never") diff --git a/src/Model_Settings.h b/src/Model_Settings.h index 749a254c..51c1caf2 100644 --- a/src/Model_Settings.h +++ b/src/Model_Settings.h @@ -69,6 +69,7 @@ public: MAKE_OPTION_DEC1(compressionBitrate); MAKE_OPTION_DEC2(outputDir); MAKE_OPTION_DEC3(outputToSourceDir); + MAKE_OPTION_DEC3(prependRelativeSourcePath); MAKE_OPTION_DEC3(writeMetaTags); MAKE_OPTION_DEC3(createPlaylist); MAKE_OPTION_DEC2(autoUpdateLastCheck); diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index 17be6b57..b98c2595 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -255,7 +255,7 @@ void InitializationThread::initNeroAac(void) if(!(neroVersion > 0)) { - qWarning("Nero AAC version could not be determined -> AAC encoding support will be disabled!", neroVersion); + qWarning("Nero AAC version could not be determined -> AAC encoding support will be disabled!"); for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]); return; } @@ -289,15 +289,12 @@ void InitializationThread::initWmaDec(void) LockedFile *wmaFileBin = NULL; QFileInfo wmaFileInfo = QFileInfo(QString("%1/%2").arg(programFilesDir.absolutePath(), wmaDecoderComponentPath)); - //Lock the WMA Decoder binaries if(!wmaFileInfo.exists()) { qDebug("WMA File Decoder not found -> WMA decoding support will be disabled!\n"); return; } - qDebug("Found WMA File Decoder binary:\n%s\n", wmaFileInfo.canonicalFilePath().toUtf8().constData()); - try { wmaFileBin = new LockedFile(wmaFileInfo.canonicalFilePath()); @@ -308,6 +305,53 @@ void InitializationThread::initWmaDec(void) return; } + QProcess process; + process.setProcessChannelMode(QProcess::MergedChannels); + process.setReadChannel(QProcess::StandardOutput); + process.start(wmaFileInfo.canonicalFilePath(), QStringList()); + + if(!process.waitForStarted()) + { + qWarning("WmaWav process failed to create!"); + qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); + process.kill(); + process.waitForFinished(-1); + return; + } + + bool b_wmaWavFound = false; + + while(process.state() != QProcess::NotRunning) + { + if(!process.waitForReadyRead()) + { + if(process.state() == QProcess::Running) + { + qWarning("WmaWav process time out -> killing!"); + process.kill(); + process.waitForFinished(-1); + return; + } + } + while(process.canReadLine()) + { + QString line = QString::fromUtf8(process.readLine().constData()).simplified(); + if(line.contains("Usage: wmatowav.exe WMAFileSpec WAVFileSpec", Qt::CaseInsensitive)) + { + b_wmaWavFound = true; + } + } + } + + if(!b_wmaWavFound) + { + qWarning("WmaWav could not be identified -> WMA decoding support will be disabled!\n"); + LAMEXP_DELETE(wmaFileBin); + return; + } + + qDebug("Found WMA File Decoder binary:\n%s\n", wmaFileInfo.canonicalFilePath().toUtf8().constData()); + if(wmaFileBin) { lamexp_register_tool(wmaFileInfo.fileName(), wmaFileBin); diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index 3bab3ce2..c7aace93 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -44,12 +44,13 @@ QMutex *ProcessThread::m_mutex_genFileName = NULL; // Constructor //////////////////////////////////////////////////////////// -ProcessThread::ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, AbstractEncoder *encoder) +ProcessThread::ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, AbstractEncoder *encoder, const bool prependRelativeSourcePath) : m_audioFile(audioFile), m_outputDirectory(outputDirectory), m_encoder(encoder), m_jobId(QUuid::createUuid()), + m_prependRelativeSourcePath(prependRelativeSourcePath), m_aborted(false) { if(m_mutex_genFileName) @@ -211,6 +212,16 @@ QString ProcessThread::generateOutFileName(void) QString baseName = sourceFile.completeBaseName(); QDir targetDir(m_outputDirectory.isEmpty() ? sourceFile.canonicalPath() : m_outputDirectory); + + if(m_prependRelativeSourcePath && !m_outputDirectory.isEmpty()) + { + QDir rootDir = sourceFile.dir(); + while(!rootDir.isRoot()) + { + if(!rootDir.cdUp()) break; + } + targetDir.setPath(QString("%1/%2").arg(targetDir.absolutePath(), QFileInfo(rootDir.relativeFilePath(sourceFile.canonicalFilePath())).path())); + } if(!targetDir.exists()) { diff --git a/src/Thread_Process.h b/src/Thread_Process.h index 7e7eb2fa..6413fe7a 100644 --- a/src/Thread_Process.h +++ b/src/Thread_Process.h @@ -35,7 +35,7 @@ class ProcessThread: public QThread Q_OBJECT public: - ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, AbstractEncoder *encoder); + ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, AbstractEncoder *encoder, const bool prependRelativeSourcePath); ~ProcessThread(void); void run(); @@ -73,6 +73,7 @@ private: volatile bool m_aborted; ProcessStep m_currentStep; QStringList m_tempFiles; + const bool m_prependRelativeSourcePath; static QMutex *m_mutex_genFileName; };