Sophie

Sophie

distrib > Mageia > 6 > armv7hl > by-pkgid > 7edda378eb53b643eed57e932131aa15 > files > 6

amarok-2.8.90-6.mga6.src.rpm

From aaff3348862a1999069feff93d9e1e4d995b7225 Mon Sep 17 00:00:00 2001
From: Stefano Pettini <stefano.pettini@gmail.com>
Date: Fri, 25 Mar 2016 10:15:18 +0100
Subject: [PATCH 13/16] Fix for the infinite loop in case a home-burned or old
 audio CD is inserted

Home-burned or old audio CDs usually don't have CDTEXT, that is what
was triggering the bug. The bug was releted to poor management of
track names, that are generated using the pattern "Track%1.wav". The
audiocd:/ KIO protocol requires that a device is also added to the
URL, and this was not done everywhere. Lack of device was triggering
an unexpected/strange behaviour in some KDE function making Amarok
enter an infinite loop.

REVIEW: 127468
BUG: 339190
---
 .../collections/audiocd/AudioCdCollection.cpp      | 49 ++++++++++++++++------
 .../collections/audiocd/AudioCdCollection.h        |  7 ++++
 2 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/src/core-impl/collections/audiocd/AudioCdCollection.cpp b/src/core-impl/collections/audiocd/AudioCdCollection.cpp
index 3dfa7c3..3af6e36 100644
--- a/src/core-impl/collections/audiocd/AudioCdCollection.cpp
+++ b/src/core-impl/collections/audiocd/AudioCdCollection.cpp
@@ -91,7 +91,9 @@ KUrl
 AudioCdCollection::audiocdUrl( const QString &path ) const
 {
     KUrl url("audiocd:/");
-    url.addPath( path );
+
+    if( !path.isEmpty() )
+        url.addPath( path );
 
     if( !m_device.isEmpty() )
         url.addQueryItem( "device", m_device );
@@ -346,10 +348,32 @@ AudioCdCollection::checkForStartPlayRequest()
     }
 }
 
+
+QString
+AudioCdCollection::trackBaseFileName( int i ) const
+{
+    return QString( "Track%1" ).arg( i, 2, 10, QChar('0') );
+}
+
+
+QString
+AudioCdCollection::trackWavFileName( int i ) const
+{
+    return trackBaseFileName( i ) + ".wav";
+}
+
+
+QString
+AudioCdCollection::trackDisplayName( int i ) const
+{
+    return i18n( "Track" ) + ' ' + QString::number( i );
+}
+
+
 qint64
-AudioCdCollection::trackLength(int i) const
+AudioCdCollection::trackLength( int i ) const
 {
-    KUrl kioUrl = audiocdUrl( QString("Track%1.wav").arg(i, 2, 10, QChar('0') ) );
+    KUrl kioUrl = audiocdUrl( trackWavFileName( i ) );
     KIO::UDSEntry uds;
     if ( KIO::NetAccess::stat(kioUrl, uds, NULL) )
     {
@@ -480,19 +504,21 @@ AudioCdCollection::noInfoAvailable()
 
 
     int i = 1;
-    QString prefix( "0" );
-    QString trackName = "Track " + prefix + QString::number( i );
+    QString trackWav = trackWavFileName( i );
 
-    while( KIO::NetAccess::exists( QString( "audiocd:/" + trackName + ".wav" ), KIO::NetAccess::SourceSide, 0 ) )
+    // This will find also data tracks on mixed CDs:
+    // a better way to discover the available audio tracks should be found
+    while( KIO::NetAccess::exists( audiocdUrl( trackWav ), KIO::NetAccess::SourceSide, 0 ) )
     {
-        debug() << "got track: " << "audiocd:/" + trackName + ".wav";
+        debug() << "got track url: " << audiocdUrl( trackWav );
 
-        QString baseUrl = "audiocd:/" + m_discCddbId + '/' + QString::number( i );
+        //we hack the url so the engine controller knows what track on the CD to play..
+        KUrl baseUrl = audiocdUrl( m_discCddbId + '/' + QString::number( i ) );
 
-        Meta::AudioCdTrackPtr trackPtr = Meta::AudioCdTrackPtr( new Meta::AudioCdTrack( this, trackName, baseUrl ) );
+        Meta::AudioCdTrackPtr trackPtr = Meta::AudioCdTrackPtr( new Meta::AudioCdTrack( this, trackDisplayName( i ), baseUrl ) );
 
         trackPtr->setTrackNumber( i );
-        trackPtr->setFileNameBase( trackName );
+        trackPtr->setFileNameBase( trackBaseFileName( i ) );
         trackPtr->setLength( trackLength( i ) );
 
         memoryCollection()->addTrack( Meta::TrackPtr::staticCast( trackPtr ) );
@@ -513,8 +539,7 @@ AudioCdCollection::noInfoAvailable()
         trackPtr->setYear( yearPtr );
 
         i++;
-        prefix = i < 10 ? "0" : "";
-        trackName = "Track " + prefix + QString::number( i );
+        trackWav = trackWavFileName( i );
     }
 
     updateProxyTracks();
diff --git a/src/core-impl/collections/audiocd/AudioCdCollection.h b/src/core-impl/collections/audiocd/AudioCdCollection.h
index dc2cad7..e829368 100644
--- a/src/core-impl/collections/audiocd/AudioCdCollection.h
+++ b/src/core-impl/collections/audiocd/AudioCdCollection.h
@@ -103,6 +103,13 @@ private:
 
     // Helper function to build the audiocd url.
     KUrl audiocdUrl( const QString &path = "" ) const;
+    // The file name of the track without extension
+    QString trackBaseFileName( int i ) const;
+    // The file name of the track in .wav format
+    QString trackWavFileName( int i ) const;
+    // The name of the track that should be displayed
+    QString trackDisplayName( int i ) const;
+    // The length of the track in milliseconds
     qint64 trackLength( int i ) const;
 
     /**
-- 
2.7.4