Changeset View
Changeset View
Standalone View
Standalone View
core/scripter.cpp
Show All 15 Lines | |||||
16 | #include "script/executor_kjs_p.h" | 16 | #include "script/executor_kjs_p.h" | ||
17 | 17 | | |||
18 | using namespace Okular; | 18 | using namespace Okular; | ||
19 | 19 | | |||
20 | class Okular::ScripterPrivate | 20 | class Okular::ScripterPrivate | ||
21 | { | 21 | { | ||
22 | public: | 22 | public: | ||
23 | ScripterPrivate( DocumentPrivate *doc ) | 23 | ScripterPrivate( DocumentPrivate *doc ) | ||
24 | : m_doc( doc ), m_kjs( nullptr ), m_event( nullptr ) | 24 | : m_doc( doc ) | ||
25 | { | 25 | #ifdef WITH_KJS | ||
26 | } | 26 | , m_kjs( nullptr ) | ||
27 | 27 | #endif | |||
28 | ~ScripterPrivate() | 28 | , m_event( nullptr ) | ||
29 | { | 29 | { | ||
30 | delete m_kjs; | | |||
31 | } | 30 | } | ||
32 | 31 | | |||
33 | DocumentPrivate *m_doc; | 32 | DocumentPrivate *m_doc; | ||
34 | ExecutorKJS *m_kjs; | 33 | #ifdef WITH_KJS | ||
34 | QScopedPointer<ExecutorKJS> m_kjs; | ||||
35 | #endif | ||||
35 | Event *m_event; | 36 | Event *m_event; | ||
36 | }; | 37 | }; | ||
37 | 38 | | |||
38 | Scripter::Scripter( DocumentPrivate *doc ) | 39 | Scripter::Scripter( DocumentPrivate *doc ) | ||
39 | : d( new ScripterPrivate( doc ) ) | 40 | : d( new ScripterPrivate( doc ) ) | ||
40 | { | 41 | { | ||
41 | } | 42 | } | ||
42 | 43 | | |||
43 | Scripter::~Scripter() | 44 | Scripter::~Scripter() | ||
44 | { | 45 | { | ||
45 | delete d; | 46 | delete d; | ||
46 | } | 47 | } | ||
47 | 48 | | |||
48 | QString Scripter::execute( ScriptType type, const QString &script ) | 49 | QString Scripter::execute( ScriptType type, const QString &script ) | ||
49 | { | 50 | { | ||
50 | qCDebug(OkularCoreDebug) << "executing the script:"; | 51 | qCDebug(OkularCoreDebug) << "executing the script:"; | ||
51 | #if 0 | 52 | #ifdef WITH_KJS | ||
52 | if ( script.length() < 1000 ) | 53 | if ( script.length() < 1000 ) | ||
53 | qDebug() << script; | 54 | qDebug() << script; | ||
54 | else | 55 | else | ||
55 | qDebug() << script.left( 1000 ) << "[...]"; | 56 | qDebug() << script.left( 1000 ) << "[...]"; | ||
56 | #endif | | |||
57 | static QString builtInScript; | 57 | static QString builtInScript; | ||
58 | if ( builtInScript.isNull() ) | 58 | if ( builtInScript.isNull() ) | ||
59 | { | 59 | { | ||
60 | QFile builtInResource ( ":/script/builtin.js" ); | 60 | QFile builtInResource ( ":/script/builtin.js" ); | ||
61 | if (!builtInResource.open( QIODevice::ReadOnly )) | 61 | if (!builtInResource.open( QIODevice::ReadOnly )) | ||
62 | { | 62 | { | ||
63 | qCDebug(OkularCoreDebug) << "failed to load builtin script"; | 63 | qCDebug(OkularCoreDebug) << "failed to load builtin script"; | ||
64 | } | 64 | } | ||
65 | else | 65 | else | ||
66 | { | 66 | { | ||
67 | builtInScript = QString::fromUtf8( builtInResource.readAll() ); | 67 | builtInScript = QString::fromUtf8( builtInResource.readAll() ); | ||
68 | builtInResource.close(); | 68 | builtInResource.close(); | ||
69 | } | 69 | } | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | switch ( type ) | 72 | switch ( type ) | ||
73 | { | 73 | { | ||
74 | case JavaScript: | 74 | case JavaScript: | ||
75 | if ( !d->m_kjs ) | 75 | if ( !d->m_kjs ) | ||
76 | { | 76 | { | ||
77 | d->m_kjs = new ExecutorKJS( d->m_doc ); | 77 | d->m_kjs.reset(new ExecutorKJS( d->m_doc )); | ||
78 | } | 78 | } | ||
79 | d->m_kjs->execute( builtInScript + script, d->m_event ); | 79 | d->m_kjs->execute( builtInScript + script, d->m_event ); | ||
80 | break; | 80 | break; | ||
81 | } | 81 | } | ||
82 | #endif | ||||
82 | return QString(); | 83 | return QString(); | ||
83 | } | 84 | } | ||
84 | 85 | | |||
85 | void Scripter::setEvent( Event *event ) | 86 | void Scripter::setEvent( Event *event ) | ||
86 | { | 87 | { | ||
87 | d->m_event = event; | 88 | d->m_event = event; | ||
88 | } | 89 | } | ||
89 | 90 | | |||
90 | Event *Scripter::event() const | 91 | Event *Scripter::event() const | ||
91 | { | 92 | { | ||
92 | return d->m_event; | 93 | return d->m_event; | ||
93 | } | 94 | } |