• 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_console.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_console_p.h"
12 
13 #include <kjs/kjsobject.h>
14 #include <kjs/kjsprototype.h>
15 #include <kjs/kjsarguments.h>
16 
17 #include <kdebug.h>
18 
19 #include "../debug_p.h"
20 
21 using namespace Okular;
22 
23 static KJSPrototype *g_consoleProto;
24 
25 #ifdef OKULAR_JS_CONSOLE
26 
27 #include <qlayout.h>
28 #include <qplaintextedit.h>
29 
30 #include <kdialog.h>
31 #include <kstandardguiitem.h>
32 
33 K_GLOBAL_STATIC( KDialog, g_jsConsoleWindow )
34 static QPlainTextEdit *g_jsConsoleLog = 0;
35 
36 static void createConsoleWindow()
37 {
38  if ( g_jsConsoleWindow.exists() )
39  return;
40 
41  g_jsConsoleWindow->setButtons( KDialog::Close | KDialog::User1 );
42  g_jsConsoleWindow->setButtonGuiItem( KDialog::User1, KStandardGuiItem::clear() );
43 
44  QVBoxLayout *mainLay = new QVBoxLayout( g_jsConsoleWindow->mainWidget() );
45  mainLay->setMargin( 0 );
46  g_jsConsoleLog = new QPlainTextEdit( g_jsConsoleWindow->mainWidget() );
47  g_jsConsoleLog->setReadOnly( true );
48  mainLay->addWidget( g_jsConsoleLog );
49 
50  QObject::connect( g_jsConsoleWindow, SIGNAL(closeClicked()),
51  g_jsConsoleWindow, SLOT(close()) );
52  QObject::connect( g_jsConsoleWindow, SIGNAL(user1Clicked()),
53  g_jsConsoleLog, SLOT(clear()) );
54 }
55 
56 static void showConsole()
57 {
58  createConsoleWindow();
59  g_jsConsoleWindow->show();
60 }
61 
62 static void hideConsole()
63 {
64  if ( !g_jsConsoleWindow.exists() )
65  return;
66 
67  g_jsConsoleWindow->hide();
68 }
69 
70 static void clearConsole()
71 {
72  if ( !g_jsConsoleWindow.exists() )
73  return;
74 
75  g_jsConsoleLog->clear();
76 }
77 
78 static void outputToConsole( const QString &message )
79 {
80  showConsole();
81  g_jsConsoleLog->appendPlainText( message );
82 }
83 
84 #else /* OKULAR_JS_CONSOLE */
85 
86 static void showConsole()
87 {
88 }
89 
90 static void hideConsole()
91 {
92 }
93 
94 static void clearConsole()
95 {
96 }
97 
98 static void outputToConsole( const QString &cMessage )
99 {
100  kDebug(OkularDebug) << "CONSOLE:" << cMessage;
101 }
102 
103 #endif /* OKULAR_JS_CONSOLE */
104 
105 static KJSObject consoleClear( KJSContext *, void *, const KJSArguments & )
106 {
107  clearConsole();
108  return KJSUndefined();
109 }
110 
111 static KJSObject consoleHide( KJSContext *, void *, const KJSArguments & )
112 {
113  hideConsole();
114  return KJSUndefined();
115 }
116 
117 static KJSObject consolePrintln( KJSContext *ctx, void *,
118  const KJSArguments &arguments )
119 {
120  QString cMessage = arguments.at( 0 ).toString( ctx );
121  outputToConsole( cMessage );
122 
123  return KJSUndefined();
124 }
125 
126 static KJSObject consoleShow( KJSContext *, void *, const KJSArguments & )
127 {
128  showConsole();
129  return KJSUndefined();
130 }
131 
132 void JSConsole::initType( KJSContext *ctx )
133 {
134  static bool initialized = false;
135  if ( initialized )
136  return;
137  initialized = true;
138 
139  g_consoleProto = new KJSPrototype();
140 
141  g_consoleProto->defineFunction( ctx, "clear", consoleClear );
142  g_consoleProto->defineFunction( ctx, "hide", consoleHide );
143  g_consoleProto->defineFunction( ctx, "println", consolePrintln );
144  g_consoleProto->defineFunction( ctx, "hide", consoleShow );
145 }
146 
147 KJSObject JSConsole::object( KJSContext *ctx )
148 {
149  return g_consoleProto->constructObject( ctx, 0 );
150 }
consolePrintln
static KJSObject consolePrintln(KJSContext *ctx, void *, const KJSArguments &arguments)
Definition: kjs_console.cpp:117
consoleHide
static KJSObject consoleHide(KJSContext *, void *, const KJSArguments &)
Definition: kjs_console.cpp:111
Okular::JSConsole::object
static KJSObject object(KJSContext *ctx)
Definition: kjs_console.cpp:147
g_consoleProto
static KJSPrototype * g_consoleProto
Definition: kjs_console.cpp:23
kjs_console_p.h
OkularDebug
#define OkularDebug
Definition: debug_p.h:13
consoleClear
static KJSObject consoleClear(KJSContext *, void *, const KJSArguments &)
Definition: kjs_console.cpp:105
hideConsole
static void hideConsole()
Definition: kjs_console.cpp:90
Okular::JSConsole::initType
static void initType(KJSContext *ctx)
Definition: kjs_console.cpp:132
showConsole
static void showConsole()
Definition: kjs_console.cpp:86
clearConsole
static void clearConsole()
Definition: kjs_console.cpp:94
consoleShow
static KJSObject consoleShow(KJSContext *, void *, const KJSArguments &)
Definition: kjs_console.cpp:126
outputToConsole
static void outputToConsole(const QString &cMessage)
Definition: kjs_console.cpp:98
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