get rid of the old QtScript bindings

This commit is contained in:
Marco Martin 2014-01-27 19:27:11 +01:00
parent e019e293fa
commit 2f4867bf0c
70 changed files with 0 additions and 9867 deletions

View File

@ -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})

View File

@ -1,2 +0,0 @@
#! /usr/bin/env bash
$XGETTEXT `find . -name '*.cpp'` -o $podir/plasma_scriptengine_qscript.pot

View File

@ -1,21 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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)

View File

@ -1,38 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QString>
#include <KAuthorized>
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

View File

@ -1,23 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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"

View File

@ -1,207 +0,0 @@
/*
* Copyright 2011 Aaron Seigo <aseigo@kde.org>
*
* 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 <QDir>
#include <KDesktopFile>
#include <KGlobalSettings>
#include <KIO/CopyJob>
#include <KIO/Job>
#include <KRun>
#include <KStandardDirs>
#include <Plasma/Package>
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<QUrl>(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<QUrl>(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<QUrl>(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<Plasma::Package>().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));
}
}

View File

@ -1,253 +0,0 @@
/*
* Copyright 2011 Aaron Seigo <aseigo@kde.org>
*
* 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 <KEMailSettings>
#include <KMimeTypeTrader>
#include <KStandardDirs>
#include <KRun>
#include <KServiceTypeTrader>
#include <KShell>
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<KUrl::List>(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<QStringList>(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();
}

View File

@ -1,22 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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"

View File

@ -1,69 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <KConfigGroup>
#include <KDesktopFile>
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"

View File

@ -1,35 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <Plasma/PackageStructure>
class JavascriptAddonPackageStructure : public Plasma::PackageStructure
{
Q_OBJECT
public:
JavascriptAddonPackageStructure(QObject *parent = 0, const QVariantList &args = QVariantList());
void pathChanged();
};
#endif

View File

@ -1,532 +0,0 @@
/*
* Copyright 2007-2008 Richard J. Moore <rich@kde.org>
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <iostream>
#include <QFile>
#include <QMetaEnum>
#include <QDebug>
#include <KDesktopFile>
#include <KIO/Job>
#include <KLocale>
#include <KMimeType>
#include <KPluginInfo>
#include <KService>
#include <KServiceTypeTrader>
#include <KShell>
#include <KStandardDirs>
#include <KRun>
#include <Plasma/Package>
#include <qstandardpaths.h>
#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<ScriptEnv*>(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<QString> 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<Plasma::Package>().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<QScriptValue> 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<QScriptValue> 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

View File

@ -1,121 +0,0 @@
/*
* Copyright 2007-2008 Richard J. Moore <rich@kde.org>
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QScriptEngine>
#include <QSet>
#include <KPluginInfo>
#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<QString> 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<QString> m_extensions;
AllowedUrls m_allowedUrls;
QScriptEngine *m_engine;
QHash<QString, QScriptValueList> m_eventListeners;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ScriptEnv::AllowedUrls)
#endif

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,352 +0,0 @@
/*
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
*
* 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 <QScriptEngine>
#include <Plasma/Package>
#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<JavaScriptDataEngine *>(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<JavaScriptDataEngine *>(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<Plasma::Service *>(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 <javascriptdataengine.moc>

View File

@ -1,79 +0,0 @@
/*
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
*
* 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 <Plasma/DataEngineScript>
#include <QScriptValue>
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

View File

@ -1,119 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QFile>
#include <QDebug>
#include <Plasma/ServiceJob>
#include "common/scriptenv.h"
#include "javascriptdataengine.h"
JavaScriptServiceJob::JavaScriptServiceJob(QScriptEngine *engine, const QString &destination, const QString &operation,
const QMap<QString, QVariant> &parameters, 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<QString, QVariant> &parameters)
{
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"

View File

@ -1,90 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QWeakPointer>
#include <QScriptValue>
#include <Plasma/Package>
#include <Plasma/Service>
#include <Plasma/ServiceJob>
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<QString, QVariant> &parameters, 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<QString, QVariant> &parameters);
void registerOperationsScheme();
private:
QWeakPointer<JavaScriptDataEngine> m_dataEngine;
QScriptValue m_setupFunc;
};
#endif

View File

@ -1,204 +0,0 @@
/*
Copyright 2011 Marco Martin <notmart@gmail.com>
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 <QGraphicsLayout>
#include <QDebug>
#include <Plasma/Applet>
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<Plasma::Applet *>(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"

View File

@ -1,97 +0,0 @@
/*
Copyright 2011 Marco Martin <notmart@gmail.com>
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 <QDeclarativeItem>
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<Plasma::Applet> m_applet;
};
#endif

View File

@ -1,120 +0,0 @@
/***************************************************************************
* Copyright 2011 Marco Martin <mart@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "declarativeitemcontainer_p.h"
#include <QDebug>
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<QGraphicsItem *>(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"

View File

@ -1,54 +0,0 @@
/***************************************************************************
* Copyright 2011 Marco Martin <mart@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef DECLARATIVEITEMCONTAINER_P
#define DECLARATIVEITEMCONTAINER_P
#include <QDeclarativeItem>
#include <QGraphicsObject>
#include <QGraphicsWidget>
#include <QGraphicsSceneResizeEvent>
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<QDeclarativeItem> m_declarativeItem;
};
#endif

View File

@ -1,88 +0,0 @@
/*
* Copyright 2010 Marco Martin <notmart@gmail.com>
*
* 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 <QNetworkReply>
#include <Plasma/Package>
#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
}
}

View File

@ -1,56 +0,0 @@
/*
* Copyright 2010 Marco Martin <notmart@gmail.com>
*
* 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 <kio/accessmanager.h>
#else
#include <QtNetwork/QNetworkAccessManager>
#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

View File

@ -1,43 +0,0 @@
/*
* Copyright 2010 Marco Martin <notmart@gmail.com>
*
* 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 <Plasma/Package>
#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);
}

View File

@ -1,45 +0,0 @@
/*
* Copyright 2010 Marco Martin <notmart@gmail.com>
*
* 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 <QDeclarativeNetworkAccessManagerFactory>
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

View File

@ -1,180 +0,0 @@
/*
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
* Copyright 2008 by Marco Martin <notmart@gmail.com>
* Copyright 2012 by Sebastian Kügler <sebas@kde.org>
*
* 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 <QAction>
#include <KIcon>
#include <QDebug>
#include <Plasma/Corona>
class ToolBoxProxyPrivate {
public:
bool showing;
Plasma::Containment *containment;
QList<QAction*> 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<Plasma::Containment *>(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<QAction> ToolBoxProxy::actions()
{
return QDeclarativeListProperty<QAction>(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<QAction*>(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"

View File

@ -1,81 +0,0 @@
/*
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
* Copyright 2008 by Marco Martin <notmart@gmail.com>
* Copyright 2012 by Sebastian Kügler <sebas@kde.org>
*
* 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 <Plasma/AbstractToolBox>
#include <Plasma/Plasma>
#include <QDeclarativeListProperty>
class QAction;
class ToolBoxProxyPrivate;
class AppletInterface;
class ToolBoxProxy : public Plasma::AbstractToolBox
{
Q_OBJECT
Q_PROPERTY(QDeclarativeListProperty<QAction> 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<QAction> 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

View File

@ -1,172 +0,0 @@
/*
* Copyright 2008 Richard J. Moore <rich@kde.org>
*
* 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 <QFile>
#include <QDebug>
#include <Plasma/AbstractRunner>
#include <Plasma/Package>
#include <Plasma/QueryMatch>
#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"

View File

@ -1,67 +0,0 @@
// -*- c++ -*-
/*
* Copyright 2008 Richard J. Moore <rich@kde.org>
*
* 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 <QScriptValue>
#include <Plasma/RunnerScript>
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

View File

@ -1,154 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
* Copyright 2009 Artur Duque de Souza <asouza@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QGraphicsWidget>
#include <QGraphicsAnchorLayout>
#include <Plasma/Applet>
#include "backportglobal.h"
Q_DECLARE_METATYPE(QScript::Pointer<QGraphicsItem>::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<Qt::AnchorPoint>(ctx->argument(1).toInt32()),
item2, static_cast<Qt::AnchorPoint>(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<Qt::AnchorPoint>(ctx->argument(1).toInt32()),
item2, static_cast<Qt::AnchorPoint>(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<Qt::Corner>(ctx->argument(1).toInt32()),
item2, static_cast<Qt::Corner>(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<Qt::Orientation>(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<QGraphicsAnchorLayout>(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<QGraphicsAnchorLayout>(eng, proto);
QScriptValue ctorFun = eng->newFunction(ctor, proto);
return ctorFun;
}

View File

@ -1,102 +0,0 @@
/*
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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"

View File

@ -1,60 +0,0 @@
/*
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QParallelAnimationGroup>
#include <QSequentialAnimationGroup>
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

View File

@ -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 <QtCore/QSharedData>
#include <QPixmap>
Q_DECLARE_METATYPE(QPixmap*)
Q_DECLARE_METATYPE(QPixmap)
#define DECLARE_SELF(Class, __fn__) \
Class* self = qscriptvalue_cast<Class*>(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<Class*>(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<T>(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<ArgType>(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<ArgType>(ctx->argument(0)))); \
} END_DECLARE_METHOD
#define DECLARE_POINTER_METATYPE(T) \
Q_DECLARE_METATYPE(T*) \
Q_DECLARE_METATYPE(QScript::Pointer<T>::wrapped_pointer_type)
namespace QScript
{
enum {
UserOwnership = 1
};
template <typename T>
class Pointer : public QSharedData
{
public:
typedef T* pointer_type;
typedef QExplicitlySharedDataPointer<Pointer<T> > 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<T*>(var)) {
target = qvariant_cast<T*>(var);
} else if (qVariantCanConvert<wrapped_pointer_type>(var)) {
target = qvariant_cast<wrapped_pointer_type>(var)->operator T*();
} else {
// look in prototype chain
target = 0;
int type = qMetaTypeId<T*>();
int pointerType = qMetaTypeId<wrapped_pointer_type>();
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<wrapped_pointer_type*>(var.data()))->operator T*();
break;
} else {
target = static_cast<T*>(var.data());
break;
}
}
proto = proto.prototype();
}
}
} else if (value.isQObject()) {
QObject *qobj = value.toQObject();
QByteArray typeName = QMetaType::typeName(qMetaTypeId<T*>());
target = reinterpret_cast<T*>(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 <typename T>
int registerPointerMetaType(
QScriptEngine *eng,
const QScriptValue &prototype = QScriptValue(),
T * /* dummy */ = 0
)
{
QScriptValue (*mf)(QScriptEngine *, T* const &) = Pointer<T>::toScriptValue;
void (*df)(const QScriptValue &, T* &) = Pointer<T>::fromScriptValue;
const int id = qMetaTypeId<T*>();
qScriptRegisterMetaType_helper(
eng, id, reinterpret_cast<QScriptEngine::MarshalFunction>(mf),
reinterpret_cast<QScriptEngine::DemarshalFunction>(df),
prototype);
eng->setDefaultPrototype(qMetaTypeId<typename Pointer<T>::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<Pointer<void*>::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<Pointer<void*>::wrapped_pointer_type *>(var.data()))->unsetFlags(UserOwnership);
}
}
template <class T>
inline QScriptValue wrapPointer(QScriptEngine *eng, T *ptr, uint flags = 0)
{
return eng->newVariant(qVariantFromValue(Pointer<T>::create(ptr, flags)));
}
} // namespace QScript
#ifdef QGRAPHICSITEM_H
namespace QScript {
template <class T>
inline QScriptValue wrapGVPointer(QScriptEngine *eng, T *item)
{
uint flags = item->parentItem() ? UserOwnership : 0;
return wrapPointer<T>(eng, item, flags);
}
} // namespace QScript
#endif // QGRAPHICSITEM_H
#endif // QTSCRIPTEXTENSIONS_GLOBAL_H

View File

@ -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 <QtScript/QScriptClassPropertyIterator>
#include <QtScript/QScriptEngine>
#include "bytearrayprototype.h"
#include <stdlib.h>
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<QByteArray>(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<QByteArray*>(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<QByteArray*>(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<QByteArray*>(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<ByteArrayClass*>(ctx->callee().data());
if (!cls)
return QScriptValue();
QScriptValue arg = ctx->argument(0);
if (arg.instanceOf(ctx->callee()))
return cls->newInstance(qscriptvalue_cast<QByteArray>(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<ByteArrayClass*>(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<QByteArray*>(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<QByteArray*>(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]

View File

@ -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 <QtCore/QObject>
#include <QtScript/QScriptClass>
#include <QtScript/QScriptString>
#include <QtScript/QScriptEngine>
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

View File

@ -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 <QtScript/QScriptEngine>
Q_DECLARE_METATYPE(QByteArray*)
ByteArrayPrototype::ByteArrayPrototype(QObject *parent)
: QObject(parent)
{
}
ByteArrayPrototype::~ByteArrayPrototype()
{
}
//! [0]
QByteArray *ByteArrayPrototype::thisByteArray() const
{
return qscriptvalue_cast<QByteArray*>(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]

View File

@ -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 <QtCore/QByteArray>
#include <QtCore/QObject>
#include <QtScript/QScriptable>
#include <QtScript/QScriptValue>
//! [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

View File

@ -1,146 +0,0 @@
/*
* Copyright (c) 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QColor>
#include <QDebug>
#include <Plasma/Theme>
#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<Plasma::Theme::ColorRole>(arg);
// qDebug() << "color is: " << Plasma::Theme::defaultTheme()->color(static_cast<Plasma::Theme::ColorRole>(arg));
self->setRgba(Plasma::Theme::defaultTheme()->color(static_cast<Plasma::Theme::ColorRole>(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<QColor>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QColor*>(), proto);
return eng->newFunction(ctor, proto);
}

View File

@ -1,72 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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<Plasma::Service *>(service), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void serviceFromQScriptValue(const QScriptValue &scriptValue, ServicePtr &service)
{
QObject *obj = scriptValue.toQObject();
service = static_cast<Plasma::Service *>(obj);
}
typedef Plasma::DataEngine *DataEnginePtr;
QScriptValue qScriptValueFromDataEngine(QScriptEngine *engine, const DataEnginePtr &dataEngine)
{
return engine->newQObject(const_cast<Plasma::DataEngine *>(dataEngine), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void dataEngineFromQScriptValue(const QScriptValue &scriptValue, DataEnginePtr &dataEngine)
{
QObject *obj = scriptValue.toQObject();
dataEngine = static_cast<Plasma::DataEngine *>(obj);
}
typedef Plasma::ServiceJob *ServiceJobPtr;
QScriptValue qScriptValueFromServiceJob(QScriptEngine *engine, const ServiceJobPtr &serviceJob)
{
return engine->newQObject(const_cast<Plasma::ServiceJob *>(serviceJob), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void serviceJobFromQScriptValue(const QScriptValue &scriptValue, ServiceJobPtr &serviceJob)
{
QObject *obj = scriptValue.toQObject();
serviceJob = static_cast<Plasma::ServiceJob *>(obj);
}
typedef QMap< QString, QString > StringStringMap;
Q_DECLARE_METATYPE(StringStringMap)
void registerDataEngineMetaTypes(QScriptEngine *engine)
{
qRegisterMetaType<Plasma::DataEngine::Data>("Plasma::DataEngine::Data");
qRegisterMetaType<Plasma::DataEngine::Data>("DataEngine::Data");
qScriptRegisterVariantMapMetaType<Plasma::DataEngine::Data>(engine);
qScriptRegisterMapMetaType<StringStringMap>(engine);
qScriptRegisterMetaType<Plasma::Service *>(engine, qScriptValueFromService, serviceFromQScriptValue);
qScriptRegisterMetaType<Plasma::DataEngine *>(engine, qScriptValueFromDataEngine, dataEngineFromQScriptValue);
qScriptRegisterMetaType<Plasma::ServiceJob *>(engine, qScriptValueFromServiceJob, serviceJobFromQScriptValue);
qRegisterMetaType<Plasma::Service *>("Service*");
qRegisterMetaType<Plasma::ServiceJob *>("ServiceJob*");
}

View File

@ -1,113 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QScriptEngine>
#include <QScriptValue>
#include <QScriptValueIterator>
#include <QDebug>
#include <Plasma/DataEngine>
#include <Plasma/Service>
#include <Plasma/ServiceJob>
using namespace Plasma;
#ifndef DECLARATIVE_BINDING
Q_DECLARE_METATYPE(QVariant)
#endif
Q_DECLARE_METATYPE(DataEngine::Dict)
Q_DECLARE_METATYPE(DataEngine::Data)
template <class M>
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 <class M>
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 <class M>
void qScriptValueToMap(const QScriptValue &value, M &map)
{
//qDebug() << "qScriptValueToMap called";
QScriptValueIterator it(value);
while (it.hasNext()) {
it.next();
map[it.name()] = qscriptvalue_cast<typename M::mapped_type>(it.value());
}
}
template<typename T>
int qScriptRegisterVariantMapMetaType(
QScriptEngine *engine,
const QScriptValue &prototype = QScriptValue()
#ifndef qdoc
, T * /* dummy */ = 0
#endif
)
{
return qScriptRegisterMetaType<T>(engine, qScriptValueFromVariantMap, qScriptValueToMap, prototype);
}
template<typename T>
int qScriptRegisterMapMetaType(
QScriptEngine *engine,
const QScriptValue &prototype = QScriptValue()
#ifndef qdoc
, T * /* dummy */ = 0
#endif
)
{
return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap, qScriptValueToMap, prototype);
}
void registerDataEngineMetaTypes(QScriptEngine *engine);
#endif // DATAENGINE_H

View File

@ -1,226 +0,0 @@
/*
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QScriptEngine>
#include "dataengine.h"
#include "scriptenv.h"
QSet<DataEngineReceiver*> 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<Plasma::DataEngine::Data>(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<DataEngine *>(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<Plasma::Types::IntervalAlignment>(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<DataEngine *>(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<Plasma::Types::IntervalAlignment>(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<DataEngine *>(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"

View File

@ -1,59 +0,0 @@
/*
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
*
* 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 <QScriptValue>
#include <Plasma/DataEngine>
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<DataEngineReceiver*> 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

View File

@ -1,160 +0,0 @@
/*
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
*
* 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 <QEasingCurve>
#include <QMetaEnum>
#include <QScriptValue>
#include <QScriptEngine>
#include <QScriptContext>
#include <QScriptable>
#include "backportglobal.h"
Q_DECLARE_METATYPE(QEasingCurve)
Q_DECLARE_METATYPE(QEasingCurve*)
#include <QDebug>
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<QEasingCurve::Type>(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<QEasingCurve::Type>(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<QEasingCurve>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QEasingCurve*>(), proto);
return ctorFun;
}

View File

@ -1,178 +0,0 @@
/*
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QScriptEngine>
#include <QDebug>
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<FileDialogProxy *>(fd), QScriptEngine::AutoOwnership,
QScriptEngine::PreferExistingWrapperObject | QScriptEngine::ExcludeSuperClassContents);
}
void fileDialogProxyFromQScriptValue(const QScriptValue &scriptValue, FileDialogProxyPtr &fd)
{
QObject *obj = scriptValue.toQObject();
fd = static_cast<FileDialogProxy *>(obj);
}
void FileDialogProxy::registerWithRuntime(QScriptEngine *engine)
{
QScriptValue global = engine->globalObject();
qScriptRegisterMetaType<FileDialogProxy*>(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"

View File

@ -1,85 +0,0 @@
/*
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QObject>
#include <QScriptValue>
#include <KFileDialog>
class QScriptEngine;
class QScriptContext;
class FileDialogProxy : public QObject
{
Q_OBJECT
Q_PROPERTY(QUrl url READ selectedUrl WRITE setUrl)
Q_PROPERTY(QList<QUrl> 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<QUrl> 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

View File

@ -1,303 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QFont>
#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<QFont*>(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<QFont*>(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<QFont*>(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<QFont>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QFont*>(), proto);
return eng->newFunction(ctor, proto);
}

View File

@ -1,412 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QCursor>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include "backportglobal.h"
Q_DECLARE_METATYPE(QScript::Pointer<QGraphicsItem>::wrapped_pointer_type)
Q_DECLARE_METATYPE(QList<QGraphicsItem*>)
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<int>(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<QGraphicsItem*>(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<Qt::ItemSelectionMode>(ctx->argument(1).toInt32())));
} END_DECLARE_METHOD
BEGIN_DECLARE_METHOD(QGraphicsItem, collidesWithPath) {
QPainterPath path = qscriptvalue_cast<QPainterPath>(ctx->argument(0));
if (ctx->argument(1).isUndefined())
return QScriptValue(eng, self->collidesWithPath(path));
else
return QScriptValue(eng, self->collidesWithPath(path, static_cast<Qt::ItemSelectionMode>(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<Qt::ItemSelectionMode>(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<int>(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<QRectF>(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<QPainter*>(ctx->argument(0)),
qscriptvalue_cast<QStyleOptionGraphicsItem*>(ctx->argument(1)),
qscriptvalue_cast<QWidget*>(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<QGraphicsPathItem*>());
break;
case 3:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsRectItem*>());
break;
case 4:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsEllipseItem*>());
break;
case 5:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsPolygonItem*>());
break;
case 6:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsLineItem*>());
break;
case 7:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsPixmapItem*>());
break;
case 8:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsTextItem*>());
break;
case 9:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsSimpleTextItem*>());
break;
case 10:
proto = eng->defaultPrototype(qMetaTypeId<QGraphicsItemGroup*>());
break;
}
if (proto.isValid())
ret.setPrototype(proto);
return ret;
} END_DECLARE_METHOD
BEGIN_DECLARE_METHOD(QGraphicsItem, setAcceptedMouseButtons) {
self->setAcceptedMouseButtons(static_cast<Qt::MouseButtons>(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<QGraphicsItem::GraphicsItemFlag>(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<QGraphicsItem::GraphicsItemFlags>(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<Qt::FocusReason>(ctx->argument(0).toInt32()));
return eng->undefinedValue();
} END_DECLARE_METHOD
BEGIN_DECLARE_METHOD(QGraphicsItem, setParentItem) {
QScriptValue arg = ctx->argument(0);
QGraphicsItem *item = qscriptvalue_cast<QGraphicsItem*>(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<QPointF>(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<QRectF>(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<QGraphicsItem>(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<QGraphicsItem>(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;
}

View File

@ -1,182 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QGraphicsWidget>
#include <QGraphicsGridLayout>
#include <QGraphicsLayout>
#include <Plasma/Applet>
#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<QGraphicsItem>::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<Qt::Alignment>(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<Qt::Alignment>(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<QGraphicsGridLayout>(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<QGraphicsGridLayout>(eng, proto);
QScriptValue ctorFun = eng->newFunction(ctor, proto);
return ctorFun;
}

View File

@ -1,121 +0,0 @@
/*
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
*
* 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 <QScriptContext>
#include <QScriptEngine>
#include <QDebug>
#include <KLocalizedString>
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));
}

View File

@ -1,35 +0,0 @@
/*
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
*
* 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 <QScriptValue>
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

View File

@ -1,111 +0,0 @@
/*
* Copyright (c) 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <KIcon>
#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<QPixmap>();
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<QPixmap>();
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<QIcon>(), proto);
return ctorFun;
}

View File

@ -1,244 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QGraphicsAnchorLayout>
#include <QGraphicsLayout>
#include <QGraphicsLinearLayout>
#include <QGraphicsGridLayout>
#include <QGraphicsWidget>
#include <Plasma/Applet>
#include "backportglobal.h"
#include "plasmoid/appletinterface.h"
Q_DECLARE_METATYPE(QScript::Pointer<QGraphicsItem>::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<QGraphicsWidget *>(object);
if (!w) {
AppletInterface *interface = qobject_cast<AppletInterface*>(object);
if (!interface) {
interface = qobject_cast<AppletInterface*>(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<QGraphicsLayoutItem *>();
//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<QGraphicsLayout *>();
if (!item) {
item = variant.value<QGraphicsLinearLayout *>();
if (!item) {
item = variant.value<QGraphicsGridLayout *>();
if (!item) {
item = variant.value<QGraphicsAnchorLayout *>();
}
}
}
}
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(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<Qt::Orientation>(ctx->argument(0).toInt32()));
}
return QScriptValue(eng, static_cast<int>(self->orientation()));
} END_DECLARE_METHOD
BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, setAlignment) {
QGraphicsLayoutItem *item = extractLayoutItem(ctx);
if (!item) {
return eng->undefinedValue();
}
self->setAlignment(item, static_cast<Qt::Alignment>(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<QGraphicsLayoutItem*>();
if (!item) {
return eng->undefinedValue();
}
self->setStretchFactor(item, static_cast<Qt::Orientation>(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<QGraphicsLinearLayout>(eng, new QGraphicsLinearLayout(), );
qRegisterMetaType<QGraphicsLayoutItem*>();
QGraphicsLayoutItem * i = new QGraphicsLinearLayout;
QVariant v;
///v.setValue<QGraphicsLayoutItem*>(i);
v.setValue<void*>(i);
QScriptValue proto = QScript::wrapPointer<QGraphicsLinearLayout>(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<QGraphicsLinearLayout>(eng, proto);
QScriptValue ctorFun = eng->newFunction(ctor, proto);
//ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemIsMovable);
return ctorFun;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,170 +0,0 @@
/*
* Copyright (c) 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QPen>
#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<QBrush>(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<QColor>(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<QPen>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QPen*>(), proto);
return ctorFun;
}

View File

@ -1,76 +0,0 @@
/*
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QPixmap>
#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<QPixmap>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QPixmap*>(), proto);
return eng->newFunction(ctor, proto);
}

View File

@ -1,91 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QtCore/QPoint>
#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<QPoint>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QPoint*>(), proto);
return eng->newFunction(ctor, proto);
}

View File

@ -1,147 +0,0 @@
/*
* Copyright 2007-2008 Richard J. Moore <rich@kde.org>
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QGraphicsWidget>
#include <QScriptEngine>
#include <Plasma/Applet>
#include <Plasma/Animation>
#include <Plasma/Extender>
#include <Plasma/VideoWidget>
//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<double>)
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<Plasma::Animation *>(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void abstractAnimationFromQScriptValue(const QScriptValue &scriptValue, AnimationPtr &anim)
{
QObject *obj = scriptValue.toQObject();
anim = static_cast<Plasma::Animation *>(obj);
}
typedef QGraphicsWidget * QGraphicsWidgetPtr;
QScriptValue qScriptValueFromQGraphicsWidget(QScriptEngine *engine, const QGraphicsWidgetPtr &anim)
{
return engine->newQObject(const_cast<QGraphicsWidget *>(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void graphicsWidgetFromQScriptValue(const QScriptValue &scriptValue, QGraphicsWidgetPtr &anim)
{
QObject *obj = scriptValue.toQObject();
anim = static_cast<QGraphicsWidget *>(obj);
}
typedef Plasma::Svg * SvgPtr;
QScriptValue qScriptValueFromSvg(QScriptEngine *engine, const SvgPtr &anim)
{
return engine->newQObject(const_cast<Plasma::Svg *>(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void svgFromQScriptValue(const QScriptValue &scriptValue, SvgPtr &anim)
{
QObject *obj = scriptValue.toQObject();
anim = static_cast<Plasma::Svg *>(obj);
}
typedef Plasma::Extender *ExtenderPtr;
QScriptValue qScriptValueFromExtender(QScriptEngine *engine, const ExtenderPtr &extender)
{
return engine->newQObject(const_cast<Plasma::Extender *>(extender), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void extenderFromQScriptValue(const QScriptValue &scriptValue, ExtenderPtr &extender)
{
QObject *obj = scriptValue.toQObject();
extender = static_cast<Plasma::Extender *>(obj);
}
QScriptValue qScriptValueFromMouseButton(QScriptEngine *, const Qt::MouseButton &button)
{
return int(button);
}
void mouseButtonFromScriptValue(const QScriptValue &scriptValue, Qt::MouseButton &button)
{
button = static_cast<Qt::MouseButton>(scriptValue.toInt32());
}
#include "simplebindings/qscriptnonguibookkeeping.cpp"
using namespace Plasma;
void registerSimpleAppletMetaTypes(QScriptEngine *engine)
{
registerNonGuiMetaTypes(engine);
qScriptRegisterMetaType<QGraphicsWidget*>(engine, qScriptValueFromQGraphicsWidget, graphicsWidgetFromQScriptValue);
qScriptRegisterMetaType<Plasma::Svg*>(engine, qScriptValueFromSvg, svgFromQScriptValue);
qScriptRegisterSequenceMetaType<QList<double> >(engine);
qScriptRegisterMetaType<Plasma::Animation *>(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue);
qScriptRegisterMetaType<Plasma::Extender *>(engine, qScriptValueFromExtender, extenderFromQScriptValue);
qScriptRegisterMetaType<Plasma::VideoWidget::Controls>(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue());
qScriptRegisterMetaType<Qt::MouseButton>(engine, qScriptValueFromMouseButton, mouseButtonFromScriptValue);
}

View File

@ -1,108 +0,0 @@
/*
* Copyright 2007-2008 Richard J. Moore <rich@kde.org>
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QScriptEngine>
#include <KConfigGroup>
#include <KIO/Job>
#include <KSharedConfig>
#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<KJob *>(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void qKJobFromQScriptValue(const QScriptValue &scriptValue, KJobPtr &job)
{
QObject *obj = scriptValue.toQObject();
job = static_cast<KJob *>(obj);
}
Q_DECLARE_METATYPE(KIO::Job *)
typedef KIO::Job* KioJobPtr;
QScriptValue qScriptValueFromKIOJob(QScriptEngine *engine, const KioJobPtr &job)
{
return engine->newQObject(const_cast<KIO::Job *>(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void qKIOJobFromQScriptValue(const QScriptValue &scriptValue, KioJobPtr &job)
{
QObject *obj = scriptValue.toQObject();
job = static_cast<KIO::Job *>(obj);
}
QScriptValue qScriptValueFromKConfigGroup(QScriptEngine *engine, const KConfigGroup &config)
{
QScriptValue obj = engine->newObject();
if (!config.isValid()) {
return obj;
}
QMap<QString, QString> entryMap = config.entryMap();
QMap<QString, QString>::const_iterator it = entryMap.constBegin();
QMap<QString, QString>::const_iterator begin = it;
QMap<QString, QString>::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<KConfigGroup>(engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue);
qScriptRegisterMetaType<KJob *>(engine, qScriptValueFromKJob, qKJobFromQScriptValue);
qScriptRegisterMetaType<KIO::Job *>(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue);
registerDataEngineMetaTypes(engine);
}

View File

@ -1,330 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QtCore/QRectF>
#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<QRectF>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QRectF*>(), proto);
return eng->newFunction(ctor, proto);
}

View File

@ -1,74 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QtCore/QSizeF>
#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<QSizeF>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QSizeF*>(), proto);
return eng->newFunction(ctor, proto);
}

View File

@ -1,102 +0,0 @@
/*
* Copyright (c) 2010 Aaron J. Seigo <aseigo@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QSizePolicy>
#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<QSizePolicy::Policy>(ctx->argument(0).toInt32());
v = static_cast<QSizePolicy::Policy>(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<QSizePolicy::Policy>(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<QSizePolicy::Policy>(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<QSizePolicy>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QSizePolicy*>(), proto);
return eng->newFunction(ctor, proto);
}

View File

@ -1,70 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QtScript/QScriptable>
#include <QtCore/QTimer>
#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<QObject*>(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<QTimer*>(), proto);
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
proto.setProperty("active", eng->newFunction(active), getter | setter);
return eng->newFunction(ctor, proto);
}

View File

@ -1,135 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QGraphicsGridLayout>
#include <QGraphicsLinearLayout>
#include <QStringList>
#include <QDebug>
#include <Plasma/BusyWidget>
#include <Plasma/CheckBox>
#include <Plasma/ComboBox>
#include <Plasma/FlashingLabel>
#include <Plasma/Frame>
#include <Plasma/GroupBox>
#include <Plasma/IconWidget>
#include <Plasma/ItemBackground>
#include <Plasma/Label>
#include <Plasma/LineEdit>
#include <Plasma/Meter>
#include <Plasma/PushButton>
#include <Plasma/RadioButton>
#include <Plasma/ScrollBar>
#include <Plasma/ScrollWidget>
#include <Plasma/Separator>
#include <Plasma/SignalPlotter>
#include <Plasma/Slider>
#include <Plasma/SpinBox>
#include <Plasma/SvgWidget>
#include <Plasma/TabBar>
#include <Plasma/TextEdit>
#include <Plasma/ToolButton>
#include <Plasma/TreeView>
#include <Plasma/WebView>
#include <Plasma/VideoWidget>
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;
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <KSharedPtr>
#include <plasma/applet.h>
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<QString, widgetCreator> m_widgetCtors;
};
#endif // PLASMA_UILOADER_H

View File

@ -1,117 +0,0 @@
/*
* Copyright 2007 Richard J. Moore <rich@kde.org>
*
* 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 <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QUrl>
#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<QUrl*>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QUrl>(), proto);
return eng->newFunction(ctor, proto);
}