Commit aaff3348 authored by Stefano Pettini's avatar Stefano Pettini Committed by Heiko Becker
Browse files

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
parent f6ec3098
......@@ -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();
......
......@@ -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;
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment