diff --git a/src/scriptengines/CMakeLists.txt b/src/scriptengines/CMakeLists.txt index b53f1193b..fb5c94414 100644 --- a/src/scriptengines/CMakeLists.txt +++ b/src/scriptengines/CMakeLists.txt @@ -1,2 +1,7 @@ add_subdirectory(qml) -#add_subdirectory(javascript) + +add_subdirectory(ruby) + +if (PYTHONLIBRARY_FOUND AND NOT WIN32) + add_subdirectory(python) +endif () diff --git a/src/scriptengines/javascript/CMakeLists.txt b/src/scriptengines/javascript/CMakeLists.txt deleted file mode 100644 index de9a1a0d5..000000000 --- a/src/scriptengines/javascript/CMakeLists.txt +++ /dev/null @@ -1,123 +0,0 @@ -# APPLET - -if(KDE_PLATFORM_FEATURE_BINARY_COMPATIBLE_FEATURE_REDUCTION) - set(PLASMA_NO_KDEWEBKIT TRUE) - set(PLASMA_NO_SOLID TRUE) - set(PLASMA_NO_KIO TRUE) -endif() - -set(simple_javascript_engine_SRCS - common/extension_launchapp.cpp - common/extension_io.cpp - common/guiscriptenv.cpp - common/javascriptaddonpackagestructure.cpp - declarative/toolboxproxy.cpp - declarative/appletcontainer.cpp - plasmoid/abstractjsappletscript.cpp - plasmoid/appletauthorization.cpp - plasmoid/jsappletinterface.cpp - plasmoid/simplejavascriptapplet.cpp - plasmoid/themedsvg.cpp - simplebindings/animationgroup.cpp - simplebindings/anchorlayout.cpp - simplebindings/dataenginereceiver.cpp - simplebindings/bytearrayclass.cpp - simplebindings/bytearrayprototype.cpp - simplebindings/color.cpp - simplebindings/dataengine.cpp - simplebindings/easingcurve.cpp - simplebindings/font.cpp - simplebindings/filedialogproxy.cpp - simplebindings/graphicsitem.cpp - simplebindings/icon.cpp - simplebindings/i18n.cpp - simplebindings/linearlayout.cpp - simplebindings/gridlayout.cpp - simplebindings/painter.cpp - simplebindings/pen.cpp - simplebindings/pixmap.cpp - simplebindings/point.cpp - simplebindings/rect.cpp - simplebindings/qscriptbookkeeping.cpp - simplebindings/size.cpp - simplebindings/sizepolicy.cpp - simplebindings/timer.cpp - simplebindings/uiloader.cpp - simplebindings/url.cpp -) - -include_directories(${PHONON_INCLUDES}) - -add_library(plasma_appletscript_simple_javascript MODULE ${simple_javascript_engine_SRCS}) - -target_link_libraries(plasma_appletscript_simple_javascript - KF5::KIOCore KF5::KIOWidgets - KF5::Plasma - Qt5::Declarative - Qt5::Xml - ) - -install(TARGETS plasma_appletscript_simple_javascript DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES data/plasma-scriptengine-applet-simple-javascript.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) - -# RUNNER - -set(javascript_runner_engine_SRCS - common/extension_launchapp.cpp - common/extension_io.cpp - common/javascriptaddonpackagestructure.cpp - common/scriptenv.cpp - runner/javascriptrunner.cpp - simplebindings/i18n.cpp -) - -add_library(plasma_runnerscript_javascript MODULE ${javascript_runner_engine_SRCS}) - -target_link_libraries(plasma_runnerscript_javascript - KF5::CoreAddons - KF5::KIOWidgets - KF5::Plasma - Qt5::Script) - -install(TARGETS plasma_runnerscript_javascript DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES data/plasma-scriptengine-runner-javascript.desktop DESTINATION ${SERVICES_INSTALL_DIR}) - - -# DATAENGINE - -set(javascript_dataengine_engine_SRCS - common/extension_launchapp.cpp - common/extension_io.cpp - common/javascriptaddonpackagestructure.cpp - common/scriptenv.cpp - dataengine/javascriptdataengine.cpp - dataengine/javascriptservice.cpp - simplebindings/dataengine.cpp - simplebindings/i18n.cpp - simplebindings/qscriptnonguibookkeeping.cpp -) -add_library(plasma_dataenginescript_javascript MODULE ${javascript_dataengine_engine_SRCS}) - -target_link_libraries(plasma_dataenginescript_javascript - KF5::CoreAddons - KF5::KIOWidgets - KF5::Plasma - Qt5::Script) - -install(TARGETS plasma_dataenginescript_javascript DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES data/plasma-scriptengine-dataengine-javascript.desktop DESTINATION ${SERVICES_INSTALL_DIR}) - -# ADDONS - -set(javascript_addon_packagestructure_SRCS - common/addonpackageplugin.cpp - common/javascriptaddonpackagestructure.cpp -) - -add_library(plasma_packagestructure_javascriptaddon MODULE ${javascript_addon_packagestructure_SRCS}) -target_link_libraries(plasma_packagestructure_javascriptaddon KF5::Plasma) - -install(TARGETS plasma_packagestructure_javascriptaddon DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES data/plasma-packagestructure-javascript-addon.desktop DESTINATION ${SERVICES_INSTALL_DIR}) - -install(FILES data/plasma-javascriptaddon.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) diff --git a/src/scriptengines/javascript/Messages.sh b/src/scriptengines/javascript/Messages.sh deleted file mode 100644 index c524893e9..000000000 --- a/src/scriptengines/javascript/Messages.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /usr/bin/env bash -$XGETTEXT `find . -name '*.cpp'` -o $podir/plasma_scriptengine_qscript.pot diff --git a/src/scriptengines/javascript/common/addonpackageplugin.cpp b/src/scriptengines/javascript/common/addonpackageplugin.cpp deleted file mode 100644 index 20046fc6f..000000000 --- a/src/scriptengines/javascript/common/addonpackageplugin.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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., - */ - -#include "javascriptaddonpackagestructure.h" - -K_EXPORT_PLASMA_PACKAGESTRUCTURE(javascriptaddon, JavascriptAddonPackageStructure) - diff --git a/src/scriptengines/javascript/common/authorization.h b/src/scriptengines/javascript/common/authorization.h deleted file mode 100644 index 08eb10594..000000000 --- a/src/scriptengines/javascript/common/authorization.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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. - */ - -#ifndef AUTHORIZATION_H -#define AUTHORIZATION_H - -#include - -#include - -class Authorization -{ -public: - Authorization() {} - virtual ~Authorization() {} - - virtual bool authorizeRequiredExtension(const QString &) { return true; } - virtual bool authorizeOptionalExtension(const QString &) { return true; } - virtual bool authorizeExternalExtensions() { return KAuthorized::authorize("plasma/external_script_extensions"); } -}; - -#endif - diff --git a/src/scriptengines/javascript/common/declarativescriptenv.cpp b/src/scriptengines/javascript/common/declarativescriptenv.cpp deleted file mode 100644 index ac08bd29c..000000000 --- a/src/scriptengines/javascript/common/declarativescriptenv.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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. - */ - -#define USEGUI -#define DECLARATIVE -#include "scriptenv.cpp" -#include "scriptenv.moc" - diff --git a/src/scriptengines/javascript/common/extension_io.cpp b/src/scriptengines/javascript/common/extension_io.cpp deleted file mode 100644 index 983ac405c..000000000 --- a/src/scriptengines/javascript/common/extension_io.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2011 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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 "scriptenv.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include - -QScriptValue ScriptEnv::openUrl(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - if (context->argumentCount() == 0) { - return false; - } - - QScriptValue v = context->argument(0); - QUrl url = v.isString() ? QUrl::fromUserInput(v.toString()) : qscriptvalue_cast(v); - - if (!url.isValid()) { - return false; - } - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (!env) { - return false; - } - - if (!(env->m_allowedUrls & AppLaunching) && - !((env->m_allowedUrls & HttpUrls) && (url.protocol() == "http" || url.protocol() == "https"))) { - return false; - } - - new KRun(url, 0); - return true; -} - -// TODO these should throw an exception -QScriptValue ScriptEnv::getUrl(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() == 0) { - return engine->undefinedValue(); - } - - QScriptValue v = context->argument(0); - QUrl url = v.isString() ? QUrl::fromUserInput(v.toString()) : qscriptvalue_cast(v); - - if (!url.isValid()) { - return engine->undefinedValue(); - } - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (!env) { - //qDebug() << "findScriptEnv failed"; - return engine->undefinedValue(); - } - - if (url.isLocalFile()) { - if (!(env->m_allowedUrls & LocalUrls)) { - return engine->undefinedValue(); - } - } else if (!(env->m_allowedUrls & NetworkUrls) && - !((env->m_allowedUrls & HttpUrls) && (url.protocol() == "http" || url.protocol() == "https"))) { - return engine->undefinedValue(); - } - - KIO::Job *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); - return engine->newQObject(job); -} - -QScriptValue ScriptEnv::download(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() == 0) { - return engine->undefinedValue(); - } - - QScriptValue v = context->argument(0); - QUrl url = v.isString() ? QUrl::fromUserInput(v.toString()) : qscriptvalue_cast(v); - - if (!url.isValid()) { - return engine->undefinedValue(); - } - - QString requestedFileName; - if (context->argumentCount() > 1) { - requestedFileName = context->argument(1).toString(); - } - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (!env) { - //qDebug() << "findScriptEnv failed"; - return engine->undefinedValue(); - } - - QStringList protocols; - protocols << "http" << "https" << "ftp" << "ftps"; - if (!protocols.contains(url.protocol())) { - return engine->undefinedValue(); - } - - QScriptContext *c = engine->currentContext(); - QString destination; - while (c) { - QScriptValue v = c->activationObject().property("__plasma_package"); - if (v.isVariant()) { - KDesktopFile config(v.toVariant().value().path() + "/metadata.desktop"); - KConfigGroup cg = config.desktopGroup(); - const QString pluginName = cg.readEntry("X-KDE-PluginInfo-Name", QString()); - destination = KGlobalSettings::downloadPath() + "Plasma/" + pluginName + '/'; - break; - } - - c = c->parentContext(); - } - - if (destination.isEmpty()) { - return engine->undefinedValue(); - } - - requestedFileName.prepend(destination); - QDir dir(requestedFileName); - dir.mkpath(destination); - if (!dir.absolutePath().startsWith(destination)) { - requestedFileName = destination; - } - - //TODO: allow showing desktop progress info? - KIO::CopyJob *job = KIO::copy(url, QUrl::fromLocalFile(requestedFileName), KIO::HideProgressInfo); - return engine->newQObject(job); -} - -QScriptValue ScriptEnv::userDataPath(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - if (context->argumentCount() == 0) { - return QDir::homePath(); - } - - const QString type = context->argument(0).toString(); - if (type.isEmpty()) { - return QDir::homePath(); - } - - if (context->argumentCount() > 1) { - const QString filename = context->argument(1).toString(); - return KStandardDirs::locateLocal(type.toLatin1(), filename); - } - - if (type.compare("desktop", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::desktopPath(); - } else if (type.compare("autostart", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::autostartPath(); - } else if (type.compare("documents", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::documentPath(); - } else if (type.compare("music", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::musicPath(); - } else if (type.compare("video", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::videosPath(); - } else if (type.compare("downloads", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::downloadPath(); - } else if (type.compare("pictures", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::picturesPath(); - } - - return QString(); -} - -void ScriptEnv::registerGetUrl(QScriptValue &obj) -{ - QScriptValue get = obj.property("getUrl"); - if (!get.isValid()) { - obj.setProperty("getUrl", m_engine->newFunction(ScriptEnv::getUrl)); - } -} - -void ScriptEnv::registerOpenUrl(QScriptValue &obj) -{ - QScriptValue value = obj.property("openUrl"); - if (!value.isValid()) { - obj.setProperty("openUrl", m_engine->newFunction(ScriptEnv::openUrl)); - } -} - - diff --git a/src/scriptengines/javascript/common/extension_launchapp.cpp b/src/scriptengines/javascript/common/extension_launchapp.cpp deleted file mode 100644 index 11fb83247..000000000 --- a/src/scriptengines/javascript/common/extension_launchapp.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright 2011 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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 "scriptenv.h" - -#include -#include -#include -#include -#include -#include - -QScriptValue ScriptEnv::runApplication(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - if (context->argumentCount() == 0) { - return false; - } - - KUrl::List urls; - if (context->argumentCount() > 1) { - urls = qscriptvalue_cast(context->argument(1)); - } - - const QString app = context->argument(0).toString(); - - const QString exec = KStandardDirs::findExe(app); - if (!exec.isEmpty()) { - return KRun::run(exec, urls, 0); - } - - KService::Ptr service = KService::serviceByStorageId(app); - if (service) { - return KRun::run(*service, urls, 0); - } - - return false; -} - -QScriptValue ScriptEnv::runCommand(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine); - - if (context->argumentCount() == 0) { - return false; - } - - const QString exec = KStandardDirs::findExe(context->argument(0).toString()); - if (!exec.isEmpty()) { - QString args; - if (context->argumentCount() > 1) { - const QStringList argList = qscriptvalue_cast(context->argument(1)); - if (!argList.isEmpty()) { - args = ' ' + KShell::joinArgs(argList); - } - } - - return KRun::runCommand(exec + args, 0); - } - - return false; -} - -QScriptValue ScriptEnv::applicationExists(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - if (context->argumentCount() == 0) { - return false; - } - - const QString application = context->argument(0).toString(); - if (application.isEmpty()) { - return false; - } - - // first, check for it in $PATH - if (!KStandardDirs::findExe(application).isEmpty()) { - return true; - } - - if (KService::serviceByStorageId(application)) { - return true; - } - - if (application.contains("'")) { - // apostrophes just screw up the trader lookups below, so check for it - return false; - } - - // next, consult ksycoca for an app by that name - if (!KServiceTypeTrader::self()->query("Application", QString("Name =~ '%1'").arg(application)).isEmpty()) { - return true; - } - - // next, consult ksycoca for an app by that generic name - if (!KServiceTypeTrader::self()->query("Application", QString("GenericName =~ '%1'").arg(application)).isEmpty()) { - return true; - } - - return false; -} - -QScriptValue ScriptEnv::defaultApplication(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - if (context->argumentCount() == 0) { - return false; - } - - const QString application = context->argument(0).toString(); - if (application.isEmpty()) { - return false; - } - - const bool storageId = context->argumentCount() < 2 ? false : context->argument(1).toBool(); - - // FIXME: there are some pretty horrible hacks below, in the sense that they assume a very - // specific implementation system. there is much room for improvement here. see - // kdebase-runtime/kcontrol/componentchooser/ for all the gory details ;) - if (application.compare("mailer", Qt::CaseInsensitive) == 0) { - KEMailSettings settings; - - // in KToolInvocation, the default is kmail; but let's be friendlier :) - QString command = settings.getSetting(KEMailSettings::ClientProgram); - if (command.isEmpty()) { - if (KService::Ptr kontact = KService::serviceByStorageId("kontact")) { - return storageId ? kontact->storageId() : kontact->exec(); - } else if (KService::Ptr kmail = KService::serviceByStorageId("kmail")) { - return storageId ? kmail->storageId() : kmail->exec(); - } - } - - if (!command.isEmpty()) { - if (settings.getSetting(KEMailSettings::ClientTerminal) == "true") { - KConfigGroup confGroup(KSharedConfig::openConfig(), "General"); - const QString preferredTerminal = confGroup.readPathEntry("TerminalApplication", - QString::fromLatin1("konsole")); - command = preferredTerminal + QString::fromLatin1(" -e ") + command; - } - - return command; - } - } else if (application.compare("browser", Qt::CaseInsensitive) == 0) { - KConfigGroup config(KSharedConfig::openConfig(), "General"); - QString browserApp = config.readPathEntry("BrowserApplication", QString()); - if (browserApp.isEmpty()) { - const KService::Ptr htmlApp = KMimeTypeTrader::self()->preferredService(QLatin1String("text/html")); - if (htmlApp) { - browserApp = storageId ? htmlApp->storageId() : htmlApp->exec(); - } - } else if (browserApp.startsWith('!')) { - browserApp = browserApp.mid(1); - } - - return browserApp; - } else if (application.compare("terminal", Qt::CaseInsensitive) == 0) { - KConfigGroup confGroup(KSharedConfig::openConfig(), "General"); - return confGroup.readPathEntry("TerminalApplication", QString::fromLatin1("konsole")); - } else if (application.compare("filemanager", Qt::CaseInsensitive) == 0) { - KService::Ptr service = KMimeTypeTrader::self()->preferredService("inode/directory"); - if (service) { - return storageId ? service->storageId() : service->exec(); - } - } else if (application.compare("windowmanager", Qt::CaseInsensitive) == 0) { - KConfig cfg("ksmserverrc", KConfig::NoGlobals); - KConfigGroup confGroup(&cfg, "General"); - return confGroup.readEntry("windowManager", QString::fromLatin1("konsole")); - } else if (KService::Ptr service = KMimeTypeTrader::self()->preferredService(application)) { - return storageId ? service->storageId() : service->exec(); - } else { - // try the files in share/apps/kcm_componentchooser/ - const QStringList services = KGlobal::dirs()->findAllResources("data","kcm_componentchooser/*.desktop", KStandardDirs::NoDuplicates); - //qDebug() << "ok, trying in" << services.count(); - foreach (const QString &service, services) { - KConfig config(service, KConfig::SimpleConfig); - KConfigGroup cg = config.group(QByteArray()); - const QString type = cg.readEntry("valueName", QString()); - //qDebug() << " checking" << service << type << application; - if (type.compare(application, Qt::CaseInsensitive) == 0) { - KConfig store(cg.readPathEntry("storeInFile", "null")); - KConfigGroup storeCg(&store, cg.readEntry("valueSection", QString())); - const QString exec = storeCg.readPathEntry(cg.readEntry("valueName", "kcm_componenchooser_null"), - cg.readEntry("defaultImplementation", QString())); - if (!exec.isEmpty()) { - return exec; - } - - break; - } - } - } - - return false; -} - -QScriptValue ScriptEnv::applicationPath(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - if (context->argumentCount() == 0) { - return false; - } - - const QString application = context->argument(0).toString(); - if (application.isEmpty()) { - return false; - } - - // first, check for it in $PATH - const QString path = KStandardDirs::findExe(application); - if (!path.isEmpty()) { - return path; - } - - if (KService::Ptr service = KService::serviceByStorageId(application)) { - return KStandardDirs::locate("apps", service->entryPath()); - } - - if (application.contains("'")) { - // apostrophes just screw up the trader lookups below, so check for it - return QString(); - } - - // next, consult ksycoca for an app by that name - KService::List offers = KServiceTypeTrader::self()->query("Application", QString("Name =~ '%1'").arg(application)); - if (offers.isEmpty()) { - // next, consult ksycoca for an app by that generic name - offers = KServiceTypeTrader::self()->query("Application", QString("GenericName =~ '%1'").arg(application)); - } - - if (!offers.isEmpty()) { - KService::Ptr offer = offers.first(); - return KStandardDirs::locate("apps", offer->entryPath()); - } - - return QString(); -} - diff --git a/src/scriptengines/javascript/common/guiscriptenv.cpp b/src/scriptengines/javascript/common/guiscriptenv.cpp deleted file mode 100644 index 204dda8c0..000000000 --- a/src/scriptengines/javascript/common/guiscriptenv.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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. - */ - -#define USEGUI -#include "scriptenv.cpp" -#include "scriptenv.moc" - diff --git a/src/scriptengines/javascript/common/javascriptaddonpackagestructure.cpp b/src/scriptengines/javascript/common/javascriptaddonpackagestructure.cpp deleted file mode 100644 index aba80b41c..000000000 --- a/src/scriptengines/javascript/common/javascriptaddonpackagestructure.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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 "javascriptaddonpackagestructure.h" - -#include -#include - -JavascriptAddonPackageStructure::JavascriptAddonPackageStructure(QObject *parent, const QVariantList &args) - : Plasma::PackageStructure(parent, "Plasma/JavascriptAddon") -{ - Q_UNUSED(args) - setServicePrefix("plasma-javascriptaddon-"); - setDefaultPackageRoot("plasma/javascript-addons/"); - addDirectoryDefinition("images", "images/", i18n("Images")); - QStringList mimetypes; - mimetypes << "image/svg+xml" << "image/png" << "image/jpeg"; - setMimetypes("images", mimetypes); - - addDirectoryDefinition("config", "config/", i18n("Configuration Definitions")); - mimetypes.clear(); - mimetypes << "text/xml"; - setMimetypes("config", mimetypes); - - addDirectoryDefinition("ui", "ui", i18n("User Interface")); - setMimetypes("ui", mimetypes); - - addDirectoryDefinition("data", "data", i18n("Data Files")); - - addDirectoryDefinition("scripts", "code", i18n("Executable Scripts")); - mimetypes.clear(); - mimetypes << "text/plain"; - setMimetypes("scripts", mimetypes); - - addDirectoryDefinition("translations", "locale", i18n("Translations")); - - addDirectoryDefinition("animations", "animations/", i18n("Animation scripts")); - - addFileDefinition("mainscript", "code/main.js", i18n("Main Script File")); - setRequired("mainscript", true); -} - -void JavascriptAddonPackageStructure::pathChanged() -{ - KDesktopFile config(path() + "/metadata.desktop"); - KConfigGroup cg = config.desktopGroup(); - QString mainScript = cg.readEntry("X-Plasma-MainScript", QString()); - if (!mainScript.isEmpty()) { - addFileDefinition("mainscript", mainScript, i18n("Main Script File")); - } -} - -#include "javascriptaddonpackagestructure.moc" - diff --git a/src/scriptengines/javascript/common/javascriptaddonpackagestructure.h b/src/scriptengines/javascript/common/javascriptaddonpackagestructure.h deleted file mode 100644 index 88b1cb4e8..000000000 --- a/src/scriptengines/javascript/common/javascriptaddonpackagestructure.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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. - */ - -#ifndef JAVASCRIPTADDONPACKAGESTRUCTURE_H -#define JAVASCRIPTADDONPACKAGESTRUCTURE_H - -#include - -class JavascriptAddonPackageStructure : public Plasma::PackageStructure -{ - Q_OBJECT - -public: - JavascriptAddonPackageStructure(QObject *parent = 0, const QVariantList &args = QVariantList()); - - void pathChanged(); -}; - -#endif - diff --git a/src/scriptengines/javascript/common/scriptenv.cpp b/src/scriptengines/javascript/common/scriptenv.cpp deleted file mode 100644 index 63d899caa..000000000 --- a/src/scriptengines/javascript/common/scriptenv.cpp +++ /dev/null @@ -1,532 +0,0 @@ -/* - * Copyright 2007-2008 Richard J. Moore - * Copyright 2009 Aaron J. Seigo - * - * 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 "scriptenv.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef USEGUI -#include "simplebindings/filedialogproxy.h" -#endif - -#include "javascriptaddonpackagestructure.h" - -Q_DECLARE_METATYPE(ScriptEnv*) - -ScriptEnv::ScriptEnv(QObject *parent, QScriptEngine *engine) - : QObject(parent), - m_allowedUrls(NoUrls), - m_engine(engine) -{ - connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), this, SLOT(signalException())); - - setupGlobalObject(); -} - -ScriptEnv::~ScriptEnv() -{ -} - -void ScriptEnv::setupGlobalObject() -{ - QScriptValue global = m_engine->globalObject(); - - // Add an accessor so we can find the scriptenv given only the engine. The - // property is hidden from scripts. - global.setProperty("__plasma_scriptenv", m_engine->newQObject(this), - QScriptValue::ReadOnly|QScriptValue::Undeletable|QScriptValue::SkipInEnumeration); - // Add utility functions -#ifndef DECLARATIVE - global.setProperty("print", m_engine->newFunction(ScriptEnv::print)); -#endif - global.setProperty("debug", m_engine->newFunction(ScriptEnv::debug)); -} - -void ScriptEnv::addMainObjectProperties(QScriptValue &value) -{ - value.setProperty("listAddons", m_engine->newFunction(ScriptEnv::listAddons)); - value.setProperty("loadAddon", m_engine->newFunction(ScriptEnv::loadAddon)); - value.setProperty("addEventListener", m_engine->newFunction(ScriptEnv::addEventListener)); - value.setProperty("removeEventListener", m_engine->newFunction(ScriptEnv::removeEventListener)); - value.setProperty("hasExtension", m_engine->newFunction(ScriptEnv::hasExtension)); -} - -QScriptEngine *ScriptEnv::engine() const -{ - return m_engine; -} - -ScriptEnv *ScriptEnv::findScriptEnv(QScriptEngine *engine) -{ - QScriptValue global = engine->globalObject(); - return qscriptvalue_cast(global.property("__plasma_scriptenv")); -} - -void ScriptEnv::signalException() -{ - checkForErrors(false); -} - -void ScriptEnv::registerEnums(QScriptValue &scriptValue, const QMetaObject &meta) -{ - //manually create enum values. ugh - QScriptEngine *engine = scriptValue.engine(); - for (int i = 0; i < meta.enumeratorCount(); ++i) { - QMetaEnum e = meta.enumerator(i); - //qDebug() << e.name(); - for (int i=0; i < e.keyCount(); ++i) { - //qDebug() << e.key(i) << e.value(i); - scriptValue.setProperty(e.key(i), QScriptValue(engine, e.value(i))); - } - } -} - -bool ScriptEnv::include(const QString &path) -{ - QFile file(path); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning() << i18n("Unable to load script file: %1", path); - return false; - } - - QString script = file.readAll(); - //qDebug() << "Script says" << script; - - // change the context to the parent context so that the include is actually - // executed in the same context as the caller; seems to be what javascript - // coders expect :) - QScriptContext *ctx = m_engine->currentContext(); - if (ctx && ctx->parentContext()) { - ctx->setActivationObject(ctx->parentContext()->activationObject()); - ctx->setThisObject(ctx->parentContext()->thisObject()); - } - - m_engine->evaluate(script, path); - - return !checkForErrors(true); -} - -bool ScriptEnv::checkForErrors(bool fatal) -{ - if (m_engine->hasUncaughtException()) { - emit reportError(this, fatal); - if (!fatal) { - m_engine->clearExceptions(); - } - return true; - } - - return false; -} - -bool ScriptEnv::importBuiltinExtension(const QString &extension, QScriptValue &obj) -{ - // qDebug() << extension; - if ("filedialog" == extension) { -#ifdef USEGUI - FileDialogProxy::registerWithRuntime(m_engine); - return true; -#endif - } else if ("launchapp" == extension) { - m_allowedUrls |= AppLaunching; - obj.setProperty("runApplication", m_engine->newFunction(ScriptEnv::runApplication)); - obj.setProperty("runCommand", m_engine->newFunction(ScriptEnv::runCommand)); - registerOpenUrl(obj); - return true; - } else if ("http" == extension) { - m_allowedUrls |= HttpUrls; - registerGetUrl(obj); - registerOpenUrl(obj); - return true; - } else if ("networkio" == extension) { - m_allowedUrls |= HttpUrls | NetworkUrls; - registerGetUrl(obj); - return true; - } else if ("localio" == extension) { - m_allowedUrls |= LocalUrls; - registerGetUrl(obj); - obj.setProperty("userDataPath", m_engine->newFunction(ScriptEnv::userDataPath)); - obj.setProperty("runCommand", m_engine->newFunction(ScriptEnv::runCommand)); - return true; - } else if ("download" == extension) { - obj.setProperty("download", m_engine->newFunction(ScriptEnv::download)); - return true; - } - - return false; -} - -bool ScriptEnv::importExtensions(const KPluginInfo &info, QScriptValue &obj, Authorization &auth) -{ - QStringList requiredExtensions = info.property("X-Plasma-RequiredExtensions", QVariant::StringList).toStringList(); - if (!requiredExtensions.isEmpty()) { - // qDebug() << "required extensions are" << requiredExtensions; - } - - foreach (const QString &ext, requiredExtensions) { - QString extension = ext.toLower(); - if (m_extensions.contains(extension)) { - continue; - } - - if (!auth.authorizeRequiredExtension(extension)) { - return false; - } - - if (!importBuiltinExtension(extension, obj)) { - if (auth.authorizeExternalExtensions()) { - m_engine->importExtension(extension); - } - } - - if (checkForErrors(true)) { - return false; - } else { - m_extensions << extension; - } - } - - QStringList optionalExtensions = info.property("X-Plasma-OptionalExtensions", QVariant::StringList).toStringList(); - if (!optionalExtensions.isEmpty()) { - // qDebug() << "optional extensions are" << optionalExtensions; - } - - foreach (const QString &ext, optionalExtensions) { - QString extension = ext.toLower(); - - if (m_extensions.contains(extension)) { - continue; - } - - if (!auth.authorizeOptionalExtension(extension)) { - continue; - } - - if (!importBuiltinExtension(extension, obj)) { - if (auth.authorizeExternalExtensions()) { - m_engine->importExtension(extension); - } - } - - if (!checkForErrors(false)) { - m_extensions << extension; - } - } - - return true; -} - -QSet ScriptEnv::loadedExtensions() const -{ - return m_extensions; -} - -QScriptValue ScriptEnv::debug(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() != 1) { - return throwNonFatalError(i18n("debug takes one argument"), context, engine); - } - - // qDebug() << context->argument(0).toString(); - return engine->undefinedValue(); -} - -QScriptValue ScriptEnv::throwNonFatalError(const QString &msg, QScriptContext *context, QScriptEngine *engine) -{ - QScriptValue rv = context->throwError(msg); - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (env) { - env->checkForErrors(false); - } - return rv; -} - -QScriptValue ScriptEnv::print(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() != 1) { - return throwNonFatalError(i18n("print() takes one argument"), context, engine); - } - - std::cout << context->argument(0).toString().toLocal8Bit().constData() << std::endl; - return engine->undefinedValue(); -} - -QScriptValue ScriptEnv::listAddons(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 1) { - return throwNonFatalError(i18n("listAddons takes one argument: addon type"), context, engine); - } - - const QString type = context->argument(0).toString(); - - if (type.isEmpty()) { - return engine->undefinedValue(); - } - - const QString constraint = QString("[X-KDE-PluginInfo-Category] == '%1'").arg(type); - KService::List offers = KServiceTypeTrader::self()->query("Plasma/JavascriptAddon", constraint); - - int i = 0; - QScriptValue addons = engine->newArray(offers.count()); - foreach (KService::Ptr offer, offers) { - KPluginInfo info(offer); - QScriptValue v = engine->newObject(); - v.setProperty("id", info.pluginName(), QScriptValue::ReadOnly); - v.setProperty("name", info.name(), QScriptValue::ReadOnly); - addons.setProperty(i++, v); - } - - return addons; -} - -QScriptValue ScriptEnv::loadAddon(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 2) { - return throwNonFatalError(i18n("loadAddon takes two arguments: addon type and addon name to load"), context, engine); - } - - const QString type = context->argument(0).toString(); - const QString plugin = context->argument(1).toString(); - - if (type.isEmpty() || plugin.isEmpty()) { - return throwNonFatalError(i18n("loadAddon takes two arguments: addon type and addon name to load"), context, engine); - } - - const QString constraint = QString("[X-KDE-PluginInfo-Category] == '%1' and [X-KDE-PluginInfo-Name] == '%2'") - .arg(type, plugin); - KService::List offers = KServiceTypeTrader::self()->query("Plasma/JavascriptAddon", constraint); - - if (offers.isEmpty()) { - return throwNonFatalError(i18n("Failed to find Addon %1 of type %2", plugin, type), context, engine); - } - - Plasma::PackageStructure::Ptr structure(new JavascriptAddonPackageStructure); - const QString subPath = structure->defaultPackageRoot() + '/' + plugin + '/'; - const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, subPath); - Plasma::Package package(path, structure); - - QFile file(package.filePath("mainscript")); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - return throwNonFatalError(i18n("Failed to open script file for Addon %1: %2", plugin, package.filePath("mainscript")), context, engine); - } - - QTextStream buffer(&file); - QString code(buffer.readAll()); - - QScriptContext *innerContext = engine->pushContext(); - innerContext->activationObject().setProperty("registerAddon", engine->newFunction(ScriptEnv::registerAddon)); - QScriptValue v = engine->newVariant(QVariant::fromValue(package)); - innerContext->activationObject().setProperty("__plasma_package", v, - QScriptValue::ReadOnly | - QScriptValue::Undeletable | - QScriptValue::SkipInEnumeration); - //qDebug() << "context is" << innerContext; - engine->evaluate(code, file.fileName()); - engine->popContext(); - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (env && env->checkForErrors(false)) { - return false; - } - - return true; -} - -QScriptValue ScriptEnv::registerAddon(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() > 0) { - QScriptValue func = context->argument(0); - if (func.isFunction()) { - QScriptValue obj = func.construct(); - obj.setProperty("__plasma_package", - context->parentContext()->activationObject().property("__plasma_package"), - QScriptValue::ReadOnly | - QScriptValue::Undeletable | - QScriptValue::SkipInEnumeration); - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (env) { - QScriptValueList args; - args << obj; - env->callEventListeners("addoncreated", args); - } - } - } - - return engine->undefinedValue(); -} - -QString ScriptEnv::filePathFromScriptContext(const char *type, const QString &file) const -{ - //qDebug() << type << file; - QScriptContext *c = m_engine->currentContext(); - while (c) { - QScriptValue v = c->activationObject().property("__plasma_package"); - //qDebug() << "variant in parent context?" << v.isVariant(); - if (v.isVariant()) { - const QString path = v.toVariant().value().filePath(type, file); - if (!path.isEmpty()) { - return path; - } - } - - c = c->parentContext(); - } - - //qDebug() << "fail"; - return QString(); -} - -QScriptValue ScriptEnv::addEventListener(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 2) { - return false; - } - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (!env) { - return false; - } - - return env->addEventListener(context->argument(0).toString(), context->argument(1)); -} - -QScriptValue ScriptEnv::removeEventListener(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 2) { - return false; - } - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (!env) { - return false; - } - - return env->removeEventListener(context->argument(0).toString(), context->argument(1)); -} - -QScriptValue ScriptEnv::hasExtension(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 1) { - return false; - } - - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - if (!env) { - return false; - } - - return env->m_extensions.contains(context->argument(0).toString().toLower()); -} - -QScriptValue ScriptEnv::callFunction(QScriptValue &func, const QScriptValueList &args, const QScriptValue &activator) -{ - if (!func.isFunction()) { - return m_engine->undefinedValue(); - } - - QScriptContext *ctx = m_engine->pushContext(); - ctx->setActivationObject(activator); - QScriptValue rv = func.call(activator, args); - m_engine->popContext(); - - if (m_engine->hasUncaughtException()) { - emit reportError(this, false); - m_engine->clearExceptions(); - return m_engine->undefinedValue(); - } - - return rv; -} - -bool ScriptEnv::hasEventListeners(const QString &event) const -{ - return m_eventListeners.contains(event); -} - -bool ScriptEnv::callEventListeners(const QString &event, const QScriptValueList &args) -{ - if (!m_eventListeners.contains(event.toLower())) { - return false; - } - - QScriptValueList funcs = m_eventListeners.value(event.toLower()); - QMutableListIterator it(funcs); - while (it.hasNext()) { - callFunction(it.next(), args); - } - - return true; -} - -bool ScriptEnv::addEventListener(const QString &event, const QScriptValue &func) -{ - if (func.isFunction() && !event.isEmpty()) { - m_eventListeners[event.toLower()].append(func); - return true; - } - - return false; -} - -bool ScriptEnv::removeEventListener(const QString &event, const QScriptValue &func) -{ - bool found = false; - - if (func.isFunction()) { - QScriptValueList funcs = m_eventListeners.value(event); - QMutableListIterator it(funcs); - while (it.hasNext()) { - if (it.next().equals(func)) { - it.remove(); - found = true; - } - } - - if (funcs.isEmpty()) { - m_eventListeners.remove(event.toLower()); - } else { - m_eventListeners.insert(event.toLower(), funcs); - } - } - - return found; -} - -#ifndef USEGUI -#include "scriptenv.moc" -#endif diff --git a/src/scriptengines/javascript/common/scriptenv.h b/src/scriptengines/javascript/common/scriptenv.h deleted file mode 100644 index cc0c4f5be..000000000 --- a/src/scriptengines/javascript/common/scriptenv.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2007-2008 Richard J. Moore - * Copyright 2009 Aaron J. Seigo - * - * 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. - */ - -#ifndef SCRIPTENV_H -#define SCRIPTENV_H - -#include -#include - -#include - -#include "authorization.h" - -namespace Plasma -{ - class Package; -} // namespace Plasma - -class ScriptEnv : public QObject -{ - Q_OBJECT -public: - enum AllowedUrl { NoUrls = 0, - HttpUrls = 1, - NetworkUrls = 2, - LocalUrls = 4, - AppLaunching = 8}; - Q_DECLARE_FLAGS(AllowedUrls, AllowedUrl) - - ScriptEnv(QObject *parent, QScriptEngine *engine); - ~ScriptEnv(); - - /** - * Adds common properties (e.g. registerEventFilter) - * for a 'main' object (e.g. plasmoid, engine, runner) - */ - void addMainObjectProperties(QScriptValue &value); - - /** Returns the QScriptEngine in use. */ - QScriptEngine *engine() const; - - /** Returns the ScriptEnv in use for a given QScriptEngine or 0. */ - static ScriptEnv *findScriptEnv(QScriptEngine *engine); - - static void registerEnums(QScriptValue &scriptValue, const QMetaObject &meta); - bool include(const QString &path); - - bool importExtensions(const KPluginInfo &info, QScriptValue &obj, Authorization &authorizer); - QSet loadedExtensions() const; - - bool checkForErrors(bool fatal); - - bool addEventListener(const QString &event, const QScriptValue &func); - bool removeEventListener(const QString &event, const QScriptValue &func); - - QScriptValue callFunction(QScriptValue &func, const QScriptValueList &args = QScriptValueList(), const QScriptValue &activator = QScriptValue()); - bool callEventListeners(const QString &event, const QScriptValueList &args = QScriptValueList()); - bool hasEventListeners(const QString &event) const; - - QString filePathFromScriptContext(const char *type, const QString &file) const; - -Q_SIGNALS: - void reportError(ScriptEnv *engine, bool fatal); - -private: - void registerGetUrl(QScriptValue &obj); - void registerOpenUrl(QScriptValue &obj); - bool importBuiltinExtension(const QString &extension, QScriptValue &obj); - - static QScriptValue debug(QScriptContext *context, QScriptEngine *engine); - static QScriptValue print(QScriptContext *context, QScriptEngine *engine); - static QScriptValue runApplication(QScriptContext *context, QScriptEngine *engine); - static QScriptValue runCommand(QScriptContext *context, QScriptEngine *engine); - static QScriptValue defaultApplication(QScriptContext *context, QScriptEngine *engine); - static QScriptValue applicationPath(QScriptContext *context, QScriptEngine *engine); - static QScriptValue applicationExists(QScriptContext *context, QScriptEngine *engine); - static QScriptValue openUrl(QScriptContext *context, QScriptEngine *engine); - static QScriptValue getUrl(QScriptContext *context, QScriptEngine *engine); - static QScriptValue download(QScriptContext *context, QScriptEngine *engine); - static QScriptValue userDataPath(QScriptContext *context, QScriptEngine *engine); - static QScriptValue listAddons(QScriptContext *context, QScriptEngine *engine); - static QScriptValue loadAddon(QScriptContext *context, QScriptEngine *engine); - static QScriptValue registerAddon(QScriptContext *context, QScriptEngine *engine); - static QScriptValue addEventListener(QScriptContext *context, QScriptEngine *engine); - static QScriptValue removeEventListener(QScriptContext *context, QScriptEngine *engine); - static QScriptValue hasExtension(QScriptContext *context, QScriptEngine *engine); - static QScriptValue throwNonFatalError(const QString &msg, QScriptContext *context, QScriptEngine *engine); - -private Q_SLOTS: - void signalException(); - -private: - /** Call to set common properties on the global object **/ - void setupGlobalObject(); - - QSet m_extensions; - AllowedUrls m_allowedUrls; - QScriptEngine *m_engine; - QHash m_eventListeners; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(ScriptEnv::AllowedUrls) - -#endif - diff --git a/src/scriptengines/javascript/data/plasma-javascriptaddon.desktop b/src/scriptengines/javascript/data/plasma-javascriptaddon.desktop deleted file mode 100644 index c95e2f1b9..000000000 --- a/src/scriptengines/javascript/data/plasma-javascriptaddon.desktop +++ /dev/null @@ -1,21 +0,0 @@ -[Desktop Entry] -Name=Plasma JavaScript Addon -Name[cs]=Doplněk Plasmy JavaScript -Name[de]=JavaScript-Erweiterung für Plasma -Name[es]=Complemento JavaScript para Plasma -Name[fi]=Plasma JavaScript -liitännäinen -Name[fr]=Extension JavaScript de Plasma -Name[mr]=प्लाज्मा जावास्क्रिप्ट Addon -Name[nl]=Addon voor Plasma JavaScript -Name[pl]=Dodatek dla JavaScript -Name[pt]=Extensão de JavaScript do Plasma -Name[pt_BR]=Complementos de JavaScript do Plasma -Name[sk]=Doplnok JavaScript pre plasmu -Name[sv]=Plasma Javaskript-tillägg -Name[tr]=Plasma JavaScript Eklentisi -Name[ug]=Plasma JavaScript قوشۇلما -Name[uk]=Додаток JavaScript до Плазми -Name[x-test]=xxPlasma JavaScript Addonxx -Type=ServiceType -X-KDE-ServiceType=Plasma/JavascriptAddon -Icon=plasma diff --git a/src/scriptengines/javascript/data/plasma-packagestructure-javascript-addon.desktop b/src/scriptengines/javascript/data/plasma-packagestructure-javascript-addon.desktop deleted file mode 100644 index 5298b57d7..000000000 --- a/src/scriptengines/javascript/data/plasma-packagestructure-javascript-addon.desktop +++ /dev/null @@ -1,48 +0,0 @@ -[Desktop Entry] -Name=Javascript Addon -Name[cs]=Doplněk JavaScript -Name[de]=JavaScript-Erweiterung -Name[es]=Complemento JavaScript -Name[fi]=Javascript-liitännäinen -Name[fr]=Extension JavaScript -Name[mr]=जावास्क्रिप्ट Addon -Name[nl]=Addon voor JavaScript -Name[pl]=Dodatek dla JavaScript -Name[pt]=Extensão de JavaScript -Name[pt_BR]=Complementos de JavaScript -Name[sk]=Doplnok JavaScript -Name[sv]=Javaskript-tillägg -Name[tr]=Javascript Eklentisi -Name[ug]=Javascript قوشۇلما -Name[uk]=Додаток JavaScript -Name[x-test]=xxJavascript Addonxx -Comment=Addons for Javascript Plasma plugins -Comment[cs]=Doplňky pro javascriptové zásuvné moduly plasmy -Comment[de]=Erweiterungen für JavaScript-Module in Plasma -Comment[fi]=Lisäosia JavaScript Plasma -liitännäisille -Comment[fr]=Extensions pour les modules externes de Plasma en JavaScript -Comment[mr]=जावास्क्रिप्ट प्लाज्मा प्लगइनचे Addon -Comment[nl]=Addons voor Javascript Plasma plugins -Comment[pl]=Dodatki dla wtyczek Plazmy w JavaScript -Comment[pt]=Extras para os 'plugins' do Plasma em JavaScript -Comment[pt_BR]=Complementos para os plugins do Plasma em JavaScript -Comment[sk]=Doplnky pre Javascriptové moduly plasmy -Comment[sv]=Tillägg för Javascript Plasma-insticksprogram -Comment[tr]=Javascript Plasma eklentileri için ek araçlar -Comment[ug]=Javascript Plasma قىستۇرمىسى ئۈچۈن قوشۇلما -Comment[uk]=Додатки для використання Javascript у Плазмі -Comment[x-test]=xxAddons for Javascript Plasma pluginsxx -Type=Service -X-KDE-ServiceTypes=Plasma/PackageStructure - -X-KDE-Library=plasma_packagestructure_javascriptaddon -X-KDE-PluginInfo-Author=Aaron Seigo -X-KDE-PluginInfo-Email=aseigh@kde.org -X-KDE-PluginInfo-Name=Plasma/JavascriptAddon -X-KDE-PluginInfo-Version=0.1 -X-KDE-PluginInfo-Website=http://plasma.kde.org/ -X-KDE-PluginInfo-License=GPLv2+ -X-KDE-PluginInfo-EnabledByDefault=true -X-Plasma-PackageFileFilter=*.plasmaaddon -X-Plasma-PackageFileMimetypes=application/zip - diff --git a/src/scriptengines/javascript/data/plasma-scriptengine-applet-declarative.desktop b/src/scriptengines/javascript/data/plasma-scriptengine-applet-declarative.desktop deleted file mode 100644 index 4373d4838..000000000 --- a/src/scriptengines/javascript/data/plasma-scriptengine-applet-declarative.desktop +++ /dev/null @@ -1,50 +0,0 @@ -[Desktop Entry] -Name=Declarative widget -Name[cs]=Deklarativní widget -Name[de]=Deklaratives Bedienelement -Name[fi]=Deklaratiivinen sovelma -Name[fr]=Composant graphique déclaratif -Name[mr]=वर्णनात्मक विजेट -Name[nl]=Widget voor declaratie -Name[pl]=Deklaratywny element interfejsu -Name[pt]=Item declarativo -Name[pt_BR]=Widget declarativo -Name[sk]=Deklaratívny widget -Name[sv]=Deklarativ grafisk komponent -Name[tr]=Bildirim parçacığı -Name[ug]=ئېنىقلىما ۋىجېت -Name[uk]=Декларативний віджет -Name[x-test]=xxDeclarative widgetxx -Comment=Native Plasma widget written in QML and JavaScript -Comment[cs]=Nativní Plasma widget napsaný v QML a JavaScriptu -Comment[de]=Echtes Plasma-Programm, geschrieben in QML und JavaScript -Comment[fi]=Natiivi, QML-pohjainen Plasma-sovelma -Comment[fr]=Composant graphique natif écrit en QML et JavaScript -Comment[mr]=जावास्क्रिप्ट व QML अंतर्गत लिहीले गेलेले मूळ प्लाज्मा विजेट -Comment[nl]=Hier thuishorend Plasma-widget geschreven in QML en JavaScript -Comment[pl]=Element interfejsu Plazmy napisany w QML lub JavaScript -Comment[pt]=Elemento nativo do Plasma feito em QML e JavaScript -Comment[pt_BR]=Widget do Plasma nativo escrito em QML e JavaScript -Comment[sk]=Natívny plasma widget napísaný v QML a JavaScripte -Comment[sv]=Inbyggd grafisk Plasma-komponent skriven i QML och Javascript -Comment[tr]=JavaScript ve QML ile yazılmış gerçek Plasma gereci -Comment[ug]=QML ۋە JavaScript بىلەن يېزىلغان ئەسلى Plasma ۋىجېتى -Comment[uk]=Віджет Плазми, написаний на QML та JavaScript -Comment[x-test]=xxNative Plasma widget written in QML and JavaScriptxx -Type=Service -Icon=text-x-script - -X-KDE-ServiceTypes=Plasma/ScriptEngine -X-KDE-Library=plasma_appletscript_declarative -X-EngineName=declarativeappletscript -X-Plasma-API=declarativeappletscript -X-Plasma-ComponentTypes=Applet - -X-KDE-PluginInfo-Author=Alexis Menard -X-KDE-PluginInfo-Email=menard@kde.org -X-KDE-PluginInfo-Name=qmlscript -X-KDE-PluginInfo-Version=0.1 -X-KDE-PluginInfo-Category=Examples -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=LGPL -X-KDE-PluginInfo-EnabledByDefault=true diff --git a/src/scriptengines/javascript/data/plasma-scriptengine-applet-simple-javascript.desktop b/src/scriptengines/javascript/data/plasma-scriptengine-applet-simple-javascript.desktop deleted file mode 100644 index 276eb6ad1..000000000 --- a/src/scriptengines/javascript/data/plasma-scriptengine-applet-simple-javascript.desktop +++ /dev/null @@ -1,41 +0,0 @@ -[Desktop Entry] -Name=JavaScript Widget -Name[cs]=JavaScript Widget -Name[de]=JavaScript-Programm -Name[fi]=JavaScript-sovelma -Name[fr]=Composant graphique de JavaScript -Name[mr]=जावास्क्रिप्ट विजेट -Name[nl]=JavaScript-widget -Name[pl]=Element interfejsu w JavaScript -Name[pt]=Elemento de JavaScript -Name[pt_BR]=Widget de JavaScript -Name[sk]=JavaScript widget -Name[sv]=Grafisk Javascript-komponent -Name[tr]=JavaScript Gereci -Name[ug]=JavaScript ۋىجېتى -Name[uk]=Віджет JavaScript -Name[x-test]=xxJavaScript Widgetxx -Comment=Native Plasma widget written in JavaScript -Comment[cs]=Nativní Plasma widget napsaný v JavaScriptu -Comment[de]=Echtes Plasma-Programm, geschrieben in JavaScript -Comment[fi]=Natiivi, JavaScript-pohjainen Plasma-sovelma -Comment[fr]=Composant graphique natif écrit en JavaScript -Comment[hu]=Natív Plasma felületi elem JavaScript nyelven írva -Comment[mr]=जावास्क्रिप्ट अंतर्गत लिहीले गेलेले मूळ प्लाज्मा विजेट -Comment[nl]=Plasma-widget geschreven in JavaScript -Comment[pl]=Element interfejsu Plazmy napisany w JavaScript -Comment[pt]=Elemento nativo do Plasma feito em JavaScript -Comment[pt_BR]=Widget do Plasma nativo escrito em JavaScript -Comment[sk]=Natívny plasma widget napísaný v JavaScripte -Comment[sv]=Inbyggd grafisk Plasma-komponent skriven i Javascript -Comment[tr]=JavaScript ile yazılmış gerçek Plasma gereci -Comment[ug]=JavaScript بىلەن يېزىلغان ئەسلى Plasma ۋىجېتى -Comment[uk]=Віджет Плазми, написаний на JavaScript -Comment[x-test]=xxNative Plasma widget written in JavaScriptxx -X-KDE-ServiceTypes=Plasma/ScriptEngine -Type=Service -Icon=text-x-script -X-KDE-Library=plasma_appletscript_simple_javascript -X-Plasma-API=javascript -X-Plasma-ComponentTypes=Applet -X-KDE-PluginInfo-Version=5 diff --git a/src/scriptengines/javascript/data/plasma-scriptengine-dataengine-javascript.desktop b/src/scriptengines/javascript/data/plasma-scriptengine-dataengine-javascript.desktop deleted file mode 100644 index 23452de9d..000000000 --- a/src/scriptengines/javascript/data/plasma-scriptengine-dataengine-javascript.desktop +++ /dev/null @@ -1,25 +0,0 @@ -[Desktop Entry] -Name=JavaScript DataEngine -Name[bs]=Javascript pogon podataka -Name[cs]=Datový nástroj JavaScript -Name[de]=JavaScript-Datentreiber -Name[fi]=JavaScript-datakone -Name[fr]=Moteur de données de JavaScript -Name[hu]=JavaScript adatmotor -Name[mr]=जावास्क्रिप्ट डेटाइंजिन -Name[nl]=JavaScript-data-engine -Name[pl]=Silnik danych JavaScript -Name[pt]=Motor de Dados do JavaScript -Name[pt_BR]=Mecanismo de dados JavaScript -Name[sk]=Dátový nástroj JavaScript -Name[sv]=Javascript-datagränssnitt -Name[tr]=JavaScript Veri Motoru -Name[ug]=JavaScript سانلىق-مەلۇمات ماتورى -Name[uk]=Рушій даних JavaScript -Name[x-test]=xxJavaScript DataEnginexx -X-KDE-ServiceTypes=Plasma/ScriptEngine -Type=Service -Icon=text-x-script -X-KDE-Library=plasma_dataenginescript_javascript -X-Plasma-API=javascript -X-Plasma-ComponentTypes=DataEngine diff --git a/src/scriptengines/javascript/data/plasma-scriptengine-runner-javascript.desktop b/src/scriptengines/javascript/data/plasma-scriptengine-runner-javascript.desktop deleted file mode 100644 index 1f978cdbd..000000000 --- a/src/scriptengines/javascript/data/plasma-scriptengine-runner-javascript.desktop +++ /dev/null @@ -1,45 +0,0 @@ -[Desktop Entry] -Name=JavaScript Runner -Name[bs]=Javascript izvođač -Name[cs]=Spouštěč JavaScriptu -Name[de]=JavaScript-Ausführung -Name[es]=Lanzador JavaScript -Name[fi]=JavaScript-suoritusohjelma -Name[fr]=Lanceur de JavaScript -Name[hu]=JavaScript futtató -Name[mr]=जावास्क्रिप्ट चालक -Name[nl]=JavaScript-runner -Name[pl]=Silnik JavaScript -Name[pt]=Execução de JavaScript -Name[pt_BR]=Mecanismo JavaScript -Name[sk]=Spúšťač JavaScriptu -Name[sv]=Kör Javascript -Name[tr]=JavaScript Çalıştırıcı -Name[ug]=JavaScript ئىجراچىسى -Name[uk]=Механізм запуску JavaScript -Name[x-test]=xxJavaScript Runnerxx -Comment=JavaScript Runner -Comment[bs]=Javascript izvođač -Comment[cs]=Spouštěč JavaScriptu -Comment[de]=JavaScript-Ausführung -Comment[es]=Lanzador JavaScript -Comment[fi]=JavaScript-suoritusohjelma -Comment[fr]=Lanceur de JavaScript -Comment[hu]=JavaScript futtató -Comment[mr]=जावास्क्रिप्ट चालक -Comment[nl]=JavaScript-runner -Comment[pl]=Silnik JavaScript -Comment[pt]=Execução de JavaScript -Comment[pt_BR]=Mecanismo JavaScript -Comment[sk]=Spúšťač JavaScriptu -Comment[sv]=Kör Javascript -Comment[tr]=JavaScript Çalıştırıcı -Comment[ug]=JavaScript ئىجراچىسى -Comment[uk]=Механізм запуску JavaScript -Comment[x-test]=xxJavaScript Runnerxx -X-KDE-ServiceTypes=Plasma/ScriptEngine -Type=Service -Icon=text-x-script -X-KDE-Library=plasma_runnerscript_javascript -X-Plasma-API=javascript -X-Plasma-ComponentTypes=Runner diff --git a/src/scriptengines/javascript/dataengine/javascriptdataengine.cpp b/src/scriptengines/javascript/dataengine/javascriptdataengine.cpp deleted file mode 100644 index 4c44af782..000000000 --- a/src/scriptengines/javascript/dataengine/javascriptdataengine.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright 2009 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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 "javascriptdataengine.h" - -#include - -#include - -#include "javascriptservice.h" -#include "common/authorization.h" -#include "common/scriptenv.h" -#include "simplebindings/i18n.h" -#include "simplebindings/dataengine.h" - -void registerNonGuiMetaTypes(QScriptEngine *engine); - -JavaScriptDataEngine::JavaScriptDataEngine(QObject *parent, const QVariantList &args) - : DataEngineScript(parent) -{ - Q_UNUSED(args); - - m_qscriptEngine = new QScriptEngine(this); - m_env = new ScriptEnv(this, m_qscriptEngine); - - connect(m_env, SIGNAL(reportError(ScriptEnv*,bool)), this, SLOT(reportError(ScriptEnv*,bool))); -} - -bool JavaScriptDataEngine::init() -{ - QScriptValue global = m_qscriptEngine->globalObject(); - - bindI18N(m_qscriptEngine); - - m_iface = m_qscriptEngine->newQObject(this); - m_iface.setScope(global); - m_env->addMainObjectProperties(m_iface); - - global.setProperty("engine", m_iface); - - global.setProperty("setData", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsSetData)); - global.setProperty("removeAllData", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsRemoveAllData)); - global.setProperty("removeData", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsRemoveData)); - global.setProperty("removeAllSources", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsRemoveAllSources)); - global.setProperty("Service", m_qscriptEngine->newFunction(JavaScriptDataEngine::serviceCtor)); - - registerNonGuiMetaTypes(m_qscriptEngine); - - Authorization auth; - if (!m_env->importExtensions(description(), m_iface, auth)) { - return false; - } - - return m_env->include(mainScript()); -} - -QScriptEngine *JavaScriptDataEngine::engine() const -{ - return m_qscriptEngine; -} - -void JavaScriptDataEngine::jsSetMaxSourceCount(int count) -{ - setMaxSourceCount(count); -} - -int JavaScriptDataEngine::maxSourceCount() const -{ - return dataEngine()->maxSourceCount(); -} - -void JavaScriptDataEngine::jsSetMinimumPollingInterval(int interval) -{ - setMinimumPollingInterval(interval); -} - -int JavaScriptDataEngine::jsMinimumPollingInterval() const -{ - return minimumPollingInterval(); -} - -void JavaScriptDataEngine::jsSetPollingInterval(int interval) -{ - m_pollingInterval = interval; - setPollingInterval(interval); -} - -int JavaScriptDataEngine::pollingInterval() const -{ - return m_pollingInterval; -} - -QScriptValue JavaScriptDataEngine::jsSetData(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 1) { - return context->throwError(i18n("setData() takes at least one argument")); - } - - QString error; - JavaScriptDataEngine *iFace = extractIFace(engine, error); - - if (!iFace) { - return context->throwError(error); - } - - const QString source = context->argument(0).toString(); - if (context->argumentCount() == 1) { - iFace->setData(source, DataEngine::Data()); - } else if (context->argument(1).isArray() || context->argument(1).isObject()) { - // qDebug()<< "array or object"; - QScriptValueIterator it(context->argument(1)); - DataEngine::Data data; - - while (it.hasNext()) { - it.next(); - data.insert(it.name(), it.value().toVariant()); - } - - iFace->setData(source, data); - } else { - const QString value = context->argument(1).toString(); - if (context->argumentCount() > 2) { - if (context->argument(2).isArray() || context->argument(2).isObject()) { - QScriptValueIterator it(context->argument(2)); - DataEngine::Data data; - - while (it.hasNext()) { - it.next(); - data.insert(it.name(), it.value().toVariant()); - } - - iFace->setData(source, value, data); - } else { - iFace->setData(source, value, context->argument(2).toString()); - } - } else { - iFace->setData(source, value); - } - } - - return engine->newVariant(true); -} - -JavaScriptDataEngine *JavaScriptDataEngine::extractIFace(QScriptEngine *engine, QString &error) -{ - JavaScriptDataEngine *interface = 0; - QScriptValue engineValue = engine->globalObject().property("engine"); - QObject *engineObject = engineValue.toQObject(); - - if (!engineObject) { - error = i18n("Could not extract the DataEngineObject"); - } else { - interface = qobject_cast(engineObject); - if (!interface) { - error = i18n("Could not extract the DataEngine"); - } - } - - return interface; -} - -QScriptValue JavaScriptDataEngine::jsRemoveAllData(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 1) { - return context->throwError(i18n("removeAllData() takes at least one argument (the source name)")); - } - - QString source = context->argument(0).toString(); - QString error; - JavaScriptDataEngine *iFace = extractIFace(engine, error); - - if (iFace) { - iFace->removeAllData(source); - return engine->newVariant(true); - } - - return context->throwError(error); -} - -QScriptValue JavaScriptDataEngine::jsRemoveData(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 2) { - return context->throwError(i18n("removeData() takes at least two arguments (the source and key names)")); - } - - QString source = context->argument(0).toString(); - QString key = context->argument(1).toString(); - QString error; - JavaScriptDataEngine *iFace = extractIFace(engine, error); - - if (iFace) { - iFace->removeData(source, key); - return engine->newVariant(true); - } - - return context->throwError(error); -} - -QScriptValue JavaScriptDataEngine::jsRemoveAllSources(QScriptContext *context, QScriptEngine *engine) -{ - QString error; - JavaScriptDataEngine *iFace = extractIFace(engine, error); - - if (iFace) { - iFace->removeAllSources(); - return engine->newVariant(true); - } - - return context->throwError(error); -} - -QScriptValue JavaScriptDataEngine::serviceCtor(QScriptContext *context, QScriptEngine *engine) -{ - QString error; - JavaScriptDataEngine *iFace = extractIFace(engine, error); - if (!iFace) { - return context->throwError(error); - } - - if (context->argumentCount() < 1) { - return context->throwError(i18n("Service requires at least one parameter: the name of the service")); - } - - const QString &serviceName = context->argument(0).toString(); - if (serviceName.isEmpty()) { - return context->throwError(i18n("Service requires at least one parameter: the name of the service")); - } - - JavaScriptService *service = new JavaScriptService(serviceName, iFace); - if (service->wasFound()) { - QScriptValue v = engine->newQObject(service, QScriptEngine::QtOwnership, QScriptEngine::ExcludeSuperClassContents); - return v; - } - - delete service; - return context->throwError(i18n("Requested service %1 was not found in the Package.", serviceName)); -} - -QScriptValue JavaScriptDataEngine::callFunction(const QString &functionName, const QScriptValueList &args) -{ - QScriptValue func = m_iface.property(functionName); - return m_env->callFunction(func, args, m_iface); -} - -void JavaScriptDataEngine::reportError(ScriptEnv *env, bool fatal) const -{ - Q_UNUSED(fatal) - - // qDebug() << "Error: " << env->engine()->uncaughtException().toString() - // << " at line " << env->engine()->uncaughtExceptionLineNumber() << endl; - // qDebug() << env->engine()->uncaughtExceptionBacktrace(); -} - -QStringList JavaScriptDataEngine::sources() const -{ - JavaScriptDataEngine *unconst = const_cast(this); - QScriptValueList args; - QScriptValue rv = unconst->callFunction("sources", args); - if (rv.isValid() && (rv.isVariant() || rv.isArray())) { - return rv.toVariant().toStringList(); - } - - return DataEngineScript::sources(); -} - -bool JavaScriptDataEngine::sourceRequestEvent(const QString &name) -{ - QScriptValueList args; - args << name; - m_env->callEventListeners("sourceRequestEvent", args); - QScriptValue rv = callFunction("sourceRequestEvent", args); - if (rv.isValid() && rv.isBool()) { - return rv.toBool(); - } - - return false; -} - -bool JavaScriptDataEngine::updateSourceEvent(const QString &source) -{ - QScriptValueList args; - args << source; - m_env->callEventListeners("updateSourcEvent", args); - QScriptValue rv = callFunction("updateSourceEvent", args); - if (rv.isValid() && rv.isBool()) { - return rv.toBool(); - } - - return false; -} - -Plasma::Service *JavaScriptDataEngine::serviceForSource(const QString &source) -{ - QScriptValueList args; - args << source; - QScriptValue rv = callFunction("serviceForSource", args); - if (rv.isValid() && rv.isQObject()) { - Plasma::Service *service = qobject_cast(rv.toQObject()); - if (service) { - if (service->destination().isEmpty()) { - service->setDestination(source); - } - - return service; - } else { - delete rv.toQObject(); - } - } - - return 0; -} - -QString JavaScriptDataEngine::filePath(const char *type, const QString &file) const -{ - const QString path = m_env->filePathFromScriptContext(type, file); - if (!path.isEmpty()) { - return path; - } - - return package()->filePath(type, file); -} - -bool JavaScriptDataEngine::include(const QString &script) -{ - const QString path = filePath("scripts", script); - if (path.isEmpty()) { - return false; - } - - return m_env->include(path); -} - -K_EXPORT_PLASMA_DATAENGINESCRIPTENGINE(javascriptdataengine, JavaScriptDataEngine) - -#include - diff --git a/src/scriptengines/javascript/dataengine/javascriptdataengine.h b/src/scriptengines/javascript/dataengine/javascriptdataengine.h deleted file mode 100644 index bc8802ed1..000000000 --- a/src/scriptengines/javascript/dataengine/javascriptdataengine.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2009 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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. - */ - -#ifndef JAVASCRIPTDATAENGINE_H -#define JAVASCRIPTDATAENGINE_H - -#include - -#include - -class ScriptEnv; -class QScriptContext; -class QScriptEngine; - -class JavaScriptDataEngine : public Plasma::DataEngineScript -{ - Q_OBJECT - Q_PROPERTY(int sourceCount WRITE jsSetMaxSourceCount READ maxSourceCount) - Q_PROPERTY(int minimumPollingInterval WRITE jsSetMinimumPollingInterval READ jsMinimumPollingInterval) - Q_PROPERTY(int pollingInterval WRITE jsSetPollingInterval READ pollingInterval) - -public: - JavaScriptDataEngine(QObject *parent, const QVariantList &args); - bool init(); - - QScriptEngine *engine() const; - QString filePath(const char *type, const QString &file) const; - - QStringList sources() const; - bool sourceRequestEvent(const QString &name); - bool updateSourceEvent(const QString &source); - Plasma::Service *serviceForSource(const QString &source); - - int maxSourceCount() const; - void jsSetMaxSourceCount(int count); - void jsSetMinimumPollingInterval(int interval); - int jsMinimumPollingInterval() const; - void jsSetPollingInterval(int interval); - int pollingInterval() const; - -public Q_SLOTS: - bool include(const QString &file); - -private Q_SLOTS: - void reportError(ScriptEnv *engine, bool fatal) const; - -private: - static JavaScriptDataEngine *extractIFace(QScriptEngine *engine, QString &error); - static QScriptValue jsSetData(QScriptContext *context, QScriptEngine *engine); - static QScriptValue jsRemoveAllData(QScriptContext *context, QScriptEngine *engine); - static QScriptValue jsRemoveData(QScriptContext *context, QScriptEngine *engine); - static QScriptValue jsRemoveAllSources(QScriptContext *context, QScriptEngine *engine); - static QScriptValue serviceCtor(QScriptContext *context, QScriptEngine *engine); - - QScriptValue callFunction(const QString &functionName, const QScriptValueList &args); - - QScriptEngine *m_qscriptEngine; - ScriptEnv *m_env; - QScriptValue m_iface; - int m_pollingInterval; -}; - -#endif diff --git a/src/scriptengines/javascript/dataengine/javascriptservice.cpp b/src/scriptengines/javascript/dataengine/javascriptservice.cpp deleted file mode 100644 index 63f7fe93c..000000000 --- a/src/scriptengines/javascript/dataengine/javascriptservice.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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 "javascriptservice.h" - -#include -#include -#include - -#include "common/scriptenv.h" -#include "javascriptdataengine.h" - -JavaScriptServiceJob::JavaScriptServiceJob(QScriptEngine *engine, const QString &destination, const QString &operation, - const QMap ¶meters, QObject *parent) - : Plasma::ServiceJob(destination, operation, parameters, parent), - m_thisObject(engine->newQObject(this, QScriptEngine::QtOwnership, QScriptEngine::ExcludeSuperClassContents)) -{ -} - -void JavaScriptServiceJob::start() -{ - if (!m_startFunction.isFunction()) { - setResult(false); - return; - } - - m_startFunction.call(m_thisObject); -} - -QScriptValue JavaScriptServiceJob::scriptValue() const -{ - return m_thisObject; -} - -QScriptValue JavaScriptServiceJob::startFunction() const -{ - return m_startFunction; -} - -void JavaScriptServiceJob::setStartFunction(const QScriptValue &v) -{ - m_startFunction = v; -} - -JavaScriptService::JavaScriptService(const QString &serviceName, JavaScriptDataEngine *engine) - : Plasma::Service(engine), - m_dataEngine(engine) -{ - setName(serviceName); -} - -JavaScriptService::~JavaScriptService() -{ -// qDebug(); -} - -Plasma::ServiceJob *JavaScriptService::createJob(const QString &operation, QMap ¶meters) -{ - if (m_setupFunc.isFunction() && m_dataEngine && isOperationEnabled(operation)) { - JavaScriptServiceJob *job = new JavaScriptServiceJob(m_dataEngine.data()->engine(), destination(), operation, parameters, this); - QScriptValueList args; - args << job->scriptValue(); - m_setupFunc.call(QScriptValue(), args); - return job; - } - - return 0; -} - -bool JavaScriptService::wasFound() const -{ - return m_dataEngine; -} - -void JavaScriptService::registerOperationsScheme() -{ - if (!m_dataEngine) { - return; - } - - const QString path = m_dataEngine.data()->filePath("services", name() + ".operations"); - - if (path.isEmpty()) { - // qDebug() << "Cannot find operations description:" << name() << ".operations"; - m_dataEngine.clear(); - return; - } - - QFile file(path); - setOperationsScheme(&file); -} - -QScriptValue JavaScriptService::setupJobFunction() const -{ - return m_setupFunc; -} - -void JavaScriptService::setSetupJobFunction(const QScriptValue &v) -{ - m_setupFunc = v; -} - -#include "javascriptservice.moc" - diff --git a/src/scriptengines/javascript/dataengine/javascriptservice.h b/src/scriptengines/javascript/dataengine/javascriptservice.h deleted file mode 100644 index c69f5d5c8..000000000 --- a/src/scriptengines/javascript/dataengine/javascriptservice.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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. - */ - -#ifndef JAVASCRIPTSERVICE_H -#define JAVASCRIPTSERVICE_H - -#include -#include - -#include -#include -#include - -namespace Plasma -{ - class Package; -} // namespace Plasma - -class JavaScriptDataEngine; - -class JavaScriptServiceJob : public Plasma::ServiceJob -{ - Q_OBJECT - Q_PROPERTY(QString destination READ destination) - Q_PROPERTY(QString operationName READ operationName) - Q_PROPERTY(QVariantMap parameters READ parameters) - Q_PROPERTY(QVariant result READ result WRITE setResult) - Q_PROPERTY(int error READ error WRITE setError) - Q_PROPERTY(QString errorText READ errorText WRITE setErrorText) - Q_PROPERTY(QScriptValue start READ startFunction WRITE setStartFunction) - -public: - JavaScriptServiceJob(QScriptEngine *engine, const QString &destination, const QString &operation, - const QMap ¶meters, QObject *parent = 0); - - void start(); - - QScriptValue startFunction() const; - void setStartFunction(const QScriptValue &v); - - QScriptValue scriptValue() const; - -private: - QScriptValue m_startFunction; - QScriptValue m_thisObject; -}; - -class JavaScriptService : public Plasma::Service -{ - Q_OBJECT - Q_PROPERTY(QString destination READ destination WRITE setDestination) - Q_PROPERTY(QStringList operationNames READ operationNames) - Q_PROPERTY(QString name READ name) - Q_PROPERTY(QScriptValue setupJob READ setupJobFunction WRITE setSetupJobFunction) - -public: - JavaScriptService(const QString &serviceName, JavaScriptDataEngine *engine); - ~JavaScriptService(); - - bool wasFound() const; - - QScriptValue setupJobFunction() const; - void setSetupJobFunction(const QScriptValue &v); - -protected: - Plasma::ServiceJob *createJob(const QString &operation, QMap ¶meters); - void registerOperationsScheme(); - -private: - QWeakPointer m_dataEngine; - QScriptValue m_setupFunc; -}; - -#endif - diff --git a/src/scriptengines/javascript/declarative/appletcontainer.cpp b/src/scriptengines/javascript/declarative/appletcontainer.cpp deleted file mode 100644 index f9a12bcab..000000000 --- a/src/scriptengines/javascript/declarative/appletcontainer.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - Copyright 2011 Marco Martin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "appletcontainer.h" - -#include - -#include - -#include - -AppletContainer::AppletContainer(QDeclarativeItem *parent) - : QDeclarativeItem(parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, true); - - //the virtual geometryChanged is *NOT* called in case of change by the anchors - connect(this, SIGNAL(widthChanged()), this, SLOT(afterWidthChanged()), Qt::QueuedConnection); - connect(this, SIGNAL(heightChanged()), this, SLOT(afterHeightChanged()), Qt::QueuedConnection); -} - -AppletContainer::~AppletContainer() -{ -} - -QGraphicsWidget *AppletContainer::applet() const -{ - return m_applet.data(); -} - -void AppletContainer::setApplet(QGraphicsWidget *widget) -{ - Plasma::Applet *applet = qobject_cast(widget); - if (!applet || applet == m_applet.data()) { - return; - } - - if (m_applet) { - disconnect(m_applet.data(), 0, this, 0); - m_applet.data()->setParentItem(parentItem()); - } - - m_applet = applet; - - connect(applet, SIGNAL(sizeHintChanged(Qt::SizeHint)), this, SLOT(sizeHintChanged(Qt::SizeHint))); - connect(applet, SIGNAL(statusChanged(Plasma::Types::ItemStatus)), this, SIGNAL(statusChanged())); - - applet->setParentItem(this); - applet->setGeometry(0, 0, qMax((qreal)16, width()), qMax((qreal)16, height())); - applet->setFlag(QGraphicsItem::ItemIsMovable, false); - - emit appletChanged(widget); - emit statusChanged(); -} - -void AppletContainer::sizeHintChanged(Qt::SizeHint which) -{ - switch (which) { - case Qt::MinimumSize: - emit minimumWidthChanged(minimumWidth()); - emit minimumHeightChanged(minimumHeight()); - break; - case Qt::PreferredSize: - emit preferredWidthChanged(preferredWidth()); - emit preferredHeightChanged(preferredHeight()); - break; - case Qt::MaximumSize: - emit maximumWidthChanged(maximumWidth()); - emit maximumHeightChanged(maximumHeight()); - break; - default: - break; - } -} - -int AppletContainer::minimumWidth() const -{ - if (!m_applet) { - return -1; - } - - return m_applet.data()->effectiveSizeHint(Qt::MinimumSize).width(); -} - -int AppletContainer::minimumHeight() const -{ - if (!m_applet) { - return -1; - } - - return m_applet.data()->effectiveSizeHint(Qt::MinimumSize).height(); -} - - -int AppletContainer::preferredWidth() const -{ - if (!m_applet) { - return -1; - } - - return m_applet.data()->effectiveSizeHint(Qt::PreferredSize).width(); -} - -int AppletContainer::preferredHeight() const -{ - if (!m_applet) { - return -1; - } - - return m_applet.data()->effectiveSizeHint(Qt::PreferredSize).height(); -} - - -int AppletContainer::maximumWidth() const -{ - if (!m_applet) { - return -1; - } - - return m_applet.data()->effectiveSizeHint(Qt::MaximumSize).width(); -} - -int AppletContainer::maximumHeight() const -{ - if (!m_applet) { - return -1; - } - - return m_applet.data()->effectiveSizeHint(Qt::MaximumSize).height(); -} - -void AppletContainer::setStatus(const AppletContainer::ItemStatus status) -{ - if (!m_applet) { - return; - } - - m_applet.data()->setStatus((Plasma::Types::ItemStatus)status); -} - -AppletContainer::ItemStatus AppletContainer::status() const -{ - if (!m_applet) { - return UnknownStatus; - } - - return (AppletContainer::ItemStatus)((int)(m_applet.data()->status())); -} - -void AppletContainer::afterWidthChanged() -{ - if (!m_applet) { - return; - } - - m_applet.data()->resize(width(), height()); - m_applet.data()->setPos(width()/2 - m_applet.data()->size().width()/2, - height()/2 - m_applet.data()->size().height()/2); - emit minimumWidthChanged(minimumWidth()); - emit preferredWidthChanged(preferredWidth()); - emit maximumWidthChanged(maximumWidth()); - - emit minimumHeightChanged(minimumHeight()); - emit preferredHeightChanged(preferredHeight()); - emit maximumHeightChanged(maximumHeight()); -} - -void AppletContainer::afterHeightChanged() -{ - if (!m_applet) { - return; - } - - m_applet.data()->resize(width(), height()); - m_applet.data()->setPos(width()/2 - m_applet.data()->size().width()/2, - height()/2 - m_applet.data()->size().height()/2); - - emit minimumWidthChanged(minimumWidth()); - emit preferredWidthChanged(preferredWidth()); - emit maximumWidthChanged(maximumWidth()); - - emit minimumHeightChanged(minimumHeight()); - emit preferredHeightChanged(preferredHeight()); - emit maximumHeightChanged(maximumHeight()); -} - - -#include "appletcontainer.moc" diff --git a/src/scriptengines/javascript/declarative/appletcontainer.h b/src/scriptengines/javascript/declarative/appletcontainer.h deleted file mode 100644 index a877585a3..000000000 --- a/src/scriptengines/javascript/declarative/appletcontainer.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright 2011 Marco Martin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef APPLETCONTAINER_H -#define APPLETCONTAINER_H - -#include - -namespace Plasma { - class Applet; -} - -class AppletContainer : public QDeclarativeItem -{ - Q_OBJECT - Q_PROPERTY(QGraphicsWidget *applet READ applet WRITE setApplet NOTIFY appletChanged) - - Q_PROPERTY(int minimumWidth READ minimumWidth NOTIFY minimumWidthChanged) - Q_PROPERTY(int minimumHeight READ minimumHeight NOTIFY minimumHeightChanged) - - Q_PROPERTY(int preferredWidth READ preferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(int preferredHeight READ preferredHeight NOTIFY preferredHeightChanged) - - Q_PROPERTY(int maximumWidth READ maximumWidth NOTIFY maximumWidthChanged) - Q_PROPERTY(int maximumHeight READ maximumHeight NOTIFY maximumHeightChanged) - - Q_PROPERTY(ItemStatus status READ status WRITE setStatus NOTIFY statusChanged) - Q_ENUMS(ItemStatus) - -public: - enum ItemStatus { - UnknownStatus = 0, /**< The status is unknown **/ - PassiveStatus = 1, /**< The Item is passive **/ - ActiveStatus = 2, /**< The Item is active **/ - NeedsAttentionStatus = 3, /**< The Item needs attention **/ - AcceptingInputStatus = 4 /**< The Item is accepting input **/ - }; - - AppletContainer(QDeclarativeItem *parent = 0); - ~AppletContainer(); - - QGraphicsWidget *applet() const; - void setApplet(QGraphicsWidget *applet); - - int minimumWidth() const; - int minimumHeight() const; - - int preferredWidth() const; - int preferredHeight() const; - - int maximumWidth() const; - int maximumHeight() const; - - void setStatus(const ItemStatus status); - ItemStatus status() const; - -Q_SIGNALS: - void appletChanged(QGraphicsWidget *applet); - - void minimumWidthChanged(int); - void minimumHeightChanged(int); - - void preferredWidthChanged(int); - void preferredHeightChanged(int); - - void maximumWidthChanged(int); - void maximumHeightChanged(int); - - void statusChanged(); - - -protected Q_SLOTS: - void sizeHintChanged(Qt::SizeHint which); - void afterWidthChanged(); - void afterHeightChanged(); - -private: - QWeakPointer m_applet; -}; - -#endif diff --git a/src/scriptengines/javascript/declarative/declarativeitemcontainer.cpp b/src/scriptengines/javascript/declarative/declarativeitemcontainer.cpp deleted file mode 100644 index 912e618e2..000000000 --- a/src/scriptengines/javascript/declarative/declarativeitemcontainer.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/*************************************************************************** - * Copyright 2011 Marco Martin * - * * - * 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, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -#include "declarativeitemcontainer_p.h" - -#include - -DeclarativeItemContainer::DeclarativeItemContainer(QGraphicsItem *parent) - : QGraphicsWidget(parent) -{ -} - -DeclarativeItemContainer::~DeclarativeItemContainer() -{ -} - -void DeclarativeItemContainer::setDeclarativeItem(QDeclarativeItem *item, bool reparent) -{ - if (m_declarativeItem) { - disconnect(m_declarativeItem.data(), 0, this, 0); - } - m_declarativeItem = item; - if (reparent) { - static_cast(item)->setParentItem(this); - } - setMinimumWidth(item->implicitWidth()); - setMinimumHeight(item->implicitHeight()); - resize(item->width(), item->height()); - connect(m_declarativeItem.data(), SIGNAL(widthChanged()), this, SLOT(widthChanged())); - connect(m_declarativeItem.data(), SIGNAL(heightChanged()), this, SLOT(heightChanged())); - - if (m_declarativeItem.data()->metaObject()->indexOfProperty("minimumWidth") >= 0) { - QObject::connect(m_declarativeItem.data(), SIGNAL(minimumWidthChanged()), this, SLOT(minimumWidthChanged())); - } - - if (m_declarativeItem.data()->metaObject()->indexOfProperty("minimumHeight") >= 0) { - QObject::connect(m_declarativeItem.data(), SIGNAL(minimumHeightChanged()), this, SLOT(minimumHeightChanged())); - } - minimumWidthChanged(); - minimumHeightChanged(); -} - -QDeclarativeItem *DeclarativeItemContainer::declarativeItem() const -{ - return m_declarativeItem.data(); -} - -void DeclarativeItemContainer::resizeEvent(QGraphicsSceneResizeEvent *event) -{ - if (m_declarativeItem) { - m_declarativeItem.data()->setProperty("width", event->newSize().width()); - m_declarativeItem.data()->setProperty("height", event->newSize().height()); - } -} - -void DeclarativeItemContainer::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - event->ignore(); -} - -void DeclarativeItemContainer::widthChanged() -{ - if (!m_declarativeItem) { - return; - } - - QSizeF newSize(size()); - newSize.setWidth(m_declarativeItem.data()->width()); - resize(newSize); -} - -void DeclarativeItemContainer::heightChanged() -{ - if (!m_declarativeItem) { - return; - } - - QSizeF newSize(size()); - newSize.setHeight(m_declarativeItem.data()->height()); - resize(newSize); -} - -void DeclarativeItemContainer::minimumWidthChanged() -{ - if (!m_declarativeItem) { - return; - } - - qreal minimumWidth = m_declarativeItem.data()->property("minimumWidth").toReal(); - setMinimumWidth(minimumWidth); -} - -void DeclarativeItemContainer::minimumHeightChanged() -{ - if (!m_declarativeItem) { - return; - } - - qreal minimumHeight = m_declarativeItem.data()->property("minimumHeight").toReal(); - setMinimumHeight(minimumHeight); -} - - -#include "declarativeitemcontainer_p.moc" diff --git a/src/scriptengines/javascript/declarative/declarativeitemcontainer_p.h b/src/scriptengines/javascript/declarative/declarativeitemcontainer_p.h deleted file mode 100644 index 27d2f1dcc..000000000 --- a/src/scriptengines/javascript/declarative/declarativeitemcontainer_p.h +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - * Copyright 2011 Marco Martin * - * * - * 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, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -#ifndef DECLARATIVEITEMCONTAINER_P -#define DECLARATIVEITEMCONTAINER_P - -#include -#include -#include -#include - - -class DeclarativeItemContainer : public QGraphicsWidget -{ - Q_OBJECT - -public: - DeclarativeItemContainer(QGraphicsItem *parent = 0); - ~DeclarativeItemContainer(); - - void setDeclarativeItem(QDeclarativeItem *item, bool reparent = true); - QDeclarativeItem *declarativeItem() const; - -protected: - void resizeEvent(QGraphicsSceneResizeEvent *event); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - -protected Q_SLOTS: - void widthChanged(); - void heightChanged(); - void minimumWidthChanged(); - void minimumHeightChanged(); - -private: - QWeakPointer m_declarativeItem; -}; - -#endif diff --git a/src/scriptengines/javascript/declarative/packageaccessmanager.cpp b/src/scriptengines/javascript/declarative/packageaccessmanager.cpp deleted file mode 100644 index b32fa2546..000000000 --- a/src/scriptengines/javascript/declarative/packageaccessmanager.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2010 Marco Martin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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 "packageaccessmanager.h" - -#include - -#include - -#include "plasmoid/appletauthorization.h" - -class ErrorReply : public QNetworkReply -{ -public: - ErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &req) - : QNetworkReply() - { - setError(QNetworkReply::ContentOperationNotPermittedError, "The plasmoid has not been authorized to load remote content"); - setOperation(op); - setRequest(req); - setUrl(req.url()); - } - - qint64 readData(char *data, qint64 maxSize) - { - Q_UNUSED(data); - Q_UNUSED(maxSize); - return 0; - } - - void abort() - { - } -}; - -PackageAccessManager::PackageAccessManager(const Plasma::Package *package, AppletAuthorization *auth, QObject *parent) - : KIO::AccessManager(parent), - m_package(package), - m_auth(auth) -{ -} - -PackageAccessManager::~PackageAccessManager() -{ -} - - -QNetworkReply *PackageAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData) -{ - QUrl reqUrl(req.url()); - - if (reqUrl.scheme() == "plasmapackage") { - QNetworkRequest request = req; - reqUrl.setScheme("file"); - reqUrl.setPath(m_package->filePath(0, reqUrl.path())); - request.setUrl(reqUrl); - return QNetworkAccessManager::createRequest(op, request, outgoingData); - } else if ((reqUrl.scheme() == "http" && !m_auth->authorizeRequiredExtension("http")) || - ((reqUrl.scheme() == "file" || reqUrl.scheme() == "desktop") && !m_auth->authorizeRequiredExtension("localio")) || - (!m_auth->authorizeRequiredExtension("networkio"))) { - return new ErrorReply(op, req); - } else { -#ifndef PLASMA_NO_KIO - return KIO::AccessManager::createRequest(op, req, outgoingData); -#else - return QNetworkAccessManager::createRequest(op, req, outgoingData); -#endif - } -} - - - diff --git a/src/scriptengines/javascript/declarative/packageaccessmanager.h b/src/scriptengines/javascript/declarative/packageaccessmanager.h deleted file mode 100644 index 3733e0cb2..000000000 --- a/src/scriptengines/javascript/declarative/packageaccessmanager.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2010 Marco Martin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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. - */ - -#ifndef PACKAGEACCESSMANAGER_H -#define PACKAGEACCESSMANAGER_H - - -#ifndef PLASMA_NO_KIO -#include -#else -#include -#endif - -namespace Plasma -{ - class Package; -} - -class AppletAuthorization; - -class PackageAccessManager : -#ifdef PLASMA_NO_KIO -public QNetworkAccessManager -#else -public KIO::AccessManager -#endif -{ -public: - PackageAccessManager(const Plasma::Package *package, AppletAuthorization *auth, QObject *parent = 0); - ~PackageAccessManager(); - -protected: - QNetworkReply *createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0); - -private: - const Plasma::Package *m_package; - AppletAuthorization *m_auth; -}; - -#endif diff --git a/src/scriptengines/javascript/declarative/packageaccessmanagerfactory.cpp b/src/scriptengines/javascript/declarative/packageaccessmanagerfactory.cpp deleted file mode 100644 index a30a45305..000000000 --- a/src/scriptengines/javascript/declarative/packageaccessmanagerfactory.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2010 Marco Martin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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 "packageaccessmanagerfactory.h" - -#include - -#include "packageaccessmanager.h" -#include "plasmoid/appletauthorization.h" - -PackageAccessManagerFactory::PackageAccessManagerFactory(const Plasma::Package *package, AppletAuthorization *auth) - : QDeclarativeNetworkAccessManagerFactory(), - m_package(package), - m_auth(auth) -{ -} - -PackageAccessManagerFactory::~PackageAccessManagerFactory() -{ -} - -QNetworkAccessManager *PackageAccessManagerFactory::create(QObject *parent) -{ - return new PackageAccessManager(m_package, m_auth, parent); -} - - diff --git a/src/scriptengines/javascript/declarative/packageaccessmanagerfactory.h b/src/scriptengines/javascript/declarative/packageaccessmanagerfactory.h deleted file mode 100644 index 8b4ba0d12..000000000 --- a/src/scriptengines/javascript/declarative/packageaccessmanagerfactory.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2010 Marco Martin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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. - */ - -#ifndef PACKAGEACCESSMANAGERFACTORY_H -#define PACKAGEACCESSMANAGERFACTORY_H - -#include - - -namespace Plasma -{ - class Package; -} - -class AppletAuthorization; - -class PackageAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory -{ -public: - PackageAccessManagerFactory(const Plasma::Package *package, AppletAuthorization *auth); - ~PackageAccessManagerFactory(); - QNetworkAccessManager *create(QObject *parent); - -private: - const Plasma::Package *m_package; - AppletAuthorization *m_auth; -}; - -#endif diff --git a/src/scriptengines/javascript/declarative/toolboxproxy.cpp b/src/scriptengines/javascript/declarative/toolboxproxy.cpp deleted file mode 100644 index 04ff71fbb..000000000 --- a/src/scriptengines/javascript/declarative/toolboxproxy.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright 2007 by Aaron Seigo - * Copyright 2008 by Marco Martin - * Copyright 2012 by Sebastian Kügler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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 "toolboxproxy.h" -#include "../plasmoid/appletinterface.h" - -#include -#include -#include - -#include - -class ToolBoxProxyPrivate { -public: - bool showing; - Plasma::Containment *containment; - QList actions; - AppletInterface* appletInterface; - QAction* addPanelAction; - QAction* addWidgetsAction; - QAction* configureAction; -}; - -ToolBoxProxy::ToolBoxProxy(Plasma::Containment *parent, AppletInterface *appletInterface) - : AbstractToolBox(parent) -{ - d = new ToolBoxProxyPrivate; - d->containment = parent; - d->appletInterface = appletInterface; - init(); -} - -ToolBoxProxy::ToolBoxProxy(QObject *parent, const QVariantList &args) - : AbstractToolBox(parent, args) -{ - d = new ToolBoxProxyPrivate; - d->containment = qobject_cast(parent); - d->appletInterface = 0; - init(); -} - -ToolBoxProxy::~ToolBoxProxy() -{ - delete d; -} - -void ToolBoxProxy::init() -{ - d->showing = false; - d->addPanelAction = 0; - d->addWidgetsAction = 0; - d->configureAction = 0; - - if (d->containment) { - connect(d->containment, SIGNAL(immutabilityChanged(Plasma::Types::ImmutabilityType)), - this, SLOT(immutabilityChanged(Plasma::Types::ImmutabilityType))); - connect(this, SIGNAL(configureRequested(Plasma::Containment*)), - d->containment, SIGNAL(configureRequested(Plasma::Containment*))); - connect(this, SIGNAL(showAddWidgetsInterface(const QPointF&)), - d->containment, SIGNAL(showAddWidgetsInterface(const QPointF&))); - } - loadActions(); -} - -void ToolBoxProxy::loadActions() -{ - d->actions.clear(); - if (d->containment) { - if (!d->configureAction) { - d->configureAction = new QAction(this); - d->configureAction->setText(i18n("%1 Settings", d->containment->name())); - d->configureAction->setIcon(KIcon("configure")); - d->configureAction->setObjectName("configure"); - connect(d->configureAction, SIGNAL(triggered()), this, SLOT(configureRequested())); - } - addTool(d->configureAction); - - if (d->appletInterface) { - foreach (QAction *action, d->appletInterface->contextualActions()) { - addTool(action); - } - } - foreach (QAction *action, d->containment->actions()) { - addTool(action); - } - foreach (QAction *action, d->containment->corona()->actions()) { - addTool(action); - } - if (!d->addWidgetsAction) { - d->addWidgetsAction = new QAction(this); - d->addWidgetsAction->setObjectName("add widgets"); - d->addWidgetsAction->setText(i18n("Add Widgets")); - d->addWidgetsAction->setIcon(KIcon("list-add")); - connect(d->addWidgetsAction, SIGNAL(triggered()), this, SLOT(addWidgetsRequested())); - } - if (d->appletInterface && !d->appletInterface->immutable()) { - addTool(d->addWidgetsAction); - } - } - emit actionsChanged(); -} - -QDeclarativeListProperty ToolBoxProxy::actions() -{ - return QDeclarativeListProperty(this, d->actions); -} - -void ToolBoxProxy::addTool(QAction *action) -{ - if (!action || d->actions.contains(action)) { - return; - } - if (d->appletInterface && d->appletInterface->immutable() && action->objectName() == "add panel") { - d->addPanelAction = action; - return; - } - connect(action, SIGNAL(destroyed(QObject*)), this, SLOT(actionDestroyed(QObject*)), Qt::UniqueConnection); - d->actions.append(action); -} - -void ToolBoxProxy::removeTool(QAction *action) -{ - disconnect(action, 0, this, 0); - d->actions.removeAll(action); - emit actionsChanged(); -} - -void ToolBoxProxy::actionDestroyed(QObject *object) -{ - d->actions.removeAll(static_cast(object)); -} - -void ToolBoxProxy::configureRequested() -{ - emit configureRequested(d->containment); -} - -void ToolBoxProxy::addWidgetsRequested() -{ - emit showAddWidgetsInterface(QPointF(0, 0)); -} - -bool ToolBoxProxy::isShowing() const -{ - return d->showing; -} - -void ToolBoxProxy::setShowing(const bool show) -{ - if (d->showing == show) { - return; - } - d->showing = show; -} - -void ToolBoxProxy::immutabilityChanged(Plasma::Types::ImmutabilityType immutability) -{ - Q_UNUSED(immutability); - loadActions(); -} - -#include "toolboxproxy.moc" diff --git a/src/scriptengines/javascript/declarative/toolboxproxy.h b/src/scriptengines/javascript/declarative/toolboxproxy.h deleted file mode 100644 index e69cdbe44..000000000 --- a/src/scriptengines/javascript/declarative/toolboxproxy.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2007 by Aaron Seigo - * Copyright 2008 by Marco Martin - * Copyright 2012 by Sebastian Kügler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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. - */ - -#ifndef TOOLBOXPROXY_H -#define TOOLBOXPROXY_H - -#include -#include - -#include - -class QAction; - -class ToolBoxProxyPrivate; -class AppletInterface; - -class ToolBoxProxy : public Plasma::AbstractToolBox -{ - Q_OBJECT - Q_PROPERTY(QDeclarativeListProperty actions READ actions NOTIFY actionsChanged) - -public: - explicit ToolBoxProxy(Plasma::Containment *parent, AppletInterface *appletInterface); - explicit ToolBoxProxy(QObject *parent = 0, const QVariantList &args = QVariantList()); - ~ToolBoxProxy(); - - bool isShowing() const; // satisfy badly named API - void setShowing(const bool show); - - QDeclarativeListProperty actions(); - -public Q_SLOTS: - void configureRequested(); - void addWidgetsRequested(); - -Q_SIGNALS: - void actionsChanged(); - void immutableChanged(); - - void configureRequested(Plasma::Containment* containment); - void showAddWidgetsInterface(const QPointF& pos); - -private Q_SLOTS: - void actionDestroyed(QObject *object); - void immutabilityChanged(Plasma::Types::ImmutabilityType immutability); - -private: - void init(); - void loadActions(); - /** - * create a toolbox tool from the given action - * @p action the action to associate hte tool with - */ - void addTool(QAction *action); - /** - * remove the tool associated with this action - */ - void removeTool(QAction *action); - - ToolBoxProxyPrivate* d; -}; - -#endif // TOOLBOXPROXY_H diff --git a/src/scriptengines/javascript/runner/javascriptrunner.cpp b/src/scriptengines/javascript/runner/javascriptrunner.cpp deleted file mode 100644 index e7eba9836..000000000 --- a/src/scriptengines/javascript/runner/javascriptrunner.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2008 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 "javascriptrunner.h" - -#include - -#include - -#include -#include -#include - -#include "authorization.h" -#include "scriptenv.h" - -typedef const Plasma::RunnerContext* ConstRunnerContextStar; -typedef const Plasma::QueryMatch* ConstSearchMatchStar; - -Q_DECLARE_METATYPE(Plasma::QueryMatch*) -Q_DECLARE_METATYPE(Plasma::RunnerContext*) -Q_DECLARE_METATYPE(ConstRunnerContextStar) -Q_DECLARE_METATYPE(ConstSearchMatchStar) - -JavaScriptRunner::JavaScriptRunner(QObject *parent, const QVariantList &args) - : RunnerScript(parent) -{ - Q_UNUSED(args); - - m_engine = new QScriptEngine(this); - m_env = new ScriptEnv(this, m_engine); - - connect(m_engine, SIGNAL(reportError(ScriptEnv*,bool)), this, SLOT(reportError(ScriptEnv*,bool))); -} - -JavaScriptRunner::~JavaScriptRunner() -{ -} - -Plasma::AbstractRunner* JavaScriptRunner::runner() const -{ - return RunnerScript::runner(); -} - -bool JavaScriptRunner::init() -{ - setupObjects(); - - Authorization auth; - if (!m_env->importExtensions(description(), m_self, auth)) { - return false; - } - - QFile file(mainScript()); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text) ) { - qWarning() << "Unable to load script file"; - return false; - } - - QString script = file.readAll(); - // qDebug() << "Script says" << script; - - m_engine->evaluate(script); - if (m_engine->hasUncaughtException()) { - reportError(m_env, true); - return false; - } - - return m_env->include(mainScript()); -} - -void JavaScriptRunner::match(Plasma::RunnerContext &search) -{ - QScriptValue fun = m_self.property("match"); - if (!fun.isFunction()) { - // qDebug() << "Script: match is not a function, " << fun.toString(); - return; - } - - QScriptValueList args; - args << m_engine->toScriptValue(&search); - - QScriptContext *ctx = m_engine->pushContext(); - ctx->setActivationObject(m_self); - fun.call(m_self, args); - m_engine->popContext(); - - if (m_engine->hasUncaughtException()) { - reportError(m_env, false); - m_engine->clearExceptions(); - } -} - -void JavaScriptRunner::exec(const Plasma::RunnerContext *search, const Plasma::QueryMatch *action) -{ - QScriptValue fun = m_self.property("exec"); - if (!fun.isFunction()) { - // qDebug() << "Script: exec is not a function, " << fun.toString(); - return; - } - - QScriptValueList args; - args << m_engine->toScriptValue(search); - args << m_engine->toScriptValue(action); - - QScriptContext *ctx = m_engine->pushContext(); - ctx->setActivationObject(m_self); - fun.call(m_self, args); - m_engine->popContext(); - - if (m_engine->hasUncaughtException()) { - reportError(m_env, false); - m_engine->clearExceptions(); - } -} - -void JavaScriptRunner::setupObjects() -{ - QScriptValue global = m_engine->globalObject(); - - // Expose the runner - m_self = m_engine->newQObject(this); - m_self.setScope(global); - m_env->addMainObjectProperties(m_self); - - global.setProperty("runner", m_self); -} - -void JavaScriptRunner::reportError(ScriptEnv *env, bool fatal) -{ - Q_UNUSED(fatal) - // qDebug() << "Error: " << env->engine()->uncaughtException().toString() - // << " at line " << env->engine()->uncaughtExceptionLineNumber() << endl; - // qDebug() << env->engine()->uncaughtExceptionBacktrace(); -} - -QString JavaScriptRunner::filePath(const char *type, const QString &file) const -{ - const QString path = m_env->filePathFromScriptContext(type, file); - if (!path.isEmpty()) { - return path; - } - - return package()->filePath(type, file); -} - -bool JavaScriptRunner::include(const QString &script) -{ - const QString path = filePath("scripts", script); - if (path.isEmpty()) { - return false; - } - - return m_env->include(path); -} - -#include "javascriptrunner.moc" diff --git a/src/scriptengines/javascript/runner/javascriptrunner.h b/src/scriptengines/javascript/runner/javascriptrunner.h deleted file mode 100644 index 4d84390c0..000000000 --- a/src/scriptengines/javascript/runner/javascriptrunner.h +++ /dev/null @@ -1,67 +0,0 @@ -// -*- c++ -*- - -/* - * Copyright 2008 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. - */ - -#ifndef JAVASCRIPTRUNNER_H -#define JAVASCRIPTRUNNER_H - -#include - -#include - -class QScriptEngine; - -class ScriptEnv; - -class JavaScriptRunner : public Plasma::RunnerScript -{ - Q_OBJECT - -public: - JavaScriptRunner(QObject *parent, const QVariantList &args); - ~JavaScriptRunner(); - - bool init(); - - /** Reimplemented to add Q_INVOKABLE. */ - Q_INVOKABLE Plasma::AbstractRunner* runner() const; - - /** Reimplemented to forward to script. */ - void match(Plasma::RunnerContext &search); - - /** Reimplemented to forward to script. */ - void exec(const Plasma::RunnerContext *search, const Plasma::QueryMatch *action); - -public Q_SLOTS: - bool include(const QString &script); - -private: - void setupObjects(); - void importExtensions(); - void reportError(ScriptEnv *engine, bool fatal); - QString filePath(const char *type, const QString &file) const; - - QScriptEngine *m_engine; - ScriptEnv *m_env; - QScriptValue m_self; -}; - -K_EXPORT_PLASMA_RUNNERSCRIPTENGINE(qscriptrunner, JavaScriptRunner) - -#endif // JAVASCRIPTRUNNER_H diff --git a/src/scriptengines/javascript/simplebindings/anchorlayout.cpp b/src/scriptengines/javascript/simplebindings/anchorlayout.cpp deleted file mode 100644 index 343fe3338..000000000 --- a/src/scriptengines/javascript/simplebindings/anchorlayout.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2007 Richard J. Moore - * Copyright 2009 Artur Duque de Souza - * - * 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 - -#include - -#include "backportglobal.h" - -Q_DECLARE_METATYPE(QScript::Pointer::wrapped_pointer_type) -Q_DECLARE_METATYPE(QGraphicsWidget*) -Q_DECLARE_METATYPE(QGraphicsAnchor*) -Q_DECLARE_METATYPE(QGraphicsLayoutItem*) -DECLARE_POINTER_METATYPE(QGraphicsAnchorLayout) - -// QGraphicsAnchorLayout -DECLARE_VOID_NUMBER_METHOD(QGraphicsAnchorLayout, setSpacing) -DECLARE_NUMBER_GET_SET_METHODS(QGraphicsAnchorLayout, horizontalSpacing, setHorizontalSpacing) -DECLARE_NUMBER_GET_SET_METHODS(QGraphicsAnchorLayout, verticalSpacing, setVerticalSpacing) -DECLARE_VOID_NUMBER_METHOD(QGraphicsAnchorLayout, removeAt) - - -///////////////////////////////////////////////////////////// - -QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0, bool noExistingLayout = false); - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - QGraphicsLayoutItem *parent = extractLayoutItem(ctx, 0, true); - //FIXME: don't leak memory when parent is 0 - return qScriptValueFromValue(eng, new QGraphicsAnchorLayout(parent)); -} - -BEGIN_DECLARE_METHOD(QGraphicsAnchorLayout, addAnchor) { - QGraphicsLayoutItem *item1 = extractLayoutItem(ctx, 0); - QGraphicsLayoutItem *item2 = extractLayoutItem(ctx, 2); - - if (!item1 || !item2) { - return eng->undefinedValue(); - } - - QGraphicsAnchor *anchor = self->addAnchor(item1, static_cast(ctx->argument(1).toInt32()), - item2, static_cast(ctx->argument(3).toInt32())); - - return eng->newQObject(anchor, QScriptEngine::QtOwnership); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsAnchorLayout, anchor) { - QGraphicsLayoutItem *item1 = extractLayoutItem(ctx, 0); - QGraphicsLayoutItem *item2 = extractLayoutItem(ctx, 2); - - if (!item1 || !item2) { - return eng->undefinedValue(); - } - - QGraphicsAnchor *anchor = self->anchor(item1, static_cast(ctx->argument(1).toInt32()), - item2, static_cast(ctx->argument(3).toInt32())); - - return eng->newQObject(anchor, QScriptEngine::QtOwnership); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsAnchorLayout, addCornerAnchors) { - QGraphicsLayoutItem *item1 = extractLayoutItem(ctx, 0); - QGraphicsLayoutItem *item2 = extractLayoutItem(ctx, 2); - - if (!item1 || !item2) { - return eng->undefinedValue(); - } - - self->addCornerAnchors(item1, static_cast(ctx->argument(1).toInt32()), - item2, static_cast(ctx->argument(3).toInt32())); - - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsAnchorLayout, addAnchors) { - QGraphicsLayoutItem *item1 = extractLayoutItem(ctx, 0); - QGraphicsLayoutItem *item2 = extractLayoutItem(ctx, 1); - - if (!item1 || !item2) { - return eng->undefinedValue(); - } - - self->addAnchors(item1, item2, static_cast(ctx->argument(2).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsAnchorLayout, toString) { - return QScriptValue(eng, "QGraphicsAnchorLayout"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsAnchorLayout, activate) { - self->activate(); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// - -class PrototypeAnchorLayout : public QGraphicsAnchorLayout -{ -public: - PrototypeAnchorLayout() - { } -}; - -QScriptValue constructAnchorLayoutClass(QScriptEngine *eng) -{ - QScriptValue proto = - QScript::wrapPointer(eng, - new QGraphicsAnchorLayout(), - QScript::UserOwnership); - const QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - const QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("horizontalSpacing", eng->newFunction(horizontalSpacing), getter); - proto.setProperty("horizontalSpacing", eng->newFunction(setHorizontalSpacing), setter); - proto.setProperty("verticalSpacing", eng->newFunction(verticalSpacing), getter); - proto.setProperty("verticalSpacing", eng->newFunction(setVerticalSpacing), setter); - - ADD_METHOD(proto, setSpacing); - ADD_METHOD(proto, removeAt); - ADD_METHOD(proto, addAnchor); - ADD_METHOD(proto, anchor); - ADD_METHOD(proto, addAnchors); - ADD_METHOD(proto, addCornerAnchors); - ADD_METHOD(proto, toString); - ADD_METHOD(proto, activate); - - QScript::registerPointerMetaType(eng, proto); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - return ctorFun; -} diff --git a/src/scriptengines/javascript/simplebindings/animationgroup.cpp b/src/scriptengines/javascript/simplebindings/animationgroup.cpp deleted file mode 100644 index 5b1ba3c7d..000000000 --- a/src/scriptengines/javascript/simplebindings/animationgroup.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2009 Aaron J. Seigo - * - * 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 "animationgroup.h" - -ParallelAnimationGroup::ParallelAnimationGroup(QObject *parent) - : QParallelAnimationGroup(parent) -{ -} - -void ParallelAnimationGroup::addAnimation(QAbstractAnimation *animation) -{ - QParallelAnimationGroup::addAnimation(animation); -} - -QAbstractAnimation *ParallelAnimationGroup::animationAt(int index) const -{ - return QParallelAnimationGroup::animationAt(index); -} - -int ParallelAnimationGroup::animationCount() const -{ - return QParallelAnimationGroup::animationCount(); -} - -void ParallelAnimationGroup::clear() -{ - QParallelAnimationGroup::clear(); -} - -int ParallelAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const -{ - return QParallelAnimationGroup::indexOfAnimation(animation); -} - -void ParallelAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation) -{ - QParallelAnimationGroup::insertAnimation(index, animation); -} - -void ParallelAnimationGroup::removeAnimation(QAbstractAnimation *animation) -{ - QParallelAnimationGroup::removeAnimation(animation); -} - - -SequentialAnimationGroup::SequentialAnimationGroup(QObject *parent) - : QSequentialAnimationGroup(parent) -{ -} - -void SequentialAnimationGroup::addAnimation(QAbstractAnimation *animation) -{ - QSequentialAnimationGroup::addAnimation(animation); -} - -QAbstractAnimation *SequentialAnimationGroup::animationAt(int index) const -{ - return QSequentialAnimationGroup::animationAt(index); -} - -int SequentialAnimationGroup::animationCount() const -{ - return QSequentialAnimationGroup::animationCount(); -} - -void SequentialAnimationGroup::clear() -{ - QSequentialAnimationGroup::clear(); -} - -int SequentialAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const -{ - return QSequentialAnimationGroup::indexOfAnimation(animation); -} - -void SequentialAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation) -{ - QSequentialAnimationGroup::insertAnimation(index, animation); -} - -void SequentialAnimationGroup::removeAnimation(QAbstractAnimation *animation) -{ - QSequentialAnimationGroup::removeAnimation(animation); -} - -#include "animationgroup.moc" diff --git a/src/scriptengines/javascript/simplebindings/animationgroup.h b/src/scriptengines/javascript/simplebindings/animationgroup.h deleted file mode 100644 index 556831be0..000000000 --- a/src/scriptengines/javascript/simplebindings/animationgroup.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2009 Aaron J. Seigo - * - * 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. - */ - -#ifndef ANIMATIONGROUP_H -#define ANIMATIONGROUP_H - -#include -#include - -class ParallelAnimationGroup : public QParallelAnimationGroup -{ - Q_OBJECT - -public: - ParallelAnimationGroup(QObject *parent); - -public Q_SLOTS: - void addAnimation(QAbstractAnimation * animation); - QAbstractAnimation *animationAt(int index) const; - int animationCount() const; - void clear(); - int indexOfAnimation(QAbstractAnimation *animation) const; - void insertAnimation(int index, QAbstractAnimation * animation); - void removeAnimation(QAbstractAnimation * animation); -}; - -class SequentialAnimationGroup : public QSequentialAnimationGroup -{ - Q_OBJECT - -public: - SequentialAnimationGroup(QObject *parent); - -public Q_SLOTS: - void addAnimation(QAbstractAnimation * animation); - QAbstractAnimation *animationAt(int index) const; - int animationCount() const; - void clear(); - int indexOfAnimation(QAbstractAnimation *animation) const; - void insertAnimation(int index, QAbstractAnimation * animation); - void removeAnimation(QAbstractAnimation * animation); -}; - -#endif - diff --git a/src/scriptengines/javascript/simplebindings/backportglobal.h b/src/scriptengines/javascript/simplebindings/backportglobal.h deleted file mode 100644 index 6f676a9f6..000000000 --- a/src/scriptengines/javascript/simplebindings/backportglobal.h +++ /dev/null @@ -1,348 +0,0 @@ -/**************************************************************************** -** -** This file is part of the Qt Script Generator. -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation info@qt.nokia.com -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation -** and appearing in the file LICENSE.LGPL included in the packaging of -** this file. Please review the following information to ensure the GNU -** Lesser General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** Copyright (C) 2011 Nokia. All rights reserved -****************************************************************************/ -#ifndef QTSCRIPTEXTENSIONS_GLOBAL_H -#define QTSCRIPTEXTENSIONS_GLOBAL_H - -#include - -#include -Q_DECLARE_METATYPE(QPixmap*) -Q_DECLARE_METATYPE(QPixmap) - -#define DECLARE_SELF(Class, __fn__) \ - Class* self = qscriptvalue_cast(ctx->thisObject()); \ - if (!self) { \ - return ctx->throwError(QScriptContext::TypeError, \ - QString::fromLatin1("%0.prototype.%1: this object is not a %0") \ - .arg(#Class).arg(#__fn__)); \ - } - -#define DECLARE_SELF2(Class, __fn__, __ret__) \ - Class* self = qscriptvalue_cast(thisObject()); \ - if (!self) { \ - context()->throwError(QScriptContext::TypeError, \ - QString::fromLatin1("%0.prototype.%1: this object is not a %0") \ - .arg(#Class).arg(#__fn__)); \ - return __ret__; \ - } - - - -#define ADD_METHOD(__p__, __f__) \ - __p__.setProperty(#__f__, __p__.engine()->newFunction(__f__)) - -#define ADD_GET_METHOD(__p__, __get__) \ - ADD_METHOD(__p__, __get__) - -#define ADD_GET_SET_METHODS(__p__, __get__, __set__) \ -do { \ - ADD_METHOD(__p__, __get__); \ - ADD_METHOD(__p__, __set__); \ -} while (0); - -#define ADD_CTOR_FUNCTION(__c__, __f__) ADD_METHOD(__c__, __f__) - -#define ADD_ENUM_VALUE(__c__, __ns__, __v__) \ - __c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__)) - - -#define BEGIN_DECLARE_METHOD(Class, __mtd__) \ -static QScriptValue __mtd__(QScriptContext *ctx, QScriptEngine *eng) \ -{ \ - DECLARE_SELF(Class, __mtd__); - -#define END_DECLARE_METHOD \ -} - - -#define DECLARE_GET_METHOD(Class, __get__) \ -BEGIN_DECLARE_METHOD(Class, __get__) { \ - return qScriptValueFromValue(eng, self->__get__()); \ -} END_DECLARE_METHOD - -#define DECLARE_SET_METHOD(Class, T, __set__) \ -BEGIN_DECLARE_METHOD(Class, __set__) { \ - self->__set__(qscriptvalue_cast(ctx->argument(0))); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_GET_SET_METHODS(Class, T, __get__, __set__) \ -DECLARE_GET_METHOD(Class, /*T,*/ __get__) \ -DECLARE_SET_METHOD(Class, T, __set__) - - - -#define DECLARE_SIMPLE_GET_METHOD(Class, __get__) \ -BEGIN_DECLARE_METHOD(Class, __get__) { \ - return QScriptValue(eng, self->__get__()); \ -} END_DECLARE_METHOD - -#define DECLARE_SIMPLE_SET_METHOD(Class, ToType, __set__) \ -BEGIN_DECLARE_METHOD(Class, __set__) { \ - self->__set__(ctx->argument(0).ToType()); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_BOOLEAN_GET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_GET_METHOD(Class, __set__) -#define DECLARE_BOOLEAN_SET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_SET_METHOD(Class, toBoolean, __set__) - -#define DECLARE_INT_GET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_GET_METHOD(Class, __set__) -#define DECLARE_INT_SET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_SET_METHOD(Class, toInt32, __set__) - -#define DECLARE_NUMBER_GET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_GET_METHOD(Class, __set__) -#define DECLARE_NUMBER_SET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_SET_METHOD(Class, toNumber, __set__) - -#define DECLARE_STRING_GET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_GET_METHOD(Class, __set__) -#define DECLARE_STRING_SET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_SET_METHOD(Class, toString, __set__) - -#define DECLARE_QOBJECT_GET_METHOD(Class, __get__) \ -BEGIN_DECLARE_METHOD(Class, __get__) { \ - return eng->newQObject(self->__get__()); \ -} END_DECLARE_METHOD -#define DECLARE_QOBJECT_SET_METHOD(Class, __set__) \ - DECLARE_SIMPLE_SET_METHOD(Class, toQObject, __set__) - -#define DECLARE_BOOLEAN_GET_SET_METHODS(Class, __get__, __set__) \ - DECLARE_BOOLEAN_GET_METHOD(Class, __get__) \ - DECLARE_BOOLEAN_SET_METHOD(Class, __set__) - -#define DECLARE_NUMBER_GET_SET_METHODS(Class, __get__, __set__) \ - DECLARE_NUMBER_GET_METHOD(Class, __get__) \ - DECLARE_NUMBER_SET_METHOD(Class, __set__) - -#define DECLARE_INT_GET_SET_METHODS(Class, __get__, __set__) \ - DECLARE_INT_GET_METHOD(Class, __get__) \ - DECLARE_INT_SET_METHOD(Class, __set__) - -#define DECLARE_STRING_GET_SET_METHODS(Class, __get__, __set__) \ - DECLARE_STRING_GET_METHOD(Class, __get__) \ - DECLARE_STRING_SET_METHOD(Class, __set__) - -#define DECLARE_QOBJECT_GET_SET_METHODS(Class, __get__, __set__) \ - DECLARE_QOBJECT_GET_METHOD(Class, __get__) \ - DECLARE_QOBJECT_SET_METHOD(Class, __set__) - - -#define DECLARE_VOID_METHOD(Class, __fun__) \ -BEGIN_DECLARE_METHOD(Class, __fun__) { \ - self->__fun__(); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_VOID_NUMBER_METHOD(Class, __fun__) \ -BEGIN_DECLARE_METHOD(Class, __fun__) { \ - self->__fun__(ctx->argument(0).toNumber()); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_VOID_NUMBER_NUMBER_METHOD(Class, __fun__) \ -BEGIN_DECLARE_METHOD(Class, __fun__) { \ - self->__fun__(ctx->argument(0).toNumber(), ctx->argument(1).toNumber()); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_VOID_QUAD_NUMBER_METHOD(Class, __fun__) \ -BEGIN_DECLARE_METHOD(Class, __fun__) { \ - self->__fun__(ctx->argument(0).toNumber(), ctx->argument(1).toNumber(), ctx->argument(2).toNumber(), ctx->argument(3).toNumber()); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_VOID_1ARG_METHOD(Class, ArgType, __fun__) \ -BEGIN_DECLARE_METHOD(Class, __fun__) { \ - self->__fun__(qscriptvalue_cast(ctx->argument(0))); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_BOOLEAN_1ARG_METHOD(Class, ArgType, __fun__) \ -BEGIN_DECLARE_METHOD(Class, __fun__) { \ - return QScriptValue(eng, self->__fun__(qscriptvalue_cast(ctx->argument(0)))); \ -} END_DECLARE_METHOD - - -#define DECLARE_POINTER_METATYPE(T) \ - Q_DECLARE_METATYPE(T*) \ - Q_DECLARE_METATYPE(QScript::Pointer::wrapped_pointer_type) - -namespace QScript -{ - -enum { - UserOwnership = 1 -}; - -template -class Pointer : public QSharedData -{ -public: - typedef T* pointer_type; - typedef QExplicitlySharedDataPointer > wrapped_pointer_type; - - ~Pointer() - { - if (!(m_flags & UserOwnership)) - delete m_value; - } - - operator T*() - { - return m_value; - } - - operator const T*() const - { - return m_value; - } - - static wrapped_pointer_type create(T *value, uint flags = 0) - { - return wrapped_pointer_type(new Pointer(value, flags)); - } - - static QScriptValue toScriptValue(QScriptEngine *engine, T* const &source) - { - if (!source) - return engine->nullValue(); - return engine->newVariant(qVariantFromValue(source)); - } - - static void fromScriptValue(const QScriptValue &value, T* &target) - { - if (value.isVariant()) { - QVariant var = value.toVariant(); - if (qVariantCanConvert(var)) { - target = qvariant_cast(var); - } else if (qVariantCanConvert(var)) { - target = qvariant_cast(var)->operator T*(); - } else { - // look in prototype chain - target = 0; - int type = qMetaTypeId(); - int pointerType = qMetaTypeId(); - QScriptValue proto = value.prototype(); - while (proto.isObject() && proto.isVariant()) { - int protoType = proto.toVariant().userType(); - if ((type == protoType) || (pointerType == protoType)) { - QByteArray name = QMetaType::typeName(var.userType()); - if (name.startsWith("QScript::Pointer<")) { - target = (*reinterpret_cast(var.data()))->operator T*(); - break; - } else { - target = static_cast(var.data()); - break; - } - } - proto = proto.prototype(); - } - } - } else if (value.isQObject()) { - QObject *qobj = value.toQObject(); - QByteArray typeName = QMetaType::typeName(qMetaTypeId()); - target = reinterpret_cast(qobj->qt_metacast(typeName.left(typeName.size()-1))); - } else { - target = 0; - } - } - - uint flags() const - { return m_flags; } - void setFlags(uint flags) - { m_flags = flags; } - void unsetFlags(uint flags) - { m_flags &= ~flags; } - -protected: - Pointer(T* value, uint flags) - : m_flags(flags), m_value(value) - {} - -private: - uint m_flags; - T* m_value; -}; - -template -int registerPointerMetaType( - QScriptEngine *eng, - const QScriptValue &prototype = QScriptValue(), - T * /* dummy */ = 0 -) -{ - QScriptValue (*mf)(QScriptEngine *, T* const &) = Pointer::toScriptValue; - void (*df)(const QScriptValue &, T* &) = Pointer::fromScriptValue; - const int id = qMetaTypeId(); - qScriptRegisterMetaType_helper( - eng, id, reinterpret_cast(mf), - reinterpret_cast(df), - prototype); - eng->setDefaultPrototype(qMetaTypeId::wrapped_pointer_type>(), prototype); - return id; -} - -inline void maybeReleaseOwnership(const QScriptValue &value) -{ - if (value.isVariant()) { - QVariant var = value.toVariant(); - QByteArray name = QMetaType::typeName(var.userType()); - if (name.startsWith("QScript::Pointer<")) - (*reinterpret_cast::wrapped_pointer_type *>(var.data()))->setFlags(UserOwnership); - } -} - -inline void maybeTakeOwnership(const QScriptValue &value) -{ - if (value.isVariant()) { - QVariant var = value.toVariant(); - QByteArray name = QMetaType::typeName(var.userType()); - if (name.startsWith("QScript::Pointer<")) - (*reinterpret_cast::wrapped_pointer_type *>(var.data()))->unsetFlags(UserOwnership); - } -} - -template -inline QScriptValue wrapPointer(QScriptEngine *eng, T *ptr, uint flags = 0) -{ - return eng->newVariant(qVariantFromValue(Pointer::create(ptr, flags))); -} - -} // namespace QScript - -#ifdef QGRAPHICSITEM_H - -namespace QScript { - -template -inline QScriptValue wrapGVPointer(QScriptEngine *eng, T *item) -{ - uint flags = item->parentItem() ? UserOwnership : 0; - return wrapPointer(eng, item, flags); -} - -} // namespace QScript - -#endif // QGRAPHICSITEM_H - -#endif // QTSCRIPTEXTENSIONS_GLOBAL_H diff --git a/src/scriptengines/javascript/simplebindings/bytearrayclass.cpp b/src/scriptengines/javascript/simplebindings/bytearrayclass.cpp deleted file mode 100644 index c3113e15b..000000000 --- a/src/scriptengines/javascript/simplebindings/bytearrayclass.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "bytearrayclass.h" - -#include -#include - -#include "bytearrayprototype.h" - -#include - -Q_DECLARE_METATYPE(QByteArray*) -Q_DECLARE_METATYPE(ByteArrayClass*) - -class ByteArrayClassPropertyIterator : public QScriptClassPropertyIterator -{ -public: - ByteArrayClassPropertyIterator(const QScriptValue &object); - ~ByteArrayClassPropertyIterator(); - - bool hasNext() const; - void next(); - - bool hasPrevious() const; - void previous(); - - void toFront(); - void toBack(); - - QScriptString name() const; - uint id() const; - -private: - int m_index; - int m_last; -}; - -//! [0] -ByteArrayClass::ByteArrayClass(QScriptEngine *engine) - : QObject(engine), QScriptClass(engine) -{ - qScriptRegisterMetaType(engine, toScriptValue, fromScriptValue); - - length = engine->toStringHandle(QLatin1String("length")); - - proto = engine->newQObject(new ByteArrayPrototype(this), - QScriptEngine::QtOwnership, - QScriptEngine::SkipMethodsInEnumeration - | QScriptEngine::ExcludeSuperClassMethods - | QScriptEngine::ExcludeSuperClassProperties); - QScriptValue global = engine->globalObject(); - proto.setPrototype(global.property("Object").property("prototype")); - - ctor = engine->newFunction(construct, proto); - ctor.setData(qScriptValueFromValue(engine, this)); -} -//! [0] - -ByteArrayClass::~ByteArrayClass() -{ -} - -//! [3] -QScriptClass::QueryFlags ByteArrayClass::queryProperty(const QScriptValue &object, - const QScriptString &name, - QueryFlags flags, uint *id) -{ - QByteArray *ba = qscriptvalue_cast(object.data()); - if (!ba) - return 0; - if (name == length) { - return flags; - } else { - bool isArrayIndex; - qint32 pos = name.toArrayIndex(&isArrayIndex); - if (!isArrayIndex) - return 0; - *id = pos; - if ((flags & HandlesReadAccess) && (pos >= ba->size())) - flags &= ~HandlesReadAccess; - return flags; - } -} -//! [3] - -//! [4] -QScriptValue ByteArrayClass::property(const QScriptValue &object, - const QScriptString &name, uint id) -{ - QByteArray *ba = qscriptvalue_cast(object.data()); - if (!ba) - return QScriptValue(); - if (name == length) { - return ba->length(); - } else { - qint32 pos = id; - if ((pos < 0) || (pos >= ba->size())) - return QScriptValue(); - return uint(ba->at(pos)) & 255; - } - return QScriptValue(); -} -//! [4] - -//! [5] -void ByteArrayClass::setProperty(QScriptValue &object, - const QScriptString &name, - uint id, const QScriptValue &value) -{ - QByteArray *ba = qscriptvalue_cast(object.data()); - if (!ba) - return; - if (name == length) { - ba->resize(value.toInt32()); - } else { - qint32 pos = id; - if (pos < 0) - return; - if (ba->size() <= pos) - ba->resize(pos + 1); - (*ba)[pos] = char(value.toInt32()); - } -} -//! [5] - -//! [6] -QScriptValue::PropertyFlags ByteArrayClass::propertyFlags( - const QScriptValue &/*object*/, const QScriptString &name, uint /*id*/) -{ - if (name == length) { - return QScriptValue::Undeletable - | QScriptValue::SkipInEnumeration; - } - return QScriptValue::Undeletable; -} -//! [6] - -//! [7] -QScriptClassPropertyIterator *ByteArrayClass::newIterator(const QScriptValue &object) -{ - return new ByteArrayClassPropertyIterator(object); -} -//! [7] - -QString ByteArrayClass::name() const -{ - return QLatin1String("ByteArray"); -} - -QScriptValue ByteArrayClass::prototype() const -{ - return proto; -} - -QScriptValue ByteArrayClass::constructor() -{ - return ctor; -} - -QScriptValue ByteArrayClass::newInstance(int size) -{ - return newInstance(QByteArray(size, /*ch=*/0)); -} - -//! [1] -QScriptValue ByteArrayClass::newInstance(const QByteArray &ba) -{ - QScriptValue data = engine()->newVariant(qVariantFromValue(ba)); - return engine()->newObject(this, data); -} -//! [1] - -//! [2] -QScriptValue ByteArrayClass::construct(QScriptContext *ctx, QScriptEngine *) -{ - ByteArrayClass *cls = qscriptvalue_cast(ctx->callee().data()); - if (!cls) - return QScriptValue(); - QScriptValue arg = ctx->argument(0); - if (arg.instanceOf(ctx->callee())) - return cls->newInstance(qscriptvalue_cast(arg)); - int size = arg.toInt32(); - return cls->newInstance(size); -} -//! [2] - -QScriptValue ByteArrayClass::toScriptValue(QScriptEngine *eng, const QByteArray &ba) -{ - QScriptValue ctor = eng->globalObject().property("ByteArray"); - ByteArrayClass *cls = qscriptvalue_cast(ctor.data()); - if (!cls) - return eng->newVariant(qVariantFromValue(ba)); - return cls->newInstance(ba); -} - -void ByteArrayClass::fromScriptValue(const QScriptValue &obj, QByteArray &ba) -{ - ba = obj.toVariant().toByteArray(); -} - - - -ByteArrayClassPropertyIterator::ByteArrayClassPropertyIterator(const QScriptValue &object) - : QScriptClassPropertyIterator(object) -{ - toFront(); -} - -ByteArrayClassPropertyIterator::~ByteArrayClassPropertyIterator() -{ -} - -//! [8] -bool ByteArrayClassPropertyIterator::hasNext() const -{ - QByteArray *ba = qscriptvalue_cast(object().data()); - return m_index < ba->size(); -} - -void ByteArrayClassPropertyIterator::next() -{ - m_last = m_index; - ++m_index; -} - -bool ByteArrayClassPropertyIterator::hasPrevious() const -{ - return (m_index > 0); -} - -void ByteArrayClassPropertyIterator::previous() -{ - --m_index; - m_last = m_index; -} - -void ByteArrayClassPropertyIterator::toFront() -{ - m_index = 0; - m_last = -1; -} - -void ByteArrayClassPropertyIterator::toBack() -{ - QByteArray *ba = qscriptvalue_cast(object().data()); - m_index = ba->size(); - m_last = -1; -} - -QScriptString ByteArrayClassPropertyIterator::name() const -{ - return object().engine()->toStringHandle(QString::number(m_last)); -} - -uint ByteArrayClassPropertyIterator::id() const -{ - return m_last; -} -//! [8] diff --git a/src/scriptengines/javascript/simplebindings/bytearrayclass.h b/src/scriptengines/javascript/simplebindings/bytearrayclass.h deleted file mode 100644 index 126127132..000000000 --- a/src/scriptengines/javascript/simplebindings/bytearrayclass.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef BYTEARRAYCLASS_H -#define BYTEARRAYCLASS_H - -#include -#include -#include -#include - -class ByteArrayClass : public QObject, public QScriptClass -{ -public: - ByteArrayClass(QScriptEngine *engine); - ~ByteArrayClass(); - - QScriptValue constructor(); - - QScriptValue newInstance(int size = 0); - QScriptValue newInstance(const QByteArray &ba); - - QueryFlags queryProperty(const QScriptValue &object, - const QScriptString &name, - QueryFlags flags, uint *id); - - QScriptValue property(const QScriptValue &object, - const QScriptString &name, uint id); - - void setProperty(QScriptValue &object, const QScriptString &name, - uint id, const QScriptValue &value); - - QScriptValue::PropertyFlags propertyFlags( - const QScriptValue &object, const QScriptString &name, uint id); - - QScriptClassPropertyIterator *newIterator(const QScriptValue &object); - - QString name() const; - - QScriptValue prototype() const; - -private: - static QScriptValue construct(QScriptContext *ctx, QScriptEngine *eng); - - static QScriptValue toScriptValue(QScriptEngine *eng, const QByteArray &ba); - static void fromScriptValue(const QScriptValue &obj, QByteArray &ba); - - QScriptString length; - QScriptValue proto; - QScriptValue ctor; -}; - -#endif diff --git a/src/scriptengines/javascript/simplebindings/bytearrayprototype.cpp b/src/scriptengines/javascript/simplebindings/bytearrayprototype.cpp deleted file mode 100644 index 2bb5f99e9..000000000 --- a/src/scriptengines/javascript/simplebindings/bytearrayprototype.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "bytearrayprototype.h" -#include - -Q_DECLARE_METATYPE(QByteArray*) - -ByteArrayPrototype::ByteArrayPrototype(QObject *parent) - : QObject(parent) -{ -} - -ByteArrayPrototype::~ByteArrayPrototype() -{ -} - -//! [0] -QByteArray *ByteArrayPrototype::thisByteArray() const -{ - return qscriptvalue_cast(thisObject().data()); -} -//! [0] - -void ByteArrayPrototype::chop(int n) -{ - thisByteArray()->chop(n); -} - -bool ByteArrayPrototype::equals(const QByteArray &other) -{ - return *thisByteArray() == other; -} - -QByteArray ByteArrayPrototype::left(int len) const -{ - return thisByteArray()->left(len); -} - -//! [1] -QByteArray ByteArrayPrototype::mid(int pos, int len) const -{ - return thisByteArray()->mid(pos, len); -} - -QScriptValue ByteArrayPrototype::remove(int pos, int len) -{ - thisByteArray()->remove(pos, len); - return thisObject(); -} -//! [1] - -QByteArray ByteArrayPrototype::right(int len) const -{ - return thisByteArray()->right(len); -} - -QByteArray ByteArrayPrototype::simplified() const -{ - return thisByteArray()->simplified(); -} - -QByteArray ByteArrayPrototype::toBase64() const -{ - return thisByteArray()->toBase64(); -} - -QByteArray ByteArrayPrototype::toLower() const -{ - return thisByteArray()->toLower(); -} - -QByteArray ByteArrayPrototype::toUpper() const -{ - return thisByteArray()->toUpper(); -} - -QByteArray ByteArrayPrototype::trimmed() const -{ - return thisByteArray()->trimmed(); -} - -void ByteArrayPrototype::truncate(int pos) -{ - thisByteArray()->truncate(pos); -} - -QString ByteArrayPrototype::toLatin1String() const -{ - return QString::fromLatin1(*thisByteArray()); -} - -QString ByteArrayPrototype::toUtf8() const -{ - return QString::fromUtf8(*thisByteArray()); -} - -//! [2] -QScriptValue ByteArrayPrototype::valueOf() const -{ - return thisObject().data(); -} -//! [2] diff --git a/src/scriptengines/javascript/simplebindings/bytearrayprototype.h b/src/scriptengines/javascript/simplebindings/bytearrayprototype.h deleted file mode 100644 index 838fd3efa..000000000 --- a/src/scriptengines/javascript/simplebindings/bytearrayprototype.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef BYTEARRAYPROTOTYPE_H -#define BYTEARRAYPROTOTYPE_H - -#include -#include -#include -#include - -//! [0] -class ByteArrayPrototype : public QObject, public QScriptable -{ -Q_OBJECT -public: - ByteArrayPrototype(QObject *parent = 0); - ~ByteArrayPrototype(); - -public Q_SLOTS: - void chop(int n); - bool equals(const QByteArray &other); - QByteArray left(int len) const; - QByteArray mid(int pos, int len = -1) const; - QScriptValue remove(int pos, int len); - QByteArray right(int len) const; - QByteArray simplified() const; - QByteArray toBase64() const; - QByteArray toLower() const; - QByteArray toUpper() const; - QByteArray trimmed() const; - void truncate(int pos); - QString toLatin1String() const; - QString toUtf8() const; - QScriptValue valueOf() const; - -private: - QByteArray *thisByteArray() const; -}; -//! [0] - - -#endif diff --git a/src/scriptengines/javascript/simplebindings/color.cpp b/src/scriptengines/javascript/simplebindings/color.cpp deleted file mode 100644 index 595c76157..000000000 --- a/src/scriptengines/javascript/simplebindings/color.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2009 Aaron J. Seigo - * - * 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 - -#include - -#include "backportglobal.h" - -Q_DECLARE_METATYPE(QColor*) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() == 0) { - return qScriptValueFromValue(eng, QColor()); - } else if (ctx->argumentCount() == 1) { - QString namedColor = ctx->argument(0).toString(); - return qScriptValueFromValue(eng, QColor(namedColor)); - } - - int r = 0; - int g = 0; - int b = 0; - int a = 255; - if (ctx->argumentCount() == 3) { - r = ctx->argument(0).toInt32(); - g = ctx->argument(1).toInt32(); - b = ctx->argument(2).toInt32(); - } - - if (ctx->argumentCount() == 4) { - a = ctx->argument(3).toInt32(); - } - - return qScriptValueFromValue(eng, QColor(r, g, b, a)); -} - -// red, green, blue, alpha, setRed, setGreen, setBlue, setAlpha, isValid, toString, name - -static QScriptValue red(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QColor, red); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setRed(arg.toInt32()); - } - - return QScriptValue(eng, self->red()); -} - -static QScriptValue green(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QColor, green); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setGreen(arg.toInt32()); - } - - return QScriptValue(eng, self->green()); -} - -static QScriptValue blue(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QColor, blue); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setBlue(arg.toInt32()); - } - - return QScriptValue(eng, self->blue()); -} - -static QScriptValue alpha(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QColor, alpha); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setAlpha(arg.toInt32()); - } - - return QScriptValue(eng, self->alpha()); -} - -static QScriptValue valid(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QColor, valid); - return QScriptValue(eng, self->isValid()); -} - -static QScriptValue setThemeColor(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QColor, themeColor); - - if (ctx->argumentCount() > 0) { - const qint32 arg = ctx->argument(0).toInt32(); - if (arg >= 0 && arg <= Plasma::Theme::VisitedLinkColor) { - // qDebug() << "setting to: " << static_cast(arg); - // qDebug() << "color is: " << Plasma::Theme::defaultTheme()->color(static_cast(arg)); - self->setRgba(Plasma::Theme::defaultTheme()->color(static_cast(arg)).rgba()); - } - } - - return ctx->thisObject();//.property("themeColor"); -} - -QScriptValue constructColorClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QColor()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - proto.setProperty("red", eng->newFunction(red), getter | setter); - proto.setProperty("green", eng->newFunction(green), getter | setter); - proto.setProperty("blue", eng->newFunction(blue), getter | setter); - proto.setProperty("alpha", eng->newFunction(alpha), getter | setter); - proto.setProperty("valid", eng->newFunction(valid), getter); - ADD_METHOD(proto, setThemeColor); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/javascript/simplebindings/dataengine.cpp b/src/scriptengines/javascript/simplebindings/dataengine.cpp deleted file mode 100644 index 299e00c2f..000000000 --- a/src/scriptengines/javascript/simplebindings/dataengine.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 "dataengine.h" - -typedef Plasma::Service *ServicePtr; -QScriptValue qScriptValueFromService(QScriptEngine *engine, const ServicePtr &service) -{ - return engine->newQObject(const_cast(service), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void serviceFromQScriptValue(const QScriptValue &scriptValue, ServicePtr &service) -{ - QObject *obj = scriptValue.toQObject(); - service = static_cast(obj); -} - -typedef Plasma::DataEngine *DataEnginePtr; -QScriptValue qScriptValueFromDataEngine(QScriptEngine *engine, const DataEnginePtr &dataEngine) -{ - return engine->newQObject(const_cast(dataEngine), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void dataEngineFromQScriptValue(const QScriptValue &scriptValue, DataEnginePtr &dataEngine) -{ - QObject *obj = scriptValue.toQObject(); - dataEngine = static_cast(obj); -} - -typedef Plasma::ServiceJob *ServiceJobPtr; -QScriptValue qScriptValueFromServiceJob(QScriptEngine *engine, const ServiceJobPtr &serviceJob) -{ - return engine->newQObject(const_cast(serviceJob), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void serviceJobFromQScriptValue(const QScriptValue &scriptValue, ServiceJobPtr &serviceJob) -{ - QObject *obj = scriptValue.toQObject(); - serviceJob = static_cast(obj); -} - -typedef QMap< QString, QString > StringStringMap; -Q_DECLARE_METATYPE(StringStringMap) - -void registerDataEngineMetaTypes(QScriptEngine *engine) -{ - qRegisterMetaType("Plasma::DataEngine::Data"); - qRegisterMetaType("DataEngine::Data"); - qScriptRegisterVariantMapMetaType(engine); - qScriptRegisterMapMetaType(engine); - qScriptRegisterMetaType(engine, qScriptValueFromService, serviceFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromDataEngine, dataEngineFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromServiceJob, serviceJobFromQScriptValue); - qRegisterMetaType("Service*"); - qRegisterMetaType("ServiceJob*"); -} - diff --git a/src/scriptengines/javascript/simplebindings/dataengine.h b/src/scriptengines/javascript/simplebindings/dataengine.h deleted file mode 100644 index 41598bb29..000000000 --- a/src/scriptengines/javascript/simplebindings/dataengine.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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. - */ - -#ifndef DATAENGINE_H -#define DATAENGINE_H - -#include -#include -#include -#include - -#include -#include -#include - -using namespace Plasma; - -#ifndef DECLARATIVE_BINDING -Q_DECLARE_METATYPE(QVariant) -#endif -Q_DECLARE_METATYPE(DataEngine::Dict) -Q_DECLARE_METATYPE(DataEngine::Data) - -template -QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map) -{ - //qDebug() << "qScriptValueFromMap called"; - QScriptValue obj = eng->newObject(); - typename M::const_iterator begin = map.constBegin(); - typename M::const_iterator end = map.constEnd(); - typename M::const_iterator it; - for (it = begin; it != end; ++it) { - obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value())); - } - - return obj; -} - -template -QScriptValue qScriptValueFromVariantMap(QScriptEngine *eng, const M &map) -{ - //qDebug() << "qScriptValueFromMap called"; - QScriptValue obj = eng->newObject(); - typename M::const_iterator begin = map.constBegin(); - typename M::const_iterator end = map.constEnd(); - typename M::const_iterator it; - for (it = begin; it != end; ++it) { - if (it.value().type() == QVariant::Hash) { - obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toHash())); - } else if (it.value().type() == QVariant::Map) { - obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toMap())); - } else { - obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value())); - } - } - - return obj; -} - -template -void qScriptValueToMap(const QScriptValue &value, M &map) -{ - //qDebug() << "qScriptValueToMap called"; - QScriptValueIterator it(value); - while (it.hasNext()) { - it.next(); - map[it.name()] = qscriptvalue_cast(it.value()); - } -} - -template -int qScriptRegisterVariantMapMetaType( - QScriptEngine *engine, - const QScriptValue &prototype = QScriptValue() -#ifndef qdoc - , T * /* dummy */ = 0 -#endif -) -{ - return qScriptRegisterMetaType(engine, qScriptValueFromVariantMap, qScriptValueToMap, prototype); -} - -template -int qScriptRegisterMapMetaType( - QScriptEngine *engine, - const QScriptValue &prototype = QScriptValue() -#ifndef qdoc - , T * /* dummy */ = 0 -#endif -) -{ - return qScriptRegisterMetaType(engine, qScriptValueFromMap, qScriptValueToMap, prototype); -} - -void registerDataEngineMetaTypes(QScriptEngine *engine); - -#endif // DATAENGINE_H - diff --git a/src/scriptengines/javascript/simplebindings/dataenginereceiver.cpp b/src/scriptengines/javascript/simplebindings/dataenginereceiver.cpp deleted file mode 100644 index d632e976a..000000000 --- a/src/scriptengines/javascript/simplebindings/dataenginereceiver.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2010 Aaron J. Seigo - * - * 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 "dataenginereceiver.h" - -#include - -#include "dataengine.h" -#include "scriptenv.h" - -QSet DataEngineReceiver::s_receivers; - -DataEngineReceiver::DataEngineReceiver(const Plasma::DataEngine *engine, const QString &source, const QScriptValue &func, QObject *parent) - : QObject(parent), - m_engine(engine), - m_source(source), - m_func(func), - m_obj(m_func) -{ - s_receivers.insert(this); - if (!m_func.isFunction()) { - QScriptValue func = m_func.property("dataUpdated"); - if (func.isFunction()) { - m_func = func; - } else { - m_obj = QScriptValue(); - } - } -} - -DataEngineReceiver::~DataEngineReceiver() -{ - s_receivers.remove(this); - //qDebug() << s_receivers.count(); -} - -bool DataEngineReceiver::isValid() const -{ - return m_obj.isValid(); -} - -bool DataEngineReceiver::matches(const Plasma::DataEngine *engine, const QString &source, const QScriptValue &v) -{ - return engine == m_engine && m_source == source && v.equals(m_obj); -} - -void DataEngineReceiver::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data) -{ - QScriptEngine *engine = m_func.engine(); -// QScriptValue appletValue = engine->globalObject().property("plasmoid"); - QScriptValueList args; - args << source; - args << qScriptValueFromMap(engine, data); - - m_func.call(m_obj, args); - - if (engine->hasUncaughtException()) { - ScriptEnv *env = ScriptEnv::findScriptEnv(engine); - env->checkForErrors(false); - } -} - -DataEngineReceiver *DataEngineReceiver::getReceiver(Plasma::DataEngine *dataEngine, const QString &source, const QScriptValue &v) -{ - foreach (DataEngineReceiver *receiver, DataEngineReceiver::s_receivers) { - if (receiver->matches(dataEngine, source, v)) { - return receiver; - } - } - - return 0; -} - -QObject *DataEngineReceiver::extractTargetQObject(QScriptEngine *engine, const QString &source, const QScriptValue &v, Plasma::DataEngine *dataEngine) -{ - QObject *obj = 0; - - // if it's a function we get, then use that directly - // next see if it is a qobject with a good slot; if it is then use that directly - // otherwise, try to use the object with a dataUpdated method call - if (v.isFunction()) { - obj = getReceiver(dataEngine, source, v); - if (!obj) { - obj = new DataEngineReceiver(dataEngine, source, v, ScriptEnv::findScriptEnv(engine)); - } - } else if (v.isObject()) { - obj = v.toQObject(); - if (!obj || obj->metaObject()->indexOfSlot("dataUpdated(QString,Plasma::DataEngine::Data)") == -1) { - obj = getReceiver(dataEngine, source, v); - if (!obj) { - DataEngineReceiver *receiver = new DataEngineReceiver(dataEngine, source, v, ScriptEnv::findScriptEnv(engine)); - if (receiver->isValid()) { - obj = receiver; - } else { - delete receiver; - } - } - } - } - - return obj; -} - -QScriptValue DataEngineReceiver::connectAllSources(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 1) { - return engine->undefinedValue(); - } - - DataEngine *dataEngine = qobject_cast(context->thisObject().toQObject()); - if (!dataEngine) { - return engine->undefinedValue(); - } - - int pollingInterval = 0; - Plasma::Types::IntervalAlignment intervalAlignment = Plasma::NoAlignment; - if (context->argumentCount() > 1) { - pollingInterval = context->argument(2).toInt32(); - - if (context->argumentCount() > 2) { - intervalAlignment = static_cast(context->argument(4).toInt32()); - } - } - - QObject *obj = extractTargetQObject(engine, QString(), context->argument(0), dataEngine); - if (!obj) { - return engine->undefinedValue(); - } - - dataEngine->connectAllSources(obj, pollingInterval, intervalAlignment); - return true; -} - -QScriptValue DataEngineReceiver::connectSource(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 2) { - return engine->undefinedValue(); - } - - DataEngine *dataEngine = qobject_cast(context->thisObject().toQObject()); - if (!dataEngine) { - return engine->undefinedValue(); - } - - const QString source = context->argument(0).toString(); - if (source.isEmpty()) { - return engine->undefinedValue(); - } - - QObject *obj = extractTargetQObject(engine, source, context->argument(1), dataEngine); - if (!obj) { - return engine->undefinedValue(); - } - - int pollingInterval = 0; - Plasma::Types::IntervalAlignment intervalAlignment = Plasma::NoAlignment; - if (context->argumentCount() > 2) { - pollingInterval = context->argument(2).toInt32(); - - if (context->argumentCount() > 3) { - intervalAlignment = static_cast(context->argument(4).toInt32()); - } - } - - dataEngine->connectSource(source, obj, pollingInterval, intervalAlignment); - return true; -} - -QScriptValue DataEngineReceiver::disconnectSource(QScriptContext *context, QScriptEngine *engine) -{ - if (context->argumentCount() < 2) { - return engine->undefinedValue(); - } - - DataEngine *dataEngine = qobject_cast(context->thisObject().toQObject()); - if (!dataEngine) { - //qDebug() << "no engine!"; - return engine->undefinedValue(); - } - - const QString source = context->argument(0).toString(); - if (source.isEmpty()) { - //qDebug() << "no source!"; - return engine->undefinedValue(); - } - - QObject *obj = 0; - QScriptValue v = context->argument(1); - if (v.isQObject()) { - obj = v.toQObject(); - } else if (v.isObject() || v.isFunction()) { - foreach (DataEngineReceiver *receiver, DataEngineReceiver::s_receivers) { - if (receiver->matches(dataEngine, source, v)) { - obj = receiver; - receiver->deleteLater(); - break; - } - } - } - - if (!obj) { - //qDebug() << "no object!"; - return engine->undefinedValue(); - } - - dataEngine->disconnectSource(source, obj); - return true; -} - -#include "dataenginereceiver.moc" - diff --git a/src/scriptengines/javascript/simplebindings/dataenginereceiver.h b/src/scriptengines/javascript/simplebindings/dataenginereceiver.h deleted file mode 100644 index f1f2a426c..000000000 --- a/src/scriptengines/javascript/simplebindings/dataenginereceiver.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2010 Aaron Seigo - * - * 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. - */ - -#ifndef DATAENGINERECEIVER_H -#define DATAENGINERECEIVER_H - -#include - -#include - -class QScriptContext; -class QScriptEngine; - -class DataEngineReceiver : public QObject -{ - Q_OBJECT -public: - DataEngineReceiver(const Plasma::DataEngine *engine, const QString &source, const QScriptValue &func, QObject *parent); - ~DataEngineReceiver(); - - bool isValid() const; - - static QScriptValue connectSource(QScriptContext *context, QScriptEngine *engine); - static QScriptValue connectAllSources(QScriptContext *context, QScriptEngine *engine); - static QScriptValue disconnectSource(QScriptContext *context, QScriptEngine *engine); - static QSet s_receivers; - - bool matches(const Plasma::DataEngine *engine, const QString &source, const QScriptValue &v); - -public Q_SLOTS: - void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data); - -private: - static DataEngineReceiver *getReceiver(Plasma::DataEngine *dataEngine, const QString &source, const QScriptValue &v); - static QObject *extractTargetQObject(QScriptEngine *engine, const QString &source, const QScriptValue &v, Plasma::DataEngine *dataEngine); - - const Plasma::DataEngine *m_engine; - const QString m_source; - QScriptValue m_func; - QScriptValue m_obj; -}; - -#endif // DATAENGINERECEIVER_H - diff --git a/src/scriptengines/javascript/simplebindings/easingcurve.cpp b/src/scriptengines/javascript/simplebindings/easingcurve.cpp deleted file mode 100644 index ef465a224..000000000 --- a/src/scriptengines/javascript/simplebindings/easingcurve.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2010 Aaron Seigo - * - * 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 -#include - -#include "backportglobal.h" - -Q_DECLARE_METATYPE(QEasingCurve) -Q_DECLARE_METATYPE(QEasingCurve*) - -#include -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - if (arg.isNumber()) { - qint32 type = arg.toInt32(); - if (type > -1 && type < QEasingCurve::Custom) { - return qScriptValueFromValue(eng, QEasingCurve(static_cast(type))); - } - } - } - - return qScriptValueFromValue(eng, QEasingCurve()); -} - -static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QEasingCurve, toString); - return QScriptValue(eng, QString::fromLatin1("QEasingCurve(type=%0)").arg(self->type())); -} - -static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QEasingCurve, type); - - if (ctx->argumentCount()) { - QScriptValue arg = ctx->argument(0); - - qint32 type = -1; - if (arg.isNumber()) { - type = arg.toInt32(); - } else if (arg.isString()) { - QMetaObject meta = QEasingCurve::staticMetaObject; - QMetaEnum easingCurveEnum = meta.enumerator(meta.indexOfEnumerator("Type")); - - type = easingCurveEnum.keyToValue(arg.toString().toAscii().data()); - } - if (type > -1 && type < QEasingCurve::Custom) { - self->setType(static_cast(type)); - } - } - - return QScriptValue(eng, self->type()); -} - -static QScriptValue valueForProgress(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QEasingCurve, valueForProgress); - if (ctx->argumentCount() < 1 || !ctx->argument(0).isNumber()) { - return eng->undefinedValue(); - } - - return self->valueForProgress(ctx->argument(0).toNumber()); -} - -QScriptValue constructEasingCurveClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QEasingCurve()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("type", eng->newFunction(type), getter | setter); - proto.setProperty("toString", eng->newFunction(toString), getter); - proto.setProperty("valueForProgress", eng->newFunction(valueForProgress), getter); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, Linear); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuad); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuad); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuad); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuad); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCubic); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCubic); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutCubic); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInCubic); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuart); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuart); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuart); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuart); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuint); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuint); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuint); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuint); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InSine); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutSine); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutSine); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInSine); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InExpo); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutExpo); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutExpo); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInExpo); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCirc); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCirc); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutCirc); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInCirc); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InElastic); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutElastic); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutElastic); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInElastic); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InBack); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutBack); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutBack); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInBack); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InBounce); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutBounce); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutBounce); - - ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCurve); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCurve); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, SineCurve); - ADD_ENUM_VALUE(ctorFun, QEasingCurve, CosineCurve); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return ctorFun; -} - diff --git a/src/scriptengines/javascript/simplebindings/filedialogproxy.cpp b/src/scriptengines/javascript/simplebindings/filedialogproxy.cpp deleted file mode 100644 index bc93b4bc8..000000000 --- a/src/scriptengines/javascript/simplebindings/filedialogproxy.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2009 Aaron J. Seigo - * - * 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 "filedialogproxy.h" - -#include - -#include - -FileDialogProxy::FileDialogProxy(KFileDialog::OperationMode mode, QObject *parent) - : QObject(parent), - m_dialog(new KFileDialog(QUrl::fromLocalFile("~"), QString(), 0)) -{ - m_dialog->setOperationMode(mode); - connect(m_dialog, SIGNAL(finished()), this, SLOT(dialogFinished())); -} - -FileDialogProxy::~FileDialogProxy() -{ - delete m_dialog; -} - -QUrl FileDialogProxy::selectedUrl() const -{ - return m_dialog->selectedUrl(); -} - -void FileDialogProxy::setUrl(const QUrl &url) -{ - m_dialog->setUrl(url); -} - -QUrl::List FileDialogProxy::selectedUrls() const -{ - return m_dialog->selectedUrls(); -} - -QUrl FileDialogProxy::baseUrl() const -{ - return m_dialog->baseUrl(); -} - -QString FileDialogProxy::selectedFile() const -{ - return m_dialog->selectedFile(); -} - -QStringList FileDialogProxy::selectedFiles() const -{ - return m_dialog->selectedFiles(); -} - -QString FileDialogProxy::filter() const -{ - return m_dialog->currentFilter(); -} - -void FileDialogProxy::setFilter(const QString &filter) -{ - m_dialog->setFilter(filter); -} - -bool FileDialogProxy::localOnly() const -{ - return m_dialog->mode() & KFile::LocalOnly; -} - -void FileDialogProxy::setLocalOnly(bool localOnly) -{ - if (localOnly) { - m_dialog->setMode(m_dialog->mode() ^ KFile::LocalOnly); - } else { - m_dialog->setMode(m_dialog->mode() | KFile::LocalOnly); - } -} - -bool FileDialogProxy::directoriesOnly() const -{ - return m_dialog->mode() & KFile::Directory; -} - -void FileDialogProxy::setDirectoriesOnly(bool directoriesOnly) -{ - if (directoriesOnly) { - m_dialog->setMode(m_dialog->mode() ^ KFile::Directory); - } else { - m_dialog->setMode(m_dialog->mode() | KFile::Directory); - } -} - -bool FileDialogProxy::existingOnly() const -{ - return m_dialog->mode() & KFile::ExistingOnly; -} - -void FileDialogProxy::setExistingOnly(bool existingOnly) -{ - if (existingOnly) { - m_dialog->setMode(m_dialog->mode() ^ KFile::ExistingOnly); - } else { - m_dialog->setMode(m_dialog->mode() | KFile::ExistingOnly); - } -} - -void FileDialogProxy::show() -{ - m_dialog->show(); -} - -void FileDialogProxy::dialogFinished() -{ - if (m_dialog->result() == QDialog::Accepted) { - emit accepted(this); - } - emit finished(this); -} - -Q_DECLARE_METATYPE(FileDialogProxy *) -typedef FileDialogProxy* FileDialogProxyPtr; -QScriptValue qScriptValueFromFileDialogProxy(QScriptEngine *engine, const FileDialogProxyPtr &fd) -{ - return engine->newQObject(const_cast(fd), QScriptEngine::AutoOwnership, - QScriptEngine::PreferExistingWrapperObject | QScriptEngine::ExcludeSuperClassContents); -} - -void fileDialogProxyFromQScriptValue(const QScriptValue &scriptValue, FileDialogProxyPtr &fd) -{ - QObject *obj = scriptValue.toQObject(); - fd = static_cast(obj); -} - -void FileDialogProxy::registerWithRuntime(QScriptEngine *engine) -{ - QScriptValue global = engine->globalObject(); - qScriptRegisterMetaType(engine, qScriptValueFromFileDialogProxy, fileDialogProxyFromQScriptValue); - global.setProperty("OpenFileDialog", engine->newFunction(FileDialogProxy::fileDialogOpen)); - global.setProperty("SaveFileDialog", engine->newFunction(FileDialogProxy::fileDialogSave)); -} - -QScriptValue FileDialogProxy::fileDialogSave(QScriptContext *context, QScriptEngine *engine) -{ - QObject *parent = 0; - if (context->argumentCount()) { - parent = context->argument(0).toQObject(); - } - - FileDialogProxy *fd = new FileDialogProxy(KFileDialog::Saving, parent); - return engine->newQObject(fd, QScriptEngine::AutoOwnership, QScriptEngine::ExcludeSuperClassContents); -} - -QScriptValue FileDialogProxy::fileDialogOpen(QScriptContext *context, QScriptEngine *engine) -{ - QObject *parent = 0; - if (context->argumentCount()) { - parent = context->argument(0).toQObject(); - } - - FileDialogProxy *fd = new FileDialogProxy(KFileDialog::Opening, parent); - return engine->newQObject(fd, QScriptEngine::AutoOwnership, QScriptEngine::ExcludeSuperClassContents); -} - -#include "filedialogproxy.moc" - diff --git a/src/scriptengines/javascript/simplebindings/filedialogproxy.h b/src/scriptengines/javascript/simplebindings/filedialogproxy.h deleted file mode 100644 index 6aa6f3dce..000000000 --- a/src/scriptengines/javascript/simplebindings/filedialogproxy.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2009 Aaron J. Seigo - * - * 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. - */ - -#ifndef FILEDIALOGPROXY_H -#define FILEDIALOGPROXY_H - -#include -#include - -#include - -class QScriptEngine; -class QScriptContext; - -class FileDialogProxy : public QObject -{ - Q_OBJECT - Q_PROPERTY(QUrl url READ selectedUrl WRITE setUrl) - Q_PROPERTY(QList urls READ selectedUrls) - Q_PROPERTY(QUrl baseUrl READ baseUrl) - Q_PROPERTY(QString file READ selectedFile) - Q_PROPERTY(QStringList files READ selectedFiles) - Q_PROPERTY(QString filter READ filter WRITE setFilter) - Q_PROPERTY(bool localOnly READ localOnly WRITE setLocalOnly) - Q_PROPERTY(bool directoriesOnly READ directoriesOnly WRITE setDirectoriesOnly) - Q_PROPERTY(bool existingOnly READ existingOnly WRITE setExistingOnly) - -public: - FileDialogProxy(KFileDialog::OperationMode mode, QObject *parent = 0); - ~FileDialogProxy(); - - QUrl selectedUrl() const; - void setUrl(const QUrl &url); - - QList selectedUrls() const; - QUrl baseUrl() const; - QString selectedFile() const; - QStringList selectedFiles() const; - - QString filter() const; - void setFilter(const QString &filter); - - bool localOnly() const; - void setLocalOnly(bool localOnly); - - bool directoriesOnly() const; - void setDirectoriesOnly(bool directoriesOnly); - - bool existingOnly() const; - void setExistingOnly(bool existingOnly); - - static void registerWithRuntime(QScriptEngine *global); - static QScriptValue fileDialogSave(QScriptContext *context, QScriptEngine *engine); - static QScriptValue fileDialogOpen(QScriptContext *context, QScriptEngine *engine); - -public Q_SLOTS: - void show(); - -Q_SIGNALS: - void accepted(FileDialogProxy *); - void finished(FileDialogProxy *); - -private Q_SLOTS: - void dialogFinished(); - -private: - KFileDialog *m_dialog; -}; - -#endif diff --git a/src/scriptengines/javascript/simplebindings/font.cpp b/src/scriptengines/javascript/simplebindings/font.cpp deleted file mode 100644 index 0184311a6..000000000 --- a/src/scriptengines/javascript/simplebindings/font.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * 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(QFont*) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() == 0) - return qScriptValueFromValue(eng, QFont()); - QString family = ctx->argument(0).toString(); - if (ctx->argumentCount() == 1) { - QFont *other = qscriptvalue_cast(ctx->argument(0)); - if (other) - return qScriptValueFromValue(eng, QFont(*other)); - return qScriptValueFromValue(eng, QFont(family)); - } - int pointSize = ctx->argument(1).toInt32(); - if (ctx->argumentCount() == 2) - return qScriptValueFromValue(eng, QFont(family, pointSize)); - int weight = ctx->argument(2).toInt32(); - if (ctx->argumentCount() == 3) - return qScriptValueFromValue(eng, QFont(family, pointSize, weight)); - bool italic = ctx->argument(3).toBoolean(); - return qScriptValueFromValue(eng, QFont(family, pointSize, weight, italic)); -} - -static QScriptValue bold(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, bold); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setBold(arg.toBoolean()); - } - - return QScriptValue(eng, self->bold()); -} - -static QScriptValue defaultFamily(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, defaultFamily); - return QScriptValue(eng, self->defaultFamily()); -} - -static QScriptValue exactMatch(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, exactMatch); - return QScriptValue(eng, self->exactMatch()); -} - -static QScriptValue family(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, family); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setFamily(arg.toString()); - } - - return QScriptValue(eng, self->family()); -} - -static QScriptValue fixedPitch(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, fixedPitch); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setFixedPitch(arg.toBoolean()); - } - - return QScriptValue(eng, self->fixedPitch()); -} - -static QScriptValue fromString(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, fromString); - return QScriptValue(eng, self->fromString(ctx->argument(0).toString())); -} - -static QScriptValue isCopyOf(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, isCopyOf); - QFont *other = qscriptvalue_cast(ctx->argument(0)); - if (!other) { - return ctx->throwError(QScriptContext::TypeError, - "QFont.prototype.isCopyOf: argument is not a Font"); - } - return QScriptValue(eng, self->isCopyOf(*other)); -} - -static QScriptValue italic(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, italic); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setItalic(arg.toBoolean()); - } - - return QScriptValue(eng, self->italic()); -} - -static QScriptValue kerning(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, kerning); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setKerning(arg.toBoolean()); - } - - return QScriptValue(eng, self->kerning()); -} - -static QScriptValue key(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, key); - return QScriptValue(eng, self->key()); -} - -static QScriptValue lastResortFamily(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, lastResortFamily); - return QScriptValue(eng, self->lastResortFamily()); -} - -static QScriptValue lastResortFont(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, lastResortFont); - return QScriptValue(eng, self->lastResortFont()); -} - -static QScriptValue overline(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, overline); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setOverline(arg.toBoolean()); - } - - return QScriptValue(eng, self->overline()); -} - -static QScriptValue pixelSize(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, pixelSize); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setPixelSize(arg.toInt32()); - } - - return QScriptValue(eng, self->pixelSize()); -} - -static QScriptValue pointSize(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, pointSize); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setPointSize(arg.toInt32()); - } - - return QScriptValue(eng, self->pointSize()); -} - -static QScriptValue pointSizeF(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, pointSizeF); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setPointSizeF(arg.toNumber()); - } - - return QScriptValue(eng, self->pointSizeF()); -} - -static QScriptValue resolve(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, resolve); - QFont *other = qscriptvalue_cast(ctx->argument(0)); - if (!other) { - return ctx->throwError(QScriptContext::TypeError, - "QFont.prototype.isCopyOf: argument is not a Font"); - } - return qScriptValueFromValue(eng, self->resolve(*other)); -} - -static QScriptValue stretch(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, stretch); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setStretch(arg.toInt32()); - } - - return QScriptValue(eng, self->stretch()); -} - -static QScriptValue strikeOut(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, strikeOut); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setStrikeOut(arg.toBoolean()); - } - - return QScriptValue(eng, self->strikeOut()); -} - -static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, toString); - return QScriptValue(eng, self->toString()); -} - -static QScriptValue underline(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, underline); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setUnderline(arg.toBoolean()); - } - - return QScriptValue(eng, self->underline()); -} - -static QScriptValue weight(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QFont, weight); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setWeight(arg.toInt32()); - } - - return QScriptValue(eng, self->weight()); -} - -QScriptValue constructFontClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QFont()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("key", eng->newFunction(key), getter); - proto.setProperty("lastResortFamily", eng->newFunction(lastResortFamily), getter); - proto.setProperty("lastResortFont", eng->newFunction(lastResortFont), getter); - proto.setProperty("defaultFamily", eng->newFunction(defaultFamily), getter); - proto.setProperty("exactMatch", eng->newFunction(exactMatch), getter); - proto.setProperty("toString", eng->newFunction(toString), getter); - - proto.setProperty("bold", eng->newFunction(bold), getter | setter); - proto.setProperty("family", eng->newFunction(family), getter|setter); - proto.setProperty("fixedPitch", eng->newFunction(fixedPitch), getter); - proto.setProperty("fromString", eng->newFunction(fromString), setter); - proto.setProperty("italic", eng->newFunction(italic), getter | setter); - proto.setProperty("kerning", eng->newFunction(kerning), getter | setter); - proto.setProperty("overline", eng->newFunction(overline), getter | setter); - proto.setProperty("pixelSize", eng->newFunction(pixelSize), getter | setter); - proto.setProperty("pointSize", eng->newFunction(pointSize), getter | setter); - proto.setProperty("pointSizeF", eng->newFunction(pointSizeF), getter | setter); - proto.setProperty("strikeOut", eng->newFunction(strikeOut), getter | setter); - proto.setProperty("stretch", eng->newFunction(stretch), getter | setter); - proto.setProperty("underline", eng->newFunction(underline), getter | setter); - proto.setProperty("weight", eng->newFunction(weight), getter | setter); - - proto.setProperty("isCopyOf", eng->newFunction(isCopyOf)); - proto.setProperty("resolve", eng->newFunction(resolve)); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/javascript/simplebindings/graphicsitem.cpp b/src/scriptengines/javascript/simplebindings/graphicsitem.cpp deleted file mode 100644 index 3f17b636b..000000000 --- a/src/scriptengines/javascript/simplebindings/graphicsitem.cpp +++ /dev/null @@ -1,412 +0,0 @@ -/* - * 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 -#include -#include "backportglobal.h" - -Q_DECLARE_METATYPE(QScript::Pointer::wrapped_pointer_type) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QPainterPath) -#ifndef QT_NO_CURSOR -Q_DECLARE_METATYPE(QCursor) -#endif -Q_DECLARE_METATYPE(QGraphicsItemGroup*) -Q_DECLARE_METATYPE(QPainter*) -Q_DECLARE_METATYPE(QStyleOptionGraphicsItem*) - -Q_DECLARE_METATYPE(QGraphicsPathItem*) -Q_DECLARE_METATYPE(QGraphicsRectItem*) -Q_DECLARE_METATYPE(QGraphicsEllipseItem*) -Q_DECLARE_METATYPE(QGraphicsPolygonItem*) -Q_DECLARE_METATYPE(QGraphicsLineItem*) -Q_DECLARE_METATYPE(QGraphicsPixmapItem*) -Q_DECLARE_METATYPE(QGraphicsTextItem*) -Q_DECLARE_METATYPE(QGraphicsSimpleTextItem*) - -DECLARE_BOOLEAN_GET_SET_METHODS(QGraphicsItem, acceptDrops, setAcceptDrops) -DECLARE_BOOLEAN_GET_SET_METHODS(QGraphicsItem, acceptsHoverEvents, setAcceptsHoverEvents) -DECLARE_GET_METHOD(QGraphicsItem, boundingRect) -DECLARE_GET_METHOD(QGraphicsItem, children) -DECLARE_GET_METHOD(QGraphicsItem, childrenBoundingRect) -#ifndef QT_NO_CURSOR -DECLARE_GET_SET_METHODS(QGraphicsItem, QCursor, cursor, setCursor) -DECLARE_BOOLEAN_GET_METHOD(QGraphicsItem, hasCursor) -#endif -DECLARE_GET_SET_METHODS(QGraphicsItem, QGraphicsItemGroup*, group, setGroup) -DECLARE_BOOLEAN_GET_SET_METHODS(QGraphicsItem, handlesChildEvents, setHandlesChildEvents) -DECLARE_BOOLEAN_GET_METHOD(QGraphicsItem, hasFocus) -DECLARE_BOOLEAN_GET_SET_METHODS(QGraphicsItem, isEnabled, setEnabled) -DECLARE_BOOLEAN_GET_SET_METHODS(QGraphicsItem, isSelected, setSelected) -DECLARE_BOOLEAN_GET_SET_METHODS(QGraphicsItem, isVisible, setVisible) -DECLARE_GET_METHOD(QGraphicsItem, opaqueArea) -DECLARE_GET_METHOD(QGraphicsItem, pos) -DECLARE_QOBJECT_GET_METHOD(QGraphicsItem, scene) -DECLARE_GET_METHOD(QGraphicsItem, sceneBoundingRect) -DECLARE_GET_METHOD(QGraphicsItem, scenePos) -DECLARE_GET_METHOD(QGraphicsItem, sceneTransform) -DECLARE_GET_METHOD(QGraphicsItem, shape) -#ifndef QT_NO_TOOLTIP -DECLARE_STRING_GET_SET_METHODS(QGraphicsItem, toolTip, setToolTip) -#endif -DECLARE_GET_METHOD(QGraphicsItem, topLevelItem) -DECLARE_GET_SET_METHODS(QGraphicsItem, QTransform, transform, setTransform) -DECLARE_NUMBER_GET_METHOD(QGraphicsItem, type) -DECLARE_NUMBER_GET_METHOD(QGraphicsItem, x) -DECLARE_NUMBER_GET_METHOD(QGraphicsItem, y) -DECLARE_NUMBER_GET_SET_METHODS(QGraphicsItem, zValue, setZValue) - -DECLARE_BOOLEAN_1ARG_METHOD(QGraphicsItem, QPointF, contains) -DECLARE_VOID_METHOD(QGraphicsItem, clearFocus) -DECLARE_VOID_METHOD(QGraphicsItem, hide) -DECLARE_BOOLEAN_1ARG_METHOD(QGraphicsItem, QGraphicsItem*, isAncestorOf) -DECLARE_BOOLEAN_1ARG_METHOD(QGraphicsItem, QGraphicsItem*, isObscuredBy) -DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsItem, moveBy) -DECLARE_VOID_METHOD(QGraphicsItem, resetTransform) -#ifndef QT_NO_CURSOR -DECLARE_VOID_METHOD(QGraphicsItem, unsetCursor) -#endif -DECLARE_VOID_METHOD(QGraphicsItem, show) -DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsItem, translate) -DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsItem, scale) -DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsItem, shear) -DECLARE_VOID_1ARG_METHOD(QGraphicsItem, QGraphicsItem*, installSceneEventFilter) -DECLARE_VOID_1ARG_METHOD(QGraphicsItem, QGraphicsItem*, removeSceneEventFilter) -DECLARE_VOID_NUMBER_METHOD(QGraphicsItem, rotate) - -///////////////////////////////////////////////////////////// - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *) -{ - return ctx->throwError("QGraphicsItem cannot be instantiated"); -} - -BEGIN_DECLARE_METHOD(QGraphicsItem, acceptedMouseButtons) { - return QScriptValue(eng, static_cast(self->acceptedMouseButtons())); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, advance) { - self->advance(ctx->argument(0).toInt32()); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, collidesWithItem) { - QGraphicsItem *other = qscriptvalue_cast(ctx->argument(0)); - if (!other) { - return ctx->throwError(QScriptContext::TypeError, - "QGraphicsItem.prototype.collidesWithItem: argument is not a GraphicsItem"); - } - if (ctx->argument(1).isUndefined()) - return QScriptValue(eng, self->collidesWithItem(other)); - else - return QScriptValue(eng, self->collidesWithItem(other, static_cast(ctx->argument(1).toInt32()))); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, collidesWithPath) { - QPainterPath path = qscriptvalue_cast(ctx->argument(0)); - if (ctx->argument(1).isUndefined()) - return QScriptValue(eng, self->collidesWithPath(path)); - else - return QScriptValue(eng, self->collidesWithPath(path, static_cast(ctx->argument(1).toInt32()))); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, collidingItems) { - if (ctx->argument(0).isUndefined()) - return qScriptValueFromValue(eng, self->collidingItems()); - else - return qScriptValueFromValue(eng, self->collidingItems(static_cast(ctx->argument(0).toInt32()))); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, data) { - return eng->newVariant(self->data(ctx->argument(0).toInt32())); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, ensureVisible) { - Q_UNUSED(eng); - return ctx->throwError("QGraphicsItem.prototype.ensureVisible is not implemented"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, flags) { - return QScriptValue(eng, static_cast(self->flags())); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, isObscured) { - if (ctx->argumentCount() == 0) { - return QScriptValue(eng, self->isObscured()); - } else if (ctx->argumentCount() > 1) { - return QScriptValue(eng, self->isObscured(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32())); - } else { - return QScriptValue(eng, self->isObscured(qscriptvalue_cast(ctx->argument(0)))); - } -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, mapFromItem) { - Q_UNUSED(eng); - return ctx->throwError("QGraphicsItem.prototype.mapFromItem is not implemented"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, mapFromParent) { - Q_UNUSED(eng); - return ctx->throwError("QGraphicsItem.prototype.mapFromParent is not implemented"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, mapFromScene) { - Q_UNUSED(eng); - return ctx->throwError("QGraphicsItem.prototype.mapFromScene is not implemented"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, mapToItem) { - Q_UNUSED(eng); - return ctx->throwError("QGraphicsItem.prototype.mapToItem is not implemented"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, mapToParent) { - Q_UNUSED(eng); - return ctx->throwError("QGraphicsItem.prototype.mapToParent is not implemented"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, mapToScene) { - Q_UNUSED(eng); - return ctx->throwError("QGraphicsItem.prototype.mapToScene is not implemented"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, paint) { - self->paint(qscriptvalue_cast(ctx->argument(0)), - qscriptvalue_cast(ctx->argument(1)), - qscriptvalue_cast(ctx->argument(2))); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, parentItem) { - QGraphicsItem *parent = self->parentItem(); - if (!parent) - return eng->nullValue(); - QScriptValue ret = qScriptValueFromValue(eng, parent); - QScriptValue proto; - switch (parent->type()) { - case 2: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 3: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 4: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 5: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 6: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 7: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 8: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 9: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - case 10: - proto = eng->defaultPrototype(qMetaTypeId()); - break; - } - if (proto.isValid()) - ret.setPrototype(proto); - return ret; -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, setAcceptedMouseButtons) { - self->setAcceptedMouseButtons(static_cast(ctx->argument(0).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, setData) { - self->setData(ctx->argument(0).toInt32(), ctx->argument(1).toVariant()); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, setFlag) { - QGraphicsItem::GraphicsItemFlag flag = static_cast(ctx->argument(0).toInt32()); - if (ctx->argument(1).isUndefined()) - self->setFlag(flag); - else - self->setFlag(flag, ctx->argument(1).toBoolean()); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, setFlags) { - self->setFlags(static_cast(ctx->argument(0).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, setFocus) { - if (ctx->argument(0).isUndefined()) - self->setFocus(); - else - self->setFocus(static_cast(ctx->argument(0).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, setParentItem) { - QScriptValue arg = ctx->argument(0); - QGraphicsItem *item = qscriptvalue_cast(arg); - self->setParentItem(item); - if (item) - QScript::maybeReleaseOwnership(ctx->thisObject()); - else if (!self->scene()) - QScript::maybeTakeOwnership(ctx->thisObject()); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, setPos) { - if (ctx->argumentCount() > 1) - self->setPos(ctx->argument(0).toNumber(), ctx->argument(1).toNumber()); - else - self->setPos(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, update) { - if (ctx->argumentCount() > 1) { - self->update(ctx->argument(0).toNumber(), - ctx->argument(1).toNumber(), - ctx->argument(2).toNumber(), - ctx->argument(3).toNumber()); - } else { - self->update(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, toString) { - return QScriptValue(eng, "QGraphicsItem"); -} END_DECLARE_METHOD - -///////////////////////////////////////////////////////////// - -class PrototypeGraphicsItem : public QGraphicsItem -{ -public: - PrototypeGraphicsItem() - { } - QRectF boundingRect() const - { return QRectF(); } - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) - { } -}; - -QScriptValue constructGraphicsItemClass(QScriptEngine *eng) -{ - QScriptValue proto = QScript::wrapGVPointer(eng, new PrototypeGraphicsItem()); - ADD_GET_SET_METHODS(proto, acceptDrops, setAcceptDrops); - ADD_GET_SET_METHODS(proto, acceptsHoverEvents, setAcceptsHoverEvents); - ADD_GET_METHOD(proto, boundingRect); - ADD_GET_METHOD(proto, children); - ADD_GET_METHOD(proto, childrenBoundingRect); -#ifndef QT_NO_CURSOR - ADD_GET_SET_METHODS(proto, cursor, setCursor); - ADD_GET_METHOD(proto, hasCursor); -#endif - ADD_GET_SET_METHODS(proto, group, setGroup); - ADD_GET_SET_METHODS(proto, handlesChildEvents, setHandlesChildEvents); - ADD_GET_METHOD(proto, hasFocus); - ADD_GET_SET_METHODS(proto, isEnabled, setEnabled); - ADD_GET_SET_METHODS(proto, isSelected, setSelected); - ADD_GET_SET_METHODS(proto, isVisible, setVisible); - ADD_GET_METHOD(proto, opaqueArea); - ADD_GET_METHOD(proto, pos); - ADD_GET_METHOD(proto, scene); - ADD_GET_METHOD(proto, sceneBoundingRect); - ADD_GET_METHOD(proto, scenePos); - ADD_GET_METHOD(proto, sceneTransform); - ADD_GET_METHOD(proto, shape); -#ifndef QT_NO_TOOLTIP - ADD_GET_SET_METHODS(proto, toolTip, setToolTip); -#endif - ADD_GET_METHOD(proto, topLevelItem); - ADD_GET_SET_METHODS(proto, transform, setTransform); - ADD_GET_METHOD(proto, type); - ADD_GET_METHOD(proto, x); - ADD_GET_METHOD(proto, y); - ADD_GET_SET_METHODS(proto, zValue, setZValue); - - ADD_METHOD(proto, acceptedMouseButtons); - ADD_METHOD(proto, advance); - ADD_METHOD(proto, clearFocus); - ADD_METHOD(proto, collidesWithItem); - ADD_METHOD(proto, collidesWithPath); - ADD_METHOD(proto, collidingItems); - ADD_METHOD(proto, contains); - ADD_METHOD(proto, data); - ADD_METHOD(proto, ensureVisible); - ADD_METHOD(proto, flags); - ADD_METHOD(proto, hide); - ADD_METHOD(proto, installSceneEventFilter); - ADD_METHOD(proto, isAncestorOf); - ADD_METHOD(proto, isObscured); - ADD_METHOD(proto, isObscuredBy); - ADD_METHOD(proto, mapFromItem); - ADD_METHOD(proto, mapFromParent); - ADD_METHOD(proto, mapFromScene); - ADD_METHOD(proto, mapToItem); - ADD_METHOD(proto, mapToParent); - ADD_METHOD(proto, mapToScene); - ADD_METHOD(proto, moveBy); - ADD_METHOD(proto, paint); - ADD_METHOD(proto, parentItem); - ADD_METHOD(proto, removeSceneEventFilter); - ADD_METHOD(proto, resetTransform); - ADD_METHOD(proto, rotate); - ADD_METHOD(proto, scale); - ADD_METHOD(proto, setAcceptedMouseButtons); - ADD_METHOD(proto, setData); - ADD_METHOD(proto, setFlag); - ADD_METHOD(proto, setFlags); - ADD_METHOD(proto, setFocus); - ADD_METHOD(proto, setParentItem); - ADD_METHOD(proto, setPos); - ADD_METHOD(proto, shear); - ADD_METHOD(proto, show); - ADD_METHOD(proto, toString); - ADD_METHOD(proto, translate); -#ifndef QT_NO_CURSOR - ADD_METHOD(proto, unsetCursor); -#endif - ADD_METHOD(proto, update); - - QScript::registerPointerMetaType(eng, proto); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemIsMovable); - ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemIsSelectable); - ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemIsFocusable); - ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemClipsToShape); - ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemClipsChildrenToShape); - ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemIgnoresTransformations); - - return ctorFun; -} diff --git a/src/scriptengines/javascript/simplebindings/gridlayout.cpp b/src/scriptengines/javascript/simplebindings/gridlayout.cpp deleted file mode 100644 index 44165463b..000000000 --- a/src/scriptengines/javascript/simplebindings/gridlayout.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * 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 -#include - -#include - -#include "backportglobal.h" - -#define DECLARE_INT_NUMBER_GET_METHOD(Class, __get__) \ -BEGIN_DECLARE_METHOD(Class, __get__) { \ - return QScriptValue(eng, self->__get__(ctx->argument(0).toInt32())); \ -} END_DECLARE_METHOD - -#define DECLARE_INT_NUMBER_SET_METHOD(Class, __set__) \ -BEGIN_DECLARE_METHOD(Class, __set__) { \ - self->__set__(ctx->argument(0).toInt32(), ctx->argument(1).toNumber()); \ - return eng->undefinedValue(); \ -} END_DECLARE_METHOD - -#define DECLARE_INT_NUMBER_GET_SET_METHODS(Class, __get__, __set__) \ - DECLARE_INT_NUMBER_GET_METHOD(Class, __get__) \ - DECLARE_INT_NUMBER_SET_METHOD(Class, __set__) - -Q_DECLARE_METATYPE(QScript::Pointer::wrapped_pointer_type) -Q_DECLARE_METATYPE(QGraphicsWidget*) -Q_DECLARE_METATYPE(QGraphicsLayout*) -Q_DECLARE_METATYPE(QGraphicsLayoutItem*) -DECLARE_POINTER_METATYPE(QGraphicsGridLayout) - -DECLARE_VOID_NUMBER_METHOD(QGraphicsGridLayout, removeAt) -DECLARE_VOID_NUMBER_METHOD(QGraphicsGridLayout, setSpacing) -DECLARE_VOID_QUAD_NUMBER_METHOD(QGraphicsGridLayout, setContentsMargins) - -DECLARE_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, horizontalSpacing, setHorizontalSpacing) -DECLARE_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, verticalSpacing, setVerticalSpacing) - -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, rowSpacing, setRowSpacing) -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, columnSpacing, setColumnSpacing) - -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, rowMinimumHeight, setRowMinimumHeight) -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, rowPreferredHeight, setRowPreferredHeight) -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, rowMaximumHeight, setRowMaximumHeight) -DECLARE_INT_NUMBER_SET_METHOD(QGraphicsGridLayout, setRowFixedHeight) - -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, columnMinimumWidth, setColumnMinimumWidth) -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, columnPreferredWidth, setColumnPreferredWidth) -DECLARE_INT_NUMBER_GET_SET_METHODS(QGraphicsGridLayout, columnMaximumWidth, setColumnMaximumWidth) -DECLARE_INT_NUMBER_SET_METHOD(QGraphicsGridLayout, setColumnFixedWidth) - - -///////////////////////////////////////////////////////////// - -QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0, bool noExistingLayout = false); - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - QGraphicsLayoutItem *parent = extractLayoutItem(ctx, 0, true); - //FIXME: don't leak memory when parent is 0 - return qScriptValueFromValue(eng, new QGraphicsGridLayout(parent)); -} - -BEGIN_DECLARE_METHOD(QGraphicsGridLayout, setAlignment) { - QGraphicsLayoutItem *item = extractLayoutItem(ctx); - - if (!item) { - return eng->undefinedValue(); - } - - self->setAlignment(item, static_cast(ctx->argument(1).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsGridLayout, addItem) { - QGraphicsLayoutItem *item = extractLayoutItem(ctx); - - if (!item) { - return eng->undefinedValue(); - } - - int rowSpan = 1; - int colSpan = 1; - Qt::Alignment alignment = 0; - const int argCount = ctx->argumentCount(); - if (argCount > 3) { - rowSpan = ctx->argument(3).toInt32(); - if (argCount > 4) { - colSpan = ctx->argument(4).toInt32(); - - if (argCount > 5) { - alignment = static_cast(ctx->argument(5).toInt32()); - } - } - } - - self->addItem(item, ctx->argument(1).toInt32(), ctx->argument(2).toInt32(), - rowSpan, colSpan, alignment); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsGridLayout, toString) { - return QScriptValue(eng, "QGraphicsGridLayout"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsGridLayout, activate) { - self->activate(); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -///////////////////////////////////////////////////////////// - -class PrototypeGridLayout : public QGraphicsGridLayout -{ -public: - PrototypeGridLayout() - { } -}; - -QScriptValue constructGridLayoutClass(QScriptEngine *eng) -{ - QScriptValue proto = QScript::wrapPointer(eng, new QGraphicsGridLayout(), QScript::UserOwnership); - const QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - const QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - proto.setProperty("horizontalSpacing", eng->newFunction(horizontalSpacing), getter); - proto.setProperty("horizontalSpacing", eng->newFunction(setHorizontalSpacing), setter); - proto.setProperty("verticalSpacing", eng->newFunction(verticalSpacing), getter); - proto.setProperty("verticalSpacing", eng->newFunction(setVerticalSpacing), setter); - - ADD_METHOD(proto, rowSpacing); - ADD_METHOD(proto, setRowSpacing); - ADD_METHOD(proto, columnSpacing); - ADD_METHOD(proto, setColumnSpacing); - - ADD_METHOD(proto, rowMinimumHeight); - ADD_METHOD(proto, setRowMinimumHeight); - ADD_METHOD(proto, rowPreferredHeight); - ADD_METHOD(proto, setRowPreferredHeight); - ADD_METHOD(proto, rowMaximumHeight); - ADD_METHOD(proto, setRowMaximumHeight); - ADD_METHOD(proto, setRowFixedHeight); - - ADD_METHOD(proto, columnMinimumWidth); - ADD_METHOD(proto, setColumnMinimumWidth); - ADD_METHOD(proto, columnPreferredWidth); - ADD_METHOD(proto, setColumnPreferredWidth); - ADD_METHOD(proto, columnMaximumWidth); - ADD_METHOD(proto, setColumnMaximumWidth); - ADD_METHOD(proto, setColumnFixedWidth); - - ADD_METHOD(proto, removeAt); - ADD_METHOD(proto, setAlignment); - ADD_METHOD(proto, setSpacing); - ADD_METHOD(proto, setContentsMargins); - ADD_METHOD(proto, addItem); - ADD_METHOD(proto, toString); - ADD_METHOD(proto, activate); - - QScript::registerPointerMetaType(eng, proto); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - return ctorFun; -} diff --git a/src/scriptengines/javascript/simplebindings/i18n.cpp b/src/scriptengines/javascript/simplebindings/i18n.cpp deleted file mode 100644 index 6ef8c568b..000000000 --- a/src/scriptengines/javascript/simplebindings/i18n.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2009 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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 "i18n.h" - -#include -#include - -#include -#include - -QScriptValue jsi18n(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - - if (context->argumentCount() < 1) { - // qDebug() << i18n("i18n() takes at least one argument"); - return engine->undefinedValue(); - } - - KLocalizedString message = ki18n(context->argument(0).toString().toUtf8()); - - const int numArgs = context->argumentCount(); - for (int i = 1; i < numArgs; ++i) { - message = message.subs(context->argument(i).toString()); - } - - return message.toString(); -} - -QScriptValue jsi18nc(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - - if (context->argumentCount() < 2) { - // qDebug() << i18n("i18nc() takes at least two arguments"); - return engine->undefinedValue(); - } - - KLocalizedString message = ki18nc(context->argument(0).toString().toUtf8(), - context->argument(1).toString().toUtf8()); - - const int numArgs = context->argumentCount(); - for (int i = 2; i < numArgs; ++i) { - message = message.subs(context->argument(i).toString()); - } - - return message.toString(); -} - -QScriptValue jsi18np(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - - if (context->argumentCount() < 2) { - // qDebug() << i18n("i18np() takes at least two arguments"); - return engine->undefinedValue(); - } - - KLocalizedString message = ki18np(context->argument(0).toString().toUtf8(), - context->argument(1).toString().toUtf8()); - - const int numArgs = context->argumentCount(); - for (int i = 2; i < numArgs; ++i) { - QScriptValue v = context->argument(i); - if (v.isNumber()) { - message = message.subs(v.toInt32()); - } else { - message = message.subs(v.toString()); - } - } - - return message.toString(); -} - -QScriptValue jsi18ncp(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(engine) - - if (context->argumentCount() < 3) { - // qDebug() << i18n("i18ncp() takes at least three arguments"); - return engine->undefinedValue(); - } - - KLocalizedString message = ki18ncp(context->argument(0).toString().toUtf8(), - context->argument(1).toString().toUtf8(), - context->argument(2).toString().toUtf8()); - - const int numArgs = context->argumentCount(); - for (int i = 3; i < numArgs; ++i) { - message = message.subs(context->argument(i).toString()); - } - - return message.toString(); -} - -void bindI18N(QScriptEngine *engine) -{ - QScriptValue global = engine->globalObject(); - global.setProperty("i18n", engine->newFunction(jsi18n)); - global.setProperty("i18nc", engine->newFunction(jsi18nc)); - global.setProperty("i18np", engine->newFunction(jsi18np)); - global.setProperty("i18ncp", engine->newFunction(jsi18ncp)); -} - diff --git a/src/scriptengines/javascript/simplebindings/i18n.h b/src/scriptengines/javascript/simplebindings/i18n.h deleted file mode 100644 index 5644a0dff..000000000 --- a/src/scriptengines/javascript/simplebindings/i18n.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2009 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 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. - */ - -#ifndef JAVASCRIPTBINDI18N_H -#define JAVASCRIPTBINDI18N_H - -#include - -class QScriptContext; -class QScriptEngine; - -QScriptValue jsi18n(QScriptContext *context, QScriptEngine *engine); -QScriptValue jsi18nc(QScriptContext *context, QScriptEngine *engine); -QScriptValue jsi18np(QScriptContext *context, QScriptEngine *engine); -QScriptValue jsi18ncp(QScriptContext *context, QScriptEngine *engine); -void bindI18N(QScriptEngine *engine); - -#endif - diff --git a/src/scriptengines/javascript/simplebindings/icon.cpp b/src/scriptengines/javascript/simplebindings/icon.cpp deleted file mode 100644 index 62055a571..000000000 --- a/src/scriptengines/javascript/simplebindings/icon.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2009 Aaron J. Seigo - * - * 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(QIcon) -Q_DECLARE_METATYPE(QIcon*) -Q_DECLARE_METATYPE(KIcon) -Q_DECLARE_METATYPE(KIcon*) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() > 0) { - QScriptValue v = ctx->argument(0); - if (v.isString()) { - QIcon icon = KIcon(v.toString()); - return qScriptValueFromValue(eng, icon); - } else if (v.isVariant()) { - QVariant variant = v.toVariant(); - QPixmap p = variant.value(); - if (!p.isNull()) { - return qScriptValueFromValue(eng, QIcon(p)); - } - } - } - return qScriptValueFromValue(eng, QIcon()); -} - -static QScriptValue addPixmap(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QIcon, addPixmap); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - - if (arg.isVariant()) { - QVariant variant = arg.toVariant(); - QPixmap p = variant.value(); - if (!p.isNull()) { - self->addPixmap(p); - } - } - } - - return eng->undefinedValue(); -} - -static QScriptValue addFile(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QIcon, addFile); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - - if (arg.isString()) { - self->addFile(arg.toString()); - } - } - - return eng->undefinedValue(); -} - -static QScriptValue isNull(QScriptContext *ctx, QScriptEngine *eng) -{ - Q_UNUSED(eng) - DECLARE_SELF(QIcon, isNull); - return self->isNull(); -} - -QScriptValue constructIconClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QIcon()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - proto.setProperty("addPixmap", eng->newFunction(addPixmap)); - proto.setProperty("addFile", eng->newFunction(addFile)); - proto.setProperty("null", eng->newFunction(isNull), getter); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - ADD_ENUM_VALUE(ctorFun, QIcon, Normal); - ADD_ENUM_VALUE(ctorFun, QIcon, Disabled); - ADD_ENUM_VALUE(ctorFun, QIcon, Active); - ADD_ENUM_VALUE(ctorFun, QIcon, Selected); - ADD_ENUM_VALUE(ctorFun, QIcon, Off); - ADD_ENUM_VALUE(ctorFun, QIcon, On); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return ctorFun; -} - diff --git a/src/scriptengines/javascript/simplebindings/linearlayout.cpp b/src/scriptengines/javascript/simplebindings/linearlayout.cpp deleted file mode 100644 index 88a79b892..000000000 --- a/src/scriptengines/javascript/simplebindings/linearlayout.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include - -#include "backportglobal.h" -#include "plasmoid/appletinterface.h" - -Q_DECLARE_METATYPE(QScript::Pointer::wrapped_pointer_type) -Q_DECLARE_METATYPE(QGraphicsWidget*) -Q_DECLARE_METATYPE(QGraphicsLayout*) -Q_DECLARE_METATYPE(QGraphicsLayoutItem*) -Q_DECLARE_METATYPE(QGraphicsAnchorLayout*) -Q_DECLARE_METATYPE(QGraphicsGridLayout*) -DECLARE_POINTER_METATYPE(QGraphicsLinearLayout) - -DECLARE_VOID_NUMBER_METHOD(QGraphicsLinearLayout, removeAt) -DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsLinearLayout, insertStretch) -DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsLinearLayout, setItemSpacing) -DECLARE_VOID_QUAD_NUMBER_METHOD(QGraphicsLinearLayout, setContentsMargins) - -///////////////////////////////////////////////////////////// - -// Q_DECLARE_METATYPE(QGraphicsLayoutItem*) -QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0, bool noExistingLayout = false) -{ - QScriptValue v = ctx->argument(index); - if (ctx->argumentCount() == 0 || v.isQObject()) { - QObject *object = v.toQObject(); - QGraphicsWidget *w = qobject_cast(object); - if (!w) { - AppletInterface *interface = qobject_cast(object); - if (!interface) { - interface = qobject_cast(ctx->engine()->globalObject().property("plasmoid").toQObject()); - } - - if (interface) { - w = interface->applet(); - } - } - - if (noExistingLayout && w->layout()) { - return 0; - } - - return w; - } - - QVariant variant = v.toVariant(); - QGraphicsLayoutItem *item = variant.value(); - //this is horribly ugly code, but when a QLinearLayout* is stuffed into a QVariant, - //QVariant does not know that it is a QGraphicsLayoutItem. repeat for all subclasses - //of same - if (!item) { - item = variant.value(); - - if (!item) { - item = variant.value(); - - if (!item) { - item = variant.value(); - - if (!item) { - item = variant.value(); - } - } - } - } - - QGraphicsWidget *w = dynamic_cast(item); - if (noExistingLayout && w && w->layout()) { - return 0; - } - - return item; -} - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - QGraphicsLayoutItem *parent = extractLayoutItem(ctx, 0, true); - //FIXME: don't leak memory when parent is 0 - return qScriptValueFromValue(eng, new QGraphicsLinearLayout(parent)); -} - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, orientation) { - if (ctx->argumentCount() > 0) { - self->setOrientation(static_cast(ctx->argument(0).toInt32())); - } - - return QScriptValue(eng, static_cast(self->orientation())); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, setAlignment) { - QGraphicsLayoutItem *item = extractLayoutItem(ctx); - - if (!item) { - return eng->undefinedValue(); - } - - self->setAlignment(item, static_cast(ctx->argument(1).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, insertItem) { - QGraphicsLayoutItem *item = extractLayoutItem(ctx, 1); - - if (!item) { - return eng->undefinedValue(); - } - - self->insertItem(ctx->argument(0).toInt32(), item); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, removeItem) { - QGraphicsLayoutItem *item = extractLayoutItem(ctx); - - if (!item) { - return eng->undefinedValue(); - } - - self->removeItem(item); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, addStretch) { - self->addStretch(qMax(1, ctx->argument(0).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, setStretchFactor) { - QGraphicsLayoutItem *item = ctx->argument(0).toVariant().value(); - - if (!item) { - return eng->undefinedValue(); - } - - self->setStretchFactor(item, static_cast(ctx->argument(1).toInt32())); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, addItem) { - QGraphicsLayoutItem *item = extractLayoutItem(ctx); - if (!item) { - return ctx->throwError(QScriptContext::TypeError, - "QGraphicsLinearLayout.prototype.addItem: argument is not a GraphicsLayoutItem"); - } - - self->addItem(item); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsItem, toString) { - return QScriptValue(eng, "QGraphicsLinearLayout"); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, count) { - return QScriptValue(eng, self->count()); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, itemAt) { - if (ctx->argumentCount() < 1) { - return eng->undefinedValue(); - } - - int index = ctx->argument(0).toInt32(); - return qScriptValueFromValue(eng, self->itemAt(index)); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, spacing) { - if (ctx->argumentCount() > 0) { - int pixels = ctx->argument(0).toInt32(); - self->setSpacing(pixels); - } - - return QScriptValue(eng, self->spacing()); -} END_DECLARE_METHOD - -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, activate) { - self->activate(); - return eng->undefinedValue(); -} END_DECLARE_METHOD - -///////////////////////////////////////////////////////////// - -QScriptValue constructLinearLayoutClass(QScriptEngine *eng) -{ -// QScriptValue proto = QScript::wrapGVPointer(eng, new QGraphicsLinearLayout(), ); - qRegisterMetaType(); - QGraphicsLayoutItem * i = new QGraphicsLinearLayout; - QVariant v; - ///v.setValue(i); - v.setValue(i); - QScriptValue proto = QScript::wrapPointer(eng, new QGraphicsLinearLayout(), QScript::UserOwnership); - const QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - const QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - proto.setProperty("count", eng->newFunction(count), getter); - proto.setProperty("spacing", eng->newFunction(spacing), getter | setter); - proto.setProperty("orientation", eng->newFunction(orientation), getter | setter); - ADD_METHOD(proto, itemAt); - ADD_METHOD(proto, removeAt); - ADD_METHOD(proto, addStretch); - ADD_METHOD(proto, setStretchFactor); - ADD_METHOD(proto, setAlignment); - ADD_METHOD(proto, insertStretch); - ADD_METHOD(proto, setItemSpacing); - ADD_METHOD(proto, setContentsMargins); - ADD_METHOD(proto, addItem); - ADD_METHOD(proto, removeItem); - ADD_METHOD(proto, insertItem); - ADD_METHOD(proto, toString); - ADD_METHOD(proto, activate); - - QScript::registerPointerMetaType(eng, proto); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - //ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemIsMovable); - - return ctorFun; -} diff --git a/src/scriptengines/javascript/simplebindings/painter.cpp b/src/scriptengines/javascript/simplebindings/painter.cpp deleted file mode 100644 index 66233bda2..000000000 --- a/src/scriptengines/javascript/simplebindings/painter.cpp +++ /dev/null @@ -1,1158 +0,0 @@ -/* - * 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 -#include -#include - -#include - -#include "backportglobal.h" - -Q_DECLARE_METATYPE(QPolygonF) -Q_DECLARE_METATYPE(QPainterPath) -Q_DECLARE_METATYPE(QPainterPath*) -Q_DECLARE_METATYPE(QPicture) -Q_DECLARE_METATYPE(QVector) -Q_DECLARE_METATYPE(QPaintDevice*) -Q_DECLARE_METATYPE(QPaintEngine*) - -DECLARE_POINTER_METATYPE(QPainter) - -static QScriptValue newPainter(QScriptEngine *eng, QPainter *p) -{ - return QScript::wrapPointer(eng, p); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() > 0) { - QPaintDevice *device = qscriptvalue_cast(ctx->argument(0)); - if (!device) { - QPixmap *pixmap = qscriptvalue_cast(ctx->argument(0)); - if (pixmap) { - return newPainter(eng, new QPainter(pixmap)); - } else { - return newPainter(eng, new QPainter()); - } - } - return newPainter(eng, new QPainter(device)); - } else { - return newPainter(eng, new QPainter()); - } -} - -///////////////////////////////////////////////////////////// - -static QScriptValue background(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, background); - return qScriptValueFromValue(eng, self->background()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue backgroundMode(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, backgroundMode); - return QScriptValue(eng, static_cast(self->backgroundMode())); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue begin(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, begin); - QWidget *device = qscriptvalue_cast(ctx->argument(0)); - if (!device) { - return ctx->throwError(QScriptContext::TypeError, - "QPainter.prototype.begin: argument is not a QWidget"); - } - return QScriptValue(eng, self->begin(device)); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue boundingRect(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, boundingRect); - QRect result; - if (ctx->argumentCount() == 3) { - result = self->boundingRect(qscriptvalue_cast(ctx->argument(0)), - ctx->argument(1).toInt32(), - ctx->argument(2).toString()); - } else if (ctx->argumentCount() == 6) { - result = self->boundingRect(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32(), - ctx->argument(4).toInt32(), - ctx->argument(5).toString()); - } - return qScriptValueFromValue(eng, result); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue brush(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, brush); - return qScriptValueFromValue(eng, self->brush()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue brushOrigin(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, brushOrigin); - return qScriptValueFromValue(eng, self->brushOrigin()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue clipPath(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, clipPath); - return qScriptValueFromValue(eng, self->clipPath()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue clipRegion(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, clipRegion); - return qScriptValueFromValue(eng, self->clipRegion()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue combinedMatrix(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, combinedMatrix); - return qScriptValueFromValue(eng, self->combinedMatrix()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue combinedTransform(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, combinedTransform); - return qScriptValueFromValue(eng, self->combinedTransform()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue compositionMode(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, compositionMode); - return QScriptValue(eng, static_cast(self->compositionMode())); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawArc(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawArc); - if (ctx->argumentCount() == 6) { - // drawArc(x, y, height, width, startAngle, spanAngle) - self->drawArc(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32(), - ctx->argument(4).toInt32(), - ctx->argument(5).toInt32()); - } else if (ctx->argumentCount() == 3) { - // drawArc(rectangle, startAngle, spanAngle) - self->drawArc(qscriptvalue_cast(ctx->argument(0)), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32()); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawChord(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawChord); - if (ctx->argumentCount() == 6) { - // x, y, height, width, startAngle, spanAngle - self->drawChord(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32(), - ctx->argument(4).toInt32(), - ctx->argument(5).toInt32()); - } else if (ctx->argumentCount() == 3) { - // rectangle, startAngle, spanAngle - self->drawChord(qscriptvalue_cast(ctx->argument(0)), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32()); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawConvexPolygon(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawConvexPolygon); - self->drawConvexPolygon(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawEllipse(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawEllipse); - if (ctx->argumentCount() == 4) { - // drawEllipse(x, y, width, height) - self->drawEllipse(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else if (ctx->argumentCount() == 1) { - // drawEllipse(rect) - self->drawEllipse(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawImage(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawImage); - if (ctx->argumentCount() == 2) { - // target, image - QScriptValue arg0 = ctx->argument(0); - QImage image = qscriptvalue_cast(ctx->argument(1)); - if (arg0.property("width").isValid()) { - self->drawImage(qscriptvalue_cast(arg0), image); - } else { - self->drawImage(qscriptvalue_cast(arg0), image); - } - } else if (ctx->argumentCount() == 3) { - // x, y, image - self->drawImage(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - qscriptvalue_cast(ctx->argument(2))); - } else if (ctx->argumentCount() == 5) { - // x, y, width, height, image - self->drawImage(QRect(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()), - qscriptvalue_cast(ctx->argument(4))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawLine(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawLine); - if (ctx->argumentCount() == 4) { - // x1, y1, x2, y2 - self->drawLine(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else if (ctx->argumentCount() == 2) { - // p1, p2 - self->drawLine(qscriptvalue_cast(ctx->argument(0)), - qscriptvalue_cast(ctx->argument(1))); - } else if (ctx->argumentCount() == 1) { - // line - self->drawLine(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawLines(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawLines); - return ctx->throwError("QPainter.prototype.drawLines is not implemented"); -// self->drawLines(qscriptvalue_cast >(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPath(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPath); - self->drawPath(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPicture(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPicture); - if (ctx->argumentCount() == 2) { - self->drawPicture(qscriptvalue_cast(ctx->argument(0)), - qscriptvalue_cast(ctx->argument(1))); - } else if (ctx->argumentCount() == 3) { - self->drawPicture(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - qscriptvalue_cast(ctx->argument(2))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPie(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPie); - if (ctx->argumentCount() == 6) { - // x, y, height, width, startAngle, spanAngle - self->drawPie(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32(), - ctx->argument(4).toInt32(), - ctx->argument(5).toInt32()); - } else if (ctx->argumentCount() == 3) { - // rectangle, startAngle, spanAngle - self->drawPie(qscriptvalue_cast(ctx->argument(0)), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32()); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPixmap(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPixmap); - if (ctx->argumentCount() == 2) { - // target, pixmap - QScriptValue arg0 = ctx->argument(0); - QPixmap pixmap = qscriptvalue_cast(ctx->argument(1)); - if (arg0.property("width").isValid()) { - self->drawPixmap(qscriptvalue_cast(arg0), pixmap, - QRectF(0, 0, pixmap.width(), pixmap.height())); - } else { - self->drawPixmap(qscriptvalue_cast(arg0), pixmap); - } - } else if (ctx->argumentCount() == 3) { - // x, y, pixmap - self->drawPixmap(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - qscriptvalue_cast(ctx->argument(2))); - } else if (ctx->argumentCount() == 5) { - // x, y, width, height, pixmap - self->drawPixmap(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32(), - qscriptvalue_cast(ctx->argument(4))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPoint(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPoint); - if (ctx->argumentCount() == 2) { - // drawPoint(x, y) - self->drawPoint(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32()); - } else if (ctx->argumentCount() == 1) { - // drawPoint(point) - self->drawPoint(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPoints(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPoints); - self->drawPoints(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPolygon(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPolygon); - // ### fillRule (2nd argument) - self->drawPolygon(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawPolyline(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawPolyline); - self->drawPolyline(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawRect(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawRect); - if (ctx->argumentCount() == 4) { - // x, y, width, height - self->drawRect(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else if (ctx->argumentCount() == 1) { - // rect - self->drawRect(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawRects(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawRects); - self->drawRects(qscriptvalue_cast >(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawRoundRect(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawRoundRect); - // ### xRnd, yRnd - if (ctx->argumentCount() >= 4) { - self->drawRoundRect(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else { - self->drawRoundRect(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawText(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawText); - if (ctx->argumentCount() == 3) { - // x, y, text - self->drawText(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toString()); - } else if (ctx->argumentCount() == 2) { - QScriptValue arg0 = ctx->argument(0); - if (arg0.property("width").isValid()) { - self->drawText(qscriptvalue_cast(arg0), - ctx->argument(1).toString()); - } else { - self->drawText(qscriptvalue_cast(arg0), - ctx->argument(1).toString()); - } - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue drawTiledPixmap(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, drawTiledPixmap); - if (ctx->argumentCount() >= 5) { - // x, y, width, height, pixmap, sx, sy - self->drawTiledPixmap(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32(), - qscriptvalue_cast(ctx->argument(4)), - ctx->argument(5).toInt32(), - ctx->argument(6).toInt32()); - } else { - // rect, pixmap, position - self->drawTiledPixmap(qscriptvalue_cast(ctx->argument(0)), - qscriptvalue_cast(ctx->argument(1)), - qscriptvalue_cast(ctx->argument(2))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue end(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, end); - return QScriptValue(eng, self->end()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue eraseRect(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, eraseRect); - if (ctx->argumentCount() == 4) { - // x, y, width, height - self->eraseRect(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else if (ctx->argumentCount() == 1) { - // rect - self->eraseRect(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue fillPath(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, fillPath); - QPainterPath *path = qscriptvalue_cast(ctx->argument(0)); - if (!path) { - return ctx->throwError(QScriptContext::TypeError, - "QPainter.prototype.fillPath: argument is not a PainterPath"); - } - self->fillPath(*path, qscriptvalue_cast(ctx->argument(1))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue fillRect(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, fillRect); - if (ctx->argumentCount() == 5) { - // x, y, width, height, brush - self->fillRect(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32(), - qscriptvalue_cast(ctx->argument(4))); - } else if (ctx->argumentCount() == 2) { - // rect, brush - self->fillRect(qscriptvalue_cast(ctx->argument(0)), - qscriptvalue_cast(ctx->argument(1))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue font(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, font); - return qScriptValueFromValue(eng, self->font()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue hasClipping(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, hasClipping); - return QScriptValue(eng, self->hasClipping()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue active(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, active); - return QScriptValue(eng, self->isActive()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue layoutDirection(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, layoutDirection); - return QScriptValue(eng, static_cast(self->layoutDirection())); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue opacity(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, opacity); - return QScriptValue(eng, self->opacity()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue pen(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, pen); - return qScriptValueFromValue(eng, self->pen()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue renderHints(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, renderHints); - return QScriptValue(eng, static_cast(self->renderHints())); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue resetMatrix(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, resetMatrix); - self->resetMatrix(); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue resetTransform(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, resetTransform); - self->resetTransform(); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue restore(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, restore); - self->restore(); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue rotate(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, rotate); - self->rotate(ctx->argument(0).toNumber()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue save(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, save); - self->save(); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue scale(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, scale); - self->scale(ctx->argument(0).toNumber(), - ctx->argument(1).toNumber()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setBackground(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setBackground); - self->setBackground(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setBackgroundMode(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setBackgroundMode); - self->setBackgroundMode(static_cast(ctx->argument(0).toInt32())); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setBrush(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setBrush); - self->setBrush(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setBrushOrigin(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setBrushOrigin); - self->setBrushOrigin(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setClipPath(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setClipPath); - // ### ClipOperation - self->setClipPath(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setClipRect(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setClipRect); - // ### ClipOperation - if (ctx->argumentCount() >= 4) { - // x, y, width, height [, operation] - self->setClipRect(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else if (ctx->argumentCount() >= 1) { - // rect [, operation] - self->setClipRect(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setClipRegion(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setClipRegion); - // ### ClipOperation - self->setClipRegion(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setClipping(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setClipping); - self->setClipping(ctx->argument(0).toBoolean()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setCompositionMode(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setCompositionMode); - self->setCompositionMode(static_cast(ctx->argument(0).toInt32())); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setFont(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setFont); - self->setFont(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setLayoutDirection(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setLayoutDirection); - self->setLayoutDirection(static_cast(ctx->argument(0).toInt32())); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setOpacity(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setOpacity); - self->setOpacity(ctx->argument(0).toNumber()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setPen(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setPen); - self->setPen(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setRenderHint(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setRenderHint); - self->setRenderHint(static_cast(ctx->argument(0).toInt32()), - ctx->argument(1).toBoolean()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setRenderHints(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setRenderHints); - self->setRenderHints(static_cast(ctx->argument(0).toInt32()), - ctx->argument(1).toBoolean()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setTransform(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setTransform); - self->setTransform(qscriptvalue_cast(ctx->argument(0))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setViewTransformEnabled(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setViewTransformEnabled); - self->setViewTransformEnabled(ctx->argument(0).toBoolean()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setViewport(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setViewport); - if (ctx->argumentCount() == 4) { - // x, y, width, height - self->setViewport(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else if (ctx->argumentCount() == 1) { - // rect - self->setViewport(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setWindow(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setWindow); - if (ctx->argumentCount() == 4) { - // x, y, width, height - self->setWindow(ctx->argument(0).toInt32(), - ctx->argument(1).toInt32(), - ctx->argument(2).toInt32(), - ctx->argument(3).toInt32()); - } else if (ctx->argumentCount() == 1) { - // rect - self->setWindow(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setWorldMatrix(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setWorldMatrix); - self->setWorldMatrix(qscriptvalue_cast(ctx->argument(0)), - ctx->argument(1).toBoolean()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setWorldMatrixEnabled(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setWorldMatrixEnabled); - self->setWorldMatrixEnabled(ctx->argument(0).toBoolean()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue setWorldTransform(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, setWorldTransform); - self->setWorldTransform(qscriptvalue_cast(ctx->argument(0)), - ctx->argument(1).toBoolean()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue shear(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, shear); - self->shear(ctx->argument(0).toNumber(), - ctx->argument(1).toNumber()); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue strokePath(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, strokePath); - QPainterPath *path = qscriptvalue_cast(ctx->argument(0)); - if (!path) { - return ctx->throwError(QScriptContext::TypeError, - "QPainter.prototype.strokePath: argument is not a PainterPath"); - } - self->strokePath(*path, qscriptvalue_cast(ctx->argument(1))); - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue testRenderHint(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, testRenderHint); - return QScriptValue(eng, self->testRenderHint(static_cast(ctx->argument(0).toInt32()))); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue transform(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, transform); - return qScriptValueFromValue(eng, self->transform()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue translate(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, translate); - if (ctx->argumentCount() == 2) { - // dx, dy - self->translate(ctx->argument(0).toNumber(), - ctx->argument(1).toNumber()); - } else if (ctx->argumentCount() == 1) { - // offset - self->translate(qscriptvalue_cast(ctx->argument(0))); - } - return eng->undefinedValue(); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue viewTransformEnabled(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, viewTransformEnabled); - return QScriptValue(eng, self->viewTransformEnabled()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue viewport(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, viewport); - return qScriptValueFromValue(eng, self->viewport()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue window(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, window); - return qScriptValueFromValue(eng, self->window()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue worldMatrix(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, worldMatrix); - return qScriptValueFromValue(eng, self->worldMatrix()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue worldMatrixEnabled(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, worldMatrixEnabled); - return QScriptValue(eng, self->worldMatrixEnabled()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue worldTransform(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, worldTransform); - return qScriptValueFromValue(eng, self->worldTransform()); -} - -///////////////////////////////////////////////////////////// - -static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPainter, toString); - return QScriptValue(eng, "QPainter"); -} - -///////////////////////////////////////////////////////////// - -QScriptValue constructPainterClass(QScriptEngine *eng) -{ - QScriptValue proto = newPainter(eng, new QPainter()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("background", eng->newFunction(background), getter); - proto.setProperty("background", eng->newFunction(setBackground), setter); - - proto.setProperty("backgroundMode", eng->newFunction(backgroundMode), getter); - proto.setProperty("backgroundMode", eng->newFunction(setBackgroundMode), setter); - - proto.setProperty("brush", eng->newFunction(brush), getter); - proto.setProperty("brush", eng->newFunction(setBrush), setter); - - proto.setProperty("brushOrigin", eng->newFunction(brushOrigin), getter); - proto.setProperty("brushOrigin", eng->newFunction(setBrushOrigin), setter); - - proto.setProperty("clipping", eng->newFunction(hasClipping), getter); - proto.setProperty("clipping", eng->newFunction(setClipping), getter); - - proto.setProperty("clipPath", eng->newFunction(clipPath), getter); - proto.setProperty("clipPath", eng->newFunction(setClipPath), setter); - - proto.setProperty("clipRegion", eng->newFunction(clipRegion), getter); - proto.setProperty("clipRegion", eng->newFunction(setClipRegion), setter); - - proto.setProperty("compositionMode", eng->newFunction(compositionMode), getter); - proto.setProperty("compositionMode", eng->newFunction(setCompositionMode), setter); - - proto.setProperty("font", eng->newFunction(font), getter); - proto.setProperty("font", eng->newFunction(setFont), setter); - - proto.setProperty("layoutDirection", eng->newFunction(layoutDirection), getter); - proto.setProperty("layoutDirection", eng->newFunction(setLayoutDirection), setter); - - proto.setProperty("opacity", eng->newFunction(opacity), getter); - proto.setProperty("opacity", eng->newFunction(setOpacity), setter); - - proto.setProperty("pen", eng->newFunction(pen), getter); - proto.setProperty("pen", eng->newFunction(setPen), setter); - - proto.setProperty("renderHints", eng->newFunction(renderHints), getter); - proto.setProperty("renderHints", eng->newFunction(setRenderHints), setter); - - proto.setProperty("transform", eng->newFunction(transform), getter); - proto.setProperty("transform", eng->newFunction(setTransform), getter); - - proto.setProperty("viewport", eng->newFunction(viewport), getter); - proto.setProperty("viewport", eng->newFunction(setViewport), setter); - - proto.setProperty("viewTransformEnabled", eng->newFunction(viewTransformEnabled), getter); - proto.setProperty("viewTransformEnabled", eng->newFunction(setViewTransformEnabled), setter); - - proto.setProperty("window", eng->newFunction(window), getter); - proto.setProperty("window", eng->newFunction(setWindow), setter); - - proto.setProperty("worldMatrix", eng->newFunction(worldMatrix), getter); - proto.setProperty("worldMatrix", eng->newFunction(setWorldMatrix), setter); - - proto.setProperty("worldTransform", eng->newFunction(worldTransform), getter); - proto.setProperty("worldTransform", eng->newFunction(setWorldTransform), setter); - - proto.setProperty("worldMatrixEnabled", eng->newFunction(worldMatrixEnabled), getter); - proto.setProperty("worldMatrixEnabled", eng->newFunction(setWorldMatrixEnabled), setter); - - proto.setProperty("combinedMatrix", eng->newFunction(combinedMatrix), getter); - proto.setProperty("combinedTransform", eng->newFunction(combinedTransform), getter); - proto.setProperty("active", eng->newFunction(active), getter); - - ADD_METHOD(proto, begin); - ADD_METHOD(proto, end); - ADD_METHOD(proto, boundingRect); - ADD_METHOD(proto, drawChord); - ADD_METHOD(proto, drawConvexPolygon); - ADD_METHOD(proto, drawArc); - ADD_METHOD(proto, drawEllipse); - ADD_METHOD(proto, drawImage); - ADD_METHOD(proto, drawLine); - ADD_METHOD(proto, drawLines); - ADD_METHOD(proto, drawPath); - ADD_METHOD(proto, drawPicture); - ADD_METHOD(proto, drawPie); - ADD_METHOD(proto, drawPixmap); - ADD_METHOD(proto, drawPoint); - ADD_METHOD(proto, drawPoints); - ADD_METHOD(proto, drawPolygon); - ADD_METHOD(proto, drawPolyline); - ADD_METHOD(proto, drawRect); - ADD_METHOD(proto, drawRects); - ADD_METHOD(proto, drawRoundRect); - ADD_METHOD(proto, drawText); - ADD_METHOD(proto, drawTiledPixmap); - ADD_METHOD(proto, eraseRect); - ADD_METHOD(proto, fillPath); - ADD_METHOD(proto, fillRect); - ADD_METHOD(proto, resetMatrix); - ADD_METHOD(proto, resetTransform); - ADD_METHOD(proto, restore); - ADD_METHOD(proto, rotate); - ADD_METHOD(proto, save); - ADD_METHOD(proto, scale); - ADD_METHOD(proto, setClipRect); - ADD_METHOD(proto, setRenderHint); - ADD_METHOD(proto, shear); - ADD_METHOD(proto, strokePath); - ADD_METHOD(proto, testRenderHint); - ADD_METHOD(proto, toString); - ADD_METHOD(proto, translate); - - QScript::registerPointerMetaType(eng, proto); - - qScriptRegisterSequenceMetaType >(eng); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - ADD_ENUM_VALUE(ctorFun, QPainter, Antialiasing); - ADD_ENUM_VALUE(ctorFun, QPainter, TextAntialiasing); - ADD_ENUM_VALUE(ctorFun, QPainter, SmoothPixmapTransform); - ADD_ENUM_VALUE(ctorFun, QPainter, HighQualityAntialiasing); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return ctorFun; -} diff --git a/src/scriptengines/javascript/simplebindings/pen.cpp b/src/scriptengines/javascript/simplebindings/pen.cpp deleted file mode 100644 index fc01b8076..000000000 --- a/src/scriptengines/javascript/simplebindings/pen.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2009 Aaron J. Seigo - * - * 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(QPen*) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - Q_UNUSED(ctx) - return qScriptValueFromValue(eng, QPen()); -} - -static QScriptValue brush(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, brush); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setBrush(qscriptvalue_cast(arg)); - } - - return qScriptValueFromValue(eng, self->brush()); -} - -static QScriptValue color(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, color); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setColor(qscriptvalue_cast(arg)); - } - - return qScriptValueFromValue(eng, self->color()); -} - -static QScriptValue style(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, style); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setStyle(Qt::PenStyle(arg.toInt32())); - } - - return QScriptValue(eng, self->style()); -} - -static QScriptValue capStyle(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, capStyle); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setCapStyle(Qt::PenCapStyle(arg.toInt32())); - } - - return QScriptValue(eng, self->capStyle()); -} - -static QScriptValue joinStyle(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, joinStyle); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setJoinStyle(Qt::PenJoinStyle(arg.toInt32())); - } - - return QScriptValue(eng, self->joinStyle()); -} - -static QScriptValue dashOffset(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, dashOffset); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setDashOffset(arg.toInt32()); - } - - return QScriptValue(eng, self->dashOffset()); -} - -static QScriptValue miterLimit(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, miterLimit); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setMiterLimit(arg.toInt32()); - } - - return QScriptValue(eng, self->miterLimit()); -} - -static QScriptValue width(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, width); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setWidth(arg.toInt32()); - } - - return QScriptValue(eng, self->width()); -} - -static QScriptValue solid(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPen, solid); - return QScriptValue(eng, self->isSolid()); -} - -QScriptValue constructPenClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QColor()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - proto.setProperty("brush", eng->newFunction(brush), getter | setter); - proto.setProperty("color", eng->newFunction(color), getter | setter); - proto.setProperty("capStyle", eng->newFunction(capStyle), getter | setter); - proto.setProperty("joinStyle", eng->newFunction(joinStyle), getter | setter); - proto.setProperty("style", eng->newFunction(style), getter | setter); - proto.setProperty("dashOffset", eng->newFunction(dashOffset), getter | setter); - proto.setProperty("miterLimit", eng->newFunction(miterLimit), getter | setter); - proto.setProperty("width", eng->newFunction(width), getter | setter); - proto.setProperty("solid", eng->newFunction(solid), getter); - - QScriptValue ctorFun = eng->newFunction(ctor, proto); - ADD_ENUM_VALUE(ctorFun, Qt, FlatCap); - ADD_ENUM_VALUE(ctorFun, Qt, SquareCap); - ADD_ENUM_VALUE(ctorFun, Qt, RoundCap); - ADD_ENUM_VALUE(ctorFun, Qt, RoundCap); - ADD_ENUM_VALUE(ctorFun, Qt, BevelJoin); - ADD_ENUM_VALUE(ctorFun, Qt, MiterJoin); - ADD_ENUM_VALUE(ctorFun, Qt, RoundJoin); - ADD_ENUM_VALUE(ctorFun, Qt, SolidLine); - ADD_ENUM_VALUE(ctorFun, Qt, DashLine); - ADD_ENUM_VALUE(ctorFun, Qt, DotLine); - ADD_ENUM_VALUE(ctorFun, Qt, DashDotLine); - ADD_ENUM_VALUE(ctorFun, Qt, DashDotDotLine); - ADD_ENUM_VALUE(ctorFun, Qt, CustomDashLine); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return ctorFun; -} - diff --git a/src/scriptengines/javascript/simplebindings/pixmap.cpp b/src/scriptengines/javascript/simplebindings/pixmap.cpp deleted file mode 100644 index 11bc092b3..000000000 --- a/src/scriptengines/javascript/simplebindings/pixmap.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2009 Aaron J. Seigo - * - * 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" -#include "plasmoid/appletinterface.h" - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() == 1 && ctx->argument(0).isString()) { - // a path on disk in the package - AppletInterface *interface = AppletInterface::extract(eng); - const QString path = interface ? interface->file("images", ctx->argument(0).toString()) : QString(); - return qScriptValueFromValue(eng, QPixmap(path)); - } - - if (ctx->argumentCount() == 2) { - qreal x = ctx->argument(0).toNumber(); - qreal y = ctx->argument(1).toNumber(); - return qScriptValueFromValue(eng, QPixmap(x, y)); - } - - return qScriptValueFromValue(eng, QPixmap()); -} - -static QScriptValue rect(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPixmap, rect) - return qScriptValueFromValue(eng, QRectF(self->rect())); -} - -static QScriptValue null(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPixmap, null); - return QScriptValue(eng, self->isNull()); -} - -static QScriptValue scaled(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPixmap, scaled); - qreal x = ctx->argument(0).toNumber(); - qreal y = ctx->argument(1).toNumber(); - return qScriptValueFromValue(eng, self->scaled(x, y)); -} - -QScriptValue constructQPixmapClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QPixmap()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - proto.setProperty("null", eng->newFunction(null), getter); - proto.setProperty("rect", eng->newFunction(rect), getter); - proto.setProperty("scaled", eng->newFunction(scaled)); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/javascript/simplebindings/point.cpp b/src/scriptengines/javascript/simplebindings/point.cpp deleted file mode 100644 index 274c898fa..000000000 --- a/src/scriptengines/javascript/simplebindings/point.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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(QPoint*) -Q_DECLARE_METATYPE(QPoint) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() == 2) - { - int x = ctx->argument(0).toInt32(); - int y = ctx->argument(1).toInt32(); - return qScriptValueFromValue(eng, QPoint(x, y)); - } - - return qScriptValueFromValue(eng, QPoint()); -} - -static QScriptValue null(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPoint, null); - return QScriptValue(eng, self->isNull()); -} - -static QScriptValue manhattanLength(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPoint, manhattanLength); - return QScriptValue(eng, self->manhattanLength()); -} - -static QScriptValue x(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPoint, x); - - if (ctx->argumentCount() > 0) { - int x = ctx->argument(0).toInt32(); - self->setX(x); - } - - return QScriptValue(eng, self->x()); -} - -static QScriptValue y(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QPoint, y); - - if (ctx->argumentCount() > 0) { - int y = ctx->argument(0).toInt32(); - self->setY(y); - } - - return QScriptValue(eng, self->y()); -} - -QScriptValue constructQPointClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QPoint()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("null", eng->newFunction(null), getter); - proto.setProperty("manhattanLength", eng->newFunction(manhattanLength), getter); - proto.setProperty("x", eng->newFunction(x), getter | setter); - proto.setProperty("y", eng->newFunction(y), getter | setter); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/javascript/simplebindings/qscriptbookkeeping.cpp b/src/scriptengines/javascript/simplebindings/qscriptbookkeeping.cpp deleted file mode 100644 index bc9cb8b7b..000000000 --- a/src/scriptengines/javascript/simplebindings/qscriptbookkeeping.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2007-2008 Richard J. Moore - * Copyright 2009 Aaron J. Seigo - * - * 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 -#include - -//Q_DECLARE_METATYPE(SimpleJavaScriptApplet*) -Q_DECLARE_METATYPE(QGraphicsWidget*) -Q_DECLARE_METATYPE(QGraphicsLayout*) - -Q_DECLARE_METATYPE(Plasma::Animation*) -Q_DECLARE_METATYPE(Plasma::Applet*) -Q_DECLARE_METATYPE(Plasma::Extender*) -Q_DECLARE_METATYPE(Plasma::VideoWidget::Controls) -Q_DECLARE_METATYPE(Plasma::Svg*) -Q_DECLARE_METATYPE(Qt::MouseButton) -Q_DECLARE_METATYPE(QList) - -QScriptValue qScriptValueFromControls(QScriptEngine *engine, const Plasma::VideoWidget::Controls &controls) -{ - return QScriptValue(engine, controls); -} - -void controlsFromScriptValue(const QScriptValue& obj, Plasma::VideoWidget::Controls &controls) -{ - int flagValue = obj.toInteger(); - //FIXME: it has to be a less ugly way to do that :) - if (flagValue & Plasma::VideoWidget::Play) { - controls |= Plasma::VideoWidget::Play; - } - if (flagValue & Plasma::VideoWidget::Pause) { - controls |= Plasma::VideoWidget::Pause; - } - if (flagValue & Plasma::VideoWidget::Stop) { - controls |= Plasma::VideoWidget::Stop; - } - if (flagValue & Plasma::VideoWidget::PlayPause) { - controls |= Plasma::VideoWidget::PlayPause; - } - if (flagValue & Plasma::VideoWidget::Progress) { - controls |= Plasma::VideoWidget::Progress; - } - if (flagValue & Plasma::VideoWidget::Volume) { - controls |= Plasma::VideoWidget::Volume; - } - if (flagValue & Plasma::VideoWidget::OpenFile) { - controls |= Plasma::VideoWidget::OpenFile; - } -} - -typedef Plasma::Animation* AnimationPtr; -QScriptValue qScriptValueFromAnimation(QScriptEngine *engine, const AnimationPtr &anim) -{ - return engine->newQObject(const_cast(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void abstractAnimationFromQScriptValue(const QScriptValue &scriptValue, AnimationPtr &anim) -{ - QObject *obj = scriptValue.toQObject(); - anim = static_cast(obj); -} - -typedef QGraphicsWidget * QGraphicsWidgetPtr; -QScriptValue qScriptValueFromQGraphicsWidget(QScriptEngine *engine, const QGraphicsWidgetPtr &anim) -{ - return engine->newQObject(const_cast(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void graphicsWidgetFromQScriptValue(const QScriptValue &scriptValue, QGraphicsWidgetPtr &anim) -{ - QObject *obj = scriptValue.toQObject(); - anim = static_cast(obj); -} - -typedef Plasma::Svg * SvgPtr; -QScriptValue qScriptValueFromSvg(QScriptEngine *engine, const SvgPtr &anim) -{ - return engine->newQObject(const_cast(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void svgFromQScriptValue(const QScriptValue &scriptValue, SvgPtr &anim) -{ - QObject *obj = scriptValue.toQObject(); - anim = static_cast(obj); -} - -typedef Plasma::Extender *ExtenderPtr; -QScriptValue qScriptValueFromExtender(QScriptEngine *engine, const ExtenderPtr &extender) -{ - return engine->newQObject(const_cast(extender), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void extenderFromQScriptValue(const QScriptValue &scriptValue, ExtenderPtr &extender) -{ - QObject *obj = scriptValue.toQObject(); - extender = static_cast(obj); -} - -QScriptValue qScriptValueFromMouseButton(QScriptEngine *, const Qt::MouseButton &button) -{ - return int(button); -} - -void mouseButtonFromScriptValue(const QScriptValue &scriptValue, Qt::MouseButton &button) -{ - button = static_cast(scriptValue.toInt32()); -} - -#include "simplebindings/qscriptnonguibookkeeping.cpp" - -using namespace Plasma; - -void registerSimpleAppletMetaTypes(QScriptEngine *engine) -{ - registerNonGuiMetaTypes(engine); - qScriptRegisterMetaType(engine, qScriptValueFromQGraphicsWidget, graphicsWidgetFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromSvg, svgFromQScriptValue); - - qScriptRegisterSequenceMetaType >(engine); - qScriptRegisterMetaType(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromExtender, extenderFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue()); - qScriptRegisterMetaType(engine, qScriptValueFromMouseButton, mouseButtonFromScriptValue); -} - - diff --git a/src/scriptengines/javascript/simplebindings/qscriptnonguibookkeeping.cpp b/src/scriptengines/javascript/simplebindings/qscriptnonguibookkeeping.cpp deleted file mode 100644 index 8b8c1a712..000000000 --- a/src/scriptengines/javascript/simplebindings/qscriptnonguibookkeeping.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2007-2008 Richard J. Moore - * Copyright 2009 Aaron J. Seigo - * - * 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 "dataengine.h" - -Q_DECLARE_METATYPE(KConfigGroup) -Q_DECLARE_METATYPE(KJob *) - -typedef KJob* KJobPtr; -QScriptValue qScriptValueFromKJob(QScriptEngine *engine, const KJobPtr &job) -{ - return engine->newQObject(const_cast(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void qKJobFromQScriptValue(const QScriptValue &scriptValue, KJobPtr &job) -{ - QObject *obj = scriptValue.toQObject(); - job = static_cast(obj); -} - -Q_DECLARE_METATYPE(KIO::Job *) -typedef KIO::Job* KioJobPtr; -QScriptValue qScriptValueFromKIOJob(QScriptEngine *engine, const KioJobPtr &job) -{ - return engine->newQObject(const_cast(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void qKIOJobFromQScriptValue(const QScriptValue &scriptValue, KioJobPtr &job) -{ - QObject *obj = scriptValue.toQObject(); - job = static_cast(obj); -} - -QScriptValue qScriptValueFromKConfigGroup(QScriptEngine *engine, const KConfigGroup &config) -{ - QScriptValue obj = engine->newObject(); - - if (!config.isValid()) { - return obj; - } - - QMap entryMap = config.entryMap(); - QMap::const_iterator it = entryMap.constBegin(); - QMap::const_iterator begin = it; - QMap::const_iterator end = entryMap.constEnd(); - - //setting the group name - obj.setProperty("__file", QScriptValue(engine, config.config()->name())); - obj.setProperty("__name", QScriptValue(engine, config.name())); - - //setting the key/value pairs - for (it = begin; it != end; ++it) { - //qDebug() << "setting" << it.key() << "to" << it.value(); - QString prop = it.key(); - prop.replace(' ', '_'); - obj.setProperty(prop, it.value()); - } - - return obj; -} - -void kConfigGroupFromScriptValue(const QScriptValue& obj, KConfigGroup &config) -{ - config = KConfigGroup(KSharedConfig::openConfig(obj.property("__file").toString()), obj.property("__name").toString()); - - QScriptValueIterator it(obj); - - while (it.hasNext()) { - it.next(); - //qDebug() << it.name() << "is" << it.value().toString(); - if (it.name() != "__name") { - config.writeEntry(it.name(), it.value().toString()); - } - } -} - -using namespace Plasma; - -void registerNonGuiMetaTypes(QScriptEngine *engine) -{ - qScriptRegisterMetaType(engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromKJob, qKJobFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue); - registerDataEngineMetaTypes(engine); -} - diff --git a/src/scriptengines/javascript/simplebindings/rect.cpp b/src/scriptengines/javascript/simplebindings/rect.cpp deleted file mode 100644 index ac2382c50..000000000 --- a/src/scriptengines/javascript/simplebindings/rect.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/* - * 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(QRectF*) -Q_DECLARE_METATYPE(QRectF) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() == 4) - { - qreal x = ctx->argument(0).toNumber(); - qreal y = ctx->argument(1).toNumber(); - qreal width = ctx->argument(2).toNumber(); - qreal height = ctx->argument(3).toNumber(); - return qScriptValueFromValue(eng, QRectF(x, y, width, height)); - } - - return qScriptValueFromValue(eng, QRectF()); -} - -static QScriptValue adjust(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, adjust); - qreal dx1 = ctx->argument(0).toNumber(); - qreal dy1 = ctx->argument(1).toNumber(); - qreal dx2 = ctx->argument(2).toNumber(); - qreal dy2 = ctx->argument(3).toNumber(); - - self->adjust(dx1, dy1, dx2, dy2); - return QScriptValue(); -} - -static QScriptValue adjusted(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, adjusted); - qreal dx1 = ctx->argument(0).toNumber(); - qreal dy1 = ctx->argument(1).toNumber(); - qreal dx2 = ctx->argument(2).toNumber(); - qreal dy2 = ctx->argument(3).toNumber(); - - QRectF tmp = self->adjusted(dx1, dy1, dx2, dy2); - return qScriptValueFromValue(eng, tmp); -} - -static QScriptValue bottom(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, bottom); - - if (ctx->argumentCount() > 0) { - int bottom = ctx->argument(0).toInt32(); - self->setBottom(bottom); - } - - return QScriptValue(eng, self->bottom()); -} - -static QScriptValue top(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, top); - - if (ctx->argumentCount() > 0) { - int top = ctx->argument(0).toInt32(); - self->setTop(top); - } - - return QScriptValue(eng, self->top()); -} - -static QScriptValue contains(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, contains); - qreal x = ctx->argument(0).toNumber(); - qreal y = ctx->argument(1).toNumber(); - return QScriptValue(eng, self->contains(x, y)); -} - -static QScriptValue height(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, height); - - if (ctx->argumentCount() > 0) { - int height = ctx->argument(0).toInt32(); - self->setHeight(height); - } - - return QScriptValue(eng, self->height()); -} - -static QScriptValue empty(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, empty); - return QScriptValue(eng, self->isEmpty()); -} - -static QScriptValue null(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, null); - return QScriptValue(eng, self->isNull()); -} - -static QScriptValue valid(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, valid); - return QScriptValue(eng, self->isValid()); -} - -static QScriptValue left(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, left); - - if (ctx->argumentCount() > 0) { - int left = ctx->argument(0).toInt32(); - self->setLeft(left); - } - - return QScriptValue(eng, self->left()); -} - -static QScriptValue moveBottom(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, moveBottom); - qreal bottom = ctx->argument(0).toNumber(); - self->moveBottom(bottom); - return QScriptValue(); -} - -static QScriptValue moveLeft(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, moveLeft); - qreal left = ctx->argument(0).toNumber(); - self->moveLeft(left); - return QScriptValue(); -} - -static QScriptValue moveRight(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, moveRight); - qreal right = ctx->argument(0).toNumber(); - self->moveRight(right); - return QScriptValue(); -} - - -static QScriptValue moveTo(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, moveTo); - qreal x = ctx->argument(0).toNumber(); - qreal y = ctx->argument(1).toNumber(); - self->moveTo(x, y); - return QScriptValue(); -} - -static QScriptValue moveTop(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, moveTop); - qreal top = ctx->argument(0).toNumber(); - self->moveTop(top); - return QScriptValue(); -} - -static QScriptValue right(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, right); - - if (ctx->argumentCount() > 0) { - int right = ctx->argument(0).toInt32(); - self->setRight(right); - } - - return QScriptValue(eng, self->right()); -} - -static QScriptValue setCoords(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, setCoords); - qreal x1 = ctx->argument(0).toNumber(); - qreal y1 = ctx->argument(1).toNumber(); - qreal x2 = ctx->argument(2).toNumber(); - qreal y2 = ctx->argument(3).toNumber(); - self->setCoords(x1, y1, x2, y2); - return QScriptValue(); -} - -static QScriptValue setRect(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, setRect); - qreal x = ctx->argument(0).toNumber(); - qreal y = ctx->argument(1).toNumber(); - qreal width = ctx->argument(2).toNumber(); - qreal height = ctx->argument(3).toNumber(); - self->setRect(x, y, width, height); - return QScriptValue(); -} - -static QScriptValue translate(QScriptContext *ctx, QScriptEngine *) -{ - DECLARE_SELF(QRectF, translate); - qreal dx = ctx->argument(0).toNumber(); - qreal dy = ctx->argument(1).toNumber(); - self->translate(dx, dy); - return QScriptValue(); -} - -static QScriptValue width(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, width); - - if (ctx->argumentCount() > 0) { - int width = ctx->argument(0).toInt32(); - self->setWidth(width); - } - - return QScriptValue(eng, self->width()); -} - -static QScriptValue x(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, x); - - if (ctx->argumentCount() > 0) { - int x = ctx->argument(0).toInt32(); - self->setX(x); - } - - return QScriptValue(eng, self->x()); -} - -static QScriptValue y(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QRectF, y); - - if (ctx->argumentCount() > 0) { - int y = ctx->argument(0).toInt32(); - self->setY(y); - } - - return QScriptValue(eng, self->y()); -} - -/* Not Implemented Yet */ -// QPointF bottomLeft () const -// QPointF bottomRight () const -// QPointF center () const -// bool contains ( const QPointF & point ) const -// bool contains ( const QRectF & rectangle ) const -// void getCoords ( qreal * x1, qreal * y1, qreal * x2, qreal * y2 ) const -// void getRect ( qreal * x, qreal * y, qreal * width, qreal * height ) const -// QRectF intersected ( const QRectF & rectangle ) const -// bool intersects ( const QRectF & rectangle ) const -// void moveBottomLeft ( const QPointF & position ) -// void moveBottomRight ( const QPointF & position ) -// void moveCenter ( const QPointF & position ) -// void moveTo ( const QPointF & position ) -// void moveTopLeft ( const QPointF & position ) -// void moveTopRight ( const QPointF & position ) -// QRectF normalized () const -// void setBottomLeft ( const QPointF & position ) -// void setBottomRight ( const QPointF & position ) -// void setSize ( const QSizeF & size ) -// void setTopLeft ( const QPointF & position ) -// void setTopRight ( const QPointF & position ) -// QSizeF size () const -// QRect toAlignedRect () const -// QRect toRect () const -// QPointF topLeft () const -// QPointF topRight () const -// void translate ( const QPointF & offset ) -// QRectF translated ( qreal dx, qreal dy ) const -// QRectF translated ( const QPointF & offset ) const -// QRectF united ( const QRectF & rectangle ) const - -QScriptValue constructQRectFClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QRectF()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("adjust", eng->newFunction(adjust)); - proto.setProperty("adjusted", eng->newFunction(adjusted)); - proto.setProperty("translate", eng->newFunction(translate)); - proto.setProperty("setCoords", eng->newFunction(setCoords)); - proto.setProperty("setRect", eng->newFunction(setRect)); - - proto.setProperty("contains", eng->newFunction(contains)); - - proto.setProperty("moveBottom", eng->newFunction(moveBottom)); - proto.setProperty("moveLeft", eng->newFunction(moveLeft)); - proto.setProperty("moveRight", eng->newFunction(moveRight)); - proto.setProperty("moveTo", eng->newFunction(moveTo)); - proto.setProperty("moveTop", eng->newFunction(moveTop)); - - proto.setProperty("empty", eng->newFunction(empty), getter); - proto.setProperty("null", eng->newFunction(null), getter); - proto.setProperty("valid", eng->newFunction(valid), getter); - - proto.setProperty("left", eng->newFunction(left), getter | setter); - proto.setProperty("top", eng->newFunction(top), getter | setter); - proto.setProperty("bottom", eng->newFunction(bottom), getter | setter); - proto.setProperty("right", eng->newFunction(right), getter | setter); - proto.setProperty("height", eng->newFunction(height), getter | setter); - proto.setProperty("width", eng->newFunction(width), getter | setter); - proto.setProperty("x", eng->newFunction(x), getter | setter); - proto.setProperty("y", eng->newFunction(y), getter | setter); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/javascript/simplebindings/size.cpp b/src/scriptengines/javascript/simplebindings/size.cpp deleted file mode 100644 index 3f41b46f1..000000000 --- a/src/scriptengines/javascript/simplebindings/size.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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(QSizeF*) -Q_DECLARE_METATYPE(QSizeF) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() == 2) { - qreal width = ctx->argument(1).toNumber(); - qreal height = ctx->argument(1).toNumber(); - return qScriptValueFromValue(eng, QSizeF(width, height)); - } - - return qScriptValueFromValue(eng, QSizeF()); -} - -static QScriptValue width(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QSizeF, width); - if (ctx->argumentCount() > 0) { - qreal width = ctx->argument(0).toNumber(); - self->setWidth(width); - } - - return QScriptValue(eng, self->width()); -} - -static QScriptValue height(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QSizeF, height); - if (ctx->argumentCount() > 0) { - qreal height = ctx->argument(0).toNumber(); - self->setHeight(height); - } - - return QScriptValue(eng, self->height()); -} - -QScriptValue constructQSizeFClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QSizeF()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("width", eng->newFunction(width), getter | setter); - proto.setProperty("height", eng->newFunction(height), getter | setter); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - return eng->newFunction(ctor, proto); -} - diff --git a/src/scriptengines/javascript/simplebindings/sizepolicy.cpp b/src/scriptengines/javascript/simplebindings/sizepolicy.cpp deleted file mode 100644 index d500f7ba1..000000000 --- a/src/scriptengines/javascript/simplebindings/sizepolicy.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2010 Aaron J. Seigo - * - * 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(QSizePolicy*) - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - QSizePolicy::Policy h(QSizePolicy::Fixed); - QSizePolicy::Policy v(QSizePolicy::Fixed); - if (ctx->argumentCount() > 1) { - h = static_cast(ctx->argument(0).toInt32()); - v = static_cast(ctx->argument(1).toInt32()); - } - - QScriptValue value = qScriptValueFromValue(eng, QSizePolicy(h, v)); - return value; -} - -static QScriptValue horizontalPolicy(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QSizePolicy, horizontalPolicy); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setHorizontalPolicy(static_cast(arg.toInt32())); - } - - return QScriptValue(eng, self->horizontalPolicy()); -} - -static QScriptValue verticalPolicy(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QSizePolicy, vertialPolicy); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setVerticalPolicy(static_cast(arg.toInt32())); - } - - return QScriptValue(eng, self->verticalPolicy()); -} - -static QScriptValue horizontalStretch(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QSizePolicy, horizontalStretch); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setHorizontalStretch(arg.toInt32()); - } - - return QScriptValue(eng, self->horizontalStretch()); -} - -static QScriptValue verticalStretch(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QSizePolicy, verticalStretch); - - if (ctx->argumentCount() > 0) { - QScriptValue arg = ctx->argument(0); - self->setVerticalStretch(arg.toInt32()); - } - - return QScriptValue(eng, self->verticalStretch()); -} - -QScriptValue constructQSizePolicyClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QSizePolicy()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - proto.setProperty("horizontalPolicy", eng->newFunction(horizontalPolicy), getter | setter); - proto.setProperty("verticalPolicy", eng->newFunction(verticalPolicy), getter | setter); - proto.setProperty("horizontalStretch", eng->newFunction(horizontalStretch), getter | setter); - proto.setProperty("verticalStretch", eng->newFunction(verticalStretch), getter | setter); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/javascript/simplebindings/timer.cpp b/src/scriptengines/javascript/simplebindings/timer.cpp deleted file mode 100644 index 40c982d5e..000000000 --- a/src/scriptengines/javascript/simplebindings/timer.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 -#include "backportglobal.h" - -Q_DECLARE_METATYPE(QTimer*) - -static QScriptValue newTimer(QScriptEngine *eng, QTimer *timer) -{ - return eng->newQObject(timer, QScriptEngine::AutoOwnership); -} - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - return newTimer(eng, new QTimer(qscriptvalue_cast(ctx->argument(0)))); -} - -static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QTimer, toString); - return QScriptValue(eng, QString::fromLatin1("QTimer(interval=%0)") - .arg(self->interval())); -} - -static QScriptValue active(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QTimer, active); - - if (ctx->argumentCount()) { - if (ctx->argument(0).toBool()) { - self->start(); - } else { - self->stop(); - } - } - - return QScriptValue(eng, self->isActive()); -} - -QScriptValue constructTimerClass(QScriptEngine *eng) -{ - QScriptValue proto = newTimer(eng, new QTimer()); - ADD_METHOD(proto, toString); - eng->setDefaultPrototype(qMetaTypeId(), proto); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - proto.setProperty("active", eng->newFunction(active), getter | setter); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/javascript/simplebindings/uiloader.cpp b/src/scriptengines/javascript/simplebindings/uiloader.cpp deleted file mode 100644 index d85083118..000000000 --- a/src/scriptengines/javascript/simplebindings/uiloader.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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 as - * published by the Free Software Foundation; either version 2, 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 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 "uiloader.h" - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -QGraphicsWidget *createBusyWidget(QGraphicsWidget *parent) { return new Plasma::BusyWidget(parent); } -QGraphicsWidget *createCheckBox(QGraphicsWidget *parent) { return new Plasma::CheckBox(parent); } -QGraphicsWidget *createComboBox(QGraphicsWidget *parent) { return new Plasma::ComboBox(parent); } -QGraphicsWidget *createFlashingLabel(QGraphicsWidget *parent) { return new Plasma::FlashingLabel(parent); } -QGraphicsWidget *createFrame(QGraphicsWidget *parent) { return new Plasma::Frame(parent); } -QGraphicsWidget *createGroupBox(QGraphicsWidget *parent) { return new Plasma::GroupBox(parent); } -QGraphicsWidget *createIconWidget(QGraphicsWidget *parent) { return new Plasma::IconWidget(parent); } -QGraphicsWidget *createItemBackground(QGraphicsWidget *parent) { return new Plasma::ItemBackground(parent); } -QGraphicsWidget *createLabel(QGraphicsWidget *parent) { return new Plasma::Label(parent); } -QGraphicsWidget *createLineEdit(QGraphicsWidget *parent) { return new Plasma::LineEdit(parent); } -QGraphicsWidget *createMeter(QGraphicsWidget *parent) { return new Plasma::Meter(parent); } -QGraphicsWidget *createPushButton(QGraphicsWidget *parent) { return new Plasma::PushButton(parent); } -QGraphicsWidget *createRadioButton(QGraphicsWidget *parent) { return new Plasma::RadioButton(parent); } -QGraphicsWidget *createScrollBar(QGraphicsWidget *parent) { return new Plasma::ScrollBar(parent); } -QGraphicsWidget *createScrollWidget(QGraphicsWidget *parent) { return new Plasma::ScrollWidget(parent); } -QGraphicsWidget *createSeparator(QGraphicsWidget *parent) { return new Plasma::Separator(parent); } -QGraphicsWidget *createSignalPlotter(QGraphicsWidget *parent) { return new Plasma::SignalPlotter(parent); } -QGraphicsWidget *createSlider(QGraphicsWidget *parent) { return new Plasma::Slider(parent); } -QGraphicsWidget *createSpinBox(QGraphicsWidget *parent) { return new Plasma::SpinBox(parent); } -QGraphicsWidget *createSvgWidget(QGraphicsWidget *parent) { return new Plasma::SvgWidget(parent); } -QGraphicsWidget *createTabBar(QGraphicsWidget *parent) { return new Plasma::TabBar(parent); } -QGraphicsWidget *createTextEdit(QGraphicsWidget *parent) { return new Plasma::TextEdit(parent); } -QGraphicsWidget *createToolButton(QGraphicsWidget *parent) { return new Plasma::ToolButton(parent); } -QGraphicsWidget *createTreeView(QGraphicsWidget *parent) { return new Plasma::TreeView(parent); } -QGraphicsWidget *createVideoWidget(QGraphicsWidget *parent) { return new Plasma::VideoWidget(parent); } -QGraphicsWidget *createWebView(QGraphicsWidget *parent) { return new Plasma::WebView(parent); } -QGraphicsWidget *createGraphicsWidget(QGraphicsWidget *parent) { return new QGraphicsWidget(parent); } - -UiLoader::UiLoader() -{ - m_widgetCtors.insert("BusyWidget", createBusyWidget); - m_widgetCtors.insert("CheckBox", createCheckBox); - m_widgetCtors.insert("ComboBox", createComboBox); - m_widgetCtors.insert("FlashingLabel", createFlashingLabel); - m_widgetCtors.insert("Frame", createFrame); - m_widgetCtors.insert("GroupBox", createGroupBox); - m_widgetCtors.insert("IconWidget", createIconWidget); - m_widgetCtors.insert("ItemBackground", createItemBackground); - m_widgetCtors.insert("Label", createLabel); - m_widgetCtors.insert("LineEdit", createLineEdit); - m_widgetCtors.insert("Meter", createMeter); - m_widgetCtors.insert("PushButton", createPushButton); - m_widgetCtors.insert("RadioButton", createRadioButton); - m_widgetCtors.insert("ScrollBar", createScrollBar); - m_widgetCtors.insert("ScrollWidget", createScrollWidget); - m_widgetCtors.insert("Separator", createSeparator); - m_widgetCtors.insert("SignalPlotter", createSignalPlotter); - m_widgetCtors.insert("Slider", createSlider); - m_widgetCtors.insert("SpinBox", createSpinBox); - m_widgetCtors.insert("SvgWidget", createSvgWidget); - m_widgetCtors.insert("TabBar", createTabBar); - m_widgetCtors.insert("TextEdit", createTextEdit); - m_widgetCtors.insert("ToolButton", createToolButton); - m_widgetCtors.insert("TreeView", createTreeView); - m_widgetCtors.insert("VideoWidget", createVideoWidget); - m_widgetCtors.insert("WebView", createWebView); - m_widgetCtors.insert("GraphicsWidget", createWebView); -} - -UiLoader::~UiLoader() -{ - // qDebug(); -} - -QStringList UiLoader::availableWidgets() const -{ - return m_widgetCtors.keys(); -} - -QGraphicsWidget *UiLoader::createWidget(const QString &className, QGraphicsWidget *parent) -{ - widgetCreator w = m_widgetCtors.value(className, 0); - if (w) { - return (w)(parent); - } - - return 0; -} - - diff --git a/src/scriptengines/javascript/simplebindings/uiloader.h b/src/scriptengines/javascript/simplebindings/uiloader.h deleted file mode 100644 index 396890a25..000000000 --- a/src/scriptengines/javascript/simplebindings/uiloader.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 as - * published by the Free Software Foundation; either version 2, 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 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. - */ - -#ifndef PLASMA_UILOADER_H -#define PLASMA_UILOADER_H - -#include - -#include - -class QGraphicsWidget; - -class UiLoader : public QSharedData -{ -public: - UiLoader(); - virtual ~UiLoader(); - - QStringList availableWidgets() const; - QGraphicsWidget *createWidget(const QString &className, QGraphicsWidget *parent = 0); - -private: - typedef QGraphicsWidget *(*widgetCreator)(QGraphicsWidget*); - QHash m_widgetCtors; -}; - - -#endif // PLASMA_UILOADER_H diff --git a/src/scriptengines/javascript/simplebindings/url.cpp b/src/scriptengines/javascript/simplebindings/url.cpp deleted file mode 100644 index 2b704c414..000000000 --- a/src/scriptengines/javascript/simplebindings/url.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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(QUrl*) -//Q_DECLARE_METATYPE(QUrl) unneeded; found in qurl.h - -static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) -{ - if (ctx->argumentCount() == 1) - { - QString url = ctx->argument(0).toString(); - return qScriptValueFromValue(eng, QUrl(url)); - } - - return qScriptValueFromValue(eng, QUrl()); -} - -static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QUrl, toString); - return QScriptValue(eng, self->prettyUrl()); -} - -static QScriptValue protocol(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QUrl, protocol); - if (ctx->argumentCount()) { - QString v = ctx->argument(0).toString(); - self->setProtocol(v); - } - - return QScriptValue(eng, self->protocol()); -} - -static QScriptValue host(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QUrl, protocol); - if (ctx->argumentCount()) { - QString v = ctx->argument(0).toString(); - self->setHost(v); - } - - return QScriptValue(eng, self->host()); -} - -static QScriptValue path(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QUrl, path); - if (ctx->argumentCount()) { - QString v = ctx->argument(0).toString(); - self->setPath(v); - } - - return QScriptValue(eng, self->path()); -} - -static QScriptValue user(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QUrl, user); - if (ctx->argumentCount()) { - QString v = ctx->argument(0).toString(); - self->setUser(v); - } - - return QScriptValue(eng, self->user()); -} - -static QScriptValue password(QScriptContext *ctx, QScriptEngine *eng) -{ - DECLARE_SELF(QUrl, password); - if (ctx->argumentCount()) { - QString v = ctx->argument(0).toString(); - self->setPassword(v); - } - - return QScriptValue(eng, self->password()); -} - -QScriptValue constructQUrlClass(QScriptEngine *eng) -{ - QScriptValue proto = qScriptValueFromValue(eng, QUrl()); - QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; - QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - - proto.setProperty("toString", eng->newFunction(toString), getter); - proto.setProperty("protocol", eng->newFunction(protocol), getter | setter); - proto.setProperty("host", eng->newFunction(host), getter | setter); - proto.setProperty("path", eng->newFunction(path), getter | setter); - proto.setProperty("user", eng->newFunction(user), getter | setter); - proto.setProperty("password", eng->newFunction(password), getter | setter); - - eng->setDefaultPrototype(qMetaTypeId(), proto); - eng->setDefaultPrototype(qMetaTypeId(), proto); - - return eng->newFunction(ctor, proto); -} diff --git a/src/scriptengines/python/CMakeLists.txt b/src/scriptengines/python/CMakeLists.txt new file mode 100644 index 000000000..2bd980b6a --- /dev/null +++ b/src/scriptengines/python/CMakeLists.txt @@ -0,0 +1,23 @@ +project(plasma-python) + +include(PythonMacros) + +# install the library, .desktop, and plasma.py +python_install(plasma_importer.py ${DATA_INSTALL_DIR}/plasma_scriptengine_python) +python_install(pydataengine.py ${DATA_INSTALL_DIR}/plasma_scriptengine_python) +python_install(pyrunner.py ${DATA_INSTALL_DIR}/plasma_scriptengine_python) + +# remove the following three lines once we branch 4.5, they are only necessary as long +# as people update kdebase but not yet kdelibs (PYTHON_SITE_PACKAGES_INSTALL_DIR has just +# recently been added to FindPYthonLib.cmake and should be used as install destination). Alex +if(NOT PYTHON_SITE_PACKAGES_INSTALL_DIR) + set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${PYTHON_SITE_PACKAGES_DIR} ) +endif() + +python_install(plasmascript.py ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/PyKDE4) + +install(FILES plasma-scriptengine-dataengine-python.desktop + DESTINATION ${SERVICES_INSTALL_DIR}) +install(FILES plasma-scriptengine-runner-python.desktop + DESTINATION ${SERVICES_INSTALL_DIR}) + diff --git a/src/scriptengines/python/plasma-scriptengine-dataengine-python.desktop b/src/scriptengines/python/plasma-scriptengine-dataengine-python.desktop new file mode 100644 index 000000000..284907fa2 --- /dev/null +++ b/src/scriptengines/python/plasma-scriptengine-dataengine-python.desktop @@ -0,0 +1,153 @@ +[Desktop Entry] +Name=Python data engine +Name[ar]=محرك بيانات بايثون +Name[ast]=Motor de datos de Python +Name[be@latin]=Systema źviestak u movie „Python” +Name[bg]=Ядро за данни с Python +Name[bn_IN]=Python ডাটা ইঞ্জিন +Name[bs]=Python pogon podataka +Name[ca]=Motor de dades en Python +Name[ca@valencia]=Motor de dades en Python +Name[cs]=Rozhraní v Pythonu +Name[csb]=Czérownik Phythona +Name[da]=Datamotor til Python +Name[de]=Python-Datentreiber +Name[el]=Μηχανή δεδομένων Python +Name[en_GB]=Python data engine +Name[eo]=Pitona datuma motoro +Name[es]=Motor de datos de Python +Name[et]=Pythoni andmete mootor +Name[eu]=Python-en datu-motorra +Name[fi]=Python-tietomoottori +Name[fr]=Moteur de données Python +Name[fy]=Python gegevens motor +Name[ga]=Inneall sonraí Python +Name[gl]=Motor de datos de Python +Name[gu]=પાયથોન માહિતી એન્જિન +Name[he]=מנוע תוכן של Python +Name[hi]=पायथन डाटा इंजिन +Name[hne]=पायथन डाटा इंजिन +Name[hr]=Pythonov podatkovni mehanizam +Name[hu]=Adatkezelő modul Python nyelven +Name[ia]=Motor de datos de Python +Name[id]=Mesin data Python +Name[is]=Python gagnavél +Name[it]=Motore di dati di Python +Name[ja]=Python データエンジン +Name[kk]=Python деректер тетігі +Name[km]=ម៉ាស៊ីន​ទិន្នន័យ Python +Name[kn]=ಪೈಥಾನ್ ದತ್ತಾಂಶ ಎಂಜಿನ್ +Name[ko]=파이썬 데이터 엔진 +Name[lt]=Python duomenų variklis +Name[lv]=Python datu dzinējs +Name[ml]=പൈത്തണ്‍ ഡേറ്റാ എഞ്ചിന്‍ +Name[mr]=Python माहिती इन्जीन +Name[nb]=Python datamotor +Name[nds]=Python-Datenkarn +Name[nl]=Python (gegevensengine) +Name[nn]=Python-datamotor +Name[or]=ପାଇଥନ ତଥ୍ୟ ମେସିନ +Name[pa]=ਪਾਈਥਨ ਡਾਟਾ ਇੰਜਣ +Name[pl]=Silnik danych w Pythonie +Name[pt]=Motor de dados Python +Name[pt_BR]=Mecanismo de dados Python +Name[ro]=Motor de date Python +Name[ru]=Источник данных на языке Python +Name[si]=Python data engine +Name[sk]=Python dátový nástroj +Name[sl]=Podatkovni vir v Pythonu +Name[sr]=питонски датомотор +Name[sr@ijekavian]=питонски датомотор +Name[sr@ijekavianlatin]=Python datomotor +Name[sr@latin]=Python datomotor +Name[sv]=Python datagränssnitt +Name[ta]=Python data engine +Name[tg]=Системаи санаи Python +Name[th]=กลไกข้อมูลภาษาไพธอน +Name[tr]=Python veri motoru +Name[ug]=Python سانلىق-مەلۇمات ماتورى +Name[uk]=Рушій даних Python +Name[wa]=Moteur di dnêyes Python +Name[x-test]=xxPython data enginexx +Name[zh_CN]=Python 数据引擎 +Name[zh_TW]=Python 資料引擎 +Comment=Plasma data engine support for Python +Comment[ar]=دعم محرك بيانات بلازما للبايثون +Comment[ast]=Sofitu del motor de datos de plasma pa Python +Comment[be@latin]=Absłuhoŭvańnie systemy źviestak „Plasma” u movie „Python” +Comment[bg]=Поддръжка за създаване на ядра за данни на Plasma с Python +Comment[bs]=Podrška plazma pogona podataka za Python +Comment[ca]=Implementació de motor de dades del Plasma per al Python +Comment[ca@valencia]=Implementació de motor de dades del Plasma per al Python +Comment[cs]=Podpora datového rozhraní Plasmy v Pythonu +Comment[da]=Plasma datamotor-understøttelse af Python +Comment[de]=Unterstützung für Plasma-Datentreiber in Python +Comment[el]=Υποστήριξη μηχανής δεδομένων Plasma για την Python +Comment[en_GB]=Plasma data engine support for Python +Comment[eo]=Plasma datummotora apogo por Pitono +Comment[es]=Soporte del motor de datos de plasma para Python +Comment[et]=Plasma andmemootori toetus Pythonile +Comment[eu]=Python-erako Plasmaren datu-motorraren euskarria +Comment[fi]=Plasma-tietomoottorituki Python-kielelle +Comment[fr]=Prise en charge du moteur de données Python pour Plasma +Comment[fy]=Plasma-gegevensmotor-stipe foar Python +Comment[ga]=Tacaíocht innill sonraí Plasma le haghaidh Python +Comment[gl]=Motor de datos de Plasma para dar soporte a Python +Comment[gu]=પાયથોન માટે પ્લાઝમા માહિતી એન્જિન આધાર +Comment[he]=תמיכה במנועי תוכן של Plasma עבור Python +Comment[hi]=पायथन के लिए प्लाज्मा डाटा इंजिन समर्थन +Comment[hne]=पायथन बर प्लाज्मा डाटा इंजिन सपोर्ट +Comment[hr]=Plasmin podatkovni mehanizam koji podržava Python +Comment[hu]=Plazma adatkezelő modul Pythonhoz +Comment[ia]=Supporto de motor de datos de Plasma pro Python +Comment[id]=Mesin data Plasma didukung oleh Python +Comment[is]=Plasma gagnavélarstuðningur fyrir Python +Comment[it]=Supporto al motore di dati di Plasma per Python +Comment[ja]=Python のための Plasma データエンジンのサポート +Comment[kk]=Python деректер тетігінің Plasma қолдауы +Comment[km]=កា​រគាំទ្រ​ម៉ាស៊ីន​ទិន្នន័យ​ប្លាស្មា​សម្រាប់ Python +Comment[kn]=ಪೈಥಾನ್‌ಗಾಗಿ ಪ್ಲಾಸ್ಮಾ ದತ್ತ ಸಾಧನದ ಬೆಂಬಲ +Comment[ko]=파이썬을 위한 Plasma 데이터 엔진 지원 +Comment[lt]=Plasma duomenų variklio palaikymas Python kalbai +Comment[lv]=Plasma datu dzinēju atbalsts Python +Comment[ml]=പൈത്തിണിനുള്ള പ്ലാസ്മ ഡാറ്റാഎഞ്ചിന്‍ പിന്തുണ +Comment[mr]=Python करिता Plasma माहिती इन्जीन समर्थन +Comment[nb]=Plasma datamotor-støtte for Python +Comment[nds]=Plasma-Datenkarnünnerstütten för Python +Comment[nl]=Plasma-gegevensengine-ondersteuning voor Python +Comment[nn]=Plasma-datamotorstøtte for Python +Comment[or]=ପାଇଥନ ପାଇଁ ପ୍ଲାଜମା ତଥ୍ୟ ମେସିନ ସମର୍ଥନ +Comment[pa]=ਪਾਈਥਨ ਲਈ ਪਲਾਜ਼ਮਾ ਡਾਟਾ ਇੰਜਣ ਸਹਿਯੋਗ +Comment[pl]=Obsługa silnika danych Plazmy w Pythonie +Comment[pt]=Suporte para os motores de dados do Plasma em Python +Comment[pt_BR]=Suporte aos mecanismos de dados em Python +Comment[ro]=Suport motor de date Plasma pentru Python +Comment[ru]=Поддержка источников данных для Python +Comment[si]=Plasma data engine support for Python +Comment[sk]=Podpora dátového nástroja plasmy pre Python +Comment[sl]=Podpora za podatkovne vire napisane v Pythonu +Comment[sr]=Подршка плазма датомотора за питон +Comment[sr@ijekavian]=Подршка плазма датомотора за питон +Comment[sr@ijekavianlatin]=Podrška plasma datomotora za Python +Comment[sr@latin]=Podrška plasma datomotora za Python +Comment[sv]=Plasma datagränssnittstöd för Python +Comment[ta]=Plasma data engine support for Python +Comment[te]=ఫైథాన్ మద్దతుకొరకు ప్లాస్మా డాటా యింజన్ +Comment[tg]=Пуштибонии Python дар асоси маълумоти Plasma +Comment[th]=กลไกข้อมูลของพลาสมาที่เป็นภาษาไพธอน +Comment[tr]=Python için Plasma veri motoru desteği +Comment[ug]=Python نىڭ Plasma سانلىق-مەلۇمات ماتورىنى قوللىشى +Comment[uk]=Підтримка у рушіях даних для Python +Comment[wa]=Sopoirt po Python do moteur di dnêyes di Plasma +Comment[x-test]=xxPlasma data engine support for Pythonxx +Comment[zh_CN]=Python 的 Plasma 数据引擎支持 +Comment[zh_TW]=支援 Python 的 Plasma 資料引擎 + +X-KDE-ServiceTypes=Plasma/ScriptEngine +Type=Service +Icon=text-x-script +X-KDE-Library=kpythonpluginfactory +X-KDE-PluginKeyword=plasma_scriptengine_python/pydataengine.py +X-EngineName=pythondataengine +X-Plasma-API=python +X-Plasma-ComponentTypes=DataEngine diff --git a/src/scriptengines/python/plasma-scriptengine-runner-python.desktop b/src/scriptengines/python/plasma-scriptengine-runner-python.desktop new file mode 100644 index 000000000..c9fb81d0c --- /dev/null +++ b/src/scriptengines/python/plasma-scriptengine-runner-python.desktop @@ -0,0 +1,135 @@ +[Desktop Entry] +Name=Python Runner +Name[ar]=مشغل بايثون +Name[ast]=Llanzador Python +Name[bg]=Стартер с Python +Name[bs]=Python izvođač +Name[ca]=Executor en Python +Name[ca@valencia]=Executor en Python +Name[cs]=Python spouštěč +Name[da]=Python Runner +Name[de]=Python-Starter +Name[el]=Εκτελεστής Python +Name[en_GB]=Python Runner +Name[eo]=Pitona motoro +Name[es]=Lanzador Python +Name[et]=Pythoni käivitaja +Name[eu]=Python abiarazlea +Name[fi]=Python-suoritusohjelma +Name[fr]=Lanceur Python +Name[ga]=Feidhmitheoir Python +Name[gl]=Executor en Python +Name[gu]=Python રનર +Name[he]=Python Runner +Name[hi]=पायथन रनर +Name[hr]=Python Runner +Name[hu]=Python-indító +Name[ia]=Executor de Python +Name[id]=Pelari Python +Name[is]=Python keyrari +Name[it]=Esecutore per Python +Name[ja]=Python ラナー +Name[kk]=Python-ды жегу +Name[km]=កម្មវិធី​រត់ Python +Name[kn]=ಪೈಥಾನ್ ರನ್ನರ್ +Name[ko]=파이썬 실행기 +Name[lt]=Python leistukas +Name[lv]=Python darbinātājs +Name[mr]=पायथोन रनर +Name[nb]=Python-kjører +Name[nds]=Python-Dreger +Name[nl]=Python-starter +Name[nn]=Python-køyrar +Name[pa]=ਪਾਈਥਨ ਰਨਰ +Name[pl]=Uruchamianie w Pythonie +Name[pt]=Módulo de Execução em Python +Name[pt_BR]=Execução em Python +Name[ro]=Executor Python +Name[ru]=Модули запуска команд на языке Python +Name[si]=Python ධාවකය +Name[sk]=Python spúšťač +Name[sl]=Zaganjalnik v Pythonu +Name[sr]=питонски извођач +Name[sr@ijekavian]=питонски извођач +Name[sr@ijekavianlatin]=Python izvođač +Name[sr@latin]=Python izvođač +Name[sv]=Python körningsprogram +Name[tg]=Системаи санаи Python +Name[th]=ตัวเรียกใช้โปรแกรมภาษาไพธอน +Name[tr]=Python Çalıştırıcı +Name[ug]=Python ئىجراچىسى +Name[uk]=Запуск для Python +Name[wa]=Enondeu Python +Name[x-test]=xxPython Runnerxx +Name[zh_CN]=Python 运行器 +Name[zh_TW]=Python 執行器 +Comment=Plasma Runner support for Python +Comment[ar]=دعم مشغل بلازما لبايثون +Comment[ast]=Implementación de llanzador Plasma pa Python +Comment[bg]=Поддръжка за създаване на стартери на Plasma с Python +Comment[bs]=Podrška plazma izvođača za Python +Comment[ca]=Implementació de l'executor del Plasma per al Python +Comment[ca@valencia]=Implementació de l'executor del Plasma per al Python +Comment[cs]=Podpora Plasma spouštěče pro Python +Comment[da]=Understøttelse af Plasma Runner til Python +Comment[de]=Plasma-Starter-Unterstützung für Python +Comment[el]=Υποστήριξη εκτελεστή Plasma για την Python +Comment[en_GB]=Plasma Runner support for Python +Comment[es]=Implementación de lanzador Plasma para Python +Comment[et]=Plasma käivitaja toetus Pythonile +Comment[eu]=Python-erako Plasmaren abiarazlearen euskarria +Comment[fi]=Plasma-suoritusohjelmatuki Python-kielelle +Comment[fr]=Prise en charge du lanceur Plasma pour Python +Comment[gl]=Executor de Plasma que permite usar Python +Comment[he]=תמיכה ב־Runner של Plasma עבור Python +Comment[hi]=पायथन के लिए प्लाज्मा रनर समर्थन +Comment[hr]=Plasma Runner podrška za Python +Comment[hu]=Plazma-indító támogatás Pythonhoz +Comment[ia]=Supporto de executor de Plasma pro Python +Comment[id]=Dukungan Pelari Plasma terhadap Python +Comment[is]=Plasma gagnavélarstuðningur fyrir Python +Comment[it]=Supporto per l'esecutore Plasma per Python +Comment[ja]=Python のための Plasma ラナーサポート +Comment[kk]=Plasma-дағы Python-ды жегуін қолдауы +Comment[km]=ការ​គាំទ្រ​កម្មវិធី​រត់​ប្លាស្មា​សម្រាប់ Python +Comment[kn]=ಪೈಥಾನ್‌ಗಾಗಿ ಪ್ಲಾಸ್ಮಾ ರನ್ನರ್ ಬೆಂಬಲ +Comment[ko]=Plasma 파이썬 실행기 +Comment[lt]=Plasma paleidiklio palaikymas Python kalbai +Comment[lv]=Plasma darbinātāja atbalsts Python +Comment[mr]=पायथोन करिता प्लाज्मा रनर समर्थन +Comment[nb]=Plasma kjørerstøtte for Python +Comment[nds]=Plasma-Dregerünnerstütten för Python +Comment[nl]=Plasma-starter-ondersteuning voor Python +Comment[nn]=Plasma-køyrarstøtte for Python +Comment[pa]=ਪਾਈਥਨ ਲਈ ਪਲਾਜ਼ਮਾ ਰਨਰ ਸਹਿਯੋਗ +Comment[pl]=Obsługa programów uruchamiających dla Pythona +Comment[pt]=Suporte para os motores de execução do Plasma em Python +Comment[pt_BR]=Suporte aos mecanismos de execução do Plasma para Python +Comment[ro]=Suport executori Plasma pentru Python +Comment[ru]=Поддержка модулей запуска KRunner на языке Python +Comment[si]=Python සඳහා ප්ලාස්මා ධාවක සහාය +Comment[sk]=Podpora spúšťača plasmy pre Python +Comment[sl]=Podpora za zaganjalnike napisane v Pythonu +Comment[sr]=Подршка плазма извођача за питон +Comment[sr@ijekavian]=Подршка плазма извођача за питон +Comment[sr@ijekavianlatin]=Podrška plasma izvođača za Python +Comment[sr@latin]=Podrška plasma izvođača za Python +Comment[sv]=Plasma körningsstöd för Python +Comment[tg]=Пуштибонии Python дар асоси маълумоти Plasma +Comment[th]=ตัวเรียกใช้งานของพลาสมาที่รองรับสำหรับโปรแกรมภาษาไพธอน +Comment[tr]=Python için Plasma Çalıştırıcı desteği +Comment[ug]=Python نى قوللايدىغان Plasma ئىجراچىسى +Comment[uk]=Підтримка Python у інструментах запуску +Comment[wa]=Sopoirt po Python di l' enondeu di Plasma +Comment[x-test]=xxPlasma Runner support for Pythonxx +Comment[zh_CN]=支持 Python 的 Plasma 运行器 +Comment[zh_TW]=支援 Python 的執行器 + +X-KDE-ServiceTypes=Plasma/ScriptEngine +Type=Service +Icon=text-x-script +X-KDE-Library=kpythonpluginfactory +X-KDE-PluginKeyword=plasma_scriptengine_python/pyrunner.py +X-EngineName=pythonrunner +X-Plasma-API=python +X-Plasma-ComponentTypes=Runner diff --git a/src/scriptengines/python/plasma_importer.py b/src/scriptengines/python/plasma_importer.py new file mode 100644 index 000000000..dae245aea --- /dev/null +++ b/src/scriptengines/python/plasma_importer.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2008 Simon Edwards +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library General Public License as +# published by the Free Software Foundation; either version 2, 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 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. +# + +import sys +import os +import imp + +PY3 = sys.version_info[0] == 3 + + +class PlasmaImporter(object): + def __init__(self): + self.toplevel = {} + self.toplevelcount = {} + self.marker = '' + str(id(self)) + sys.path.append(self.marker) + sys.path_hooks.append(self.hook) + + def hook(self,path): + if path==self.marker: + return self + else: + raise ImportError() + + def register_top_level(self,name,path): + if name not in self.toplevel: + self.toplevelcount[name] = 1 + self.toplevel[name] = path + else: + self.toplevelcount[name] += 1 + + def unregister_top_level(self,name): + value = self.toplevelcount[name]-1 + self.toplevelcount[name] = value + if value==0: + del self.toplevelcount[name] + del self.toplevel[name] + for key in list(sys.modules.keys()): + if key==name or key.startswith(name+"."): + del sys.modules[key] + + def find_module(self,fullname, path=None): + location = self.find_pymod(fullname) + if location is not None: + return self + else: + return None + + # Find the given module in the plasma directory. + # Result a tuple on success otherwise None. The tuple contains the location + # of the module/package in disk and a boolean indicating if it is a package + # or module + def find_pymod(self,modulename): + parts = modulename.split('.') + toppackage = parts[0] + rest = parts[1:] + + if toppackage in self.toplevel: + path = self.toplevel[toppackage] + if len(rest)==0: + # Simple top level Plasma package + return (path,True) + else: + restpath = apply(os.path.join,rest) + fullpath = os.path.join(path,'contents','code',restpath) + if os.path.isdir(fullpath): + return (fullpath,True) + elif os.path.exists(fullpath+'.py'): + return (fullpath+'.py',False) + else: + return None + + def _get_code(self,location): + return open(location).read() + + def load_module(self, fullname): + location,ispkg = self.find_pymod(fullname) + if ispkg: # Package dir. + initlocation = os.path.join(location,'__init__.py') + code = None + if os.path.isfile(initlocation): + code = open(initlocation) + else: + code = open(location) + + mod = sys.modules.setdefault(fullname, imp.new_module(fullname)) + mod.__file__ = location #"<%s>" % self.__class__.__name__ + mod.__loader__ = self + if ispkg: + mod.__path__ = [self.marker] + if code is not None: + try: + if PY3: + exec(code in mod.__dict__) + else: + exec code in mod.__dict__ + finally: + code.close() + return mod + +#plasma_importer = PlasmaImporter() +#plasma_importer.register_top_level('plasma_pyclock','/home/sbe/devel/python_plasma_2/test/plasma-pyclock') +#from plasma_pyclock import main diff --git a/src/scriptengines/python/plasmascript.py b/src/scriptengines/python/plasmascript.py new file mode 100644 index 000000000..ba149cf5e --- /dev/null +++ b/src/scriptengines/python/plasmascript.py @@ -0,0 +1,225 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2008 Simon Edwards +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library General Public License as +# published by the Free Software Foundation; either version 2, 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 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. +# + +# Plasma applet API for Python + +from PyQt4.QtCore import QObject +from PyQt4.QtGui import QGraphicsWidget +from PyKDE4.plasma import Plasma # Plasma C++ namespace + +#import sip +#import gc + +class Applet(QObject): + ''' Subclass Applet in your module and return an instance of it in a global function named + applet(). Implement the following functions to breathe life into your applet: + * paint - Draw the applet given a QPainter and some options + It provides the same API as Plasma.Applet; it just has slightly less irritating event names. ''' + def __init__(self, parent=None): + # this should be set when the applet is created + QObject.__init__(self, parent) + #sip.settracemask(0x3f) + self.applet = None + self.applet_script = None + self._forward_to_applet = True + + def __getattr__(self, key): + # provide transparent access to the real applet instance + if self._forward_to_applet: + try: + return getattr(self.applet_script, key) + except: + return getattr(self.applet, key) + else: + raise AttributeError(key) + + def _enableForwardToApplet(self): + self._forward_to_applet = True + def _disableForwardToApplet(self): + self._forward_to_applet = False + + # Events + def setApplet(self,applet): + self.applet = applet + + def setAppletScript(self,appletScript): + self.applet_script = appletScript + + def init(self): + pass + + def configChanged(self): + pass + + def paintInterface(self, painter, options, rect): + pass + + def constraintsEvent(self, flags): + pass + + def showConfigurationInterface(self): + self.dlg = self.standardConfigurationDialog() + self.createConfigurationInterface(self.dlg) + self.addStandardConfigurationPages(self.dlg) + self.dlg.show() + + def createConfigurationInterface(self, dlg): + pass + + def contextualActions(self): + return [] + + def shape(self): + return QGraphicsWidget.shape(self.applet) + + def initExtenderItem(self, item): + print ("Missing implementation of initExtenderItem in the applet " + \ + item.config().readEntry('SourceAppletPluginName', '').toString() + \ + "!\nAny applet that uses extenders should implement initExtenderItem to " + \ + "instantiate a widget.") + + def saveState(self, config): + pass + +########################################################################### +class DataEngine(QObject): + def __init__(self, parent=None): + QObject.__init__(self, parent) + self.dataengine = None + self.dataengine_script = None + + def setDataEngine(self,dataEngine): + self.dataEngine = dataEngine + + def setDataEngineScript(self,dataEngineScript): + self.data_engine_script = dataEngineScript + + def __getattr__(self, key): + # provide transparent access to the real dataengine script instance + try: + return getattr(self.data_engine_script, key) + except: + return getattr(self.dataEngine, key) + + def init(self): + pass + + def sources(self): + return [] + + def sourceRequestEvent(self,name): + return False + + def updateSourceEvent(self,source): + return False + + def serviceForSource(self,source): + return Plasma.DataEngineScript.serviceForSource(self.data_engine_script,source) + +########################################################################### +class Wallpaper(QObject): + def __init__(self, parent=None): + QObject.__init__(self, parent) + self.wallpaper = None + self.wallpaper_script = None + + def setWallpaper(self,wallpaper): + self.wallpaper = wallpaper + + def setWallpaperScript(self,wallpaperScript): + self.wallpaper_script = wallpaperScript + + def __getattr__(self, key): + # provide transparent access to the real wallpaper script instance + try: + return getattr(self.wallpaper_script, key) + except: + return getattr(self.wallpaper, key) + + def init(self, config): + pass + + def paint(self,painter, exposedRect): + pass + + def save(self,config): + pass + + def createConfigurationInterface(self,parent): + return None + + def mouseMoveEvent(self,event): + pass + + def mousePressEvent(self,event): + pass + + def mouseReleaseEvent(self,event): + pass + + def wheelEvent(self,event): + pass + + def renderCompleted(self, image): + pass + + def urlDropped(self, url): + pass + +########################################################################### +class Runner(QObject): + def __init__(self, parent=None): + QObject.__init__(self, parent) + self.runner = None + self.runner_script = None + + def setRunner(self,runner): + self.runner = runner + + def setRunnerScript(self,runnerScript): + self.runner_script = runnerScript + + def __getattr__(self, key): + # provide transparent access to the real runner script instance + try: + return getattr(self.runner_script, key) + except: + return getattr(self.runner, key) + + def init(self): + pass + + def match(self, search): + pass + + def run(self, search, action): + pass + + def prepare(self): + pass + + def teardown(self): + pass + + def createRunOptions(self, widget): + pass + + def reloadConfiguration(self): + pass diff --git a/src/scriptengines/python/pydataengine.py b/src/scriptengines/python/pydataengine.py new file mode 100644 index 000000000..edb93c9c9 --- /dev/null +++ b/src/scriptengines/python/pydataengine.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2008 Simon Edwards +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library General Public License as +# published by the Free Software Foundation; either version 2, 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 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. +# +from PyQt4.QtCore import * +from PyQt4.QtGui import * +from PyKDE4.plasma import Plasma +import plasma_importer +import os.path + +class PythonDataEngineScript(Plasma.DataEngineScript): + importer = None + + def __init__(self, parent): + Plasma.DataEngineScript.__init__(self,parent) + if PythonDataEngineScript.importer is None: + PythonDataEngineScript.importer = plasma_importer.PlasmaImporter() + self.initialized = False + + def init(self): + self.moduleName = str(self.dataEngine().pluginName()) + self.pluginName = 'dataengine_' + self.moduleName.replace('-','_') + + PythonDataEngineScript.importer.register_top_level(self.pluginName, str(self.dataEngine().package().path())) + + # import the code at the file name reported by mainScript() + relpath = os.path.relpath(str(self.mainScript()),str(self.dataEngine().package().path())) + if relpath.startswith("contents/code/"): + relpath = relpath[14:] + if relpath.endswith(".py"): + relpath = relpath[:-3] + relpath = relpath.replace("/",".") + self.module = __import__(self.pluginName+'.'+relpath) + # The script may not necessarily be called "main" + # So we use __dict__ to look up the right name + basename = os.path.basename(str(self.mainScript())) + basename = os.path.splitext(basename)[0] + + self.pydataengine = self.module.__dict__[basename].CreateDataEngine(None) + self.pydataengine.setDataEngine(self.dataEngine()) + self.pydataengine.setDataEngineScript(self) + self.pydataengine.init() + + self.initialized = True + return True + + def __dtor__(self): + PythonDataEngineScript.importer.unregister_top_level(self.pluginName) + self.pydataengine = None + + def sources(self): + return self.pydataengine.sources() + + def serviceForSource(self,source): + return self.pydataengine.serviceForSource(source) + + def sourceRequestEvent(self,name): + return self.pydataengine.sourceRequestEvent(name) + + def updateSourceEvent(self,source): + return self.pydataengine.updateSourceEvent(source) + +def CreatePlugin(widget_parent, parent, component_data): + return PythonDataEngineScript(parent) diff --git a/src/scriptengines/python/pyrunner.py b/src/scriptengines/python/pyrunner.py new file mode 100644 index 000000000..e520e307e --- /dev/null +++ b/src/scriptengines/python/pyrunner.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2008 Simon Edwards +# Copyright 2009 Petri Damstén +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library General Public License as +# published by the Free Software Foundation; either version 2, 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 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. +# +from PyQt4.QtCore import * +from PyQt4.QtGui import * +from PyKDE4.plasma import Plasma +import plasma_importer +import os.path + +class PythonRunnerScript(Plasma.RunnerScript): + importer = None + + def __init__(self, parent): + Plasma.RunnerScript.__init__(self,parent) + if PythonRunnerScript.importer is None: + PythonRunnerScript.importer = plasma_importer.PlasmaImporter() + self.initialized = False + + def init(self): + self.moduleName = str(self.runner().package().metadata().pluginName()) + self.pluginName = 'runner_' + self.moduleName.replace('-','_') + + PythonRunnerScript.importer.register_top_level(self.pluginName, str(self.runner().package().path())) + + # import the code at the file name reported by mainScript() + relpath = os.path.relpath(str(self.mainScript()),str(self.runner().package().path())) + if relpath.startswith("contents/code/"): + relpath = relpath[14:] + if relpath.endswith(".py"): + relpath = relpath[:-3] + relpath = relpath.replace("/",".") + self.module = __import__(self.pluginName+'.'+relpath) + basename = os.path.basename(str(self.mainScript())) + basename = os.path.splitext(basename)[0] + self.pyrunner = self.module.__dict__[basename].CreateRunner(None) + self.pyrunner.setRunner(self.runner()) + self.pyrunner.setRunnerScript(self) + self.connect(self, SIGNAL('prepare()'), self, SLOT('prepare()')) + self.connect(self, SIGNAL('teardown()'), self, SLOT('teardown()')) + self.connect(self, SIGNAL('createRunOptions(QWidget*)'), + self, SLOT('createRunOptions(QWidget*)')) + self.connect(self, SIGNAL('reloadConfiguration()'), + self, SLOT('reloadConfiguration()')) + self.pyrunner.init() + + self.initialized = True + return True + + def __dtor__(self): + PythonRunnerScript.importer.unregister_top_level(self.pluginName) + self.pyrunner = None + + def match(self, search): + self.pyrunner.match(search) + + def run(self, search, action): + self.pyrunner.run(search, action) + + @pyqtSignature("prepare()") + def prepare(self): + self.pyrunner.prepare() + + @pyqtSignature("teardown()") + def teardown(self): + self.pyrunner.teardown() + + @pyqtSignature("createRunOptions(QWidget*)") + def createRunOptions(self, widget): + self.pyrunner.createRunOptions(widget) + + @pyqtSignature("reloadConfiguration()") + def reloadConfiguration(self): + self.pyrunner.reloadConfiguration() + +def CreatePlugin(widget_parent, parent, component_data): + return PythonRunnerScript(parent) diff --git a/src/scriptengines/ruby/CMakeLists.txt b/src/scriptengines/ruby/CMakeLists.txt new file mode 100644 index 000000000..f040afc74 --- /dev/null +++ b/src/scriptengines/ruby/CMakeLists.txt @@ -0,0 +1,4 @@ +install(FILES data_engine.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_scriptengine_ruby) + +install(FILES plasma-scriptengine-ruby-dataengine.desktop DESTINATION ${SERVICES_INSTALL_DIR}) + diff --git a/src/scriptengines/ruby/ChangeLog b/src/scriptengines/ruby/ChangeLog new file mode 100644 index 000000000..24df1d187 --- /dev/null +++ b/src/scriptengines/ruby/ChangeLog @@ -0,0 +1,140 @@ +2010-02-14 Richard Dale + +* Special case the constructors of the new Plasma widgets so that they can be +passed a PlasmaScripting::Applet as parent +* Fixed the dialog handling so that it uses the standardConfigurationDialog() +and addStandardConfigurationPages() methods + +2009-08-07 Richard Dale +* Fixed typo in the type signature of the initExtenderItem() slot. Thanks to +David Palacio for reporting the bug + +2009-07-19 Richard Dale +* Use the new name 'extenderItemRestored()' for the signal to connect to +initExtenderItem() + +2009-07-18 Richard Dale +* Add a Ruby version of the C++ extender tutorial example on Techbase + +2009-07-17 Richard Dale +* If an applet has implemented an initExtenderItem() method, then connect the +new initScriptingExtenderItem() signal to it. + +2009-06-16 Richard Dale +* The resize() method doesn't work with scripting plasmoids, so if it is used +output a warning message, and suggest adding a X-Plasma-DefautSize entry in +the metadata.desktop file. + +2009-05-26 Richard Dale +* Add a callback for the configChanged() method in scripting applets + +2009-04-27 Richard Dale +* Added some special casing for the new KDE 4.3 widgets, so they work with +PLasmaScripting::Applet arguments + +2009-04-22 Richard Dale +* Added PlasmaScripting::Containment and PlasmaScripting::PopupApplet classes, + now that scripting containments and popups can be created + +2009-02-10 Richard Dale +* For the methods that need to be special cased to work with + PlasmaScripting::Applet type arguments, add lower case/underscore versions + of the methods + +2009-02-05 Richard Dale +* Added various special casing to the Plasma::ToolTipManager class so you can + pass a PlasmaScripting::Applet to the methods. Thanks to Mathieu Jobin for + reporting the bug. + +2008-12-22 Richard Dale +* Changed the tiger applet example to find its tiger.svg resource from within + the plasmoid package. Thanks to Rany Keddo for helping to get it working. + +2008-12-01 Richard Dale +* Added updateAllSources() and removeSource() slots to the + PlasmScripting::DataEngine +* Add DBus notification to the time data engine example for when the config + changes + +2008-11-18 Richard Dale +* Fix problem with the ruby 'type()' method clashing with the one in + Qt::GraphicsItem subclasses reported by David Palacio +* Added a 'dbpedia-queries' data engine for making SPARQL queries to DBpedia + about music albums +* The sources() and init() methods needn't be implemented by a scripting + data engine + +2008-11-17 Richard Dale +* Fixed missing constructor bug in Qt::GraphicsProxyWidget reported by David + Palacio. Thanks to David for reporting the bug. +* Improved the names of the Ruby applet and dataengine examples +* Allow a PlasmaScripting::Applet to be a parent of all the Qt::GraphicsItem + sub classes in their constructors + +2008-11-05 Richard Dale +* Fixed some bugs in the DataEngineScript class. The expected path was + 'plasma/engines' whereas the plasmapkg tool installs them in + 'plasma/dataengines'. The mainScript() and package() methods hadn't been + implemented and were added. +* Added a 'ruby_time' example scripting data engine + +2008-10-30 Richard Dale +* Separated the script engine plugins from the plasma ruby extension and moved + the script engine code to kdebase with the other script engines + +2008-10-23 Richard Dale +* Converted the webapplet to use the script engine api, and renamed it + plasma_applet_ruby_webapplet + +2008-08-15 Richard Dale +* Re-added the ruby version of the plasmoidviewer app + +2008-08-12 Arno Rehn +* Fix restoring of applet sizes. + +2008-08-07 Richard Dale +* The marshaller for Plasma::DataEngine::Data was creating Qt::Variants with + the wrong smoke pointer in the smokeruby_object struct, and this was causing + a crash in the GC marking function. +* In PlasmaScripting::Applet, if a constant such as NoBackground is referenced + and found to be missing, then look for it in Plasma::Applet. +* Fix bugs in the PlasmaScripting::Applet#showConfigurationInterface method +* Special case Plasma::Applet#id so it doesn't get a Ruby warning. +* In PlasmaScriptengineRuby::Applet the module name wasn't being derived + correctly from the Package path +* Add two versions of the clock applet + * plasma_applet_ruby_clock uses the ScriptEngine api and is packaged as a + plasmoid. It can be installed by typing the following command in the + examples/applets directory: + + $ plasmapkg --install plasma_applet_ruby_clock --type plasmoid + + * analog-clock uses the C++ plugin api. Normally Ruby applets should be + written using the script engine api, and this example is only included + to show how the two apis differ. The clocks are functionally identical. + +2008-08-06 Richard Dale +* Add some fixes for the new Plasma::Frame and Plasma::Slider widgets + +2008-07-03 Richard Dale +* Add slots and signals for scripting applets and data engines corresponding + to the ones in Plasma::Applet and Plasma::DataEngine +* Change the install destination to plasma_scriptengine_ruby and the modules + of the plugin classes to match + +2008-06-30 Richard Dale +* For script engine based applets, add the directory where the mainScript was + found to the ruby load path. + +2008-06-29 Richard Dale +* If a method call is invoked on a PlasmaScripting::Applet, then relay it to + the underlying Plasma::Applet in the script engine. +* Add an event filter to the RubyAppletScript::Applet class so that scripting + applets can implement event method handling overrides. +* Change various methods in the QGraphicsView and Plasma api so that they can + accept instances of PlasmaScripting::Applet, and the instance is substituted + for the underlying Plasma::Applet in the ScriptEngine. + +2008-06-28 Richard Dale +* Make the Ruby ScriptEngine based plugins work +* Add a Ruby version of the Javascript Tiger applet diff --git a/src/scriptengines/ruby/data_engine.rb b/src/scriptengines/ruby/data_engine.rb new file mode 100644 index 000000000..459c9cc9b --- /dev/null +++ b/src/scriptengines/ruby/data_engine.rb @@ -0,0 +1,147 @@ +=begin + * Copyright 2008 by Richard Dale + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 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. +=end + +require 'plasma_applet' + +module PlasmaScripting + class DataEngine < Qt::Object + slots :updateAllSources, "removeSource(QString)" + signals "sourceAdded(QString)", "sourceRemoved(QString)" + + attr_accessor :data_engine_script + + def initialize(parent, args = nil) + super(parent) + @data_engine_script = parent + connect(@data_engine_script.dataEngine, SIGNAL("sourceAdded(QString)"), self, SIGNAL("sourceAdded(QString)")) + connect(@data_engine_script.dataEngine, SIGNAL("sourceRemoved(QString)"), self, SIGNAL("sourceRemoved(QString)")) + end + + def init + end + + def sourceRequestEvent(name) + end + + def updateSourceEvent(source) + end + + def setData(*args) + if args.length == 2 && !args[1].kind_of?(Qt::Variant) + args[1] = Qt::Variant.fromValue(args[1]) + elsif args.length == 3 && !args[2].kind_of?(Qt::Variant) + args[2] = Qt::Variant.fromValue(args[2]) + end + @data_engine_script.setData(*args) + end + + def removeAllData(source) + @data_engine_script.removeAllData(source) + end + + def removeData(source, key) + @data_engine_script.removeData(source, key) + end + + def setMaxSourceCount(limit) + @data_engine_script.setMaxSourceCount(limit) + end + + def maxSourceCount=(limit) + setMaxSourceCount(limit) + end + + def setMinimumPollingInterval(minimumMs) + @data_engine_script.setMinimumPollingInterval(minimumMs) + end + + def minimumPollingInterval=(minimumMs) + setMinimumPollingInterval(minimumMs) + end + + def minimumPollingInterval + @data_engine_script.minimumPollingInterval + end + + def setPollingInterval(frequency) + @data_engine_script.setPollingInterval(frequency) + end + + def pollingInterval=(frequency) + setPollingInterval(frequency) + end + + def removeAllSources + @data_engine_script.removeAllSources + end + + def sources + return [] + end + + def removeSource(source) + @data_engine_script.dataEngine.removeSource(source) + end + + def updateAllSources + @data_engine_script.dataEngine.updateAllSources + end + end +end + +module PlasmaScriptengineRuby + class DataEngine < Plasma::DataEngineScript + def initialize(parent, args) + super(parent) + end + + def camelize(str) + str.gsub(/(^|[._-])(.)/) { $2.upcase } + end + + def init + puts "RubyAppletScript::DataEngine#init mainScript: #{mainScript}" + program = Qt::FileInfo.new(mainScript) + $: << program.path + load Qt::File.encodeName(program.filePath).to_s + moduleName = camelize(Qt::Dir.new(package.path).dirName) + className = camelize(program.baseName) + puts "RubyAppletScript::DataEngine#init instantiating: #{moduleName}::#{className}" + klass = Object.const_get(moduleName.to_sym).const_get(className.to_sym) + @data_engine_script = klass.new(self) + @data_engine_script.init + return true + end + + def sources + @data_engine_script.sources + end + + def sourceRequestEvent(name) + @data_engine_script.sourceRequestEvent(name) + end + + def updateSourceEvent(source) + @data_engine_script.updateSourceEvent(source) + end + end +end + +# kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; + diff --git a/src/scriptengines/ruby/plasma-scriptengine-ruby-dataengine.desktop b/src/scriptengines/ruby/plasma-scriptengine-ruby-dataengine.desktop new file mode 100644 index 000000000..735589f8b --- /dev/null +++ b/src/scriptengines/ruby/plasma-scriptengine-ruby-dataengine.desktop @@ -0,0 +1,152 @@ +[Desktop Entry] +Name=Ruby Widget +Name[ar]=ودجة روبي +Name[ast]=Elementu gráficu en Ruby +Name[be@latin]=Widžet u movie „Ruby” +Name[bg]=Джаджа на Ruby +Name[bn]=রুবি উইজেট +Name[bn_IN]=Ruby উইজেট +Name[bs]=Ruby grafička kontrola +Name[ca]=Estri Ruby +Name[ca@valencia]=Estri Ruby +Name[cs]=Ruby widget +Name[csb]=Interfejs Ruby +Name[da]=Ruby-widget +Name[de]=Ruby-Miniprogramm +Name[el]=Συστατικό Ruby +Name[en_GB]=Ruby Widget +Name[eo]=Ruby-fenestraĵo +Name[es]=Elemento gráfico en Ruby +Name[et]=Ruby vidin +Name[eu]=Ruby trepeta +Name[fi]=Ruby-sovelma +Name[fr]=Composant graphique Ruby +Name[fy]=Ruby widget +Name[ga]=Giuirléid Ruby +Name[gl]=Widget escrito en Ruby +Name[gu]=રૂબી વિજેટ +Name[he]=ווידג׳ט של Ruby +Name[hi]=रूबी विज़ेट +Name[hne]=रूबी विजेट +Name[hr]=Ruby widget +Name[hu]=Ruby-elem +Name[ia]=Elemento graphic (Widget) de Ruby +Name[id]=Widget Ruby +Name[is]=Ruby græja +Name[it]=Oggetto Ruby +Name[ja]=Ruby ウィジェット +Name[kk]=Ruby бөлшегі +Name[km]=ធាតុក្រាហ្វិក​ +Name[kn]=ರೂಬಿ ನಿಯಂತ್ರಣಾ ಸಂಪರ್ಕತಟ (ವಿಡ್ಗೆಟ್) +Name[ko]=루비 위젯 +Name[ku]=Alava Ruby +Name[lt]=Ruby valdiklis +Name[lv]=Ruby sīkrīks +Name[ml]=റൂബി ഉരുപ്പടി +Name[mr]=Ruby विजेट +Name[nb]=Ruby-element +Name[nds]=Ruby-Lüttprogramm +Name[nl]=Ruby-widget +Name[nn]=Ruby-element +Name[or]=ରୁବି ୱିଜେଟ +Name[pa]=ਰੂਬੀ ਵਿਦਜੈੱਟ +Name[pl]=Element interfejsu w języku Ruby +Name[pt]=Elemento Ruby +Name[pt_BR]=Widget Ruby +Name[ro]=Control Ruby +Name[ru]=Виджет на языке Ruby +Name[si]=Ruby මෙවලම් +Name[sk]=Ruby widget +Name[sl]=Gradnik v Ruby +Name[sr]=рубијевски виџет +Name[sr@ijekavian]=рубијевски виџет +Name[sr@ijekavianlatin]=ruby vidžet +Name[sr@latin]=ruby vidžet +Name[sv]=Grafisk Ruby-komponent +Name[ta]=Ruby Widget +Name[tg]=Илова ба Ruby +Name[th]=วิดเจ็ตภาษารูบี้ +Name[tr]=Ruby Gereci +Name[ug]=Ruby ۋىجېتى +Name[uk]=Віджет Ruby +Name[wa]=Ahesse Ruby +Name[x-test]=xxRuby Widgetxx +Name[zh_CN]=Ruby 部件 +Name[zh_TW]=Ruby 元件 +Comment=Native Plasma widget written in Ruby +Comment[ar]=وجة بلازما أصلية مكتوبة بروبي +Comment[ast]=Elementu gráficu nativu de Plasma escrito en Ruby +Comment[be@latin]=Rodny widžet systemy „Plasma”, napisany ŭ movie „Ruby” +Comment[bg]=Оригинална джаджа за Plasma, написана на Ruby +Comment[bs]=Samosvojni plazma grafička kontrola napisana u Ruby-ju +Comment[ca]=Estri nadiu del Plasma escrit en Ruby +Comment[ca@valencia]=Estri nadiu del Plasma escrit en Ruby +Comment[cs]=Nativní plasmoid napsaný v Ruby +Comment[da]=Ægte Plasma-widget skrevet i Ruby +Comment[de]=Echtes Plasma-Programm, geschrieben in Ruby +Comment[el]=Εγγενές συστατικό Plasma γραμμένο σε Ruby +Comment[en_GB]=Native Plasma widget written in Ruby +Comment[es]=Elemento gráfico nativo de Plasma escrito en Ruby +Comment[et]=Rubys kirjutatud Plasma vidin +Comment[eu]=Jatorrizko Plasma trepeta, Ruby lengoaian idatzia +Comment[fi]=Natiivi, Ruby-pohjainen Plasma-sovelma +Comment[fr]=Composant graphique natif de Plasma écrit en Ruby +Comment[fy]=Plasma widget skreaun yn Ruby +Comment[ga]=Giuirléid dhúchasach Plasma scríofa i Ruby +Comment[gl]=Widget nativo de Plasma escrito en Ruby +Comment[gu]=રૂબીમાં લખાયેલ મૂળભૂત પ્લાઝમા વિજેટ +Comment[he]=ווידג׳ט Plasma הנכתב ב־Ruby +Comment[hi]=रूबी में लिखा गया नेटिव प्लाज्मा विजेट +Comment[hne]=रुबी मं लिखे नेटिव प्लाज्मा विजेट +Comment[hr]=Izvorna Plasma widget napisana u Rubyu +Comment[hu]=Plasma-elem Ruby nyelven +Comment[ia]=Elemento graphic (widget) native de Plasma scribite in Ruby +Comment[id]=Widget Plasma asli yang ditulis dalam Ruby +Comment[is]=Upprunabundin Plasma græja skrifuð í Ruby +Comment[it]=Oggetto nativo di Plasma scritto in Ruby +Comment[ja]=Ruby で書かれた Plasma のネイティブウィジェット +Comment[kk]=Ruby-дег жазылған Plasma интерфейс бөлшегі +Comment[km]=ធាតុក្រាហ្វិក​ប្លាស្មា​ដើម​បាន​សរសេរ​នៅ​ក្នុង Ruby +Comment[kn]=ರೂಬಿಯಲ್ಲಿ ಬರೆಯಲಾದ ಸ್ಥಳೀಯ ಪ್ಲಾಸ್ಮಾ ನಿಯಂತ್ರಣಾ ಸಂಪರ್ಕತಟ (ವಿಡ್ಗೆಟ್) +Comment[ko]=루비로 작성된 Plasma 위젯 +Comment[lt]=Nuosavas Plasma valdiklis parašytas Ruby kalba +Comment[lv]=Plasma sīkrīks, rakstīts Ruby +Comment[ml]=റൂബിയില്‍ തയ്യാറാക്കിയിരിക്കുന്ന നേറ്റീവ് പ്ലാസ്മാ ഉരുപ്പടി +Comment[mr]=Ruby अंतर्गत लिहीले गेलेले मूळ Plasma विजेट +Comment[nb]=Plasmaelement for dette systemet, skrevet i Ruby +Comment[nds]=En orginaal Plasmaelement, schreven in Ruby +Comment[nl]=Plasma-widget geschreven in Ruby +Comment[nn]=Lokalt Plasma-element skrive i Ruby +Comment[or]=Ruby ରେ ଲେଖା ହୋଇଥିବା ସ୍ଥାନୀୟ ପ୍ଲାଜମା ୱିଜେଟ +Comment[pa]=ਰੂਬੀ ਵਿੱਚ ਲਿਖੇ ਨੇਟਿਵ ਪਲਾਜ਼ਮਾ ਵਿਦਜੈੱਟ +Comment[pl]=Element interfejsu Plazmy napisany w języku Ruby +Comment[pt]=Elemento nativo do Plasma feito em Ruby +Comment[pt_BR]=Widget nativo do Plasma, escrito em Ruby +Comment[ro]=Miniaplicație Plasma scrisă în Ruby +Comment[ru]=Виджет Plasma, написанный на языке Ruby +Comment[si]=Native Plasma widget written in Ruby +Comment[sk]=Natívny plasma widget napísaný v Ruby +Comment[sl]=Lastni gradnik za Plasmo, ki je napisan v Rubyu +Comment[sr]=Самосвојни плазма виџет написан у рубију +Comment[sr@ijekavian]=Самосвојни плазма виџет написан у рубију +Comment[sr@ijekavianlatin]=Samosvojni plasma vidžet napisan u Rubyju +Comment[sr@latin]=Samosvojni plasma vidžet napisan u Rubyju +Comment[sv]=Inbyggd grafisk Plasma-komponent skriven i Ruby +Comment[ta]=Native Plasma widget written in Ruby +Comment[tg]=Модуль Plasma, написанный на языке JavaScript +Comment[th]=วิดเจ็ตพลาสมาแท้ที่ถูกเขียนด้วยภาษารูบี้ +Comment[tr]=Ruby ile yazılmış gerçek Plasma gereci +Comment[ug]=Ruby بىلەن يېزىلغان ئەسلى Plasma كىچىك ئەپ +Comment[uk]=Віджет Плазми, написаний на Ruby +Comment[wa]=Ahesse askepieye po Plasma eyet scrîte e Ruby +Comment[x-test]=xxNative Plasma widget written in Rubyxx +Comment[zh_CN]=使用 Ruby 编写的原生 Plasma 部件 +Comment[zh_TW]=用 Ruby 寫的原始 Plasma 元件 +X-KDE-ServiceTypes=Plasma/ScriptEngine +Type=Service +Icon=text-x-script +X-KDE-Library=krubypluginfactory +X-KDE-PluginKeyword=plasma_scriptengine_ruby/data_engine.rb +X-EngineName=ruby-dataengine-script +X-Plasma-API=ruby-script +X-Plasma-ComponentTypes=DataEngine diff --git a/tools/port-cmake.sh b/tools/port-cmake.sh index cfcc0be8e..571429777 100755 --- a/tools/port-cmake.sh +++ b/tools/port-cmake.sh @@ -37,8 +37,8 @@ for FS in `find $PWD -type f -name 'CMakeLists.txt'`; do perl -p -i -e 's/\$\{KDE4_SOLID_LIBS\}/KF5\:\:Solid/g' $FS perl -p -i -e 's/\$\{KDE4_KIO_LIBS\}/KF5\:\:KIOWidgets/g' $FS perl -p -i -e 's/\$\{KDE4_KNOTIFYCONFIG_LIBRARY\}/KF5\:\:NotifyConfig/g' $FS - perl -p -i -e 's/\$\{KDE4_KNEWSTUFF3_LIBRARY\}/KF5\:\KNewStuff/g' $FS - perl -p -i -e 's/\$\{KDE4_KNEWSTUFF3_LIBS\}/KF5\:\KNewStuff/g' $FS + perl -p -i -e 's/\$\{KDE4_KNEWSTUFF3_LIBRARY\}/KF5\:\:NewStuff/g' $FS + perl -p -i -e 's/\$\{KDE4_KNEWSTUFF3_LIBS\}/KF5\:\:NewStuff/g' $FS perl -p -i -e 's/\$\{KDE4_KDESU_LIBS\}/KF5\:\:KDESu/g' $FS perl -p -i -e 's/\$\{KDE4_KTEXTEDITOR_LIBS\}/KF5\:\:TextEditor/g' $FS perl -p -i -e 's/\$\{KDE4_KPTY_LIBS\}/KF5\:\:Pty/g' $FS