File indexing completed on 2024-04-28 04:32:35

0001 /*
0002     SPDX-FileCopyrightText: 2004 Enrico Ros <eros.kde@email.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef _OKULAR_ACTION_H_
0008 #define _OKULAR_ACTION_H_
0009 
0010 #include "global.h"
0011 #include "okularcore_export.h"
0012 
0013 #include <QString>
0014 #include <QVariant>
0015 
0016 namespace Okular
0017 {
0018 class ActionPrivate;
0019 class GotoActionPrivate;
0020 class ExecuteActionPrivate;
0021 class BrowseActionPrivate;
0022 class DocumentActionPrivate;
0023 class SoundActionPrivate;
0024 class ScriptActionPrivate;
0025 class MovieActionPrivate;
0026 class RenditionActionPrivate;
0027 class MovieAnnotation;
0028 class ScreenAnnotation;
0029 class Movie;
0030 class Sound;
0031 class DocumentViewport;
0032 
0033 /**
0034  * @short Encapsulates data that describes an action.
0035  *
0036  * This is the base class for actions. It makes mandatory for inherited
0037  * widgets to reimplement the 'actionType' method and return the type of
0038  * the action described by the reimplemented class.
0039  */
0040 class OKULARCORE_EXPORT Action
0041 {
0042 public:
0043     /**
0044      * Describes the type of action.
0045      */
0046     enum ActionType {
0047         Goto,         ///< Goto a given page or external document
0048         Execute,      ///< Execute a command or external application
0049         Browse,       ///< Browse a given website
0050         DocAction,    ///< Start a custom action
0051         Sound,        ///< Play a sound
0052         Movie,        ///< Play a movie
0053         Script,       ///< Executes a Script code
0054         Rendition,    ///< Play a movie and/or execute a Script code @since 0.16 (KDE 4.10)
0055         BackendOpaque ///< Calls back to the backend with the action @since 1.1
0056     };
0057 
0058     /**
0059      * Destroys the action.
0060      */
0061     virtual ~Action();
0062 
0063     /**
0064      * Returns the type of the action. Every inherited class must return
0065      * an unique identifier.
0066      *
0067      * @see ActionType
0068      */
0069     virtual ActionType actionType() const = 0;
0070 
0071     /**
0072      * Returns a i18n'ed tip of the action that is presented to
0073      * the user.
0074      */
0075     virtual QString actionTip() const;
0076 
0077     /**
0078      * Sets the "native" @p id of the action.
0079      *
0080      * This is for use of the Generator, that can optionally store an
0081      * handle (a pointer, an identifier, etc) of the "native" action
0082      * object, if any.
0083      *
0084      * @note Okular makes no use of this
0085      *
0086      * @since 0.15 (KDE 4.9)
0087      */
0088     void setNativeId(const QVariant &id);
0089 
0090     /**
0091      * Returns the "native" id of the action.
0092      *
0093      * @since 0.15 (KDE 4.9)
0094      */
0095     QVariant nativeId() const;
0096 
0097     /**
0098      * Returns the next actions to be executed after.
0099      *
0100      * @since 1.5
0101      */
0102     QVector<Action *> nextActions() const;
0103 
0104     /**
0105      * Sets the next actions.
0106      *
0107      * Takes ownership of the objects in the actions vector.
0108      * @since 1.5
0109      */
0110     void setNextActions(const QVector<Action *> &actions);
0111 
0112 protected:
0113     /// @cond PRIVATE
0114     explicit Action(ActionPrivate &dd);
0115     Q_DECLARE_PRIVATE(Action)
0116     ActionPrivate *d_ptr;
0117     /// @endcond
0118 
0119 private:
0120     Q_DISABLE_COPY(Action)
0121 };
0122 
0123 /**
0124  * The Goto action changes the viewport to another page
0125  * or loads an external document.
0126  */
0127 class OKULARCORE_EXPORT GotoAction : public Action
0128 {
0129 public:
0130     /**
0131      * Creates a new goto action.
0132      *
0133      * @p fileName The name of an external file that shall be loaded.
0134      * @p viewport The target viewport information of the current document.
0135      */
0136     GotoAction(const QString &fileName, const DocumentViewport &viewport);
0137 
0138     /**
0139      * Creates a new goto action.
0140      *
0141      * @p fileName The name of an external file that shall be loaded.
0142      * @p namedDestination The target named destination for the target document.
0143      *
0144      * @since 0.9 (KDE 4.3)
0145      */
0146     GotoAction(const QString &fileName, const QString &namedDestination);
0147 
0148     /**
0149      * Destroys the goto action.
0150      */
0151     ~GotoAction() override;
0152 
0153     /**
0154      * Returns the action type.
0155      */
0156     ActionType actionType() const override;
0157 
0158     /**
0159      * Returns the action tip.
0160      */
0161     QString actionTip() const override;
0162 
0163     /**
0164      * Returns whether the goto action points to an external document.
0165      */
0166     bool isExternal() const;
0167 
0168     /**
0169      * Returns the filename of the external document.
0170      */
0171     QString fileName() const;
0172 
0173     /**
0174      * Returns the document viewport the goto action points to.
0175      */
0176     DocumentViewport destViewport() const;
0177 
0178     /**
0179      * Returns the document named destination the goto action points to.
0180      *
0181      * @since 0.9 (KDE 4.3)
0182      */
0183     QString destinationName() const;
0184 
0185 private:
0186     Q_DECLARE_PRIVATE(GotoAction)
0187     Q_DISABLE_COPY(GotoAction)
0188 };
0189 
0190 /**
0191  * The Execute action executes an external application.
0192  */
0193 class OKULARCORE_EXPORT ExecuteAction : public Action
0194 {
0195 public:
0196     /**
0197      * Creates a new execute action.
0198      *
0199      * @param fileName The file name of the application to execute.
0200      * @param parameters The parameters of the application to execute.
0201      */
0202     ExecuteAction(const QString &fileName, const QString &parameters);
0203 
0204     /**
0205      * Destroys the execute action.
0206      */
0207     ~ExecuteAction() override;
0208 
0209     /**
0210      * Returns the action type.
0211      */
0212     ActionType actionType() const override;
0213 
0214     /**
0215      * Returns the action tip.
0216      */
0217     QString actionTip() const override;
0218 
0219     /**
0220      * Returns the file name of the application to execute.
0221      */
0222     QString fileName() const;
0223 
0224     /**
0225      * Returns the parameters of the application to execute.
0226      */
0227     QString parameters() const;
0228 
0229 private:
0230     Q_DECLARE_PRIVATE(ExecuteAction)
0231     Q_DISABLE_COPY(ExecuteAction)
0232 };
0233 
0234 /**
0235  * The Browse action browses an url by opening a web browser or
0236  * email client, depending on the url protocol (e.g. http, mailto, etc.).
0237  */
0238 class OKULARCORE_EXPORT BrowseAction : public Action
0239 {
0240 public:
0241     /**
0242      * Creates a new browse action.
0243      *
0244      * @param url The url to browse.
0245      */
0246     explicit BrowseAction(const QUrl &url);
0247 
0248     /**
0249      * Destroys the browse action.
0250      */
0251     ~BrowseAction() override;
0252 
0253     /**
0254      * Returns the action type.
0255      */
0256     ActionType actionType() const override;
0257 
0258     /**
0259      * Returns the action tip.
0260      */
0261     QString actionTip() const override;
0262 
0263     /**
0264      * Returns the url to browse.
0265      */
0266     QUrl url() const;
0267 
0268 private:
0269     Q_DECLARE_PRIVATE(BrowseAction)
0270     Q_DISABLE_COPY(BrowseAction)
0271 };
0272 
0273 /**
0274  * The DocumentAction action contains an action that is performed on
0275  * the current document.
0276  */
0277 class OKULARCORE_EXPORT DocumentAction : public Action
0278 {
0279 public:
0280     /**
0281      * Describes the possible action types.
0282      */
0283     enum DocumentActionType {
0284         PageFirst = 1,       ///< Jump to first page
0285         PagePrev = 2,        ///< Jump to previous page
0286         PageNext = 3,        ///< Jump to next page
0287         PageLast = 4,        ///< Jump to last page
0288         HistoryBack = 5,     ///< Go back in page history
0289         HistoryForward = 6,  ///< Go forward in page history
0290         Quit = 7,            ///< Quit application
0291         Presentation = 8,    ///< Start presentation
0292         EndPresentation = 9, ///< End presentation
0293         Find = 10,           ///< Open find dialog
0294         GoToPage = 11,       ///< Goto page
0295         Close = 12,          ///< Close document
0296         Print = 13,          ///< Print the document @since 22.04
0297         SaveAs = 14          ///< SaveAs the document @since 22.04
0298     };
0299 
0300     /**
0301      * Creates a new document action.
0302      *
0303      * @param documentActionType The type of document action.
0304      */
0305     explicit DocumentAction(enum DocumentActionType documentActionType);
0306 
0307     /**
0308      * Destroys the document action.
0309      */
0310     ~DocumentAction() override;
0311 
0312     /**
0313      * Returns the action type.
0314      */
0315     ActionType actionType() const override;
0316 
0317     /**
0318      * Returns the action tip.
0319      */
0320     QString actionTip() const override;
0321 
0322     /**
0323      * Returns the type of action.
0324      */
0325     DocumentActionType documentActionType() const;
0326 
0327 private:
0328     Q_DECLARE_PRIVATE(DocumentAction)
0329     Q_DISABLE_COPY(DocumentAction)
0330 };
0331 
0332 /**
0333  * The Sound action plays a sound on activation.
0334  */
0335 class OKULARCORE_EXPORT SoundAction : public Action
0336 {
0337 public:
0338     /**
0339      * Creates a new sound action.
0340      *
0341      * @param volume The volume of the sound.
0342      * @param synchronous Whether the sound shall be played synchronous.
0343      * @param repeat Whether the sound shall be repeated.
0344      * @param mix Whether the sound shall be mixed.
0345      * @param sound The sound object which contains the sound data.
0346      */
0347     SoundAction(double volume, bool synchronous, bool repeat, bool mix, Okular::Sound *sound);
0348 
0349     /**
0350      * Destroys the sound action.
0351      */
0352     ~SoundAction() override;
0353 
0354     /**
0355      * Returns the action type.
0356      */
0357     ActionType actionType() const override;
0358 
0359     /**
0360      * Returns the action tip.
0361      */
0362     QString actionTip() const override;
0363 
0364     /**
0365      * Returns the volume of the sound.
0366      */
0367     double volume() const;
0368 
0369     /**
0370      * Returns whether the sound shall be played synchronous.
0371      */
0372     bool synchronous() const;
0373 
0374     /**
0375      * Returns whether the sound shall be repeated.
0376      */
0377     bool repeat() const;
0378 
0379     /**
0380      * Returns whether the sound shall be mixed.
0381      */
0382     bool mix() const;
0383 
0384     /**
0385      * Returns the sound object which contains the sound data.
0386      */
0387     Okular::Sound *sound() const;
0388 
0389 private:
0390     Q_DECLARE_PRIVATE(SoundAction)
0391     Q_DISABLE_COPY(SoundAction)
0392 };
0393 
0394 /**
0395  * The Script action executes a Script code.
0396  *
0397  * @since 0.7 (KDE 4.1)
0398  */
0399 class OKULARCORE_EXPORT ScriptAction : public Action
0400 {
0401 public:
0402     /**
0403      * Creates a new Script action.
0404      *
0405      * @param type The type of the script (for now, only JavaScript = 0 is implemented).
0406      * @param script The code to execute.
0407      */
0408     ScriptAction(enum ScriptType type, const QString &script);
0409 
0410     /**
0411      * Destroys the browse action.
0412      */
0413     ~ScriptAction() override;
0414 
0415     /**
0416      * Returns the action type.
0417      */
0418     ActionType actionType() const override;
0419 
0420     /**
0421      * Returns the action tip.
0422      */
0423     QString actionTip() const override;
0424 
0425     /**
0426      * Returns the type of action.
0427      */
0428     ScriptType scriptType() const;
0429 
0430     /**
0431      * Returns the code.
0432      */
0433     QString script() const;
0434 
0435 private:
0436     Q_DECLARE_PRIVATE(ScriptAction)
0437     Q_DISABLE_COPY(ScriptAction)
0438 };
0439 
0440 /**
0441  * The Movie action executes an operation on a video on activation.
0442  *
0443  * @since 0.15 (KDE 4.9)
0444  */
0445 class OKULARCORE_EXPORT MovieAction : public Action
0446 {
0447 public:
0448     /**
0449      * Describes the possible operation types.
0450      */
0451     enum OperationType { Play, Stop, Pause, Resume };
0452 
0453     /**
0454      * Creates a new movie action.
0455      */
0456     explicit MovieAction(OperationType operation);
0457 
0458     /**
0459      * Destroys the movie action.
0460      */
0461     ~MovieAction() override;
0462 
0463     /**
0464      * Returns the action type.
0465      */
0466     ActionType actionType() const override;
0467 
0468     /**
0469      * Returns the action tip.
0470      */
0471     QString actionTip() const override;
0472 
0473     /**
0474      * Returns the operation type.
0475      */
0476     OperationType operation() const;
0477 
0478     /**
0479      * Sets the @p annotation that is associated with the movie action.
0480      */
0481     void setAnnotation(MovieAnnotation *annotation);
0482 
0483     /**
0484      * Returns the annotation or @c 0 if no annotation has been set.
0485      */
0486     MovieAnnotation *annotation() const;
0487 
0488 private:
0489     Q_DECLARE_PRIVATE(MovieAction)
0490     Q_DISABLE_COPY(MovieAction)
0491 };
0492 
0493 /**
0494  * The Rendition action executes an operation on a video or
0495  * executes some JavaScript code on activation.
0496  *
0497  * @since 0.16 (KDE 4.10)
0498  */
0499 class OKULARCORE_EXPORT RenditionAction : public Action
0500 {
0501 public:
0502     /**
0503      * Describes the possible operation types.
0504      */
0505     enum OperationType {
0506         None,  ///< Execute only the JavaScript
0507         Play,  ///< Start playing the video
0508         Stop,  ///< Stop playing the video
0509         Pause, ///< Pause the video
0510         Resume ///< Resume playing the video
0511     };
0512 
0513     /**
0514      * Creates a new rendition action.
0515      *
0516      * @param operation The type of operation the action executes.
0517      * @param movie The movie object the action references.
0518      * @param scriptType The type of script the action executes.
0519      * @param script The actual script the action executes.
0520      */
0521     RenditionAction(OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script);
0522 
0523     /**
0524      * Destroys the rendition action.
0525      */
0526     ~RenditionAction() override;
0527 
0528     /**
0529      * Returns the action type.
0530      */
0531     ActionType actionType() const override;
0532 
0533     /**
0534      * Returns the action tip.
0535      */
0536     QString actionTip() const override;
0537 
0538     /**
0539      * Returns the operation type.
0540      */
0541     OperationType operation() const;
0542 
0543     /**
0544      * Returns the movie object or @c 0 if no movie object was set on construction time.
0545      */
0546     Okular::Movie *movie() const;
0547 
0548     /**
0549      * Returns the type of script.
0550      */
0551     ScriptType scriptType() const;
0552 
0553     /**
0554      * Returns the script code.
0555      */
0556     QString script() const;
0557 
0558     /**
0559      * Sets the @p annotation that is associated with the rendition action.
0560      */
0561     void setAnnotation(ScreenAnnotation *annotation);
0562 
0563     /**
0564      * Returns the annotation or @c 0 if no annotation has been set.
0565      */
0566     ScreenAnnotation *annotation() const;
0567 
0568 private:
0569     Q_DECLARE_PRIVATE(RenditionAction)
0570     Q_DISABLE_COPY(RenditionAction)
0571 };
0572 
0573 class OKULARCORE_EXPORT BackendOpaqueAction : public Action
0574 {
0575 public:
0576     BackendOpaqueAction();
0577 
0578     /**
0579      * Returns the action type.
0580      */
0581     ActionType actionType() const override;
0582 
0583 private:
0584     Q_DISABLE_COPY(BackendOpaqueAction)
0585 };
0586 
0587 }
0588 
0589 #endif