• 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
kjs_app.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 "kjs_app_p.h"
12 
13 #include <kjs/kjsarguments.h>
14 #include <kjs/kjsobject.h>
15 #include <kjs/kjsprototype.h>
16 
17 #include <qapplication.h>
18 
19 #include <kglobal.h>
20 #include <klocale.h>
21 
22 #include "../document_p.h"
23 #include "kjs_fullscreen_p.h"
24 
25 using namespace Okular;
26 
27 static KJSPrototype *g_appProto;
28 
29 // the acrobat version we fake
30 static const double fake_acroversion = 8.00;
31 
32 static const struct FakePluginInfo {
33  const char *name;
34  bool certified;
35  bool loaded;
36  const char *path;
37 } s_fake_plugins[] = {
38  { "Annots", true, true, "" },
39  { "EFS", true, true, "" },
40  { "EScript", true, true, "" },
41  { "Forms", true, true, "" },
42  { "ReadOutLoud", true, true, "" },
43  { "WebLink", true, true, "" }
44 };
45 static const int s_num_fake_plugins = sizeof( s_fake_plugins ) / sizeof( s_fake_plugins[0] );
46 
47 
48 static KJSObject appGetFormsVersion( KJSContext *, void * )
49 {
50  // faking a bit...
51  return KJSNumber( fake_acroversion );
52 }
53 
54 static KJSObject appGetLanguage( KJSContext *, void * )
55 {
56  QString lang;
57  QString country;
58  QString dummy;
59  KLocale::splitLocale( KGlobal::locale()->language(),
60  lang, country, dummy, dummy );
61  QString acroLang = QString::fromLatin1( "ENU" );
62  if ( lang == QLatin1String( "da" ) )
63  acroLang = QString::fromLatin1( "DAN" ); // Danish
64  else if ( lang == QLatin1String( "de" ) )
65  acroLang = QString::fromLatin1( "DEU" ); // German
66  else if ( lang == QLatin1String( "en" ) )
67  acroLang = QString::fromLatin1( "ENU" ); // English
68  else if ( lang == QLatin1String( "es" ) )
69  acroLang = QString::fromLatin1( "ESP" ); // Spanish
70  else if ( lang == QLatin1String( "fr" ) )
71  acroLang = QString::fromLatin1( "FRA" ); // French
72  else if ( lang == QLatin1String( "it" ) )
73  acroLang = QString::fromLatin1( "ITA" ); // Italian
74  else if ( lang == QLatin1String( "ko" ) )
75  acroLang = QString::fromLatin1( "KOR" ); // Korean
76  else if ( lang == QLatin1String( "ja" ) )
77  acroLang = QString::fromLatin1( "JPN" ); // Japanese
78  else if ( lang == QLatin1String( "nl" ) )
79  acroLang = QString::fromLatin1( "NLD" ); // Dutch
80  else if ( lang == QLatin1String( "pt" ) && country == QLatin1String( "BR" ) )
81  acroLang = QString::fromLatin1( "PTB" ); // Brazilian Portuguese
82  else if ( lang == QLatin1String( "fi" ) )
83  acroLang = QString::fromLatin1( "SUO" ); // Finnish
84  else if ( lang == QLatin1String( "sv" ) )
85  acroLang = QString::fromLatin1( "SVE" ); // Swedish
86  else if ( lang == QLatin1String( "zh" ) && country == QLatin1String( "CN" ) )
87  acroLang = QString::fromLatin1( "CHS" ); // Chinese Simplified
88  else if ( lang == QLatin1String( "zh" ) && country == QLatin1String( "TW" ) )
89  acroLang = QString::fromLatin1( "CHT" ); // Chinese Traditional
90  return KJSString( acroLang );
91 }
92 
93 static KJSObject appGetNumPlugins( KJSContext *, void * )
94 {
95  return KJSNumber( s_num_fake_plugins );
96 }
97 
98 static KJSObject appGetPlatform( KJSContext *, void * )
99 {
100 #if defined(Q_OS_WIN)
101  return KJSString( QString::fromLatin1( "WIN" ) );
102 #elif defined(Q_OS_MAC)
103  return KJSString( QString::fromLatin1( "MAC" ) );
104 #else
105  return KJSString( QString::fromLatin1( "UNIX" ) );
106 #endif
107 }
108 
109 static KJSObject appGetPlugIns( KJSContext *context, void * )
110 {
111  KJSArray plugins( context, s_num_fake_plugins );
112  for ( int i = 0; i < s_num_fake_plugins; ++i )
113  {
114  const FakePluginInfo &info = s_fake_plugins[i];
115  KJSObject plugin;
116  plugin.setProperty( context, "certified", info.certified );
117  plugin.setProperty( context, "loaded", info.loaded );
118  plugin.setProperty( context, "name", info.name );
119  plugin.setProperty( context, "path", info.path );
120  plugin.setProperty( context, "version", fake_acroversion );
121  plugins.setProperty( context, QString::number( i ), plugin );
122  }
123  return plugins;
124 }
125 
126 static KJSObject appGetPrintColorProfiles( KJSContext *context, void * )
127 {
128  return KJSArray( context, 0 );
129 }
130 
131 static KJSObject appGetPrinterNames( KJSContext *context, void * )
132 {
133  return KJSArray( context, 0 );
134 }
135 
136 static KJSObject appGetViewerType( KJSContext *, void * )
137 {
138  // faking a bit...
139  return KJSString( QString::fromLatin1( "Reader" ) );
140 }
141 
142 static KJSObject appGetViewerVariation( KJSContext *, void * )
143 {
144  // faking a bit...
145  return KJSString( QString::fromLatin1( "Reader" ) );
146 }
147 
148 static KJSObject appGetViewerVersion( KJSContext *, void * )
149 {
150  // faking a bit...
151  return KJSNumber( fake_acroversion );
152 }
153 
154 static KJSObject appBeep( KJSContext *context, void *,
155  const KJSArguments &arguments )
156 {
157  if ( arguments.count() < 1 )
158  {
159  return context->throwException( "Missing beep type" );
160  }
161  QApplication::beep();
162  return KJSUndefined();
163 }
164 
165 static KJSObject appGetNthPlugInName( KJSContext *context, void *,
166  const KJSArguments &arguments )
167 {
168  if ( arguments.count() < 1 )
169  {
170  return context->throwException( "Missing plugin index" );
171  }
172  const int nIndex = arguments.at( 0 ).toInt32( context );
173 
174  if ( nIndex < 0 || nIndex >= s_num_fake_plugins )
175  return context->throwException( "PlugIn index out of bounds" );
176 
177  const FakePluginInfo &info = s_fake_plugins[nIndex];
178  return KJSString( info.name );
179 }
180 
181 static KJSObject appGoBack( KJSContext *, void *object,
182  const KJSArguments & )
183 {
184  const DocumentPrivate *doc = reinterpret_cast< DocumentPrivate * >( object );
185  if ( doc->m_parent->historyAtBegin() )
186  return KJSUndefined();
187 
188  doc->m_parent->setPrevViewport();
189  return KJSUndefined();
190 }
191 
192 static KJSObject appGoForward( KJSContext *, void *object,
193  const KJSArguments & )
194 {
195  const DocumentPrivate *doc = reinterpret_cast< DocumentPrivate * >( object );
196  if ( doc->m_parent->historyAtEnd() )
197  return KJSUndefined();
198 
199  doc->m_parent->setNextViewport();
200  return KJSUndefined();
201 }
202 
203 void JSApp::initType( KJSContext *ctx )
204 {
205  static bool initialized = false;
206  if ( initialized )
207  return;
208  initialized = true;
209 
210  g_appProto = new KJSPrototype();
211 
212  g_appProto->defineProperty( ctx, "formsVersion", appGetFormsVersion );
213  g_appProto->defineProperty( ctx, "language", appGetLanguage );
214  g_appProto->defineProperty( ctx, "numPlugIns", appGetNumPlugins );
215  g_appProto->defineProperty( ctx, "platform", appGetPlatform );
216  g_appProto->defineProperty( ctx, "plugIns", appGetPlugIns );
217  g_appProto->defineProperty( ctx, "printColorProfiles", appGetPrintColorProfiles );
218  g_appProto->defineProperty( ctx, "printerNames", appGetPrinterNames );
219  g_appProto->defineProperty( ctx, "viewerType", appGetViewerType );
220  g_appProto->defineProperty( ctx, "viewerVariation", appGetViewerVariation );
221  g_appProto->defineProperty( ctx, "viewerVersion", appGetViewerVersion );
222 
223  g_appProto->defineFunction( ctx, "beep", appBeep );
224  g_appProto->defineFunction( ctx, "getNthPlugInName", appGetNthPlugInName );
225  g_appProto->defineFunction( ctx, "goBack", appGoBack );
226  g_appProto->defineFunction( ctx, "goForward", appGoForward );
227 }
228 
229 KJSObject JSApp::object( KJSContext *ctx, DocumentPrivate *doc )
230 {
231  return g_appProto->constructObject( ctx, doc );
232 }
kjs_fullscreen_p.h
s_num_fake_plugins
static const int s_num_fake_plugins
Definition: kjs_app.cpp:45
Okular::JSApp::object
static KJSObject object(KJSContext *ctx, DocumentPrivate *doc)
Definition: kjs_app.cpp:229
appGetPlatform
static KJSObject appGetPlatform(KJSContext *, void *)
Definition: kjs_app.cpp:98
s_fake_plugins
static const struct FakePluginInfo s_fake_plugins[]
appGetViewerType
static KJSObject appGetViewerType(KJSContext *, void *)
Definition: kjs_app.cpp:136
appGetPrintColorProfiles
static KJSObject appGetPrintColorProfiles(KJSContext *context, void *)
Definition: kjs_app.cpp:126
appGetPlugIns
static KJSObject appGetPlugIns(KJSContext *context, void *)
Definition: kjs_app.cpp:109
appBeep
static KJSObject appBeep(KJSContext *context, void *, const KJSArguments &arguments)
Definition: kjs_app.cpp:154
fake_acroversion
static const double fake_acroversion
Definition: kjs_app.cpp:30
g_appProto
static KJSPrototype * g_appProto
Definition: kjs_app.cpp:27
Okular::Document::setNextViewport
void setNextViewport()
Sets the current document viewport to the previous viewport in the viewport history.
Definition: document.cpp:3208
kjs_app_p.h
appGetNthPlugInName
static KJSObject appGetNthPlugInName(KJSContext *context, void *, const KJSArguments &arguments)
Definition: kjs_app.cpp:165
appGoForward
static KJSObject appGoForward(KJSContext *, void *object, const KJSArguments &)
Definition: kjs_app.cpp:192
appGetFormsVersion
static KJSObject appGetFormsVersion(KJSContext *, void *)
Definition: kjs_app.cpp:48
appGetViewerVersion
static KJSObject appGetViewerVersion(KJSContext *, void *)
Definition: kjs_app.cpp:148
Okular::DocumentPrivate
Definition: document_p.h:83
Okular::Document::setPrevViewport
void setPrevViewport()
Sets the current document viewport to the next viewport in the viewport history.
Definition: document.cpp:3191
Okular::Document::historyAtBegin
bool historyAtBegin() const
Returns whether the document history is at the begin.
Definition: document.cpp:2736
Okular::JSApp::initType
static void initType(KJSContext *ctx)
Definition: kjs_app.cpp:203
Okular::Document::historyAtEnd
bool historyAtEnd() const
Returns whether the document history is at the end.
Definition: document.cpp:2741
appGetViewerVariation
static KJSObject appGetViewerVariation(KJSContext *, void *)
Definition: kjs_app.cpp:142
appGetPrinterNames
static KJSObject appGetPrinterNames(KJSContext *context, void *)
Definition: kjs_app.cpp:131
appGetLanguage
static KJSObject appGetLanguage(KJSContext *, void *)
Definition: kjs_app.cpp:54
Okular::DocumentPrivate::m_parent
Document * m_parent
Definition: document_p.h:187
appGetNumPlugins
static KJSObject appGetNumPlugins(KJSContext *, void *)
Definition: kjs_app.cpp:93
appGoBack
static KJSObject appGoBack(KJSContext *, void *object, const KJSArguments &)
Definition: kjs_app.cpp:181
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