diff --git a/CMakeLists.txt b/CMakeLists.txt index 51c1d6de8..f75623eac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ set(okularcore_SRCS core/pagesize.cpp core/pagetransition.cpp core/rotationjob.cpp + core/scripter.cpp core/sound.cpp core/sourcereference.cpp core/textdocumentgenerator.cpp diff --git a/core/document.cpp b/core/document.cpp index b4a658e90..6c8c6e33e 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -62,6 +62,7 @@ #include "page.h" #include "page_p.h" #include "pagecontroller_p.h" +#include "scripter.h" #include "settings.h" #include "sourcereference.h" @@ -1434,6 +1435,16 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi AudioPlayer::instance()->d->m_currentDocument = isstdin ? KUrl() : d->m_url; d->m_docSize = document_size; + const QStringList docScripts = d->m_generator->metaData( "DocumentScripts", "JavaScript" ).toStringList(); + if ( !docScripts.isEmpty() ) + { + d->m_scripter = new Scripter( d ); + Q_FOREACH ( const QString &docscript, docScripts ) + { + d->m_scripter->execute( JavaScript, docscript ); + } + } + return true; } @@ -1455,6 +1466,9 @@ void Document::closeDocument() if ( !d->m_generator ) return; + delete d->m_scripter; + d->m_scripter = 0; + QEventLoop loop; bool startEventLoop = false; do @@ -2630,6 +2644,13 @@ void Document::processAction( const Action * action ) AudioPlayer::instance()->playSound( linksound->sound(), linksound ); } break; + case Action::Script: { + const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); + if ( !d->m_scripter ) + d->m_scripter = new Scripter( d ); + d->m_scripter->execute( linkscript->scriptType(), linkscript->script() ); + } break; + case Action::Movie: //const MovieAction * movie = static_cast< const MovieAction * >( action ); // TODO this (Movie action) diff --git a/core/document_p.h b/core/document_p.h index e2677adf1..65eb1aeee 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -36,6 +36,7 @@ struct RunningSearch; namespace Okular { class ConfigInterface; class SaveInterface; +class Scripter; } struct GeneratorInfo @@ -77,6 +78,7 @@ class DocumentPrivate m_generator( 0 ), m_generatorsLoaded( false ), m_closingLoop( 0 ), + m_scripter( 0 ), m_fontsCached( false ) { } @@ -189,6 +191,8 @@ class DocumentPrivate QEventLoop *m_closingLoop; + Scripter *m_scripter; + QPointer< FontExtractionThread > m_fontThread; bool m_fontsCached; FontInfo::List m_fontsCache; diff --git a/core/scripter.cpp b/core/scripter.cpp new file mode 100644 index 000000000..2fd77013d --- /dev/null +++ b/core/scripter.cpp @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "scripter.h" + +#include + +#include "debug_p.h" + +using namespace Okular; + +class Okular::ScripterPrivate +{ + public: + ScripterPrivate( DocumentPrivate *doc ) + : m_doc( doc ) + { + } + + ~ScripterPrivate() + { + } + + DocumentPrivate *m_doc; +}; + +Scripter::Scripter( DocumentPrivate *doc ) + : d( new ScripterPrivate( doc ) ) +{ +} + +Scripter::~Scripter() +{ + delete d; +} + +QString Scripter::execute( ScriptType type, const QString &script ) +{ + kDebug(OkularDebug) << "executing the script:"; +#if 0 + if ( script.length() < 1000 ) + qDebug() << script; + else + qDebug() << script.left( 1000 ) << "[...]"; +#endif + switch ( type ) + { + case JavaScript: + break; + } + return QString(); +} diff --git a/core/scripter.h b/core/scripter.h new file mode 100644 index 000000000..69cf5d491 --- /dev/null +++ b/core/scripter.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef OKULAR_SCRIPTER_H +#define OKULAR_SCRIPTER_H + +#include "global.h" + +class QString; +class QStringList; + +namespace Okular { + +class Document; +class DocumentPrivate; +class ScripterPrivate; + +class Scripter +{ + friend class Document; + friend class DocumentPrivate; + + public: + ~Scripter(); + + QString execute( ScriptType type, const QString &script ); + + private: + friend class ScripterPrivate; + ScripterPrivate* d; + + Scripter( DocumentPrivate *doc ); +}; + +} + +#endif