diff --git a/core/action.cpp b/core/action.cpp index 03a7cea0d..c672a3ec5 100644 --- a/core/action.cpp +++ b/core/action.cpp @@ -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 diff --git a/core/action.h b/core/action.h index 4c462c90e..9e4eac3b7 100644 --- a/core/action.h +++ b/core/action.h @@ -10,6 +10,7 @@ #ifndef _OKULAR_ACTION_H_ #define _OKULAR_ACTION_H_ +#include #include #include @@ -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. diff --git a/core/global.h b/core/global.h index 92a922f6f..24cef77b4 100644 --- a/core/global.h +++ b/core/global.h @@ -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