remove plasmoid stuff in qtscript bindings
causes just confusion
This commit is contained in:
parent
996665c2be
commit
78a5f5e2c5
@ -125,47 +125,3 @@ install(TARGETS plasma_packagestructure_javascriptaddon DESTINATION ${PLUGIN_INS
|
||||
install(FILES data/plasma-packagestructure-javascript-addon.desktop DESTINATION ${SERVICES_INSTALL_DIR})
|
||||
|
||||
install(FILES data/plasma-javascriptaddon.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR})
|
||||
|
||||
#DECLARATIVE APPLET
|
||||
set(declarative_appletscript_SRCS
|
||||
common/extension_launchapp.cpp
|
||||
common/extension_io.cpp
|
||||
common/javascriptaddonpackagestructure.cpp
|
||||
common/declarativescriptenv.cpp
|
||||
declarative/toolboxproxy.cpp
|
||||
declarative/appletcontainer.cpp
|
||||
declarative/declarativeitemcontainer.cpp
|
||||
declarative/packageaccessmanager.cpp
|
||||
declarative/packageaccessmanagerfactory.cpp
|
||||
plasmoid/abstractjsappletscript.cpp
|
||||
plasmoid/appletauthorization.cpp
|
||||
plasmoid/appletinterface.cpp
|
||||
plasmoid/declarativeappletscript.cpp
|
||||
plasmoid/themedsvg.cpp
|
||||
simplebindings/bytearrayclass.cpp
|
||||
simplebindings/bytearrayprototype.cpp
|
||||
simplebindings/dataengine.cpp
|
||||
simplebindings/dataenginereceiver.cpp
|
||||
simplebindings/filedialogproxy.cpp
|
||||
simplebindings/qscriptbookkeeping.cpp
|
||||
simplebindings/url.cpp
|
||||
simplebindings/point.cpp
|
||||
)
|
||||
|
||||
include_directories(${PHONON_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
|
||||
kde4_add_plugin(plasma_appletscript_declarative ${declarative_appletscript_SRCS})
|
||||
target_link_libraries(plasma_appletscript_declarative
|
||||
${KDE4_PLASMA_LIBS}
|
||||
${KDE4_KIO_LIBS}
|
||||
${QT_QTSCRIPT_LIBRARY}
|
||||
${QT_QTDECLARATIVE_LIBRARY}
|
||||
${QT_QTUITOOLS_LIBRARY}
|
||||
|
||||
)
|
||||
|
||||
|
||||
install(TARGETS plasma_appletscript_declarative DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||
install(FILES data/plasma-scriptengine-applet-declarative.desktop DESTINATION ${SERVICES_INSTALL_DIR})
|
||||
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <mart@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 "plasmoid/abstractjsappletscript.h"
|
||||
|
||||
|
||||
AbstractJsAppletScript::AbstractJsAppletScript(QObject *parent, const QVariantList &args)
|
||||
: Plasma::AppletScript(parent)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
}
|
||||
|
||||
AbstractJsAppletScript::~AbstractJsAppletScript()
|
||||
{
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <mart@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 ABSTRACTJS_APPLETSCRIPT_H
|
||||
#define ABSTRACTJS_APPLETSCRIPT_H
|
||||
|
||||
#include <QScriptValue>
|
||||
|
||||
#include <Plasma/AppletScript>
|
||||
|
||||
class AbstractJsAppletScript : public Plasma::AppletScript
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AbstractJsAppletScript(QObject *parent, const QVariantList &args = QVariantList());
|
||||
~AbstractJsAppletScript();
|
||||
|
||||
virtual QScriptEngine *engine() const = 0;
|
||||
virtual bool include(const QString &path) = 0;
|
||||
virtual QString filePath(const QString &type, const QString &file) const = 0;
|
||||
virtual QScriptValue variantToScriptValue(QVariant var) = 0;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,54 +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 <KAuthorized>
|
||||
|
||||
#include "appletauthorization.h"
|
||||
#include <Plasma/AppletScript>
|
||||
#include <Plasma/Applet>
|
||||
|
||||
AppletAuthorization::AppletAuthorization(Plasma::AppletScript *scriptEngine)
|
||||
: Authorization(),
|
||||
m_scriptEngine(scriptEngine)
|
||||
{
|
||||
}
|
||||
|
||||
bool AppletAuthorization::authorizeRequiredExtension(const QString &extension)
|
||||
{
|
||||
bool ok = m_scriptEngine->applet()->hasAuthorization(extension);
|
||||
|
||||
if (!ok) {
|
||||
m_scriptEngine->setLaunchErrorMessage(true,
|
||||
i18n("Authorization for required extension '%1' was denied.",
|
||||
extension));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool AppletAuthorization::authorizeOptionalExtension(const QString &extension)
|
||||
{
|
||||
return m_scriptEngine->applet()->hasAuthorization(extension);
|
||||
}
|
||||
|
||||
bool AppletAuthorization::authorizeExternalExtensions()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,44 +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 APPLETAUTHORIZATION_H
|
||||
#define APPLETAUTHORIZATION_H
|
||||
|
||||
#include "authorization.h"
|
||||
|
||||
namespace Plasma {
|
||||
class AppletScript;
|
||||
}
|
||||
|
||||
class SimpleJavaScriptApplet;
|
||||
|
||||
class AppletAuthorization : public Authorization
|
||||
{
|
||||
public:
|
||||
AppletAuthorization(Plasma::AppletScript *scriptEngine);
|
||||
|
||||
bool authorizeRequiredExtension(const QString &extension);
|
||||
bool authorizeOptionalExtension(const QString &extension);
|
||||
bool authorizeExternalExtensions();
|
||||
|
||||
private:
|
||||
Plasma::AppletScript *m_scriptEngine;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,732 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Chani Armitage <chani@kde.org>
|
||||
* Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010 Marco Martin <mart@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 "appletinterface.h"
|
||||
#include "../declarative/appletcontainer.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QScriptEngine>
|
||||
#include <QSignalMapper>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KGlobalSettings>
|
||||
#include <KIcon>
|
||||
#include <KService>
|
||||
#include <KServiceTypeTrader>
|
||||
|
||||
#include <Plasma/Plasma>
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Corona>
|
||||
#include <Plasma/Context>
|
||||
#include <Plasma/Package>
|
||||
#include <Plasma/ToolTipManager>
|
||||
|
||||
Q_DECLARE_METATYPE(AppletInterface*)
|
||||
|
||||
AppletInterface::AppletInterface(AbstractJsAppletScript *parent)
|
||||
: QObject(parent),
|
||||
m_appletScriptEngine(parent),
|
||||
m_actionSignals(0)
|
||||
{
|
||||
connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
|
||||
connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving()));
|
||||
connect(applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SIGNAL(immutableChanged()));
|
||||
connect(applet(), SIGNAL(statusChanged(Plasma::ItemStatus)), this, SIGNAL(statusChanged()));
|
||||
connect(m_appletScriptEngine, SIGNAL(formFactorChanged()),
|
||||
this, SIGNAL(formFactorChanged()));
|
||||
connect(m_appletScriptEngine, SIGNAL(locationChanged()),
|
||||
this, SIGNAL(locationChanged()));
|
||||
connect(m_appletScriptEngine, SIGNAL(contextChanged()),
|
||||
this, SIGNAL(contextChanged()));
|
||||
}
|
||||
|
||||
AppletInterface::~AppletInterface()
|
||||
{
|
||||
}
|
||||
|
||||
AppletInterface *AppletInterface::extract(QScriptEngine *engine)
|
||||
{
|
||||
QScriptValue appletValue = engine->globalObject().property("plasmoid");
|
||||
return qobject_cast<AppletInterface*>(appletValue.toQObject());
|
||||
}
|
||||
|
||||
Plasma::DataEngine* AppletInterface::dataEngine(const QString &name)
|
||||
{
|
||||
return applet()->dataEngine(name);
|
||||
}
|
||||
|
||||
AppletInterface::FormFactor AppletInterface::formFactor() const
|
||||
{
|
||||
return static_cast<FormFactor>(applet()->formFactor());
|
||||
}
|
||||
|
||||
AppletInterface::Location AppletInterface::location() const
|
||||
{
|
||||
return static_cast<Location>(applet()->location());
|
||||
}
|
||||
|
||||
QString AppletInterface::currentActivity() const
|
||||
{
|
||||
return applet()->context()->currentActivity();
|
||||
}
|
||||
|
||||
bool AppletInterface::shouldConserveResources() const
|
||||
{
|
||||
return applet()->shouldConserveResources();
|
||||
}
|
||||
|
||||
void AppletInterface::setFailedToLaunch(bool failed, const QString &reason)
|
||||
{
|
||||
m_appletScriptEngine->setLaunchErrorMessage(failed, reason);
|
||||
}
|
||||
|
||||
bool AppletInterface::isBusy() const
|
||||
{
|
||||
return applet()->isBusy();
|
||||
}
|
||||
|
||||
void AppletInterface::setBusy(bool busy)
|
||||
{
|
||||
applet()->setBusy(busy);
|
||||
}
|
||||
|
||||
AppletInterface::BackgroundHints AppletInterface::backgroundHints() const
|
||||
{
|
||||
return static_cast<BackgroundHints>(static_cast<int>(applet()->backgroundHints()));
|
||||
}
|
||||
|
||||
void AppletInterface::setBackgroundHints(BackgroundHints hint)
|
||||
{
|
||||
applet()->setBackgroundHints(Plasma::Applet::BackgroundHints(hint));
|
||||
}
|
||||
|
||||
void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason)
|
||||
{
|
||||
m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason);
|
||||
}
|
||||
|
||||
void JsAppletInterface::update(const QRectF &rect)
|
||||
{
|
||||
applet()->update(rect);
|
||||
}
|
||||
|
||||
QGraphicsLayout *JsAppletInterface::layout() const
|
||||
{
|
||||
return applet()->layout();
|
||||
}
|
||||
|
||||
void JsAppletInterface::setLayout(QGraphicsLayout *layout)
|
||||
{
|
||||
applet()->setLayout(layout);
|
||||
}
|
||||
|
||||
QString AppletInterface::activeConfig() const
|
||||
{
|
||||
return m_currentConfig.isEmpty() ? "main" : m_currentConfig;
|
||||
}
|
||||
|
||||
void AppletInterface::setActiveConfig(const QString &name)
|
||||
{
|
||||
if (name == "main") {
|
||||
m_currentConfig.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
Plasma::ConfigLoader *loader = m_configs.value(name, 0);
|
||||
|
||||
if (!loader) {
|
||||
QString path = m_appletScriptEngine->filePath("config", name + ".xml");
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile f(path);
|
||||
KConfigGroup cg = applet()->config();
|
||||
loader = new Plasma::ConfigLoader(&cg, &f, this);
|
||||
m_configs.insert(name, loader);
|
||||
}
|
||||
|
||||
m_currentConfig = name;
|
||||
}
|
||||
|
||||
void AppletInterface::writeConfig(const QString &entry, const QVariant &value)
|
||||
{
|
||||
Plasma::ConfigLoader *config = 0;
|
||||
if (m_currentConfig.isEmpty()) {
|
||||
config = applet()->configScheme();
|
||||
} else {
|
||||
config = m_configs.value(m_currentConfig, 0);
|
||||
}
|
||||
|
||||
if (config) {
|
||||
KConfigSkeletonItem *item = config->findItemByName(entry);
|
||||
if (item) {
|
||||
item->setProperty(value);
|
||||
config->blockSignals(true);
|
||||
config->writeConfig();
|
||||
config->blockSignals(false);
|
||||
m_appletScriptEngine->configNeedsSaving();
|
||||
}
|
||||
} else
|
||||
kWarning() << "Couldn't find a configuration entry";
|
||||
}
|
||||
|
||||
QScriptValue AppletInterface::readConfig(const QString &entry) const
|
||||
{
|
||||
Plasma::ConfigLoader *config = 0;
|
||||
QVariant result;
|
||||
|
||||
if (m_currentConfig.isEmpty()) {
|
||||
config = applet()->configScheme();
|
||||
} else {
|
||||
config = m_configs.value(m_currentConfig, 0);
|
||||
}
|
||||
|
||||
if (config) {
|
||||
result = config->property(entry);
|
||||
}
|
||||
|
||||
return m_appletScriptEngine->variantToScriptValue(result);
|
||||
}
|
||||
|
||||
QString AppletInterface::file(const QString &fileType)
|
||||
{
|
||||
return m_appletScriptEngine->filePath(fileType, QString());
|
||||
}
|
||||
|
||||
QString AppletInterface::file(const QString &fileType, const QString &filePath)
|
||||
{
|
||||
return m_appletScriptEngine->filePath(fileType, filePath);
|
||||
}
|
||||
|
||||
QList<QAction*> AppletInterface::contextualActions() const
|
||||
{
|
||||
QList<QAction*> actions;
|
||||
Plasma::Applet *a = applet();
|
||||
if (a->launchErrorMessage()) {
|
||||
return actions;
|
||||
}
|
||||
|
||||
foreach (const QString &name, m_actions) {
|
||||
QAction *action = a->action(name);
|
||||
|
||||
if (action) {
|
||||
actions << action;
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
QSizeF AppletInterface::size() const
|
||||
{
|
||||
return applet()->size();
|
||||
}
|
||||
|
||||
QRectF AppletInterface::rect() const
|
||||
{
|
||||
return applet()->contentsRect();
|
||||
}
|
||||
|
||||
void AppletInterface::setActionSeparator(const QString &name)
|
||||
{
|
||||
Plasma::Applet *a = applet();
|
||||
QAction *action = a->action(name);
|
||||
|
||||
if (action) {
|
||||
action->setSeparator(true);
|
||||
} else {
|
||||
action = new QAction(this);
|
||||
action->setSeparator(true);
|
||||
a->addAction(name, action);
|
||||
m_actions.append(name);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletInterface::setAction(const QString &name, const QString &text, const QString &icon, const QString &shortcut)
|
||||
{
|
||||
Plasma::Applet *a = applet();
|
||||
QAction *action = a->action(name);
|
||||
|
||||
if (action) {
|
||||
action->setText(text);
|
||||
} else {
|
||||
action = new QAction(text, this);
|
||||
a->addAction(name, action);
|
||||
|
||||
Q_ASSERT(!m_actions.contains(name));
|
||||
m_actions.append(name);
|
||||
|
||||
if (!m_actionSignals) {
|
||||
m_actionSignals = new QSignalMapper(this);
|
||||
connect(m_actionSignals, SIGNAL(mapped(QString)),
|
||||
m_appletScriptEngine, SLOT(executeAction(QString)));
|
||||
}
|
||||
|
||||
connect(action, SIGNAL(triggered()), m_actionSignals, SLOT(map()));
|
||||
m_actionSignals->setMapping(action, name);
|
||||
}
|
||||
|
||||
if (!icon.isEmpty()) {
|
||||
action->setIcon(KIcon(icon));
|
||||
}
|
||||
|
||||
if (!shortcut.isEmpty()) {
|
||||
action->setShortcut(shortcut);
|
||||
}
|
||||
|
||||
action->setObjectName(name);
|
||||
}
|
||||
|
||||
void AppletInterface::removeAction(const QString &name)
|
||||
{
|
||||
Plasma::Applet *a = applet();
|
||||
QAction *action = a->action(name);
|
||||
|
||||
if (action) {
|
||||
if (m_actionSignals) {
|
||||
m_actionSignals->removeMappings(action);
|
||||
}
|
||||
|
||||
delete action;
|
||||
}
|
||||
|
||||
m_actions.removeAll(name);
|
||||
}
|
||||
|
||||
QAction *AppletInterface::action(QString name) const
|
||||
{
|
||||
return applet()->action(name);
|
||||
}
|
||||
|
||||
void AppletInterface::resize(qreal w, qreal h)
|
||||
{
|
||||
applet()->resize(w,h);
|
||||
}
|
||||
|
||||
void AppletInterface::setMinimumSize(qreal w, qreal h)
|
||||
{
|
||||
applet()->setMinimumSize(w,h);
|
||||
}
|
||||
|
||||
void AppletInterface::setPreferredSize(qreal w, qreal h)
|
||||
{
|
||||
applet()->setPreferredSize(w,h);
|
||||
}
|
||||
|
||||
bool AppletInterface::immutable() const
|
||||
{
|
||||
return applet()->immutability() != Plasma::Mutable;
|
||||
}
|
||||
|
||||
bool AppletInterface::userConfiguring() const
|
||||
{
|
||||
return applet()->isUserConfiguring();
|
||||
}
|
||||
|
||||
int AppletInterface::apiVersion() const
|
||||
{
|
||||
const QString constraint("[X-Plasma-API] == 'javascript' and 'Applet' in [X-Plasma-ComponentTypes]");
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ScriptEngine", constraint);
|
||||
if (offers.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return offers.first()->property("X-KDE-PluginInfo-Version", QVariant::Int).toInt();
|
||||
}
|
||||
|
||||
bool AppletInterface::include(const QString &script)
|
||||
{
|
||||
const QString path = m_appletScriptEngine->filePath("scripts", script);
|
||||
|
||||
if (path.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_appletScriptEngine->include(path);
|
||||
}
|
||||
|
||||
void AppletInterface::debug(const QString &msg)
|
||||
{
|
||||
kDebug() << msg;
|
||||
}
|
||||
|
||||
QObject *AppletInterface::findChild(const QString &name) const
|
||||
{
|
||||
if (name.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach (QGraphicsItem *item, applet()->childItems()) {
|
||||
QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget *>(item);
|
||||
if (widget && widget->objectName() == name) {
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Plasma::Extender *AppletInterface::extender() const
|
||||
{
|
||||
return m_appletScriptEngine->extender();
|
||||
}
|
||||
|
||||
void AppletInterface::setAssociatedApplication(const QString &string)
|
||||
{
|
||||
applet()->setAssociatedApplication(string);
|
||||
}
|
||||
|
||||
QString AppletInterface::associatedApplication() const
|
||||
{
|
||||
return applet()->associatedApplication();
|
||||
}
|
||||
|
||||
void AppletInterface::setStatus(const AppletInterface::ItemStatus &status)
|
||||
{
|
||||
applet()->setStatus((Plasma::ItemStatus)status);
|
||||
}
|
||||
|
||||
AppletInterface::ItemStatus AppletInterface::status() const
|
||||
{
|
||||
return (AppletInterface::ItemStatus)((int)(applet()->status()));
|
||||
}
|
||||
|
||||
void AppletInterface::setHorizontalSizePolicy(QtSizePolicy horizPolicy)
|
||||
{
|
||||
QSizePolicy policy = applet()->sizePolicy();
|
||||
policy.setHorizontalPolicy((QSizePolicy::Policy)horizPolicy);
|
||||
applet()->setSizePolicy(policy);
|
||||
}
|
||||
|
||||
AppletInterface::QtSizePolicy AppletInterface::horizontalSizePolicy() const
|
||||
{
|
||||
return (AppletInterface::QtSizePolicy)applet()->sizePolicy().horizontalPolicy();
|
||||
}
|
||||
|
||||
|
||||
void AppletInterface::setVerticalSizePolicy(QtSizePolicy vertPolicy)
|
||||
{
|
||||
QSizePolicy policy = applet()->sizePolicy();
|
||||
policy.setVerticalPolicy((QSizePolicy::Policy)vertPolicy);
|
||||
applet()->setSizePolicy(policy);
|
||||
}
|
||||
|
||||
AppletInterface::QtSizePolicy AppletInterface::verticalSizePolicy() const
|
||||
{
|
||||
return (AppletInterface::QtSizePolicy)applet()->sizePolicy().verticalPolicy();
|
||||
}
|
||||
|
||||
/*
|
||||
QString AppletInterface::downloadPath(const QString &file)
|
||||
{
|
||||
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 + '/';
|
||||
}
|
||||
*/
|
||||
|
||||
QStringList AppletInterface::downloadedFiles() const
|
||||
{
|
||||
const QString downloadDir = KGlobalSettings::downloadPath() + "/Plasma/" + applet()->pluginName();
|
||||
QDir dir(downloadDir);
|
||||
return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable);
|
||||
}
|
||||
|
||||
void AppletInterface::gc()
|
||||
{
|
||||
QTimer::singleShot(0, m_appletScriptEngine, SLOT(collectGarbage()));
|
||||
}
|
||||
|
||||
|
||||
PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent)
|
||||
: APPLETSUPERCLASS(parent)
|
||||
{
|
||||
connect(m_appletScriptEngine, SIGNAL(popupEvent(bool)), this, SIGNAL(popupEvent(bool)));
|
||||
connect(m_appletScriptEngine, SIGNAL(popupEvent(bool)), this, SLOT(sourceAppletPopupEvent(bool)));
|
||||
}
|
||||
|
||||
void PopupAppletInterface::setPopupIcon(const QIcon &icon)
|
||||
{
|
||||
popupApplet()->setPopupIcon(icon);
|
||||
}
|
||||
|
||||
QIcon PopupAppletInterface::popupIcon()
|
||||
{
|
||||
return popupApplet()->popupIcon();
|
||||
}
|
||||
|
||||
void PopupAppletInterface::setPopupIconByName(const QString &name)
|
||||
{
|
||||
return popupApplet()->setPopupIcon(name);
|
||||
}
|
||||
|
||||
void PopupAppletInterface::setPopupIconToolTip(const QVariantHash &data)
|
||||
{
|
||||
if (data == m_rawToolTipData) {
|
||||
return;
|
||||
} else if (!data.contains("image") && !data.contains("mainText") &&
|
||||
!data.contains("subText")) {
|
||||
m_rawToolTipData = QVariantHash();
|
||||
Plasma::ToolTipManager::self()->clearContent(popupApplet());
|
||||
Plasma::ToolTipManager::self()->unregisterWidget(popupApplet());
|
||||
emit popupIconToolTipChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Plasma::ToolTipContent content(data.value("mainText").toString(), data.value("subText").toString());
|
||||
|
||||
const QVariant image = data.value("image");
|
||||
if (image.canConvert<QIcon>()) {
|
||||
content.setImage(image.value<QIcon>());
|
||||
} else if (image.canConvert<QPixmap>()) {
|
||||
content.setImage(image.value<QPixmap>());
|
||||
} else if (image.canConvert<QImage>()) {
|
||||
content.setImage(QPixmap::fromImage(image.value<QImage>()));
|
||||
} else if (image.canConvert<QString>()) {
|
||||
content.setImage(KIcon(image.toString()));
|
||||
}
|
||||
|
||||
Plasma::ToolTipManager::self()->registerWidget(popupApplet());
|
||||
Plasma::ToolTipManager::self()->setContent(popupApplet(), content);
|
||||
m_rawToolTipData = data;
|
||||
m_toolTipData = content;
|
||||
emit popupIconToolTipChanged();
|
||||
}
|
||||
|
||||
QVariantHash PopupAppletInterface::popupIconToolTip() const
|
||||
{
|
||||
return m_rawToolTipData;
|
||||
}
|
||||
|
||||
void PopupAppletInterface::setPassivePopup(bool passive)
|
||||
{
|
||||
popupApplet()->setPassivePopup(passive);
|
||||
}
|
||||
|
||||
bool PopupAppletInterface::isPassivePopup() const
|
||||
{
|
||||
return popupApplet()->isPassivePopup();
|
||||
}
|
||||
|
||||
bool PopupAppletInterface::isPopupShowing() const
|
||||
{
|
||||
return popupApplet()->isPopupShowing();
|
||||
}
|
||||
|
||||
void PopupAppletInterface::setPopupShowing(bool show)
|
||||
{
|
||||
show ? popupApplet()->showPopup() : popupApplet()->hidePopup();
|
||||
}
|
||||
|
||||
void PopupAppletInterface::togglePopup()
|
||||
{
|
||||
popupApplet()->togglePopup();
|
||||
}
|
||||
|
||||
void PopupAppletInterface::hidePopup()
|
||||
{
|
||||
popupApplet()->hidePopup();
|
||||
}
|
||||
|
||||
void PopupAppletInterface::showPopup()
|
||||
{
|
||||
popupApplet()->showPopup();
|
||||
}
|
||||
|
||||
void PopupAppletInterface::showPopup(int timeout)
|
||||
{
|
||||
popupApplet()->showPopup(timeout);
|
||||
}
|
||||
|
||||
void PopupAppletInterface::setPopupWidget(QGraphicsWidget *widget)
|
||||
{
|
||||
popupApplet()->setGraphicsWidget(widget);
|
||||
}
|
||||
|
||||
QGraphicsWidget *PopupAppletInterface::popupWidget()
|
||||
{
|
||||
return popupApplet()->graphicsWidget();
|
||||
}
|
||||
|
||||
void PopupAppletInterface::sourceAppletPopupEvent(bool show)
|
||||
{
|
||||
if (show) {
|
||||
Plasma::ToolTipManager::self()->clearContent(popupApplet());
|
||||
} else {
|
||||
Plasma::ToolTipManager::self()->registerWidget(popupApplet());
|
||||
Plasma::ToolTipManager::self()->setContent(popupApplet(), m_toolTipData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////// ContainmentInterface
|
||||
|
||||
ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
|
||||
: APPLETSUPERCLASS(parent),
|
||||
m_movableApplets(true),
|
||||
m_toolBox(0)
|
||||
{
|
||||
connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *)));
|
||||
|
||||
connect(containment(), SIGNAL(appletAdded(Plasma::Applet *, const QPointF &)), this, SLOT(appletAddedForward(Plasma::Applet *, const QPointF &)));
|
||||
|
||||
connect(containment(), SIGNAL(screenChanged(int, int, Plasma::Containment*)), this, SIGNAL(screenChanged()));
|
||||
|
||||
connect(containment()->context(), SIGNAL(activityChanged(Plasma::Context *)), this, SIGNAL(activityNameChanged()));
|
||||
connect(containment()->context(), SIGNAL(changed(Plasma::Context *)), this, SIGNAL(activityIdChanged()));
|
||||
|
||||
if (containment()->corona()) {
|
||||
connect(containment()->corona(), SIGNAL(availableScreenRegionChanged()),
|
||||
this, SIGNAL(availableScreenRegionChanged()));
|
||||
}
|
||||
|
||||
qmlRegisterType<AppletContainer>("org.kde.plasma.containments", 0, 1, "AppletContainer");
|
||||
qmlRegisterType<ToolBoxProxy>();
|
||||
}
|
||||
|
||||
QScriptValue ContainmentInterface::applets()
|
||||
{
|
||||
QScriptValue list = m_appletScriptEngine->engine()->newArray(containment()->applets().size());
|
||||
int i = 0;
|
||||
foreach (Plasma::Applet *applet, containment()->applets()) {
|
||||
list.setProperty(i, m_appletScriptEngine->engine()->newQObject(applet));
|
||||
++i;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void ContainmentInterface::setDrawWallpaper(bool drawWallpaper)
|
||||
{
|
||||
m_appletScriptEngine->setDrawWallpaper(drawWallpaper);
|
||||
}
|
||||
|
||||
bool ContainmentInterface::drawWallpaper()
|
||||
{
|
||||
return m_appletScriptEngine->drawWallpaper();
|
||||
}
|
||||
|
||||
ContainmentInterface::Type ContainmentInterface::containmentType() const
|
||||
{
|
||||
return (ContainmentInterface::Type)m_appletScriptEngine->containmentType();
|
||||
}
|
||||
|
||||
void ContainmentInterface::setContainmentType(ContainmentInterface::Type type)
|
||||
{
|
||||
m_appletScriptEngine->setContainmentType((Plasma::Containment::Type)type);
|
||||
}
|
||||
|
||||
int ContainmentInterface::screen() const
|
||||
{
|
||||
return containment()->screen();
|
||||
}
|
||||
|
||||
QScriptValue ContainmentInterface::screenGeometry(int id) const
|
||||
{
|
||||
QRectF rect;
|
||||
if (containment()->corona()) {
|
||||
rect = QRectF(containment()->corona()->screenGeometry(id));
|
||||
}
|
||||
|
||||
QScriptValue val = m_appletScriptEngine->engine()->newObject();
|
||||
val.setProperty("x", rect.x());
|
||||
val.setProperty("y", rect.y());
|
||||
val.setProperty("width", rect.width());
|
||||
val.setProperty("height", rect.height());
|
||||
return val;
|
||||
}
|
||||
|
||||
QScriptValue ContainmentInterface::availableScreenRegion(int id) const
|
||||
{
|
||||
QRegion reg;
|
||||
if (containment()->corona()) {
|
||||
reg = containment()->corona()->availableScreenRegion(id);
|
||||
}
|
||||
|
||||
QScriptValue regVal = m_appletScriptEngine->engine()->newArray(reg.rects().size());
|
||||
int i = 0;
|
||||
foreach (QRect rect, reg.rects()) {
|
||||
QScriptValue val = m_appletScriptEngine->engine()->newObject();
|
||||
val.setProperty("x", rect.x());
|
||||
val.setProperty("y", rect.y());
|
||||
val.setProperty("width", rect.width());
|
||||
val.setProperty("height", rect.height());
|
||||
regVal.setProperty(i++, val);
|
||||
}
|
||||
return regVal;
|
||||
}
|
||||
|
||||
void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPointF &pos)
|
||||
{
|
||||
applet->setFlag(QGraphicsItem::ItemIsMovable, m_movableApplets);
|
||||
emit appletAdded(applet, pos);
|
||||
}
|
||||
|
||||
void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet)
|
||||
{
|
||||
applet->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
emit appletRemoved(applet);
|
||||
}
|
||||
|
||||
void ContainmentInterface::setMovableApplets(bool movable)
|
||||
{
|
||||
if (m_movableApplets == movable) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_movableApplets = movable;
|
||||
|
||||
foreach (Plasma::Applet *applet, containment()->applets()) {
|
||||
applet->setFlag(QGraphicsItem::ItemIsMovable, movable);
|
||||
}
|
||||
}
|
||||
|
||||
bool ContainmentInterface::hasMovableApplets() const
|
||||
{
|
||||
return m_movableApplets;
|
||||
}
|
||||
|
||||
QString ContainmentInterface::activityName() const
|
||||
{
|
||||
return containment()->context()->currentActivity();
|
||||
}
|
||||
|
||||
QString ContainmentInterface::activityId() const
|
||||
{
|
||||
return containment()->context()->currentActivityId();
|
||||
}
|
||||
|
||||
ToolBoxProxy* ContainmentInterface::toolBox()
|
||||
{
|
||||
if (!m_toolBox) {
|
||||
m_toolBox = new ToolBoxProxy(containment(), this);
|
||||
//m_appletScriptEngine->setToolBox(m_toolBox); // setToolBox() is protected :/
|
||||
}
|
||||
return m_toolBox;
|
||||
}
|
||||
|
||||
#ifndef USE_JS_SCRIPTENGINE
|
||||
#include "appletinterface.moc"
|
||||
#endif
|
@ -1,457 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Chani Armitage <chani@kde.org>
|
||||
* Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010 Marco Martin <mart@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 APPLETINTERFACE_H
|
||||
#define APPLETINTERFACE_H
|
||||
|
||||
#include <QAbstractAnimation>
|
||||
#include <QObject>
|
||||
#include <QSizePolicy>
|
||||
#include <QScriptValue>
|
||||
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/PopupApplet>
|
||||
#include <Plasma/DataEngine>
|
||||
#include <Plasma/Theme>
|
||||
#include <Plasma/ToolTipContent>
|
||||
|
||||
#include "abstractjsappletscript.h"
|
||||
#include "../declarative/toolboxproxy.h"
|
||||
|
||||
class QAction;
|
||||
class QmlAppletScript;
|
||||
class QSignalMapper;
|
||||
class QSizeF;
|
||||
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class ConfigLoader;
|
||||
class Extender;
|
||||
} // namespace Plasa
|
||||
|
||||
class AppletInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(FormFactor)
|
||||
Q_ENUMS(Location)
|
||||
Q_ENUMS(BackgroundHints)
|
||||
Q_ENUMS(QtOrientation)
|
||||
Q_ENUMS(QtModifiers)
|
||||
Q_ENUMS(QtAnchorPoint)
|
||||
Q_ENUMS(QtCorner)
|
||||
Q_ENUMS(QtSizePolicy)
|
||||
Q_ENUMS(QtAlignment)
|
||||
Q_ENUMS(QtMouseButton)
|
||||
Q_ENUMS(AnimationDirection)
|
||||
Q_ENUMS(IntervalAlignment)
|
||||
Q_ENUMS(ThemeColors)
|
||||
Q_ENUMS(ItemStatus)
|
||||
Q_PROPERTY(FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
|
||||
Q_PROPERTY(Location location READ location NOTIFY locationChanged)
|
||||
Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged)
|
||||
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
|
||||
Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig)
|
||||
Q_PROPERTY(bool busy WRITE setBusy READ isBusy)
|
||||
Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints)
|
||||
Q_PROPERTY(bool immutable READ immutable NOTIFY immutableChanged)
|
||||
Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5
|
||||
Q_PROPERTY(int apiVersion READ apiVersion CONSTANT)
|
||||
Q_PROPERTY(ItemStatus status READ status WRITE setStatus NOTIFY statusChanged)
|
||||
Q_PROPERTY(QRectF rect READ rect)
|
||||
Q_PROPERTY(QSizeF size READ size)
|
||||
Q_PROPERTY(QString associatedApplication WRITE setAssociatedApplication READ associatedApplication)
|
||||
Q_PROPERTY(QtSizePolicy horizontalSizePolicy READ horizontalSizePolicy WRITE setHorizontalSizePolicy)
|
||||
Q_PROPERTY(QtSizePolicy verticalSizePolicy READ verticalSizePolicy WRITE setVerticalSizePolicy)
|
||||
|
||||
public:
|
||||
AppletInterface(AbstractJsAppletScript *parent);
|
||||
~AppletInterface();
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//enums copy&pasted from plasma.h because qtscript is evil
|
||||
|
||||
enum FormFactor {
|
||||
Planar = 0, /**< The applet lives in a plane and has two
|
||||
degrees of freedom to grow. Optimize for
|
||||
desktop, laptop or tablet usage: a high
|
||||
resolution screen 1-3 feet distant from the
|
||||
viewer. */
|
||||
MediaCenter, /**< As with Planar, the applet lives in a plane
|
||||
but the interface should be optimized for
|
||||
medium-to-high resolution screens that are
|
||||
5-15 feet distant from the viewer. Sometimes
|
||||
referred to as a "ten foot interface".*/
|
||||
Horizontal, /**< The applet is constrained vertically, but
|
||||
can expand horizontally. */
|
||||
Vertical, /**< The applet is constrained horizontally, but
|
||||
can expand vertically. */
|
||||
Application /**< The Applet lives in a plane and should be optimized to look as a full application,
|
||||
for the desktop or the particular device. */
|
||||
};
|
||||
|
||||
enum Location {
|
||||
Floating = 0, /**< Free floating. Neither geometry or z-ordering
|
||||
is described precisely by this value. */
|
||||
Desktop, /**< On the planar desktop layer, extending across
|
||||
the full screen from edge to edge */
|
||||
FullScreen, /**< Full screen */
|
||||
TopEdge, /**< Along the top of the screen*/
|
||||
BottomEdge, /**< Along the bottom of the screen*/
|
||||
LeftEdge, /**< Along the left side of the screen */
|
||||
RightEdge /**< Along the right side of the screen */
|
||||
};
|
||||
|
||||
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 **/
|
||||
};
|
||||
|
||||
//From Qt namespace
|
||||
enum QtModifiers {
|
||||
QtNoModifier = Qt::NoModifier,
|
||||
QtShiftModifier = Qt::ShiftModifier,
|
||||
QtControlModifier = Qt::ControlModifier,
|
||||
QtAltModifier = Qt::AltModifier,
|
||||
QtMetaModifier = Qt::MetaModifier
|
||||
};
|
||||
|
||||
enum QtOrientation {
|
||||
QtHorizontal= Qt::Horizontal,
|
||||
QtVertical = Qt::Vertical
|
||||
};
|
||||
|
||||
enum QtAnchorPoint {
|
||||
QtAnchorLeft = Qt::AnchorLeft,
|
||||
QtAnchorRight = Qt::AnchorRight,
|
||||
QtAnchorBottom = Qt::AnchorBottom,
|
||||
QtAnchorTop = Qt::AnchorTop,
|
||||
QtAnchorHorizontalCenter = Qt::AnchorHorizontalCenter,
|
||||
QtAnchorVerticalCenter = Qt::AnchorVerticalCenter
|
||||
};
|
||||
|
||||
enum QtCorner {
|
||||
QtTopLeftCorner = Qt::TopLeftCorner,
|
||||
QtTopRightCorner = Qt::TopRightCorner,
|
||||
QtBottomLeftCorner = Qt::BottomLeftCorner,
|
||||
QtBottomRightCorner = Qt::BottomRightCorner
|
||||
};
|
||||
|
||||
enum QtSizePolicy {
|
||||
QSizePolicyFixed = QSizePolicy::Fixed,
|
||||
QSizePolicyMinimum = QSizePolicy::Minimum,
|
||||
QSizePolicyMaximum = QSizePolicy::Maximum,
|
||||
QSizePolicyPreferred = QSizePolicy::Preferred,
|
||||
QSizePolicyExpanding = QSizePolicy::Expanding,
|
||||
QSizePolicyMinimumExpanding = QSizePolicy::MinimumExpanding,
|
||||
QSizePolicyIgnored = QSizePolicy::Ignored
|
||||
};
|
||||
|
||||
enum BackgroundHints {
|
||||
NoBackground = Plasma::Applet::NoBackground,
|
||||
StandardBackground = Plasma::Applet::StandardBackground,
|
||||
TranslucentBackground = Plasma::Applet::TranslucentBackground,
|
||||
DefaultBackground = Plasma::Applet::DefaultBackground
|
||||
};
|
||||
|
||||
enum ThemeColors {
|
||||
TextColor = Plasma::Theme::TextColor,
|
||||
HighlightColor = Plasma::Theme::HighlightColor,
|
||||
BackgroundColor = Plasma::Theme::BackgroundColor,
|
||||
ButtonTextColor = Plasma::Theme::ButtonTextColor,
|
||||
ButtonBackgroundColor = Plasma::Theme::ButtonBackgroundColor,
|
||||
LinkColor = Plasma::Theme::LinkColor,
|
||||
VisitedLinkColor = Plasma::Theme::VisitedLinkColor
|
||||
};
|
||||
|
||||
enum QtAlignment {
|
||||
QtAlignLeft = 0x0001,
|
||||
QtAlignRight = 0x0002,
|
||||
QtAlignHCenter = 0x0004,
|
||||
QtAlignJustify = 0x0005,
|
||||
QtAlignTop = 0x0020,
|
||||
QtAlignBottom = 0x0020,
|
||||
QtAlignVCenter = 0x0080
|
||||
};
|
||||
|
||||
enum QtMouseButton {
|
||||
QtNoButton = Qt::NoButton,
|
||||
QtLeftButton = Qt::LeftButton,
|
||||
QtRightButton = Qt::RightButton,
|
||||
QtMidButton = Qt::MidButton,
|
||||
QtXButton1 = Qt::XButton1,
|
||||
QtXButton2 = Qt::XButton2
|
||||
};
|
||||
|
||||
enum QtScrollBarPolicy {
|
||||
QtScrollBarAsNeeded = Qt::ScrollBarAsNeeded,
|
||||
QtScrollBarAlwaysOff = Qt::ScrollBarAlwaysOff,
|
||||
QtScrollBarAlwaysOn = Qt::ScrollBarAlwaysOn
|
||||
};
|
||||
|
||||
enum AnimationDirection {
|
||||
AnimationForward = QAbstractAnimation::Forward,
|
||||
AnimationBackward = QAbstractAnimation::Backward
|
||||
};
|
||||
|
||||
enum IntervalAlignment {
|
||||
NoAlignment = 0,
|
||||
AlignToMinute,
|
||||
AlignToHour
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
Q_INVOKABLE void gc();
|
||||
Q_INVOKABLE FormFactor formFactor() const;
|
||||
|
||||
Location location() const;
|
||||
QString currentActivity() const;
|
||||
bool shouldConserveResources() const;
|
||||
|
||||
Q_INVOKABLE void setFailedToLaunch(bool failed, const QString &reason = QString());
|
||||
|
||||
Q_INVOKABLE bool isBusy() const;
|
||||
Q_INVOKABLE void setBusy(bool busy);
|
||||
|
||||
Q_INVOKABLE BackgroundHints backgroundHints() const;
|
||||
Q_INVOKABLE void setBackgroundHints(BackgroundHints hint);
|
||||
|
||||
Q_INVOKABLE void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
|
||||
|
||||
Q_INVOKABLE QSizeF size() const;
|
||||
Q_INVOKABLE QRectF rect() const;
|
||||
|
||||
Q_INVOKABLE void setActionSeparator(const QString &name);
|
||||
Q_INVOKABLE void setAction(const QString &name, const QString &text,
|
||||
const QString &icon = QString(), const QString &shortcut = QString());
|
||||
|
||||
Q_INVOKABLE void removeAction(const QString &name);
|
||||
|
||||
Q_INVOKABLE QAction *action(QString name) const;
|
||||
|
||||
Q_INVOKABLE void resize(qreal w, qreal h);
|
||||
|
||||
Q_INVOKABLE void setMinimumSize(qreal w, qreal h);
|
||||
|
||||
Q_INVOKABLE void setPreferredSize(qreal w, qreal h);
|
||||
|
||||
Q_INVOKABLE QString activeConfig() const;
|
||||
|
||||
Q_INVOKABLE void setActiveConfig(const QString &name);
|
||||
|
||||
Q_INVOKABLE QScriptValue readConfig(const QString &entry) const;
|
||||
|
||||
Q_INVOKABLE void writeConfig(const QString &entry, const QVariant &value);
|
||||
|
||||
Q_INVOKABLE QString file(const QString &fileType);
|
||||
Q_INVOKABLE QString file(const QString &fileType, const QString &filePath);
|
||||
|
||||
Q_INVOKABLE bool include(const QString &script);
|
||||
|
||||
Q_INVOKABLE void debug(const QString &msg);
|
||||
Q_INVOKABLE QObject *findChild(const QString &name) const;
|
||||
|
||||
Q_INVOKABLE Plasma::Extender *extender() const;
|
||||
|
||||
Plasma::DataEngine *dataEngine(const QString &name);
|
||||
|
||||
QList<QAction*> contextualActions() const;
|
||||
bool immutable() const;
|
||||
bool userConfiguring() const;
|
||||
int apiVersion() const;
|
||||
|
||||
static AppletInterface *extract(QScriptEngine *engine);
|
||||
inline Plasma::Applet *applet() const { return m_appletScriptEngine->applet(); }
|
||||
|
||||
void setAssociatedApplication(const QString &string);
|
||||
QString associatedApplication() const;
|
||||
|
||||
void setStatus(const ItemStatus &status);
|
||||
ItemStatus status() const;
|
||||
|
||||
void setHorizontalSizePolicy(QtSizePolicy policy);
|
||||
QtSizePolicy horizontalSizePolicy() const;
|
||||
|
||||
void setVerticalSizePolicy(QtSizePolicy policy);
|
||||
QtSizePolicy verticalSizePolicy() const;
|
||||
|
||||
// Q_INVOKABLE QString downloadPath(const QString &file);
|
||||
Q_INVOKABLE QStringList downloadedFiles() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void releaseVisualFocus();
|
||||
void configNeedsSaving();
|
||||
|
||||
void formFactorChanged();
|
||||
void locationChanged();
|
||||
void contextChanged();
|
||||
void immutableChanged();
|
||||
void statusChanged();
|
||||
|
||||
protected:
|
||||
AbstractJsAppletScript *m_appletScriptEngine;
|
||||
|
||||
private:
|
||||
QStringList m_actions;
|
||||
QSignalMapper *m_actionSignals;
|
||||
QString m_currentConfig;
|
||||
QMap<QString, Plasma::ConfigLoader*> m_configs;
|
||||
};
|
||||
|
||||
class JsAppletInterface : public AppletInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QGraphicsLayout *layout WRITE setLayout READ layout)
|
||||
Q_PROPERTY(QObject *sender READ sender)
|
||||
|
||||
public:
|
||||
JsAppletInterface(AbstractJsAppletScript *parent)
|
||||
: AppletInterface(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Q_INVOKABLE void update(const QRectF &rect = QRectF());
|
||||
QGraphicsLayout *layout() const;
|
||||
void setLayout(QGraphicsLayout *);
|
||||
};
|
||||
|
||||
#ifdef USE_JS_SCRIPTENGINE
|
||||
#define APPLETSUPERCLASS JsAppletInterface
|
||||
#else
|
||||
#define APPLETSUPERCLASS AppletInterface
|
||||
#endif
|
||||
class PopupAppletInterface : public APPLETSUPERCLASS
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QIcon popupIcon READ popupIcon WRITE setPopupIcon)
|
||||
Q_PROPERTY(bool passivePopup READ isPassivePopup WRITE setPassivePopup)
|
||||
Q_PROPERTY(QGraphicsWidget *popupWidget READ popupWidget WRITE setPopupWidget)
|
||||
Q_PROPERTY(QVariantHash popupIconToolTip READ popupIconToolTip WRITE setPopupIconToolTip NOTIFY popupIconToolTipChanged)
|
||||
Q_PROPERTY(bool popupShowing READ isPopupShowing WRITE setPopupShowing NOTIFY popupEvent)
|
||||
|
||||
public:
|
||||
PopupAppletInterface(AbstractJsAppletScript *parent);
|
||||
|
||||
void setPopupIcon(const QIcon &icon);
|
||||
QIcon popupIcon();
|
||||
|
||||
void setPopupIconToolTip(const QVariantHash &data);
|
||||
QVariantHash popupIconToolTip() const;
|
||||
|
||||
inline Plasma::PopupApplet *popupApplet() const { return static_cast<Plasma::PopupApplet *>(m_appletScriptEngine->applet()); }
|
||||
|
||||
void setPassivePopup(bool passive);
|
||||
bool isPassivePopup() const;
|
||||
|
||||
bool isPopupShowing() const;
|
||||
void setPopupShowing(bool show);
|
||||
|
||||
void setPopupWidget(QGraphicsWidget *widget);
|
||||
QGraphicsWidget *popupWidget();
|
||||
|
||||
Q_SIGNALS:
|
||||
void popupEvent(bool popupShowing);
|
||||
void popupIconToolTipChanged();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setPopupIconByName(const QString &name);
|
||||
void togglePopup();
|
||||
void hidePopup();
|
||||
void showPopup();
|
||||
void showPopup(int timeout);
|
||||
|
||||
private Q_SLOTS:
|
||||
void sourceAppletPopupEvent(bool show);
|
||||
|
||||
private:
|
||||
QVariantHash m_rawToolTipData;
|
||||
Plasma::ToolTipContent m_toolTipData;
|
||||
};
|
||||
|
||||
|
||||
class ContainmentInterface : public APPLETSUPERCLASS
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QScriptValue applets READ applets)
|
||||
Q_PROPERTY(bool drawWallpaper READ drawWallpaper WRITE setDrawWallpaper)
|
||||
Q_PROPERTY(Type containmentType READ containmentType WRITE setContainmentType)
|
||||
Q_PROPERTY(int screen READ screen NOTIFY screenChanged)
|
||||
Q_PROPERTY(bool movableApplets READ hasMovableApplets WRITE setMovableApplets)
|
||||
Q_PROPERTY(QString activityName READ activityName NOTIFY activityNameChanged)
|
||||
Q_PROPERTY(QString activityId READ activityId NOTIFY activityIdChanged)
|
||||
Q_PROPERTY(ToolBoxProxy* toolBox READ toolBox CONSTANT)
|
||||
Q_ENUMS(Type)
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
NoContainmentType = -1, /**< @internal */
|
||||
DesktopContainment = 0, /**< A desktop containment */
|
||||
PanelContainment, /**< A desktop panel */
|
||||
CustomContainment = 127, /**< A containment that is neither a desktop nor a panel
|
||||
but something application specific */
|
||||
CustomPanelContainment = 128 /**< A customized desktop panel */
|
||||
};
|
||||
ContainmentInterface(AbstractJsAppletScript *parent);
|
||||
|
||||
inline Plasma::Containment *containment() const { return static_cast<Plasma::Containment *>(m_appletScriptEngine->applet()); }
|
||||
|
||||
QScriptValue applets();
|
||||
|
||||
void setDrawWallpaper(bool drawWallpaper);
|
||||
bool drawWallpaper();
|
||||
Type containmentType() const;
|
||||
void setContainmentType(Type type);
|
||||
int screen() const;
|
||||
|
||||
void setMovableApplets(bool movable);
|
||||
bool hasMovableApplets() const;
|
||||
|
||||
QString activityName() const;
|
||||
QString activityId() const;
|
||||
|
||||
ToolBoxProxy* toolBox();
|
||||
|
||||
Q_INVOKABLE QScriptValue screenGeometry(int id) const;
|
||||
Q_INVOKABLE QScriptValue availableScreenRegion(int id) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void appletAdded(QGraphicsWidget *applet, const QPointF &pos);
|
||||
void appletRemoved(QGraphicsWidget *applet);
|
||||
void screenChanged();
|
||||
void activityNameChanged();
|
||||
void activityIdChanged();
|
||||
void availableScreenRegionChanged();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void appletAddedForward(Plasma::Applet *applet, const QPointF &pos);
|
||||
void appletRemovedForward(Plasma::Applet *applet);
|
||||
|
||||
private:
|
||||
bool m_movableApplets;
|
||||
ToolBoxProxy* m_toolBox;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,583 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 by Alan Alpert <alan.alpert@nokia.com>
|
||||
* Copyright 2010 by Ménard Alexis <menard@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 <QDeclarativeComponent>
|
||||
#include <QDeclarativeContext>
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QDeclarativeExpression>
|
||||
#include <QFile>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValueIterator>
|
||||
#include <QTimer>
|
||||
#include <QUiLoader>
|
||||
#include <QWidget>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KDebug>
|
||||
#include <KGlobalSettings>
|
||||
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/DeclarativeWidget>
|
||||
#include <Plasma/Extender>
|
||||
#include <Plasma/ExtenderItem>
|
||||
#include <Plasma/FrameSvg>
|
||||
#include <Plasma/Package>
|
||||
#include <Plasma/PopupApplet>
|
||||
#include <Plasma/Svg>
|
||||
|
||||
|
||||
#include "plasmoid/declarativeappletscript.h"
|
||||
|
||||
#include "plasmoid/appletinterface.h"
|
||||
#include "plasmoid/themedsvg.h"
|
||||
|
||||
#include "common/scriptenv.h"
|
||||
#include "declarative/declarativeitemcontainer_p.h"
|
||||
#include "declarative/packageaccessmanagerfactory.h"
|
||||
#include "simplebindings/bytearrayclass.h"
|
||||
//not pretty but only way to avoid a double Q_DECLARE_METATYPE(QVariant) in dataengine.h
|
||||
#define DECLARATIVE_BINDING
|
||||
#include "simplebindings/dataengine.h"
|
||||
#include "simplebindings/dataenginereceiver.h"
|
||||
|
||||
|
||||
K_EXPORT_PLASMA_APPLETSCRIPTENGINE(declarativeappletscript, DeclarativeAppletScript)
|
||||
|
||||
|
||||
QScriptValue constructIconClass(QScriptEngine *engine);
|
||||
QScriptValue constructKUrlClass(QScriptEngine *engine);
|
||||
QScriptValue constructQPointClass(QScriptEngine *engine);
|
||||
void registerSimpleAppletMetaTypes(QScriptEngine *engine);
|
||||
DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariantList &args)
|
||||
: AbstractJsAppletScript(parent, args),
|
||||
m_declarativeWidget(0),
|
||||
m_toolBoxWidget(0),
|
||||
m_interface(0),
|
||||
m_engine(0),
|
||||
m_env(0),
|
||||
m_auth(this)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
}
|
||||
|
||||
DeclarativeAppletScript::~DeclarativeAppletScript()
|
||||
{
|
||||
}
|
||||
|
||||
bool DeclarativeAppletScript::init()
|
||||
{
|
||||
m_declarativeWidget = new Plasma::DeclarativeWidget(applet());
|
||||
m_declarativeWidget->setInitializationDelayed(true);
|
||||
connect(m_declarativeWidget, SIGNAL(finished()), this, SLOT(qmlCreationFinished()));
|
||||
KGlobal::locale()->insertCatalog("plasma_applet_" % description().pluginName());
|
||||
|
||||
//make possible to import extensions from the package
|
||||
//FIXME: probably to be removed, would make possible to use native code from within the package :/
|
||||
//m_declarativeWidget->engine()->addImportPath(package()->path()+"/contents/imports");
|
||||
|
||||
//use our own custom network access manager that will access Plasma packages and to manage security (i.e. deny access to remote stuff when the proper extension isn't enabled
|
||||
QDeclarativeEngine *engine = m_declarativeWidget->engine();
|
||||
QDeclarativeNetworkAccessManagerFactory *factory = engine->networkAccessManagerFactory();
|
||||
engine->setNetworkAccessManagerFactory(0);
|
||||
delete factory;
|
||||
engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory(package(), &m_auth));
|
||||
|
||||
m_declarativeWidget->setQmlPath(mainScript());
|
||||
|
||||
if (!m_declarativeWidget->engine() || !m_declarativeWidget->engine()->rootContext() || !m_declarativeWidget->engine()->rootContext()->isValid() || m_declarativeWidget->mainComponent()->isError()) {
|
||||
QString reason;
|
||||
foreach (QDeclarativeError error, m_declarativeWidget->mainComponent()->errors()) {
|
||||
reason += error.toString()+'\n';
|
||||
}
|
||||
setFailedToLaunch(true, reason);
|
||||
return false;
|
||||
}
|
||||
|
||||
Plasma::Applet *a = applet();
|
||||
Plasma::PopupApplet *pa = qobject_cast<Plasma::PopupApplet *>(a);
|
||||
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(a);
|
||||
|
||||
if (pa) {
|
||||
pa->setPopupIcon(a->icon());
|
||||
pa->setGraphicsWidget(m_declarativeWidget);
|
||||
} else {
|
||||
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(a);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->addItem(m_declarativeWidget);
|
||||
}
|
||||
|
||||
if (pa) {
|
||||
m_interface = new PopupAppletInterface(this);
|
||||
} else if (cont) {
|
||||
m_interface = new ContainmentInterface(this);
|
||||
//fail? so it's a normal Applet
|
||||
} else {
|
||||
m_interface = new AppletInterface(this);
|
||||
}
|
||||
|
||||
connect(applet(), SIGNAL(extenderItemRestored(Plasma::ExtenderItem*)),
|
||||
this, SLOT(extenderItemRestored(Plasma::ExtenderItem*)));
|
||||
connect(applet(), SIGNAL(activate()),
|
||||
this, SLOT(activate()));
|
||||
|
||||
setupObjects();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::qmlCreationFinished()
|
||||
{
|
||||
//If it's a popupapplet and the root object has a "compactRepresentation" component, use that instead of the icon
|
||||
Plasma::Applet *a = applet();
|
||||
Plasma::PopupApplet *pa = qobject_cast<Plasma::PopupApplet *>(a);
|
||||
m_self.setProperty("rootItem", m_engine->newQObject(m_declarativeWidget->rootObject()));
|
||||
|
||||
if (pa) {
|
||||
QDeclarativeComponent *iconComponent = m_declarativeWidget->rootObject()->property("compactRepresentation").value<QDeclarativeComponent *>();
|
||||
if (iconComponent) {
|
||||
QDeclarativeItem *declarativeIcon = qobject_cast<QDeclarativeItem *>(iconComponent->create(iconComponent->creationContext()));
|
||||
if (declarativeIcon) {
|
||||
pa->setPopupIcon(QIcon());
|
||||
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(a);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
DeclarativeItemContainer *declarativeItemContainer = new DeclarativeItemContainer(a);
|
||||
lay->addItem(declarativeItemContainer);
|
||||
declarativeItemContainer->setDeclarativeItem(declarativeIcon, true);
|
||||
} else {
|
||||
pa->setPopupIcon(a->icon());
|
||||
}
|
||||
} else {
|
||||
pa->setPopupIcon(a->icon());
|
||||
}
|
||||
}
|
||||
|
||||
Plasma::Containment *pc = qobject_cast<Plasma::Containment *>(a);
|
||||
if (pc) {
|
||||
Plasma::PackageStructure::Ptr structure = Plasma::PackageStructure::load("Plasma/Generic");
|
||||
Plasma::Package pkg = Plasma::Package(QString(), "org.kde.toolbox", structure);
|
||||
if (pkg.isValid()) {
|
||||
const QString qmlPath = pkg.filePath("mainscript");
|
||||
|
||||
m_toolBoxWidget = new Plasma::DeclarativeWidget(pc);
|
||||
m_toolBoxWidget->setInitializationDelayed(true);
|
||||
m_toolBoxWidget->setQmlPath(qmlPath);
|
||||
|
||||
QGraphicsLinearLayout *toolBoxScreenLayout = new QGraphicsLinearLayout(m_declarativeWidget);
|
||||
toolBoxScreenLayout->addItem(m_toolBoxWidget);
|
||||
toolBoxScreenLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
QScriptEngine *engine = m_toolBoxWidget->scriptEngine();
|
||||
if (!engine) {
|
||||
return;
|
||||
}
|
||||
QScriptValue global = engine->globalObject();
|
||||
m_self = engine->newQObject(m_interface);
|
||||
m_self.setScope(global);
|
||||
global.setProperty("plasmoid", m_self);
|
||||
} else {
|
||||
kWarning() << "Could not load org.kde.toolbox package.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::collectGarbage()
|
||||
{
|
||||
if (!m_engine) {
|
||||
return;
|
||||
}
|
||||
m_engine->collectGarbage();
|
||||
}
|
||||
|
||||
QString DeclarativeAppletScript::filePath(const QString &type, const QString &file) const
|
||||
{
|
||||
const QString path = m_env->filePathFromScriptContext(type.toLocal8Bit().constData(), file);
|
||||
|
||||
if (!path.isEmpty()) {
|
||||
return path;
|
||||
}
|
||||
|
||||
return package()->filePath(type.toLocal8Bit().constData(), file);
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::configChanged()
|
||||
{
|
||||
if (!m_env) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_env->callEventListeners("configchanged");
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::loadui(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("loadui() takes one argument"));
|
||||
}
|
||||
|
||||
QString filename = context->argument(0).toString();
|
||||
QFile f(filename);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
return context->throwError(i18n("Unable to open '%1'",filename));
|
||||
}
|
||||
|
||||
QUiLoader loader;
|
||||
QWidget *w = loader.load(&f);
|
||||
f.close();
|
||||
|
||||
return engine->newQObject(w, QScriptEngine::AutoOwnership);
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::newPlasmaSvg(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("Constructor takes at least 1 argument"));
|
||||
}
|
||||
|
||||
const QString filename = context->argument(0).toString();
|
||||
Plasma::Svg *svg = new ThemedSvg(0);
|
||||
svg->setImagePath(ThemedSvg::findSvg(engine, filename));
|
||||
|
||||
QScriptValue obj = engine->newQObject(svg);
|
||||
ScriptEnv::registerEnums(obj, *svg->metaObject());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::variantToScriptValue(QVariant var)
|
||||
{
|
||||
if (!m_engine) {
|
||||
return QScriptValue();
|
||||
}
|
||||
return m_engine->newVariant(var);
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("Constructor takes at least 1 argument"));
|
||||
}
|
||||
|
||||
QString filename = context->argument(0).toString();
|
||||
|
||||
bool parentedToApplet = false;
|
||||
QGraphicsWidget *parent = extractParent(context, engine, 1, &parentedToApplet);
|
||||
Plasma::FrameSvg *frameSvg = new ThemedFrameSvg(parent);
|
||||
frameSvg->setImagePath(ThemedSvg::findSvg(engine, filename));
|
||||
|
||||
QScriptValue obj = engine->newQObject(frameSvg);
|
||||
ScriptEnv::registerEnums(obj, *frameSvg->metaObject());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Plasma::Extender *extender = 0;
|
||||
if (context->argumentCount() > 0) {
|
||||
extender = qobject_cast<Plasma::Extender *>(context->argument(0).toQObject());
|
||||
}
|
||||
|
||||
if (!extender) {
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
extender = interface->extender();
|
||||
}
|
||||
|
||||
Plasma::ExtenderItem *extenderItem = new Plasma::ExtenderItem(extender);
|
||||
QScriptValue fun = engine->newQObject(extenderItem);
|
||||
ScriptEnv::registerEnums(fun, *extenderItem->metaObject());
|
||||
return fun;
|
||||
}
|
||||
|
||||
QGraphicsWidget *DeclarativeAppletScript::extractParent(QScriptContext *context, QScriptEngine *engine,
|
||||
int argIndex, bool *parentedToApplet)
|
||||
{
|
||||
if (parentedToApplet) {
|
||||
*parentedToApplet = false;
|
||||
}
|
||||
|
||||
QGraphicsWidget *parent = 0;
|
||||
if (context->argumentCount() >= argIndex) {
|
||||
parent = qobject_cast<QGraphicsWidget*>(context->argument(argIndex).toQObject());
|
||||
}
|
||||
|
||||
if (!parent) {
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//kDebug() << "got the applet!";
|
||||
parent = interface->applet();
|
||||
|
||||
if (parentedToApplet) {
|
||||
*parentedToApplet = true;
|
||||
}
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::callPlasmoidFunction(const QString &functionName, const QScriptValueList &args, ScriptEnv *env)
|
||||
{
|
||||
if (!m_env) {
|
||||
m_env = ScriptEnv::findScriptEnv(m_engine);
|
||||
}
|
||||
|
||||
if (env) {
|
||||
QScriptValue func = m_self.property(functionName);
|
||||
m_env->callFunction(func, args, m_self);
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::constraintsEvent(Plasma::Constraints constraints)
|
||||
{
|
||||
if (constraints & Plasma::FormFactorConstraint) {
|
||||
emit formFactorChanged();
|
||||
}
|
||||
|
||||
if (constraints & Plasma::LocationConstraint) {
|
||||
emit locationChanged();
|
||||
}
|
||||
|
||||
if (constraints & Plasma::ContextConstraint) {
|
||||
emit contextChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::popupEvent(bool popped)
|
||||
{
|
||||
if (!m_env) {
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << popped;
|
||||
|
||||
m_env->callEventListeners("popupEvent", args);
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::dataUpdated(const QString &name, const Plasma::DataEngine::Data &data)
|
||||
{
|
||||
if (!m_engine) {
|
||||
return;
|
||||
}
|
||||
QScriptValueList args;
|
||||
args << m_engine->toScriptValue(name) << m_engine->toScriptValue(data);
|
||||
|
||||
m_env->callEventListeners("dataUpdated", args);
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::extenderItemRestored(Plasma::ExtenderItem* item)
|
||||
{
|
||||
if (!m_env) {
|
||||
return;
|
||||
}
|
||||
if (!m_engine) {
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << m_engine->newQObject(item, QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
|
||||
m_env->callEventListeners("initExtenderItem", args);
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::activate()
|
||||
{
|
||||
if (!m_env) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_env->callEventListeners("activate");
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::executeAction(const QString &name)
|
||||
{
|
||||
if (!m_env) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_declarativeWidget->rootObject()) {
|
||||
QMetaObject::invokeMethod(m_declarativeWidget->rootObject(), QString("action_" + name).toLatin1(), Qt::DirectConnection);
|
||||
}
|
||||
}
|
||||
|
||||
bool DeclarativeAppletScript::include(const QString &path)
|
||||
{
|
||||
return m_env->include(path);
|
||||
}
|
||||
|
||||
ScriptEnv *DeclarativeAppletScript::scriptEnv()
|
||||
{
|
||||
return m_env;
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::setupObjects()
|
||||
{
|
||||
m_engine = m_declarativeWidget->scriptEngine();
|
||||
if (!m_engine) {
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_engine, SIGNAL(signalHandlerException(const QScriptValue &)),
|
||||
this, SLOT(signalHandlerException(const QScriptValue &)));
|
||||
|
||||
delete m_env;
|
||||
m_env = new ScriptEnv(this, m_engine);
|
||||
|
||||
QScriptValue global = m_engine->globalObject();
|
||||
|
||||
QScriptValue v = m_engine->newVariant(QVariant::fromValue(*applet()->package()));
|
||||
global.setProperty("__plasma_package", v,
|
||||
QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
|
||||
|
||||
m_self = m_engine->newQObject(m_interface);
|
||||
m_self.setScope(global);
|
||||
global.setProperty("plasmoid", m_self);
|
||||
m_env->addMainObjectProperties(m_self);
|
||||
|
||||
QScriptValue args = m_engine->newArray();
|
||||
int i = 0;
|
||||
foreach (const QVariant &arg, applet()->startupArguments()) {
|
||||
args.setProperty(i, m_engine->newVariant(arg));
|
||||
++i;
|
||||
}
|
||||
global.setProperty("startupArguments", args);
|
||||
|
||||
// Add a global loadui method for ui files
|
||||
QScriptValue fun = m_engine->newFunction(DeclarativeAppletScript::loadui);
|
||||
global.setProperty("loadui", fun);
|
||||
|
||||
ScriptEnv::registerEnums(global, AppletInterface::staticMetaObject);
|
||||
//Make enum values accessible also as plasmoid.Planar etc
|
||||
ScriptEnv::registerEnums(m_self, AppletInterface::staticMetaObject);
|
||||
|
||||
global.setProperty("dataEngine", m_engine->newFunction(DeclarativeAppletScript::dataEngine));
|
||||
global.setProperty("service", m_engine->newFunction(DeclarativeAppletScript::service));
|
||||
global.setProperty("loadService", m_engine->newFunction(DeclarativeAppletScript::loadService));
|
||||
|
||||
//Add stuff from Qt
|
||||
//TODO: move to libkdeclarative?
|
||||
ByteArrayClass *baClass = new ByteArrayClass(m_engine);
|
||||
global.setProperty("ByteArray", baClass->constructor());
|
||||
global.setProperty("QPoint", constructQPointClass(m_engine));
|
||||
|
||||
// Add stuff from KDE libs
|
||||
qScriptRegisterSequenceMetaType<KUrl::List>(m_engine);
|
||||
global.setProperty("Url", constructKUrlClass(m_engine));
|
||||
|
||||
// Add stuff from Plasma
|
||||
global.setProperty("Svg", m_engine->newFunction(DeclarativeAppletScript::newPlasmaSvg));
|
||||
global.setProperty("FrameSvg", m_engine->newFunction(DeclarativeAppletScript::newPlasmaFrameSvg));
|
||||
global.setProperty("ExtenderItem", m_engine->newFunction(DeclarativeAppletScript::newPlasmaExtenderItem));
|
||||
|
||||
if (!m_env->importExtensions(description(), m_self, m_auth)) {
|
||||
return;
|
||||
}
|
||||
|
||||
registerSimpleAppletMetaTypes(m_engine);
|
||||
QTimer::singleShot(0, this, SLOT(configChanged()));
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::dataEngine(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("dataEngine() takes one argument"));
|
||||
}
|
||||
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return context->throwError(i18n("Could not extract the Applet"));
|
||||
}
|
||||
|
||||
const QString dataEngineName = context->argument(0).toString();
|
||||
Plasma::DataEngine *dataEngine = interface->dataEngine(dataEngineName);
|
||||
QScriptValue v = engine->newQObject(dataEngine, QScriptEngine::QtOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
v.setProperty("connectSource", engine->newFunction(DataEngineReceiver::connectSource));
|
||||
v.setProperty("connectAllSources", engine->newFunction(DataEngineReceiver::connectAllSources));
|
||||
v.setProperty("disconnectSource", engine->newFunction(DataEngineReceiver::disconnectSource));
|
||||
return v;
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::service(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 2) {
|
||||
return context->throwError(i18n("service() takes two arguments"));
|
||||
}
|
||||
|
||||
QString dataEngine = context->argument(0).toString();
|
||||
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return context->throwError(i18n("Could not extract the Applet"));
|
||||
}
|
||||
|
||||
Plasma::DataEngine *data = interface->dataEngine(dataEngine);
|
||||
QString source = context->argument(1).toString();
|
||||
Plasma::Service *service = data->serviceForSource(source);
|
||||
//kDebug( )<< "lets try to get" << source << "from" << dataEngine;
|
||||
return engine->newQObject(service, QScriptEngine::AutoOwnership);
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::loadService(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("service() takes one argument"));
|
||||
}
|
||||
|
||||
QString pluginName = context->argument(0).toString();
|
||||
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return context->throwError(i18n("Could not extract the Applet"));
|
||||
}
|
||||
|
||||
Plasma::Service *service = Plasma::Service::load(pluginName, interface);
|
||||
|
||||
//kDebug( )<< "lets try to get" << source << "from" << dataEngine;
|
||||
return engine->newQObject(service, QScriptEngine::AutoOwnership);
|
||||
}
|
||||
|
||||
QList<QAction*> DeclarativeAppletScript::contextualActions()
|
||||
{
|
||||
if (!m_interface) {
|
||||
return QList<QAction *>();
|
||||
}
|
||||
|
||||
return m_interface->contextualActions();
|
||||
}
|
||||
|
||||
QScriptEngine *DeclarativeAppletScript::engine() const
|
||||
{
|
||||
return m_engine;
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::signalHandlerException(const QScriptValue &exception)
|
||||
{
|
||||
kWarning()<<"Exception caught: "<<exception.toVariant();
|
||||
}
|
||||
|
||||
#include "declarativeappletscript.moc"
|
||||
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 by Alan Alpert <alan.alpert@nokia.com>
|
||||
* Copyright 2010 by Ménard Alexis <menard@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 DECLARATIVE_APPLETSCRIPT_H
|
||||
#define DECLARATIVE_APPLETSCRIPT_H
|
||||
|
||||
#include <QScriptValue>
|
||||
#include <QScriptContext>
|
||||
|
||||
#include "abstractjsappletscript.h"
|
||||
#include "plasmoid/appletauthorization.h"
|
||||
#include <Plasma/DataEngine>
|
||||
|
||||
class AppletInterface;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class DeclarativeWidget;
|
||||
class ExtenderItem;
|
||||
}
|
||||
|
||||
class ScriptEnv;
|
||||
class EngineAccess;
|
||||
|
||||
class DeclarativeAppletScript : public AbstractJsAppletScript
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DeclarativeAppletScript(QObject *parent, const QVariantList &args);
|
||||
~DeclarativeAppletScript();
|
||||
|
||||
QString filePath(const QString &type, const QString &file) const;
|
||||
|
||||
QList<QAction*> contextualActions();
|
||||
|
||||
void constraintsEvent(Plasma::Constraints constraints);
|
||||
|
||||
bool include(const QString &path);
|
||||
|
||||
ScriptEnv *scriptEnv();
|
||||
|
||||
QScriptEngine *engine() const;
|
||||
|
||||
QScriptValue variantToScriptValue(QVariant var);
|
||||
|
||||
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue service(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue loadService(QScriptContext *context, QScriptEngine *engine);
|
||||
|
||||
public Q_SLOTS:
|
||||
void executeAction(const QString &name);
|
||||
void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
|
||||
void signalHandlerException(const QScriptValue &exception);
|
||||
void popupEvent(bool popped);
|
||||
void activate();
|
||||
void extenderItemRestored(Plasma::ExtenderItem* item);
|
||||
void collectGarbage();
|
||||
void configChanged();
|
||||
void qmlCreationFinished();
|
||||
|
||||
protected:
|
||||
bool init();
|
||||
void setupObjects();
|
||||
static QGraphicsWidget *extractParent(QScriptContext *context,
|
||||
QScriptEngine *engine,
|
||||
int parentIndex = 0,
|
||||
bool *parentedToApplet = 0);
|
||||
|
||||
Q_SIGNALS:
|
||||
void formFactorChanged();
|
||||
void locationChanged();
|
||||
void contextChanged();
|
||||
|
||||
private:
|
||||
void callPlasmoidFunction(const QString &functionName, const QScriptValueList &args, ScriptEnv *env);
|
||||
Plasma::DeclarativeWidget *m_declarativeWidget;
|
||||
Plasma::DeclarativeWidget *m_toolBoxWidget;
|
||||
AppletInterface *m_interface;
|
||||
EngineAccess *m_engineAccess;
|
||||
QScriptEngine *m_engine;
|
||||
QScriptValue m_self;
|
||||
ScriptEnv *m_env;
|
||||
AppletAuthorization m_auth;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <mart@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 USE_JS_SCRIPTENGINE
|
||||
#include "appletinterface.cpp"
|
||||
#include "appletinterface.moc"
|
||||
|
@ -1,898 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007-2008,2010 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 "simplejavascriptapplet.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QFile>
|
||||
#include <QKeyEvent>
|
||||
#include <QGraphicsLayout>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QPauseAnimation>
|
||||
#include <QSequentialAnimationGroup>
|
||||
#include <QUiLoader>
|
||||
#include <QWidget>
|
||||
#include <QScriptEngine>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KDebug>
|
||||
#include <KFileDialog>
|
||||
#include <KIcon>
|
||||
#include <KIO/Job>
|
||||
#include <KMimeType>
|
||||
#include <KShell>
|
||||
#include <KStandardDirs>
|
||||
#include <KLocale>
|
||||
#include <KRun>
|
||||
|
||||
#include <Plasma/Animation>
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Extender>
|
||||
#include <Plasma/ExtenderItem>
|
||||
#include <Plasma/FrameSvg>
|
||||
#include <Plasma/Package>
|
||||
#include <Plasma/PopupApplet>
|
||||
#include <Plasma/Svg>
|
||||
#include <Plasma/VideoWidget>
|
||||
|
||||
#define USE_JS_SCRIPTENGINE
|
||||
|
||||
#include "appletauthorization.h"
|
||||
#include "appletinterface.h"
|
||||
#include "scriptenv.h"
|
||||
#include "simplebindings/animationgroup.h"
|
||||
#include "simplebindings/bytearrayclass.h"
|
||||
#include "simplebindings/dataengine.h"
|
||||
#include "simplebindings/dataenginereceiver.h"
|
||||
#include "simplebindings/i18n.h"
|
||||
#include "themedsvg.h"
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
Q_DECLARE_METATYPE(QKeyEvent*)
|
||||
Q_DECLARE_METATYPE(QPainter*)
|
||||
Q_DECLARE_METATYPE(QStyleOptionGraphicsItem*)
|
||||
Q_DECLARE_METATYPE(QGraphicsSceneHoverEvent *)
|
||||
Q_DECLARE_METATYPE(QGraphicsSceneMouseEvent *)
|
||||
Q_DECLARE_METATYPE(QGraphicsSceneWheelEvent *)
|
||||
|
||||
QScriptValue constructColorClass(QScriptEngine *engine);
|
||||
QScriptValue constructEasingCurveClass(QScriptEngine *engine);
|
||||
QScriptValue constructFontClass(QScriptEngine *engine);
|
||||
QScriptValue constructGraphicsItemClass(QScriptEngine *engine);
|
||||
QScriptValue constructIconClass(QScriptEngine *engine);
|
||||
QScriptValue constructKUrlClass(QScriptEngine *engine);
|
||||
QScriptValue constructLinearLayoutClass(QScriptEngine *engine);
|
||||
QScriptValue constructGridLayoutClass(QScriptEngine *engine);
|
||||
QScriptValue constructAnchorLayoutClass(QScriptEngine *engine);
|
||||
QScriptValue constructPainterClass(QScriptEngine *engine);
|
||||
QScriptValue constructPenClass(QScriptEngine *engine);
|
||||
QScriptValue constructQPixmapClass(QScriptEngine *engine);
|
||||
QScriptValue constructQPointClass(QScriptEngine *engine);
|
||||
QScriptValue constructQRectFClass(QScriptEngine *engine);
|
||||
QScriptValue constructQSizeFClass(QScriptEngine *engine);
|
||||
QScriptValue constructQSizePolicyClass(QScriptEngine *engine);
|
||||
QScriptValue constructTimerClass(QScriptEngine *engine);
|
||||
void registerSimpleAppletMetaTypes(QScriptEngine *engine);
|
||||
|
||||
KSharedPtr<UiLoader> SimpleJavaScriptApplet::s_widgetLoader;
|
||||
QHash<QString, Plasma::Animator::Animation> SimpleJavaScriptApplet::s_animationDefs;
|
||||
|
||||
SimpleJavaScriptApplet::SimpleJavaScriptApplet(QObject *parent, const QVariantList &args)
|
||||
: AbstractJsAppletScript(parent),
|
||||
m_interface(0)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
// kDebug() << "Script applet launched, args" << applet()->startupArguments();
|
||||
|
||||
// TODO this will be set to the engine we get from QML
|
||||
m_engine = new QScriptEngine(this);
|
||||
m_env = new ScriptEnv(this, m_engine);
|
||||
connect(m_env, SIGNAL(reportError(ScriptEnv*,bool)), this, SLOT(reportError(ScriptEnv*,bool)));
|
||||
}
|
||||
|
||||
SimpleJavaScriptApplet::~SimpleJavaScriptApplet()
|
||||
{
|
||||
delete m_interface;
|
||||
if (s_widgetLoader.count() == 1) {
|
||||
s_widgetLoader.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::reportError(ScriptEnv *env, bool fatal)
|
||||
{
|
||||
const QScriptValue error = env->engine()->uncaughtException();
|
||||
QString file = error.property("fileName").toString();
|
||||
file.remove(package()->path());
|
||||
|
||||
const QString failureMsg = i18n("Error in %1 on line %2.<br><br>%3",
|
||||
file, error.property("lineNumber").toString(),
|
||||
error.toString());
|
||||
if (fatal) {
|
||||
setLaunchErrorMessage(true, failureMsg);
|
||||
} else {
|
||||
showMessage(KIcon("dialog-error"), failureMsg, Plasma::ButtonOk);
|
||||
}
|
||||
|
||||
kDebug() << failureMsg;
|
||||
kDebug() << env->engine()->uncaughtExceptionBacktrace();
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::configChanged()
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env || !env->callEventListeners("configchanged")) {
|
||||
callPlasmoidFunction("configChanged", QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::dataUpdated(const QString &name, const DataEngine::Data &data)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << m_engine->toScriptValue(name) << m_engine->toScriptValue(data);
|
||||
|
||||
if (!env->callEventListeners("dataUpdated", args)) {
|
||||
callPlasmoidFunction("dataUpdated", args, env);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::extenderItemRestored(Plasma::ExtenderItem* item)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << m_engine->newQObject(item, QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
|
||||
if (!env->callEventListeners("initExtenderItem", args)) {
|
||||
callPlasmoidFunction("initExtenderItem", args, env);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::activate()
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env || !env->callEventListeners("activate")) {
|
||||
callPlasmoidFunction("activate", QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::popupEvent(bool popped)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << popped;
|
||||
|
||||
if (!env->callEventListeners("popupEvent", args)) {
|
||||
callPlasmoidFunction("popupEvent", args, env);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::executeAction(const QString &name)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString func("action_" + name);
|
||||
if (!env->callEventListeners(func)) {
|
||||
callPlasmoidFunction(func, QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << m_engine->toScriptValue(p);
|
||||
args << m_engine->toScriptValue(const_cast<QStyleOptionGraphicsItem*>(option));
|
||||
args << m_engine->toScriptValue(QRectF(contentsRect));
|
||||
|
||||
if (!env->callEventListeners("paintInterface")) {
|
||||
callPlasmoidFunction("paintInterface", args, env);
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction*> SimpleJavaScriptApplet::contextualActions()
|
||||
{
|
||||
if (!m_interface) {
|
||||
return QList<QAction *>();
|
||||
}
|
||||
|
||||
return m_interface->contextualActions();
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::callPlasmoidFunction(const QString &functionName, const QScriptValueList &args, ScriptEnv *env)
|
||||
{
|
||||
if (!env) {
|
||||
env = ScriptEnv::findScriptEnv(m_engine);
|
||||
}
|
||||
|
||||
if (env) {
|
||||
QScriptValue func = m_self.property(functionName);
|
||||
env->callFunction(func, args, m_self);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::constraintsEvent(Plasma::Constraints constraints)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (constraints & Plasma::FormFactorConstraint) {
|
||||
if (!env->callEventListeners("formFactorChanged")) {
|
||||
callPlasmoidFunction("formFactorChanged", QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraints & Plasma::LocationConstraint) {
|
||||
if (!env->callEventListeners("locationChanged")) {
|
||||
callPlasmoidFunction("locationChanged", QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraints & Plasma::ContextConstraint) {
|
||||
if (!env->callEventListeners("currentActivityChanged")) {
|
||||
callPlasmoidFunction("currentActivityChanged", QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraints & Plasma::SizeConstraint) {
|
||||
if (!env || !env->callEventListeners("sizeChanged")) {
|
||||
callPlasmoidFunction("sizeChanged", QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraints & Plasma::ImmutableConstraint) {
|
||||
if (!env->callEventListeners("immutabilityChanged")) {
|
||||
callPlasmoidFunction("immutabilityChanged", QScriptValueList(), env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SimpleJavaScriptApplet::include(const QString &path)
|
||||
{
|
||||
return m_env->include(path);
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::populateAnimationsHash()
|
||||
{
|
||||
if (s_animationDefs.isEmpty()) {
|
||||
s_animationDefs.insert("fade", Plasma::Animator::FadeAnimation);
|
||||
s_animationDefs.insert("geometry", Plasma::Animator::GeometryAnimation);
|
||||
s_animationDefs.insert("grow", Plasma::Animator::GrowAnimation);
|
||||
s_animationDefs.insert("pulse", Plasma::Animator::PulseAnimation);
|
||||
s_animationDefs.insert("rotate", Plasma::Animator::RotationAnimation);
|
||||
s_animationDefs.insert("rotateStacked", Plasma::Animator::RotationStackedAnimation);
|
||||
s_animationDefs.insert("slide", Plasma::Animator::SlideAnimation);
|
||||
s_animationDefs.insert("zoom", Plasma::Animator::ZoomAnimation);
|
||||
}
|
||||
}
|
||||
|
||||
bool SimpleJavaScriptApplet::init()
|
||||
{
|
||||
connect(applet(), SIGNAL(extenderItemRestored(Plasma::ExtenderItem*)),
|
||||
this, SLOT(extenderItemRestored(Plasma::ExtenderItem*)));
|
||||
connect(applet(), SIGNAL(activate()),
|
||||
this, SLOT(activate()));
|
||||
KGlobal::locale()->insertCatalog("plasma_applet_" % description().pluginName());
|
||||
setupObjects();
|
||||
|
||||
AppletAuthorization auth(this);
|
||||
if (!m_env->importExtensions(description(), m_self, auth)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
kDebug() << "ScriptName:" << applet()->name();
|
||||
kDebug() << "ScriptCategory:" << applet()->category();
|
||||
applet()->installEventFilter(this);
|
||||
return m_env->include(mainScript());
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::createKeyEventObject(QKeyEvent *event)
|
||||
{
|
||||
QScriptValue v = m_env->engine()->newObject();
|
||||
v.setProperty("count", event->count());
|
||||
v.setProperty("key", event->key());
|
||||
v.setProperty("modifiers", static_cast<int>(event->modifiers()));
|
||||
v.setProperty("text", event->text());
|
||||
return v;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::createHoverEventObject(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
QScriptEngine *engine = m_env->engine();
|
||||
QScriptValue v = engine->newObject();
|
||||
v.setProperty("pos", engine->toScriptValue<QPoint>(event->pos().toPoint()));
|
||||
v.setProperty("scenePos", engine->toScriptValue<QPoint>(event->scenePos().toPoint()));
|
||||
v.setProperty("screenPos", engine->toScriptValue<QPoint>(event->screenPos()));
|
||||
v.setProperty("lastPos", engine->toScriptValue<QPoint>(event->lastPos().toPoint()));
|
||||
v.setProperty("lastScenePos", engine->toScriptValue<QPoint>(event->lastScenePos().toPoint()));
|
||||
v.setProperty("lastScreenPos", engine->toScriptValue<QPoint>(event->lastScreenPos()));
|
||||
v.setProperty("modifiers", static_cast<int>(event->modifiers()));
|
||||
return v;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::createMouseEventObject(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QScriptEngine *engine = m_env->engine();
|
||||
QScriptValue v = engine->newObject();
|
||||
v.setProperty("button", static_cast<int>(event->button()));
|
||||
v.setProperty("buttons", static_cast<int>(event->buttons()));
|
||||
v.setProperty("modifiers", static_cast<int>(event->modifiers()));
|
||||
v.setProperty("pos", engine->toScriptValue<QPoint>(event->pos().toPoint()));
|
||||
v.setProperty("scenePos", engine->toScriptValue<QPoint>(event->scenePos().toPoint()));
|
||||
v.setProperty("screenPos", engine->toScriptValue<QPoint>(event->screenPos()));
|
||||
v.setProperty("lastPos", engine->toScriptValue<QPoint>(event->lastPos().toPoint()));
|
||||
v.setProperty("lastScenePos", engine->toScriptValue<QPoint>(event->lastScenePos().toPoint()));
|
||||
v.setProperty("lastScreenPos", engine->toScriptValue<QPoint>(event->lastScreenPos()));
|
||||
return v;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::createWheelEventObject(QGraphicsSceneWheelEvent *event)
|
||||
{
|
||||
QScriptEngine *engine = m_env->engine();
|
||||
QScriptValue v = engine->newObject();
|
||||
v.setProperty("delta", event->delta());
|
||||
v.setProperty("buttons", static_cast<int>(event->buttons()));
|
||||
v.setProperty("modifiers", static_cast<int>(event->modifiers()));
|
||||
v.setProperty("orientation", static_cast<int>(event->orientation()));
|
||||
v.setProperty("pos", engine->toScriptValue<QPoint>(event->pos().toPoint()));
|
||||
v.setProperty("scenePos", engine->toScriptValue<QPoint>(event->scenePos().toPoint()));
|
||||
v.setProperty("screenPos", engine->toScriptValue<QPoint>(event->screenPos()));
|
||||
return v;
|
||||
}
|
||||
|
||||
bool SimpleJavaScriptApplet::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::KeyPress: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("keypress")) {
|
||||
QScriptValueList args;
|
||||
args << createKeyEventObject(static_cast<QKeyEvent *>(event));
|
||||
env->callEventListeners("keypress", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
case QEvent::KeyRelease: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("keyrelease")) {
|
||||
QScriptValueList args;
|
||||
args << createKeyEventObject(static_cast<QKeyEvent *>(event));
|
||||
env->callEventListeners("keyrelease", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneHoverEnter: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("hoverenter")) {
|
||||
QScriptValueList args;
|
||||
args << createHoverEventObject(static_cast<QGraphicsSceneHoverEvent *>(event));
|
||||
env->callEventListeners("hoverenter", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneHoverLeave: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("hoverleave")) {
|
||||
QScriptValueList args;
|
||||
args << createHoverEventObject(static_cast<QGraphicsSceneHoverEvent *>(event));
|
||||
env->callEventListeners("hoverleave", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneHoverMove: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("hovermove")) {
|
||||
QScriptValueList args;
|
||||
args << createHoverEventObject(static_cast<QGraphicsSceneHoverEvent *>(event));
|
||||
env->callEventListeners("hovermove", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneMousePress: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("mousepress")) {
|
||||
QScriptValueList args;
|
||||
args << createMouseEventObject(static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
env->callEventListeners("mousepress", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneMouseRelease: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("mouserelease")) {
|
||||
QScriptValueList args;
|
||||
args << createMouseEventObject(static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
env->callEventListeners("mouserelease", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneMouseMove: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("mousemove")) {
|
||||
QScriptValueList args;
|
||||
args << createMouseEventObject(static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
env->callEventListeners("mousemove", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneMouseDoubleClick: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("mousedoubleclick")) {
|
||||
QScriptValueList args;
|
||||
args << createMouseEventObject(static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
env->callEventListeners("mousedoubleclick", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneWheel: {
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env && env->hasEventListeners("wheel")) {
|
||||
QScriptValueList args;
|
||||
args << createWheelEventObject(static_cast<QGraphicsSceneWheelEvent *>(event));
|
||||
env->callEventListeners("wheel", args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Plasma::AppletScript::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::setupObjects()
|
||||
{
|
||||
QScriptValue global = m_engine->globalObject();
|
||||
|
||||
// Bindings for animations
|
||||
global.setProperty("animation", m_engine->newFunction(SimpleJavaScriptApplet::animation));
|
||||
global.setProperty("AnimationGroup", m_engine->newFunction(SimpleJavaScriptApplet::animationGroup));
|
||||
global.setProperty("ParallelAnimationGroup", m_engine->newFunction(SimpleJavaScriptApplet::parallelAnimationGroup));
|
||||
|
||||
QScriptValue v = m_engine->newVariant(QVariant::fromValue(*applet()->package()));
|
||||
global.setProperty("__plasma_package", v,
|
||||
QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
|
||||
|
||||
// Bindings for data engine
|
||||
|
||||
bindI18N(m_engine);
|
||||
global.setProperty("dataEngine", m_engine->newFunction(SimpleJavaScriptApplet::dataEngine));
|
||||
global.setProperty("service", m_engine->newFunction(SimpleJavaScriptApplet::service));
|
||||
global.setProperty("loadService", m_engine->newFunction(SimpleJavaScriptApplet::loadService));
|
||||
|
||||
// Expose applet interface
|
||||
const bool isPopupApplet = qobject_cast<Plasma::PopupApplet *>(applet());
|
||||
m_interface = isPopupApplet ? new PopupAppletInterface(this) : new JsAppletInterface(this);
|
||||
m_self = m_engine->newQObject(m_interface, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater);
|
||||
m_env->addMainObjectProperties(m_self);
|
||||
m_self.setScope(global);
|
||||
global.setProperty("plasmoid", m_self);
|
||||
|
||||
if (isPopupApplet) {
|
||||
connect(applet(), SIGNAL(popupEvent(bool)), this, SLOT(popupEvent(bool)));
|
||||
}
|
||||
|
||||
QScriptValue args = m_engine->newArray();
|
||||
int i = 0;
|
||||
foreach (const QVariant &arg, applet()->startupArguments()) {
|
||||
args.setProperty(i, m_engine->newVariant(arg));
|
||||
++i;
|
||||
}
|
||||
global.setProperty("startupArguments", args);
|
||||
|
||||
ScriptEnv::registerEnums(global, AppletInterface::staticMetaObject);
|
||||
|
||||
// Add a global loadui method for ui files
|
||||
QScriptValue fun = m_engine->newFunction(SimpleJavaScriptApplet::loadui);
|
||||
global.setProperty("loadui", fun);
|
||||
|
||||
// Work around bug in 4.3.0
|
||||
qMetaTypeId<QVariant>();
|
||||
|
||||
// Add stuff from Qt
|
||||
global.setProperty("QPainter", constructPainterClass(m_engine));
|
||||
global.setProperty("QGraphicsItem", constructGraphicsItemClass(m_engine));
|
||||
global.setProperty("QIcon", constructIconClass(m_engine));
|
||||
global.setProperty("QTimer", constructTimerClass(m_engine));
|
||||
global.setProperty("QFont", constructFontClass(m_engine));
|
||||
global.setProperty("QColor", constructColorClass(m_engine));
|
||||
global.setProperty("QEasingCurve", constructEasingCurveClass(m_engine));
|
||||
global.setProperty("QRectF", constructQRectFClass(m_engine));
|
||||
global.setProperty("QPen", constructPenClass(m_engine));
|
||||
global.setProperty("QPixmap", constructQPixmapClass(m_engine));
|
||||
global.setProperty("QSizeF", constructQSizeFClass(m_engine));
|
||||
global.setProperty("QSizePolicy", constructQSizePolicyClass(m_engine));
|
||||
global.setProperty("QPoint", constructQPointClass(m_engine));
|
||||
global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine));
|
||||
global.setProperty("GridLayout", constructGridLayoutClass(m_engine));
|
||||
global.setProperty("AnchorLayout", constructAnchorLayoutClass(m_engine));
|
||||
ByteArrayClass *baClass = new ByteArrayClass(m_engine);
|
||||
global.setProperty("ByteArray", baClass->constructor());
|
||||
|
||||
// Add stuff from KDE libs
|
||||
qScriptRegisterSequenceMetaType<KUrl::List>(m_engine);
|
||||
global.setProperty("Url", constructKUrlClass(m_engine));
|
||||
|
||||
// Add stuff from Plasma
|
||||
global.setProperty("PlasmaSvg", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaSvg));
|
||||
global.setProperty("PlasmaFrameSvg", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaFrameSvg));
|
||||
global.setProperty("Svg", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaSvg));
|
||||
global.setProperty("FrameSvg", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaFrameSvg));
|
||||
global.setProperty("ExtenderItem", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaExtenderItem));
|
||||
|
||||
registerSimpleAppletMetaTypes(m_engine);
|
||||
installWidgets(m_engine);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::dataEngine(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("dataEngine() takes one argument"));
|
||||
}
|
||||
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return context->throwError(i18n("Could not extract the Applet"));
|
||||
}
|
||||
|
||||
const QString dataEngineName = context->argument(0).toString();
|
||||
DataEngine *dataEngine = interface->dataEngine(dataEngineName);
|
||||
QScriptValue v = engine->newQObject(dataEngine, QScriptEngine::QtOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
v.setProperty("connectSource", engine->newFunction(DataEngineReceiver::connectSource));
|
||||
v.setProperty("connectAllSources", engine->newFunction(DataEngineReceiver::connectAllSources));
|
||||
v.setProperty("disconnectSource", engine->newFunction(DataEngineReceiver::disconnectSource));
|
||||
return v;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::service(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 2) {
|
||||
return context->throwError(i18n("service() takes two arguments"));
|
||||
}
|
||||
|
||||
QString dataEngine = context->argument(0).toString();
|
||||
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return context->throwError(i18n("Could not extract the Applet"));
|
||||
}
|
||||
|
||||
DataEngine *data = interface->dataEngine(dataEngine);
|
||||
QString source = context->argument(1).toString();
|
||||
Service *service = data->serviceForSource(source);
|
||||
//kDebug( )<< "lets try to get" << source << "from" << dataEngine;
|
||||
return engine->newQObject(service, QScriptEngine::AutoOwnership);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::loadService(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("service() takes one argument"));
|
||||
}
|
||||
|
||||
QString pluginName = context->argument(0).toString();
|
||||
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return context->throwError(i18n("Could not extract the Applet"));
|
||||
}
|
||||
|
||||
Plasma::Service *service = Plasma::Service::load(pluginName, interface);
|
||||
|
||||
//kDebug( )<< "lets try to get" << source << "from" << dataEngine;
|
||||
return engine->newQObject(service, QScriptEngine::AutoOwnership);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::animation(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("animation() takes one argument"));
|
||||
}
|
||||
|
||||
populateAnimationsHash();
|
||||
QString name = context->argument(0).toString();
|
||||
QString animName = name.toLower();
|
||||
const bool isPause = animName == "pause";
|
||||
const bool isProperty = animName == "property";
|
||||
|
||||
bool parentIsApplet = false;
|
||||
QGraphicsWidget *parent = extractParent(context, engine, 0, &parentIsApplet);
|
||||
QAbstractAnimation *anim = 0;
|
||||
Plasma::Animation *plasmaAnim = 0;
|
||||
if (isPause) {
|
||||
anim = new QPauseAnimation(parent);
|
||||
} else if (isProperty) {
|
||||
anim = new QPropertyAnimation(parent);
|
||||
} else if (s_animationDefs.contains(animName)) {
|
||||
plasmaAnim = Plasma::Animator::create(s_animationDefs.value(animName), parent);
|
||||
} else {
|
||||
SimpleJavaScriptApplet *jsApplet = qobject_cast<SimpleJavaScriptApplet *>(engine->parent());
|
||||
if (jsApplet) {
|
||||
//kDebug() << "trying to load it from the package";
|
||||
plasmaAnim = jsApplet->loadAnimationFromPackage(name, parent);
|
||||
}
|
||||
|
||||
if (!plasmaAnim) {
|
||||
plasmaAnim = Plasma::Animator::create(animName, parent);
|
||||
}
|
||||
}
|
||||
|
||||
if (plasmaAnim) {
|
||||
if (!parentIsApplet) {
|
||||
plasmaAnim->setTargetWidget(parent);
|
||||
}
|
||||
anim = plasmaAnim;
|
||||
}
|
||||
|
||||
if (anim) {
|
||||
QScriptValue value = engine->newQObject(anim);
|
||||
ScriptEnv::registerEnums(value, *anim->metaObject());
|
||||
return value;
|
||||
}
|
||||
|
||||
context->throwError(i18n("%1 is not a known animation type", animName));
|
||||
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(engine);
|
||||
if (env) {
|
||||
env->checkForErrors(false);
|
||||
}
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::animationGroup(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
QGraphicsWidget *parent = extractParent(context, engine);
|
||||
SequentialAnimationGroup *group = new SequentialAnimationGroup(parent);
|
||||
return engine->newQObject(group);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::parallelAnimationGroup(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
QGraphicsWidget *parent = extractParent(context, engine);
|
||||
ParallelAnimationGroup *group = new ParallelAnimationGroup(parent);
|
||||
return engine->newQObject(group);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::loadui(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("loadui() takes one argument"));
|
||||
}
|
||||
|
||||
QString filename = context->argument(0).toString();
|
||||
QFile f(filename);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
return context->throwError(i18n("Unable to open '%1'",filename));
|
||||
}
|
||||
|
||||
QUiLoader loader;
|
||||
QWidget *w = loader.load(&f);
|
||||
f.close();
|
||||
|
||||
return engine->newQObject(w, QScriptEngine::AutoOwnership);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::newPlasmaSvg(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("Constructor takes at least 1 argument"));
|
||||
}
|
||||
|
||||
const QString filename = context->argument(0).toString();
|
||||
bool parentedToApplet = false;
|
||||
QGraphicsWidget *parent = extractParent(context, engine, 1, &parentedToApplet);
|
||||
Svg *svg = new ThemedSvg(parent);
|
||||
svg->setImagePath(ThemedSvg::findSvg(engine, filename));
|
||||
|
||||
QScriptValue obj = engine->newQObject(svg);
|
||||
ScriptEnv::registerEnums(obj, *svg->metaObject());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("Constructor takes at least 1 argument"));
|
||||
}
|
||||
|
||||
QString filename = context->argument(0).toString();
|
||||
|
||||
bool parentedToApplet = false;
|
||||
QGraphicsWidget *parent = extractParent(context, engine, 1, &parentedToApplet);
|
||||
FrameSvg *frameSvg = new ThemedFrameSvg(parent);
|
||||
frameSvg->setImagePath(ThemedSvg::findSvg(engine, filename));
|
||||
|
||||
QScriptValue obj = engine->newQObject(frameSvg);
|
||||
ScriptEnv::registerEnums(obj, *frameSvg->metaObject());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Plasma::Extender *extender = 0;
|
||||
if (context->argumentCount() > 0) {
|
||||
extender = qobject_cast<Plasma::Extender *>(context->argument(0).toQObject());
|
||||
}
|
||||
|
||||
if (!extender) {
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
engine->undefinedValue();
|
||||
}
|
||||
|
||||
extender = interface->extender();
|
||||
}
|
||||
|
||||
Plasma::ExtenderItem *extenderItem = new Plasma::ExtenderItem(extender);
|
||||
QScriptValue fun = engine->newQObject(extenderItem);
|
||||
ScriptEnv::registerEnums(fun, *extenderItem->metaObject());
|
||||
return fun;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::widgetAdjustSize(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(context->thisObject().toQObject());
|
||||
if (widget) {
|
||||
widget->adjustSize();
|
||||
}
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::installWidgets(QScriptEngine *engine)
|
||||
{
|
||||
QScriptValue globalObject = engine->globalObject();
|
||||
if (!s_widgetLoader) {
|
||||
s_widgetLoader = new UiLoader;
|
||||
}
|
||||
|
||||
foreach (const QString &widget, s_widgetLoader->availableWidgets()) {
|
||||
QScriptValue fun = engine->newFunction(createWidget);
|
||||
QScriptValue name = engine->toScriptValue(widget);
|
||||
fun.setProperty(QString("functionName"), name,
|
||||
QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
|
||||
fun.setProperty(QString("prototype"), engine->newObject());
|
||||
globalObject.setProperty(widget, fun);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptEngine *SimpleJavaScriptApplet::engine() const
|
||||
{
|
||||
return m_engine;
|
||||
}
|
||||
|
||||
QGraphicsWidget *SimpleJavaScriptApplet::extractParent(QScriptContext *context, QScriptEngine *engine,
|
||||
int argIndex, bool *parentedToApplet)
|
||||
{
|
||||
if (parentedToApplet) {
|
||||
*parentedToApplet = false;
|
||||
}
|
||||
|
||||
QGraphicsWidget *parent = 0;
|
||||
if (context->argumentCount() >= argIndex) {
|
||||
parent = qobject_cast<QGraphicsWidget*>(context->argument(argIndex).toQObject());
|
||||
}
|
||||
|
||||
if (!parent) {
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//kDebug() << "got the applet!";
|
||||
parent = interface->applet();
|
||||
|
||||
if (parentedToApplet) {
|
||||
*parentedToApplet = true;
|
||||
}
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::createWidget(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
QGraphicsWidget *parent = extractParent(context, engine);
|
||||
QString self = context->callee().property("functionName").toString();
|
||||
if (!s_widgetLoader) {
|
||||
s_widgetLoader = new UiLoader;
|
||||
}
|
||||
|
||||
QGraphicsWidget *w = s_widgetLoader->createWidget(self, parent);
|
||||
|
||||
if (!w) {
|
||||
return QScriptValue();
|
||||
}
|
||||
|
||||
QScriptValue fun = engine->newQObject(w);
|
||||
fun.setPrototype(context->callee().property("prototype"));
|
||||
fun.setProperty("adjustSize", engine->newFunction(widgetAdjustSize));
|
||||
|
||||
//register enums will be accessed for instance as frame.Sunken for Frame shadow...
|
||||
ScriptEnv::registerEnums(fun, *w->metaObject());
|
||||
return fun;
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::collectGarbage()
|
||||
{
|
||||
m_engine->collectGarbage();
|
||||
}
|
||||
|
||||
QString SimpleJavaScriptApplet::filePath(const QString &type, const QString &file) const
|
||||
{
|
||||
const QString path = m_env->filePathFromScriptContext(type.toLocal8Bit().constData(), file);
|
||||
if (!path.isEmpty()) {
|
||||
return path;
|
||||
}
|
||||
|
||||
return package()->filePath(type.toLocal8Bit().constData(), file);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::variantToScriptValue(QVariant var)
|
||||
{
|
||||
return m_engine->newVariant(var);
|
||||
}
|
||||
|
||||
K_EXPORT_PLASMA_APPLETSCRIPTENGINE(qscriptapplet, SimpleJavaScriptApplet)
|
||||
|
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, 2010 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 SCRIPT_H
|
||||
#define SCRIPT_H
|
||||
|
||||
#include <QScriptValue>
|
||||
|
||||
#include <Plasma/Animator>
|
||||
#include <Plasma/DataEngine>
|
||||
|
||||
#include "simplebindings/uiloader.h"
|
||||
#include "abstractjsappletscript.h"
|
||||
|
||||
class QScriptContext;
|
||||
class QScriptEngine;
|
||||
|
||||
class AppletInterface;
|
||||
class ScriptEnv;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class ExtenderItem;
|
||||
} // namespace Plasma
|
||||
|
||||
class SimpleJavaScriptApplet : public AbstractJsAppletScript
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SimpleJavaScriptApplet(QObject *parent, const QVariantList &args);
|
||||
~SimpleJavaScriptApplet();
|
||||
bool init();
|
||||
|
||||
|
||||
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect);
|
||||
QList<QAction*> contextualActions();
|
||||
void constraintsEvent(Plasma::Constraints constraints);
|
||||
bool include(const QString &path);
|
||||
QSet<QString> loadedExtensions() const;
|
||||
QScriptValue variantToScriptValue(QVariant var);
|
||||
QString filePath(const QString &type, const QString &file) const;
|
||||
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
QScriptEngine *engine() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
|
||||
void configChanged();
|
||||
void executeAction(const QString &name);
|
||||
void collectGarbage();
|
||||
void extenderItemRestored(Plasma::ExtenderItem* item);
|
||||
void popupEvent(bool popped);
|
||||
void activate();
|
||||
|
||||
private Q_SLOTS:
|
||||
void reportError(ScriptEnv *error, bool fatal);
|
||||
|
||||
private:
|
||||
void setupObjects();
|
||||
void callPlasmoidFunction(const QString &functionName, const QScriptValueList &args = QScriptValueList(), ScriptEnv *env = 0);
|
||||
QScriptValue createKeyEventObject(QKeyEvent *event);
|
||||
QScriptValue createHoverEventObject(QGraphicsSceneHoverEvent *event);
|
||||
QScriptValue createMouseEventObject(QGraphicsSceneMouseEvent *event);
|
||||
QScriptValue createWheelEventObject(QGraphicsSceneWheelEvent *event);
|
||||
static void populateAnimationsHash();
|
||||
|
||||
static QString findSvg(QScriptContext *context, QScriptEngine *engine, const QString &file);
|
||||
static QScriptValue animation(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue animationGroup(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue parallelAnimationGroup(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue jsi18n(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue jsi18nc(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue jsi18np(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue jsi18ncp(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue service(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue loadService(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine);
|
||||
|
||||
void installWidgets(QScriptEngine *engine);
|
||||
static QScriptValue createWidget(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue widgetAdjustSize(QScriptContext *context, QScriptEngine *engine);
|
||||
|
||||
static QGraphicsWidget *extractParent(QScriptContext *context,
|
||||
QScriptEngine *engine,
|
||||
int parentIndex = 0,
|
||||
bool *parentedToApplet = 0);
|
||||
|
||||
private:
|
||||
static KSharedPtr<UiLoader> s_widgetLoader;
|
||||
static QHash<QString, Plasma::Animator::Animation> s_animationDefs;
|
||||
ScriptEnv *m_env;
|
||||
QScriptEngine *m_engine;
|
||||
QScriptValue m_self;
|
||||
QVariantList m_args;
|
||||
AppletInterface *m_interface;
|
||||
friend class AppletInterface;
|
||||
};
|
||||
|
||||
#endif // SCRIPT_H
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007-2008,2010 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 "themedsvg.h"
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "appletinterface.h"
|
||||
|
||||
ThemedSvg::ThemedSvg(QObject *parent)
|
||||
: Plasma::Svg(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ThemedSvg::setThemedImagePath(const QString &path)
|
||||
{
|
||||
setImagePath(findSvg(engine(), path));
|
||||
}
|
||||
|
||||
QString ThemedSvg::findSvg(QScriptEngine *engine, const QString &file)
|
||||
{
|
||||
AppletInterface *interface = AppletInterface::extract(engine);
|
||||
if (!interface) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString path = interface->file("images", file + ".svg");
|
||||
if (path.isEmpty()) {
|
||||
path = interface->file("images", file + ".svgz");
|
||||
|
||||
if (path.isEmpty()) {
|
||||
path = Plasma::Theme::defaultTheme()->imagePath(file);
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
ThemedFrameSvg::ThemedFrameSvg(QObject *parent)
|
||||
: Plasma::FrameSvg(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ThemedFrameSvg::setThemedImagePath(const QString &path)
|
||||
{
|
||||
setImagePath(ThemedSvg::findSvg(engine(), path));
|
||||
}
|
||||
|
||||
#include "themedsvg.moc"
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007-2008,2010 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 THEMEDSVG_H
|
||||
#define THEMEDSVG_H
|
||||
|
||||
#include <QScriptable>
|
||||
|
||||
#include <Plasma/Svg>
|
||||
#include <Plasma/FrameSvg>
|
||||
|
||||
class ThemedSvg : public Plasma::Svg, public QScriptable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString imagePath READ imagePath WRITE setThemedImagePath)
|
||||
|
||||
public:
|
||||
ThemedSvg(QObject *parent = 0);
|
||||
|
||||
void setThemedImagePath(const QString &path);
|
||||
|
||||
static QString findSvg(QScriptEngine *engine, const QString &file);
|
||||
};
|
||||
|
||||
class ThemedFrameSvg : public Plasma::FrameSvg, public QScriptable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString imagePath READ imagePath WRITE setThemedImagePath)
|
||||
|
||||
public:
|
||||
ThemedFrameSvg(QObject *parent = 0);
|
||||
|
||||
void setThemedImagePath(const QString &path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user