mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-22 00:42:04 +02:00
better logic for clearing and reloading the playlist
This commit is contained in:
parent
1f169e0c24
commit
738d462545
src/libtomahawk/playlist
@ -46,7 +46,7 @@ DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
|
||||
|
||||
|
||||
connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
|
||||
PlaylistModel::loadPlaylist( m_playlist );
|
||||
PlaylistModel::loadPlaylist( m_playlist, m_onDemandRunning );
|
||||
}
|
||||
|
||||
void
|
||||
@ -54,6 +54,9 @@ DynamicModel::startOnDemand()
|
||||
{
|
||||
connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
|
||||
|
||||
// delete all the tracks
|
||||
clear();
|
||||
|
||||
m_playlist->generator()->startOnDemand();
|
||||
|
||||
m_onDemandRunning = true;
|
||||
@ -79,8 +82,6 @@ DynamicModel::stopOnDemand()
|
||||
m_onDemandRunning = false;
|
||||
AudioEngine::instance()->stop();
|
||||
|
||||
// delete all the tracks
|
||||
clear();
|
||||
disconnect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
|
||||
}
|
||||
|
||||
@ -112,7 +113,7 @@ DynamicModel::trackResolveFinished( bool success )
|
||||
if( m_currentAttempts < 30 ) {
|
||||
m_playlist->generator()->fetchNext();
|
||||
} else {
|
||||
emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters and try again." ) );
|
||||
emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters or try again." ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ EchonestFactory::typeSelectors() const
|
||||
EchonestGenerator::EchonestGenerator ( QObject* parent )
|
||||
: GeneratorInterface ( parent )
|
||||
, m_dynPlaylist( new Echonest::DynamicPlaylist() )
|
||||
, m_steerer( 0 )
|
||||
, m_steeredSinceLastTrack( false )
|
||||
{
|
||||
m_type = "echonest";
|
||||
@ -201,8 +200,8 @@ EchonestGenerator::dynamicFetched()
|
||||
m_steerData.first = Echonest::DynamicPlaylist::Steer;
|
||||
m_steerData.second = QString();
|
||||
|
||||
if( m_steerer )
|
||||
m_steerer->resetSteering( true );
|
||||
if( !m_steerer.isNull() )
|
||||
m_steerer.data()->resetSteering( true );
|
||||
|
||||
try
|
||||
{
|
||||
@ -289,14 +288,14 @@ EchonestGenerator::queryFromSong(const Echonest::Song& song)
|
||||
QWidget*
|
||||
EchonestGenerator::steeringWidget()
|
||||
{
|
||||
if( !m_steerer ) {
|
||||
m_steerer = new EchonestSteerer();
|
||||
if( m_steerer.isNull() ) {
|
||||
m_steerer = QWeakPointer< EchonestSteerer >( new EchonestSteerer );
|
||||
|
||||
connect( m_steerer, SIGNAL( steerField( QString ) ), this, SLOT( steerField( QString ) ) );
|
||||
connect( m_steerer, SIGNAL( steerDescription( QString ) ), this, SLOT( steerDescription( QString ) ) );
|
||||
connect( m_steerer.data(), SIGNAL( steerField( QString ) ), this, SLOT( steerField( QString ) ) );
|
||||
connect( m_steerer.data(), SIGNAL( steerDescription( QString ) ), this, SLOT( steerDescription( QString ) ) );
|
||||
}
|
||||
|
||||
return m_steerer;
|
||||
return m_steerer.data();
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ private:
|
||||
Echonest::DynamicPlaylist* m_dynPlaylist;
|
||||
QPixmap m_logo;
|
||||
|
||||
EchonestSteerer* m_steerer;
|
||||
QWeakPointer<EchonestSteerer> m_steerer;
|
||||
bool m_steeredSinceLastTrack;
|
||||
Echonest::DynamicPlaylist::DynamicControl m_steerData;
|
||||
};
|
||||
|
@ -118,11 +118,12 @@ DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
|
||||
return;
|
||||
}
|
||||
m_seqRevLaunched = 0;
|
||||
|
||||
// if we're being told to load the same dynamic playlist over again, only do it if the controls have a different number
|
||||
if( !m_playlist.isNull() && ( m_playlist.data() == playlist.data() ) // same playlist pointer
|
||||
&& m_playlist->generator()->controls().size() == playlist->generator()->controls().size() ) {
|
||||
// we can skip our work. just let the dynamiccontrollist show the difference
|
||||
qDebug() << "SKIPPING SETTING:" << playlist->generator()->controls().size();
|
||||
// qDebug() << "SKIPPING SETTING:" << playlist->generator()->controls().size();
|
||||
foreach( const dyncontrol_ptr& control, playlist->generator()->controls() ) {
|
||||
qDebug() << "CONTROL:" << control->selectedType() << control->match() << control->input();
|
||||
}
|
||||
@ -236,6 +237,7 @@ DynamicWidget::generateOrStart()
|
||||
} else { // stop
|
||||
m_model->stopOnDemand();
|
||||
m_runningOnDemand = false;
|
||||
delete m_steering;
|
||||
m_steering = 0;
|
||||
m_generateButton->setText( tr( "Start" ) );
|
||||
}
|
||||
@ -275,6 +277,10 @@ DynamicWidget::tracksGenerated( const QList< query_ptr >& queries )
|
||||
void
|
||||
DynamicWidget::controlsChanged()
|
||||
{
|
||||
// if we're playing a station, stop it in either case
|
||||
if( m_runningOnDemand )
|
||||
generateOrStart(); // as if the stop button were pressed
|
||||
|
||||
m_playlist->createNewRevision();
|
||||
m_seqRevLaunched++;
|
||||
}
|
||||
@ -282,6 +288,10 @@ DynamicWidget::controlsChanged()
|
||||
void
|
||||
DynamicWidget::controlChanged( const Tomahawk::dyncontrol_ptr& control )
|
||||
{
|
||||
// if we're playing a station, stop it in either case
|
||||
if( m_runningOnDemand )
|
||||
generateOrStart(); // as if the stop button were pressed
|
||||
|
||||
m_playlist->createNewRevision();
|
||||
m_seqRevLaunched++;
|
||||
}
|
||||
|
@ -50,12 +50,12 @@ PlaylistModel::headerData( int section, Qt::Orientation orientation, int role )
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist )
|
||||
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 ) ) );
|
||||
|
||||
if ( rowCount( QModelIndex() ) )
|
||||
if ( rowCount( QModelIndex() ) && loadEntries )
|
||||
{
|
||||
emit beginRemoveRows( QModelIndex(), 0, rowCount( QModelIndex() ) - 1 );
|
||||
delete m_rootItem;
|
||||
@ -68,6 +68,9 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist )
|
||||
|
||||
setReadOnly( !m_playlist->author()->isLocal() );
|
||||
|
||||
if( !loadEntries )
|
||||
return;
|
||||
|
||||
PlItem* plitem;
|
||||
QList<plentry_ptr> entries = playlist->entries();
|
||||
if ( entries.count() )
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
|
||||
Tomahawk::playlist_ptr playlist() const { return m_playlist; }
|
||||
|
||||
void loadPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||
void loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEntries = true );
|
||||
void loadHistory( const Tomahawk::source_ptr& source, unsigned int amount = 100 );
|
||||
|
||||
void clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user