2010-09-21 14:31:40 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
|
2011-12-23 10:52:06 +00:00
|
|
|
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, 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 General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
2011-01-01 09:37:08 +00:00
|
|
|
#ifndef KWIN_SCRIPTING_H
|
|
|
|
#define KWIN_SCRIPTING_H
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
2011-12-23 10:52:06 +00:00
|
|
|
class QScriptEngine;
|
|
|
|
class QScriptValue;
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2012-01-22 11:38:03 +00:00
|
|
|
class WorkspaceWrapper;
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2011-12-23 07:49:28 +00:00
|
|
|
class Script : public QObject
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-12-23 07:49:28 +00:00
|
|
|
Q_OBJECT
|
2011-12-23 10:52:06 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
2011-12-23 07:49:28 +00:00
|
|
|
|
2011-12-23 10:52:06 +00:00
|
|
|
Script(int id, QString scriptName, QDir dir, QObject *parent = NULL);
|
2011-12-23 07:49:28 +00:00
|
|
|
virtual ~Script();
|
2011-12-23 10:52:06 +00:00
|
|
|
QString fileName() const {
|
|
|
|
return m_scriptFile.fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void printMessage(const QString &message);
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
Q_SCRIPTABLE void stop();
|
|
|
|
Q_SCRIPTABLE void run();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
Q_SCRIPTABLE void print(const QString &text);
|
|
|
|
Q_SCRIPTABLE void printError(const QString &text);
|
2011-12-23 07:49:28 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
/**
|
|
|
|
* A nice clean way to handle exceptions in scripting.
|
|
|
|
* TODO: Log to file, show from notifier..
|
|
|
|
*/
|
|
|
|
void sigException(const QScriptValue &exception);
|
|
|
|
|
|
|
|
private:
|
2011-12-23 10:52:06 +00:00
|
|
|
int m_scriptId;
|
2011-12-23 07:49:28 +00:00
|
|
|
QScriptEngine *m_engine;
|
|
|
|
QDir m_scriptDir;
|
|
|
|
QFile m_scriptFile;
|
2012-01-22 11:38:03 +00:00
|
|
|
WorkspaceWrapper *m_workspace;
|
2011-12-23 10:52:06 +00:00
|
|
|
bool m_running;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The heart of KWin::Scripting. Infinite power lies beyond
|
|
|
|
*/
|
2011-12-23 07:56:25 +00:00
|
|
|
class Scripting : public QObject
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2011-12-23 10:52:06 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
|
2011-01-30 14:34:42 +00:00
|
|
|
private:
|
|
|
|
QStringList scriptList;
|
|
|
|
QDir scriptsDir;
|
2011-12-23 10:52:06 +00:00
|
|
|
QList<KWin::Script*> scripts;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
// Preferably call ONLY at load time
|
|
|
|
void runScripts();
|
|
|
|
|
|
|
|
public:
|
2011-12-23 07:56:25 +00:00
|
|
|
Scripting(QObject *parent = NULL);
|
2011-01-30 14:34:42 +00:00
|
|
|
/**
|
|
|
|
* Start running scripts. This was essential to have KWin::Scripting
|
|
|
|
* be initialized on stack and also have the option to disable scripting.
|
|
|
|
*/
|
|
|
|
void start();
|
|
|
|
~Scripting();
|
2011-12-23 10:52:06 +00:00
|
|
|
Q_SCRIPTABLE Q_INVOKABLE int loadScript(const QString &filePath);
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void scriptDestroyed(QObject *object);
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|