Commit 0e07efe5 authored by Alex Merry's avatar Alex Merry
Browse files

Play the correct track when inserting tracks into a sorted playlist

When Playlist::Controller::insertOptioned() is told to play the track
that has been inserted, it previously failed to account for the
relocation of the tracks when inserted into a sorted list.  The last
track in the list would end up being played, rather than the first
inserted track.

BUG: 244595
FIXED-IN: 2.6
parent 9ee51016
......@@ -140,8 +140,9 @@ Playlist::Controller::insertOptioned( Meta::TrackList list, int options )
//make sure that we turn off dynamic mode.
Amarok::actionCollection()->action( "disable_dynamic" )->trigger();
topModelInsertRow = 0;
insertionHelper( insertionTopRowToBottom( topModelInsertRow ), list );
int bottomModelInsertRow = insertionTopRowToBottom( 0 );
insertionHelper( bottomModelInsertRow, list );
topModelInsertRow = m_topModel->rowFromBottomModel( bottomModelInsertRow );
m_undoStack->endMacro();
visibleInsertedRowCount = m_topModel->qaim()->rowCount(); // simple
}
......@@ -157,6 +158,7 @@ Playlist::Controller::insertOptioned( Meta::TrackList list, int options )
int bottomModelInsertRow = insertionTopRowToBottom( topModelInsertRow );
insertionHelper( bottomModelInsertRow, list );
topModelInsertRow = m_topModel->rowFromBottomModel( bottomModelInsertRow );
visibleInsertedRowCount = m_topModel->qaim()->rowCount() - oldVisibleRowCount;
// Construct list of rows to be queued
......@@ -177,7 +179,9 @@ Playlist::Controller::insertOptioned( Meta::TrackList list, int options )
int oldVisibleRowCount = m_topModel->qaim()->rowCount();
topModelInsertRow = m_topModel->qaim()->rowCount();
insertionHelper( insertionTopRowToBottom( topModelInsertRow ), list );
int bottomModelInsertRow = insertionTopRowToBottom( topModelInsertRow );
insertionHelper( bottomModelInsertRow, list );
topModelInsertRow = m_topModel->rowFromBottomModel( bottomModelInsertRow );
visibleInsertedRowCount = m_topModel->qaim()->rowCount() - oldVisibleRowCount;
}
......
......@@ -80,6 +80,7 @@ class AMAROK_EXPORT Model : public QAbstractListModel, public Meta::Observer, pu
quint64 idAt( const int row ) const;
bool rowExists( int row ) const { return (( row >= 0 ) && ( row < m_items.size() ) ); }
int rowForId( const quint64 id ) const; // returns -1 if the id is invalid
int rowFromBottomModel( const int row ) { return row; }
int rowToBottomModel( const int row ) { return row; }
void setActiveId( const quint64 id ) { setActiveRow( rowForId( id ) ); }
void setActiveRow( int row );
......
......@@ -214,6 +214,13 @@ public:
*/
virtual int rowForId( const quint64 id ) const = 0;
/**
* Returns the row number of a track given the row number in the bottom model.
* @param row the row in the bottom model.
* @return the row in a proxy model
*/
virtual int rowFromBottomModel( const int row ) = 0;
/**
* Returns the row number of a track in terms of the bottom model.
* @param row the row in a proxy model
......
......@@ -187,6 +187,12 @@ ProxyBase::rowForId( const quint64 id ) const
return rowFromSource( m_belowModel->rowForId( id ) );
}
int
ProxyBase::rowFromBottomModel( const int row )
{
return rowFromSource( m_belowModel->rowFromBottomModel( row ) );
}
int
ProxyBase::rowToBottomModel( const int row )
{
......
......@@ -65,6 +65,7 @@ public:
virtual quint64 idAt( const int row ) const;
virtual bool rowExists( int row ) const;
virtual int rowForId( const quint64 id ) const;
virtual int rowFromBottomModel( const int rowInBase );
virtual int rowToBottomModel( const int rowInProxy );
virtual void setActiveId( const quint64 id );
virtual void setActiveRow( int row );
......
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