2008-04-13 22:31:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "scripter.h"
|
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QDebug>
|
2018-02-21 22:56:51 +00:00
|
|
|
#include <QFile>
|
2008-04-13 22:31:59 +00:00
|
|
|
|
|
|
|
#include "debug_p.h"
|
Start implementing the JavaScript scripting API for PDF documents,
thanks to Harri and Maksim and the brand-new public KJS API.
This starts the implementation of some of the API objects needed,
like App, Console, Data, Document, Field, FullScreen, Spell, Util.
Also, workaround the fact that we cannot change the read-only status for form fields.
svn path=/trunk/KDE/kdegraphics/okular/; revision=809259
2008-05-18 16:37:07 +00:00
|
|
|
#include "script/executor_kjs_p.h"
|
2008-04-13 22:31:59 +00:00
|
|
|
|
|
|
|
using namespace Okular;
|
|
|
|
|
|
|
|
class Okular::ScripterPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScripterPrivate(DocumentPrivate *doc)
|
2018-04-16 20:35:40 +00:00
|
|
|
: m_doc(doc)
|
2020-09-09 12:13:09 +00:00
|
|
|
#ifdef WITH_KJS
|
2018-04-16 20:35:40 +00:00
|
|
|
, m_kjs(nullptr)
|
2020-09-09 12:13:09 +00:00
|
|
|
#endif
|
2018-04-16 20:35:40 +00:00
|
|
|
, m_event(nullptr)
|
2008-04-13 22:31:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentPrivate *m_doc;
|
2020-09-09 12:13:09 +00:00
|
|
|
#ifdef WITH_KJS
|
2018-04-16 20:35:40 +00:00
|
|
|
QScopedPointer<ExecutorKJS> m_kjs;
|
2020-09-09 12:13:09 +00:00
|
|
|
#endif
|
2018-02-21 22:54:16 +00:00
|
|
|
Event *m_event;
|
2008-04-13 22:31:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Scripter::Scripter(DocumentPrivate *doc)
|
|
|
|
: d(new ScripterPrivate(doc))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Scripter::~Scripter()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2019-06-28 12:39:02 +00:00
|
|
|
void Scripter::execute(ScriptType type, const QString &script)
|
2008-04-13 22:31:59 +00:00
|
|
|
{
|
2014-09-11 17:36:01 +00:00
|
|
|
qCDebug(OkularCoreDebug) << "executing the script:";
|
2020-09-09 12:13:09 +00:00
|
|
|
#ifdef WITH_KJS
|
2008-04-13 22:31:59 +00:00
|
|
|
#if 0
|
|
|
|
if ( script.length() < 1000 )
|
|
|
|
qDebug() << script;
|
|
|
|
else
|
|
|
|
qDebug() << script.left( 1000 ) << "[...]";
|
|
|
|
#endif
|
2018-02-21 22:56:51 +00:00
|
|
|
static QString builtInScript;
|
|
|
|
if (builtInScript.isNull()) {
|
2019-04-25 21:10:48 +00:00
|
|
|
QFile builtInResource(QStringLiteral(":/script/builtin.js"));
|
2018-02-21 22:56:51 +00:00
|
|
|
if (!builtInResource.open(QIODevice::ReadOnly)) {
|
|
|
|
qCDebug(OkularCoreDebug) << "failed to load builtin script";
|
|
|
|
} else {
|
|
|
|
builtInScript = QString::fromUtf8(builtInResource.readAll());
|
|
|
|
builtInResource.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-13 22:31:59 +00:00
|
|
|
switch (type) {
|
|
|
|
case JavaScript:
|
Start implementing the JavaScript scripting API for PDF documents,
thanks to Harri and Maksim and the brand-new public KJS API.
This starts the implementation of some of the API objects needed,
like App, Console, Data, Document, Field, FullScreen, Spell, Util.
Also, workaround the fact that we cannot change the read-only status for form fields.
svn path=/trunk/KDE/kdegraphics/okular/; revision=809259
2008-05-18 16:37:07 +00:00
|
|
|
if (!d->m_kjs) {
|
2018-04-16 20:35:40 +00:00
|
|
|
d->m_kjs.reset(new ExecutorKJS(d->m_doc));
|
2019-06-28 12:39:02 +00:00
|
|
|
}
|
2018-02-21 22:56:51 +00:00
|
|
|
d->m_kjs->execute(builtInScript + script, d->m_event);
|
2020-07-10 22:15:05 +00:00
|
|
|
}
|
2020-09-09 12:13:09 +00:00
|
|
|
#endif
|
2008-04-13 22:31:59 +00:00
|
|
|
}
|
2018-02-21 22:54:16 +00:00
|
|
|
|
|
|
|
void Scripter::setEvent(Event *event)
|
|
|
|
{
|
|
|
|
d->m_event = event;
|
|
|
|
}
|
|
|
|
|
|
|
|
Event *Scripter::event() const
|
|
|
|
{
|
|
|
|
return d->m_event;
|
|
|
|
}
|