kwin/scripting/scripting.h

103 lines
2.6 KiB
C
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
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/>.
*********************************************************************/
#ifndef KWIN_SCRIPTING_H
#define KWIN_SCRIPTING_H
#include <QDir>
class QScriptEngine;
class QScriptValue;
namespace KWin
{
class WorkspaceWrapper;
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
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
Script(int id, QString scriptName, QDir dir, QObject *parent = NULL);
2011-12-23 07:49:28 +00:00
virtual ~Script();
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:
int m_scriptId;
2011-12-23 07:49:28 +00:00
QScriptEngine *m_engine;
QDir m_scriptDir;
QFile m_scriptFile;
WorkspaceWrapper *m_workspace;
bool m_running;
2011-01-30 14:34:42 +00:00
};
/**
* The heart of KWin::Scripting. Infinite power lies beyond
*/
class Scripting : public QObject
2011-01-30 14:34:42 +00:00
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
2011-01-30 14:34:42 +00:00
private:
QStringList scriptList;
QDir scriptsDir;
QList<KWin::Script*> scripts;
2011-01-30 14:34:42 +00:00
// Preferably call ONLY at load time
void runScripts();
public:
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();
Q_SCRIPTABLE Q_INVOKABLE int loadScript(const QString &filePath);
public Q_SLOTS:
void scriptDestroyed(QObject *object);
2011-01-30 14:34:42 +00:00
};
}
#endif