mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
* Refactored Track-, Collection-, PlaylistModel.
This commit is contained in:
@@ -108,6 +108,7 @@ public:
|
|||||||
|
|
||||||
static bool canParseSpotifyPlaylists() { return s_canParseSpotifyPlaylists; }
|
static bool canParseSpotifyPlaylists() { return s_canParseSpotifyPlaylists; }
|
||||||
static void setCanParseSpotifyPlaylists( bool parseable ) { s_canParseSpotifyPlaylists = parseable; }
|
static void setCanParseSpotifyPlaylists( bool parseable ) { s_canParseSpotifyPlaylists = parseable; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/// QMimeData parsing results
|
/// QMimeData parsing results
|
||||||
void tracks( const QList< Tomahawk::query_ptr >& tracks );
|
void tracks( const QList< Tomahawk::query_ptr >& tracks );
|
||||||
|
@@ -293,7 +293,7 @@ Playlist::loadRevision( const QString& rev )
|
|||||||
void
|
void
|
||||||
Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const QList< plentry_ptr >& entries )
|
Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const QList< plentry_ptr >& entries )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << newrev << oldrev << entries.count();
|
tDebug() << Q_FUNC_INFO << newrev << oldrev << entries.count();
|
||||||
|
|
||||||
if ( busy() )
|
if ( busy() )
|
||||||
{
|
{
|
||||||
@@ -387,8 +387,6 @@ Playlist::setNewRevision( const QString& rev,
|
|||||||
bool is_newest_rev,
|
bool is_newest_rev,
|
||||||
const QMap< QString, Tomahawk::plentry_ptr >& addedmap )
|
const QMap< QString, Tomahawk::plentry_ptr >& addedmap )
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO << rev << is_newest_rev << m_title << addedmap.count() << neworderedguids.count() << oldorderedguids.count();
|
|
||||||
|
|
||||||
// build up correctly ordered new list of plentry_ptrs from
|
// build up correctly ordered new list of plentry_ptrs from
|
||||||
// existing ones, and the ones that have been added
|
// existing ones, and the ones that have been added
|
||||||
QMap<QString, plentry_ptr> entriesmap;
|
QMap<QString, plentry_ptr> entriesmap;
|
||||||
@@ -410,11 +408,11 @@ Playlist::setNewRevision( const QString& rev,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* qDebug() << "id:" << id;
|
tDebug() << "id:" << id;
|
||||||
* qDebug() << "newordered:" << neworderedguids.count() << neworderedguids;
|
tDebug() << "newordered:" << neworderedguids.count() << neworderedguids;
|
||||||
* qDebug() << "entriesmap:" << entriesmap.count() << entriesmap;
|
tDebug() << "entriesmap:" << entriesmap.count() << entriesmap;
|
||||||
* qDebug() << "addedmap:" << addedmap.count() << addedmap;
|
tDebug() << "addedmap:" << addedmap.count() << addedmap;
|
||||||
* qDebug() << "m_entries" << m_entries; */
|
tDebug() << "m_entries" << m_entries;
|
||||||
|
|
||||||
tLog() << "Playlist error for playlist with guid" << guid() << "from source" << author()->friendlyName();
|
tLog() << "Playlist error for playlist with guid" << guid() << "from source" << author()->friendlyName();
|
||||||
Q_ASSERT( false ); // XXX
|
Q_ASSERT( false ); // XXX
|
||||||
@@ -452,8 +450,8 @@ Playlist::setNewRevision( const QString& rev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pr.added = addedmap.values();
|
pr.added = addedmap.values();
|
||||||
|
|
||||||
pr.newlist = entries;
|
pr.newlist = entries;
|
||||||
|
|
||||||
return pr;
|
return pr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,9 +18,6 @@
|
|||||||
|
|
||||||
#include "collectionflatmodel.h"
|
#include "collectionflatmodel.h"
|
||||||
|
|
||||||
#include <QMimeData>
|
|
||||||
#include <QTreeView>
|
|
||||||
|
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "sourcelist.h"
|
#include "sourcelist.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
@@ -31,9 +28,6 @@ using namespace Tomahawk;
|
|||||||
CollectionFlatModel::CollectionFlatModel( QObject* parent )
|
CollectionFlatModel::CollectionFlatModel( QObject* parent )
|
||||||
: TrackModel( parent )
|
: TrackModel( parent )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceOffline( Tomahawk::source_ptr ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +39,6 @@ CollectionFlatModel::~CollectionFlatModel()
|
|||||||
void
|
void
|
||||||
CollectionFlatModel::addCollections( const QList< collection_ptr >& collections )
|
CollectionFlatModel::addCollections( const QList< collection_ptr >& collections )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Adding collections!";
|
|
||||||
foreach( const collection_ptr& col, collections )
|
foreach( const collection_ptr& col, collections )
|
||||||
{
|
{
|
||||||
addCollection( col );
|
addCollection( col );
|
||||||
@@ -64,11 +57,6 @@ CollectionFlatModel::addCollection( const collection_ptr& collection, bool sendN
|
|||||||
<< collection->source()->id()
|
<< collection->source()->id()
|
||||||
<< collection->source()->userName();
|
<< collection->source()->userName();
|
||||||
|
|
||||||
connect( collection.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
|
||||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
|
||||||
connect( collection.data(), SIGNAL( tracksRemoved( QList<Tomahawk::query_ptr> ) ),
|
|
||||||
SLOT( onTracksRemoved( QList<Tomahawk::query_ptr> ) ) );
|
|
||||||
|
|
||||||
if ( sendNotifications )
|
if ( sendNotifications )
|
||||||
emit loadingStarted();
|
emit loadingStarted();
|
||||||
|
|
||||||
@@ -107,76 +95,6 @@ CollectionFlatModel::addFilteredCollection( const collection_ptr& collection, un
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
CollectionFlatModel::removeCollection( const collection_ptr& collection )
|
|
||||||
{
|
|
||||||
return; // FIXME
|
|
||||||
|
|
||||||
disconnect( collection.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
|
||||||
this, SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
|
||||||
|
|
||||||
QTime timer;
|
|
||||||
timer.start();
|
|
||||||
|
|
||||||
// QList<TrackModelItem*> plitems = m_collectionIndex.values( collection );
|
|
||||||
QList< QPair< int, int > > rows;
|
|
||||||
QList< QPair< int, int > > sortrows;
|
|
||||||
QPair< int, int > row;
|
|
||||||
QPair< int, int > rowf;
|
|
||||||
rows = m_collectionRows.values( collection );
|
|
||||||
|
|
||||||
while ( rows.count() )
|
|
||||||
{
|
|
||||||
int x = -1;
|
|
||||||
int j = 0;
|
|
||||||
foreach( row, rows )
|
|
||||||
{
|
|
||||||
if ( x < 0 || row.first > rows.at( x ).first )
|
|
||||||
x = j;
|
|
||||||
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
|
|
||||||
sortrows.append( rows.at( x ) );
|
|
||||||
rows.removeAt( x );
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach( row, sortrows )
|
|
||||||
{
|
|
||||||
QMap< Tomahawk::collection_ptr, QPair< int, int > > newrows;
|
|
||||||
foreach ( const collection_ptr& col, m_collectionRows.uniqueKeys() )
|
|
||||||
{
|
|
||||||
if ( col.data() == collection.data() )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach ( rowf, m_collectionRows.values( col ) )
|
|
||||||
{
|
|
||||||
if ( rowf.first > row.first )
|
|
||||||
{
|
|
||||||
rowf.first -= ( row.second - row.first ) + 1;
|
|
||||||
rowf.second -= ( row.second - row.first ) + 1;
|
|
||||||
}
|
|
||||||
newrows.insertMulti( col, rowf );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_collectionRows = newrows;
|
|
||||||
|
|
||||||
qDebug() << "Removing rows:" << row.first << row.second;
|
|
||||||
emit beginRemoveRows( QModelIndex(), row.first, row.second );
|
|
||||||
for ( int i = row.second; i >= row.first; i-- )
|
|
||||||
{
|
|
||||||
TrackModelItem* item = itemFromIndex( index( i, 0, QModelIndex() ) );
|
|
||||||
delete item;
|
|
||||||
}
|
|
||||||
emit endRemoveRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "Collection removed, time elapsed:" << timer.elapsed();
|
|
||||||
|
|
||||||
// emit trackCountChanged( rowCount( QModelIndex() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
|
CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
|
||||||
{
|
{
|
||||||
@@ -188,62 +106,21 @@ CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
|
|||||||
m_loadingCollections.removeAll( qobject_cast< Collection* >( sender() ) );
|
m_loadingCollections.removeAll( qobject_cast< Collection* >( sender() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool kickOff = m_tracksToAdd.isEmpty();
|
append( tracks );
|
||||||
m_tracksToAdd << tracks;
|
|
||||||
|
|
||||||
emit trackCountChanged( trackCount() );
|
if ( m_loadingCollections.isEmpty() )
|
||||||
|
|
||||||
if ( m_tracksToAdd.count() && kickOff )
|
|
||||||
processTracksToAdd();
|
|
||||||
else if ( m_tracksToAdd.isEmpty() && m_loadingCollections.isEmpty() )
|
|
||||||
emit loadingFinished();
|
emit loadingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
CollectionFlatModel::processTracksToAdd()
|
|
||||||
{
|
|
||||||
int chunkSize = 5000;
|
|
||||||
int maxc = qMin( chunkSize, m_tracksToAdd.count() );
|
|
||||||
int c = rowCount( QModelIndex() );
|
|
||||||
|
|
||||||
emit beginInsertRows( QModelIndex(), c, c + maxc - 1 );
|
|
||||||
//beginResetModel();
|
|
||||||
|
|
||||||
TrackModelItem* plitem;
|
|
||||||
QList< Tomahawk::query_ptr >::iterator iter = m_tracksToAdd.begin();
|
|
||||||
|
|
||||||
for( int i = 0; i < maxc; ++i )
|
|
||||||
{
|
|
||||||
plitem = new TrackModelItem( *iter, m_rootItem );
|
|
||||||
plitem->index = createIndex( m_rootItem->children.count() - 1, 0, plitem );
|
|
||||||
|
|
||||||
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
|
||||||
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_tracksToAdd.erase( m_tracksToAdd.begin(), iter );
|
|
||||||
|
|
||||||
if ( m_tracksToAdd.isEmpty() && m_loadingCollections.isEmpty() )
|
|
||||||
emit loadingFinished();
|
|
||||||
|
|
||||||
//endResetModel();
|
|
||||||
emit endInsertRows();
|
|
||||||
qDebug() << Q_FUNC_INFO << rowCount( QModelIndex() );
|
|
||||||
|
|
||||||
if ( m_tracksToAdd.count() )
|
|
||||||
QTimer::singleShot( 250, this, SLOT( processTracksToAdd() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks )
|
CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks )
|
||||||
{
|
{
|
||||||
QList<Tomahawk::query_ptr> t = tracks;
|
QList<Tomahawk::query_ptr> t = tracks;
|
||||||
for ( int i = rowCount( QModelIndex() ); i >= 0 && t.count(); i-- )
|
for ( int i = rowCount( QModelIndex() ); i >= 0 && t.count(); i-- )
|
||||||
{
|
{
|
||||||
TrackModelItem* item = itemFromIndex( index( i, 0, QModelIndex() ) );
|
QModelIndex idx = index( i, 0, QModelIndex() );
|
||||||
|
TrackModelItem* item = itemFromIndex( idx );
|
||||||
if ( !item )
|
if ( !item )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -252,11 +129,7 @@ CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks )
|
|||||||
{
|
{
|
||||||
if ( item->query().data() == query.data() )
|
if ( item->query().data() == query.data() )
|
||||||
{
|
{
|
||||||
qDebug() << "Removing row:" << i << query->toString();
|
remove( idx );
|
||||||
emit beginRemoveRows( QModelIndex(), i, i );
|
|
||||||
delete item;
|
|
||||||
emit endRemoveRows();
|
|
||||||
|
|
||||||
t.removeAt( j );
|
t.removeAt( j );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -264,9 +137,6 @@ CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks )
|
|||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit trackCountChanged( rowCount( QModelIndex() ) );
|
|
||||||
qDebug() << Q_FUNC_INFO << rowCount( QModelIndex() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -274,20 +144,7 @@ void
|
|||||||
CollectionFlatModel::onDataChanged()
|
CollectionFlatModel::onDataChanged()
|
||||||
{
|
{
|
||||||
TrackModelItem* p = (TrackModelItem*)sender();
|
TrackModelItem* p = (TrackModelItem*)sender();
|
||||||
// emit itemSizeChanged( p->index );
|
|
||||||
|
|
||||||
if ( p )
|
if ( p )
|
||||||
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount( QModelIndex() ) - 1 ) );
|
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount( QModelIndex() ) - 1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
CollectionFlatModel::onSourceOffline( const Tomahawk::source_ptr& src )
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
if ( m_collectionRows.contains( src->collection() ) )
|
|
||||||
{
|
|
||||||
removeCollection( src->collection() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -46,16 +46,9 @@ public:
|
|||||||
virtual int trackCount() const { return rowCount( QModelIndex() ) + m_tracksToAdd.count(); }
|
virtual int trackCount() const { return rowCount( QModelIndex() ) + m_tracksToAdd.count(); }
|
||||||
|
|
||||||
void addCollections( const QList< Tomahawk::collection_ptr >& collections );
|
void addCollections( const QList< Tomahawk::collection_ptr >& collections );
|
||||||
|
|
||||||
void addCollection( const Tomahawk::collection_ptr& collection, bool sendNotifications = true );
|
void addCollection( const Tomahawk::collection_ptr& collection, bool sendNotifications = true );
|
||||||
void removeCollection( const Tomahawk::collection_ptr& collection );
|
|
||||||
|
|
||||||
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllTracks::SortOrder order );
|
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllTracks::SortOrder order );
|
||||||
|
|
||||||
virtual void append( const Tomahawk::query_ptr& /*query*/ ) {}
|
|
||||||
virtual void append( const Tomahawk::artist_ptr& /*artist*/ ) {}
|
|
||||||
virtual void append( const Tomahawk::album_ptr& /*album*/ ) {}
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||||
void shuffleModeChanged( bool enabled );
|
void shuffleModeChanged( bool enabled );
|
||||||
@@ -70,10 +63,6 @@ private slots:
|
|||||||
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
void onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks );
|
void onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
|
|
||||||
void onSourceOffline( const Tomahawk::source_ptr& src );
|
|
||||||
|
|
||||||
void processTracksToAdd();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap< Tomahawk::collection_ptr, QPair< int, int > > m_collectionRows;
|
QMap< Tomahawk::collection_ptr, QPair< int, int > > m_collectionRows;
|
||||||
QList<Tomahawk::query_ptr> m_tracksToAdd;
|
QList<Tomahawk::query_ptr> m_tracksToAdd;
|
||||||
|
@@ -313,9 +313,9 @@ DynamicModel::removeIndex(const QModelIndex& idx, bool moreToCome)
|
|||||||
if( !moreToCome && idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) ) { // if the user is manually removing the last one, re-add as we're a station
|
if( !moreToCome && idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) ) { // if the user is manually removing the last one, re-add as we're a station
|
||||||
newTrackLoading();
|
newTrackLoading();
|
||||||
}
|
}
|
||||||
TrackModel::removeIndex( idx );
|
TrackModel::remove( idx );
|
||||||
} else
|
} else
|
||||||
PlaylistModel::removeIndex( idx, moreToCome );
|
PlaylistModel::remove( idx, moreToCome );
|
||||||
// don't call onPlaylistChanged.
|
// don't call onPlaylistChanged.
|
||||||
|
|
||||||
if( !moreToCome )
|
if( !moreToCome )
|
||||||
|
@@ -264,7 +264,7 @@ DynamicView::collapseEntries( int startRow, int num, int numToKeep )
|
|||||||
todel << proxyModel()->index( startRow + i, k );
|
todel << proxyModel()->index( startRow + i, k );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proxyModel()->removeIndexes( todel );
|
proxyModel()->remove( todel );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -39,9 +39,8 @@ using namespace Tomahawk;
|
|||||||
PlaylistModel::PlaylistModel( QObject* parent )
|
PlaylistModel::PlaylistModel( QObject* parent )
|
||||||
: TrackModel( parent )
|
: TrackModel( parent )
|
||||||
, m_isTemporary( false )
|
, m_isTemporary( false )
|
||||||
|
, m_changesOngoing( false )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
m_dropStorage.parent = QPersistentModelIndex();
|
m_dropStorage.parent = QPersistentModelIndex();
|
||||||
m_dropStorage.row = -10;
|
m_dropStorage.row = -10;
|
||||||
|
|
||||||
@@ -54,34 +53,9 @@ PlaylistModel::~PlaylistModel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
PlaylistModel::columnCount( const QModelIndex& parent ) const
|
|
||||||
{
|
|
||||||
return TrackModel::columnCount( parent );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
|
||||||
PlaylistModel::data( const QModelIndex& index, int role ) const
|
|
||||||
{
|
|
||||||
return TrackModel::data( index, role );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
|
||||||
PlaylistModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
|
||||||
{
|
|
||||||
return TrackModel::headerData( section, orientation, role );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries )
|
PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries )
|
||||||
{
|
{
|
||||||
QString currentuuid;
|
|
||||||
if ( currentItem().isValid() )
|
|
||||||
currentuuid = itemFromIndex( currentItem() )->query()->id();
|
|
||||||
|
|
||||||
if ( !m_playlist.isNull() )
|
if ( !m_playlist.isNull() )
|
||||||
{
|
{
|
||||||
disconnect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) );
|
disconnect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) );
|
||||||
@@ -89,10 +63,8 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn
|
|||||||
disconnect( m_playlist.data(), SIGNAL( changed() ), this, SIGNAL( playlistChanged() ) );
|
disconnect( m_playlist.data(), SIGNAL( changed() ), this, SIGNAL( playlistChanged() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( rowCount( QModelIndex() ) && loadEntries )
|
if ( loadEntries )
|
||||||
{
|
|
||||||
clear();
|
clear();
|
||||||
}
|
|
||||||
|
|
||||||
m_playlist = playlist;
|
m_playlist = playlist;
|
||||||
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) );
|
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) );
|
||||||
@@ -109,45 +81,8 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn
|
|||||||
if ( !loadEntries )
|
if ( !loadEntries )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TrackModelItem* plitem;
|
|
||||||
QList<plentry_ptr> entries = playlist->entries();
|
QList<plentry_ptr> entries = playlist->entries();
|
||||||
if ( entries.count() )
|
append( entries );
|
||||||
{
|
|
||||||
int c = rowCount( QModelIndex() );
|
|
||||||
|
|
||||||
qDebug() << "Starting loading" << playlist->title();
|
|
||||||
emit beginInsertRows( QModelIndex(), c, c + entries.count() - 1 );
|
|
||||||
|
|
||||||
m_waitingForResolved.clear();
|
|
||||||
foreach( const plentry_ptr& entry, entries )
|
|
||||||
{
|
|
||||||
// qDebug() << entry->query()->toString();
|
|
||||||
plitem = new TrackModelItem( entry, m_rootItem );
|
|
||||||
plitem->index = createIndex( m_rootItem->children.count() - 1, 0, plitem );
|
|
||||||
|
|
||||||
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
|
||||||
|
|
||||||
if ( entry->query()->id() == currentuuid )
|
|
||||||
setCurrentItem( plitem->index );
|
|
||||||
|
|
||||||
if ( !entry->query()->resolvingFinished() && !entry->query()->playable() )
|
|
||||||
{
|
|
||||||
m_waitingForResolved.append( entry->query().data() );
|
|
||||||
connect( entry->query().data(), SIGNAL( resolvingFinished( bool ) ), SLOT( trackResolved( bool ) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
emit endInsertRows();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
qDebug() << "Playlist seems empty:" << playlist->title();
|
|
||||||
|
|
||||||
if ( !m_waitingForResolved.isEmpty() )
|
|
||||||
{
|
|
||||||
emit loadingStarted();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -165,7 +100,7 @@ PlaylistModel::loadHistory( const Tomahawk::source_ptr& source, unsigned int amo
|
|||||||
cmd->setLimit( amount );
|
cmd->setLimit( amount );
|
||||||
|
|
||||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
|
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
|
||||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
SLOT( append( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||||
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||||
}
|
}
|
||||||
@@ -174,22 +109,23 @@ PlaylistModel::loadHistory( const Tomahawk::source_ptr& source, unsigned int amo
|
|||||||
void
|
void
|
||||||
PlaylistModel::clear()
|
PlaylistModel::clear()
|
||||||
{
|
{
|
||||||
if ( rowCount( QModelIndex() ) )
|
TrackModel::clear();
|
||||||
{
|
|
||||||
emit loadingFinished();
|
|
||||||
|
|
||||||
emit beginResetModel();
|
m_waitingForResolved.clear();
|
||||||
delete m_rootItem;
|
|
||||||
m_rootItem = 0;
|
|
||||||
m_rootItem = new TrackModelItem( 0, this );
|
|
||||||
emit endResetModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::append( const QList< plentry_ptr >& entries )
|
||||||
|
{
|
||||||
|
insert( entries, rowCount( QModelIndex() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::append( const QList< query_ptr >& queries )
|
PlaylistModel::append( const QList< query_ptr >& queries )
|
||||||
{
|
{
|
||||||
onTracksAdded( queries );
|
insert( queries, rowCount( QModelIndex() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -199,13 +135,10 @@ PlaylistModel::append( const Tomahawk::query_ptr& query )
|
|||||||
if ( query.isNull() )
|
if ( query.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList< Tomahawk::query_ptr > ql;
|
|
||||||
ql << query;
|
|
||||||
|
|
||||||
if ( !query->resolvingFinished() )
|
if ( !query->resolvingFinished() )
|
||||||
Pipeline::instance()->resolve( query );
|
Pipeline::instance()->resolve( query );
|
||||||
|
|
||||||
onTracksAdded( ql );
|
TrackModel::append( query );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -225,7 +158,7 @@ PlaylistModel::append( const Tomahawk::album_ptr& album )
|
|||||||
m_isTemporary = true;
|
m_isTemporary = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onTracksAdded( album->tracks() );
|
append( album->tracks() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -245,20 +178,83 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist )
|
|||||||
m_isTemporary = true;
|
m_isTemporary = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onTracksAdded( artist->tracks() );
|
append( artist->tracks() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::insert( unsigned int row, const Tomahawk::query_ptr& query )
|
PlaylistModel::insert( const Tomahawk::query_ptr& query, int row )
|
||||||
{
|
{
|
||||||
if ( query.isNull() )
|
TrackModel::insert( query, row );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::insert( const QList< Tomahawk::query_ptr >& queries, int row )
|
||||||
|
{
|
||||||
|
if ( !queries.count() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList< Tomahawk::query_ptr > ql;
|
QList< Tomahawk::plentry_ptr > entries;
|
||||||
ql << query;
|
foreach( const query_ptr& query, queries )
|
||||||
|
{
|
||||||
|
plentry_ptr entry = plentry_ptr( new PlaylistEntry() );
|
||||||
|
|
||||||
onTracksInserted( row, ql );
|
if ( query->results().count() )
|
||||||
|
entry->setDuration( query->results().at( 0 )->duration() );
|
||||||
|
else
|
||||||
|
entry->setDuration( 0 );
|
||||||
|
|
||||||
|
entry->setLastmodified( 0 );
|
||||||
|
entry->setAnnotation( "" ); // FIXME
|
||||||
|
entry->setQuery( query );
|
||||||
|
entry->setGuid( uuid() );
|
||||||
|
|
||||||
|
entries << entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
insert( entries, row );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::insert( const QList< Tomahawk::plentry_ptr >& entries, int row )
|
||||||
|
{
|
||||||
|
if ( !entries.count() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int c = row;
|
||||||
|
QPair< int, int > crows;
|
||||||
|
crows.first = c;
|
||||||
|
crows.second = c + entries.count() - 1;
|
||||||
|
|
||||||
|
emit beginInsertRows( QModelIndex(), crows.first, crows.second );
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
TrackModelItem* plitem;
|
||||||
|
foreach( const plentry_ptr& entry, entries )
|
||||||
|
{
|
||||||
|
plitem = new TrackModelItem( entry, m_rootItem, row + i );
|
||||||
|
plitem->index = createIndex( row + i, 0, plitem );
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if ( entry->query()->id() == currentItemUuid() )
|
||||||
|
setCurrentItem( plitem->index );
|
||||||
|
|
||||||
|
if ( !entry->query()->resolvingFinished() && !entry->query()->playable() )
|
||||||
|
{
|
||||||
|
m_waitingForResolved.append( entry->query().data() );
|
||||||
|
connect( entry->query().data(), SIGNAL( resolvingFinished( bool ) ), SLOT( trackResolved( bool ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_waitingForResolved.isEmpty() )
|
||||||
|
emit loadingStarted();
|
||||||
|
|
||||||
|
emit endInsertRows();
|
||||||
|
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -282,53 +278,9 @@ PlaylistModel::trackResolved( bool )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PlaylistModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
|
|
||||||
{
|
|
||||||
onTracksInserted( rowCount( QModelIndex() ), tracks );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PlaylistModel::onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks )
|
|
||||||
{
|
|
||||||
if ( !tracks.count() )
|
|
||||||
{
|
|
||||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int c = row;
|
|
||||||
QPair< int, int > crows;
|
|
||||||
crows.first = c;
|
|
||||||
crows.second = c + tracks.count() - 1;
|
|
||||||
|
|
||||||
emit beginInsertRows( QModelIndex(), crows.first, crows.second );
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
TrackModelItem* plitem;
|
|
||||||
foreach( const query_ptr& query, tracks )
|
|
||||||
{
|
|
||||||
plentry_ptr entry = plentry_ptr( new PlaylistEntry() );
|
|
||||||
entry->setQuery( query );
|
|
||||||
|
|
||||||
plitem = new TrackModelItem( entry, m_rootItem, row + i );
|
|
||||||
plitem->index = createIndex( row + i, 0, plitem );
|
|
||||||
|
|
||||||
i++;
|
|
||||||
|
|
||||||
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
emit endInsertRows();
|
|
||||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::onDataChanged()
|
PlaylistModel::onDataChanged()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
TrackModelItem* p = (TrackModelItem*)sender();
|
TrackModelItem* p = (TrackModelItem*)sender();
|
||||||
if ( p && p->index.isValid() )
|
if ( p && p->index.isValid() )
|
||||||
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount() - 1 ) );
|
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount() - 1 ) );
|
||||||
@@ -385,13 +337,15 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
|
|||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
if ( !data->hasFormat( "application/tomahawk.playlist.id" ) ||
|
if ( !data->hasFormat( "application/tomahawk.playlist.id" ) ||
|
||||||
( !m_playlist.isNull() && data->data( "application/tomahawk.playlist.id" ) != m_playlist->guid() ) )
|
( !m_playlist.isNull() && data->data( "application/tomahawk.playlist.id" ) != m_playlist->guid() ) )
|
||||||
|
{
|
||||||
dj->setDropAction( DropJob::Append );
|
dj->setDropAction( DropJob::Append );
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if ( action & Qt::CopyAction )
|
if ( action & Qt::CopyAction )
|
||||||
dj->setDropAction( DropJob::Append );
|
dj->setDropAction( DropJob::Append );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
||||||
dj->tracksFromMimeData( data );
|
dj->tracksFromMimeData( data );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -412,44 +366,13 @@ PlaylistModel::parsedDroppedTracks( QList< query_ptr > tracks )
|
|||||||
else
|
else
|
||||||
beginRow = rowCount( QModelIndex() );
|
beginRow = rowCount( QModelIndex() );
|
||||||
|
|
||||||
// qDebug() << data->formats();
|
|
||||||
QString currentuuid;
|
|
||||||
if ( currentItem().isValid() )
|
|
||||||
currentuuid = itemFromIndex( currentItem() )->query()->id();
|
|
||||||
|
|
||||||
if ( tracks.count() )
|
if ( tracks.count() )
|
||||||
{
|
{
|
||||||
emit beginInsertRows( QModelIndex(), beginRow, beginRow + tracks.count() - 1 );
|
bool update = ( m_dropStorage.action & Qt::CopyAction || m_dropStorage.action & Qt::MoveAction );
|
||||||
foreach( const Tomahawk::query_ptr& query, tracks )
|
if ( update )
|
||||||
{
|
beginPlaylistChanges();
|
||||||
plentry_ptr e( new PlaylistEntry() );
|
|
||||||
e->setGuid( uuid() );
|
|
||||||
|
|
||||||
if ( query->results().count() )
|
|
||||||
e->setDuration( query->results().at( 0 )->duration() );
|
|
||||||
else
|
|
||||||
e->setDuration( 0 );
|
|
||||||
|
|
||||||
e->setLastmodified( 0 );
|
|
||||||
e->setAnnotation( "" ); // FIXME
|
|
||||||
e->setQuery( query );
|
|
||||||
|
|
||||||
TrackModelItem* plitem = new TrackModelItem( e, m_rootItem, beginRow );
|
|
||||||
plitem->index = createIndex( beginRow++, 0, plitem );
|
|
||||||
|
|
||||||
if ( query->id() == currentuuid )
|
|
||||||
setCurrentItem( plitem->index );
|
|
||||||
|
|
||||||
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
|
||||||
}
|
|
||||||
emit endInsertRows();
|
|
||||||
|
|
||||||
if ( m_dropStorage.action & Qt::CopyAction || m_dropStorage.action & Qt::MoveAction )
|
|
||||||
{
|
|
||||||
onPlaylistChanged();
|
|
||||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
insert( tracks, beginRow );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_dropStorage.parent = QPersistentModelIndex();
|
m_dropStorage.parent = QPersistentModelIndex();
|
||||||
@@ -458,8 +381,26 @@ PlaylistModel::parsedDroppedTracks( QList< query_ptr > tracks )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::onPlaylistChanged()
|
PlaylistModel::beginPlaylistChanges()
|
||||||
{
|
{
|
||||||
|
Q_ASSERT( !m_changesOngoing );
|
||||||
|
m_changesOngoing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::endPlaylistChanges()
|
||||||
|
{
|
||||||
|
if ( m_changesOngoing )
|
||||||
|
{
|
||||||
|
m_changesOngoing = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tDebug() << "Called" << Q_FUNC_INFO << "unexpectedly!";
|
||||||
|
Q_ASSERT( false );
|
||||||
|
}
|
||||||
|
|
||||||
if ( m_playlist.isNull() )
|
if ( m_playlist.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -505,16 +446,17 @@ PlaylistModel::playlistEntries() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::remove( unsigned int row, bool moreToCome )
|
PlaylistModel::remove( int row, bool moreToCome )
|
||||||
{
|
{
|
||||||
removeIndex( index( row, 0, QModelIndex() ), moreToCome );
|
TrackModel::remove( row, moreToCome );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::removeIndex( const QModelIndex& index, bool moreToCome )
|
PlaylistModel::remove( const QModelIndex& index, bool moreToCome )
|
||||||
{
|
{
|
||||||
TrackModelItem* item = itemFromIndex( index );
|
TrackModelItem* item = itemFromIndex( index );
|
||||||
|
|
||||||
if ( item && m_waitingForResolved.contains( item->query().data() ) )
|
if ( item && m_waitingForResolved.contains( item->query().data() ) )
|
||||||
{
|
{
|
||||||
m_waitingForResolved.removeAll( item->query().data() );
|
m_waitingForResolved.removeAll( item->query().data() );
|
||||||
@@ -522,12 +464,27 @@ PlaylistModel::removeIndex( const QModelIndex& index, bool moreToCome )
|
|||||||
emit loadingFinished();
|
emit loadingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackModel::removeIndex( index );
|
if ( !m_changesOngoing )
|
||||||
|
beginPlaylistChanges();
|
||||||
|
|
||||||
if ( !moreToCome && !m_playlist.isNull() )
|
TrackModel::remove( index, moreToCome );
|
||||||
{
|
|
||||||
onPlaylistChanged();
|
if ( !moreToCome )
|
||||||
|
endPlaylistChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::remove( const QList<QModelIndex>& indexes )
|
||||||
|
{
|
||||||
|
TrackModel::remove( indexes );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::remove( const QList<QPersistentModelIndex>& indexes )
|
||||||
|
{
|
||||||
|
TrackModel::remove( indexes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -47,11 +47,6 @@ public:
|
|||||||
explicit PlaylistModel( QObject* parent = 0 );
|
explicit PlaylistModel( QObject* parent = 0 );
|
||||||
~PlaylistModel();
|
~PlaylistModel();
|
||||||
|
|
||||||
int columnCount( const QModelIndex& parent = QModelIndex() ) const;
|
|
||||||
|
|
||||||
QVariant data( const QModelIndex& index, int role ) const;
|
|
||||||
QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
|
|
||||||
|
|
||||||
virtual QMimeData* mimeData ( const QModelIndexList& indexes ) const;
|
virtual QMimeData* mimeData ( const QModelIndexList& indexes ) const;
|
||||||
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent );
|
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent );
|
||||||
|
|
||||||
@@ -60,44 +55,47 @@ public:
|
|||||||
virtual void loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries = true );
|
virtual void loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries = true );
|
||||||
void loadHistory( const Tomahawk::source_ptr& source, unsigned int amount = 50 );
|
void loadHistory( const Tomahawk::source_ptr& source, unsigned int amount = 50 );
|
||||||
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
void append( const Tomahawk::query_ptr& query );
|
|
||||||
void append( const Tomahawk::album_ptr& album );
|
|
||||||
void append( const Tomahawk::artist_ptr& artist );
|
|
||||||
|
|
||||||
void append( const QList< Tomahawk::query_ptr >& queries );
|
|
||||||
|
|
||||||
void insert( unsigned int row, const Tomahawk::query_ptr& query );
|
|
||||||
|
|
||||||
void remove( unsigned int row, bool moreToCome = false );
|
|
||||||
virtual void removeIndex( const QModelIndex& index, bool moreToCome = false );
|
|
||||||
bool isTemporary() const;
|
bool isTemporary() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
|
virtual void append( const Tomahawk::query_ptr& query );
|
||||||
|
virtual void append( const Tomahawk::album_ptr& album );
|
||||||
|
virtual void append( const Tomahawk::artist_ptr& artist );
|
||||||
|
virtual void append( const QList< Tomahawk::query_ptr >& queries );
|
||||||
|
virtual void append( const QList< Tomahawk::plentry_ptr >& entries );
|
||||||
|
|
||||||
|
virtual void insert( const Tomahawk::query_ptr& query, int row = 0 );
|
||||||
|
virtual void insert( const QList< Tomahawk::query_ptr >& queries, int row = 0 );
|
||||||
|
virtual void insert( const QList< Tomahawk::plentry_ptr >& entries, int row = 0 );
|
||||||
|
|
||||||
|
virtual void remove( int row, bool moreToCome = false );
|
||||||
|
virtual void remove( const QModelIndex& index, bool moreToCome = false );
|
||||||
|
virtual void remove( const QList<QModelIndex>& indexes );
|
||||||
|
virtual void remove( const QList<QPersistentModelIndex>& indexes );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||||
void shuffleModeChanged( bool enabled );
|
void shuffleModeChanged( bool enabled );
|
||||||
void itemSizeChanged( const QModelIndex& index );
|
|
||||||
void playlistDeleted();
|
void playlistDeleted();
|
||||||
void playlistChanged();
|
void playlistChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDataChanged();
|
void onDataChanged();
|
||||||
|
|
||||||
void onRevisionLoaded( Tomahawk::PlaylistRevision revision );
|
void onRevisionLoaded( Tomahawk::PlaylistRevision revision );
|
||||||
void onPlaylistChanged();
|
|
||||||
|
|
||||||
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
|
||||||
void onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks );
|
|
||||||
void parsedDroppedTracks( QList<Tomahawk::query_ptr> );
|
void parsedDroppedTracks( QList<Tomahawk::query_ptr> );
|
||||||
|
|
||||||
void trackResolved( bool );
|
void trackResolved( bool );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void beginPlaylistChanges();
|
||||||
|
void endPlaylistChanges();
|
||||||
|
|
||||||
QList<Tomahawk::plentry_ptr> playlistEntries() const;
|
QList<Tomahawk::plentry_ptr> playlistEntries() const;
|
||||||
|
|
||||||
Tomahawk::playlist_ptr m_playlist;
|
Tomahawk::playlist_ptr m_playlist;
|
||||||
bool m_isTemporary;
|
bool m_isTemporary;
|
||||||
|
bool m_changesOngoing;
|
||||||
QList< Tomahawk::Query* > m_waitingForResolved;
|
QList< Tomahawk::Query* > m_waitingForResolved;
|
||||||
QStringList m_waitForRevision;
|
QStringList m_waitForRevision;
|
||||||
|
|
||||||
|
@@ -94,7 +94,7 @@ PlaylistView::keyPressEvent( QKeyEvent* event )
|
|||||||
if ( ( event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace ) && !model()->isReadOnly() )
|
if ( ( event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace ) && !model()->isReadOnly() )
|
||||||
{
|
{
|
||||||
qDebug() << "Removing selected items";
|
qDebug() << "Removing selected items";
|
||||||
proxyModel()->removeIndexes( selectedIndexes() );
|
proxyModel()->remove( selectedIndexes() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,9 +102,10 @@ PlaylistView::keyPressEvent( QKeyEvent* event )
|
|||||||
void
|
void
|
||||||
PlaylistView::deleteItems()
|
PlaylistView::deleteItems()
|
||||||
{
|
{
|
||||||
proxyModel()->removeIndexes( selectedIndexes() );
|
proxyModel()->remove( selectedIndexes() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PlaylistView::canAutoUpdate() const
|
PlaylistView::canAutoUpdate() const
|
||||||
{
|
{
|
||||||
@@ -114,6 +115,7 @@ PlaylistView::canAutoUpdate() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PlaylistView::autoUpdate() const
|
PlaylistView::autoUpdate() const
|
||||||
{
|
{
|
||||||
|
@@ -44,7 +44,7 @@ void
|
|||||||
QueueProxyModel::onIndexActivated( const QModelIndex& index )
|
QueueProxyModel::onIndexActivated( const QModelIndex& index )
|
||||||
{
|
{
|
||||||
setCurrentIndex( QModelIndex() );
|
setCurrentIndex( QModelIndex() );
|
||||||
removeIndex( index );
|
remove( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ QueueProxyModel::siblingItem( int itemsAway )
|
|||||||
setCurrentIndex( QModelIndex() );
|
setCurrentIndex( QModelIndex() );
|
||||||
Tomahawk::result_ptr res = PlaylistProxyModel::siblingItem( itemsAway );
|
Tomahawk::result_ptr res = PlaylistProxyModel::siblingItem( itemsAway );
|
||||||
|
|
||||||
removeIndex( currentIndex() );
|
remove( currentIndex() );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@@ -230,6 +230,7 @@ QVariant
|
|||||||
TrackModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
TrackModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
||||||
{
|
{
|
||||||
Q_UNUSED( orientation );
|
Q_UNUSED( orientation );
|
||||||
|
|
||||||
QStringList headers;
|
QStringList headers;
|
||||||
headers << tr( "Artist" ) << tr( "Title" ) << tr( "Album" ) << tr( "Track" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Age" ) << tr( "Year" ) << tr( "Size" ) << tr( "Origin" ) << tr( "Score" );
|
headers << tr( "Artist" ) << tr( "Title" ) << tr( "Album" ) << tr( "Track" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Age" ) << tr( "Year" ) << tr( "Size" ) << tr( "Origin" ) << tr( "Score" );
|
||||||
if ( role == Qt::DisplayRole && section >= 0 )
|
if ( role == Qt::DisplayRole && section >= 0 )
|
||||||
@@ -244,7 +245,6 @@ TrackModel::headerData( int section, Qt::Orientation orientation, int role ) con
|
|||||||
void
|
void
|
||||||
TrackModel::setCurrentItem( const QModelIndex& index )
|
TrackModel::setCurrentItem( const QModelIndex& index )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
TrackModelItem* oldEntry = itemFromIndex( m_currentIndex );
|
TrackModelItem* oldEntry = itemFromIndex( m_currentIndex );
|
||||||
if ( oldEntry )
|
if ( oldEntry )
|
||||||
{
|
{
|
||||||
@@ -255,11 +255,13 @@ TrackModel::setCurrentItem( const QModelIndex& index )
|
|||||||
if ( entry )
|
if ( entry )
|
||||||
{
|
{
|
||||||
m_currentIndex = index;
|
m_currentIndex = index;
|
||||||
|
m_currentUuid = entry->query()->id();
|
||||||
entry->setIsPlaying( true );
|
entry->setIsPlaying( true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_currentIndex = QModelIndex();
|
m_currentIndex = QModelIndex();
|
||||||
|
m_currentUuid = QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,16 +324,96 @@ TrackModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackModel::removeIndex( const QModelIndex& index, bool moreToCome )
|
TrackModel::clear()
|
||||||
|
{
|
||||||
|
if ( rowCount( QModelIndex() ) )
|
||||||
|
{
|
||||||
|
emit loadingFinished();
|
||||||
|
|
||||||
|
emit beginResetModel();
|
||||||
|
delete m_rootItem;
|
||||||
|
m_rootItem = 0;
|
||||||
|
m_rootItem = new TrackModelItem( 0, this );
|
||||||
|
emit endResetModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::append( const Tomahawk::query_ptr& query )
|
||||||
|
{
|
||||||
|
insert( query, rowCount( QModelIndex() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::append( const QList< Tomahawk::query_ptr >& queries )
|
||||||
|
{
|
||||||
|
insert( queries, rowCount( QModelIndex() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::insert( const Tomahawk::query_ptr& query, int row )
|
||||||
|
{
|
||||||
|
if ( query.isNull() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QList< Tomahawk::query_ptr > ql;
|
||||||
|
ql << query;
|
||||||
|
|
||||||
|
insert( ql, row );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::insert( const QList< Tomahawk::query_ptr >& queries, int row )
|
||||||
|
{
|
||||||
|
if ( !queries.count() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int c = row;
|
||||||
|
QPair< int, int > crows;
|
||||||
|
crows.first = c;
|
||||||
|
crows.second = c + queries.count() - 1;
|
||||||
|
|
||||||
|
emit beginInsertRows( QModelIndex(), crows.first, crows.second );
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
TrackModelItem* plitem;
|
||||||
|
foreach( const query_ptr& query, queries )
|
||||||
|
{
|
||||||
|
plitem = new TrackModelItem( query, m_rootItem, row + i );
|
||||||
|
plitem->index = createIndex( row + i, 0, plitem );
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if ( query->id() == currentItemUuid() )
|
||||||
|
setCurrentItem( plitem->index );
|
||||||
|
|
||||||
|
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
emit endInsertRows();
|
||||||
|
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::remove( int row, bool moreToCome )
|
||||||
|
{
|
||||||
|
remove( index( row, 0, QModelIndex() ), moreToCome );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::remove( const QModelIndex& index, bool moreToCome )
|
||||||
{
|
{
|
||||||
if ( QThread::currentThread() != thread() )
|
if ( QThread::currentThread() != thread() )
|
||||||
{
|
{
|
||||||
// qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
|
QMetaObject::invokeMethod( this, "remove",
|
||||||
QMetaObject::invokeMethod( this, "removeIndex",
|
|
||||||
Qt::QueuedConnection,
|
Qt::QueuedConnection,
|
||||||
Q_ARG(const QModelIndex, index),
|
Q_ARG(const QModelIndex, index),
|
||||||
Q_ARG(bool, moreToCome)
|
Q_ARG(bool, moreToCome) );
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,24 +428,49 @@ TrackModel::removeIndex( const QModelIndex& index, bool moreToCome )
|
|||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !moreToCome )
|
||||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackModel::removeIndexes( const QList<QModelIndex>& indexes )
|
TrackModel::remove( const QList<QModelIndex>& indexes )
|
||||||
{
|
{
|
||||||
|
QList<QPersistentModelIndex> pil;
|
||||||
foreach ( const QModelIndex& idx, indexes )
|
foreach ( const QModelIndex& idx, indexes )
|
||||||
{
|
{
|
||||||
removeIndex( idx );
|
pil << idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove( pil );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::remove( const QList<QPersistentModelIndex>& indexes )
|
||||||
|
{
|
||||||
|
QList<QPersistentModelIndex> finalIndexes;
|
||||||
|
foreach ( const QPersistentModelIndex index, indexes )
|
||||||
|
{
|
||||||
|
if ( index.column() > 0 )
|
||||||
|
continue;
|
||||||
|
finalIndexes << index;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( int i = 0; i < finalIndexes.count(); i++ )
|
||||||
|
{
|
||||||
|
remove( finalIndexes.at( i ), i + 1 != finalIndexes.count() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TrackModelItem*
|
TrackModelItem*
|
||||||
TrackModel::itemFromIndex( const QModelIndex& index ) const
|
TrackModel::itemFromIndex( const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
if ( index.isValid() )
|
if ( index.isValid() )
|
||||||
|
{
|
||||||
return static_cast<TrackModelItem*>( index.internalPointer() );
|
return static_cast<TrackModelItem*>( index.internalPointer() );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return m_rootItem;
|
return m_rootItem;
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "playlistinterface.h"
|
#include "playlistinterface.h"
|
||||||
#include "trackmodelitem.h"
|
#include "trackmodelitem.h"
|
||||||
|
#include "typedefs.h"
|
||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
@@ -84,16 +85,13 @@ public:
|
|||||||
virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
|
virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
|
||||||
|
|
||||||
virtual QPersistentModelIndex currentItem() { return m_currentIndex; }
|
virtual QPersistentModelIndex currentItem() { return m_currentIndex; }
|
||||||
|
virtual Tomahawk::QID currentItemUuid() { return m_currentUuid; }
|
||||||
|
|
||||||
virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return Tomahawk::PlaylistInterface::NoRepeat; }
|
virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return Tomahawk::PlaylistInterface::NoRepeat; }
|
||||||
virtual bool shuffled() const { return false; }
|
virtual bool shuffled() const { return false; }
|
||||||
|
|
||||||
virtual void ensureResolved();
|
virtual void ensureResolved();
|
||||||
|
|
||||||
virtual void append( const Tomahawk::query_ptr& query ) = 0;
|
|
||||||
virtual void append( const Tomahawk::artist_ptr& artist ) = 0;
|
|
||||||
virtual void append( const Tomahawk::album_ptr& album ) = 0;
|
|
||||||
|
|
||||||
TrackModelItem* itemFromIndex( const QModelIndex& index ) const;
|
TrackModelItem* itemFromIndex( const QModelIndex& index ) const;
|
||||||
TrackModelItem* m_rootItem;
|
TrackModelItem* m_rootItem;
|
||||||
|
|
||||||
@@ -109,8 +107,20 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
virtual void setCurrentItem( const QModelIndex& index );
|
virtual void setCurrentItem( const QModelIndex& index );
|
||||||
|
|
||||||
virtual void removeIndex( const QModelIndex& index, bool moreToCome = false );
|
virtual void clear();
|
||||||
virtual void removeIndexes( const QList<QModelIndex>& indexes );
|
|
||||||
|
virtual void append( const QList< Tomahawk::query_ptr >& queries );
|
||||||
|
virtual void append( const Tomahawk::query_ptr& query );
|
||||||
|
virtual void append( const Tomahawk::artist_ptr& artist ) { Q_UNUSED( artist ); }
|
||||||
|
virtual void append( const Tomahawk::album_ptr& album ) { Q_UNUSED( album ); }
|
||||||
|
|
||||||
|
virtual void insert( const QList< Tomahawk::query_ptr >& queries, int row = 0 );
|
||||||
|
virtual void insert( const Tomahawk::query_ptr& query, int row = 0 );
|
||||||
|
|
||||||
|
virtual void remove( int row, bool moreToCome = false );
|
||||||
|
virtual void remove( const QModelIndex& index, bool moreToCome = false );
|
||||||
|
virtual void remove( const QList<QModelIndex>& indexes );
|
||||||
|
virtual void remove( const QList<QPersistentModelIndex>& indexes );
|
||||||
|
|
||||||
virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
|
virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
|
||||||
virtual void setShuffled( bool /*shuffled*/ ) {}
|
virtual void setShuffled( bool /*shuffled*/ ) {}
|
||||||
@@ -121,6 +131,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QPersistentModelIndex m_currentIndex;
|
QPersistentModelIndex m_currentIndex;
|
||||||
|
Tomahawk::QID m_currentUuid;
|
||||||
|
|
||||||
bool m_readOnly;
|
bool m_readOnly;
|
||||||
|
|
||||||
QString m_title;
|
QString m_title;
|
||||||
|
@@ -227,21 +227,19 @@ TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParen
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackProxyModel::removeIndex( const QModelIndex& index )
|
TrackProxyModel::remove( const QModelIndex& index )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
if ( !sourceModel() )
|
if ( !sourceModel() )
|
||||||
return;
|
return;
|
||||||
if ( !index.isValid() )
|
if ( !index.isValid() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sourceModel()->removeIndex( mapToSource( index ) );
|
sourceModel()->remove( mapToSource( index ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackProxyModel::removeIndexes( const QModelIndexList& indexes )
|
TrackProxyModel::remove( const QModelIndexList& indexes )
|
||||||
{
|
{
|
||||||
if ( !sourceModel() )
|
if ( !sourceModel() )
|
||||||
return;
|
return;
|
||||||
@@ -249,44 +247,28 @@ TrackProxyModel::removeIndexes( const QModelIndexList& indexes )
|
|||||||
QList<QPersistentModelIndex> pil;
|
QList<QPersistentModelIndex> pil;
|
||||||
foreach ( const QModelIndex& idx, indexes )
|
foreach ( const QModelIndex& idx, indexes )
|
||||||
{
|
{
|
||||||
if ( idx.isValid() && idx.column() == 0 )
|
if ( idx.isValid() )
|
||||||
pil << mapToSource( idx );
|
pil << mapToSource( idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool b = true;
|
sourceModel()->remove( pil );
|
||||||
foreach( const QPersistentModelIndex& idx, pil )
|
|
||||||
{
|
|
||||||
if ( idx == pil.last() )
|
|
||||||
b = false;
|
|
||||||
|
|
||||||
qDebug() << "b is:" << b;
|
|
||||||
sourceModel()->removeIndex( idx, b );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackProxyModel::removeIndexes( const QList<QPersistentModelIndex>& indexes )
|
TrackProxyModel::remove( const QList< QPersistentModelIndex >& indexes )
|
||||||
{
|
{
|
||||||
if ( !sourceModel() )
|
if ( !sourceModel() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList<QPersistentModelIndex> pil;
|
QList<QPersistentModelIndex> pil;
|
||||||
foreach( const QModelIndex& idx, indexes )
|
foreach ( const QPersistentModelIndex& idx, indexes )
|
||||||
{
|
{
|
||||||
if ( idx.isValid() && idx.column() == 0 )
|
if ( idx.isValid() )
|
||||||
pil << mapToSource( idx );
|
pil << mapToSource( idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool b = true;
|
sourceModel()->remove( pil );
|
||||||
foreach( const QPersistentModelIndex& idx, pil )
|
|
||||||
{
|
|
||||||
if ( idx == pil.last() )
|
|
||||||
b = false;
|
|
||||||
|
|
||||||
qDebug() << "b is:" << b;
|
|
||||||
sourceModel()->removeIndex( idx, b );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -45,9 +45,9 @@ public:
|
|||||||
virtual int unfilteredTrackCount() const { return sourceModel()->trackCount(); }
|
virtual int unfilteredTrackCount() const { return sourceModel()->trackCount(); }
|
||||||
virtual int trackCount() const { return rowCount( QModelIndex() ); }
|
virtual int trackCount() const { return rowCount( QModelIndex() ); }
|
||||||
|
|
||||||
virtual void removeIndex( const QModelIndex& index );
|
virtual void remove( const QModelIndex& index );
|
||||||
virtual void removeIndexes( const QModelIndexList& indexes );
|
virtual void remove( const QModelIndexList& indexes );
|
||||||
virtual void removeIndexes( const QList<QPersistentModelIndex>& indexes );
|
virtual void remove( const QList< QPersistentModelIndex >& indexes );
|
||||||
|
|
||||||
virtual Tomahawk::result_ptr currentItem() const;
|
virtual Tomahawk::result_ptr currentItem() const;
|
||||||
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
|
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
|
||||||
|
@@ -411,7 +411,7 @@ TrackView::startDrag( Qt::DropActions supportedActions )
|
|||||||
Qt::DropAction action = drag->exec( supportedActions, Qt::CopyAction );
|
Qt::DropAction action = drag->exec( supportedActions, Qt::CopyAction );
|
||||||
if ( action == Qt::MoveAction )
|
if ( action == Qt::MoveAction )
|
||||||
{
|
{
|
||||||
m_proxyModel->removeIndexes( pindexes );
|
m_proxyModel->remove( pindexes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user