File indexing completed on 2024-05-05 04:49:16
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0004 * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #define DEBUG_PREFIX "ServiceCollection" 0020 0021 #include "ServiceCollection.h" 0022 0023 #include "amarokconfig.h" 0024 #include "core/support/Debug.h" 0025 #include "core-impl/collections/support/MemoryQueryMaker.h" 0026 #include "services/ServiceCollectionLocation.h" 0027 #include "services/ServiceMetaBase.h" 0028 0029 using namespace Collections; 0030 0031 0032 //ServiceCollection 0033 0034 ServiceCollection::ServiceCollection( ServiceBase * service ) 0035 : Collection() 0036 , m_service( service ) 0037 , m_mc( new MemoryCollection() ) 0038 { 0039 } 0040 0041 ServiceCollection::ServiceCollection( ServiceBase * service, const QString &id, const QString &prettyName ) 0042 : Collection() 0043 , m_service( service ) 0044 , m_mc( new MemoryCollection() ) 0045 , m_collectionId( id ) 0046 , m_prettyName( prettyName ) 0047 { 0048 } 0049 0050 ServiceCollection::~ServiceCollection() 0051 { 0052 } 0053 0054 Collections::QueryMaker* 0055 ServiceCollection::queryMaker() 0056 { 0057 return new Collections::MemoryQueryMaker( m_mc.toWeakRef(), collectionId() ); 0058 } 0059 0060 QString 0061 ServiceCollection::collectionId() const 0062 { 0063 return m_collectionId; 0064 } 0065 0066 QString 0067 ServiceCollection::prettyName() const 0068 { 0069 return m_prettyName; 0070 } 0071 0072 CollectionLocation* 0073 ServiceCollection::location() 0074 { 0075 return new ServiceCollectionLocation( this ); 0076 } 0077 0078 0079 ServiceBase * ServiceCollection::service() 0080 { 0081 return m_service; 0082 } 0083 0084 void ServiceCollection::emitUpdated() 0085 { 0086 Q_EMIT( updated() ); 0087 } 0088 0089 0090 void ServiceCollection::addTrack( const Meta::TrackPtr &trackPtr ) 0091 { 0092 m_mc->addTrack( trackPtr ); 0093 const Meta::ServiceTrackPtr track = Meta::ServiceTrackPtr::dynamicCast( trackPtr ); 0094 0095 if ( track && track->id() != 0 ) 0096 m_trackIdMap.insert( track->id(), trackPtr ); 0097 } 0098 0099 void ServiceCollection::addArtist( const Meta::ArtistPtr &artistPtr ) 0100 { 0101 m_mc->addArtist( artistPtr ); 0102 const Meta::ServiceArtistPtr artist = Meta::ServiceArtistPtr::dynamicCast( artistPtr ); 0103 0104 if ( artist && artist->id() != 0 ) 0105 m_artistIdMap.insert( artist->id(), artistPtr ); 0106 } 0107 0108 void ServiceCollection::addAlbum( const Meta::AlbumPtr &albumPtr ) 0109 { 0110 m_mc->addAlbum( albumPtr ); 0111 const Meta::ServiceAlbumPtr album = Meta::ServiceAlbumPtr::dynamicCast( albumPtr ); 0112 0113 if ( album && album->id() != 0 ) 0114 m_albumIdMap.insert( album->id(), albumPtr ); 0115 } 0116 0117 void ServiceCollection::addGenre( const Meta::GenrePtr &genrePtr ) 0118 { 0119 m_mc->addGenre( genrePtr ); 0120 const Meta::ServiceGenrePtr genre = Meta::ServiceGenrePtr::dynamicCast( genrePtr ); 0121 0122 if ( genre && genre->id() != 0 ) 0123 m_genreIdMap.insert( genre->id(), genrePtr ); 0124 } 0125 0126 Meta::TrackPtr ServiceCollection::trackById( int id ) 0127 { 0128 return m_trackIdMap.value( id ); 0129 } 0130 0131 Meta::AlbumPtr ServiceCollection::albumById( int id ) 0132 { 0133 return m_albumIdMap.value( id ); 0134 } 0135 0136 Meta::ArtistPtr ServiceCollection::artistById( int id ) 0137 { 0138 return m_artistIdMap.value( id ); 0139 } 0140 0141 Meta::GenrePtr ServiceCollection::genreById( int id ) 0142 { 0143 return m_genreIdMap.value( id ); 0144 } 0145 0146 0147