File indexing completed on 2024-05-19 04:50:25
0001 /**************************************************************************************** 0002 * Copyright (c) 2007-2009 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "ScriptableServiceMeta.h" 0018 #include "ScriptableServiceMeta_p.h" 0019 0020 #include "core/meta/support/PrivateMetaRegistry.h" 0021 #include "core-impl/meta/multi/MultiTrack.h" 0022 #include "core-impl/playlists/types/file/PlaylistFileSupport.h" 0023 #include "services/scriptable/ScriptableService.h" 0024 #include "services/scriptable/ScriptableServiceManager.h" 0025 0026 using namespace Meta; 0027 0028 ScriptableServiceMetaItem::ScriptableServiceMetaItem( int level ) 0029 : m_callbackString( QString() ) 0030 , m_level( level ) 0031 , m_serviceName( QString() ) 0032 , m_serviceDescription( QString() ) 0033 , m_serviceEmblem( QPixmap() ) 0034 {} 0035 0036 void Meta::ScriptableServiceMetaItem::setCallbackString( const QString &callbackString ) 0037 { 0038 m_callbackString = callbackString; 0039 } 0040 0041 QString Meta::ScriptableServiceMetaItem::callbackString() const 0042 { 0043 return m_callbackString; 0044 } 0045 0046 int Meta::ScriptableServiceMetaItem::level() const 0047 { 0048 return m_level; 0049 } 0050 0051 void Meta::ScriptableServiceMetaItem::setServiceName( const QString & name ) 0052 { 0053 m_serviceName = name; 0054 } 0055 0056 void Meta::ScriptableServiceMetaItem::setServiceDescription( const QString & description ) 0057 { 0058 m_serviceDescription = description; 0059 } 0060 0061 void Meta::ScriptableServiceMetaItem::setServiceEmblem( const QPixmap & emblem ) 0062 { 0063 m_serviceEmblem = emblem; 0064 } 0065 0066 void Meta::ScriptableServiceMetaItem::setServiceScalableEmblem ( const QString& emblemPath ) 0067 { 0068 m_serviceScalableEmblem = emblemPath; 0069 } 0070 0071 0072 /* ScriptableServiceTrack */ 0073 ScriptableServiceTrack::ScriptableServiceTrack( const QString & name ) 0074 : ServiceTrack( name ) 0075 , ScriptableServiceMetaItem( 0 ) 0076 {} 0077 0078 ScriptableServiceTrack::ScriptableServiceTrack( const QStringList & resultRow ) 0079 : ServiceTrack( resultRow ) 0080 , ScriptableServiceMetaItem( 0 ) 0081 {} 0082 0083 0084 void Meta::ScriptableServiceTrack::setAlbumName( const QString &newAlbum ) 0085 { 0086 Meta::AlbumPtr albumPtr = Meta::PrivateMetaRegistry::instance()->album( m_serviceName, newAlbum ); 0087 if ( !albumPtr ) { 0088 ScriptableServiceInternalAlbum * intAlbum = new ScriptableServiceInternalAlbum( newAlbum ); 0089 intAlbum->setServiceName( m_serviceName ); 0090 intAlbum->setServiceDescription( m_serviceDescription ); 0091 intAlbum->setServiceEmblem( m_serviceEmblem ); 0092 intAlbum->setServiceScalableEmblem( m_serviceScalableEmblem ); 0093 albumPtr = Meta::AlbumPtr( intAlbum ); 0094 Meta::PrivateMetaRegistry::instance()->insertAlbum( m_serviceName, newAlbum, albumPtr ); 0095 } 0096 0097 setAlbumPtr( albumPtr ); 0098 } 0099 0100 void Meta::ScriptableServiceTrack::setArtistName( const QString &newArtist ) 0101 { 0102 Meta::ArtistPtr artistPtr = Meta::PrivateMetaRegistry::instance()->artist( m_serviceName, newArtist ); 0103 if ( !artistPtr ) { 0104 ScriptableServiceInternalArtist * intArtist = new ScriptableServiceInternalArtist( newArtist ); 0105 intArtist->setServiceName( m_serviceName ); 0106 intArtist->setServiceDescription( m_serviceDescription ); 0107 intArtist->setServiceEmblem( m_serviceEmblem ); 0108 intArtist->setServiceScalableEmblem( m_serviceScalableEmblem ); 0109 artistPtr = Meta::ArtistPtr( intArtist ); 0110 Meta::PrivateMetaRegistry::instance()->insertArtist( m_serviceName, newArtist, artistPtr ); 0111 } 0112 0113 setArtist( artistPtr ); 0114 } 0115 0116 void Meta::ScriptableServiceTrack::setGenreName( const QString &newGenre ) 0117 { 0118 Meta::GenrePtr genrePtr = Meta::PrivateMetaRegistry::instance()->genre( m_serviceName, newGenre ); 0119 if ( !genrePtr ) { 0120 ScriptableServiceInternalGenre * intGenre = new ScriptableServiceInternalGenre( newGenre ); 0121 intGenre->setServiceName( m_serviceName ); 0122 intGenre->setServiceDescription( m_serviceDescription ); 0123 intGenre->setServiceEmblem( m_serviceEmblem ); 0124 intGenre->setServiceScalableEmblem( m_serviceScalableEmblem ); 0125 genrePtr = Meta::GenrePtr( intGenre ); 0126 Meta::PrivateMetaRegistry::instance()->insertGenre( m_serviceName, newGenre, genrePtr ); 0127 } 0128 0129 setGenre( genrePtr ); 0130 } 0131 0132 void Meta::ScriptableServiceTrack::setComposerName( const QString &newComposer ) 0133 { 0134 Meta::ComposerPtr composerPtr = Meta::PrivateMetaRegistry::instance()->composer( m_serviceName, newComposer ); 0135 if ( !composerPtr ) { 0136 ScriptableServiceInternalComposer * intComposer = new ScriptableServiceInternalComposer( newComposer); 0137 intComposer->setServiceName( m_serviceName ); 0138 intComposer->setServiceDescription( m_serviceDescription ); 0139 intComposer->setServiceEmblem( m_serviceEmblem ); 0140 intComposer->setServiceScalableEmblem( m_serviceScalableEmblem ); 0141 composerPtr = Meta::ComposerPtr( intComposer ); 0142 Meta::PrivateMetaRegistry::instance()->insertComposer( m_serviceName, newComposer, composerPtr ); 0143 } 0144 0145 setComposer( composerPtr ); 0146 } 0147 0148 void Meta::ScriptableServiceTrack::setYearNumber( int newYear ) 0149 { 0150 const QString yearString = QString::number( newYear ); 0151 0152 Meta::YearPtr yearPtr = Meta::PrivateMetaRegistry::instance()->year( m_serviceName, yearString ); 0153 if ( !yearPtr ) { 0154 ScriptableServiceInternalYear * intYear = new ScriptableServiceInternalYear( yearString ); 0155 intYear->setServiceName( m_serviceName ); 0156 intYear->setServiceDescription( m_serviceDescription ); 0157 intYear->setServiceEmblem( m_serviceEmblem ); 0158 intYear->setServiceScalableEmblem( m_serviceScalableEmblem ); 0159 yearPtr = Meta::YearPtr( intYear ); 0160 Meta::PrivateMetaRegistry::instance()->insertYear( m_serviceName, yearString, yearPtr ); 0161 } 0162 0163 setYear( yearPtr ); 0164 } 0165 0166 void Meta::ScriptableServiceTrack::setCustomAlbumCoverUrl( const QString & coverurl ) 0167 { 0168 DEBUG_BLOCK 0169 if ( album() ) { 0170 debug() << "one"; 0171 ServiceAlbumWithCoverPtr albumWithCover = ServiceAlbumWithCoverPtr::dynamicCast( album() ); 0172 if ( albumWithCover ) { 0173 debug() << "two"; 0174 albumWithCover->setCoverUrl( coverurl ); 0175 } 0176 } 0177 } 0178 0179 0180 QString Meta::ScriptableServiceTrack::sourceName() 0181 { 0182 return m_serviceName; 0183 } 0184 0185 QString Meta::ScriptableServiceTrack::sourceDescription() 0186 { 0187 return m_serviceDescription; 0188 } 0189 0190 QPixmap Meta::ScriptableServiceTrack::emblem() 0191 { 0192 return m_serviceEmblem; 0193 } 0194 0195 QString Meta::ScriptableServiceTrack::scalableEmblem() 0196 { 0197 return m_serviceScalableEmblem; 0198 } 0199 0200 void ScriptableServiceTrack::setUidUrl( const QString &url ) 0201 { 0202 Meta::ServiceTrack::setUidUrl( url ); 0203 0204 using namespace Playlists; 0205 Meta::TrackPtr track( this ); 0206 PlaylistPtr playlist = canExpand( track ) ? expand( track ) : PlaylistPtr(); 0207 if( playlist ) 0208 // since this is a playlist masqueurading as a single track, make a MultiTrack out of it: 0209 m_playableTrack = Meta::TrackPtr( new Meta::MultiTrack( playlist ) ); 0210 else 0211 m_playableTrack = TrackPtr(); 0212 } 0213 0214 TrackPtr ScriptableServiceTrack::playableTrack() const 0215 { 0216 return m_playableTrack ? m_playableTrack : TrackPtr( const_cast<ScriptableServiceTrack *>( this ) ); 0217 } 0218 0219 0220 /* DynamicScriptableAlbum */ 0221 ScriptableServiceAlbum::ScriptableServiceAlbum( const QString & name ) 0222 : ServiceAlbumWithCover( name ) 0223 , ScriptableServiceMetaItem( 1 ) 0224 {} 0225 0226 ScriptableServiceAlbum::ScriptableServiceAlbum( const QStringList & resultRow ) 0227 : ServiceAlbumWithCover( resultRow ) 0228 , ScriptableServiceMetaItem( 1 ) 0229 {} 0230 0231 QString Meta::ScriptableServiceAlbum::sourceName() 0232 { 0233 return m_serviceName; 0234 } 0235 0236 QString Meta::ScriptableServiceAlbum::sourceDescription() 0237 { 0238 return m_serviceDescription; 0239 } 0240 0241 QPixmap Meta::ScriptableServiceAlbum::emblem() 0242 { 0243 return m_serviceEmblem; 0244 } 0245 0246 QString Meta::ScriptableServiceAlbum::scalableEmblem() 0247 { 0248 return m_serviceScalableEmblem; 0249 } 0250 0251 bool Meta::ScriptableServiceAlbum::isBookmarkable() const 0252 { 0253 ScriptableService * service = The::scriptableServiceManager()->service( m_serviceName ); 0254 if ( service ) 0255 return service->hasSearchBar(); 0256 else 0257 return false; 0258 } 0259 0260 0261 0262 /* ScriptableServiceArtist */ 0263 ScriptableServiceArtist::ScriptableServiceArtist( const QString & name ) 0264 : ServiceArtist( name ) 0265 , ScriptableServiceMetaItem( 2 ) 0266 , m_genreId( 0 ) 0267 {} 0268 0269 ScriptableServiceArtist::ScriptableServiceArtist( const QStringList & resultRow ) 0270 : ServiceArtist( resultRow ) 0271 , ScriptableServiceMetaItem( 2 ) 0272 , m_genreId( 0 ) 0273 {} 0274 0275 0276 void Meta::ScriptableServiceArtist::setGenreId(int genreId) 0277 { 0278 m_genreId = genreId; 0279 } 0280 0281 0282 int Meta::ScriptableServiceArtist::genreId() const 0283 { 0284 return m_genreId; 0285 } 0286 0287 QString Meta::ScriptableServiceArtist::sourceName() 0288 { 0289 return m_serviceName; 0290 } 0291 0292 QString Meta::ScriptableServiceArtist::sourceDescription() 0293 { 0294 return m_serviceDescription; 0295 } 0296 0297 QPixmap Meta::ScriptableServiceArtist::emblem() 0298 { 0299 return m_serviceEmblem; 0300 } 0301 0302 QString Meta::ScriptableServiceArtist::scalableEmblem() 0303 { 0304 return m_serviceScalableEmblem; 0305 } 0306 0307 bool Meta::ScriptableServiceArtist::isBookmarkable() const 0308 { 0309 ScriptableService * service = The::scriptableServiceManager()->service( m_serviceName ); 0310 if ( service ) 0311 return service->hasSearchBar(); 0312 else 0313 return false; 0314 } 0315 0316 0317 /* ScriptableServiceGenre */ 0318 ScriptableServiceGenre::ScriptableServiceGenre( const QString & name ) 0319 : ServiceGenre( name ) 0320 , ScriptableServiceMetaItem( 3 ) 0321 {} 0322 0323 ScriptableServiceGenre::ScriptableServiceGenre( const QStringList & resultRow ) 0324 : ServiceGenre( resultRow ) 0325 , ScriptableServiceMetaItem( 3 ) 0326 {} 0327 0328 0329 void Meta::ScriptableServiceGenre::setDescription(const QString & description) 0330 { 0331 m_description = description; 0332 } 0333 0334 QString Meta::ScriptableServiceGenre::description() 0335 { 0336 return m_description; 0337 } 0338 0339 QString Meta::ScriptableServiceGenre::sourceName() 0340 { 0341 return m_serviceName; 0342 } 0343 0344 QString Meta::ScriptableServiceGenre::sourceDescription() 0345 { 0346 return m_serviceDescription; 0347 } 0348 0349 QPixmap Meta::ScriptableServiceGenre::emblem() 0350 { 0351 return m_serviceEmblem; 0352 } 0353 0354 QString Meta::ScriptableServiceGenre::scalableEmblem() 0355 { 0356 return m_serviceScalableEmblem; 0357 } 0358 0359 0360 0361 0362 0363 0364