File indexing completed on 2024-05-05 05:38:49

0001 /*
0002     SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QJSEngine>
0010 #include <QJSValue>
0011 
0012 #include <QFontMetrics>
0013 
0014 #include <plasmaactivities/controller.h>
0015 
0016 #include "../shellcorona.h"
0017 
0018 namespace Plasma
0019 {
0020 class Applet;
0021 class Containment;
0022 } // namespace Plasma
0023 
0024 class KLocalizedContext;
0025 
0026 namespace WorkspaceScripting
0027 {
0028 class AppInterface;
0029 class Containment;
0030 class V1;
0031 
0032 class ScriptEngine : public QJSEngine
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     explicit ScriptEngine(Plasma::Corona *corona, QObject *parent = nullptr);
0038     ~ScriptEngine() override;
0039 
0040     QString errorString() const;
0041 
0042     static QStringList pendingUpdateScripts(Plasma::Corona *corona);
0043 
0044     Plasma::Corona *corona() const;
0045     QJSValue wrap(Plasma::Applet *w);
0046     QJSValue wrap(Plasma::Containment *c);
0047     virtual int defaultPanelScreen() const;
0048     QJSValue newError(const QString &message);
0049 
0050     static bool isPanel(const Plasma::Containment *c);
0051 
0052     Plasma::Containment *createContainment(const QString &type, const QString &plugin);
0053 
0054 public Q_SLOTS:
0055     bool evaluateScript(const QString &script, const QString &path = QString());
0056 
0057 Q_SIGNALS:
0058     void print(const QString &string);
0059     void printError(const QString &string);
0060 
0061 private:
0062     void setupEngine();
0063     static QString onlyExec(const QString &commandLine);
0064 
0065     // Script API versions
0066     class V1;
0067 
0068     // helpers
0069     QStringList availableActivities() const;
0070     QList<Containment *> desktopsForActivity(const QString &id);
0071     Containment *createContainmentWrapper(const QString &type, const QString &plugin);
0072 
0073 private Q_SLOTS:
0074     void exception(const QJSValue &value);
0075 
0076 private:
0077     Plasma::Corona *m_corona;
0078     ScriptEngine::V1 *m_globalScriptEngineObject;
0079     KLocalizedContext *m_localizedContext;
0080     AppInterface *m_appInterface;
0081     QJSValue m_scriptSelf;
0082     QString m_errorString;
0083 };
0084 
0085 static const int PLASMA_DESKTOP_SCRIPTING_VERSION = 20;
0086 }