From 63b3110f6679ede12817c3fbbbcd4c75aa6a3adc Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 28 Apr 2009 02:12:33 +0000 Subject: [PATCH] bind kurl for use with, e.g. WebView svn path=/trunk/KDE/kdebase/workspace/plasma/scriptengines/javascript/; revision=960158 --- scriptengines/javascript/qtgui/url.cpp | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scriptengines/javascript/qtgui/url.cpp diff --git a/scriptengines/javascript/qtgui/url.cpp b/scriptengines/javascript/qtgui/url.cpp new file mode 100644 index 000000000..b7fa6c308 --- /dev/null +++ b/scriptengines/javascript/qtgui/url.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2007 Richard J. Moore + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#include +#include +#include +#include +#include "../backportglobal.h" + +Q_DECLARE_METATYPE(KUrl*) + +static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) +{ + if (ctx->argumentCount() == 1) + { + QString url = ctx->argument(0).toString(); + return qScriptValueFromValue(eng, KUrl(url)); + } + + return qScriptValueFromValue(eng, KUrl()); +} + +static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(KUrl, toString); + return QScriptValue(eng, self->prettyUrl()); +} + +QScriptValue constructKUrlClass(QScriptEngine *eng) +{ + QScriptValue proto = qScriptValueFromValue(eng, KUrl()); + QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; + QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; + + proto.setProperty("toString", eng->newFunction(toString), getter); + + eng->setDefaultPrototype(qMetaTypeId(), proto); + + return eng->newFunction(ctor, proto); +}