10 #include <kjs/kjsarguments.h>
11 #include <kjs/kjsinterpreter.h>
12 #include <kjs/kjsobject.h>
13 #include <kjs/kjsprototype.h>
14 #include <kjs_version.h>
16 #include <QApplication>
21 #include <KLocalizedString>
23 #include <QMessageBox>
25 #include "../document_p.h"
26 #include "../scripter.h"
27 #include "config-okular.h"
28 #include "kjs_fullscreen_p.h"
32 #define OKULAR_TIMERID QStringLiteral("okular_timerID")
39 static const double fake_acroversion = 8.00;
41 static const struct FakePluginInfo {
46 } s_fake_plugins[] = {{
"Annots",
true,
true,
""}, {
"EFS",
true,
true,
""}, {
"EScript",
true,
true,
""}, {
"Forms",
true,
true,
""}, {
"ReadOutLoud",
true,
true,
""}, {
"WebLink",
true,
true,
""}};
47 static const int s_num_fake_plugins =
sizeof(s_fake_plugins) /
sizeof(s_fake_plugins[0]);
60 QString acroLang = QStringLiteral(
"ENU");
62 acroLang = QStringLiteral(
"DAN");
64 acroLang = QStringLiteral(
"DEU");
66 acroLang = QStringLiteral(
"ENU");
68 acroLang = QStringLiteral(
"ESP");
70 acroLang = QStringLiteral(
"FRA");
72 acroLang = QStringLiteral(
"ITA");
74 acroLang = QStringLiteral(
"KOR");
76 acroLang = QStringLiteral(
"JPN");
78 acroLang = QStringLiteral(
"NLD");
80 acroLang = QStringLiteral(
"PTB");
82 acroLang = QStringLiteral(
"SUO");
84 acroLang = QStringLiteral(
"SVE");
86 acroLang = QStringLiteral(
"CHS");
88 acroLang = QStringLiteral(
"CHT");
100 #if defined(Q_OS_WIN)
102 #elif defined(Q_OS_MAC)
105 return KJSString(QStringLiteral(
"UNIX"));
111 KJSArray plugins(context, s_num_fake_plugins);
112 for (
int i = 0; i < s_num_fake_plugins; ++i) {
113 const FakePluginInfo &info = s_fake_plugins[i];
115 plugin.
setProperty(context, QStringLiteral(
"certified"), info.certified);
116 plugin.
setProperty(context, QStringLiteral(
"loaded"), info.loaded);
117 plugin.
setProperty(context, QStringLiteral(
"name"), info.name);
118 plugin.
setProperty(context, QStringLiteral(
"path"), info.path);
119 plugin.
setProperty(context, QStringLiteral(
"version"), fake_acroversion);
138 return KJSString(QStringLiteral(
"Reader"));
144 return KJSString(QStringLiteral(
"Reader"));
159 if (arguments.
count() < 1) {
162 KJSObject cMsg, nIcon, nType, cTitle, oCheckbox;
166 cMsg = obj.
property(context, QStringLiteral(
"cMsg"));
167 nIcon = obj.
property(context, QStringLiteral(
"nIcon"));
168 nType = obj.
property(context, QStringLiteral(
"nType"));
169 cTitle = obj.
property(context, QStringLiteral(
"cTitle"));
170 oCheckbox = obj.
property(context, QStringLiteral(
"oCheckbox"));
172 cMsg = arguments.
at(0);
173 nIcon = arguments.
at(1);
174 nType = arguments.
at(2);
175 cTitle = arguments.
at(3);
176 oCheckbox = arguments.
at(5);
181 switch (nIcon.
toInt32(context)) {
202 switch (nType.
toInt32(context)) {
217 box.setStandardButtons(buttons);
222 QString msg =
i18n(
"Do not show this message again");
228 bool bInitialValue =
false;
231 bInitialValue = value.
toBoolean(context);
235 box.setCheckBox(checkBox);
241 int button = box.exec();
274 if (arguments.
count() < 1) {
275 return context->
throwException(QStringLiteral(
"Missing beep type"));
283 if (arguments.
count() < 1) {
284 return context->
throwException(QStringLiteral(
"Missing plugin index"));
286 const int nIndex = arguments.
at(0).
toInt32(context);
288 if (nIndex < 0 || nIndex >= s_num_fake_plugins) {
289 return context->
throwException(QStringLiteral(
"PlugIn index out of bounds"));
292 const FakePluginInfo &info = s_fake_plugins[nIndex];
298 const DocumentPrivate *doc =
reinterpret_cast<DocumentPrivate *
>(object);
299 if (doc->m_parent->historyAtBegin()) {
303 doc->m_parent->setPrevViewport();
309 const DocumentPrivate *doc =
reinterpret_cast<DocumentPrivate *
>(object);
310 if (doc->m_parent->historyAtEnd()) {
314 doc->m_parent->setNextViewport();
321 DocumentPrivate *doc =
reinterpret_cast<DocumentPrivate *
>(object);
323 const int interval = arguments.
at(1).
toInt32(ctx);
329 timer->
start(interval);
331 return JSApp::wrapTimer(ctx, timer);
338 const int timerId = timerObject.
property(ctx, OKULAR_TIMERID).
toInt32(ctx);
339 QTimer *timer = g_timerCache->value(timerId);
340 if (timer !=
nullptr) {
342 g_timerCache->remove(timerId);
352 DocumentPrivate *doc =
reinterpret_cast<DocumentPrivate *
>(object);
354 const int interval = arguments.
at(1).
toInt32(ctx);
361 timer->
start(interval);
363 return JSApp::wrapTimer(ctx, timer);
370 const int timerId = timerObject.
property(ctx, OKULAR_TIMERID).
toInt32(ctx);
371 QTimer *timer = g_timerCache->value(timerId);
373 if (timer !=
nullptr) {
375 g_timerCache->remove(timerId);
384 static bool initialized =
false;
392 g_appProto->
defineProperty(ctx, QStringLiteral(
"formsVersion"), appGetFormsVersion);
393 g_appProto->
defineProperty(ctx, QStringLiteral(
"language"), appGetLanguage);
394 g_appProto->
defineProperty(ctx, QStringLiteral(
"numPlugIns"), appGetNumPlugins);
395 g_appProto->
defineProperty(ctx, QStringLiteral(
"platform"), appGetPlatform);
396 g_appProto->
defineProperty(ctx, QStringLiteral(
"plugIns"), appGetPlugIns);
397 g_appProto->
defineProperty(ctx, QStringLiteral(
"printColorProfiles"), appGetPrintColorProfiles);
398 g_appProto->
defineProperty(ctx, QStringLiteral(
"printerNames"), appGetPrinterNames);
399 g_appProto->
defineProperty(ctx, QStringLiteral(
"viewerType"), appGetViewerType);
400 g_appProto->
defineProperty(ctx, QStringLiteral(
"viewerVariation"), appGetViewerVariation);
401 g_appProto->
defineProperty(ctx, QStringLiteral(
"viewerVersion"), appGetViewerVersion);
403 g_appProto->
defineFunction(ctx, QStringLiteral(
"alert"), appAlert);
405 g_appProto->
defineFunction(ctx, QStringLiteral(
"getNthPlugInName"), appGetNthPlugInName);
406 g_appProto->
defineFunction(ctx, QStringLiteral(
"goBack"), appGoBack);
407 g_appProto->
defineFunction(ctx, QStringLiteral(
"goForward"), appGoForward);
408 g_appProto->
defineFunction(ctx, QStringLiteral(
"setInterval"), appSetInterval);
409 g_appProto->
defineFunction(ctx, QStringLiteral(
"clearInterval"), appClearInterval);
410 g_appProto->
defineFunction(ctx, QStringLiteral(
"setTimeOut"), appSetTimeOut);
411 g_appProto->
defineFunction(ctx, QStringLiteral(
"clearTimeOut"), appClearTimeOut);
424 g_timerCache->insert(timer->
timerId(), timer);
429 void JSApp::clearCachedFields()
432 qDeleteAll(g_timerCache->begin(), g_timerCache->end());
433 g_timerCache->clear();