diff data/fileio/ResamplingWavFileReader.cpp @ 392:183ee2a55fc7

* More work to abstract out interactive components used in the data library, so that it does not need to depend on QtGui.
author Chris Cannam
date Fri, 14 Mar 2008 17:14:21 +0000
parents 1d656dcda8ef
children be49bf95d4a5
line wrap: on
line diff
--- a/data/fileio/ResamplingWavFileReader.cpp	Thu Mar 13 14:06:03 2008 +0000
+++ b/data/fileio/ResamplingWavFileReader.cpp	Fri Mar 14 17:14:21 2008 +0000
@@ -17,15 +17,15 @@
 
 #include "WavFileReader.h"
 #include "base/Profiler.h"
+#include "base/ProgressReporter.h"
 
-#include <QProgressDialog>
 #include <QFileInfo>
-#include <QApplication>
 
 ResamplingWavFileReader::ResamplingWavFileReader(FileSource source,
 						 ResampleMode resampleMode,
 						 CacheMode mode,
-						 size_t targetRate) :
+						 size_t targetRate,
+                                                 ProgressReporter *reporter) :
     CodedAudioFileReader(mode, targetRate),
     m_source(source),
     m_path(source.getLocalFilename()),
@@ -33,7 +33,7 @@
     m_processed(0),
     m_completion(0),
     m_original(0),
-    m_progress(0),
+    m_reporter(reporter),
     m_decodeThread(0)
 {
     m_channelCount = 0;
@@ -57,11 +57,10 @@
 
     if (resampleMode == ResampleAtOnce) {
 
-        if (dynamic_cast<QApplication *>(QCoreApplication::instance())) {
-            m_progress = new QProgressDialog
-                (QObject::tr("Resampling %1...").arg(QFileInfo(m_path).fileName()),
-                 QObject::tr("Stop"), 0, 100);
-            m_progress->hide();
+        if (m_reporter) {
+            connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled()));
+            m_reporter->setMessage
+                (tr("Resampling %1...").arg(QFileInfo(m_path).fileName()));
         }
 
         size_t blockSize = 16384;
@@ -85,10 +84,9 @@
         delete m_original;
         m_original = 0;
 
-        delete m_progress;
-        m_progress = 0;
+    } else {
 
-    } else {
+        if (m_reporter) m_reporter->setProgress(100);
 
         m_decodeThread = new DecodeThread(this);
         m_decodeThread->start();
@@ -107,6 +105,12 @@
 }
 
 void
+ResamplingWavFileReader::cancelled()
+{
+    m_cancelled = true;
+}
+
+void
 ResamplingWavFileReader::DecodeThread::run()
 {
     if (m_reader->m_cacheMode == CacheInTemporaryFile) {
@@ -151,16 +155,8 @@
     if (progress > 99) progress = 99;
     m_completion = progress;
     
-    if (m_progress) {
-	if (progress > m_progress->value()) {
-	    m_progress->setValue(progress);
-	    m_progress->show();
-	    m_progress->raise();
-	    qApp->processEvents();
-	    if (m_progress->wasCanceled()) {
-		m_cancelled = true;
-	    }
-	}
+    if (m_reporter) {
+        m_reporter->setProgress(progress);
     }
 }