1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 08:34:34 +02:00

Let collections store their shared ptrs

This commit is contained in:
Dominik Schmidt
2015-01-05 16:33:24 +01:00
parent ddb2484ad7
commit 55fa633dad
7 changed files with 28 additions and 17 deletions

View File

@@ -138,6 +138,7 @@ SourceList::add( const source_ptr& source )
connect( source.data(), SIGNAL( syncedWithDatabase() ), SLOT( sourceSynced() ) );
collection_ptr coll( new RemoteCollection( source ) );
coll->setWeakRef( coll.toWeakRef() );
source->addCollection( coll );
connect( source.data(), SIGNAL( latchedOn( Tomahawk::source_ptr ) ), this, SLOT( latchedOn( Tomahawk::source_ptr ) ) );

View File

@@ -58,6 +58,7 @@ namespace Tomahawk
class ScriptObject;
typedef QSharedPointer<Collection> collection_ptr;
typedef QWeakPointer<Collection> collection_wptr;
typedef QSharedPointer<Playlist> playlist_ptr;
typedef QSharedPointer<PlaylistEntry> plentry_ptr;
typedef QSharedPointer<PlaylistInterface> playlistinterface_ptr;

View File

@@ -53,6 +53,20 @@ Collection::~Collection()
}
void
Collection::setWeakRef( const collection_wptr& weakRef )
{
m_ownRef = weakRef;
}
const collection_wptr
Collection::weakRef() const
{
return m_ownRef;
}
QString
Collection::name() const
{

View File

@@ -53,6 +53,9 @@ public:
Collection( const source_ptr& source, const QString& name, QObject* parent = 0 );
virtual ~Collection();
void setWeakRef( const collection_wptr& weakRef );
const collection_wptr weakRef() const;
enum BackendType
{
NullCollectionType = 0,
@@ -133,7 +136,9 @@ private slots:
private:
bool m_changed;
collection_wptr m_ownRef;
source_ptr m_source;
QHash< QString, Tomahawk::playlist_ptr > m_playlists;
QHash< QString, Tomahawk::dynplaylist_ptr > m_autoplaylists;
QHash< QString, Tomahawk::dynplaylist_ptr > m_stations;

View File

@@ -783,6 +783,9 @@ JSResolver::loadCollections()
m_collections.clear();
// at this point we assume that all the tracks browsable through a resolver belong to the local source
Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( collectionInfo[ "id" ].toString(), SourceList::instance()->getLocal(), this );
Tomahawk::collection_ptr collection( sc );
collection->setWeakRef( collection.toWeakRef() );
sc->setServiceName( prettyname );
sc->setDescription( desc );
@@ -805,8 +808,6 @@ JSResolver::loadCollections()
sc->setIcon( QIcon( iconPixmap ) );
}
Tomahawk::collection_ptr collection( sc );
m_collections.insert( collection->name(), collection );
emit collectionAdded( collection );

View File

@@ -145,11 +145,7 @@ ScriptCollection::description() const
Tomahawk::ArtistsRequest*
ScriptCollection::requestArtists()
{
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
if ( thisCollection->name() != name() )
return 0;
Tomahawk::ArtistsRequest* cmd = new ScriptCommand_AllArtists( thisCollection );
Tomahawk::ArtistsRequest* cmd = new ScriptCommand_AllArtists( weakRef().toStrongRef() );
return cmd;
}
@@ -158,11 +154,7 @@ ScriptCollection::requestArtists()
Tomahawk::AlbumsRequest*
ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
{
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
if ( thisCollection->name() != name() )
return 0;
Tomahawk::AlbumsRequest* cmd = new ScriptCommand_AllAlbums( thisCollection, artist );
Tomahawk::AlbumsRequest* cmd = new ScriptCommand_AllAlbums( weakRef().toStrongRef(), artist );
return cmd;
}
@@ -171,11 +163,7 @@ ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
Tomahawk::TracksRequest*
ScriptCollection::requestTracks( const Tomahawk::album_ptr& album )
{
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
if ( thisCollection->name() != name() )
return 0;
Tomahawk::TracksRequest* cmd = new ScriptCommand_AllTracks( thisCollection, album );
Tomahawk::TracksRequest* cmd = new ScriptCommand_AllTracks( weakRef().toStrongRef(), album );
return cmd;
}

View File

@@ -516,6 +516,7 @@ TomahawkApp::initLocalCollection()
source_ptr src( new Source( 0, Database::instance()->impl()->dbid() ) );
src->setFriendlyName( tr( "You" ) );
collection_ptr coll( new LocalCollection( src ) );
coll->setWeakRef( coll.toWeakRef() );
src->addCollection( coll );
SourceList::instance()->setLocal( src );