1 /****************************************************************************************
2 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> *
3 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> *
4 * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License as published by the Free Software *
8 * Foundation; either version 2 of the License, or (at your option) any later *
9 * version. *
10 * *
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License along with *
16 * this program. If not, see <http://www.gnu.org/licenses/>. *
17 ****************************************************************************************/
18
19 #define DEBUG_PREFIX "ServiceCollection"
20
21 #include "ServiceCollection.h"
22
23 #include "amarokconfig.h"
24 #include "core/support/Debug.h"
25 #include "core-impl/collections/support/MemoryQueryMaker.h"
26 #include "services/ServiceCollectionLocation.h"
27 #include "services/ServiceMetaBase.h"
28
29 using namespace Collections;
30
31
32 //ServiceCollection
33
ServiceCollection(ServiceBase * service)34 ServiceCollection::ServiceCollection( ServiceBase * service )
35 : Collection()
36 , m_service( service )
37 , m_mc( new MemoryCollection() )
38 {
39 }
40
ServiceCollection(ServiceBase * service,const QString & id,const QString & prettyName)41 ServiceCollection::ServiceCollection( ServiceBase * service, const QString &id, const QString &prettyName )
42 : Collection()
43 , m_service( service )
44 , m_mc( new MemoryCollection() )
45 , m_collectionId( id )
46 , m_prettyName( prettyName )
47 {
48 }
49
~ServiceCollection()50 ServiceCollection::~ServiceCollection()
51 {
52 }
53
54 Collections::QueryMaker*
queryMaker()55 ServiceCollection::queryMaker()
56 {
57 return new Collections::MemoryQueryMaker( m_mc.toWeakRef(), collectionId() );
58 }
59
60 QString
collectionId() const61 ServiceCollection::collectionId() const
62 {
63 return m_collectionId;
64 }
65
66 QString
prettyName() const67 ServiceCollection::prettyName() const
68 {
69 return m_prettyName;
70 }
71
72 CollectionLocation*
location()73 ServiceCollection::location()
74 {
75 return new ServiceCollectionLocation( this );
76 }
77
78
service()79 ServiceBase * ServiceCollection::service()
80 {
81 return m_service;
82 }
83
emitUpdated()84 void ServiceCollection::emitUpdated()
85 {
86 Q_EMIT( updated() );
87 }
88
89
addTrack(const Meta::TrackPtr & trackPtr)90 void ServiceCollection::addTrack( const Meta::TrackPtr &trackPtr )
91 {
92 m_mc->addTrack( trackPtr );
93 const Meta::ServiceTrackPtr track = Meta::ServiceTrackPtr::dynamicCast( trackPtr );
94
95 if ( track && track->id() != 0 )
96 m_trackIdMap.insert( track->id(), trackPtr );
97 }
98
addArtist(const Meta::ArtistPtr & artistPtr)99 void ServiceCollection::addArtist( const Meta::ArtistPtr &artistPtr )
100 {
101 m_mc->addArtist( artistPtr );
102 const Meta::ServiceArtistPtr artist = Meta::ServiceArtistPtr::dynamicCast( artistPtr );
103
104 if ( artist && artist->id() != 0 )
105 m_artistIdMap.insert( artist->id(), artistPtr );
106 }
107
addAlbum(const Meta::AlbumPtr & albumPtr)108 void ServiceCollection::addAlbum( const Meta::AlbumPtr &albumPtr )
109 {
110 m_mc->addAlbum( albumPtr );
111 const Meta::ServiceAlbumPtr album = Meta::ServiceAlbumPtr::dynamicCast( albumPtr );
112
113 if ( album && album->id() != 0 )
114 m_albumIdMap.insert( album->id(), albumPtr );
115 }
116
addGenre(const Meta::GenrePtr & genrePtr)117 void ServiceCollection::addGenre( const Meta::GenrePtr &genrePtr )
118 {
119 m_mc->addGenre( genrePtr );
120 const Meta::ServiceGenrePtr genre = Meta::ServiceGenrePtr::dynamicCast( genrePtr );
121
122 if ( genre && genre->id() != 0 )
123 m_genreIdMap.insert( genre->id(), genrePtr );
124 }
125
trackById(int id)126 Meta::TrackPtr ServiceCollection::trackById( int id )
127 {
128 return m_trackIdMap.value( id );
129 }
130
albumById(int id)131 Meta::AlbumPtr ServiceCollection::albumById( int id )
132 {
133 return m_albumIdMap.value( id );
134 }
135
artistById(int id)136 Meta::ArtistPtr ServiceCollection::artistById( int id )
137 {
138 return m_artistIdMap.value( id );
139 }
140
genreById(int id)141 Meta::GenrePtr ServiceCollection::genreById( int id )
142 {
143 return m_genreIdMap.value( id );
144 }
145
146
147
148