mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 01:54:07 +02:00
Store a strong reference to a playlist pointer so it will not be destroyed before the postCommitHook finishes
This commit is contained in:
@@ -108,27 +108,21 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
|||||||
tLog() << "Postcommitting this playlist:" << playlistguid() << source().isNull();
|
tLog() << "Postcommitting this playlist:" << playlistguid() << source().isNull();
|
||||||
|
|
||||||
// private, but we are a friend. will recall itself in its own thread:
|
// private, but we are a friend. will recall itself in its own thread:
|
||||||
DynamicPlaylist* rawPl = 0;
|
|
||||||
dynplaylist_ptr playlist = source()->dbCollection()->autoPlaylist( playlistguid() );
|
dynplaylist_ptr playlist = source()->dbCollection()->autoPlaylist( playlistguid() );
|
||||||
if ( playlist.isNull() )
|
if ( playlist.isNull() )
|
||||||
{
|
{
|
||||||
playlist = source()->dbCollection()->station( playlistguid() );
|
playlist = source()->dbCollection()->station( playlistguid() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !playlist.isNull() )
|
if ( playlist.isNull() && !m_playlist.isNull() )
|
||||||
{
|
|
||||||
rawPl = playlist.data();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// if it's neither an auto or station, it must not be auto-loaded, so we MUST have been told about it directly
|
// if it's neither an auto or station, it must not be auto-loaded, so we MUST have been told about it directly
|
||||||
rawPl = m_playlist;
|
playlist = m_playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !rawPl )
|
if ( playlist.isNull() )
|
||||||
{
|
{
|
||||||
tLog() << "Got null playlist with guid:" << playlistguid() << "from source and collection:" << source()->friendlyName() << source()->dbCollection()->name() << "and mode is static?:" << (m_mode == Static);
|
tLog() << "Got null playlist with guid:" << playlistguid() << "from source and collection:" << source()->friendlyName() << source()->dbCollection()->name() << "and mode is static?:" << (m_mode == Static);
|
||||||
// Q_ASSERT( false );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,13 +133,13 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
|||||||
controlMap << v.toMap();
|
controlMap << v.toMap();
|
||||||
|
|
||||||
if ( m_mode == OnDemand )
|
if ( m_mode == OnDemand )
|
||||||
rawPl->setRevision( newrev(),
|
playlist->setRevision( newrev(),
|
||||||
true, // this *is* the newest revision so far
|
true, // this *is* the newest revision so far
|
||||||
m_type,
|
m_type,
|
||||||
controlMap,
|
controlMap,
|
||||||
m_applied );
|
m_applied );
|
||||||
else
|
else
|
||||||
rawPl->setRevision( newrev(),
|
playlist->setRevision( newrev(),
|
||||||
orderedentriesguids,
|
orderedentriesguids,
|
||||||
m_previous_rev_orderedguids,
|
m_previous_rev_orderedguids,
|
||||||
m_type,
|
m_type,
|
||||||
@@ -157,13 +151,13 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( m_mode == OnDemand )
|
if ( m_mode == OnDemand )
|
||||||
rawPl->setRevision( newrev(),
|
playlist->setRevision( newrev(),
|
||||||
true, // this *is* the newest revision so far
|
true, // this *is* the newest revision so far
|
||||||
m_type,
|
m_type,
|
||||||
m_controls,
|
m_controls,
|
||||||
m_applied );
|
m_applied );
|
||||||
else
|
else
|
||||||
rawPl->setRevision( newrev(),
|
playlist->setRevision( newrev(),
|
||||||
orderedentriesguids,
|
orderedentriesguids,
|
||||||
m_previous_rev_orderedguids,
|
m_previous_rev_orderedguids,
|
||||||
m_type,
|
m_type,
|
||||||
@@ -269,9 +263,9 @@ DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseCommand_SetDynamicPlaylistRevision::setPlaylist( DynamicPlaylist* pl )
|
DatabaseCommand_SetDynamicPlaylistRevision::setPlaylist( QWeakPointer<DynamicPlaylist> pl )
|
||||||
{
|
{
|
||||||
m_playlist = pl;
|
m_playlist = pl.toStrongRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -76,8 +76,7 @@ public:
|
|||||||
void setType( const QString& type ) { m_type = type; }
|
void setType( const QString& type ) { m_type = type; }
|
||||||
void setMode( int mode ) { m_mode = (GeneratorMode)mode; }
|
void setMode( int mode ) { m_mode = (GeneratorMode)mode; }
|
||||||
|
|
||||||
// TODO: Pass wptr here, so we can get a strong reference again
|
void setPlaylist( QWeakPointer<DynamicPlaylist> pl ); // raw pointer b/c we don't have the shared pointer from inside the shared pointer
|
||||||
void setPlaylist( DynamicPlaylist* pl ); // raw pointer b/c we don't have the shared pointer from inside the shared pointer
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_type;
|
QString m_type;
|
||||||
@@ -85,8 +84,7 @@ private:
|
|||||||
QList< dyncontrol_ptr > m_controls;
|
QList< dyncontrol_ptr > m_controls;
|
||||||
QList< QVariant > m_controlsV;
|
QList< QVariant > m_controlsV;
|
||||||
|
|
||||||
// ARG i hate sharedpointers sometimes
|
QSharedPointer<DynamicPlaylist> m_playlist; // Only used if setting revision of a non-autoloaded playlist, as those aren't able to be looked up by guid
|
||||||
DynamicPlaylist* m_playlist; // Only used if setting revision of a non-autoloaded playlist, as those aren't able to be looked up by guid
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -242,7 +242,7 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
|||||||
Static,
|
Static,
|
||||||
controls );
|
controls );
|
||||||
if ( !d->autoLoad )
|
if ( !d->autoLoad )
|
||||||
cmd->setPlaylist( this );
|
cmd->setPlaylist( d->weakSelf );
|
||||||
|
|
||||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||||
}
|
}
|
||||||
@@ -278,7 +278,7 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
|||||||
OnDemand,
|
OnDemand,
|
||||||
controls );
|
controls );
|
||||||
if ( !d->autoLoad )
|
if ( !d->autoLoad )
|
||||||
cmd->setPlaylist( this );
|
cmd->setPlaylist( d->weakSelf );
|
||||||
|
|
||||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user