Okular

action.cpp
1 /*
2  SPDX-FileCopyrightText: 2004-2005 Enrico Ros <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "action.h"
8 
9 // kde includes
10 #include <KLocalizedString>
11 
12 // local includes
13 #include "document.h"
14 #include "movie.h"
15 #include "sound.h"
16 #include "sourcereference_p.h"
17 
18 using namespace Okular;
19 
20 class Okular::ActionPrivate
21 {
22 public:
23  ActionPrivate()
24  {
25  }
26 
27  virtual ~ActionPrivate()
28  {
29  qDeleteAll(m_nextActions);
30  }
31 
32  ActionPrivate(const ActionPrivate &) = delete;
33  ActionPrivate &operator=(const ActionPrivate &) = delete;
34 
35  QVariant m_nativeId;
36  QVector<Action *> m_nextActions;
37 };
38 
39 Action::Action(ActionPrivate &dd)
40  : d_ptr(&dd)
41 {
42 }
43 
44 Action::~Action()
45 {
46  delete d_ptr;
47 }
48 
50 {
51  return QLatin1String("");
52 }
53 
55 {
56  Q_D(Action);
57  d->m_nativeId = id;
58 }
59 
61 {
62  Q_D(const Action);
63  return d->m_nativeId;
64 }
65 
67 {
68  Q_D(const Action);
69  return d->m_nextActions;
70 }
71 
73 {
74  Q_D(Action);
75  qDeleteAll(d->m_nextActions);
76  d->m_nextActions = actions;
77 }
78 
79 // GotoAction
80 
81 class Okular::GotoActionPrivate : public Okular::ActionPrivate
82 {
83 public:
84  GotoActionPrivate(const QString &fileName, const DocumentViewport &viewport)
85  : ActionPrivate()
86  , m_extFileName(fileName)
87  , m_vp(viewport)
88  {
89  }
90 
91  GotoActionPrivate(const QString &fileName, const QString &namedDestination)
92  : ActionPrivate()
93  , m_extFileName(fileName)
94  , m_dest(namedDestination)
95  {
96  }
97 
98  QString m_extFileName;
99  DocumentViewport m_vp;
100  QString m_dest;
101 };
102 
103 GotoAction::GotoAction(const QString &fileName, const DocumentViewport &viewport)
104  : Action(*new GotoActionPrivate(fileName, viewport))
105 {
106 }
107 
108 GotoAction::GotoAction(const QString &fileName, const QString &namedDestination)
109  : Action(*new GotoActionPrivate(fileName, namedDestination))
110 {
111 }
112 
114 {
115 }
116 
118 {
119  return Goto;
120 }
121 
123 {
124  Q_D(const GotoAction);
125  return d->m_extFileName.isEmpty() ? (d->m_vp.isValid() ? i18n("Go to page %1", d->m_vp.pageNumber + 1) : QLatin1String("")) : i18n("Open external file");
126 }
127 
129 {
130  Q_D(const GotoAction);
131  return !d->m_extFileName.isEmpty();
132 }
133 
135 {
136  Q_D(const GotoAction);
137  return d->m_extFileName;
138 }
139 
141 {
142  Q_D(const GotoAction);
143  return d->m_vp;
144 }
145 
147 {
148  Q_D(const GotoAction);
149  return d->m_dest;
150 }
151 
152 // ExecuteAction
153 
154 class Okular::ExecuteActionPrivate : public Okular::ActionPrivate
155 {
156 public:
157  ExecuteActionPrivate(const QString &file, const QString &parameters)
158  : ActionPrivate()
159  , m_fileName(file)
160  , m_parameters(parameters)
161  {
162  }
163 
164  QString m_fileName;
165  QString m_parameters;
166 };
167 
168 ExecuteAction::ExecuteAction(const QString &file, const QString &parameters)
169  : Action(*new ExecuteActionPrivate(file, parameters))
170 {
171 }
172 
174 {
175 }
176 
178 {
179  return Execute;
180 }
181 
183 {
184  Q_D(const Okular::ExecuteAction);
185  return i18n("Execute '%1'...", d->m_fileName);
186 }
187 
189 {
190  Q_D(const Okular::ExecuteAction);
191  return d->m_fileName;
192 }
193 
195 {
196  Q_D(const Okular::ExecuteAction);
197  return d->m_parameters;
198 }
199 
200 // BrowseAction
201 
202 class Okular::BrowseActionPrivate : public Okular::ActionPrivate
203 {
204 public:
205  explicit BrowseActionPrivate(const QUrl &url)
206  : ActionPrivate()
207  , m_url(url)
208  {
209  }
210 
211  QUrl m_url;
212 };
213 
215  : Action(*new BrowseActionPrivate(url))
216 {
217 }
218 
220 {
221 }
222 
224 {
225  return Browse;
226 }
227 
229 {
230  Q_D(const Okular::BrowseAction);
231  QString source;
232  int row = 0, col = 0;
233  if (extractLilyPondSourceReference(d->m_url, &source, &row, &col)) {
234  return sourceReferenceToolTip(source, row, col);
235  }
236  return d->m_url.toDisplayString();
237 }
238 
240 {
241  Q_D(const Okular::BrowseAction);
242  return d->m_url;
243 }
244 
245 // DocumentAction
246 
247 class Okular::DocumentActionPrivate : public Okular::ActionPrivate
248 {
249 public:
250  explicit DocumentActionPrivate(enum DocumentAction::DocumentActionType documentActionType)
251  : ActionPrivate()
252  , m_type(documentActionType)
253  {
254  }
255 
257 };
258 
260  : Action(*new DocumentActionPrivate(documentActionType))
261 {
262 }
263 
265 {
266 }
267 
269 {
270  Q_D(const Okular::DocumentAction);
271  return d->m_type;
272 }
273 
275 {
276  return DocAction;
277 }
278 
280 {
281  Q_D(const Okular::DocumentAction);
282  switch (d->m_type) {
283  case PageFirst:
284  return i18n("First Page");
285  case PagePrev:
286  return i18n("Previous Page");
287  case PageNext:
288  return i18n("Next Page");
289  case PageLast:
290  return i18n("Last Page");
291  case HistoryBack:
292  return i18n("Back");
293  case HistoryForward:
294  return i18n("Forward");
295  case Quit:
296  return i18n("Quit");
297  case Presentation:
298  return i18n("Start Presentation");
299  case EndPresentation:
300  return i18n("End Presentation");
301  case Find:
302  return i18n("Find...");
303  case GoToPage:
304  return i18n("Go To Page...");
305  case Close:
306  default:;
307  }
308 
309  return QString();
310 }
311 
312 // SoundAction
313 
314 class Okular::SoundActionPrivate : public Okular::ActionPrivate
315 {
316 public:
317  SoundActionPrivate(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
318  : ActionPrivate()
319  , m_volume(volume)
320  , m_sync(sync)
321  , m_repeat(repeat)
322  , m_mix(mix)
323  , m_sound(sound)
324  {
325  }
326 
327  ~SoundActionPrivate() override
328  {
329  delete m_sound;
330  }
331 
332  double m_volume;
333  bool m_sync : 1;
334  bool m_repeat : 1;
335  bool m_mix : 1;
336  Okular::Sound *m_sound;
337 };
338 
339 SoundAction::SoundAction(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
340  : Action(*new SoundActionPrivate(volume, sync, repeat, mix, sound))
341 {
342 }
343 
345 {
346 }
347 
349 {
350  return Sound;
351 }
352 
354 {
355  return i18n("Play sound...");
356 }
357 
358 double SoundAction::volume() const
359 {
360  Q_D(const Okular::SoundAction);
361  return d->m_volume;
362 }
363 
365 {
366  Q_D(const Okular::SoundAction);
367  return d->m_sync;
368 }
369 
371 {
372  Q_D(const Okular::SoundAction);
373  return d->m_repeat;
374 }
375 
376 bool SoundAction::mix() const
377 {
378  Q_D(const Okular::SoundAction);
379  return d->m_mix;
380 }
381 
383 {
384  Q_D(const Okular::SoundAction);
385  return d->m_sound;
386 }
387 
388 // ScriptAction
389 
390 class Okular::ScriptActionPrivate : public Okular::ActionPrivate
391 {
392 public:
393  ScriptActionPrivate(enum ScriptType type, const QString &script)
394  : ActionPrivate()
395  , m_scriptType(type)
396  , m_script(script)
397  {
398  }
399 
400  ScriptType m_scriptType;
401  QString m_script;
402 };
403 
405  : Action(*new ScriptActionPrivate(type, script))
406 {
407 }
408 
410 {
411 }
412 
414 {
415  return Script;
416 }
417 
419 {
420  Q_D(const Okular::ScriptAction);
421  switch (d->m_scriptType) {
422  case JavaScript:
423  return i18n("JavaScript Script");
424  }
425 
426  return QString();
427 }
428 
430 {
431  Q_D(const Okular::ScriptAction);
432  return d->m_scriptType;
433 }
434 
436 {
437  Q_D(const Okular::ScriptAction);
438  return d->m_script;
439 }
440 
441 // MovieAction
442 
443 class Okular::MovieActionPrivate : public Okular::ActionPrivate
444 {
445 public:
446  explicit MovieActionPrivate(MovieAction::OperationType operation)
447  : ActionPrivate()
448  , m_operation(operation)
449  , m_annotation(nullptr)
450  {
451  }
452 
453  MovieAction::OperationType m_operation;
454  MovieAnnotation *m_annotation;
455 };
456 
458  : Action(*new MovieActionPrivate(operation))
459 {
460 }
461 
463 {
464 }
465 
467 {
468  return Movie;
469 }
470 
472 {
473  return i18n("Play movie...");
474 }
475 
477 {
478  Q_D(const Okular::MovieAction);
479  return d->m_operation;
480 }
481 
483 {
484  Q_D(Okular::MovieAction);
485  d->m_annotation = annotation;
486 }
487 
489 {
490  Q_D(const Okular::MovieAction);
491  return d->m_annotation;
492 }
493 
494 // RenditionAction
495 
496 class Okular::RenditionActionPrivate : public Okular::ActionPrivate
497 {
498 public:
499  RenditionActionPrivate(RenditionAction::OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
500  : ActionPrivate()
501  , m_operation(operation)
502  , m_movie(movie)
503  , m_scriptType(scriptType)
504  , m_script(script)
505  , m_annotation(nullptr)
506  {
507  }
508 
509  RenditionAction::OperationType m_operation;
510  Okular::Movie *m_movie;
511  ScriptType m_scriptType;
512  QString m_script;
513  ScreenAnnotation *m_annotation;
514 };
515 
517  : Action(*new RenditionActionPrivate(operation, movie, scriptType, script))
518 {
519 }
520 
522 {
523 }
524 
526 {
527  return Rendition;
528 }
529 
531 {
532  Q_D(const Okular::RenditionAction);
533 
534  switch (d->m_operation) {
535  default:
536  case None:
537  switch (d->m_scriptType) {
538  case JavaScript:
539  return i18n("JavaScript Script");
540  default:
541  return QString();
542  }
543  case Play:
544  return i18n("Play movie");
545  case Stop:
546  return i18n("Stop movie");
547  case Pause:
548  return i18n("Pause movie");
549  case Resume:
550  return i18n("Resume movie");
551  }
552 }
553 
555 {
556  Q_D(const Okular::RenditionAction);
557  return d->m_operation;
558 }
559 
561 {
562  Q_D(const Okular::RenditionAction);
563  return d->m_movie;
564 }
565 
567 {
568  Q_D(const Okular::RenditionAction);
569  return d->m_scriptType;
570 }
571 
573 {
574  Q_D(const Okular::RenditionAction);
575  return d->m_script;
576 }
577 
579 {
581  d->m_annotation = annotation;
582 }
583 
585 {
586  Q_D(const Okular::RenditionAction);
587  return d->m_annotation;
588 }
589 
590 BackendOpaqueAction::BackendOpaqueAction()
591  : Action(*new ActionPrivate())
592 {
593 }
594 
595 Action::ActionType BackendOpaqueAction::actionType() const
596 {
597  return BackendOpaque;
598 }
Start a custom action.
Definition: action.h:50
BrowseAction(const QUrl &url)
Creates a new browse action.
Definition: action.cpp:214
SoundAction(double volume, bool synchronous, bool repeat, bool mix, Okular::Sound *sound)
Creates a new sound action.
Definition: action.cpp:339
Jump to previous page.
Definition: action.h:287
OperationType operation() const
Returns the operation type.
Definition: action.cpp:476
Jump to last page.
Definition: action.h:289
MovieAnnotation * annotation() const
Returns the annotation or 0 if no annotation has been set.
Definition: action.cpp:488
double volume() const
Returns the volume of the sound.
Definition: action.cpp:358
Close document.
Definition: action.h:297
OperationType operation() const
Returns the operation type.
Definition: action.cpp:554
QVector< Action * > nextActions() const
Returns the next actions to be executed after.
Definition: action.cpp:66
Open find dialog.
Definition: action.h:295
Pause the video.
Definition: action.h:509
Execute only the JavaScript.
Definition: action.h:506
~MovieAction() override
Destroys the movie action.
Definition: action.cpp:462
RenditionAction(OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
Creates a new rendition action.
Definition: action.cpp:516
QVariant nativeId() const
Returns the "native" id of the action.
Definition: action.cpp:60
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:228
OperationType
Describes the possible operation types.
Definition: action.h:451
The Script action executes a Script code.
Definition: action.h:399
QString script() const
Returns the code.
Definition: action.cpp:435
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:177
global.h
Definition: action.h:16
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:348
bool mix() const
Returns whether the sound shall be mixed.
Definition: action.cpp:376
The Execute action executes an external application.
Definition: action.h:193
JavaScript code.
Definition: global.h:75
MovieAction(OperationType operation)
Creates a new movie action.
Definition: action.cpp:457
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:418
DocumentAction(enum DocumentActionType documentActionType)
Creates a new document action.
Definition: action.cpp:259
The Movie action executes an operation on a video on activation.
Definition: action.h:445
Go forward in page history.
Definition: action.h:291
QString fileName() const
Returns the filename of the external document.
Definition: action.cpp:134
~RenditionAction() override
Destroys the rendition action.
Definition: action.cpp:521
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:279
bool isExternal() const
Returns whether the goto action points to an external document.
Definition: action.cpp:128
~GotoAction() override
Destroys the goto action.
Definition: action.cpp:113
PartitionTable::TableType type
QString script() const
Returns the script code.
Definition: action.cpp:572
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:530
Jump to next page.
Definition: action.h:288
void setNextActions(const QVector< Action * > &actions)
Sets the next actions.
Definition: action.cpp:72
Okular::Movie * movie() const
Returns the movie object or 0 if no movie object was set on construction time.
Definition: action.cpp:560
~ScriptAction() override
Destroys the browse action.
Definition: action.cpp:409
ScriptType
Describes the possible script types.
Definition: global.h:74
The Goto action changes the viewport to another page or loads an external document.
Definition: action.h:127
DocumentViewport destViewport() const
Returns the document viewport the goto action points to.
Definition: action.cpp:140
~SoundAction() override
Destroys the sound action.
Definition: action.cpp:344
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:182
Contains information about a sound object.
Definition: sound.h:23
Goto a given page or external document.
Definition: action.h:47
void setAnnotation(ScreenAnnotation *annotation)
Sets the annotation that is associated with the rendition action.
Definition: action.cpp:578
ExecuteAction(const QString &fileName, const QString &parameters)
Creates a new execute action.
Definition: action.cpp:168
bool repeat() const
Returns whether the sound shall be repeated.
Definition: action.cpp:370
QString destinationName() const
Returns the document named destination the goto action points to.
Definition: action.cpp:146
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:274
virtual QString actionTip() const
Returns a i18n&#39;ed tip of the action that is presented to the user.
Definition: action.cpp:49
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:353
ScriptType scriptType() const
Returns the type of script.
Definition: action.cpp:566
OperationType
Describes the possible operation types.
Definition: action.h:505
ScriptAction(enum ScriptType type, const QString &script)
Creates a new Script action.
Definition: action.cpp:404
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:466
ScreenAnnotation * annotation() const
Returns the annotation or 0 if no annotation has been set.
Definition: action.cpp:584
Encapsulates data that describes an action.
Definition: action.h:40
QString i18n(const char *text, const TYPE &arg...)
DocumentActionType
Describes the possible action types.
Definition: action.h:285
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:525
~DocumentAction() override
Destroys the document action.
Definition: action.cpp:264
Play a movie.
Definition: action.h:52
Movie annotation.
Definition: annotations.h:1541
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:122
Calls back to the backend with the action.
Definition: action.h:55
Executes a Script code.
Definition: action.h:53
Play a movie and/or execute a Script code.
Definition: action.h:54
ScriptType scriptType() const
Returns the type of action.
Definition: action.cpp:429
Jump to first page.
Definition: action.h:286
void setNativeId(const QVariant &id)
Sets the "native" id of the action.
Definition: action.cpp:54
QString parameters() const
Returns the parameters of the application to execute.
Definition: action.cpp:194
Okular::Sound * sound() const
Returns the sound object which contains the sound data.
Definition: action.cpp:382
Quit application.
Definition: action.h:292
The Browse action browses an url by opening a web browser or email client, depending on the url proto...
Definition: action.h:238
The DocumentAction action contains an action that is performed on the current document.
Definition: action.h:277
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:117
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:413
Start playing the video.
Definition: action.h:507
QString actionTip() const override
Returns the action tip.
Definition: action.cpp:471
GotoAction(const QString &fileName, const DocumentViewport &viewport)
Creates a new goto action.
Definition: action.cpp:103
QString fileName() const
Returns the file name of the application to execute.
Definition: action.cpp:188
~BrowseAction() override
Destroys the browse action.
Definition: action.cpp:219
ActionType
Describes the type of action.
Definition: action.h:46
Resume playing the video.
Definition: action.h:510
A view on the document.
Definition: document.h:1301
The Rendition action executes an operation on a video or executes some JavaScript code on activation...
Definition: action.h:499
Browse a given website.
Definition: action.h:49
Go back in page history.
Definition: action.h:290
void setAnnotation(MovieAnnotation *annotation)
Sets the annotation that is associated with the movie action.
Definition: action.cpp:482
Stop playing the video.
Definition: action.h:508
Screen annotation.
Definition: annotations.h:1587
Play a sound.
Definition: action.h:51
~ExecuteAction() override
Destroys the execute action.
Definition: action.cpp:173
DocumentActionType documentActionType() const
Returns the type of action.
Definition: action.cpp:268
bool synchronous() const
Returns whether the sound shall be played synchronous.
Definition: action.cpp:364
The Sound action plays a sound on activation.
Definition: action.h:335
Execute a command or external application.
Definition: action.h:48
Contains information about a movie object.
Definition: movie.h:25
QUrl url() const
Returns the url to browse.
Definition: action.cpp:239
ActionType actionType() const override
Returns the action type.
Definition: action.cpp:223
Start presentation.
Definition: action.h:293
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:32:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.