1 /**************************************************************************************** 2 * Copyright (c) 2004-2010 Mark Kretschmann <kretschmann@kde.org> * 3 * Copyright (c) 2005 Seb Ruiz <ruiz@kde.org> * 4 * Copyright (c) 2008 Peter ZHOU <peterzhoulei@gmail.com> * 5 * * 6 * This program is free software; you can redistribute it and/or modify it under * 7 * the terms of the GNU General Public License as published by the Free Software * 8 * Foundation; either version 2 of the License, or (at your option) any later * 9 * version. * 10 * * 11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 13 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License along with * 16 * this program. If not, see <http://www.gnu.org/licenses/>. * 17 ****************************************************************************************/ 18 19 #ifndef AMAROK_SCRIPTITEM_H 20 #define AMAROK_SCRIPTITEM_H 21 22 #include "amarok_export.h" 23 #include "scripting/scriptengine/AmarokScriptableServiceScript.h" 24 #include "scripting/scriptengine/ScriptingDefines.h" 25 #include "statusbar/PopupWidget.h" 26 27 #include <KPluginInfo> 28 #include <QUrl> 29 30 #include <QJSValue> 31 32 namespace AmarokScript { 33 class AmarokScript; 34 } 35 class ScriptItem; 36 class QTimerEvent; 37 38 class ScriptTerminatorWidget : public PopupWidget 39 { 40 Q_OBJECT 41 public: 42 explicit ScriptTerminatorWidget( const QString &message ); 43 44 Q_SIGNALS: 45 void terminate(); 46 }; 47 48 class ScriptItem : public QObject 49 { 50 Q_OBJECT 51 public: 52 ScriptItem( QObject *parent, const QString &name, const QString &path, const KPluginInfo &info ); 53 ~ScriptItem() override; 54 name()55 QString name() const { return m_name; } engine()56 AmarokScript::AmarokScriptEngine* engine() { return m_engine.data(); } service()57 AmarokScript::ScriptableServiceScript* service() { return m_service.data(); } url()58 QUrl url() const { return m_url; } info()59 KPluginInfo info() const { return m_info; } running()60 bool running() const { return m_running; } 61 QString specPath() const; output()62 QString output() const { return m_output.join(QStringLiteral("\n")); } engineResult()63 QJSValue engineResult() const { return m_engineResult; }; 64 65 virtual bool start( bool silent ); 66 virtual void pause(); 67 void uninstall(); 68 69 public Q_SLOTS: 70 void stop(); 71 72 /** 73 * Warn the user about scripts calling deprecated API calls 74 */ 75 virtual void slotDeprecatedCall( const QString &call ); 76 77 private Q_SLOTS: 78 void timerEvent( QTimerEvent *event ) override; 79 80 Q_SIGNALS: 81 void signalHandlerException( QJSValue ); 82 void evaluated( QString output ); 83 void uninstalled(); 84 85 protected: 86 /** 87 * Initialize QJSEngine and load wrapper classes 88 */ 89 virtual void initializeScriptEngine(); 90 virtual QString handleError( QJSValue *evalReturn ); 91 92 private: 93 QString m_name; 94 QUrl m_url; 95 KPluginInfo m_info; 96 QPointer<AmarokScript::AmarokScriptEngine> m_engine; 97 QJSValue m_engineResult; 98 /** Currently activated in the Script Manager */ 99 bool m_running; 100 QStringList m_log; 101 QPointer<AmarokScript::ScriptableServiceScript> m_service; 102 QStringList m_output; 103 int m_runningTime; 104 int m_timerId; 105 QPointer<ScriptTerminatorWidget> m_popupWidget; 106 bool m_qtScriptCompat = true; 107 }; 108 109 #endif /* AMAROK_SCRIPTITEM_H */ 110