Skip to content

Commit

Permalink
Don't update playlist if no tracks have changed
Browse files Browse the repository at this point in the history
  • Loading branch information
lfranchi committed Mar 5, 2012
1 parent 6b68598 commit 292d8c9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/libtomahawk/playlist/XspfUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ XspfUpdater::playlistLoaded()
foreach ( const plentry_ptr ple, playlist()->entries() )
tracks << ple->query();

QList< query_ptr > mergedTracks = TomahawkUtils::mergePlaylistChanges( tracks, loader->entries() );
bool changed = false;
QList< query_ptr > mergedTracks = TomahawkUtils::mergePlaylistChanges( tracks, loader->entries(), changed );

if ( !changed )
return;

QList<Tomahawk::plentry_ptr> el = playlist()->entriesFromQueries( mergedTracks, true );
playlist()->createNewRevision( uuid(), playlist()->currentrevision(), el );
Expand Down
6 changes: 5 additions & 1 deletion src/libtomahawk/playlist/customplaylistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ CustomPlaylistView::generateTracks()
void
CustomPlaylistView::tracksGenerated( QList< query_ptr > tracks )
{
QList< query_ptr > newTracks = TomahawkUtils::mergePlaylistChanges( m_model->queries(), tracks );
bool changed = false;
QList< query_ptr > newTracks = TomahawkUtils::mergePlaylistChanges( m_model->queries(), tracks, changed);

if ( !changed )
return;

m_model->clear();
m_model->append( newTracks );
Expand Down
5 changes: 4 additions & 1 deletion src/libtomahawk/utils/tomahawkutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,12 @@ newerVersion( const QString& oldVersion, const QString& newVersion )


QList< Tomahawk::query_ptr >
mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tomahawk::query_ptr >& newTracks )
mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tomahawk::query_ptr >& newTracks, bool& changed )
{
int sameCount = 0;
QList< Tomahawk::query_ptr > tosave = newTracks;
changed = false;

foreach ( const Tomahawk::query_ptr& newquery, newTracks )
{
foreach ( const Tomahawk::query_ptr& oldq, orig )
Expand All @@ -558,6 +560,7 @@ mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tom
if ( orig.size() == newTracks.size() && sameCount == orig.size() )
return orig;

changed = true;
return tosave;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libtomahawk/utils/tomahawkutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace TomahawkUtils
*
* \return true if some changes were made, false if the new tracks are the same as the current tracks in \param orig
*/
DLLEXPORT QList< Tomahawk::query_ptr > mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tomahawk::query_ptr >& newTracks );
DLLEXPORT QList< Tomahawk::query_ptr > mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tomahawk::query_ptr >& newTracks, bool& changed );

DLLEXPORT void crash();
}
Expand Down

0 comments on commit 292d8c9

Please sign in to comment.