Commit 0b979bb9 authored by Matěj Laitl's avatar Matěj Laitl
Browse files

Always use nonnegative position in Playlist::notifyObserversTrackAdded()

This was the cause of bug 293295. Thanks to Marius for spotting and
reporting it.

BUGFIXES:
 * Don't misbehave when track is dropped directly to saved playlist.

BUG: 293295
FIXED-IN: 2.6
parent ec41a526
......@@ -38,6 +38,7 @@ Version 2.6-Beta 1
"1.2 GB free" is shown instead of "85% used"; thicker capacity bar.
BUGFIXES:
* Don't misbehave when track is dropped directly to saved playlist. (BR 293295)
* Don't report collection of USB Mass Storage tracks as None.
* When adding, changing and removing tracks in USB Mass Storage collection,
actually update the user interface to show it.
......
......@@ -498,7 +498,7 @@ PlaylistBrowserModel::dropMimeData( const QMimeData *data, Qt::DropAction action
return false;
foreach( Meta::TrackPtr track, tracks )
playlist->addTrack( track, row++ );
playlist->addTrack( track, ( row >= 0 ) ? row++ : -1 ); // increment only if positive
return true;
}
......
......@@ -145,8 +145,14 @@ namespace Playlists
virtual void setGroups( const QStringList &groups ) { Q_UNUSED(groups) }
protected:
/**
* Implementations must call this when a track is added to playlist
*
* @param position is the actual new position of the added track, never negative
*/
inline void notifyObserversTrackAdded( Meta::TrackPtr track, int position )
{
Q_ASSERT( position >= 0 ); // notice bug 293295 early
foreach( Playlists::PlaylistObserver *observer, m_observers )
{
if( m_observers.contains( observer ) ) // guard against observers removing themselves in destructors
......@@ -154,6 +160,11 @@ namespace Playlists
}
}
/**
* Implementations must call this when a track is added to playlist
*
* @param position is the position where the track was before removal
*/
inline void notifyObserversTrackRemoved( int position )
{
foreach( Playlists::PlaylistObserver *observer, m_observers )
......
......@@ -251,9 +251,12 @@ SqlPlaylist::addTrack( Meta::TrackPtr track, int position )
if( !m_tracksLoaded )
loadTracks();
int insertAt = (position == -1) ? m_tracks.count() : position;
if( position < 0 )
position = m_tracks.count();
else
position = qMin( position, m_tracks.count() );
subscribeTo( track ); //keep track of metadata changes.
m_tracks.insert( insertAt, track );
m_tracks.insert( position, track );
saveToDb( true );
notifyObserversTrackAdded( track, position );
}
......
Supports Markdown
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