Okular

scripter.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "scripter.h"
8
9#include "config-okular.h"
10
11#include <QDebug>
12#include <QFile>
13
14#include "debug_p.h"
15#include "script/executor_js_p.h"
16
17using namespace Okular;
18
19class Okular::ScripterPrivate
20{
21public:
22 explicit ScripterPrivate(DocumentPrivate *doc)
23 : m_doc(doc)
24#if HAVE_JS
25 , m_js(nullptr)
26#endif
27 , m_event(nullptr)
28 {
29 }
30
31 DocumentPrivate *m_doc;
32#if HAVE_JS
34#endif
35 Event *m_event;
36};
37
38Scripter::Scripter(DocumentPrivate *doc)
39 : d(new ScripterPrivate(doc))
40{
41}
42
43Scripter::~Scripter()
44{
45 delete d;
46}
47
48void Scripter::execute(ScriptType type, const QString &script)
49{
50 qCDebug(OkularCoreDebug) << "executing the script:" << script;
51#if HAVE_JS
52 static QString builtInScript;
53 if (builtInScript.isNull()) {
54 QFile builtInResource(QStringLiteral(":/script/builtin.js"));
55 if (!builtInResource.open(QIODevice::ReadOnly)) {
56 qCDebug(OkularCoreDebug) << "failed to load builtin script";
57 } else {
58 builtInScript = QString::fromUtf8(builtInResource.readAll());
59 builtInResource.close();
60 }
61 }
62
63 switch (type) {
64 case JavaScript:
65 if (!d->m_js) {
66 d->m_js.reset(new ExecutorJS(d->m_doc));
67 }
68 d->m_js->execute(builtInScript + script, d->m_event);
69 }
70#endif
71}
72
73void Scripter::setEvent(Event *event)
74{
75 d->m_event = event;
76}
77
78Event *Scripter::event() const
79{
80 return d->m_event;
81}
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
global.h
Definition action.h:17
ScriptType
Describes the possible script types.
Definition global.h:75
@ JavaScript
JavaScript code.
Definition global.h:76
QString fromUtf8(QByteArrayView str)
bool isNull() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.