Fix global script methods
The callee is an AbstractScript and we should make sure that the script is not already deleted.
This commit is contained in:
parent
95ac5fa2ce
commit
b7d95a1b09
2 changed files with 18 additions and 10 deletions
|
@ -44,7 +44,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
QScriptValue kwinScriptPrint(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
KWin::Script *script = qobject_cast<KWin::Script*>(context->callee().data().toQObject());
|
||||
KWin::AbstractScript *script = qobject_cast<KWin::Script*>(context->callee().data().toQObject());
|
||||
if (!script) {
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
QString result;
|
||||
for (int i = 0; i < context->argumentCount(); ++i) {
|
||||
if (i > 0) {
|
||||
|
@ -60,6 +63,9 @@ QScriptValue kwinScriptPrint(QScriptContext *context, QScriptEngine *engine)
|
|||
QScriptValue kwinScriptReadConfig(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
KWin::AbstractScript *script = qobject_cast<KWin::AbstractScript*>(context->callee().data().toQObject());
|
||||
if (!script) {
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
if (context->argumentCount() < 1 || context->argumentCount() > 2) {
|
||||
kDebug(1212) << "Incorrect number of arguments";
|
||||
return engine->undefinedValue();
|
||||
|
@ -99,6 +105,12 @@ void KWin::AbstractScript::stop()
|
|||
deleteLater();
|
||||
}
|
||||
|
||||
void KWin::AbstractScript::printMessage(const QString &message)
|
||||
{
|
||||
kDebug(1212) << scriptFile().fileName() << ":" << message;
|
||||
emit print(message);
|
||||
}
|
||||
|
||||
void KWin::AbstractScript::installScriptFunctions(QScriptEngine* engine)
|
||||
{
|
||||
// add our print
|
||||
|
@ -123,12 +135,6 @@ KWin::Script::~Script()
|
|||
QDBusConnection::sessionBus().unregisterObject('/' + QString::number(scriptId()));
|
||||
}
|
||||
|
||||
void KWin::Script::printMessage(const QString &message)
|
||||
{
|
||||
kDebug(1212) << scriptFile().fileName() << ":" << message;
|
||||
emit print(message);
|
||||
}
|
||||
|
||||
void KWin::Script::run()
|
||||
{
|
||||
if (running()) {
|
||||
|
|
|
@ -44,12 +44,17 @@ public:
|
|||
return m_scriptFile.fileName();
|
||||
}
|
||||
|
||||
void printMessage(const QString &message);
|
||||
|
||||
KConfigGroup config() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE void stop();
|
||||
Q_SCRIPTABLE virtual void run() = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SCRIPTABLE void print(const QString &text);
|
||||
|
||||
protected:
|
||||
QFile &scriptFile() {
|
||||
return m_scriptFile;
|
||||
|
@ -90,13 +95,10 @@ public:
|
|||
Script(int id, QString scriptName, QString pluginName, QObject *parent = NULL);
|
||||
virtual ~Script();
|
||||
|
||||
void printMessage(const QString &message);
|
||||
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE void run();
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SCRIPTABLE void print(const QString &text);
|
||||
Q_SCRIPTABLE void printError(const QString &text);
|
||||
|
||||
private slots:
|
||||
|
|
Loading…
Reference in a new issue