Add an action kind for executing a script when activated.

The only script type so far is JavaScript.

svn path=/trunk/KDE/kdegraphics/okular/; revision=796633
This commit is contained in:
Pino Toscano 2008-04-13 22:30:27 +00:00
parent 2737fdb2e5
commit d249c2783b
3 changed files with 109 additions and 1 deletions

View file

@ -322,6 +322,58 @@ Okular::Sound *SoundAction::sound() const
return d->m_sound;
}
// ScriptAction
class Okular::ScriptActionPrivate : public Okular::ActionPrivate
{
public:
ScriptActionPrivate( enum ScriptType type, const QString &script )
: ActionPrivate(), m_scriptType( type ), m_script( script )
{
}
ScriptType m_scriptType;
QString m_script;
};
ScriptAction::ScriptAction( enum ScriptType type, const QString &script )
: Action( *new ScriptActionPrivate( type, script ) )
{
}
ScriptAction::~ScriptAction()
{
}
Action::ActionType ScriptAction::actionType() const
{
return Script;
}
QString ScriptAction::actionTip() const
{
Q_D( const Okular::ScriptAction );
switch ( d->m_scriptType )
{
case JavaScript:
return i18n( "JavaScript Script" );
}
return QString();
}
ScriptType ScriptAction::scriptType() const
{
Q_D( const Okular::ScriptAction );
return d->m_scriptType;
}
QString ScriptAction::script() const
{
Q_D( const Okular::ScriptAction );
return d->m_script;
}
// MovieAction
#if 0

View file

@ -10,6 +10,7 @@
#ifndef _OKULAR_ACTION_H_
#define _OKULAR_ACTION_H_
#include <okular/core/global.h>
#include <okular/core/okular_export.h>
#include <QtCore/QString>
@ -22,6 +23,7 @@ class ExecuteActionPrivate;
class BrowseActionPrivate;
class DocumentActionPrivate;
class SoundActionPrivate;
class ScriptActionPrivate;
class MovieActionPrivate;
class Sound;
class DocumentViewport;
@ -45,7 +47,8 @@ class OKULAR_EXPORT Action
Browse, ///< Browse a given website
DocAction, ///< Start a custom action
Sound, ///< Play a sound
Movie ///< Play a movie
Movie, ///< Play a movie
Script, ///< Executes a Script code
};
/**
@ -333,6 +336,51 @@ class OKULAR_EXPORT SoundAction : public Action
Q_DISABLE_COPY( SoundAction )
};
/**
* The Script action executes a Script code.
*
* @since 0.7 (KDE 4.1)
*/
class OKULAR_EXPORT ScriptAction : public Action
{
public:
/**
* Creates a new Script action.
*
* @param script The code to execute.
*/
ScriptAction( enum ScriptType type, const QString &script );
/**
* Destroys the browse action.
*/
virtual ~ScriptAction();
/**
* Returns the action type.
*/
ActionType actionType() const;
/**
* Returns the action tip.
*/
QString actionTip() const;
/**
* Returns the type of action.
*/
ScriptType scriptType() const;
/**
* Returns the code.
*/
QString script() const;
private:
Q_DECLARE_PRIVATE( ScriptAction )
Q_DISABLE_COPY( ScriptAction )
};
#if 0
/**
* The Movie action plays a video on activation.

View file

@ -70,6 +70,14 @@ enum MergeSide
MergeAll = 4 ///< Merge if the areas intersects, no matter which side(s).
};
/**
* Describes the possible script types.
*/
enum ScriptType
{
JavaScript = 0 ///< JavaScript code
};
}
#endif