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

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
0003  * Copyright (c) 2008 Peter ZHOU <peterzhoulei@gmail.com>                               *
0004  * Copyright (c) 2008-2009 Nikolaj Hald Nielsen <nhn@kde.org>                           *
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 #ifndef AMAROK_SCRIPTABLE_SERVICE_META_P_H
0020 #define AMAROK_SCRIPTABLE_SERVICE_META_P_H
0021 
0022 
0023 #include "core/support/Debug.h"
0024 #include "core/meta/Meta.h"
0025 #include "core/capabilities/SourceInfoCapability.h"
0026 
0027 #include <QObject>
0028 #include <QPixmap>
0029 #include <QPointer>
0030 #include <QString>
0031 
0032 #include <KLocalizedString>
0033 
0034 
0035 
0036 // internal helper classes
0037 
0038 
0039 /**
0040  * Base class for the private meta types. This is used to give these private items source info capability which is needed in some cases,for instance when bookmarking.
0041  */
0042 class ScriptableServiceInternalMetaItem
0043 {
0044     public:
0045 
0046         QString serviceName() { return m_serviceName; }
0047         QString serviceDescription() { return m_serviceDescription; }
0048         QPixmap serviceEmblem() { return m_serviceEmblem; }
0049         QString serviceScalableEmblem() { return m_serviceScalableEmblem; }
0050 
0051         void setServiceName( const QString &name ) { m_serviceName = name; }
0052         void setServiceDescription( const QString &description ) { m_serviceDescription = description; }
0053         void setServiceEmblem( const QPixmap &emblem ) { m_serviceEmblem = emblem; }
0054         void setServiceScalableEmblem( const QString &emblemPath ) { m_serviceScalableEmblem = emblemPath; }
0055 
0056     protected:
0057         QString m_serviceName;
0058         QString m_serviceDescription;
0059         QPixmap m_serviceEmblem;
0060         QString m_serviceScalableEmblem;
0061 };
0062 
0063 
0064 class AMAROK_EXPORT ScriptableServiceInternalSourceInfoCapability : public Capabilities::SourceInfoCapability
0065 {
0066     public:
0067         explicit ScriptableServiceInternalSourceInfoCapability( ScriptableServiceInternalMetaItem * sourceInfoProvider )
0068         {
0069             m_sourceInfoProvider = sourceInfoProvider;
0070         }
0071         ~ScriptableServiceInternalSourceInfoCapability() override {}
0072 
0073         QString sourceName() override { return m_sourceInfoProvider->serviceName(); }
0074         QString sourceDescription() override { return m_sourceInfoProvider->serviceDescription(); }
0075         QPixmap emblem() override { return m_sourceInfoProvider->serviceEmblem(); }
0076         QString scalableEmblem() override { return m_sourceInfoProvider->serviceScalableEmblem(); }
0077         
0078 
0079     private:
0080         ScriptableServiceInternalMetaItem * m_sourceInfoProvider;
0081 
0082 };
0083 
0084 
0085 class ScriptableServiceInternalArtist : public Meta::Artist, public ScriptableServiceInternalMetaItem
0086 {
0087     public:
0088         explicit ScriptableServiceInternalArtist( const QString &name = QString() )
0089         : Meta::Artist()
0090         , m_name( name )
0091         {}
0092 
0093         Meta::TrackList tracks() override
0094         {
0095             return Meta::TrackList();
0096         }
0097 
0098         QString name() const override
0099         {
0100             if( !m_name.isEmpty() )
0101                 return m_name;
0102             else
0103                 return i18nc( "The value is not known", "Unknown" );
0104         }
0105 
0106         QString prettyName() const override
0107         {
0108             return name();
0109         }
0110 
0111         bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override
0112         {
0113             return ( type == Capabilities::Capability::SourceInfo );
0114         }
0115 
0116         Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override
0117         {
0118             if ( type == Capabilities::Capability::SourceInfo )
0119                 return new ScriptableServiceInternalSourceInfoCapability( this );
0120             return nullptr;
0121         }
0122 
0123 private:
0124     QString m_name;
0125 
0126 };
0127 
0128 class ScriptableServiceInternalAlbum : public Meta::ServiceAlbumWithCover, public ScriptableServiceInternalMetaItem
0129 {
0130     public:
0131         explicit ScriptableServiceInternalAlbum( const QString &name = QString() )
0132         : Meta::ServiceAlbumWithCover( QString() )
0133         , m_name( name )
0134         {}
0135 
0136         bool isCompilation() const override
0137         {
0138             return false;
0139         }
0140 
0141         bool hasAlbumArtist() const override
0142         {
0143             return false;
0144         }
0145 
0146         Meta::ArtistPtr albumArtist() const override
0147         {
0148             return Meta::ArtistPtr();
0149         }
0150 
0151         Meta::TrackList tracks() override
0152         {
0153             return Meta::TrackList();
0154         }
0155 
0156         QString name() const override
0157         {
0158             if( !m_name.isEmpty() )
0159                 return m_name;
0160             else
0161                 return i18nc( "The value is not known", "Unknown" );
0162         }
0163 
0164         QString prettyName() const override
0165         {
0166             return name();
0167         }
0168 
0169         QString downloadPrefix() const override { return QStringLiteral("script"); }
0170         void setCoverUrl( const QString &coverUrl ) override { m_coverUrl = coverUrl; }
0171         QString coverUrl() const override { return m_coverUrl; }
0172 
0173         QUrl imageLocation( int size = 1 ) override { Q_UNUSED( size ); return QUrl( coverUrl() ); }
0174 
0175         bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override
0176         {
0177             return ( type == Capabilities::Capability::SourceInfo );
0178         }
0179 
0180         Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override
0181         {
0182             if ( type == Capabilities::Capability::SourceInfo )
0183                 return new ScriptableServiceInternalSourceInfoCapability( this );
0184             return nullptr;
0185         }
0186 
0187     private:
0188         QString m_name;
0189         QString m_coverUrl;
0190 };
0191 
0192 class ScriptableServiceInternalGenre : public Meta::Genre, public ScriptableServiceInternalMetaItem
0193 {
0194     public:
0195         explicit ScriptableServiceInternalGenre( const QString &name = QString() )
0196         : Meta::Genre()
0197         , m_name( name )
0198         {}
0199 
0200         Meta::TrackList tracks() override
0201         {
0202             return Meta::TrackList();
0203         }
0204 
0205         QString name() const override
0206         {
0207             if( !m_name.isEmpty() )
0208                 return m_name;
0209             else
0210                 return i18nc( "The value is not known", "Unknown" );
0211         }
0212 
0213         QString prettyName() const override
0214         {
0215             return name();
0216         }
0217 
0218         bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override
0219         {
0220             return ( type == Capabilities::Capability::SourceInfo );
0221         }
0222 
0223         Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override
0224         {
0225             if ( type == Capabilities::Capability::SourceInfo )
0226                 return new ScriptableServiceInternalSourceInfoCapability( this );
0227             return nullptr;
0228         }
0229 
0230     private:
0231         QString m_name;
0232 };
0233 
0234 class ScriptableServiceInternalComposer : public Meta::Composer, public ScriptableServiceInternalMetaItem
0235 {
0236     public:
0237         explicit ScriptableServiceInternalComposer( const QString &name = QString() )
0238         : Meta::Composer()
0239         , m_name( name )
0240         {}
0241 
0242         Meta::TrackList tracks() override
0243         {
0244             return Meta::TrackList();
0245         }
0246 
0247         QString name() const override
0248         {
0249 
0250             if( !m_name.isEmpty() )
0251                 return m_name;
0252             else
0253                 return i18nc( "The value is not known", "Unknown" );
0254         }
0255 
0256         QString prettyName() const override
0257         {
0258             return name();
0259         }
0260 
0261         bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override
0262         {
0263             return ( type == Capabilities::Capability::SourceInfo );
0264         }
0265 
0266         Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override
0267         {
0268             if ( type == Capabilities::Capability::SourceInfo )
0269                 return new ScriptableServiceInternalSourceInfoCapability( this );
0270             return nullptr;
0271         }
0272 
0273     private:
0274         QString m_name;
0275 };
0276 
0277 class ScriptableServiceInternalYear : public Meta::Year, public ScriptableServiceInternalMetaItem
0278 {
0279     public:
0280         explicit ScriptableServiceInternalYear( const QString &name = QString() )
0281         : Meta::Year()
0282         , m_name( name )
0283         {}
0284 
0285         Meta::TrackList tracks() override
0286         {
0287             return Meta::TrackList();
0288         }
0289 
0290         QString name() const override
0291         {
0292             if( !m_name.isEmpty() )
0293                 return m_name;
0294             else
0295                 return i18nc( "The value is not known", "Unknown" );
0296         }
0297 
0298         QString prettyName() const override
0299         {
0300             return name();
0301         }
0302 
0303         bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override
0304         {
0305             return ( type == Capabilities::Capability::SourceInfo );
0306         }
0307 
0308         Capabilities::Capability* createCapabilityInterface( Capabilities::Capability::Type type ) override
0309         {
0310             if ( type == Capabilities::Capability::SourceInfo )
0311                 return new ScriptableServiceInternalSourceInfoCapability( this );
0312             return nullptr;
0313         }
0314 
0315     private:
0316         QString m_name;
0317 };
0318 
0319 
0320 #endif