void PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries ) { if ( !m_playlist.isNull() ) { disconnect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); disconnect( m_playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) ); disconnect( m_playlist.data(), SIGNAL( changed() ), this, SIGNAL( playlistChanged() ) ); } if ( loadEntries ) clear(); m_playlist = playlist; connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); connect( playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) ); connect( playlist.data(), SIGNAL( changed() ), this, SIGNAL( playlistChanged() ) ); setReadOnly( !m_playlist->author()->isLocal() ); setTitle( playlist->title() ); setDescription( tr( "A playlist by %1, created %2" ) .arg( playlist->author()->isLocal() ? tr( "you" ) : playlist->author()->friendlyName() ) .arg( TomahawkUtils::ageToString( QDateTime::fromTime_t( playlist->createdOn() ), true ) ) ); m_isTemporary = false; if ( !loadEntries ) return; QList<plentry_ptr> entries = playlist->entries(); append( entries ); }
void PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries ) { if ( !m_playlist.isNull() ) { disconnect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); disconnect( m_playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) ); } if ( rowCount( QModelIndex() ) && loadEntries ) { clear(); } m_playlist = playlist; connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); connect( playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) ); setReadOnly( !m_playlist->author()->isLocal() ); setTitle( playlist->title() ); setDescription( tr( "A playlist by %1" ).arg( playlist->author()->isLocal() ? tr( "you" ) : playlist->author()->friendlyName() ) ); if ( !loadEntries ) return; TrackModelItem* plitem; QList<plentry_ptr> entries = playlist->entries(); if ( entries.count() ) { 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()->resolvingFinished() && entry->query()->playable() ) { m_waitingForResolved.append( entry->query().data() ); connect( entry->query().data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolved( bool ) ) ); }
void PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries ) { Q_D( PlaylistModel ); if ( d->playlist ) { disconnect( d->playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); disconnect( d->playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) ); disconnect( d->playlist.data(), SIGNAL( changed() ), this, SLOT( onPlaylistChanged() ) ); } if ( loadEntries ) { startLoading(); clear(); } d->playlist = playlist; connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); connect( playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), SIGNAL( playlistDeleted() ) ); connect( playlist.data(), SIGNAL( changed() ), SLOT( onPlaylistChanged() ) ); setReadOnly( !d->playlist->author()->isLocal() ); d->isTemporary = false; onPlaylistChanged(); if ( !loadEntries ) return; if ( playlist->loaded() ) { QList<plentry_ptr> entries = playlist->entries(); appendEntries( entries ); // finishLoading() will be called by appendEntries, so it can keep showing it until all tracks are resolved // finishLoading(); /* foreach ( const plentry_ptr& p, entries ) qDebug() << p->guid() << p->query()->track() << p->query()->artist(); */ } }
void PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries ) { if ( !m_playlist.isNull() ) { disconnect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); disconnect( m_playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), this, SIGNAL( playlistDeleted() ) ); disconnect( m_playlist.data(), SIGNAL( changed() ), this, SLOT( onPlaylistChanged() ) ); } m_isLoading = true; if ( loadEntries ) clear(); m_playlist = playlist; connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onRevisionLoaded( Tomahawk::PlaylistRevision ) ) ); connect( playlist.data(), SIGNAL( deleted( Tomahawk::playlist_ptr ) ), SIGNAL( playlistDeleted() ) ); connect( playlist.data(), SIGNAL( changed() ), SLOT( onPlaylistChanged() ) ); setReadOnly( !m_playlist->author()->isLocal() ); m_isTemporary = false; onPlaylistChanged(); if ( !loadEntries ) { m_isLoading = false; return; } QList<plentry_ptr> entries = playlist->entries(); /* foreach ( const plentry_ptr& p, entries ) qDebug() << p->guid() << p->query()->track() << p->query()->artist();*/ appendEntries( entries ); m_isLoading = false; }