• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

okular

  • sources
  • kde-4.12
  • kdegraphics
  • okular
  • core
  • script
executor_kjs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
3  * Copyright (C) 2008 by Harri Porten <porten@kde.org> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  ***************************************************************************/
10 
11 #include "executor_kjs_p.h"
12 
13 #include <kjs/kjsinterpreter.h>
14 #include <kjs/kjsobject.h>
15 #include <kjs/kjsprototype.h>
16 #include <kjs/kjsarguments.h>
17 
18 #include <kdebug.h>
19 
20 #include "../debug_p.h"
21 #include "../document_p.h"
22 
23 #include "kjs_app_p.h"
24 #include "kjs_console_p.h"
25 #include "kjs_data_p.h"
26 #include "kjs_document_p.h"
27 #include "kjs_field_p.h"
28 #include "kjs_fullscreen_p.h"
29 #include "kjs_spell_p.h"
30 #include "kjs_util_p.h"
31 
32 using namespace Okular;
33 
34 class Okular::ExecutorKJSPrivate
35 {
36  public:
37  ExecutorKJSPrivate( DocumentPrivate *doc )
38  : m_doc( doc )
39  {
40  initTypes();
41  }
42  ~ExecutorKJSPrivate()
43  {
44  JSField::clearCachedFields();
45 
46  delete m_interpreter;
47  }
48 
49  void initTypes();
50 
51  DocumentPrivate *m_doc;
52  KJSInterpreter *m_interpreter;
53  KJSGlobalObject m_docObject;
54 };
55 
56 void ExecutorKJSPrivate::initTypes()
57 {
58  m_docObject = JSDocument::wrapDocument( m_doc );
59  m_interpreter = new KJSInterpreter( m_docObject );
60 
61  KJSContext *ctx = m_interpreter->globalContext();
62 
63  JSApp::initType( ctx );
64  JSFullscreen::initType( ctx );
65  JSConsole::initType( ctx );
66  JSData::initType( ctx );
67  JSDocument::initType( ctx );
68  JSField::initType( ctx );
69  JSSpell::initType( ctx );
70  JSUtil::initType( ctx );
71 
72  m_docObject.setProperty( ctx, "app", JSApp::object( ctx, m_doc ) );
73  m_docObject.setProperty( ctx, "console", JSConsole::object( ctx ) );
74  m_docObject.setProperty( ctx, "Doc", m_docObject );
75  m_docObject.setProperty( ctx, "spell", JSSpell::object( ctx ) );
76  m_docObject.setProperty( ctx, "util", JSUtil::object( ctx ) );
77 }
78 
79 ExecutorKJS::ExecutorKJS( DocumentPrivate *doc )
80  : d( new ExecutorKJSPrivate( doc ) )
81 {
82 }
83 
84 ExecutorKJS::~ExecutorKJS()
85 {
86  delete d;
87 }
88 
89 void ExecutorKJS::execute( const QString &script )
90 {
91 #if 0
92  QString script2;
93  QString errMsg;
94  int errLine;
95  if ( !KJSInterpreter::normalizeCode( script, &script2, &errLine, &errMsg ) )
96  {
97  kWarning(OkularDebug) << "Parse error during normalization!";
98  script2 = script;
99  }
100 #endif
101 
102  KJSResult result = d->m_interpreter->evaluate( "okular.js", 1,
103  script, &d->m_docObject );
104  KJSContext* ctx = d->m_interpreter->globalContext();
105  if ( result.isException() || ctx->hasException() )
106  {
107  kDebug(OkularDebug) << "JS exception" << result.errorMessage();
108  }
109  else
110  {
111  kDebug(OkularDebug) << "result:" << result.value().toString( ctx );
112  }
113 }
Okular::ExecutorKJS::~ExecutorKJS
~ExecutorKJS()
Definition: executor_kjs.cpp:84
kjs_fullscreen_p.h
Okular::JSApp::object
static KJSObject object(KJSContext *ctx, DocumentPrivate *doc)
Definition: kjs_app.cpp:229
Okular::JSUtil::object
static KJSObject object(KJSContext *ctx)
Definition: kjs_util.cpp:70
Okular::JSDocument::initType
static void initType(KJSContext *ctx)
Definition: kjs_document.cpp:247
kjs_field_p.h
Okular::JSSpell::initType
static void initType(KJSContext *ctx)
Definition: kjs_spell.cpp:28
executor_kjs_p.h
kjs_document_p.h
Okular::JSConsole::object
static KJSObject object(KJSContext *ctx)
Definition: kjs_console.cpp:147
kjs_spell_p.h
Okular::ExecutorKJS::execute
void execute(const QString &script)
Definition: executor_kjs.cpp:89
Okular::JSData::initType
static void initType(KJSContext *ctx)
Definition: kjs_data.cpp:68
kjs_app_p.h
kjs_console_p.h
OkularDebug
#define OkularDebug
Definition: debug_p.h:13
Okular::JSDocument::wrapDocument
static KJSGlobalObject wrapDocument(DocumentPrivate *doc)
Definition: kjs_document.cpp:282
kjs_util_p.h
Okular::DocumentPrivate
Definition: document_p.h:83
Okular::JSSpell::object
static KJSObject object(KJSContext *ctx)
Definition: kjs_spell.cpp:39
Okular::JSField::clearCachedFields
static void clearCachedFields()
Definition: kjs_field.cpp:224
Okular::JSApp::initType
static void initType(KJSContext *ctx)
Definition: kjs_app.cpp:203
Okular::JSConsole::initType
static void initType(KJSContext *ctx)
Definition: kjs_console.cpp:132
Okular::JSFullscreen::initType
static void initType(KJSContext *ctx)
Definition: kjs_fullscreen.cpp:57
Okular::JSField::initType
static void initType(KJSContext *ctx)
Definition: kjs_field.cpp:198
Okular::ExecutorKJS::ExecutorKJS
ExecutorKJS(DocumentPrivate *doc)
Definition: executor_kjs.cpp:79
Okular::JSUtil::initType
static void initType(KJSContext *ctx)
Definition: kjs_util.cpp:59
kjs_data_p.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:45:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okular

Skip menu "okular"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal