2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2012-05-06 10:06:10 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
|
2012-05-06 10:06:10 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2012-05-06 10:06:10 +00:00
|
|
|
#include "scriptingutils.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
bool validateParameters(QScriptContext *context, int min, int max)
|
|
|
|
{
|
|
|
|
if (context->argumentCount() < min || context->argumentCount() > max) {
|
|
|
|
context->throwError(QScriptContext::SyntaxError,
|
|
|
|
i18nc("syntax error in KWin script", "Invalid number of arguments"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool validateArgumentType<QVariant>(QScriptContext *context, int argument)
|
|
|
|
{
|
|
|
|
const bool result =context->argument(argument).toVariant().isValid();
|
|
|
|
if (!result) {
|
|
|
|
context->throwError(QScriptContext::TypeError,
|
|
|
|
i18nc("KWin Scripting function received incorrect value for an expected type",
|
|
|
|
"%1 is not a variant type", context->argument(argument).toString()));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|