OSDN Git Service

Happy new year 2016!
[lamexp/LameXP.git] / src / Decoder_Wave.cpp
index 90bb39b..0e1ff5a 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 //Qt
 #include <QDir>
 
+//Type
+typedef struct _ProgressData
+{
+       WaveDecoder   *const instance;
+       volatile bool *const abrtFlag;
+}
+ProgressData;
+
 WaveDecoder::WaveDecoder(void)
 {
 }
@@ -40,10 +48,12 @@ WaveDecoder::~WaveDecoder(void)
 
 bool WaveDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag)
 {
-       emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
-
+       emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(QDir::toNativeSeparators(sourceFile), QDir::toNativeSeparators(outputFile)));
        emit statusUpdated(0);
-       const bool okay = MUtils::OS::copy_file(sourceFile, outputFile);
+
+       ProgressData progressData = { this, abortFlag };
+       const bool okay = MUtils::OS::copy_file(sourceFile, outputFile, true, progressHandler, &progressData);
+       
        emit statusUpdated(100);
 
        if(okay)
@@ -58,6 +68,22 @@ bool WaveDecoder::decode(const QString &sourceFile, const QString &outputFile, v
        return okay;
 }
 
+bool WaveDecoder::progressHandler(const double &progress, void *const data)
+{
+       if(data)
+       {
+               //qWarning("Copy progress: %.2f", progress);
+               reinterpret_cast<ProgressData*>(data)->instance->updateProgress(progress);
+               return (!(*reinterpret_cast<ProgressData*>(data)->abrtFlag));
+       }
+       return true;
+}
+
+void WaveDecoder::updateProgress(const double &progress)
+{
+       emit statusUpdated(qBound(0, qRound(progress * 100.0), 100));
+}
+
 bool WaveDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
 {
        if(containerType.compare("Wave", Qt::CaseInsensitive) == 0)
@@ -71,7 +97,18 @@ bool WaveDecoder::isFormatSupported(const QString &containerType, const QString
        return false;
 }
 
-QStringList WaveDecoder::supportedTypes(void)
+const AbstractDecoder::supportedType_t *WaveDecoder::supportedTypes(void)
 {
-       return QStringList() << "Waveform Audio File (*.wav)";
+       static const char *exts[] =
+       {
+               "wav", NULL
+       };
+
+       static const supportedType_t s_supportedTypes[] =
+       {
+               { "Waveform Audio File", exts },
+               { NULL, NULL }
+       };
+
+       return s_supportedTypes;
 }