File indexing completed on 2024-06-02 04:52:43

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Peter ZHOU <peterzhoulei@gmail.com>                               *
0003  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef AMAROK_SCRIPTABLE_SERVICE_SCRIPT_H
0019 #define AMAROK_SCRIPTABLE_SERVICE_SCRIPT_H
0020 
0021 #include <QMetaType> // for Q_DECLARE_METATYPE
0022 #include <QObject>
0023 #include <QJSValue>
0024 
0025 class StreamItem;
0026 class QPixmap;
0027 class QJSEngine;
0028 
0029 namespace AmarokScript
0030 {
0031     // SCRIPTDOX: ScriptableServiceScript
0032     /**
0033      * Usage: First create the scriptable service using a call to
0034      * ScriptableServiceScript( string name, int levels, string shortDescription,  string rootHtml, bool showSearchBar )
0035      */
0036     class ScriptableServiceScript : public QObject
0037     {
0038         Q_OBJECT
0039 
0040         public:
0041             explicit ScriptableServiceScript( QJSEngine* engine );
0042 
0043             void slotPopulate(const QString &name, int level, int parent_id, const QString &callbackData, const QString &filter );
0044             void slotRequestInfo(const QString &name, int level, const QString &callbackData );
0045 
0046             void slotCustomize( const QString &name );
0047 
0048             /** Script Invokable **/
0049             Q_INVOKABLE int insertItem( StreamItem* item );
0050             Q_INVOKABLE void setCurrentInfo( const QString &infoHtml );
0051 
0052             Q_INVOKABLE int donePopulating() const;
0053 
0054             Q_INVOKABLE void setIcon( const QPixmap &icon );
0055             Q_INVOKABLE void setEmblem( const QPixmap &icon );
0056             Q_INVOKABLE void setScalableEmblem( const QString &emblemPath );
0057 
0058             Q_INVOKABLE QObject *ScriptableServiceScript_prototype_ctor( QString serviceName, int levels, QString shortDescription, QString rootHtml, bool showSearchBar );
0059 
0060 
0061         private:
0062             QJSEngine* m_scriptEngine;
0063             int m_currentId;
0064             QString m_serviceName;
0065             static QJSValue ScriptableServiceScript_prototype_populate( QJSEngine *engine );
0066 
0067         Q_SIGNALS:
0068             void populate( int, const QString&, const QString& );
0069             void fetchInfo( int, const QString& );
0070             void customize();
0071     };
0072 }
0073 
0074 Q_DECLARE_METATYPE( AmarokScript::ScriptableServiceScript* )
0075 
0076 #endif