1 /****************************************************************************************
2  * Copyright (c) 2007-2009 Nikolaj Hald Nielsen <nhn@kde.org>                           *
3  *                                                                                      *
4  * This program is free software; you can redistribute it and/or modify it under        *
5  * the terms of the GNU General Public License as published by the Free Software        *
6  * Foundation; either version 2 of the License, or (at your option) any later           *
7  * version.                                                                             *
8  *                                                                                      *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12  *                                                                                      *
13  * You should have received a copy of the GNU General Public License along with         *
14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15  ****************************************************************************************/
16 
17 #include "ScriptableServiceMeta.h"
18 #include "ScriptableServiceMeta_p.h"
19 
20 #include "core/meta/support/PrivateMetaRegistry.h"
21 #include "core-impl/meta/multi/MultiTrack.h"
22 #include "core-impl/playlists/types/file/PlaylistFileSupport.h"
23 #include "services/scriptable/ScriptableService.h"
24 #include "services/scriptable/ScriptableServiceManager.h"
25 
26 using namespace Meta;
27 
ScriptableServiceMetaItem(int level)28 ScriptableServiceMetaItem::ScriptableServiceMetaItem( int level )
29     : m_callbackString( QString() )
30     , m_level( level )
31     , m_serviceName( QString() )
32     , m_serviceDescription( QString() )
33     , m_serviceEmblem( QPixmap() )
34 {}
35 
setCallbackString(const QString & callbackString)36 void Meta::ScriptableServiceMetaItem::setCallbackString( const QString &callbackString )
37 {
38     m_callbackString = callbackString;
39 }
40 
callbackString() const41 QString Meta::ScriptableServiceMetaItem::callbackString() const
42 {
43     return m_callbackString;
44 }
45 
level() const46 int Meta::ScriptableServiceMetaItem::level() const
47 {
48     return m_level;
49 }
50 
setServiceName(const QString & name)51 void Meta::ScriptableServiceMetaItem::setServiceName( const QString & name )
52 {
53     m_serviceName = name;
54 }
55 
setServiceDescription(const QString & description)56 void Meta::ScriptableServiceMetaItem::setServiceDescription( const QString & description )
57 {
58     m_serviceDescription = description;
59 }
60 
setServiceEmblem(const QPixmap & emblem)61 void Meta::ScriptableServiceMetaItem::setServiceEmblem( const QPixmap & emblem )
62 {
63     m_serviceEmblem = emblem;
64 }
65 
setServiceScalableEmblem(const QString & emblemPath)66 void Meta::ScriptableServiceMetaItem::setServiceScalableEmblem ( const QString& emblemPath )
67 {
68     m_serviceScalableEmblem = emblemPath;
69 }
70 
71 
72 /* ScriptableServiceTrack */
ScriptableServiceTrack(const QString & name)73 ScriptableServiceTrack::ScriptableServiceTrack( const QString & name )
74     : ServiceTrack( name )
75     , ScriptableServiceMetaItem( 0 )
76 {}
77 
ScriptableServiceTrack(const QStringList & resultRow)78 ScriptableServiceTrack::ScriptableServiceTrack( const QStringList & resultRow )
79     : ServiceTrack( resultRow )
80     , ScriptableServiceMetaItem( 0 )
81 {}
82 
83 
setAlbumName(const QString & newAlbum)84 void Meta::ScriptableServiceTrack::setAlbumName( const QString &newAlbum )
85 {
86     Meta::AlbumPtr albumPtr = Meta::PrivateMetaRegistry::instance()->album( m_serviceName, newAlbum );
87     if ( !albumPtr ) {
88         ScriptableServiceInternalAlbum * intAlbum = new ScriptableServiceInternalAlbum( newAlbum );
89         intAlbum->setServiceName( m_serviceName );
90         intAlbum->setServiceDescription( m_serviceDescription );
91         intAlbum->setServiceEmblem( m_serviceEmblem );
92         intAlbum->setServiceScalableEmblem( m_serviceScalableEmblem );
93         albumPtr = Meta::AlbumPtr( intAlbum );
94         Meta::PrivateMetaRegistry::instance()->insertAlbum( m_serviceName, newAlbum, albumPtr );
95     }
96 
97     setAlbumPtr( albumPtr );
98 }
99 
setArtistName(const QString & newArtist)100 void Meta::ScriptableServiceTrack::setArtistName( const QString &newArtist )
101 {
102     Meta::ArtistPtr artistPtr = Meta::PrivateMetaRegistry::instance()->artist( m_serviceName, newArtist );
103     if ( !artistPtr ) {
104         ScriptableServiceInternalArtist * intArtist = new ScriptableServiceInternalArtist( newArtist );
105         intArtist->setServiceName( m_serviceName );
106         intArtist->setServiceDescription( m_serviceDescription );
107         intArtist->setServiceEmblem( m_serviceEmblem );
108         intArtist->setServiceScalableEmblem( m_serviceScalableEmblem );
109         artistPtr = Meta::ArtistPtr( intArtist );
110         Meta::PrivateMetaRegistry::instance()->insertArtist( m_serviceName, newArtist, artistPtr );
111     }
112 
113     setArtist( artistPtr );
114 }
115 
setGenreName(const QString & newGenre)116 void Meta::ScriptableServiceTrack::setGenreName( const QString &newGenre )
117 {
118     Meta::GenrePtr genrePtr = Meta::PrivateMetaRegistry::instance()->genre( m_serviceName, newGenre );
119     if ( !genrePtr ) {
120         ScriptableServiceInternalGenre * intGenre = new ScriptableServiceInternalGenre( newGenre );
121         intGenre->setServiceName( m_serviceName );
122         intGenre->setServiceDescription( m_serviceDescription );
123         intGenre->setServiceEmblem( m_serviceEmblem );
124         intGenre->setServiceScalableEmblem( m_serviceScalableEmblem );
125         genrePtr = Meta::GenrePtr( intGenre );
126         Meta::PrivateMetaRegistry::instance()->insertGenre( m_serviceName, newGenre, genrePtr );
127     }
128 
129     setGenre( genrePtr );
130 }
131 
setComposerName(const QString & newComposer)132 void Meta::ScriptableServiceTrack::setComposerName( const QString &newComposer )
133 {
134     Meta::ComposerPtr composerPtr = Meta::PrivateMetaRegistry::instance()->composer( m_serviceName, newComposer );
135     if ( !composerPtr ) {
136         ScriptableServiceInternalComposer * intComposer = new ScriptableServiceInternalComposer( newComposer);
137         intComposer->setServiceName( m_serviceName );
138         intComposer->setServiceDescription( m_serviceDescription );
139         intComposer->setServiceEmblem( m_serviceEmblem );
140         intComposer->setServiceScalableEmblem( m_serviceScalableEmblem );
141         composerPtr = Meta::ComposerPtr( intComposer );
142         Meta::PrivateMetaRegistry::instance()->insertComposer( m_serviceName, newComposer, composerPtr );
143     }
144 
145     setComposer( composerPtr );
146 }
147 
setYearNumber(int newYear)148 void Meta::ScriptableServiceTrack::setYearNumber( int newYear )
149 {
150     const QString yearString = QString::number( newYear );
151 
152     Meta::YearPtr yearPtr = Meta::PrivateMetaRegistry::instance()->year( m_serviceName, yearString );
153     if ( !yearPtr ) {
154         ScriptableServiceInternalYear * intYear = new ScriptableServiceInternalYear( yearString );
155         intYear->setServiceName( m_serviceName );
156         intYear->setServiceDescription( m_serviceDescription );
157         intYear->setServiceEmblem( m_serviceEmblem );
158         intYear->setServiceScalableEmblem( m_serviceScalableEmblem );
159         yearPtr = Meta::YearPtr( intYear );
160         Meta::PrivateMetaRegistry::instance()->insertYear( m_serviceName, yearString, yearPtr );
161     }
162 
163     setYear( yearPtr );
164 }
165 
setCustomAlbumCoverUrl(const QString & coverurl)166 void Meta::ScriptableServiceTrack::setCustomAlbumCoverUrl( const QString & coverurl )
167 {
168     DEBUG_BLOCK
169     if ( album() ) {
170         debug() << "one";
171         ServiceAlbumWithCoverPtr albumWithCover = ServiceAlbumWithCoverPtr::dynamicCast( album() );
172         if ( albumWithCover ) {
173             debug() << "two";
174             albumWithCover->setCoverUrl( coverurl );
175         }
176     }
177 }
178 
179 
sourceName()180 QString Meta::ScriptableServiceTrack::sourceName()
181 {
182     return m_serviceName;
183 }
184 
sourceDescription()185 QString Meta::ScriptableServiceTrack::sourceDescription()
186 {
187     return m_serviceDescription;
188 }
189 
emblem()190 QPixmap Meta::ScriptableServiceTrack::emblem()
191 {
192     return m_serviceEmblem;
193 }
194 
scalableEmblem()195 QString Meta::ScriptableServiceTrack::scalableEmblem()
196 {
197     return  m_serviceScalableEmblem;
198 }
199 
setUidUrl(const QString & url)200 void ScriptableServiceTrack::setUidUrl( const QString &url )
201 {
202     Meta::ServiceTrack::setUidUrl( url );
203 
204     using namespace Playlists;
205     Meta::TrackPtr track( this );
206     PlaylistPtr playlist = canExpand( track ) ? expand( track ) : PlaylistPtr();
207     if( playlist )
208         // since this is a playlist masqueurading as a single track, make a MultiTrack out of it:
209         m_playableTrack = Meta::TrackPtr( new Meta::MultiTrack( playlist ) );
210     else
211         m_playableTrack = TrackPtr();
212 }
213 
playableTrack() const214 TrackPtr ScriptableServiceTrack::playableTrack() const
215 {
216     return m_playableTrack ? m_playableTrack : TrackPtr( const_cast<ScriptableServiceTrack *>( this ) );
217 }
218 
219 
220 /* DynamicScriptableAlbum */
ScriptableServiceAlbum(const QString & name)221 ScriptableServiceAlbum::ScriptableServiceAlbum( const QString & name )
222     : ServiceAlbumWithCover( name )
223     , ScriptableServiceMetaItem( 1 )
224 {}
225 
ScriptableServiceAlbum(const QStringList & resultRow)226 ScriptableServiceAlbum::ScriptableServiceAlbum( const QStringList & resultRow )
227     : ServiceAlbumWithCover( resultRow )
228     , ScriptableServiceMetaItem( 1 )
229 {}
230 
sourceName()231 QString Meta::ScriptableServiceAlbum::sourceName()
232 {
233     return m_serviceName;
234 }
235 
sourceDescription()236 QString Meta::ScriptableServiceAlbum::sourceDescription()
237 {
238     return m_serviceDescription;
239 }
240 
emblem()241 QPixmap Meta::ScriptableServiceAlbum::emblem()
242 {
243     return m_serviceEmblem;
244 }
245 
scalableEmblem()246 QString Meta::ScriptableServiceAlbum::scalableEmblem()
247 {
248     return  m_serviceScalableEmblem;
249 }
250 
isBookmarkable() const251 bool Meta::ScriptableServiceAlbum::isBookmarkable() const
252 {
253     ScriptableService * service = The::scriptableServiceManager()->service( m_serviceName );
254     if ( service )
255         return service->hasSearchBar();
256     else
257         return false;
258 }
259 
260 
261 
262 /* ScriptableServiceArtist */
ScriptableServiceArtist(const QString & name)263 ScriptableServiceArtist::ScriptableServiceArtist( const QString & name )
264     : ServiceArtist( name )
265     , ScriptableServiceMetaItem( 2 )
266     , m_genreId( 0 )
267 {}
268 
ScriptableServiceArtist(const QStringList & resultRow)269 ScriptableServiceArtist::ScriptableServiceArtist( const QStringList & resultRow )
270     : ServiceArtist( resultRow )
271     , ScriptableServiceMetaItem( 2 )
272     , m_genreId( 0 )
273 {}
274 
275 
setGenreId(int genreId)276 void Meta::ScriptableServiceArtist::setGenreId(int genreId)
277 {
278     m_genreId = genreId;
279 }
280 
281 
genreId() const282 int Meta::ScriptableServiceArtist::genreId() const
283 {
284     return m_genreId;
285 }
286 
sourceName()287 QString Meta::ScriptableServiceArtist::sourceName()
288 {
289     return m_serviceName;
290 }
291 
sourceDescription()292 QString Meta::ScriptableServiceArtist::sourceDescription()
293 {
294     return m_serviceDescription;
295 }
296 
emblem()297 QPixmap Meta::ScriptableServiceArtist::emblem()
298 {
299     return m_serviceEmblem;
300 }
301 
scalableEmblem()302 QString Meta::ScriptableServiceArtist::scalableEmblem()
303 {
304     return  m_serviceScalableEmblem;
305 }
306 
isBookmarkable() const307 bool Meta::ScriptableServiceArtist::isBookmarkable()  const
308 {
309     ScriptableService * service = The::scriptableServiceManager()->service( m_serviceName );
310     if ( service )
311         return service->hasSearchBar();
312     else
313         return false;
314 }
315 
316 
317 /* ScriptableServiceGenre */
ScriptableServiceGenre(const QString & name)318 ScriptableServiceGenre::ScriptableServiceGenre( const QString & name )
319     : ServiceGenre( name )
320     , ScriptableServiceMetaItem( 3 )
321 {}
322 
ScriptableServiceGenre(const QStringList & resultRow)323 ScriptableServiceGenre::ScriptableServiceGenre( const QStringList & resultRow )
324     : ServiceGenre( resultRow )
325     , ScriptableServiceMetaItem( 3 )
326 {}
327 
328 
setDescription(const QString & description)329 void Meta::ScriptableServiceGenre::setDescription(const QString & description)
330 {
331     m_description = description;
332 }
333 
description()334 QString Meta::ScriptableServiceGenre::description()
335 {
336     return m_description;
337 }
338 
sourceName()339 QString Meta::ScriptableServiceGenre::sourceName()
340 {
341     return m_serviceName;
342 }
343 
sourceDescription()344 QString Meta::ScriptableServiceGenre::sourceDescription()
345 {
346     return m_serviceDescription;
347 }
348 
emblem()349 QPixmap Meta::ScriptableServiceGenre::emblem()
350 {
351     return m_serviceEmblem;
352 }
353 
scalableEmblem()354 QString Meta::ScriptableServiceGenre::scalableEmblem()
355 {
356     return  m_serviceScalableEmblem;
357 }
358 
359 
360 
361 
362 
363 
364 
365