1 /****************************************************************************************
2  * Copyright (c) 2007 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 #ifndef AMAROKSCRIPTABLESERVICE_H
18 #define AMAROKSCRIPTABLESERVICE_H
19 
20 
21 #include "core/support/Amarok.h"
22 #include "../ServiceBase.h"
23 #include "ScriptableServiceMeta.h"
24 #include "ScriptableServiceCollection.h"
25 
26 
27 /* internally, we use the following level mapping:
28     0 = track
29     1 = album
30     2 = artist
31     3 = genre
32 
33 but we do our best to make this invisible to the scripts
34 */
35 
36 typedef QMap<int, Meta::ScriptableServiceTrack *> ScriptableServiceTrackIdMap;
37 typedef QMap<int, Meta::ScriptableServiceArtist *> ScriptableServiceArtistIdMap;
38 typedef QMap<int, Meta::ScriptableServiceAlbum *> ScriptableServiceAlbumIdMap;
39 typedef QMap<int, Meta::ScriptableServiceGenre *> ScriptableServiceGenreIdMap;
40 
41 
42 class ScriptableService : public ServiceBase
43 {
44     Q_OBJECT
45 
46 public:
47 
48      /**
49      * Constructor
50      */
51     explicit ScriptableService( const QString &name );
52 
53     /**
54      * Destructor
55      */
56     ~ScriptableService() override;
57 
58     void init( int levels, const QString &rootHtml, bool showSearchBar );
59 
60     void polish() override;
61 
62     Collections::ServiceCollection * collection() override;
63 
64     int insertItem( int level, int parentId, const QString &name, const QString &infoHtml, const QString &callbackData, const QString &playableUrl,
65                     const QString & albumOverride, const QString & artistOverride, const QString & genreOverride,
66                     const QString & composerOverride, int yearOverride, const QString &coverUrl );
67 
68 
69 
70     void donePopulating( int parentId );
71 
72     void setCustomEmblem( const QPixmap &emblem );
73     QPixmap customEmblem();
74 
75 
76     void setCustomScalableEmblem( const QString &emblemPath );
77     QString customScalableEmblem();
78 
79     void setCurrentInfo( const QString & info );
80 
contentLevels()81     int contentLevels() const { return m_levels; }
hasSearchBar()82     bool hasSearchBar() const { return m_hasSearchBar; }
83 
84 private Q_SLOTS:
85 
86 
87     //void treeItemSelected( const QModelIndex & index );
88     //void infoChanged ( QString infoHtml );
89 
90 
91 private:
92 
93     bool m_polished;
94 
95     QString m_name;
96     QString m_rootHtml;
97 
98     int m_levels;
99     bool m_hasSearchBar;
100 
101     int addTrack( Meta::ScriptableServiceTrack * track );
102     int addAlbum( Meta::ScriptableServiceAlbum * album );
103     int addArtist( Meta::ScriptableServiceArtist * artist );
104     int addGenre( Meta::ScriptableServiceGenre * genre );
105 
106     Collections::ScriptableServiceCollection * m_collection;
107     int m_trackIdCounter;
108     int m_albumIdCounter;
109     int m_artistIdCounter;
110     int m_genreIdCounter;
111 
112     ScriptableServiceTrackIdMap m_ssTrackIdMap;
113     ScriptableServiceAlbumIdMap m_ssAlbumIdMap;
114     ScriptableServiceArtistIdMap m_ssArtistIdMap;
115     ScriptableServiceGenreIdMap m_ssGenreIdMap;
116 
117     QPixmap m_customEmblem;
118     QString m_customScalableEmblem;
119 
120 };
121 
122 
123 #endif
124