diff data/fileio/MP3FileReader.cpp @ 290:92e8dbde73cd

* Revert revision 713. We do like QStrings after all.
author Chris Cannam
date Fri, 24 Aug 2007 11:41:48 +0000
parents 20028c634494
children c022976d18e8
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp	Thu Aug 16 16:47:07 2007 +0000
+++ b/data/fileio/MP3FileReader.cpp	Fri Aug 24 11:41:48 2007 +0000
@@ -34,7 +34,7 @@
 #include <QFileInfo>
 #include <QProgressDialog>
 
-MP3FileReader::MP3FileReader(std::string path, DecodeMode decodeMode, CacheMode mode) :
+MP3FileReader::MP3FileReader(QString path, DecodeMode decodeMode, CacheMode mode) :
     CodedAudioFileReader(mode),
     m_path(path),
     m_decodeThread(0)
@@ -52,20 +52,20 @@
     m_progress = 0;
 
     struct stat stat;
-    if (::stat(path.c_str(), &stat) == -1 || stat.st_size == 0) {
-        setError("File does not exist", path);
+    if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) {
+	m_error = QString("File %1 does not exist.").arg(path);
 	return;
     }
 
     m_fileSize = stat.st_size;
 
     int fd = -1;
-    if ((fd = ::open(path.c_str(), O_RDONLY
+    if ((fd = ::open(path.toLocal8Bit().data(), O_RDONLY
 #ifdef _WIN32
                      | O_BINARY
 #endif
                      , 0)) < 0) {
-	setError("Failed to open file for reading", path);
+	m_error = QString("Failed to open file %1 for reading.").arg(path);
 	return;
     }	
 
@@ -74,7 +74,7 @@
     try {
         m_filebuffer = new unsigned char[m_fileSize];
     } catch (...) {
-        setError("Out of memory");
+        m_error = QString("Out of memory");
         ::close(fd);
 	return;
     }
@@ -84,7 +84,8 @@
     while (offset < m_fileSize) {
         sz = ::read(fd, m_filebuffer + offset, m_fileSize - offset);
         if (sz < 0) {
-            setError("Read error", path);
+            m_error = QString("Read error for file %1 (after %2 bytes)")
+                .arg(path).arg(offset);
             delete[] m_filebuffer;
             ::close(fd);
             return;
@@ -104,12 +105,12 @@
     if (decodeMode == DecodeAtOnce) {
 
 	m_progress = new QProgressDialog
-	    (QObject::tr("Decoding %1...").arg(QFileInfo(path.c_str()).fileName()),
+	    (QObject::tr("Decoding %1...").arg(QFileInfo(path).fileName()),
 	     QObject::tr("Stop"), 0, 100);
 	m_progress->hide();
 
         if (!decode(m_filebuffer, m_fileSize)) {
-            setError("Failed to decode file", path);
+            m_error = QString("Failed to decode file %1.").arg(path);
         }
         
         delete[] m_filebuffer;
@@ -147,7 +148,7 @@
 
 #ifdef HAVE_ID3TAG
 
-    id3_file *file = id3_file_open(m_path.c_str(),
+    id3_file *file = id3_file_open(m_path.toLocal8Bit().data(),
                                    ID3_FILE_MODE_READONLY);
     if (!file) return;
 
@@ -203,7 +204,7 @@
         return;
     }
         
-    m_title = (const char *)u8str;
+    m_title = QString::fromUtf8((const char *)u8str);
     free(u8str);
     id3_file_close(file);
 
@@ -220,7 +221,7 @@
 MP3FileReader::DecodeThread::run()
 {
     if (!m_reader->decode(m_reader->m_filebuffer, m_reader->m_fileSize)) {
-        m_reader->setError("Failed to decode file", m_reader->m_path);
+        m_reader->m_error = QString("Failed to decode file %1.").arg(m_reader->m_path);
     }
 
     delete[] m_reader->m_filebuffer;
@@ -360,7 +361,7 @@
 }
 
 void
-MP3FileReader::getSupportedExtensions(std::set<std::string> &extensions)
+MP3FileReader::getSupportedExtensions(std::set<QString> &extensions)
 {
     extensions.insert("mp3");
 }