Some code clean up. Use an enum type for the "overwrite" mode instead of two separate flags.
This commit is contained in:
parent
b7b4fa31bd
commit
1bb96ba6db
@ -63,8 +63,7 @@ ProcessThread::ProcessThread(const AudioFileModel &audioFile, const QString &out
|
||||
m_jobId(QUuid::createUuid()),
|
||||
m_prependRelativeSourcePath(prependRelativeSourcePath),
|
||||
m_renamePattern("<BaseName>"),
|
||||
m_overwriteSkipExistingFile(false),
|
||||
m_overwriteReplacesExisting(false),
|
||||
m_overwriteMode(OverwriteMode_KeepBoth),
|
||||
m_initialized(-1),
|
||||
m_aborted(false),
|
||||
m_propDetect(new WaveProperties())
|
||||
@ -438,7 +437,7 @@ int ProcessThread::generateOutFileName(QString &outFileName)
|
||||
outFileName = QString("%1/%2.%3").arg(targetDir.canonicalPath(), fileName, m_encoder->extension());
|
||||
|
||||
//Skip file, if target file exists (optional!)
|
||||
if(m_overwriteSkipExistingFile && QFileInfo(outFileName).exists())
|
||||
if((m_overwriteMode == OverwriteMode_SkipExisting) && QFileInfo(outFileName).exists())
|
||||
{
|
||||
handleMessage(QString("%1\n%2\n").arg(tr("Target output file already exists, going to skip this file:"), QDir::toNativeSeparators(outFileName)));
|
||||
handleMessage(tr("If you don't want existing files to be skipped, please change the overwrite mode!"));
|
||||
@ -446,11 +445,11 @@ int ProcessThread::generateOutFileName(QString &outFileName)
|
||||
}
|
||||
|
||||
//Delete file, if target file exists (optional!)
|
||||
if(m_overwriteReplacesExisting && QFileInfo(outFileName).exists() && QFileInfo(outFileName).isFile())
|
||||
if((m_overwriteMode == OverwriteMode_Overwrite) && QFileInfo(outFileName).exists() && QFileInfo(outFileName).isFile())
|
||||
{
|
||||
handleMessage(QString("%1\n%2\n").arg(tr("Target output file already exists, going to delete existing file:"), QDir::toNativeSeparators(outFileName)));
|
||||
if(sourceFile.canonicalFilePath().compare(QFileInfo(outFileName).absoluteFilePath(), Qt::CaseInsensitive) != 0)
|
||||
{
|
||||
handleMessage(QString("%1\n%2\n").arg(tr("Target output file already exists, going to delete existing file:"), QDir::toNativeSeparators(outFileName)));
|
||||
for(int i = 0; i < 16; i++)
|
||||
{
|
||||
if(QFile::remove(outFileName))
|
||||
@ -459,10 +458,10 @@ int ProcessThread::generateOutFileName(QString &outFileName)
|
||||
}
|
||||
lamexp_sleep(125);
|
||||
}
|
||||
if(QFileInfo(outFileName).exists())
|
||||
{
|
||||
handleMessage(QString("%1\n").arg(tr("Failed to delete existing target file, will save to another file name!")));
|
||||
}
|
||||
}
|
||||
if(QFileInfo(outFileName).exists())
|
||||
{
|
||||
handleMessage(QString("%1\n").arg(tr("Failed to delete existing target file, will save to another file name!")));
|
||||
}
|
||||
}
|
||||
|
||||
@ -679,17 +678,19 @@ void ProcessThread::setRenamePattern(const QString &pattern)
|
||||
if(!newPattern.isEmpty()) m_renamePattern = newPattern;
|
||||
}
|
||||
|
||||
void ProcessThread::setOverwriteMode(const bool bSkipExistingFile, const bool bReplacesExisting)
|
||||
void ProcessThread::setOverwriteMode(const bool &bSkipExistingFile, const bool &bReplacesExisting)
|
||||
{
|
||||
if(bSkipExistingFile && bReplacesExisting)
|
||||
{
|
||||
qWarning("Inconsistent overwrite flags, reverting to default!");
|
||||
m_overwriteSkipExistingFile = false;
|
||||
m_overwriteReplacesExisting = false;
|
||||
qWarning("Inconsistent overwrite flags -> reverting to default!");
|
||||
m_overwriteMode = OverwriteMode_KeepBoth;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_overwriteMode = OverwriteMode_KeepBoth;
|
||||
if(bSkipExistingFile) m_overwriteMode = OverwriteMode_SkipExisting;
|
||||
if(bReplacesExisting) m_overwriteMode = OverwriteMode_Overwrite;
|
||||
}
|
||||
|
||||
m_overwriteSkipExistingFile = bSkipExistingFile;
|
||||
m_overwriteReplacesExisting = bReplacesExisting;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
|
||||
QUuid getId(void) { return m_jobId; }
|
||||
void setRenamePattern(const QString &pattern);
|
||||
void setOverwriteMode(const bool bSkipExistingFile, const bool ReplacesExisting = false);
|
||||
void setOverwriteMode(const bool &bSkipExistingFile, const bool &bReplacesExisting = false);
|
||||
void addFilter(AbstractFilter *filter);
|
||||
|
||||
public slots:
|
||||
@ -76,6 +76,13 @@ private:
|
||||
EncodingStep = 3,
|
||||
UnknownStep = 4
|
||||
};
|
||||
|
||||
enum OverwriteMode
|
||||
{
|
||||
OverwriteMode_KeepBoth = 0,
|
||||
OverwriteMode_SkipExisting = 1,
|
||||
OverwriteMode_Overwrite = 2,
|
||||
};
|
||||
|
||||
void processFile();
|
||||
int generateOutFileName(QString &outFileName);
|
||||
@ -97,8 +104,7 @@ private:
|
||||
const bool m_prependRelativeSourcePath;
|
||||
QList<AbstractFilter*> m_filters;
|
||||
QString m_renamePattern;
|
||||
bool m_overwriteSkipExistingFile;
|
||||
bool m_overwriteReplacesExisting;
|
||||
int m_overwriteMode;
|
||||
WaveProperties *m_propDetect;
|
||||
QString m_outFileName;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user