1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
* Copyright 2014 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef INTERACTIVECONSOLE
#define INTERACTIVECONSOLE
#include <QDialog>
#include <QPointer>
#include <KIO/Job>
class QSplitter;
class QAction;
class QFileDialog;
class QMenu;
class KTextEdit;
class QTextBrowser;
class ShellCorona;
namespace KTextEditor
{
class Document;
} // namespace KParts
namespace Plasma
{
class Corona;
} // namespace Plasma
class ScriptEngine;
class InteractiveConsole : public QDialog
{
Q_OBJECT
public:
InteractiveConsole(QWidget *parent = 0);
~InteractiveConsole() override;
enum ConsoleMode {
PlasmaConsole,
KWinConsole
};
void setMode(const QString &mode);
QString mode() const;
void setScriptInterface(QObject *obj);
QObject *scriptEngine() const;
void loadScript(const QString &path);
Q_SIGNALS:
void scriptEngineChanged();
void modeChanged();
void visibleChanged(bool);
protected:
void showEvent(QShowEvent *) override;
void closeEvent(QCloseEvent *event) override;
protected Q_SLOTS:
void print(const QString &string);
void reject() override;
private Q_SLOTS:
void openScriptFile();
void saveScript();
void scriptTextChanged();
void evaluateScript();
void clearEditor();
void clearOutput();
void scriptFileDataRecvd(KIO::Job *job, const QByteArray &data);
void scriptFileDataReq(KIO::Job *job, QByteArray &data);
void reenableEditor(KJob *job);
void saveScriptUrlSelected(int result);
void openScriptUrlSelected(int result);
void loadScriptFromUrl(const QUrl &url);
void populateTemplatesMenu();
void loadTemplate(QAction *);
void useTemplate(QAction *);
void modeSelectionChanged();
private:
void saveScript(const QUrl &url);
ShellCorona *m_corona;
QSplitter *m_splitter;
KTextEditor::Document *m_editorPart;
KTextEdit *m_editor;
QTextBrowser *m_output;
QAction *m_loadAction;
QAction *m_saveAction;
QAction *m_clearAction;
QAction *m_executeAction;
QAction *m_plasmaAction;
QAction *m_kwinAction;
QMenu *m_snippetsMenu;
QFileDialog *m_fileDialog;
QPointer<KIO::Job> m_job;
bool m_closeWhenCompleted;
ConsoleMode m_mode;
QPointer<QObject> m_scriptEngine;
};
class InteractiveConsoleItem : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject *scriptEngine READ scriptEngine WRITE setScriptInterface NOTIFY scriptEngineChanged)
Q_PROPERTY(QString mode READ mode WRITE setMode NOTIFY modeChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
public:
InteractiveConsoleItem()
: QObject(0),
m_dialog(new InteractiveConsole(0))
{
connect(m_dialog, &InteractiveConsole::scriptEngineChanged,
this, &InteractiveConsoleItem::scriptEngineChanged);
connect(m_dialog, &InteractiveConsole::modeChanged,
this, &InteractiveConsoleItem::modeChanged);
connect(m_dialog, &InteractiveConsole::visibleChanged,
this, &InteractiveConsoleItem::visibleChanged);
}
~InteractiveConsoleItem()
override {
m_dialog->deleteLater();
}
void setMode(const QString &mode) { m_dialog->setMode(mode); }
QString mode() const { return m_dialog->mode(); }
void setScriptInterface(QObject *obj) { m_dialog->setScriptInterface(obj); }
QObject *scriptEngine() const { return m_dialog->scriptEngine(); }
void setVisible(bool visible) const { visible ? m_dialog->show() : m_dialog->hide(); }
bool isVisible() const { return m_dialog->isVisible(); }
public Q_SLOTS:
void loadScript(const QString &path) { m_dialog->loadScript(path); }
Q_SIGNALS:
void scriptEngineChanged();
void modeChanged();
void visibleChanged(bool);
private:
InteractiveConsole *m_dialog;
};
#endif
|