1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 02:09:48 +01:00

notifications for track moved

This commit is contained in:
Leo Franchi 2012-04-13 23:06:39 -04:00
parent 8069baf911
commit b7b5e60f98
4 changed files with 45 additions and 1 deletions

View File

@ -85,6 +85,7 @@ SpotifyPlaylistUpdater::init()
connect( playlist().data(), SIGNAL( tracksInserted( QList<Tomahawk::plentry_ptr>, int ) ), this, SLOT( tomahawkTracksInserted( QList<Tomahawk::plentry_ptr>, int ) ) );
connect( playlist().data(), SIGNAL( tracksRemoved( QList<Tomahawk::query_ptr> ) ), this, SLOT( tomahawkTracksRemoved( QList<Tomahawk::query_ptr> ) ) );
connect( playlist().data(), SIGNAL( tracksMoved( QList<Tomahawk::plentry_ptr>, int ) ), this, SLOT( tomahawkTracksMoved( QList<Tomahawk::plentry_ptr>, int ) ) );
connect( playlist().data(), SIGNAL( renamed( QString, QString ) ), this, SLOT( tomahawkPlaylistRenamed( QString, QString ) ) );
connect( playlist().data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistRevisionLoaded() ), Qt::QueuedConnection ); // Queued so that in playlist.cpp:443 we let the playlist clear its own queue first
// TODO reorders in a playlist
@ -554,6 +555,17 @@ SpotifyPlaylistUpdater::onTracksRemovedReturn( const QString& msgType, const QVa
}
void
SpotifyPlaylistUpdater::tomahawkTracksMoved( const QList< plentry_ptr >& tracks, int position )
{
qDebug() << Q_FUNC_INFO << "Got tracks moved at position:" << position;
foreach ( const plentry_ptr ple, tracks )
{
qDebug() << ple->query()->track() << ple->query()->artist();
}
}
QVariantList
SpotifyPlaylistUpdater::queriesToVariant( const QList< query_ptr >& queries )
{

View File

@ -69,6 +69,7 @@ protected:
private slots:
void tomahawkTracksInserted( const QList<Tomahawk::plentry_ptr>& ,int );
void tomahawkTracksRemoved( const QList<Tomahawk::query_ptr>& );
void tomahawkTracksMoved( const QList<Tomahawk::plentry_ptr>& ,int );
void tomahawkPlaylistRenamed( const QString&, const QString& );
// SpotifyResolver message handlers, all take msgtype, msg as argument
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg );

View File

@ -220,6 +220,10 @@ signals:
/// Notification for tracks being removed from playlist
void tracksRemoved( const QList< Tomahawk::query_ptr >& tracks );
/// Notification for tracks being moved in a playlist. List is of new tracks, and new position of first track
/// Contiguous range from startPosition
void tracksMoved( const QList< Tomahawk::plentry_ptr >& tracks, int startPosition );
public slots:
// want to update the playlist from the model?
// generate a newrev using uuid() and call this:

View File

@ -428,7 +428,34 @@ PlaylistModel::endPlaylistChanges()
m_playlist->createNewRevision( newrev, m_playlist->currentrevision(), l );
}
if ( m_savedInsertPos >= 0 )
if ( m_savedInsertPos >= 0 && !m_savedInsertTracks.isEmpty() &&
!m_savedRemoveTracks.isEmpty() )
{
// If we have *both* an insert and remove, then it's a move action
// However, since we got the insert before the remove (Qt...), the index we have as the saved
// insert position is no longer valid. Find the proper one by finding the location of the first inserted
// track
for ( int i = 0; i < rowCount( QModelIndex() ); i++ )
{
const QModelIndex idx = index( i, 0, QModelIndex() );
if ( !idx.isValid() )
continue;
const TrackModelItem* item = itemFromIndex( idx );
if ( !item || item->entry().isNull() )
continue;
if ( item->entry() == m_savedInsertTracks.first() )
{
// Found our index
emit m_playlist->tracksMoved( m_savedInsertTracks, i );
break;
}
}
m_savedInsertPos = -1;
m_savedInsertTracks.clear();
m_savedRemoveTracks.clear();
}
else if ( m_savedInsertPos >= 0 )
{
emit m_playlist->tracksInserted( m_savedInsertTracks, m_savedInsertPos );
m_savedInsertPos = -1;