From kde-commits Thu Oct 18 05:19:37 2007 From: Dan Meltzer Date: Thu, 18 Oct 2007 05:19:37 +0000 To: kde-commits Subject: extragear/multimedia/amarok/src Message-Id: <1192684777.096911.12898.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=119268479402703 SVN commit 726583 by dmeltzer: Sort tracks when they are added to the playlist as well. This could possibly cause problems if the user does not want them sorted by track number on insertion, but I'm not sure if that would ever be the case M +2 -0 collectionbrowser/CollectionTreeView.cpp M +1 -1 meta/MetaUtility.cpp M +26 -15 playlist/PlaylistModel.cpp M +8 -1 playlist/PlaylistModel.h --- trunk/extragear/multimedia/amarok/src/collectionbrowser/CollectionTreeView.cpp #726582:726583 @@ -12,6 +12,7 @@ #include "debug.h" #include "collectionbrowser/CollectionTreeItemModel.h" #include "context/ContextView.h" +#include "playlist/PlaylistModel.h" #include "querybuilder.h" #include "TheInstances.h" @@ -250,6 +251,7 @@ else { Meta::TrackList tracks = item->descendentTracks(); + qStableSort( tracks.begin(), tracks.end(), Amarok::trackNumberLessThan); The::playlistModel()->insertOptioned( tracks, insertMode ); } } --- trunk/extragear/multimedia/amarok/src/meta/MetaUtility.cpp #726582:726583 @@ -79,7 +79,7 @@ if( !ec || !ec->isEditable() ) return; ec->beginMetaDataUpdate(); - QString title = metadata.contains( Meta::Field::TITLE ) ? + QString title = metadata.contains( Meta::Field::TITLE ) ? metadata.value( Meta::Field::TITLE ).toString() : QString(); ec->setTitle( title ); --- trunk/extragear/multimedia/amarok/src/playlist/PlaylistModel.cpp #726582:726583 @@ -37,6 +37,15 @@ using namespace Playlist; using namespace Meta; +namespace Amarok +{ + // Sorting of a tracklist. + bool trackNumberLessThan( Meta::TrackPtr left, Meta::TrackPtr right ) + { + return left->trackNumber() < right->trackNumber(); + } +} + Model *Model::s_instance = 0; Model::Model( QObject* parent ) @@ -126,7 +135,7 @@ AlbumGroup * albumGroup = m_albumGroups.value( track->album() ); return albumGroup->elementsInGroup( row ); - + } else if( role == Qt::DisplayRole && row != -1 ) { switch ( index.column() ) { @@ -722,15 +731,17 @@ void Model::newResultReady( const QString &collectionId, const Meta::TrackList &tracks ) //Slot { + Meta::TrackList ourTracks = tracks; + qStableSort( ourTracks.begin(), ourTracks.end(), Amarok::trackNumberLessThan ); Q_UNUSED( collectionId ) QueryMaker *qm = dynamic_cast( sender() ); if( qm ) { //requires better handling of queries which return multiple results if( m_queryMap.contains( qm ) ) - insertTracks( m_queryMap.value( qm ), tracks ); + insertTracks( m_queryMap.value( qm ), ourTracks ); else if( m_optionedQueryMap.contains( qm ) ) - insertOptioned( tracks, m_optionedQueryMap.value( qm ) ); + insertOptioned( ourTracks, m_optionedQueryMap.value( qm ) ); } } @@ -800,40 +811,40 @@ bool removeGroupBelowLastRow = false; int temp = group->firstInGroup( aboveFirst ); - if ( temp != -1 ) { + if ( temp != -1 ) { //debug() << "--3"; area1Start = temp; removeGroupAboveFirstRow = true; } temp = group->lastInGroup( firstRow + 1 ); - if ( temp != -1 ) { + if ( temp != -1 ) { //debug() << "--4"; area1End = temp; removeGroupBelowFirstRow = true; } temp = group->firstInGroup( lastRow - 1 ); - if ( temp != -1 ) { + if ( temp != -1 ) { //debug() << "--5"; area2Start = temp; removeGroupAboveLastRow = true; } temp = group->lastInGroup( belowLast ); - if ( temp != -1 ) { + if ( temp != -1 ) { //debug() << "--6"; area2End = temp; removeGroupBelowLastRow = true; } - if ( removeGroupAboveFirstRow ) + if ( removeGroupAboveFirstRow ) { group->removeGroup( aboveFirst ); /*debug() << "removing group at row: " << aboveFirst;*/ } - + if ( removeGroupBelowFirstRow ) { group->removeGroup( firstRow + 1 ); /*debug() << "removing group at row: " << firstRow + 1;*/ } - if ( removeGroupAboveLastRow ) + if ( removeGroupAboveLastRow ) { group->removeGroup( lastRow -1 ); /*debug() << "removing group at row: " << lastRow - 1;*/ } if ( removeGroupBelowLastRow ) { group->removeGroup( belowLast ); /*debug() << "removing group at row: " << belowLast;*/ } @@ -846,11 +857,11 @@ if ( group->subgroupCount() == 0 ) { //debug() << "empty..."; delete m_albumGroups.take( itt.key() ); - + } - + } if ( m_albumGroups.count() == 0 ) { // start from scratch @@ -858,7 +869,7 @@ area1Start = 0; area1End = m_items.count(); area2Start = area1Start; // just to skip second pass - + } @@ -891,8 +902,8 @@ area1Start = QMIN( area1Start, area2Start ); area2Start = area1Start; } - + //debug() << "area1Start: " << area1Start << ", area1End: " << area1End; //debug() << "area2Start: " << area2Start << ", area2End: " << area2End; @@ -957,7 +968,7 @@ //make sure that a group containg playing track is expanded - if ( m_activeRow != -1 ){ + if ( m_activeRow != -1 ){ if ( m_albumGroups.contains( m_items[ m_activeRow ]->track()->album() ) ) { m_albumGroups[ m_items[ m_activeRow ]->track()->album() ]->setCollapsed( m_activeRow, false ); debug() << "Here"; --- trunk/extragear/multimedia/amarok/src/playlist/PlaylistModel.h #726582:726583 @@ -29,6 +29,13 @@ class QueryMaker; class QUndoStack; +namespace Amarok +{ + // Sorting of a tracklist. + bool trackNumberLessThan( Meta::TrackPtr left, Meta::TrackPtr right ); +} + + namespace Playlist { class TrackNavigator; @@ -199,7 +206,7 @@ Meta::TrackList removeRowsCommand( int position, int rows ); /** - * This Method regroups albums between two modified rows. It also modifies adjacant groups ans needed, so tha + * This Method regroups albums between two modified rows. It also modifies adjacant groups ans needed, so tha * actual affected area can be somewhat larger than that specified by the two rows. */ void regroupAlbums( int firstRow, int lastRow );