10#include <QApplication>
15#include <KLocalizedString>
21#include "../document_p.h"
22#include "../scripter.h"
23#include "config-okular.h"
24#include "js_fullscreen_p.h"
28#define OKULAR_TIMERID QStringLiteral("okular_timerID")
34static const double fake_acroversion = 8.00;
37static const char *kResultProperty =
"result";
39static const struct FakePluginInfo {
44} s_fake_plugins[] = {{
"Annots",
true,
true,
""}, {
"EFS",
true,
true,
""}, {
"EScript",
true,
true,
""}, {
"Forms",
true,
true,
""}, {
"ReadOutLoud",
true,
true,
""}, {
"WebLink",
true,
true,
""}};
45static const int s_num_fake_plugins =
sizeof(s_fake_plugins) /
sizeof(s_fake_plugins[0]);
47int JSApp::formsVersion()
const
50 return fake_acroversion;
58 QString acroLang = QStringLiteral(
"ENU");
60 acroLang = QStringLiteral(
"DAN");
62 acroLang = QStringLiteral(
"DEU");
64 acroLang = QStringLiteral(
"ENU");
66 acroLang = QStringLiteral(
"ESP");
68 acroLang = QStringLiteral(
"FRA");
70 acroLang = QStringLiteral(
"ITA");
72 acroLang = QStringLiteral(
"KOR");
74 acroLang = QStringLiteral(
"JPN");
76 acroLang = QStringLiteral(
"NLD");
78 acroLang = QStringLiteral(
"PTB");
80 acroLang = QStringLiteral(
"SUO");
82 acroLang = QStringLiteral(
"SVE");
84 acroLang = QStringLiteral(
"CHS");
86 acroLang = QStringLiteral(
"CHT");
91int JSApp::numPlugIns()
const
93 return s_num_fake_plugins;
100#elif defined(Q_OS_MAC)
103 return QStringLiteral(
"UNIX");
109 QJSValue plugins = qjsEngine(
this)->newArray(s_num_fake_plugins);
110 for (
int i = 0; i < s_num_fake_plugins; ++i) {
111 const FakePluginInfo &info = s_fake_plugins[i];
112 QJSValue plugin = qjsEngine(
this)->newObject();
113 plugin.
setProperty(QStringLiteral(
"certified"), info.certified);
114 plugin.
setProperty(QStringLiteral(
"loaded"), info.loaded);
115 plugin.
setProperty(QStringLiteral(
"name"), info.name);
116 plugin.
setProperty(QStringLiteral(
"path"), info.path);
117 plugin.
setProperty(QStringLiteral(
"version"), fake_acroversion);
133QString JSApp::viewerType()
const
136 return QStringLiteral(
"Reader");
139QString JSApp::viewerVariation()
const
142 return QStringLiteral(
"Reader");
145int JSApp::viewerVersion()
const
148 return fake_acroversion;
155int JSApp::alert(
const QJSValue &arguments)
158 const auto nIcon = arguments.
property(QStringLiteral(
"nIcon")).
toInt();
159 const auto nType = arguments.
property(QStringLiteral(
"nType")).
toInt();
160 const auto cTitle = arguments.
property(QStringLiteral(
"cTitle")).
toString();
161 const auto oCheckbox = arguments.
property(QStringLiteral(
"oCheckbox"));
162 return alert(cMsg, nIcon, nType, cTitle,
QJSValue(), oCheckbox);
165int JSApp::alert(
const QString &cMsg,
int nIcon,
int nType,
const QString &cTitle, [[maybe_unused]]
const QJSValue &oDoc,
const QJSValue &oCheckbox)
183 const QString title = !cTitle.
isEmpty() ? cTitle : QStringLiteral(
"Okular");
201 box.setStandardButtons(buttons);
205 const auto oMsg = oCheckbox.
property(QStringLiteral(
"cMsg"));
206 QString msg =
i18n(
"Do not show this message again");
208 if (oMsg.isString()) {
209 msg = oMsg.toString();
212 bool bInitialValue =
false;
213 const auto value = oCheckbox.
property(QStringLiteral(
"bInitialValue"));
214 if (value.isBool()) {
215 bInitialValue = value.toBool();
219 box.setCheckBox(checkBox);
225 int button = box.exec();
256void JSApp::beep([[maybe_unused]]
int nType)
261QJSValue JSApp::getNthPlugInName(
int nIndex)
const
263 if (nIndex < 0 || nIndex >= s_num_fake_plugins) {
264 return qjsEngine(
this)->newErrorObject(
QJSValue::TypeError, QStringLiteral(
"PlugIn index out of bounds"));
267 const FakePluginInfo &info = s_fake_plugins[nIndex];
273 if (!m_doc->m_parent->historyAtBegin()) {
274 m_doc->m_parent->setPrevViewport();
278void JSApp::goForward()
280 if (!m_doc->m_parent->historyAtEnd()) {
281 m_doc->m_parent->setNextViewport();
292 timer->
start(nMilliseconds);
294 return JSApp::wrapTimer(timer);
298void JSApp::clearInterval(
const QJSValue &oInterval)
300 const int timerId = oInterval.
property(OKULAR_TIMERID).
toInt();
301 QTimer *timer = g_timerCache->value(timerId);
302 if (timer !=
nullptr) {
304 g_timerCache->remove(timerId);
317 timer->
start(nMilliseconds);
319 return JSApp::wrapTimer(timer);
323void JSApp::clearTimeOut(
const QJSValue &oTime)
326 QTimer *timer = g_timerCache->value(timerId);
328 if (timer !=
nullptr) {
330 g_timerCache->remove(timerId);
337bool JSApp::createPopUpMenuTree(
int depth,
QMenu *rootMenu,
const QJSValue &arguments)
339 const int nArgs = arguments.
property(QStringLiteral(
"length")).
toInt();
342 if (nArgs == 0 || depth > 20) {
346 for (
int i = 0; i < nArgs; ++i) {
354 createPopUpMenuTree(depth + 1, subMenu, oSubMenu);
375 if (!createPopUpMenuTree(0, &m, arguments)) {
383JSApp::JSApp(DocumentPrivate *doc,
QTimer *watchdogTimer,
QObject *parent)
386 , m_watchdogTimer(watchdogTimer)
390JSApp::~JSApp() =
default;
394 QJSValue timerObject = qjsEngine(
this)->newObject();
397 g_timerCache->insert(timer->
timerId(), timer);
402void JSApp::clearCachedFields()
405 qDeleteAll(g_timerCache->begin(), g_timerCache->end());
406 g_timerCache->clear();
QString i18n(const char *text, const TYPE &arg...)
QStringView country(QStringView ifopt)
bool isArray() const const
bool isObject() const const
bool isUndefined() const const
QJSValue property(const QString &name) const const
void setProperty(const QString &name, const QJSValue &value)
qint32 toInt() const const
QString toString() const const
Language language() const const
QString languageToString(Language language)
Territory territory() const const
QString territoryToString(Territory territory)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QVariant property(const char *name) const const
void setObjectName(QAnyStringView name)
bool setProperty(const char *name, QVariant &&value)
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
void setSingleShot(bool singleShot)
int timerId() const const
QString toString() const const