summaryrefslogtreecommitdiffstats
path: root/kplayer/kplayerengine.h
blob: 3a6cdf0a712f9c37ead9ba098440462417c6effb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
/***************************************************************************
                          kplayerengine.h
                          ---------------
    begin                : Tue Feb 10 2004
    copyright            : (C) 2004-2007 by kiriuja
    email                : http://kplayer.sourceforge.net/email.html
 ***************************************************************************/

/***************************************************************************
 *   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 3 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef KPLAYERENGINE_H
#define KPLAYERENGINE_H

#include <tdeaction.h>
#include <tdediroperator.h>
#include <tdefiledialog.h>

#include "kplayerprocess.h"

class KPlayerConfiguration;
class KPlayerPopupSliderAction;
class KPlayerSliderAction;
class KPlayerSettings;
class KPlayerSubtitleTrackActionList;
class KPlayerTrackActionList;
class KPlayerTrackProperties;
class KPlayerWidget;
class KPlayerWorkspace;

int listIndex (const TQStringList&, const TQString&);

/** The KPlayer file dialog.
  *@author kiriuja
  */
class KPlayerFileDialog : public KFileDialog
{
   TQ_OBJECT

public: 
  /** Constructor. Parameters are passed to the KFileDialog constructor. */
  KPlayerFileDialog (const TQString& dir, const TQString& filter, TQWidget* parent, const char* name);

  /** Returns the last used directory. */
  TQString directory (void)
    { return ops -> url().path (-1); }
};

/** The KPlayer engine.
  *@author kiriuja
  */
class KPlayerEngine : public TQObject
{
  TQ_OBJECT

public:
  KPlayerEngine (TDEActionCollection* ac, TQWidget* parent, const char* name, TDEConfig*);
  virtual ~KPlayerEngine();

  /** Returns whether the engine is running in the KPart mode. */
  bool light (void)
    { return m_light; }

  /** Returns whether playback is being stopped at user request. */
  bool stopped (void)
    { return m_stop; }

  /** Stops the player and the helper. */
  void kill (void);

  /** Starts loading of all mplayer drivers and codecs.
   * The updated signal is emitted when loading finishes. */
  void getLists (TQString = TQString::null);

  /** Starts amixer process to get the current ALSA volume. */
  void getAlsaVolume (void);

  /** Creates actions and connects signals to slots. */
  void setupActions (void);
  /** Enables or disables player actions. */
  void enablePlayerActions (void);
  /** Enables or disables video actions. */
  void enableVideoActions (void);
  /** Enables or disables subtitle actions. */
  void enableSubtitleActions (void);
  /** Enables or disables, checks or unchecks zoom actions. */
  void enableZoomActions (void);

  /** Loads the given URL and optionally starts playback. */
  void load (KURL);
  /** Autoloads subtitles as specified in the settings. */
  void autoloadSubtitles (void);
  /** Load subtitles from the given URLs if they look like subtitles and restarts playback if needed. */
  bool loadSubtitles (const KURL::List& urls, bool checkExtensions = false);

  /** Displays the open file dialog and lets the user choose a file or files.
      Returns the list of chosen URLs or an empty list if the user did not choose any. */
  KURL::List openFiles (const TQString& title, TQWidget* = 0);
  /** Displays the URL requester dialog and lets the user enter a URL.
      Returns the entered URL or an empty URL if the user did not enter any. */
  KURL::List openUrl (const TQString& title, TQWidget* = 0);
  /** Displays the open file dialog and lets the user choose a subtitle file.
      Returns the chosen URL or an empty URL if the user did not choose any. */
  KURL::List openSubtitles (TQWidget* = 0);
  /** Displays the URL requester dialog and lets the user enter a subtitle URL.
      Returns the entered URL or an empty URL if the user did not enter any. */
  //KURL openSubtitleUrl (TQWidget* = 0);

  /** Retrieves an action from the actionCollection by name. */
  TDEAction* action (const char* name) const
    { return m_ac -> action (name); }
  /** Retrieves a toggle action from the actionCollection by name. */
  TDEToggleAction* toggleAction (const char* name) const
    { return (TDEToggleAction*) action (name); }
  /** Retrieves a slider action from the actionCollection by name. */
  KPlayerSliderAction* sliderAction (const char* name) const
    { return (KPlayerSliderAction*) action (name); }
  /** Retrieves a slider action from the actionCollection by name. */
  KPlayerPopupSliderAction* popupAction (const char* name) const
    { return (KPlayerPopupSliderAction*) action (name); }

  /** Returns the video action list. */
  KPlayerTrackActionList* videoActionList (void) const
    { return m_video_action_list; }
  /** Returns the audio action list. */
  KPlayerTrackActionList* audioActionList (void) const
    { return m_audio_action_list; }
  /** Returns the subtitle action list. */
  KPlayerSubtitleTrackActionList* subtitleActionList (void) const
    { return m_subtitle_action_list; }

  /** Sets the sound volume. */
  void setVolume (void);
  /** Sets the video contrast. */
  void setContrast (void);
  /** Sets the video brightness. */
  void setBrightness (void);
  /** Sets the video hue. */
  void setHue (void);
  /** Sets the video saturation. */
  void setSaturation (void);

  /** Clear the given store section and all subsections. */
  void clearStoreSections (const TQString& section);

  /** Initializes the engine. */
  static void initialize (TDEActionCollection* ac, TQWidget* parent, const char* name = 0, TDEConfig* = 0);
  /** Terminates the engine. */
  static void terminate (void);

  /** Returns the static engine object. */
  static KPlayerEngine* engine (void)
    { return m_engine; }

  /** Returns the widget object. */
  KPlayerWidget* widget (void) const
    { return m_widget; }

  /** Returns the workspace object. */
  KPlayerWorkspace* workspace (void) const
    { return m_workspace; }

  /** Returns the process object. */
  KPlayerProcess* process (void) const
    { return m_process; }

  /** Returns the settings object. */
  KPlayerSettings* settings (void) const
    { return m_settings; }

  /** Returns the properties object. */
  KPlayerTrackProperties* properties (void) const;

  /** Returns the configuration object. */
  KPlayerConfiguration* configuration (void)
    { return m_configuration; }

  /** Returns the config object. */
  TDEConfig* config (void)
    { return m_config; }
  /** Returns the store object. */
  TDEConfig* store (void)
    { return m_store; }
  /** Returns the meta information object. */
  TDEConfig* meta (void)
    { return m_meta; }
  /** Returns the meta information storage set to the given group. */
  TDEConfig* meta (const TQString& group)
  {
    meta() -> setGroup (group);
    return meta();
  }
  /** Returns the value of the given key with the given default. */
  TQString meta (const TQString& group, const TQString& key, const TQString& value = TQString::null)
    { return meta (group) -> readEntry (key, value); }

  TDEActionCollection* actionCollection (void) const
   { return m_ac; }
  void setActionCollection (TDEActionCollection* collection)
   { m_ac = collection; }

  void setDisplaySize (bool zoom = false, bool resize = false);

  void maintainAspect (bool maintain, TQSize aspect);
  void refreshAspect (void);

  /** Resets full screen and maximized states. */
  void normal (void);
  /** Zoom to the given factor. */
  void zoomTo (int m, int d = 1);
  /** Zoom or seek on mouse wheel event. */
  void wheel (int delta, int state);
  /** Toggle full screen on double click. */
  void doubleClick (void);

  /** Emits windowStateChanged signal. */
  void emitWindowStateChanged (uint wid);

  /** Disables screen saver if it is enabled. */
  void disableScreenSaver (void);
  /** Enables screen saver if it was disabled. */
  void enableScreenSaver (void);

  int demuxerCount (void) const
    { return m_demuxers.count(); }
  const TQString& demuxerName (int index) const
    { return m_demuxers [index]; }
  int demuxerIndex (const TQString& codec) const
    { return listIndex (m_demuxers, codec); }

  int audioCodecCount (void) const
    { return m_audio_codecs.count(); }
  const TQString& audioCodecName (int index) const
    { return m_audio_codecs[index]; }
  int audioCodecIndex (const TQString& codec) const
    { return listIndex (m_audio_codecs, codec); }

  int audioDriverCount (void) const
    { return m_audio_drivers.count(); }
  const TQString& audioDriverName (int index) const
    { return m_audio_drivers[index]; }
  int audioDriverIndex (const TQString& driver) const
    { return listIndex (m_audio_drivers, driver); }

  int videoCodecCount (void) const
    { return m_video_codecs.count(); }
  const TQString& videoCodecName (int index) const
    { return m_video_codecs[index]; }
  int videoCodecIndex (const TQString& codec) const
    { return listIndex (m_video_codecs, codec); }

  int videoDriverCount (void) const
    { return m_video_drivers.count(); }
  const TQString& videoDriverName (int index) const
    { return m_video_drivers[index]; }
  int videoDriverIndex (const TQString& driver) const
    { return listIndex (m_video_drivers, driver); }

public slots:
  /** Handles workspace resized event. */
  void workspaceResized (void);
  /** Handles workspace user resize event. */
  void workspaceUserResize (void);
  /** Receives the updated signal from KPlayerSettings. Updates the settings. */
  void refreshSettings (void);
  /** Receives the updated signal from KPlayerProperties. Updates the settings. */
  void refreshProperties (void);

  /** Receives the stateChanged signal from KPlayerProcess. */
  void playerStateChanged (KPlayerProcess::State, KPlayerProcess::State);
  /** Receives the progressChanged signal from KPlayerProcess. */
  void playerProgressChanged (float, KPlayerProcess::ProgressType);
  /** Receives the infoAvailable signal from KPlayerProcess. */
  void playerInfoAvailable (void);
  /** Receives the sizeAvailable signal from KPlayerProcess. */
  void playerSizeAvailable (void);

  /** Displays the Open Subtitle File dialog and loads the chosen subtitles.
      Restarts playback if a file was playing. */
  void fileOpenSubtitles (void);
  /** Displays the Open Subtitle URL dialog and loads the chosen subtitles.
      Restarts playback if a file was playing. */
  //void fileOpenSubtitleUrl (void);
  /** Unloads subtitles and prevents subtitle autoloading.
      Restarts playback if a file was playing. */
  //void fileUnloadSubtitles (void);
  /** Opens File Properties dialog. */
  void fileProperties (void);

  /** Toggles full screen mode. */
  void fullScreen (void);
  /** Scales video up. */
  void zoomIn (void);
  /** Scales video down. */
  void zoomOut (void);
  /** Scales video to 50%. */
  void zoom12 (void);
  /** Scales video to 100%. */
  void zoom11 (void);
  /** Scales video to 150%. */
  void zoom32 (void);
  /** Scales video to 200%. */
  void zoom21 (void);
  /** Scales video to 250%. */
  void zoom52 (void);
  /** Scales video to 300%. */
  void zoom31 (void);
  /** Toggles the option of maintaining the video aspect ratio. */
  void maintainAspect (void);
  /** Toggles the option of maintaining the original video aspect ratio. */
  void maintainOriginalAspect (void);
  /** Toggles the option of maintaining the current video aspect ratio. */
  void maintainCurrentAspect (void);
  /** Forces 4 to 3 video aspect ratio. */
  void aspect43 (void);
  /** Forces 16 to 9 video aspect ratio. */
  void aspect169 (void);

  /** Plays the currently loaded file. */
  void play (void);
  /** Pauses the player. */
  void pause (void);
  /** Stops the player. */
  void stop (void);

  /** Seeks forward. */
  void forward (void);
  /** Seeks forward fast. */
  void fastForward (void);
  /** Seeks backward. */
  void backward (void);
  /** Seeks backward fast. */
  void fastBackward (void);
  /** Seeks to the beginning. */
  void start (void);

  /** Increases the volume. */
  void volumeIncrease (void);
  /** Decreases the volume. */
  void volumeDecrease (void);
  /** Toggles audio playback. */
  void mute (void);
  /** Increases the audio delay. */
  void audioDelayIncrease (void);
  /** Decreases the audio delay. */
  void audioDelayDecrease (void);
  /** Sets the audio stream. */
  void audioStream (int index);

  /** Toggle the soft frame dropping option. */
  void softFrameDrop (void);
  /** Toggle the hard frame dropping option. */
  void hardFrameDrop (void);

  /** Moves subtitles down. */
  void subtitlesMoveDown (void);
  /** Moves subtitles up. */
  void subtitlesMoveUp (void);
  /** Decreases subtitle delay. */
  void subtitlesDelayDecrease (void);
  /** Increases subtitle delay. */
  void subtitlesDelayIncrease (void);
  /** Sets the subtitle stream. */
  void subtitleStream (int index);

  /** Increases the video brightness. */
  void brightnessIncrease (void);
  /** Decreases the video brightness. */
  void brightnessDecrease (void);
  /** Increases the video contrast. */
  void contrastIncrease (void);
  /** Decreases the video contrast. */
  void contrastDecrease (void);
  /** Increases the video hue. */
  void hueIncrease (void);
  /** Decreases the video hue. */
  void hueDecrease (void);
  /** Increases the video saturation. */
  void saturationIncrease (void);
  /** Decreases the video saturation. */
  void saturationDecrease (void);
  /** Sets the video stream. */
  void videoStream (int index);

  /** Moves to the position chosen. */
  void progressChanged (int);
  /** Changes the volume level. */
  void volumeChanged (int);
  /** Changes the video brightness. */
  void brightnessChanged (int);
  /** Changes the video contrast. */
  void contrastChanged (int);
  /** Changes the video hue. */
  void hueChanged (int);
  /** Changes the video saturation. */
  void saturationChanged (int);

protected:
  /** Handles workspace resize based on the user flag. */
  void workspaceResize (bool user);
  /** Runs amixer with the given command and parameter. */
  void runAmixer (const TQString& command, const TQString& parameter = TQString::null);

  /** Sets up the progress slider. */
  void setupProgressSlider (int maximum);
  /** Tells the process to start playback. */
  void startPlaying (void);
  /** Shows the selected subtitles. */
  void showSubtitles (void);
  /** Autoexpands video and updates settings. */
  void autoexpand (void);

  TQString m_path;

  /** Video track action list. */
  KPlayerTrackActionList* m_video_action_list;
  /** Audio track action list. */
  KPlayerTrackActionList* m_audio_action_list;
  /** Subtitle track action list. */
  KPlayerSubtitleTrackActionList* m_subtitle_action_list;

  bool m_audio_codecs_ready;
  bool m_audio_drivers_ready;
  bool m_video_codecs_ready;
  bool m_video_drivers_ready;
  bool m_demuxers_ready;

  /** List of available audio codecs. */
  TQStringList m_audio_codecs;
  /** List of available audio drivers. */
  TQStringList m_audio_drivers;
  /** List of available video codecs. */
  TQStringList m_video_codecs;
  /** List of available video drivers. */
  TQStringList m_video_drivers;
  /** List of available demuxers. */
  TQStringList m_demuxers;

  bool m_amixer_running, m_amixer_found_control;
  int m_last_volume, m_amixer_volume, m_amixer_volume_first, m_amixer_volume_second;

  /** The static engine object. */
  static KPlayerEngine* m_engine;
  /** Main config. */
  TDEConfig* m_config;
  /** Store config. */
  TDEConfig* m_store;
  /** Meta config. */
  TDEConfig* m_meta;
  /** Configuration properties. */
  KPlayerConfiguration* m_configuration;
  /** The settings object. */
  KPlayerSettings* m_settings;
  /** The process object. */
  KPlayerProcess* m_process;
  /** The widget object. */
  KPlayerWidget* m_widget;
  /** The workspace object. */
  KPlayerWorkspace* m_workspace;
  /** The action collection object. */
  TDEActionCollection* m_ac;

  // Following should be private
  /** Indicates what actions should be used. */
  bool m_light;
  /** Indicates whether screen saver needs to be reenabled. */
  bool m_enable_screen_saver;
  /** Recursion prevention. */
  bool m_updating;
  /** Recursion prevention. */
  bool m_zooming;
  /** Work around TQRangeControl bug. */
  int m_progress_factor;
  /** Do not play any more URLs. */
  bool m_stop;
  /** Start playing when size is known. */
  bool m_play_pending;

signals:
  /** Emitted when a window state changes. */
  void windowStateChanged (uint wid);
  /** Emitted to let the main window syncronize full screen and maximized settings. */
  void syncronize (bool);
  /** Emitted when display size changes. */
  void zoom (void);
  /** Emitted when the workspace size needs adjustment. */
  void correctSize (void);
  /** Emitted when the original display size of a file becomes known. */
  void initialSize (void);
  /** Emitted when all drivers and codecs have been loaded. */
  void updated (void);

protected slots:
  /** Processes an MPlayer output line. */
  void receivedOutput (KPlayerLineOutputProcess*, char*, int);
  /** Finishes refreshing lists. */
  void processExited (TDEProcess*);

  /** Processes an amixer output line. */
  void amixerOutput (KPlayerLineOutputProcess*, char*, int);
  /** Finishes refreshing ALSA volume. */
  void amixerExited (TDEProcess*);
};

inline KPlayerEngine* kPlayerEngine (void)
{
  return KPlayerEngine::engine();
}

inline KPlayerProcess* kPlayerProcess (void)
{
  return kPlayerEngine() -> process();
}

inline TDEConfig* kPlayerConfig (void)
{
  return kPlayerEngine() -> config();
}

inline KPlayerSettings* kPlayerSettings (void)
{
  return kPlayerEngine() -> settings();
}

inline KPlayerWidget* kPlayerWidget (void)
{
  return kPlayerEngine() -> widget();
}

inline KPlayerWorkspace* kPlayerWorkspace (void)
{
  return kPlayerEngine() -> workspace();
}

#endif