mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
Let collections store their shared ptrs
This commit is contained in:
@@ -138,6 +138,7 @@ SourceList::add( const source_ptr& source )
|
|||||||
connect( source.data(), SIGNAL( syncedWithDatabase() ), SLOT( sourceSynced() ) );
|
connect( source.data(), SIGNAL( syncedWithDatabase() ), SLOT( sourceSynced() ) );
|
||||||
|
|
||||||
collection_ptr coll( new RemoteCollection( source ) );
|
collection_ptr coll( new RemoteCollection( source ) );
|
||||||
|
coll->setWeakRef( coll.toWeakRef() );
|
||||||
source->addCollection( coll );
|
source->addCollection( coll );
|
||||||
|
|
||||||
connect( source.data(), SIGNAL( latchedOn( Tomahawk::source_ptr ) ), this, SLOT( latchedOn( Tomahawk::source_ptr ) ) );
|
connect( source.data(), SIGNAL( latchedOn( Tomahawk::source_ptr ) ), this, SLOT( latchedOn( Tomahawk::source_ptr ) ) );
|
||||||
|
@@ -58,6 +58,7 @@ namespace Tomahawk
|
|||||||
class ScriptObject;
|
class ScriptObject;
|
||||||
|
|
||||||
typedef QSharedPointer<Collection> collection_ptr;
|
typedef QSharedPointer<Collection> collection_ptr;
|
||||||
|
typedef QWeakPointer<Collection> collection_wptr;
|
||||||
typedef QSharedPointer<Playlist> playlist_ptr;
|
typedef QSharedPointer<Playlist> playlist_ptr;
|
||||||
typedef QSharedPointer<PlaylistEntry> plentry_ptr;
|
typedef QSharedPointer<PlaylistEntry> plentry_ptr;
|
||||||
typedef QSharedPointer<PlaylistInterface> playlistinterface_ptr;
|
typedef QSharedPointer<PlaylistInterface> playlistinterface_ptr;
|
||||||
|
@@ -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
|
QString
|
||||||
Collection::name() const
|
Collection::name() const
|
||||||
{
|
{
|
||||||
|
@@ -53,6 +53,9 @@ public:
|
|||||||
Collection( const source_ptr& source, const QString& name, QObject* parent = 0 );
|
Collection( const source_ptr& source, const QString& name, QObject* parent = 0 );
|
||||||
virtual ~Collection();
|
virtual ~Collection();
|
||||||
|
|
||||||
|
void setWeakRef( const collection_wptr& weakRef );
|
||||||
|
const collection_wptr weakRef() const;
|
||||||
|
|
||||||
enum BackendType
|
enum BackendType
|
||||||
{
|
{
|
||||||
NullCollectionType = 0,
|
NullCollectionType = 0,
|
||||||
@@ -133,7 +136,9 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
bool m_changed;
|
bool m_changed;
|
||||||
|
|
||||||
|
collection_wptr m_ownRef;
|
||||||
source_ptr m_source;
|
source_ptr m_source;
|
||||||
|
|
||||||
QHash< QString, Tomahawk::playlist_ptr > m_playlists;
|
QHash< QString, Tomahawk::playlist_ptr > m_playlists;
|
||||||
QHash< QString, Tomahawk::dynplaylist_ptr > m_autoplaylists;
|
QHash< QString, Tomahawk::dynplaylist_ptr > m_autoplaylists;
|
||||||
QHash< QString, Tomahawk::dynplaylist_ptr > m_stations;
|
QHash< QString, Tomahawk::dynplaylist_ptr > m_stations;
|
||||||
|
@@ -783,6 +783,9 @@ JSResolver::loadCollections()
|
|||||||
m_collections.clear();
|
m_collections.clear();
|
||||||
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
// 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::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->setServiceName( prettyname );
|
||||||
sc->setDescription( desc );
|
sc->setDescription( desc );
|
||||||
|
|
||||||
@@ -805,8 +808,6 @@ JSResolver::loadCollections()
|
|||||||
sc->setIcon( QIcon( iconPixmap ) );
|
sc->setIcon( QIcon( iconPixmap ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Tomahawk::collection_ptr collection( sc );
|
|
||||||
|
|
||||||
m_collections.insert( collection->name(), collection );
|
m_collections.insert( collection->name(), collection );
|
||||||
emit collectionAdded( collection );
|
emit collectionAdded( collection );
|
||||||
|
|
||||||
|
@@ -145,11 +145,7 @@ ScriptCollection::description() const
|
|||||||
Tomahawk::ArtistsRequest*
|
Tomahawk::ArtistsRequest*
|
||||||
ScriptCollection::requestArtists()
|
ScriptCollection::requestArtists()
|
||||||
{
|
{
|
||||||
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
|
Tomahawk::ArtistsRequest* cmd = new ScriptCommand_AllArtists( weakRef().toStrongRef() );
|
||||||
if ( thisCollection->name() != name() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Tomahawk::ArtistsRequest* cmd = new ScriptCommand_AllArtists( thisCollection );
|
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
@@ -158,11 +154,7 @@ ScriptCollection::requestArtists()
|
|||||||
Tomahawk::AlbumsRequest*
|
Tomahawk::AlbumsRequest*
|
||||||
ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
|
ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
|
||||||
{
|
{
|
||||||
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
|
Tomahawk::AlbumsRequest* cmd = new ScriptCommand_AllAlbums( weakRef().toStrongRef(), artist );
|
||||||
if ( thisCollection->name() != name() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Tomahawk::AlbumsRequest* cmd = new ScriptCommand_AllAlbums( thisCollection, artist );
|
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
@@ -171,11 +163,7 @@ ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
|
|||||||
Tomahawk::TracksRequest*
|
Tomahawk::TracksRequest*
|
||||||
ScriptCollection::requestTracks( const Tomahawk::album_ptr& album )
|
ScriptCollection::requestTracks( const Tomahawk::album_ptr& album )
|
||||||
{
|
{
|
||||||
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
|
Tomahawk::TracksRequest* cmd = new ScriptCommand_AllTracks( weakRef().toStrongRef(), album );
|
||||||
if ( thisCollection->name() != name() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Tomahawk::TracksRequest* cmd = new ScriptCommand_AllTracks( thisCollection, album );
|
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
@@ -516,6 +516,7 @@ TomahawkApp::initLocalCollection()
|
|||||||
source_ptr src( new Source( 0, Database::instance()->impl()->dbid() ) );
|
source_ptr src( new Source( 0, Database::instance()->impl()->dbid() ) );
|
||||||
src->setFriendlyName( tr( "You" ) );
|
src->setFriendlyName( tr( "You" ) );
|
||||||
collection_ptr coll( new LocalCollection( src ) );
|
collection_ptr coll( new LocalCollection( src ) );
|
||||||
|
coll->setWeakRef( coll.toWeakRef() );
|
||||||
|
|
||||||
src->addCollection( coll );
|
src->addCollection( coll );
|
||||||
SourceList::instance()->setLocal( src );
|
SourceList::instance()->setLocal( src );
|
||||||
|
Reference in New Issue
Block a user