diff data/fileio/MP3FileReader.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 e6d11871e4c9
children be49bf95d4a5
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp	Thu Mar 13 14:06:03 2008 +0000
+++ b/data/fileio/MP3FileReader.cpp	Fri Mar 14 17:14:21 2008 +0000
@@ -17,7 +17,7 @@
 #ifdef HAVE_MAD
 
 #include "MP3FileReader.h"
-#include "ProgressPrinter.h"
+#include "base/ProgressReporter.h"
 
 #include "system/System.h"
 
@@ -32,12 +32,11 @@
 #endif
 #define DEBUG_ID3TAG 1
 
-#include <QApplication>
 #include <QFileInfo>
-#include <QProgressDialog>
 
 MP3FileReader::MP3FileReader(FileSource source, DecodeMode decodeMode, 
-                             CacheMode mode, size_t targetRate) :
+                             CacheMode mode, size_t targetRate,
+                             ProgressReporter *reporter) :
     CodedAudioFileReader(mode, targetRate),
     m_source(source),
     m_path(source.getLocalFilename()),
@@ -51,7 +50,7 @@
     m_cancelled = false;
     m_completion = 0;
     m_done = false;
-    m_progress = 0;
+    m_reporter = reporter;
 
     struct stat stat;
     if (::stat(m_path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) {
@@ -108,14 +107,10 @@
 
     if (decodeMode == DecodeAtOnce) {
 
-        if (dynamic_cast<QApplication *>(QCoreApplication::instance())) {
-            m_progress = new QProgressDialog
-                (QObject::tr("Decoding %1...").arg(QFileInfo(m_path).fileName()),
-                 QObject::tr("Stop"), 0, 100);
-            m_progress->hide();
-        } else {
-            ProgressPrinter *pp = new ProgressPrinter(tr("Decoding..."), this);
-            connect(this, SIGNAL(progress(int)), pp, SLOT(progress(int)));
+        if (m_reporter) {
+            connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled()));
+            m_reporter->setMessage
+                (tr("Decoding %1...").arg(QFileInfo(m_path).fileName()));
         }
 
         if (!decode(m_filebuffer, m_fileSize)) {
@@ -127,10 +122,9 @@
 
         if (isDecodeCacheInitialised()) finishDecodeCache();
 
-	delete m_progress;
-	m_progress = 0;
+    } else {
 
-    } else {
+        if (m_reporter) m_reporter->setProgress(100);
 
         m_decodeThread = new DecodeThread(this);
         m_decodeThread->start();
@@ -154,6 +148,12 @@
 }
 
 void
+MP3FileReader::cancelled()
+{
+    m_cancelled = true;
+}
+
+void
 MP3FileReader::loadTags()
 {
     m_title = "";
@@ -366,20 +366,9 @@
         int p = int(percent);
         if (p < 1) p = 1;
         if (p > 99) p = 99;
-        if (m_completion != p || (m_progress && !m_progress->isVisible())) {
+        if (m_completion != p && m_reporter) {
             m_completion = p;
-            emit progress(m_completion);
-            if (m_progress) {
-                if (m_completion > m_progress->value()) {
-                    m_progress->setValue(m_completion);
-                    m_progress->show();
-                    m_progress->raise();
-                    qApp->processEvents();
-                    if (m_progress->wasCanceled()) {
-                        m_cancelled = true;
-                    }
-                }
-            }
+            m_reporter->setProgress(m_completion);
         }
     }