File Fix-for-infinite-loop-with-some-Audio-CDs.patch of Package amarok

From: Stefano Pettini <stefano.pettini@gmail.com>
Date: Fri, 25 Mar 2016 09:15:18 +0000
Subject: Fix for the infinite loop in case a home-burned or old audio CD is inserted
X-Git-Url: http://quickgit.kde.org/?p=amarok.git&a=commitdiff&h=aaff3348862a1999069feff93d9e1e4d995b7225
---
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
---


--- a/src/core-impl/collections/audiocd/AudioCdCollection.cpp
+++ b/src/core-impl/collections/audiocd/AudioCdCollection.cpp
@@ -91,7 +91,9 @@
 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 @@
     }
 }
 
+
+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
-{
-    KUrl kioUrl = audiocdUrl( QString("Track%1.wav").arg(i, 2, 10, QChar('0') ) );
+AudioCdCollection::trackLength( int i ) const
+{
+    KUrl kioUrl = audiocdUrl( trackWavFileName( i ) );
     KIO::UDSEntry uds;
     if ( KIO::NetAccess::stat(kioUrl, uds, NULL) )
     {
@@ -480,19 +504,21 @@
 
 
     int i = 1;
-    QString prefix( "0" );
-    QString trackName = "Track " + prefix + QString::number( i );
-
-    while( KIO::NetAccess::exists( QString( "audiocd:/" + trackName + ".wav" ), KIO::NetAccess::SourceSide, 0 ) )
-    {
-        debug() << "got track: " << "audiocd:/" + trackName + ".wav";
-
-        QString baseUrl = "audiocd:/" + m_discCddbId + '/' + QString::number( i );
-
-        Meta::AudioCdTrackPtr trackPtr = Meta::AudioCdTrackPtr( new Meta::AudioCdTrack( this, trackName, baseUrl ) );
+    QString trackWav = trackWavFileName( i );
+
+    // 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 url: " << audiocdUrl( trackWav );
+
+        //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, 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 @@
         trackPtr->setYear( yearPtr );
 
         i++;
-        prefix = i < 10 ? "0" : "";
-        trackName = "Track " + prefix + QString::number( i );
+        trackWav = trackWavFileName( i );
     }
 
     updateProxyTracks();

--- a/src/core-impl/collections/audiocd/AudioCdCollection.h
+++ b/src/core-impl/collections/audiocd/AudioCdCollection.h
@@ -103,6 +103,13 @@
 
     // 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;
 
     /**

openSUSE Build Service is sponsored by