File indexing completed on 2024-05-19 04:50:24

0001 /****************************************************************************************
0002  * Copyright (c) 2007 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 "ScriptableServiceInfoParser.h"
0018 
0019 #include "scripting/scriptmanager/ScriptManager.h"
0020 #include "services/ServiceMetaBase.h"
0021 
0022 using namespace Meta;
0023 
0024 ScriptableServiceInfoParser::ScriptableServiceInfoParser( const QString &serviceName )
0025  : InfoParserBase()
0026  , m_serviceName( serviceName )
0027 {
0028 }
0029 
0030 
0031 ScriptableServiceInfoParser::~ScriptableServiceInfoParser()
0032 {
0033 }
0034 
0035 void ScriptableServiceInfoParser::getInfo( const ArtistPtr &artist )
0036 {
0037     ScriptableServiceArtist * serviceArtist = dynamic_cast< ScriptableServiceArtist * >( artist.data() );
0038     if (!serviceArtist) return;
0039 
0040     Q_EMIT( info( serviceArtist->description() ) );
0041 
0042     if ( serviceArtist->description().isEmpty() )
0043     {
0044         showLoading( i18n( "Loading info..." ) );
0045         ScriptManager::instance()->ServiceScriptRequestInfo( m_serviceName, serviceArtist->level(), serviceArtist->callbackString() );
0046     }
0047 }
0048 
0049 void ScriptableServiceInfoParser::getInfo(const AlbumPtr &album)
0050 {
0051     DEBUG_BLOCK
0052     ScriptableServiceAlbum * serviceAlbum = dynamic_cast< ScriptableServiceAlbum * >( album.data() );
0053     if (serviceAlbum == nullptr) return;
0054 
0055     Q_EMIT( info( serviceAlbum->description() ) );
0056 
0057     if ( serviceAlbum->description().isEmpty() )
0058     {
0059         showLoading( i18n( "Loading info..." ) );
0060         ScriptManager::instance()->ServiceScriptRequestInfo( m_serviceName, serviceAlbum->level(), serviceAlbum->callbackString() );
0061     }
0062 }
0063 
0064 void ScriptableServiceInfoParser::getInfo(const TrackPtr &track)
0065 {
0066     DEBUG_BLOCK
0067     ScriptableServiceTrack * serviceTrack = dynamic_cast< ScriptableServiceTrack * >( track.data() );
0068     if (!serviceTrack) return;
0069 
0070     Q_EMIT  info( serviceTrack->description() );
0071 
0072     if ( serviceTrack->description().isEmpty() )
0073     {
0074         showLoading( i18n( "Loading info..." ) );
0075         ScriptManager::instance()->ServiceScriptRequestInfo( m_serviceName, serviceTrack->level(), serviceTrack->callbackString() );
0076     }
0077 }
0078 
0079 void ScriptableServiceInfoParser::getInfo( const Meta::GenrePtr &genre )
0080 {
0081     ScriptableServiceGenre * serviceGenre = dynamic_cast< ScriptableServiceGenre * >( genre.data() );
0082     if (!serviceGenre) return;
0083 
0084     Q_EMIT info( serviceGenre->description() );
0085 
0086     if ( serviceGenre->description().isEmpty() )
0087     {
0088         showLoading( i18n( "Loading info..." ) );
0089         ScriptManager::instance()->ServiceScriptRequestInfo( m_serviceName, serviceGenre->level(), serviceGenre->callbackString() );
0090     }
0091 }