File indexing completed on 2024-05-05 04:49:14
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 #ifndef AMAROKSCRIPTABLESERVICE_H 0018 #define AMAROKSCRIPTABLESERVICE_H 0019 0020 0021 #include "core/support/Amarok.h" 0022 #include "../ServiceBase.h" 0023 #include "ScriptableServiceMeta.h" 0024 #include "ScriptableServiceCollection.h" 0025 0026 0027 /* internally, we use the following level mapping: 0028 0 = track 0029 1 = album 0030 2 = artist 0031 3 = genre 0032 0033 but we do our best to make this invisible to the scripts 0034 */ 0035 0036 typedef QMap<int, Meta::ScriptableServiceTrack *> ScriptableServiceTrackIdMap; 0037 typedef QMap<int, Meta::ScriptableServiceArtist *> ScriptableServiceArtistIdMap; 0038 typedef QMap<int, Meta::ScriptableServiceAlbum *> ScriptableServiceAlbumIdMap; 0039 typedef QMap<int, Meta::ScriptableServiceGenre *> ScriptableServiceGenreIdMap; 0040 0041 0042 class ScriptableService : public ServiceBase 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 0048 /** 0049 * Constructor 0050 */ 0051 explicit ScriptableService( const QString &name ); 0052 0053 /** 0054 * Destructor 0055 */ 0056 ~ScriptableService() override; 0057 0058 void init( int levels, const QString &rootHtml, bool showSearchBar ); 0059 0060 void polish() override; 0061 0062 Collections::ServiceCollection * collection() override; 0063 0064 int insertItem( int level, int parentId, const QString &name, const QString &infoHtml, const QString &callbackData, const QString &playableUrl, 0065 const QString & albumOverride, const QString & artistOverride, const QString & genreOverride, 0066 const QString & composerOverride, int yearOverride, const QString &coverUrl ); 0067 0068 0069 0070 void donePopulating( int parentId ); 0071 0072 void setCustomEmblem( const QPixmap &emblem ); 0073 QPixmap customEmblem(); 0074 0075 0076 void setCustomScalableEmblem( const QString &emblemPath ); 0077 QString customScalableEmblem(); 0078 0079 void setCurrentInfo( const QString & info ); 0080 0081 int contentLevels() const { return m_levels; } 0082 bool hasSearchBar() const { return m_hasSearchBar; } 0083 0084 private Q_SLOTS: 0085 0086 0087 //void treeItemSelected( const QModelIndex & index ); 0088 //void infoChanged ( QString infoHtml ); 0089 0090 0091 private: 0092 0093 bool m_polished; 0094 0095 QString m_name; 0096 QString m_rootHtml; 0097 0098 int m_levels; 0099 bool m_hasSearchBar; 0100 0101 int addTrack( Meta::ScriptableServiceTrack * track ); 0102 int addAlbum( Meta::ScriptableServiceAlbum * album ); 0103 int addArtist( Meta::ScriptableServiceArtist * artist ); 0104 int addGenre( Meta::ScriptableServiceGenre * genre ); 0105 0106 Collections::ScriptableServiceCollection * m_collection; 0107 int m_trackIdCounter; 0108 int m_albumIdCounter; 0109 int m_artistIdCounter; 0110 int m_genreIdCounter; 0111 0112 ScriptableServiceTrackIdMap m_ssTrackIdMap; 0113 ScriptableServiceAlbumIdMap m_ssAlbumIdMap; 0114 ScriptableServiceArtistIdMap m_ssArtistIdMap; 0115 ScriptableServiceGenreIdMap m_ssGenreIdMap; 0116 0117 QPixmap m_customEmblem; 0118 QString m_customScalableEmblem; 0119 0120 }; 0121 0122 0123 #endif