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 #ifndef AMAROKSCRIPTABLESERVICEMANAGER_H
0018 #define AMAROKSCRIPTABLESERVICEMANAGER_H
0019 
0020 #include "AmarokProcess.h"
0021 #include "../ServiceBase.h"
0022 #include "ScriptableService.h"
0023 
0024 #include <QObject>
0025 #include <QString>
0026 #include <QIcon>
0027 
0028 class ScriptableServiceManager;
0029 
0030 namespace The {
0031     AMAROK_EXPORT ScriptableServiceManager* scriptableServiceManager();
0032 }
0033  
0034 class ScriptableServiceManager : public QObject
0035 {
0036     Q_OBJECT
0037 
0038     friend ScriptableServiceManager* The::scriptableServiceManager();
0039 
0040     public:
0041         void removeRunningScript( const QString &name );
0042         ScriptableService * service( const QString &name );
0043 
0044 
0045     Q_SIGNALS:
0046         /**
0047          * Signal emitted whenever a new service is ready to be added
0048          * @param service The service to add
0049          */
0050         void addService( ServiceBase * service );
0051 
0052         void serviceUpdated( ServiceBase * service );
0053 
0054     public Q_SLOTS:
0055 
0056         /**
0057          * Initialzises a new service. This method is exported to DBUS
0058          * @param name the name of the service to create. Must be the same as the name of the script
0059          * @param levels How many levels of items should be added ( 1 - 4 )
0060          * @param shortDescription Some short description
0061          * @param rootHtml The html to display when the service is selected
0062          * @param showSearchBar Determines whether to show search bar
0063          * @return returns true if successful and false otherwise
0064          */
0065         bool initService( const QString &name, int levels, const QString &shortDescription, const QString &rootHtml, bool showSearchBar );
0066 
0067         /**
0068          * Add a new item to a service
0069          * @param serviceName The name of the service to add an item to
0070          * @param level The level of this item
0071          * @param parentId The id of the parent item that this item should be a child of ( -1 if no parent )
0072          * @param name The name of this item
0073          * @param infoHtml The html info to display when this item is selected
0074          * @param callbackData The callback data needed to let the script know how to populate this items children ( Empty string if leaf item )
0075          * @param playableUrl The url to play if added to the playlist ( Empty string if not leaf node )
0076          * @param albumOverride The album override
0077          * @param artistOverride The artist override
0078          * @param genreOverride The genre override
0079          * @param composerOverride The composer override
0080          * @param yearOverride The year override
0081          * @param coverUrl The cover URL
0082          * @return the id of the created item ( or -1 on failure )
0083          */
0084         int insertItem( const QString &serviceName, int level, int parentId, const QString &name, const QString &infoHtml, const QString &callbackData, const QString &playableUrl,
0085                     const QString & albumOverride, const QString & artistOverride, const QString & genreOverride,
0086                     const QString & composerOverride, int yearOverride, const QString &coverUrl );
0087 
0088         
0089         /**
0090          * Let the service know that the script has added all child nodes
0091          * @param serviceName The service we have been adding items to
0092          * @param parentId The id of the parent node
0093          */
0094         void donePopulating( const QString &serviceName, int parentId );
0095 
0096         void setIcon( const QString &serviceName, const QPixmap &icon );
0097 
0098         void setEmblem( const QString &serviceName, const QPixmap &emblem );
0099         
0100         void setScalableEmblem( const QString &serviceName, const QString &emblemPath );
0101 
0102         void setCurrentInfo( const QString &serviceName, const QString &info );
0103 
0104 
0105     private:
0106 
0107         /**
0108         * Constructor
0109         */
0110         ScriptableServiceManager();
0111 
0112         /**
0113         * Destructor
0114         */
0115         ~ScriptableServiceManager() override;
0116 
0117         static ScriptableServiceManager * s_instance;
0118 
0119         QMap<QString, ScriptableService *> m_serviceMap;
0120         QString m_rootHtml;
0121 };
0122 
0123 #endif
0124