mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-02 14:14:10 +00:00
Add a scripter class to execute scripts on request.
Trigger its execution at the document loading, if there are "top level" scripts, and when a script action is activated. svn path=/trunk/KDE/kdegraphics/okular/; revision=796637
This commit is contained in:
parent
d249c2783b
commit
513c7cf225
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
58
core/scripter.cpp
Normal file
58
core/scripter.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* 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 <kdebug.h>
|
||||
|
||||
#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();
|
||||
}
|
43
core/scripter.h
Normal file
43
core/scripter.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* 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
|
Loading…
Reference in a new issue