KPlayer – multimedia player with mplayer backend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2354 lines
89KB

  1. /***************************************************************************
  2. kplayerengine.cpp
  3. -----------------
  4. begin : Tue Feb 10 2004
  5. copyright : (C) 2004-2007 by kiriuja
  6. email : http://kplayer.sourceforge.net/email.html
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation, either version 3 of the License, or *
  12. * (at your option) any later version. *
  13. ***************************************************************************/
  14. #include <dcopclient.h>
  15. #include <tdeapplication.h>
  16. #include <tdeconfig.h>
  17. #include <tdelocale.h>
  18. #include <tdemainwindow.h>
  19. #include <tderecentdocument.h>
  20. #include <kurlrequester.h>
  21. #include <kurlrequesterdlg.h>
  22. #include <tqdatetime.h>
  23. #include <tqpopupmenu.h>
  24. #include <tqregexp.h>
  25. #ifdef DEBUG
  26. #define DEBUG_KPLAYER_ENGINE
  27. #endif
  28. #include "kplayerengine.h"
  29. #include "kplayerengine.moc"
  30. #include "kplayeractionlist.h"
  31. #include "kplayerpropertiesdialog.h"
  32. #include "kplayersettings.h"
  33. #include "kplayerslideraction.h"
  34. #include "kplayerwidget.h"
  35. KPlayerEngine* KPlayerEngine::m_engine = 0;
  36. static TQRegExp re_extension ("\\.[^/.]+$");
  37. static TQRegExp re_driver ("^\\s+([A-Za-z0-9]+)\\s+(\\S.*)");
  38. static TQRegExp re_codec ("^([A-Za-z0-9]+)\\s+\\S+\\s+\\S+\\s+(\\S.*)");
  39. static TQRegExp re_demuxer ("^\\s*([A-Za-z0-9]+)\\s+\\d+\\s+(\\S.*)");
  40. static TQRegExp re_multiple ("\\s+"), re_trailing (" $");
  41. static TQRegExp re_brackets (" ?\\[.*\\]"), re_parentheses (" ?\\((?:..+|\\?)\\)");
  42. static TQRegExp re_audio ("[- ](?:audio[- ])?(?:decoder|codec|output|out)s?", false);
  43. static TQRegExp re_video ("[- ](?:video[- ])?(?:decoder|codec|output|out)s?", false);
  44. static TQRegExp re_s ("'s", false), re_layer ("layer-", false);
  45. static TQRegExp re_dash (" - ", false);
  46. static TQRegExp re_writer (" writer", false);
  47. static TQRegExp re_demux (" demuxer", false);
  48. static TQRegExp re_sega (" for Sega Saturn CD-ROM games", false);
  49. static TQRegExp re_smjpeg ("smjpeg", false);
  50. static TQRegExp re_tv_card ("Tv card", false);
  51. static TQRegExp re_lmlm (" Compression Card stream", false);
  52. static TQRegExp re_xv ("/XV$", false), re_vidix (" \\(VIDIX\\)", false);
  53. static TQRegExp re_xover ("General X11 driver for overlay capable video output drivers", false);
  54. static TQRegExp re_opengl ("\\(OpenGL\\)", false);
  55. static TQRegExp re_matrox ("Matrox .* overlay in", false);
  56. static TQRegExp re_matroxg (" G200/G400/G450/G550", false);
  57. static TQRegExp re_macintosh ("Macintosh Audio Compression and Expansion", false);
  58. static TQRegExp re_amu ("Avid Meridien Uncompressed", false);
  59. static TQRegExp re_speech ("Windows Media Audio 9 Speech", false);
  60. void KPlayerWindowStateChanged (uint wid)
  61. {
  62. if ( kPlayerEngine() )
  63. kPlayerEngine() -> emitWindowStateChanged (wid);
  64. }
  65. int listIndex (const TQStringList& sl, const TQString& str)
  66. {
  67. TQString entry, stru (str.upper()), strusc (stru + ":");
  68. int index = 0;
  69. for ( TQStringList::ConstIterator sli = sl.begin(); sli != sl.end(); ++ sli )
  70. {
  71. entry = (*sli).upper();
  72. if ( entry == stru || entry.startsWith (strusc) )
  73. return index;
  74. index ++;
  75. }
  76. return -1;
  77. }
  78. KPlayerFileDialog::KPlayerFileDialog (const TQString& dir, const TQString& filter, TQWidget* parent, const char* name)
  79. : KFileDialog (dir, filter, parent ? parent : kPlayerWidget(), name, true)
  80. {
  81. ops -> clearHistory();
  82. }
  83. KPlayerEngine::KPlayerEngine (TDEActionCollection* ac, TQWidget* parent, const char* name, TDEConfig* config)
  84. {
  85. #ifdef DEBUG_KPLAYER_ENGINE
  86. kdDebugTime() << "Creating engine\n";
  87. #endif
  88. m_engine = this;
  89. m_ac = ac;
  90. m_light = config == 0;
  91. m_progress_factor = 0;
  92. m_stop = m_updating = m_zooming = m_play_pending = m_enable_screen_saver = m_amixer_running = false;
  93. m_config = light() ? new TDEConfig ("kplayerrc") : config;
  94. m_store = new TDEConfig ("kplayerlibraryrc");
  95. m_meta = new TDEConfig ("kplayerplaylistrc");
  96. m_configuration = new KPlayerConfiguration;
  97. configuration() -> setup();
  98. m_settings = new KPlayerSettings;
  99. m_process = new KPlayerProcess;
  100. m_workspace = new KPlayerWorkspace (parent, name);
  101. m_widget = workspace() -> widget();
  102. connect (workspace(), SIGNAL (resized()), this, SLOT (workspaceResized()));
  103. connect (workspace(), SIGNAL (userResize()), this, SLOT (workspaceUserResize()));
  104. connect (process(), SIGNAL (stateChanged(KPlayerProcess::State, KPlayerProcess::State)), this, SLOT (playerStateChanged(KPlayerProcess::State, KPlayerProcess::State)));
  105. connect (process(), SIGNAL (progressChanged(float, KPlayerProcess::ProgressType)), this, SLOT (playerProgressChanged(float, KPlayerProcess::ProgressType)));
  106. connect (process(), SIGNAL (infoAvailable()), this, SLOT (playerInfoAvailable()));
  107. connect (process(), SIGNAL (sizeAvailable()), this, SLOT (playerSizeAvailable()));
  108. connect (configuration(), SIGNAL (updated()), this, SLOT (refreshSettings()));
  109. setupActions();
  110. m_audio_drivers
  111. << "mpegpes: DVB"
  112. << "oss: OSS/ioctl"
  113. << "alsa: ALSA"
  114. << "arts: aRts"
  115. << "esd: EsounD"
  116. << "nas: NAS"
  117. << "sdl: SDLlib"
  118. << "null: Null"
  119. << "pcm: RAW PCM/WAVE file"
  120. << "plugin: Plugin";
  121. m_audio_codecs
  122. << "wma9dmo: Windows Media Audio 9 DMO"
  123. << "wmadmo: Windows Media Audio DMO"
  124. << "qdmc: Quicktime TQDMC/TQDM2"
  125. << "qclp: Quicktime TQCLP"
  126. << "qtmace3: Quicktime MACE3"
  127. << "qtmace6: Quicktime MACE6"
  128. << "racook: RealAudio COOK"
  129. << "rasipr: RealAudio Sipro"
  130. << "raatrc: RealAudio ATRAC3"
  131. << "imaadpcm: IMA ADPCM"
  132. << "msadpcm: MS ADPCM"
  133. << "dk4adpcm: Duck DK4 ADPCM"
  134. << "dk3adpcm: Duck DK3 ADPCM"
  135. << "roqaudio: Id RoQ File"
  136. << "libdv: raw DV"
  137. << "ffdv: FFmpeg DV"
  138. << "faad: AAC MPEG2/MPEG4 Audio"
  139. << "pcm: Uncompressed PCM"
  140. << "divx: DivX audio"
  141. << "msadpcmacm: MS ADPCM"
  142. << "mp3: mp3lib MPEG layer 2, layer 3"
  143. << "ffwmav1: DivX audio v1"
  144. << "ffwmav2: DivX audio v2"
  145. << "ffmac3: Macintosh Audio Comp. and Exp. 3:1"
  146. << "ffmac6: Macintosh Audio Comp. and Exp. 6:1"
  147. << "ffmp3: FFmpeg layer 3"
  148. << "ffmp2: FFmpeg layer 1,2"
  149. << "mad: libMAD MPEG layer 1-2-3"
  150. << "mp3acm: MPEG layer 3"
  151. << "imaadpcmacm: IMA ADPCM"
  152. << "msgsmacm: MS GSM"
  153. << "msnaudio: MSN AUDIO"
  154. << "msgsm: MS GSM"
  155. << "alaw: aLaw"
  156. << "ulaw: uLaw"
  157. << "dvdpcm: Uncompressed DVD/VOB LPCM"
  158. << "a52: AC3-liba52"
  159. << "ac3: AC3-libac3"
  160. << "voxware: VoxWare"
  161. << "acelp: ACELP.net Sipro Lab"
  162. << "imc: Intel Music Coder"
  163. << "hwac3: AC3 through SPDIF"
  164. << "vorbis: OggVorbis"
  165. << "vivoaudio: Vivo G.723/Siren"
  166. << "g72x: G.711/G.721/G.723"
  167. << "atrac3: Sony ATRAC3"
  168. << "ALF2: ALF2"
  169. << "truespeech: DSP Group TrueSpeech"
  170. << "voxwarert24: VoxWare RT24 speech"
  171. << "lhacm: Lernout & Hauspie CELP and SBC";
  172. m_video_drivers
  173. << "xmga: Matrox overlay in X11 window"
  174. << "mga: Matrox G200/G4x0/G550 overlay"
  175. << "3dfx: 3dfx"
  176. << "tdfxfb: 3Dfx Banshee/Voodoo3/Voodoo5"
  177. << "xv: X11/XVideo"
  178. << "xvmc: XVideo Motion Compensation"
  179. << "x11: X11"
  180. << "xover: X11 overlay"
  181. << "gl: X11 OpenGL"
  182. << "gl2: X11 OpenGL - multiple textures version"
  183. << "dga: DGA"
  184. << "sdl: SDL YUV/RGB/BGR renderer"
  185. << "ggi: General Graphics Interface"
  186. << "fbdev: Framebuffer Device"
  187. << "fbdev2: Framebuffer Device"
  188. << "svga: SVGAlib"
  189. << "aa: AAlib"
  190. << "caca: libcaca"
  191. << "dxr3: DXR3/H+ video out"
  192. << "png: PNG file"
  193. << "jpeg: JPEG file"
  194. << "gif89a: animated GIF"
  195. << "null: Null video"
  196. << "pgm: PGM file"
  197. << "md5: MD5 sum"
  198. << "mpegpes: Mpeg-PES to DVB card"
  199. << "yuv4mpeg: yuv4mpeg for mjpegtools"
  200. << "vesa: VESA VBE 2.0 video"
  201. << "directfb: Direct Framebuffer Device"
  202. << "dfbmga: DirectFB / Matrox"
  203. << "xvidix: X11/VIDIX"
  204. << "cvidix: console VIDIX"
  205. << "tga: Targa";
  206. m_video_codecs
  207. << "mpegpes: Mpeg PES"
  208. << "mpeg12: MPEG 1 or 2"
  209. << "ffmpeg12: FFmpeg MPEG 1/2"
  210. << "nuv: NuppelVideo"
  211. << "mpng: PNG images"
  212. << "mtga: TGA images"
  213. << "sgi: SGI images"
  214. << "fli: Autodesk FLI/FLC Animation"
  215. << "qtrle: Quicktime Animation"
  216. << "qtrpza: Quicktime Apple Video"
  217. << "qtsmc: Apple Graphics"
  218. << "cyuv: Creative YUV"
  219. << "msrle: Microsoft RLE"
  220. << "roqvideo: Id RoQ File Video"
  221. << "lzo: LZO compressed"
  222. << "cram: Microsoft Video 1"
  223. << "cvidvfw: Cinepak Video"
  224. << "huffyuv: HuffYUV"
  225. << "svq1: Sorenson v1"
  226. << "video1: Microsoft Video 1"
  227. << "cvid: Cinepak Video"
  228. << "mphuffyuv: HuffYUV"
  229. << "mpmszh: AVImszh"
  230. << "mpzlib: AVIzlib"
  231. << "cvidxa: XAnim Radius Cinepak Video"
  232. << "ffhuffyuv: FFHuffYUV"
  233. << "ffsvq1: FFmpeg Sorenson Video v1"
  234. << "ffdivx: FFmpeg DivX ;-)"
  235. << "ffmp42: FFmpeg M$ MPEG-4 v2"
  236. << "ffmp41: FFmpeg M$ MPEG-4 v1"
  237. << "ffwmv1: FFmpeg M$ WMV1/WMV7"
  238. << "ffwmv2: FFmpeg M$ WMV2/WMV8"
  239. << "ffodivx: FFmpeg MPEG-4"
  240. << "xvid: Xvid"
  241. << "odivx: OpenDivX API"
  242. << "divx4: DivX4Linux API"
  243. << "divx4vfw: DivX4Windows-VFW"
  244. << "divxds: DivX ;-)"
  245. << "divx: DivX ;-)"
  246. << "mpeg4ds: Microsoft MPEG-4 v1/v2"
  247. << "mpeg4: Microsoft MPEG-4 v1/v2"
  248. << "wmv8: Windows Media Video 8"
  249. << "wmv7: Windows Media Video 7"
  250. << "wmv9dmo: Windows Media Video 9 DMO"
  251. << "wmvdmo: Windows Media Video DMO"
  252. << "ubmp4: UB Video MPEG 4"
  253. << "ffmjpeg: FFmpeg MJPEG"
  254. << "ijpg: Independent JPEG Group"
  255. << "m3jpeg: Morgan Motion JPEG"
  256. << "mjpeg: MainConcept Motion JPEG"
  257. << "avid: AVID Motion JPEG"
  258. << "LEAD: LEAD (M)Jpeg"
  259. << "imagepower: ImagePower MJPEG2000"
  260. << "m3jpeg2k: Morgan MJPEG2000"
  261. << "m3jpegds: Morgan MJPEG"
  262. << "pegasusm: Pegasus Motion JPEG"
  263. << "pegasusl: Pegasus Lossless JPEG"
  264. << "pegasusmwv: Pegasus Motion Wavelet 2000"
  265. << "vivo: Vivo H.263"
  266. << "u263: UB Video H.263/H.263+/H.263++"
  267. << "i263: I263"
  268. << "ffi263: FFmpeg I263"
  269. << "ffh263: FFmpeg H263+"
  270. << "h263xa: XAnim CCITT H.263"
  271. << "h261xa: XAnim CCITT H.261"
  272. << "m261: M261"
  273. << "indeo5ds: Intel Indeo 5"
  274. << "indeo5: Intel Indeo 5"
  275. << "indeo4: Intel Indeo 4.1"
  276. << "indeo3: Intel Indeo 3.1/3.2"
  277. << "indeo5xa: XAnim Intel Indeo 5"
  278. << "indeo4xa: XAnim Intel Indeo 4.1"
  279. << "indeo3xa: XAnim Intel Indeo 3.1/3.2"
  280. << "qdv: Sony Digital Video"
  281. << "ffdv: FFmpeg DV"
  282. << "libdv: Raw DV"
  283. << "mcdv: MainConcept DV"
  284. << "3ivXxa: XAnim 3ivX Delta 3.5 plugin"
  285. << "3ivX: 3ivX Delta 3.5"
  286. << "rv40: Linux RealPlayer 9 RV40"
  287. << "rv40win: Win32 RealPlayer 9 RV40"
  288. << "rv30: Linux RealPlayer 8 RV30"
  289. << "rv30win: Win32 RealPlayer 8 RV30"
  290. << "rv20: Linux RealPlayer 8 RV20"
  291. << "rv20win: Win32 RealPlayer 8 RV20"
  292. << "ffrv10: FFmpeg RV10"
  293. << "vp3: On2 OpenSource VP3"
  294. << "mwv1: Motion Wavelets"
  295. << "asv2: ASUS V2"
  296. << "asv1: ASUS V1"
  297. << "mss1: Windows Screen Video"
  298. << "ucod: UCOD-ClearVideo"
  299. << "vcr2: ATI VCR-2"
  300. << "CJPG: CJPG"
  301. << "tm20: TrueMotion 2.0"
  302. << "sp5x: SP5x - used by Aiptek MegaCam"
  303. << "qt3ivx: win32/quicktime 3IV1"
  304. << "qth263: win32/quicktime H.263"
  305. << "qtrlerpza: win32/quicktime RLE/RPZA"
  306. << "qtvp3: win32/quicktime VP3"
  307. << "qtzygo: win32/quicktime ZyGo"
  308. << "qtbhiv: win32/quicktime BeHereiVideo"
  309. << "qtcvid: win32/quicktime Cinepak"
  310. << "qtindeo: win32/quicktime Indeo"
  311. << "qtmjpeg: win32/quicktime MJPEG"
  312. << "qtmpeg4: win32/quicktime MPEG-4"
  313. << "qtsvq3: win32/quicktime SVQ3"
  314. << "qtsvq1: win32/quicktime SVQ1"
  315. << "zlib: AVIzlib"
  316. << "mszh: AVImszh"
  317. << "alaris: Alaris VideoGramPiX"
  318. << "vcr1: ATI VCR-1"
  319. << "pim1: Pinnacle Hardware MPEG1"
  320. << "qpeg: Q-Team TQPEG"
  321. << "rricm: rricm"
  322. << "camtasia: TechSmith Camtasia Screen"
  323. << "rawrgb32: RAW RGB32"
  324. << "rawrgb24: RAW RGB24"
  325. << "rawrgb16: RAW RGB16"
  326. << "rawbgr32flip: RAW BGR32"
  327. << "rawbgr32: RAW BGR32"
  328. << "rawbgr24flip: RAW BGR24"
  329. << "rawbgr24: RAW BGR24"
  330. << "rawbgr16flip: RAW BGR15"
  331. << "rawbgr16: RAW BGR15"
  332. << "rawbgr15flip: RAW BGR15"
  333. << "rawbgr15: RAW BGR15"
  334. << "rawbgr8flip: RAW BGR8"
  335. << "rawbgr8: RAW BGR8"
  336. << "rawbgr1: RAW BGR1"
  337. << "rawyuy2: RAW YUY2"
  338. << "rawuyvy: RAW UYVY"
  339. << "rawyv12: RAW YV12"
  340. << "rawi420: RAW I420"
  341. << "rawyvu9: RAW YVU9"
  342. << "null: Null";
  343. m_demuxers
  344. << "rawaudio: Raw audio"
  345. << "rawvideo: Raw video"
  346. << "tv: TV card"
  347. << "mf: Image files"
  348. << "avi: AVI"
  349. << "y4m: YUV4MPEG2"
  350. << "asv: ASF"
  351. << "nsv: NullsoftVideo"
  352. << "nuv: NuppelVideo"
  353. << "real: Realmedia"
  354. << "smjpeg: SMJPEG"
  355. << "mkv: Matroska"
  356. << "realaudio: Realaudio"
  357. << "vqf: TwinVQ"
  358. << "mov: Quicktime/MP4"
  359. << "vivo: Vivo"
  360. << "fli: Autodesk FLIC"
  361. << "film: FILM/CPK"
  362. << "roq: RoQ"
  363. << "gif: GIF"
  364. << "ogg: Ogg"
  365. << "avs: Avisynth"
  366. << "pva: PVA"
  367. << "mpegts: MPEG-TS"
  368. << "lmlm4: LMLM4 MPEG4"
  369. << "mpegps: MPEG PS"
  370. << "mpegpes: MPEG PES"
  371. << "mpeges: MPEG ES"
  372. << "mpeggxf: MPEG ES in GXF"
  373. << "mpeg4es: MPEG4 ES"
  374. << "h264es: H.264 ES"
  375. << "rawdv: Raw DV"
  376. << "mpc: Musepack"
  377. << "audio: Audio"
  378. << "tivo: TiVo"
  379. << "rtp: LIVE555 RTP"
  380. << "aac: AAC";
  381. getLists();
  382. }
  383. KPlayerEngine::~KPlayerEngine()
  384. {
  385. #ifdef DEBUG_KPLAYER_ENGINE
  386. kdDebugTime() << "Destroying engine\n";
  387. #endif
  388. enableScreenSaver();
  389. kill();
  390. if ( process() )
  391. delete process();
  392. if ( meta() )
  393. {
  394. TQStringList groups (meta() -> groupList());
  395. #ifdef DEBUG_KPLAYER_ENGINE
  396. kdDebugTime() << "Cache has " << groups.count() << " entries\n";
  397. #endif
  398. if ( int (groups.count()) > configuration() -> cacheSizeLimit() )
  399. {
  400. TQMap<TQString,TQString> map;
  401. int i = 0;
  402. for ( TQStringList::Iterator it = groups.begin(); it != groups.end(); ++ it )
  403. {
  404. meta() -> setGroup (*it);
  405. TQDateTime dt (meta() -> readDateTimeEntry ("Date"));
  406. if ( ! dt.isNull() )
  407. map.insert (dt.toString (TQt::ISODate) + TQString().sprintf ("-%04u", i ++), *it);
  408. }
  409. i = groups.count() - configuration() -> cacheSizeLimit();
  410. for ( TQMap<TQString,TQString>::Iterator mapit = map.begin(); i && mapit != map.end(); ++ mapit )
  411. {
  412. #ifdef DEBUG_KPLAYER_ENGINE
  413. kdDebugTime() << "Deleting entry for " << mapit.data() << " from " << mapit.key() << "\n";
  414. #endif
  415. meta() -> deleteGroup (mapit.data());
  416. i --;
  417. }
  418. }
  419. }
  420. if ( settings() )
  421. {
  422. disconnect (settings() -> properties(), SIGNAL (updated()), this, SLOT (refreshProperties()));
  423. delete settings();
  424. }
  425. if ( configuration() )
  426. {
  427. disconnect (configuration(), SIGNAL (updated()), this, SLOT (refreshSettings()));
  428. configuration() -> commit();
  429. delete configuration();
  430. }
  431. if ( light() && config() )
  432. delete m_config;
  433. if ( store() )
  434. delete store();
  435. if ( meta() )
  436. delete meta();
  437. }
  438. void KPlayerEngine::initialize (TDEActionCollection* ac, TQWidget* parent, const char* name, TDEConfig* config)
  439. {
  440. if ( ! engine() )
  441. {
  442. KPlayerProperties::initialize();
  443. m_engine = new KPlayerEngine (ac, parent, name, config);
  444. }
  445. }
  446. void KPlayerEngine::terminate (void)
  447. {
  448. if ( engine() )
  449. {
  450. delete engine();
  451. m_engine = 0;
  452. KPlayerProperties::terminate();
  453. }
  454. }
  455. void KPlayerEngine::setupActions (void)
  456. {
  457. if ( ! m_ac )
  458. return;
  459. #ifdef DEBUG_KPLAYER_ENGINE
  460. kdDebugTime() << "KPlayerEngine::setupActions\n";
  461. #endif
  462. TDEAction* action;
  463. action = new TDEAction (i18n("&Properties..."), "properties", ALT + Key_Return, this, SLOT (fileProperties()), m_ac, "file_properties");
  464. action -> setStatusText (i18n("Opens the File Properties dialog"));
  465. action -> setWhatsThis (i18n("Properties command opens the File Properties dialog that lets you choose many options specific to the currently loaded file. See the File properties micro-HOWTO for details."));
  466. action = new TDEAction (i18n("&Play"), "player_play", Key_Return, this, SLOT (play()), m_ac, "player_play");
  467. action -> setStatusText (i18n("Plays the currently loaded file"));
  468. action -> setWhatsThis (i18n("Play command starts playback of the current file. If the player has been paused, this command resumes playback. This command is available when a file is loaded."));
  469. action = new TDEToggleAction (i18n("Paus&e"), "player_pause", Key_Space, this, SLOT (pause()), m_ac, "player_pause");
  470. action -> setStatusText (i18n("Pauses the player"));
  471. action -> setWhatsThis (i18n("Pause command pauses or resumes playback of the current file. This command is available when the player is not idle."));
  472. action = new TDEAction (i18n("&Stop"), "player_stop", Key_Escape, this, SLOT (stop()), m_ac, "player_stop");
  473. action -> setStatusText (i18n("Stops the player"));
  474. action -> setWhatsThis (i18n("Stop command stops playback of the current file. This command is available when the player is not idle."));
  475. action = new TDEAction (i18n("&Forward"), 0, Key_Right, this, SLOT (forward()), m_ac, "player_forward");
  476. action -> setStatusText (i18n("Moves playback forward"));
  477. action -> setWhatsThis (i18n("Forward command moves playback forward by one percent of the time length of the current file. This command is available when playing a file."));
  478. action = new TDEAction (i18n("F&ast Forward"), "player_fwd", CTRL + Key_Right, this, SLOT (fastForward()), m_ac, "player_fast_forward");
  479. action -> setStatusText (i18n("Moves playback forward fast"));
  480. action -> setWhatsThis (i18n("Fast Forward command moves playback forward by ten percent of the time length of the current file. This command is available when playing a file."));
  481. action = new TDEAction (i18n("&Backward"), 0, Key_Left, this, SLOT (backward()), m_ac, "player_backward");
  482. action -> setStatusText (i18n("Moves playback backward"));
  483. action -> setWhatsThis (i18n("Backward command moves playback backward by one percent of the time length of the current file. This command is available when playing a file."));
  484. action = new TDEAction (i18n("Fast Back&ward"), "player_rew", CTRL + Key_Left, this, SLOT (fastBackward()), m_ac, "player_fast_backward");
  485. action -> setStatusText (i18n("Moves playback backward fast"));
  486. action -> setWhatsThis (i18n("Fast Backward command moves playback backward by ten percent of the time length of the current file. This command is available when playing a file."));
  487. action = new TDEAction (i18n("Back &to Start"), 0, CTRL + Key_Home, this, SLOT (start()), m_ac, "player_start");
  488. action -> setStatusText (i18n("Moves playback to the beginning"));
  489. action -> setWhatsThis (i18n("Back to Start command moves playback to the beginning of the current file. This command is available when playing a file."));
  490. action = new TDEAction (i18n("&Increase Volume"), 0, CTRL + Key_Up, this, SLOT (volumeIncrease()), m_ac, "audio_volume_up");
  491. action -> setStatusText (i18n("Increases the volume"));
  492. action -> setWhatsThis (i18n("Increase Volume command increases the sound volume."));
  493. action = new TDEAction (i18n("&Decrease Volume"), 0, CTRL + Key_Down, this, SLOT (volumeDecrease()), m_ac, "audio_volume_down");
  494. action -> setStatusText (i18n("Decreases the volume"));
  495. action -> setWhatsThis (i18n("Decrease Volume command decreases the sound volume."));
  496. TDEToggleAction* toggle = new TDEToggleAction (i18n("&Mute"), "mute", CTRL + Key_Backslash, this, SLOT (mute()), m_ac, "audio_mute");
  497. toggle -> setStatusText (i18n("Turns the sound on/off"));
  498. toggle -> setWhatsThis (i18n("Mute command turns the sound on or off."));
  499. if ( configuration() -> mute() )
  500. toggle -> setChecked (true);
  501. toggle = new TDEToggleAction (i18n("Maintain &Aspect"), "viewmagfit", CTRL + Key_A, this, SLOT (maintainAspect()), m_ac, "view_maintain_aspect");
  502. toggle -> setStatusText (i18n("Maintains the video aspect ratio"));
  503. toggle -> setWhatsThis (i18n("Maintain Aspect command toggles the option to maintain the video aspect ratio."));
  504. if ( settings() -> maintainAspect() )
  505. toggle -> setChecked (true);
  506. m_updating = true;
  507. KPlayerSliderAction* sa = new KPlayerSliderAction (i18n("Progress"), 0, this, SLOT (progressChanged (int)), m_ac, "player_progress");
  508. sa -> slider() -> setup (0, 0, 0, configuration() -> showSliderMarks(), 0, 0, 0);
  509. sa -> setStatusText (i18n("Shows player progress and allows seeking"));
  510. sa -> setWhatsThis (i18n("Progress slider shows playback progress and allows seeking."));
  511. connect (sa -> slider(), SIGNAL (sliderReleased()), kPlayerProcess(), SLOT (progressSliderReleased()));
  512. sa = new KPlayerSliderAction (i18n("Volume"), 0, this, SLOT (volumeChanged (int)), m_ac, "audio_volume");
  513. sa -> setStatusText (i18n("Changes volume level"));
  514. sa -> setWhatsThis (i18n("Volume slider shows the current sound volume level and allows you to change it."));
  515. KPlayerPopupSliderAction* psa = new KPlayerPopupSliderAction (i18n("Volume"), "volume", Key_F9, this, SLOT (volumeChanged (int)), m_ac, "popup_volume");
  516. psa -> setStatusText (i18n("Shows the volume popup slider"));
  517. psa -> setWhatsThis (i18n("Volume button displays a slider that shows the current sound volume level and allows you to change it."));
  518. if ( light() )
  519. {
  520. refreshSettings();
  521. enablePlayerActions();
  522. enableVideoActions();
  523. return;
  524. }
  525. action = new TDEAction (i18n("&Load Subtitles..."), 0, CTRL + Key_S, this, SLOT (fileOpenSubtitles()), m_ac, "subtitles_load");
  526. action -> setStatusText (i18n("Opens a subtitle file"));
  527. action -> setWhatsThis (i18n("Load Subtitles command displays the standard Open File dialog and lets you choose a subtitle file to use with the current file or URL. If you load subtitles when video is playing, KPlayer will display the subtitles immediately. By default it will also remember the subtitles you choose in the current file properties. This command is available for video files."));
  528. /*action = new TDEAction (i18n("Load Su&btitle URL..."), 0, 0, this, SLOT (fileOpenSubtitleUrl()), m_ac, "subtitles_load_url");
  529. action -> setStatusText (i18n("Opens a subtitle URL"));
  530. action -> setWhatsThis (i18n("Load Subtitle URL command displays the standard Open URL dialog and lets you type or paste in a subtitle URL to use with the current file or URL. If you load subtitles when video is playing, KPlayer will display the subtitles immediately. By default it will also remember the subtitles you choose in the current file properties. This command is available for video files."));
  531. action = new TDEAction (i18n("U&nload Subtitles"), 0, 0, this, SLOT (fileUnloadSubtitles()), m_ac, "subtitles_unload");
  532. action -> setStatusText (i18n("Unloads subtitles"));
  533. action -> setWhatsThis (i18n("Unload Subtitles command unloads the currently loaded subtitles, and if video is playing, hides the subtitles. This command is available when subtitles are loaded."));*/
  534. action = new TDEToggleAction (i18n("&Full Screen"), "window_fullscreen", CTRL + Key_F, this, SLOT (fullScreen()), m_ac, "view_full_screen");
  535. action -> setStatusText (i18n("Switches to full screen mode"));
  536. action -> setWhatsThis (i18n("Full Screen command switches to full screen video display and back to normal mode."));
  537. action = KStdAction::zoomIn (this, SLOT (zoomIn()), m_ac);
  538. action -> setStatusText (i18n("Enlarges the video"));
  539. action -> setWhatsThis (i18n("Zoom In command enlarges the video area by one half of the original video size of the current file."));
  540. action = KStdAction::zoomOut (this, SLOT (zoomOut()), m_ac);
  541. action -> setStatusText (i18n("Shrinks the video"));
  542. action -> setWhatsThis (i18n("Zoom Out command reduces the video area by one half of the original video size of the current file."));
  543. toggle = new TDEToggleAction (i18n("Zoom to 5&0%"), 0, 0, this, SLOT (zoom12()), m_ac, "view_zoom_1_2");
  544. // xgettext:no-c-format
  545. toggle -> setStatusText (i18n("Scales video to 50% of the original size"));
  546. // xgettext:no-c-format
  547. toggle -> setWhatsThis (i18n("Zoom to 50% command resizes the video area to one half of the original video size of the current file."));
  548. toggle -> setExclusiveGroup ("zoom");
  549. toggle = new TDEToggleAction (i18n("Zoom to &100%"), 0, CTRL + Key_Backspace, this, SLOT (zoom11()), m_ac, "view_zoom_1_1");
  550. toggle -> setStatusText (i18n("Scales video to its original size"));
  551. // xgettext:no-c-format
  552. toggle -> setWhatsThis (i18n("Zoom to 100% command resizes the video area to the original video size of the current file."));
  553. toggle -> setExclusiveGroup ("zoom");
  554. toggle = new TDEToggleAction (i18n("Zoo&m to 150%"), 0, 0, this, SLOT (zoom32()), m_ac, "view_zoom_3_2");
  555. // xgettext:no-c-format
  556. toggle -> setStatusText (i18n("Scales video to 150% of the original size"));
  557. // xgettext:no-c-format
  558. toggle -> setWhatsThis (i18n("Zoom to 150% command resizes the video area to 150% of the original video size of the current file."));
  559. toggle -> setExclusiveGroup ("zoom");
  560. toggle = new TDEToggleAction (i18n("Zoom to &200%"), 0, 0, this, SLOT (zoom21()), m_ac, "view_zoom_2_1");
  561. // xgettext:no-c-format
  562. toggle -> setStatusText (i18n("Scales video to 200% of the original size"));
  563. // xgettext:no-c-format
  564. toggle -> setWhatsThis (i18n("Zoom to 200% command resizes the video area to twice the original video size of the current file."));
  565. toggle -> setExclusiveGroup ("zoom");
  566. toggle = new TDEToggleAction (i18n("Zoom &to 250%"), 0, 0, this, SLOT (zoom52()), m_ac, "view_zoom_5_2");
  567. // xgettext:no-c-format
  568. toggle -> setStatusText (i18n("Scales video to 250% of the original size"));
  569. // xgettext:no-c-format
  570. toggle -> setWhatsThis (i18n("Zoom to 250% command resizes the video area to 250% of the original video size of the current file."));
  571. toggle -> setExclusiveGroup ("zoom");
  572. toggle = new TDEToggleAction (i18n("Zoom to &300%"), 0, 0, this, SLOT (zoom31()), m_ac, "view_zoom_3_1");
  573. // xgettext:no-c-format
  574. toggle -> setStatusText (i18n("Scales video to 300% of the original size"));
  575. // xgettext:no-c-format
  576. toggle -> setWhatsThis (i18n("Zoom to 300% command resizes the video area to thrice the original video size of the current file."));
  577. toggle -> setExclusiveGroup ("zoom");
  578. toggle = new TDEToggleAction (i18n("Maintain Original &Aspect"), 0, 0, this, SLOT (maintainOriginalAspect()), m_ac, "view_original_aspect");
  579. toggle -> setStatusText (i18n("Maintains the original video aspect ratio"));
  580. toggle -> setWhatsThis (i18n("Maintain Original Aspect command toggles the option to maintain the original video aspect ratio of the current file."));
  581. if ( settings() -> maintainAspect() )
  582. toggle -> setChecked (true);
  583. toggle -> setExclusiveGroup ("aspect");
  584. toggle = new TDEToggleAction (i18n("Maintain &Current Aspect"), 0, 0, this, SLOT (maintainCurrentAspect()), m_ac, "view_current_aspect");
  585. toggle -> setStatusText (i18n("Maintains the current video aspect ratio"));
  586. toggle -> setWhatsThis (i18n("Maintain Current Aspect command toggles the option to maintain the current video aspect ratio."));
  587. toggle -> setExclusiveGroup ("aspect");
  588. toggle = new TDEToggleAction (i18n("Force &4 to 3 Aspect"), 0, 0, this, SLOT (aspect43()), m_ac, "view_aspect_4_3");
  589. toggle -> setStatusText (i18n("Sets 4 to 3 video aspect ratio"));
  590. toggle -> setWhatsThis (i18n("Force 4 to 3 Aspect command toggles the option to maintain four to three video aspect ratio."));
  591. toggle -> setExclusiveGroup ("aspect");
  592. toggle = new TDEToggleAction (i18n("Force 1&6 to 9 Aspect"), 0, 0, this, SLOT (aspect169()), m_ac, "view_aspect_16_9");
  593. toggle -> setStatusText (i18n("Sets 16 to 9 video aspect ratio"));
  594. toggle -> setWhatsThis (i18n("Force 16 to 9 Aspect command toggles the option to maintain sixteen to nine video aspect ratio."));
  595. toggle -> setExclusiveGroup ("aspect");
  596. action = new TDEAction (i18n("I&ncrease Delay"), 0, CTRL + Key_BracketLeft, this, SLOT (audioDelayIncrease()), m_ac, "audio_delay_up");
  597. action -> setStatusText (i18n("Increases audio delay"));
  598. action -> setWhatsThis (i18n("Increase Delay command increases the delay of sound relative to video."));
  599. action = new TDEAction (i18n("D&ecrease Delay"), 0, CTRL + Key_BracketRight, this, SLOT (audioDelayDecrease()), m_ac, "audio_delay_down");
  600. action -> setStatusText (i18n("Decreases audio delay"));
  601. action -> setWhatsThis (i18n("Decrease Delay command decreases the delay of sound relative to video."));
  602. action = new TDEAction (i18n("Decrease C&ontrast"), 0, CTRL + Key_1, this, SLOT (contrastDecrease()), m_ac, "video_contrast_down");
  603. action -> setStatusText (i18n("Decreases video contrast"));
  604. action -> setWhatsThis (i18n("Decrease Contrast command decreases the video contrast."));
  605. action = new TDEAction (i18n("Increase &Contrast"), 0, CTRL + Key_2, this, SLOT (contrastIncrease()), m_ac, "video_contrast_up");
  606. action -> setStatusText (i18n("Increases video contrast"));
  607. action -> setWhatsThis (i18n("Increase Contrast command increases the video contrast."));
  608. action = new TDEAction (i18n("Decrease B&rightness"), 0, CTRL + Key_3, this, SLOT (brightnessDecrease()), m_ac, "video_brightness_down");
  609. action -> setStatusText (i18n("Decreases video brightness"));
  610. action -> setWhatsThis (i18n("Decrease Brightness command decreases the video brightness."));
  611. action = new TDEAction (i18n("Increase &Brightness"), 0, CTRL + Key_4, this, SLOT (brightnessIncrease()), m_ac, "video_brightness_up");
  612. action -> setStatusText (i18n("Increases video brightness"));
  613. action -> setWhatsThis (i18n("Increase Brightness command increases the video brightness."));
  614. action = new TDEAction (i18n("Decrease H&ue"), 0, CTRL + Key_5, this, SLOT (hueDecrease()), m_ac, "video_hue_down");
  615. action -> setStatusText (i18n("Decreases video hue"));
  616. action -> setWhatsThis (i18n("Decrease Hue command decreases the video hue."));
  617. action = new TDEAction (i18n("Increase &Hue"), 0, CTRL + Key_6, this, SLOT (hueIncrease()), m_ac, "video_hue_up");
  618. action -> setStatusText (i18n("Increases video hue"));
  619. action -> setWhatsThis (i18n("Increase Hue command increases the video hue."));
  620. action = new TDEAction (i18n("Decrease S&aturation"), 0, CTRL + Key_7, this, SLOT (saturationDecrease()), m_ac, "video_saturation_down");
  621. action -> setStatusText (i18n("Decreases video saturation"));
  622. action -> setWhatsThis (i18n("Decrease Saturation command decreases the video saturation."));
  623. action = new TDEAction (i18n("Increase &Saturation"), 0, CTRL + Key_8, this, SLOT (saturationIncrease()), m_ac, "video_saturation_up");
  624. action -> setStatusText (i18n("Increases video saturation"));
  625. action -> setWhatsThis (i18n("Increase Saturation command increases the video saturation."));
  626. sa = new KPlayerSliderAction (i18n("Contrast"), 0, this, SLOT (contrastChanged (int)), m_ac, "video_contrast");
  627. sa -> setStatusText (i18n("Changes contrast level"));
  628. sa -> setWhatsThis (i18n("Contrast slider shows the current video contrast level and allows you to change it."));
  629. sa = new KPlayerSliderAction (i18n("Brightness"), 0, this, SLOT (brightnessChanged (int)), m_ac, "video_brightness");
  630. sa -> setStatusText (i18n("Changes brightness level"));
  631. sa -> setWhatsThis (i18n("Brightness slider shows the current video brightness level and allows you to change it."));
  632. sa = new KPlayerSliderAction (i18n("Hue"), 0, this, SLOT (hueChanged (int)), m_ac, "video_hue");
  633. sa -> setStatusText (i18n("Changes hue level"));
  634. sa -> setWhatsThis (i18n("Hue slider shows the current video hue level and allows you to change it."));
  635. sa = new KPlayerSliderAction (i18n("Saturation"), 0, this, SLOT (saturationChanged (int)), m_ac, "video_saturation");
  636. sa -> setStatusText (i18n("Changes saturation level"));
  637. sa -> setWhatsThis (i18n("Saturation slider shows the current video saturation level and allows you to change it."));
  638. psa = new KPlayerPopupSliderAction (i18n("Contrast"), "contrast", Key_F5, this, SLOT (contrastChanged (int)), m_ac, "popup_contrast");
  639. psa -> setStatusText (i18n("Shows the contrast popup slider"));
  640. psa -> setWhatsThis (i18n("Contrast button displays a slider that shows the current video contrast level and allows you to change it."));
  641. psa = new KPlayerPopupSliderAction (i18n("Brightness"), "brightness", Key_F6, this, SLOT (brightnessChanged (int)), m_ac, "popup_brightness");
  642. psa -> setStatusText (i18n("Shows the brightness popup slider"));
  643. psa -> setWhatsThis (i18n("Brightness button displays a slider that shows the current video brightness level and allows you to change it."));
  644. psa = new KPlayerPopupSliderAction (i18n("Hue"), "hue", Key_F7, this, SLOT (hueChanged (int)), m_ac, "popup_hue");
  645. psa -> setStatusText (i18n("Shows the hue popup slider"));
  646. psa -> setWhatsThis (i18n("Hue button displays a slider that shows the current video hue level and allows you to change it."));
  647. psa = new KPlayerPopupSliderAction (i18n("Saturation"), "saturation", Key_F8, this, SLOT (saturationChanged (int)), m_ac, "popup_saturation");
  648. psa -> setStatusText (i18n("Shows the saturation popup slider"));
  649. psa -> setWhatsThis (i18n("Saturation button displays a slider that shows the current video saturation level and allows you to change it."));
  650. toggle = new TDEToggleAction (i18n("S&oft Frame Dropping"), 0, 0, this, SLOT (softFrameDrop()), m_ac, "player_soft_frame_drop");
  651. toggle -> setStatusText (i18n("Turns soft frame dropping on/off"));
  652. toggle -> setWhatsThis (i18n("Soft Frame Dropping command toggles the soft frame dropping option. If your system is too slow to play a file, MPlayer can drop some frames so playback does not slow down. The soft option drops frames less aggressively than the hard one, and should not cause playback problems. The Frame drop option can also be set on the Advanced page either globally in KPlayer Settings or for a particular file in the File Properties."));
  653. toggle -> setExclusiveGroup ("framedrop");
  654. toggle = new TDEToggleAction (i18n("&Hard Frame Dropping"), 0, 0, this, SLOT (hardFrameDrop()), m_ac, "player_hard_frame_drop");
  655. toggle -> setStatusText (i18n("Turns hard frame dropping on/off"));
  656. toggle -> setWhatsThis (i18n("Hard Frame Dropping command toggles the hard frame dropping option. If your system is too slow to play a file, MPlayer can drop some frames so playback does not slow down. The hard option drops frames more aggressively than the soft one, and may sometimes break decoding. The Frame drop option can also be set on the Advanced page either globally in KPlayer Settings or for a particular file in the File Properties."));
  657. toggle -> setExclusiveGroup ("framedrop");
  658. action = new TDEAction (i18n("Move &Down"), 0, CTRL + Key_Comma, this, SLOT (subtitlesMoveDown()), m_ac, "subtitles_move_down");
  659. action -> setStatusText (i18n("Moves subtitles down"));
  660. action -> setWhatsThis (i18n("Move Down command moves the subtitles down."));
  661. action = new TDEAction (i18n("Move &Up"), 0, CTRL + Key_Period, this, SLOT (subtitlesMoveUp()), m_ac, "subtitles_move_up");
  662. action -> setStatusText (i18n("Moves subtitles up"));
  663. action -> setWhatsThis (i18n("Move Up command moves the subtitles up."));
  664. action = new TDEAction (i18n("D&ecrease Delay"), 0, CTRL + Key_Apostrophe, this, SLOT (subtitlesDelayDecrease()), m_ac, "subtitles_delay_decrease");
  665. action -> setStatusText (i18n("Decreases subtitle delay"));
  666. action -> setWhatsThis (i18n("Decrease Delay command decreases the delay of subtitles relative to video."));
  667. action = new TDEAction (i18n("I&ncrease Delay"), 0, CTRL + Key_Semicolon, this, SLOT (subtitlesDelayIncrease()), m_ac, "subtitles_delay_increase");
  668. action -> setStatusText (i18n("Increases subtitle delay"));
  669. action -> setWhatsThis (i18n("Increase Delay command increases the delay of subtitles relative to video."));
  670. m_video_action_list = new KPlayerTrackActionList (i18n("Track %1"), i18n("Selects %1 video track"),
  671. i18n("Video %1 command switches to the selected video track."), this, "video_streams");
  672. connect (videoActionList(), SIGNAL (activated (int)), SLOT (videoStream (int)));
  673. m_audio_action_list = new KPlayerTrackActionList (i18n("Track %1"), i18n("Selects %1 audio track"),
  674. i18n("Audio %1 command switches to the selected audio track."), this, "audio_streams");
  675. connect (audioActionList(), SIGNAL (activated (int)), SLOT (audioStream (int)));
  676. m_subtitle_action_list = new KPlayerSubtitleTrackActionList (i18n("Track %1"), i18n("Selects %1 subtitle track"),
  677. i18n("Subtitles %1 command switches to the selected subtitle track."), this, "subtitle_streams");
  678. connect (subtitleActionList(), SIGNAL (activated (int)), SLOT (subtitleStream (int)));
  679. refreshSettings();
  680. enablePlayerActions();
  681. enableVideoActions();
  682. }
  683. void KPlayerEngine::refreshSettings (void)
  684. {
  685. if ( ! m_ac )
  686. return;
  687. #ifdef DEBUG_KPLAYER_ENGINE
  688. kdDebugTime() << "KPlayerEngine::refreshSettings\n";
  689. #endif
  690. m_updating = true;
  691. int value = settings() -> volume();
  692. int minimum = configuration() -> volumeMinimum();
  693. int maximum = configuration() -> volumeMaximum();
  694. int interval = configuration() -> sliderMarksInterval (maximum - minimum);
  695. bool show = configuration() -> showSliderMarks();
  696. #ifdef DEBUG_KPLAYER_ENGINE
  697. kdDebugTime() << " Volume " << value << ": " << minimum << " - " << maximum << " / " << interval << "\n";
  698. #endif
  699. sliderAction ("audio_volume") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  700. popupAction ("popup_volume") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  701. m_last_volume = settings() -> volume();
  702. if ( properties() -> audioDriverString().startsWith ("alsa") )
  703. getAlsaVolume();
  704. process() -> volume (settings() -> actualVolume());
  705. if ( light() )
  706. {
  707. m_updating = false;
  708. return;
  709. }
  710. value = settings() -> contrast();
  711. minimum = configuration() -> contrastMinimum();
  712. maximum = configuration() -> contrastMaximum();
  713. interval = configuration() -> sliderMarksInterval (maximum - minimum);
  714. #ifdef DEBUG_KPLAYER_ENGINE
  715. kdDebugTime() << " Contrast " << value << ": " << minimum << " - " << maximum << " / " << interval << "\n";
  716. #endif
  717. sliderAction ("video_contrast") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  718. popupAction ("popup_contrast") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  719. process() -> contrast (value);
  720. value = settings() -> brightness();
  721. minimum = configuration() -> brightnessMinimum();
  722. maximum = configuration() -> brightnessMaximum();
  723. interval = configuration() -> sliderMarksInterval (maximum - minimum);
  724. #ifdef DEBUG_KPLAYER_ENGINE
  725. kdDebugTime() << " Brightness " << value << ": " << minimum << " - " << maximum << " / " << interval << "\n";
  726. #endif
  727. sliderAction ("video_brightness") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  728. popupAction ("popup_brightness") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  729. process() -> brightness (value);
  730. value = settings() -> hue();
  731. minimum = configuration() -> hueMinimum();
  732. maximum = configuration() -> hueMaximum();
  733. interval = configuration() -> sliderMarksInterval (maximum - minimum);
  734. #ifdef DEBUG_KPLAYER_ENGINE
  735. kdDebugTime() << " Hue " << value << ": " << minimum << " - " << maximum << " / " << interval << "\n";
  736. #endif
  737. sliderAction ("video_hue") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  738. popupAction ("popup_hue") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  739. process() -> hue (value);
  740. value = settings() -> saturation();
  741. minimum = configuration() -> saturationMinimum();
  742. maximum = configuration() -> saturationMaximum();
  743. interval = configuration() -> sliderMarksInterval (maximum - minimum);
  744. #ifdef DEBUG_KPLAYER_ENGINE
  745. kdDebugTime() << " Saturation " << value << ": " << minimum << " - " << maximum << " / " << interval << "\n";
  746. #endif
  747. sliderAction ("video_saturation") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  748. popupAction ("popup_saturation") -> slider() -> setup (minimum, maximum, value, show, interval, interval, 1);
  749. process() -> saturation (value);
  750. if ( properties() -> hasLength() )
  751. {
  752. #ifdef DEBUG_KPLAYER_ENGINE
  753. kdDebugTime() << " Length " << properties() -> length() << "\n";
  754. #endif
  755. setupProgressSlider (sliderAction ("player_progress") -> slider() -> maxValue());
  756. }
  757. m_updating = false;
  758. value = settings() -> frameDrop();
  759. #ifdef DEBUG_KPLAYER_ENGINE
  760. kdDebugTime() << " Frame drop " << value << "\n";
  761. #endif
  762. toggleAction ("player_soft_frame_drop") -> setChecked (value == 1);
  763. toggleAction ("player_hard_frame_drop") -> setChecked (value == 2);
  764. process() -> frameDrop (value);
  765. if ( settings() -> setInitialDisplaySize() )
  766. {
  767. emit initialSize();
  768. setDisplaySize();
  769. refreshAspect();
  770. }
  771. }
  772. void KPlayerEngine::refreshProperties (void)
  773. {
  774. if ( ! m_ac )
  775. return;
  776. #ifdef DEBUG_KPLAYER_ENGINE
  777. kdDebugTime() << "KPlayerEngine::refreshProperties\n";
  778. #endif
  779. setVolume();
  780. process() -> audioDelay (settings() -> audioDelay(), true);
  781. setContrast();
  782. setBrightness();
  783. setHue();
  784. setSaturation();
  785. process() -> subtitleMove (settings() -> subtitlePosition(), true);
  786. process() -> subtitleDelay (settings() -> subtitleDelay(), true);
  787. int value = settings() -> frameDrop();
  788. if ( ! light() )
  789. {
  790. videoActionList() -> update (properties() -> videoIDs(), properties() -> videoID());
  791. audioActionList() -> update (properties() -> audioIDs(), properties() -> audioID());
  792. subtitleActionList() -> update (settings() -> showSubtitles(), properties() -> subtitleIDs(),
  793. properties() -> subtitleID(), properties() -> vobsubIDs(), properties() -> vobsubID(),
  794. settings() -> subtitles(), settings() -> vobsubSubtitles(), settings() -> currentSubtitlePath());
  795. toggleAction ("player_soft_frame_drop") -> setChecked (value == 1);
  796. toggleAction ("player_hard_frame_drop") -> setChecked (value == 2);
  797. }
  798. process() -> frameDrop (value);
  799. if ( settings() -> setInitialDisplaySize() )
  800. {
  801. emit initialSize();
  802. setDisplaySize();
  803. }
  804. enableVideoActions();
  805. if ( ! light() )
  806. toggleAction ("view_full_screen") -> setChecked (settings() -> fullScreen()
  807. && toggleAction ("view_full_screen") -> isEnabled());
  808. showSubtitles();
  809. refreshAspect();
  810. }
  811. void KPlayerEngine::refreshAspect (void)
  812. {
  813. #ifdef DEBUG_KPLAYER_ENGINE
  814. kdDebugTime() << "Engine: Refreshing aspect: " << settings() -> aspect().width() << "x" << settings() -> aspect().height()
  815. << " " << settings() -> maintainAspect() << "\n";
  816. #endif
  817. toggleAction ("view_maintain_aspect") -> setChecked (settings() -> maintainAspect());
  818. if ( light() )
  819. return;
  820. toggleAction ("view_original_aspect") -> setChecked (false);
  821. toggleAction ("view_current_aspect") -> setChecked (false);
  822. toggleAction ("view_aspect_4_3") -> setChecked (false);
  823. toggleAction ("view_aspect_16_9") -> setChecked (false);
  824. if ( ! settings() -> maintainAspect() )
  825. return;
  826. if ( settings() -> isAspect (properties() -> originalSize()) )
  827. toggleAction ("view_original_aspect") -> setChecked (true);
  828. else if ( settings() -> isAspect (TQSize (4, 3)) )
  829. toggleAction ("view_aspect_4_3") -> setChecked (true);
  830. else if ( settings() -> isAspect (TQSize (16, 9)) )
  831. toggleAction ("view_aspect_16_9") -> setChecked (true);
  832. else
  833. toggleAction ("view_current_aspect") -> setChecked (true);
  834. }
  835. void KPlayerEngine::setupProgressSlider (int maximum)
  836. {
  837. int interval = maximum * configuration() -> sliderMarks() / 100;
  838. int pagestep = properties() -> fastSeek() * m_progress_factor;
  839. if ( pagestep == 0 )
  840. pagestep = interval;
  841. int linestep = properties() -> normalSeek() * m_progress_factor;
  842. if ( linestep == 0 )
  843. linestep = 1;
  844. KPlayerSlider* slider = sliderAction ("player_progress") -> slider();
  845. slider -> setup (0, maximum, slider -> value(), configuration() -> showSliderMarks(), interval, pagestep, linestep);
  846. }
  847. void KPlayerEngine::playerStateChanged (KPlayerProcess::State state, KPlayerProcess::State previous)
  848. {
  849. if ( ! m_ac )
  850. return;
  851. #ifdef DEBUG_KPLAYER_ENGINE
  852. kdDebugTime() << "Engine received state change: " << previous << " => " << state << "\n";
  853. #endif
  854. toggleAction ("player_pause") -> setChecked (state == KPlayerProcess::Paused);
  855. enablePlayerActions();
  856. enableVideoActions();
  857. if ( state == KPlayerProcess::Playing )
  858. disableScreenSaver();
  859. else
  860. enableScreenSaver();
  861. if ( state < KPlayerProcess::Playing && previous >= KPlayerProcess::Playing
  862. && ! properties() -> temporaryName().isEmpty() )
  863. {
  864. properties() -> setTemporaryName (TQString::null);
  865. properties() -> commit();
  866. }
  867. }
  868. void KPlayerEngine::playerProgressChanged (float progress, KPlayerProcess::ProgressType type)
  869. {
  870. if ( ! m_ac || type != KPlayerProcess::Position )
  871. return;
  872. KPlayerSlider* slider = sliderAction ("player_progress") -> slider();
  873. if ( slider -> dragging() )
  874. return;
  875. m_updating = true;
  876. int maxValue = slider -> maxValue();
  877. if ( maxValue )
  878. {
  879. int value = int (progress * m_progress_factor + 0.5);
  880. if ( value > maxValue )
  881. setupProgressSlider (value);
  882. slider -> setValue (value);
  883. }
  884. m_updating = false;
  885. }
  886. void KPlayerEngine::playerInfoAvailable (void)
  887. {
  888. if ( ! m_ac )
  889. return;
  890. #ifdef DEBUG_KPLAYER_ENGINE
  891. kdDebugTime() << "Engine: Info available. Detected length: " << properties() -> length() << "\n";
  892. #endif
  893. m_updating = true;
  894. // TQRangeControl breaks if its range is more than 524287
  895. if ( properties() -> length() > 50000 )
  896. m_progress_factor = 1;
  897. else if ( properties() -> length() > 5000 )
  898. m_progress_factor = 10;
  899. else
  900. m_progress_factor = 100;
  901. setupProgressSlider (int (properties() -> length() * m_progress_factor + 0.5));
  902. if ( properties() -> hasLength() )
  903. playerProgressChanged (process() -> position(), KPlayerProcess::Position);
  904. m_updating = false;
  905. enablePlayerActions();
  906. }
  907. void KPlayerEngine::playerSizeAvailable (void)
  908. {
  909. if ( ! m_ac )
  910. return;
  911. if ( ! properties() -> hasDisplaySize() && ! properties() -> hasOriginalSize() )
  912. properties() -> setHasVideo (false);
  913. #ifdef DEBUG_KPLAYER_ENGINE
  914. kdDebugTime() << "Engine: Size Available. Video size " << properties() -> currentSize().width() << "x" << properties() -> currentSize().height() << "\n";
  915. #endif
  916. if ( settings() -> setInitialDisplaySize() )
  917. {
  918. emit initialSize();
  919. setDisplaySize();
  920. }
  921. enableVideoActions();
  922. if ( ! light() )
  923. toggleAction ("view_full_screen") -> setChecked (settings() -> fullScreen()
  924. && toggleAction ("view_full_screen") -> isEnabled());
  925. refreshAspect();
  926. if ( m_play_pending )
  927. {
  928. m_play_pending = false;
  929. if ( ! m_stop )
  930. startPlaying();
  931. }
  932. }
  933. void KPlayerEngine::enablePlayerActions (void)
  934. {
  935. if ( ! m_ac )
  936. return;
  937. #ifdef DEBUG_KPLAYER_ENGINE
  938. kdDebugTime() << "Engine: Enabling player actions\n";
  939. #endif
  940. KPlayerProcess::State state = kPlayerProcess() -> state();
  941. action ("file_properties") -> setEnabled (! properties() -> url().isEmpty());
  942. action ("player_play") -> setEnabled (! properties() -> url().isEmpty()
  943. && state != KPlayerProcess::Running && state != KPlayerProcess::Playing);
  944. bool busy = state != KPlayerProcess::Idle;
  945. action ("player_pause") -> setEnabled (busy);
  946. action ("player_stop") -> setEnabled (busy);
  947. bool unpaused = state != KPlayerProcess::Paused;
  948. busy = busy && unpaused && state != KPlayerProcess::Running && kPlayerProcess() -> isSeekable();
  949. action ("player_forward") -> setEnabled (busy);
  950. action ("player_fast_forward") -> setEnabled (busy);
  951. action ("player_backward") -> setEnabled (busy);
  952. action ("player_fast_backward") -> setEnabled (busy);
  953. action ("player_start") -> setEnabled (busy);
  954. m_updating = true;
  955. busy = busy && properties() -> hasLength();
  956. if ( ! busy )
  957. {
  958. TQMouseEvent me1 (TQEvent::MouseButtonRelease, TQPoint (0, 0), TQPoint (0, 0), TQt::LeftButton,
  959. settings() -> shift() ? TQt::ShiftButton | TQt::LeftButton : TQt::LeftButton);
  960. TQApplication::sendEvent (sliderAction ("player_progress") -> slider(), &me1);
  961. TQMouseEvent me2 (TQEvent::MouseButtonRelease, TQPoint (0, 0), TQPoint (0, 0), TQt::MidButton,
  962. settings() -> shift() ? TQt::ShiftButton | TQt::MidButton : TQt::MidButton);
  963. TQApplication::sendEvent (sliderAction ("player_progress") -> slider(), &me2);
  964. }
  965. sliderAction ("player_progress") -> slider() -> setEnabled (busy);
  966. m_updating = false;
  967. action ("audio_volume_up") -> setEnabled (unpaused);
  968. action ("audio_volume_down") -> setEnabled (unpaused);
  969. action ("audio_mute") -> setEnabled (unpaused);
  970. if ( ! light() )
  971. {
  972. action ("player_soft_frame_drop") -> setEnabled (unpaused);
  973. action ("player_hard_frame_drop") -> setEnabled (unpaused);
  974. }
  975. action ("popup_volume") -> setEnabled (unpaused);
  976. sliderAction ("audio_volume") -> slider() -> setEnabled (unpaused);
  977. }
  978. void KPlayerEngine::enableVideoActions (void)
  979. {
  980. if ( ! m_ac )
  981. return;
  982. #ifdef DEBUG_KPLAYER_ENGINE
  983. kdDebugTime() << "Engine: Enabling video actions\n";
  984. #endif
  985. bool video = properties() -> hasVideo();
  986. action ("view_maintain_aspect") -> setEnabled (video);
  987. if ( light() )
  988. return;
  989. action ("view_full_screen") -> setEnabled (video || settings() -> fullScreen());
  990. action ("view_original_aspect") -> setEnabled (video);
  991. action ("view_current_aspect") -> setEnabled (video);
  992. action ("view_aspect_4_3") -> setEnabled (video);
  993. action ("view_aspect_16_9") -> setEnabled (video);
  994. bool unpaused = video && kPlayerProcess() -> state() != KPlayerProcess::Paused;
  995. action ("audio_delay_up") -> setEnabled (unpaused);
  996. action ("audio_delay_down") -> setEnabled (unpaused);
  997. action ("video_contrast_up") -> setEnabled (unpaused);
  998. action ("video_contrast_down") -> setEnabled (unpaused);
  999. action ("video_brightness_up") -> setEnabled (unpaused);
  1000. action ("video_brightness_down") -> setEnabled (unpaused);
  1001. action ("video_hue_up") -> setEnabled (unpaused);
  1002. action ("video_hue_down") -> setEnabled (unpaused);
  1003. action ("video_saturation_up") -> setEnabled (unpaused);
  1004. action ("video_saturation_down") -> setEnabled (unpaused);
  1005. action ("popup_contrast") -> setEnabled (unpaused);
  1006. action ("popup_brightness") -> setEnabled (unpaused);
  1007. action ("popup_hue") -> setEnabled (unpaused);
  1008. action ("popup_saturation") -> setEnabled (unpaused);
  1009. sliderAction ("video_contrast") -> slider() -> setEnabled (unpaused);
  1010. sliderAction ("video_brightness") -> slider() -> setEnabled (unpaused);
  1011. sliderAction ("video_hue") -> slider() -> setEnabled (unpaused);
  1012. sliderAction ("video_saturation") -> slider() -> setEnabled (unpaused);
  1013. enableZoomActions();
  1014. enableSubtitleActions();
  1015. }
  1016. void KPlayerEngine::enableSubtitleActions (void)
  1017. {
  1018. if ( ! m_ac || light() )
  1019. return;
  1020. #ifdef DEBUG_KPLAYER_ENGINE
  1021. kdDebugTime() << "Engine: Enabling subtitle actions\n";
  1022. #endif
  1023. bool video = properties() -> hasVideo();
  1024. bool subtitles = video && settings() -> showSubtitles();
  1025. bool playing = subtitles && kPlayerProcess() -> state() == KPlayerProcess::Playing;
  1026. action ("subtitles_load") -> setEnabled (video);
  1027. //action ("subtitles_load_url") -> setEnabled (video);
  1028. //action ("subtitles_unload") -> setEnabled (subtitles);
  1029. action ("subtitles_move_down") -> setEnabled (playing);
  1030. action ("subtitles_move_up") -> setEnabled (playing);
  1031. action ("subtitles_delay_decrease") -> setEnabled (playing);
  1032. action ("subtitles_delay_increase") -> setEnabled (playing);
  1033. }
  1034. void KPlayerEngine::enableZoomActions (void)
  1035. {
  1036. if ( ! m_ac || light() )
  1037. return;
  1038. #ifdef DEBUG_KPLAYER_ENGINE
  1039. kdDebugTime() << "Engine: Enabling zoom actions\n";
  1040. #endif
  1041. toggleAction ("view_zoom_1_2") -> setChecked (settings() -> isZoomFactor (1, 2));
  1042. toggleAction ("view_zoom_1_1") -> setChecked (settings() -> isZoomFactor (1));
  1043. toggleAction ("view_zoom_3_2") -> setChecked (settings() -> isZoomFactor (3, 2));
  1044. toggleAction ("view_zoom_2_1") -> setChecked (settings() -> isZoomFactor (2));
  1045. toggleAction ("view_zoom_5_2") -> setChecked (settings() -> isZoomFactor (5, 2));
  1046. toggleAction ("view_zoom_3_1") -> setChecked (settings() -> isZoomFactor (3));
  1047. bool canZoom = ! settings() -> fullScreen() && properties() -> hasVideo();
  1048. #ifdef DEBUG_KPLAYER_ENGINE
  1049. if ( settings() -> fullScreen() )
  1050. kdDebugTime() << "Full screen, no zoom\n";
  1051. if ( ! properties() -> hasVideo() )
  1052. kdDebugTime() << "Video size empty, no zoom\n";
  1053. #endif
  1054. toggleAction ("view_zoom_in") -> setEnabled (canZoom);
  1055. toggleAction ("view_zoom_out") -> setEnabled (canZoom);
  1056. toggleAction ("view_zoom_1_2") -> setEnabled (canZoom);
  1057. toggleAction ("view_zoom_1_1") -> setEnabled (canZoom);
  1058. toggleAction ("view_zoom_3_2") -> setEnabled (canZoom);
  1059. toggleAction ("view_zoom_2_1") -> setEnabled (canZoom);
  1060. toggleAction ("view_zoom_5_2") -> setEnabled (canZoom);
  1061. toggleAction ("view_zoom_3_1") -> setEnabled (canZoom);
  1062. }
  1063. void KPlayerEngine::disableScreenSaver (void)
  1064. {
  1065. if ( ! properties() -> hasVideo() )
  1066. return;
  1067. TQByteArray data, reply;
  1068. TQCString type;
  1069. if ( ! kapp -> dcopClient() -> call ("kdesktop", "KScreensaverIface", "isEnabled()", data, type, reply)
  1070. || type != "bool" )
  1071. {
  1072. #ifdef DEBUG_KPLAYER_ENGINE
  1073. kdDebugTime() << "Could not get screen saver status\n";
  1074. #endif
  1075. return;
  1076. }
  1077. TQDataStream replyStream (reply, IO_ReadOnly);
  1078. bool enabled = false;
  1079. replyStream >> enabled;
  1080. if ( ! enabled )
  1081. {
  1082. #ifdef DEBUG_KPLAYER_ENGINE
  1083. kdDebugTime() << "Screen saver is not enabled\n";
  1084. #endif
  1085. return;
  1086. }
  1087. TQDataStream argStream (data, IO_WriteOnly);
  1088. argStream << false;
  1089. #ifdef DEBUG_KPLAYER_ENGINE
  1090. if ( kapp -> dcopClient() -> send ("kdesktop", "KScreensaverIface", "enable(bool)", data) )
  1091. kdDebugTime() << "Screensaver successfully disabled\n";
  1092. else
  1093. kdWarning() << "Could not disable screensaver\n";
  1094. #else
  1095. kapp -> dcopClient() -> send ("kdesktop", "KScreensaverIface", "enable(bool)", data);
  1096. #endif
  1097. m_enable_screen_saver = true;
  1098. }
  1099. void KPlayerEngine::enableScreenSaver (void)
  1100. {
  1101. if ( ! m_enable_screen_saver )
  1102. return;
  1103. TQByteArray data;
  1104. TQDataStream argStream (data, IO_WriteOnly);
  1105. argStream << true;
  1106. #ifdef DEBUG_KPLAYER_ENGINE
  1107. if ( kapp -> dcopClient() -> send ("kdesktop", "KScreensaverIface", "enable(bool)", data) )
  1108. kdDebugTime() << "Screensaver successfully enabled\n";
  1109. else
  1110. kdWarning() << "Could not enable screensaver\n";
  1111. #else
  1112. kapp -> dcopClient() -> send ("kdesktop", "KScreensaverIface", "enable(bool)", data);
  1113. #endif
  1114. m_enable_screen_saver = false;
  1115. }
  1116. bool isReadableFile (const TQString& path)
  1117. {
  1118. TQFileInfo info (path);
  1119. return info.exists() && info.isReadable() && ! info.isDir();
  1120. }
  1121. void KPlayerEngine::startPlaying (void)
  1122. {
  1123. #ifdef DEBUG_KPLAYER_ENGINE
  1124. kdDebugTime() << "Engine::startPlaying\n";
  1125. #endif
  1126. m_play_pending = m_stop = false;
  1127. m_last_volume = settings() -> volume();
  1128. if ( properties() -> audioDriverString().startsWith ("alsa") )
  1129. getAlsaVolume();
  1130. if ( settings() -> showSubtitles() )
  1131. if ( ! properties() -> originalSizeKnown() && process() -> gettingInfo() )
  1132. {
  1133. m_play_pending = true;
  1134. return;
  1135. }
  1136. else if ( properties() -> needsExpanding() )
  1137. autoexpand();
  1138. if ( properties() -> originalSizeKnown() )
  1139. setDisplaySize();
  1140. process() -> play();
  1141. }
  1142. void KPlayerEngine::load (KURL url)
  1143. {
  1144. #ifdef DEBUG_KPLAYER_ENGINE
  1145. kdDebugTime() << "Engine::load (" << url.prettyURL() << ")\n";
  1146. #endif
  1147. if ( ! m_ac || url.path().isEmpty() && url.host().isEmpty() )
  1148. return;
  1149. m_last_volume = settings() -> volume();
  1150. if ( url == properties() -> url() )
  1151. {
  1152. if ( properties() -> audioDriverString().startsWith ("alsa") )
  1153. getAlsaVolume();
  1154. play();
  1155. return;
  1156. }
  1157. kill();
  1158. if ( settings() -> shift() )
  1159. stop();
  1160. else
  1161. m_stop = false;
  1162. m_play_pending = false;
  1163. if ( settings() -> properties() )
  1164. disconnect (settings() -> properties(), SIGNAL (updated()), this, SLOT (refreshProperties()));
  1165. settings() -> load (url);
  1166. process() -> load (url);
  1167. connect (settings() -> properties(), SIGNAL (updated()), this, SLOT (refreshProperties()));
  1168. playerProgressChanged (0, KPlayerProcess::Position);
  1169. settings() -> clearSubtitles();
  1170. if ( properties() -> subtitleAutoload() )
  1171. autoloadSubtitles();
  1172. if ( properties() -> hasSubtitleUrl() && isReadableFile (properties() -> subtitleUrlString()) )
  1173. settings() -> addSubtitlePath (properties() -> subtitleUrlString());
  1174. refreshProperties();
  1175. if ( properties() -> originalSizeKnown() )
  1176. playerSizeAvailable();
  1177. if ( properties() -> hasLength() )
  1178. playerInfoAvailable();
  1179. if ( ! properties() -> hasLength() || ! properties() -> originalSizeKnown() )
  1180. process() -> get_info();
  1181. if ( ! m_stop )
  1182. startPlaying();
  1183. #ifdef DEBUG_KPLAYER_ENGINE
  1184. else
  1185. kdDebugTime() << "Engine::load: shift pressed, not starting playback\n";
  1186. #endif
  1187. }
  1188. void KPlayerEngine::autoloadSubtitles (void)
  1189. {
  1190. #ifdef DEBUG_KPLAYER_ENGINE
  1191. kdDebugTime() << "Autoloading subtitles\n";
  1192. #endif
  1193. if ( ! properties() -> url().isLocalFile() )
  1194. return;
  1195. TQString urls (properties() -> subtitleUrlString());
  1196. TQStringList exts (configuration() -> subtitleExtensions());
  1197. TQString filename (properties() -> url().fileName());
  1198. TQString basename (filename.section ('.', 0, -2));
  1199. TQDir dir (properties() -> url().directory(), TQString::null, TQDir::Name | TQDir::IgnoreCase, TQDir::Files);
  1200. #ifdef DEBUG_KPLAYER_ENGINE
  1201. kdDebugTime() << " File name " << filename << "\n";
  1202. kdDebugTime() << " Base name " << basename << "\n";
  1203. #endif
  1204. const TQFileInfoList* list = dir.entryInfoList();
  1205. if ( list )
  1206. {
  1207. #ifdef DEBUG_KPLAYER_ENGINE
  1208. kdDebugTime() << " Directory " << dir.path() << "\n";
  1209. #endif
  1210. TQFileInfoListIterator fileinfoiterator (*list);
  1211. while ( TQFileInfo* info = fileinfoiterator.current() )
  1212. {
  1213. TQString name (info -> fileName());
  1214. if ( name != filename && info -> filePath() != urls && name.startsWith (basename, false)
  1215. && info -> exists() && info -> isReadable() && ! info -> isDir() )
  1216. {
  1217. TQStringList::ConstIterator extiterator (exts.constBegin());
  1218. while ( extiterator != exts.constEnd() )
  1219. {
  1220. if ( name.endsWith (*extiterator, false) )
  1221. {
  1222. #ifdef DEBUG_KPLAYER_ENGINE
  1223. kdDebugTime() << " Autoloaded " << info -> filePath() << "\n";
  1224. #endif
  1225. settings() -> addSubtitlePath (info -> filePath());
  1226. break;
  1227. }
  1228. ++ extiterator;
  1229. }
  1230. }
  1231. ++ fileinfoiterator;
  1232. }
  1233. }
  1234. }
  1235. void KPlayerEngine::autoexpand (void)
  1236. {
  1237. #ifdef DEBUG_KPLAYER_ENGINE
  1238. kdDebugTime() << "Engine::autoexpand\n";
  1239. #endif
  1240. properties() -> autoexpand();
  1241. if ( settings() -> setInitialDisplaySize() )
  1242. {
  1243. emit initialSize();
  1244. setDisplaySize();
  1245. enableVideoActions();
  1246. refreshAspect();
  1247. }
  1248. }
  1249. void KPlayerEngine::showSubtitles (void)
  1250. {
  1251. #ifdef DEBUG_KPLAYER_ENGINE
  1252. kdDebugTime() << "Engine::showSubtitles\n";
  1253. #endif
  1254. if ( settings() -> hasSubtitles() )
  1255. {
  1256. if ( settings() -> showSubtitles() && properties() -> needsExpanding() )
  1257. {
  1258. autoexpand();
  1259. process() -> restart();
  1260. }
  1261. else
  1262. process() -> subtitles();
  1263. enableSubtitleActions();
  1264. }
  1265. }
  1266. bool KPlayerEngine::loadSubtitles (const KURL::List& urls, bool checkExtensions)
  1267. {
  1268. #ifdef DEBUG_KPLAYER_ENGINE
  1269. kdDebugTime() << "Engine::loadSubtitles\n";
  1270. #endif
  1271. if ( urls.isEmpty() || properties() -> url().isEmpty() )
  1272. return false;
  1273. TQStringList exts (configuration() -> subtitleExtensions());
  1274. KURL::List::ConstIterator urliterator (urls.begin());
  1275. while ( urliterator != urls.end() )
  1276. {
  1277. const KURL& url (*urliterator);
  1278. if ( ! url.isLocalFile() )
  1279. return false;
  1280. TQString path (url.path());
  1281. if ( path.isEmpty() )
  1282. return false;
  1283. TQFileInfo info (path);
  1284. if ( ! info.exists() || ! info.isReadable() || info.isDir() )
  1285. return false;
  1286. if ( checkExtensions )
  1287. {
  1288. TQStringList::ConstIterator extiterator (exts.constBegin());
  1289. while ( extiterator != exts.constEnd() )
  1290. {
  1291. if ( path.endsWith (*extiterator, false) )
  1292. break;
  1293. ++ extiterator;
  1294. }
  1295. if ( extiterator == exts.constEnd() )
  1296. return false;
  1297. }
  1298. ++ urliterator;
  1299. }
  1300. urliterator = urls.begin();
  1301. while ( urliterator != urls.end() )
  1302. {
  1303. settings() -> addSubtitlePath ((*urliterator).path());
  1304. ++ urliterator;
  1305. }
  1306. const KURL& url = urls.first();
  1307. if ( url != properties() -> subtitleUrl() )
  1308. {
  1309. properties() -> showSubtitleUrl (url);
  1310. properties() -> commit();
  1311. showSubtitles();
  1312. }
  1313. return true;
  1314. }
  1315. void KPlayerEngine::fileOpenSubtitles (void)
  1316. {
  1317. loadSubtitles (openSubtitles());
  1318. }
  1319. void KPlayerEngine::fileProperties (void)
  1320. {
  1321. if ( properties() -> url().isValid() )
  1322. {
  1323. KPlayerPropertiesDialog* dialog = KPlayerPropertiesDialog::createDialog (properties());
  1324. dialog -> setup (properties() -> url());
  1325. dialog -> exec();
  1326. delete dialog;
  1327. }
  1328. }
  1329. void KPlayerEngine::fullScreen (void)
  1330. {
  1331. settings() -> setFullScreen (toggleAction ("view_full_screen") -> isChecked());
  1332. #ifdef DEBUG_KPLAYER_ENGINE
  1333. kdDebugTime() << "Engine::fullScreen (" << settings() -> fullScreen() << ")\n";
  1334. #endif
  1335. m_zooming = true;
  1336. emit syncronize (false);
  1337. }
  1338. void KPlayerEngine::normal (void)
  1339. {
  1340. settings() -> setMaximized (false);
  1341. settings() -> setFullScreen (false);
  1342. toggleAction ("view_full_screen") -> setChecked (false);
  1343. }
  1344. void KPlayerEngine::zoomIn (void)
  1345. {
  1346. if ( ! properties() -> hasOriginalSize() )
  1347. return;
  1348. normal();
  1349. settings() -> setDisplaySize (settings() -> displaySize() + properties() -> currentSize() / 2);
  1350. setDisplaySize (true);
  1351. }
  1352. void KPlayerEngine::zoomOut (void)
  1353. {
  1354. if ( ! properties() -> hasOriginalSize() )
  1355. return;
  1356. normal();
  1357. settings() -> setDisplaySize (settings() -> displaySize() - properties() -> currentSize() / 2);
  1358. setDisplaySize (true);
  1359. }
  1360. void KPlayerEngine::zoomTo (int m, int d)
  1361. {
  1362. if ( ! properties() -> hasOriginalSize() )
  1363. return;
  1364. normal();
  1365. settings() -> setDisplaySize (properties() -> currentSize() * m / d);
  1366. setDisplaySize (true);
  1367. }
  1368. void KPlayerEngine::zoom12 (void)
  1369. {
  1370. zoomTo (1, 2);
  1371. }
  1372. void KPlayerEngine::zoom11 (void)
  1373. {
  1374. zoomTo (1);
  1375. }
  1376. void KPlayerEngine::zoom32 (void)
  1377. {
  1378. zoomTo (3, 2);
  1379. }
  1380. void KPlayerEngine::zoom21 (void)
  1381. {
  1382. zoomTo (2);
  1383. }
  1384. void KPlayerEngine::zoom52 (void)
  1385. {
  1386. zoomTo (5, 2);
  1387. }
  1388. void KPlayerEngine::zoom31 (void)
  1389. {
  1390. zoomTo (3);
  1391. }
  1392. void KPlayerEngine::wheel (int delta, int state)
  1393. {
  1394. if ( ! settings() -> maximized() && ! settings() -> fullScreen() && properties() -> hasOriginalSize() )
  1395. {
  1396. settings() -> setDisplaySize (settings() -> displaySize() + properties() -> currentSize() * delta / 1200);
  1397. setDisplaySize (true);
  1398. }
  1399. else if ( (state & TQt::ControlButton) == TQt::ControlButton )
  1400. {
  1401. if ( delta >= 0 )
  1402. fastForward();
  1403. else
  1404. fastBackward();
  1405. }
  1406. else
  1407. {
  1408. if ( delta >= 0 )
  1409. forward();
  1410. else
  1411. backward();
  1412. }
  1413. }
  1414. void KPlayerEngine::doubleClick (void)
  1415. {
  1416. if ( stopped() || ! properties() -> hasVideo() || light() )
  1417. return;
  1418. settings() -> setFullScreen (! settings() -> fullScreen());
  1419. #ifdef DEBUG_KPLAYER_ENGINE
  1420. kdDebugTime() << "Engine::doubleClick (" << settings() -> fullScreen() << ")\n";
  1421. #endif
  1422. m_zooming = true;
  1423. emit syncronize (false);
  1424. }
  1425. void KPlayerEngine::emitWindowStateChanged (uint wid)
  1426. {
  1427. #ifdef DEBUG_KPLAYER_ENGINE
  1428. kdDebugTime() << "Engine::emitWindowStateChanged (" << wid << ")\n";
  1429. #endif
  1430. emit windowStateChanged (wid);
  1431. }
  1432. void KPlayerEngine::maintainAspect (void)
  1433. {
  1434. maintainAspect (toggleAction ("view_maintain_aspect") -> isChecked(), properties() -> currentAspect());
  1435. }
  1436. void KPlayerEngine::maintainOriginalAspect (void)
  1437. {
  1438. maintainAspect (toggleAction ("view_original_aspect") -> isChecked(), properties() -> originalSize());
  1439. }
  1440. void KPlayerEngine::maintainCurrentAspect (void)
  1441. {
  1442. maintainAspect (toggleAction ("view_current_aspect") -> isChecked(), settings() -> displaySize());
  1443. if ( settings() -> maintainAspect() )
  1444. toggleAction ("view_current_aspect") -> setChecked (true);
  1445. }
  1446. void KPlayerEngine::aspect43 (void)
  1447. {
  1448. maintainAspect (toggleAction ("view_aspect_4_3") -> isChecked(), TQSize (4, 3));
  1449. if ( settings() -> maintainAspect() )
  1450. toggleAction ("view_aspect_4_3") -> setChecked (true);
  1451. }
  1452. void KPlayerEngine::aspect169 (void)
  1453. {
  1454. maintainAspect (toggleAction ("view_aspect_16_9") -> isChecked(), TQSize (16, 9));
  1455. if ( settings() -> maintainAspect() )
  1456. toggleAction ("view_aspect_16_9") -> setChecked (true);
  1457. }
  1458. void KPlayerEngine::play (void)
  1459. {
  1460. if ( process() -> state() == KPlayerProcess::Paused )
  1461. process() -> pause();
  1462. else if ( process() -> state() == KPlayerProcess::Idle )
  1463. {
  1464. if ( settings() -> shift() )
  1465. kill();
  1466. startPlaying();
  1467. }
  1468. }
  1469. void KPlayerEngine::pause (void)
  1470. {
  1471. if ( process() -> state() != KPlayerProcess::Idle )
  1472. process() -> pause();
  1473. else
  1474. {
  1475. TDEToggleAction* action = toggleAction ("player_pause");
  1476. if ( action -> isChecked() )
  1477. action -> setChecked (false);
  1478. }
  1479. }
  1480. void KPlayerEngine::stop (void)
  1481. {
  1482. m_stop = true;
  1483. m_play_pending = false;
  1484. process() -> stop();
  1485. setDisplaySize();
  1486. }
  1487. void KPlayerEngine::kill (void)
  1488. {
  1489. m_stop = true;
  1490. m_play_pending = false;
  1491. process() -> kill();
  1492. }
  1493. void KPlayerEngine::forward (void)
  1494. {
  1495. process() -> relativeSeek (properties() -> normalSeek());
  1496. }
  1497. void KPlayerEngine::fastForward (void)
  1498. {
  1499. process() -> relativeSeek (properties() -> fastSeek());
  1500. }
  1501. void KPlayerEngine::backward (void)
  1502. {
  1503. process() -> relativeSeek (- properties() -> normalSeek());
  1504. }
  1505. void KPlayerEngine::fastBackward (void)
  1506. {
  1507. process() -> relativeSeek (- properties() -> fastSeek());
  1508. }
  1509. void KPlayerEngine::start (void)
  1510. {
  1511. process() -> absoluteSeek (0);
  1512. }
  1513. void KPlayerEngine::progressChanged (int progress)
  1514. {
  1515. if ( m_updating || ! m_progress_factor )
  1516. return;
  1517. #ifdef DEBUG_KPLAYER_ENGINE
  1518. kdDebugTime() << "Seek to " << progress << ": " << process() -> position() << " => " << ((progress + m_progress_factor / 2) / m_progress_factor) << " / " << properties() -> length() << "\n";
  1519. #endif
  1520. process() -> absoluteSeek ((progress + m_progress_factor / 2) / m_progress_factor);
  1521. }
  1522. void KPlayerEngine::volumeChanged (int volume)
  1523. {
  1524. if ( m_updating )
  1525. return;
  1526. settings() -> setVolume (volume);
  1527. setVolume();
  1528. }
  1529. void KPlayerEngine::contrastChanged (int contrast)
  1530. {
  1531. if ( m_updating )
  1532. return;
  1533. settings() -> setContrast (contrast);
  1534. setContrast();
  1535. }
  1536. void KPlayerEngine::brightnessChanged (int brightness)
  1537. {
  1538. if ( m_updating )
  1539. return;
  1540. settings() -> setBrightness (brightness);
  1541. setBrightness();
  1542. }
  1543. void KPlayerEngine::hueChanged (int hue)
  1544. {
  1545. if ( m_updating )
  1546. return;
  1547. settings() -> setHue (hue);
  1548. setHue();
  1549. }
  1550. void KPlayerEngine::saturationChanged (int saturation)
  1551. {
  1552. if ( m_updating )
  1553. return;
  1554. settings() -> setSaturation (saturation);
  1555. setSaturation();
  1556. }
  1557. void KPlayerEngine::setVolume (void)
  1558. {
  1559. m_updating = true;
  1560. int volume = settings() -> volume();
  1561. sliderAction ("audio_volume") -> slider() -> setValue (volume);
  1562. popupAction ("popup_volume") -> slider() -> setValue (volume);
  1563. process() -> volume (settings() -> actualVolume());
  1564. m_updating = false;
  1565. }
  1566. void KPlayerEngine::setContrast (void)
  1567. {
  1568. m_updating = true;
  1569. int contrast = settings() -> contrast();
  1570. process() -> contrast (contrast);
  1571. if ( ! light() )
  1572. {
  1573. sliderAction ("video_contrast") -> slider() -> setValue (contrast);
  1574. popupAction ("popup_contrast") -> slider() -> setValue (contrast);
  1575. }
  1576. m_updating = false;
  1577. }
  1578. void KPlayerEngine::setBrightness (void)
  1579. {
  1580. m_updating = true;
  1581. int brightness = settings() -> brightness();
  1582. process() -> brightness (brightness);
  1583. if ( ! light() )
  1584. {
  1585. sliderAction ("video_brightness") -> slider() -> setValue (brightness);
  1586. popupAction ("popup_brightness") -> slider() -> setValue (brightness);
  1587. }
  1588. m_updating = false;
  1589. }
  1590. void KPlayerEngine::setHue (void)
  1591. {
  1592. m_updating = true;
  1593. int hue = settings() -> hue();
  1594. process() -> hue (hue);
  1595. if ( ! light() )
  1596. {
  1597. sliderAction ("video_hue") -> slider() -> setValue (hue);
  1598. popupAction ("popup_hue") -> slider() -> setValue (hue);
  1599. }
  1600. m_updating = false;
  1601. }
  1602. void KPlayerEngine::setSaturation (void)
  1603. {
  1604. m_updating = true;
  1605. int saturation = settings() -> saturation();
  1606. process() -> saturation (saturation);
  1607. if ( ! light() )
  1608. {
  1609. sliderAction ("video_saturation") -> slider() -> setValue (saturation);
  1610. popupAction ("popup_saturation") -> slider() -> setValue (saturation);
  1611. }
  1612. m_updating = false;
  1613. }
  1614. void KPlayerEngine::volumeIncrease (void)
  1615. {
  1616. settings() -> setVolume (settings() -> volume() + configuration() -> volumeStep());
  1617. setVolume();
  1618. }
  1619. void KPlayerEngine::volumeDecrease (void)
  1620. {
  1621. settings() -> setVolume (settings() -> volume() - configuration() -> volumeStep());
  1622. setVolume();
  1623. }
  1624. void KPlayerEngine::mute (void)
  1625. {
  1626. configuration() -> setMute (toggleAction ("audio_mute") -> isChecked());
  1627. process() -> volume (settings() -> actualVolume());
  1628. }
  1629. void KPlayerEngine::audioDelayIncrease (void)
  1630. {
  1631. settings() -> setAudioDelay (settings() -> audioDelay() + configuration() -> audioDelayStep());
  1632. process() -> audioDelay (configuration() -> audioDelayStep());
  1633. }
  1634. void KPlayerEngine::audioDelayDecrease (void)
  1635. {
  1636. settings() -> setAudioDelay (settings() -> audioDelay() - configuration() -> audioDelayStep());
  1637. process() -> audioDelay (- configuration() -> audioDelayStep());
  1638. }
  1639. void KPlayerEngine::audioStream (int index)
  1640. {
  1641. #ifdef DEBUG_KPLAYER_ENGINE
  1642. kdDebugTime() << "KPlayerEngine::audioStream\n";
  1643. kdDebugTime() << " Index " << index << "\n";
  1644. #endif
  1645. properties() -> setAudioIDOption (index + 1);
  1646. m_last_volume = settings() -> volume();
  1647. if ( properties() -> audioDriverString().startsWith ("alsa") )
  1648. getAlsaVolume();
  1649. process() -> audioID (properties() -> audioID());
  1650. }
  1651. void KPlayerEngine::videoStream (int index)
  1652. {
  1653. #ifdef DEBUG_KPLAYER_ENGINE
  1654. kdDebugTime() << "KPlayerEngine::videoStream\n";
  1655. kdDebugTime() << " Index " << index << "\n";
  1656. #endif
  1657. properties() -> setVideoIDOption (index + 1);
  1658. m_last_volume = settings() -> volume();
  1659. if ( properties() -> audioDriverString().startsWith ("alsa") )
  1660. getAlsaVolume();
  1661. process() -> restart();
  1662. }
  1663. void KPlayerEngine::subtitleStream (int index)
  1664. {
  1665. if ( index || settings() -> showSubtitles() )
  1666. {
  1667. int count = properties() -> subtitleIDs().count() + properties() -> vobsubIDs().count();
  1668. if ( index > count )
  1669. properties() -> setSubtitleUrl (settings() -> subtitles() [index - count - 1]);
  1670. properties() -> setSubtitleOption (index);
  1671. showSubtitles();
  1672. }
  1673. }
  1674. void KPlayerEngine::softFrameDrop (void)
  1675. {
  1676. int drop = toggleAction ("player_soft_frame_drop") -> isChecked() ? 1 : 0;
  1677. settings() -> setFrameDrop (drop);
  1678. process() -> frameDrop (drop);
  1679. }
  1680. void KPlayerEngine::hardFrameDrop (void)
  1681. {
  1682. int drop = toggleAction ("player_hard_frame_drop") -> isChecked() ? 2 : 0;
  1683. settings() -> setFrameDrop (drop);
  1684. process() -> frameDrop (drop);
  1685. }
  1686. void KPlayerEngine::subtitlesMoveDown (void)
  1687. {
  1688. settings() -> setSubtitlePosition (settings() -> subtitlePosition() + configuration() -> subtitlePositionStep());
  1689. process() -> subtitleMove (configuration() -> subtitlePositionStep());
  1690. }
  1691. void KPlayerEngine::subtitlesMoveUp (void)
  1692. {
  1693. settings() -> setSubtitlePosition (settings() -> subtitlePosition() - configuration() -> subtitlePositionStep());
  1694. process() -> subtitleMove (- configuration() -> subtitlePositionStep());
  1695. }
  1696. void KPlayerEngine::subtitlesDelayDecrease (void)
  1697. {
  1698. settings() -> setSubtitleDelay (settings() -> subtitleDelay() - configuration() -> subtitleDelayStep());
  1699. process() -> subtitleDelay (- configuration() -> subtitleDelayStep());
  1700. }
  1701. void KPlayerEngine::subtitlesDelayIncrease (void)
  1702. {
  1703. settings() -> setSubtitleDelay (settings() -> subtitleDelay() + configuration() -> subtitleDelayStep());
  1704. process() -> subtitleDelay (configuration() -> subtitleDelayStep());
  1705. }
  1706. void KPlayerEngine::contrastIncrease (void)
  1707. {
  1708. settings() -> setContrast (settings() -> contrast() + configuration() -> contrastStep());
  1709. setContrast();
  1710. }
  1711. void KPlayerEngine::contrastDecrease (void)
  1712. {
  1713. settings() -> setContrast (settings() -> contrast() - configuration() -> contrastStep());
  1714. setContrast();
  1715. }
  1716. void KPlayerEngine::brightnessIncrease (void)
  1717. {
  1718. settings() -> setBrightness (settings() -> brightness() + configuration() -> brightnessStep());
  1719. setBrightness();
  1720. }
  1721. void KPlayerEngine::brightnessDecrease (void)
  1722. {
  1723. settings() -> setBrightness (settings() -> brightness() - configuration() -> brightnessStep());
  1724. setBrightness();
  1725. }
  1726. void KPlayerEngine::hueIncrease (void)
  1727. {
  1728. settings() -> setHue (settings() -> hue() + configuration() -> hueStep());
  1729. setHue();
  1730. }
  1731. void KPlayerEngine::hueDecrease (void)
  1732. {
  1733. settings() -> setHue (settings() -> hue() - configuration() -> hueStep());
  1734. setHue();
  1735. }
  1736. void KPlayerEngine::saturationIncrease (void)
  1737. {
  1738. settings() -> setSaturation (settings() -> saturation() + configuration() -> saturationStep());
  1739. setSaturation();
  1740. }
  1741. void KPlayerEngine::saturationDecrease (void)
  1742. {
  1743. settings() -> setSaturation (settings() -> saturation() - configuration() -> saturationStep());
  1744. setSaturation();
  1745. }
  1746. KURL::List KPlayerEngine::openFiles (const TQString& title, TQWidget* parent)
  1747. {
  1748. static TQString filter = i18n("*|All files\n*.avi *.AVI|AVI files\n*.mpg *.mpeg *.MPG *.MPEG|MPEG files\n*.ogg *.OGG|OGG files\n*.mp3 *.MP3|MP3 files");
  1749. TDEConfig* config = kPlayerConfig();
  1750. config -> setGroup ("Dialog Options");
  1751. TQString dir = config -> readPathEntry ("Open File Directory");
  1752. //Saving dialog position did not work: dlg.pos() returns wrong position in TQt 3.1.1
  1753. //int x = config -> readNumEntry ("Open File Left");
  1754. //int y = config -> readNumEntry ("Open File Top");
  1755. int width = config -> readNumEntry ("Open File Width");
  1756. int height = config -> readNumEntry ("Open File Height");
  1757. #ifdef DEBUG_KPLAYER_ENGINE
  1758. //kdDebugTime() << "Geometry " << x << "x" << y << " " << width << "x" << height << "\n";
  1759. #endif
  1760. KPlayerFileDialog dlg (dir, filter, parent, "filedialog");
  1761. dlg.setOperationMode (KFileDialog::Opening);
  1762. dlg.setMode (KFile::Files | KFile::ExistingOnly);
  1763. dlg.setCaption (title);
  1764. if ( width > 0 && height > 0 )
  1765. dlg.resize (width, height);
  1766. //dlg.setGeometry (x, y, width, height);
  1767. //dlg.move (x, y);
  1768. #ifdef DEBUG_KPLAYER_ENGINE
  1769. //kdDebugTime() << " " << dlg.x() << "x" << dlg.y() << " " << dlg.width() << "x" << dlg.height() << "\n";
  1770. #endif
  1771. dlg.exec();
  1772. config -> writePathEntry ("Open File Directory", dlg.directory());
  1773. //config -> writeEntry ("Open File Left", dlg.x());
  1774. //config -> writeEntry ("Open File Top", dlg.y());
  1775. config -> writeEntry ("Open File Width", dlg.width());
  1776. config -> writeEntry ("Open File Height", dlg.height());
  1777. #ifdef DEBUG_KPLAYER_ENGINE
  1778. //kdDebugTime() << "Geometry " << coord.x() << "x" << coord.y() << " " << dlg.width() << "x" << dlg.height() << "\n";
  1779. #endif
  1780. return dlg.selectedURLs();
  1781. }
  1782. KURL::List KPlayerEngine::openUrl (const TQString& title, TQWidget* parent)
  1783. {
  1784. KURL::List list;
  1785. TDEConfig* config = kPlayerConfig();
  1786. config -> setGroup ("Dialog Options");
  1787. TQString dir = config -> readEntry ("Open URL");
  1788. //int x = config -> readNumEntry ("Open URL Left");
  1789. //int y = config -> readNumEntry ("Open URL Top");
  1790. int width = config -> readNumEntry ("Open URL Width");
  1791. int height = config -> readNumEntry ("Open URL Height");
  1792. KURLRequesterDlg dlg (dir, parent, "filedialog", true);
  1793. dlg.setCaption (title);
  1794. if ( width > 0 && height > 0 )
  1795. dlg.resize (width, height);
  1796. //dlg.setGeometry (x, y, width, height);
  1797. dlg.exec();
  1798. KURL url (dlg.selectedURL());
  1799. if ( ! url.isEmpty() && url.isValid() )
  1800. {
  1801. list.append (url);
  1802. TDERecentDocument::add (url);
  1803. }
  1804. if ( dlg.result() == TQDialog::Accepted )
  1805. config -> writeEntry ("Open URL", url.isLocalFile() ? url.path() : url.url());
  1806. //config -> writeEntry ("Open URL Left", dlg.x());
  1807. //config -> writeEntry ("Open URL Top", dlg.y());
  1808. config -> writeEntry ("Open URL Width", dlg.width());
  1809. config -> writeEntry ("Open URL Height", dlg.height());
  1810. return list;
  1811. }
  1812. KURL::List KPlayerEngine::openSubtitles (TQWidget* parent)
  1813. {
  1814. static TQString filter = i18n("*|All files\n*.aqt *.AQT *.ass *.ASS *.js *.JS *.jss *.JSS *.rt *.RT *.smi *.SMI *.srt *.SRT *.ssa *.SSA *.sub *.SUB *.txt *.TXT *.utf *.UTF *.idx *.IDX *.ifo *.IFO|All subtitle files\n*.aqt *.AQT|AQT files\n*.ass *.ASS|ASS files\n*.js *.JS|JS files\n*.jss *.JSS|JSS files\n*.rt *.RT|RT files\n*.smi *.SMI|SMI files\n*.srt *.SRT|SRT files\n*.ssa *.SSA|SSA files\n*.sub *.SUB|SUB files\n*.txt *.TXT|TXT files\n*.utf *.UTF *.utf8 *.UTF8 *.utf-8 *.UTF-8|UTF files\n*.idx *.IDX *.ifo *.IFO|VobSub files");
  1815. TDEConfig* config = kPlayerConfig();
  1816. config -> setGroup ("Dialog Options");
  1817. TQString dir = config -> readEntry ("Open Subtitle Directory");
  1818. //int x = config -> readNumEntry ("Open Subtitle Left");
  1819. //int y = config -> readNumEntry ("Open Subtitle Top");
  1820. int width = config -> readNumEntry ("Open Subtitle Width");
  1821. int height = config -> readNumEntry ("Open Subtitle Height");
  1822. KPlayerFileDialog dlg (dir, filter, parent, "filedialog");
  1823. dlg.setOperationMode (KFileDialog::Opening);
  1824. dlg.setMode (KFile::Files | KFile::ExistingOnly);
  1825. dlg.setCaption (i18n("Load Subtitles"));
  1826. if ( width > 0 && height > 0 )
  1827. dlg.resize (width, height);
  1828. //dlg.setGeometry (x, y, width, height);
  1829. dlg.exec();
  1830. config -> writeEntry ("Open Subtitle Directory", dlg.directory());
  1831. //config -> writeEntry ("Open Subtitle Left", dlg.x());
  1832. //config -> writeEntry ("Open Subtitle Top", dlg.y());
  1833. config -> writeEntry ("Open Subtitle Width", dlg.width());
  1834. config -> writeEntry ("Open Subtitle Height", dlg.height());
  1835. return dlg.selectedURLs();
  1836. }
  1837. /*KURL KPlayerEngine::openSubtitleUrl (TQWidget* parent)
  1838. {
  1839. TDEConfig* config = kPlayerConfig();
  1840. config -> setGroup ("Dialog Options");
  1841. TQString dir = config -> readEntry ("Open Subtitle URL");
  1842. //int x = config -> readNumEntry ("Open Subtitle URL Left");
  1843. //int y = config -> readNumEntry ("Open Subtitle URL Top");
  1844. int width = config -> readNumEntry ("Open Subtitle URL Width");
  1845. int height = config -> readNumEntry ("Open Subtitle URL Height");
  1846. KURLRequesterDlg dlg (dir, parent, "filedialog", true);
  1847. dlg.setCaption (i18n("Open Subtitle URL"));
  1848. if ( width > 0 && height > 0 )
  1849. dlg.resize (width, height);
  1850. //dlg.setGeometry (x, y, width, height);
  1851. dlg.exec();
  1852. KURL url (dlg.selectedURL());
  1853. if ( ! url.isEmpty() && url.isValid() )
  1854. TDERecentDocument::add (url);
  1855. if ( dlg.result() == TQDialog::Accepted )
  1856. config -> writeEntry ("Open Subtitle URL", url.isLocalFile() ? url.path() : url.url());
  1857. //config -> writeEntry ("Open Subtitle URL Left", dlg.x());
  1858. //config -> writeEntry ("Open Subtitle URL Top", dlg.y());
  1859. config -> writeEntry ("Open Subtitle URL Width", dlg.width());
  1860. config -> writeEntry ("Open Subtitle URL Height", dlg.height());
  1861. return url;
  1862. }*/
  1863. void KPlayerEngine::getLists (TQString path)
  1864. {
  1865. if ( path.isEmpty() )
  1866. path = properties() -> executablePath();
  1867. if ( path == m_path )
  1868. return;
  1869. m_path = path;
  1870. #ifdef DEBUG_KPLAYER_ENGINE
  1871. kdDebugTime() << "KPlayerEngine::getLists (" << path << ")\n";
  1872. #endif
  1873. m_audio_codecs_ready = m_audio_drivers_ready = m_video_codecs_ready = m_video_drivers_ready = m_demuxers_ready = false;
  1874. KPlayerLineOutputProcess* player = new KPlayerLineOutputProcess;
  1875. *player << path << "-identify" << "-ac" << "help" << "-ao" << "help"
  1876. << "-vc" << "help" << "-vo" << "help" << "-demuxer" << "help";
  1877. connect (player, SIGNAL (receivedStdoutLine (KPlayerLineOutputProcess*, char*, int)),
  1878. SLOT (receivedOutput (KPlayerLineOutputProcess*, char*, int)));
  1879. connect (player, SIGNAL (processExited (TDEProcess*)), SLOT (processExited (TDEProcess*)));
  1880. player -> start (TDEProcess::NotifyOnExit, TDEProcess::All);
  1881. }
  1882. void KPlayerEngine::receivedOutput (KPlayerLineOutputProcess*, char* str, int)
  1883. {
  1884. if ( strcmp (str, "ID_VIDEO_OUTPUTS") == 0 )
  1885. {
  1886. m_video_drivers.clear();
  1887. m_video_drivers_ready = true;
  1888. m_audio_codecs_ready = m_audio_drivers_ready = m_video_codecs_ready = m_demuxers_ready = false;
  1889. }
  1890. else if ( strcmp (str, "ID_VIDEO_CODECS") == 0 )
  1891. {
  1892. m_video_codecs.clear();
  1893. m_video_codecs_ready = true;
  1894. m_audio_codecs_ready = m_audio_drivers_ready = m_video_drivers_ready = m_demuxers_ready = false;
  1895. }
  1896. else if ( strcmp (str, "ID_AUDIO_OUTPUTS") == 0 )
  1897. {
  1898. m_audio_drivers.clear();
  1899. m_audio_drivers_ready = true;
  1900. m_audio_codecs_ready = m_video_codecs_ready = m_video_drivers_ready = m_demuxers_ready = false;
  1901. }
  1902. else if ( strcmp (str, "ID_AUDIO_CODECS") == 0 )
  1903. {
  1904. m_audio_codecs.clear();
  1905. m_audio_codecs_ready = true;
  1906. m_audio_drivers_ready = m_video_codecs_ready = m_video_drivers_ready = m_demuxers_ready = false;
  1907. }
  1908. else if ( strcmp (str, "ID_DEMUXERS") == 0 )
  1909. {
  1910. m_demuxers.clear();
  1911. m_demuxers_ready = true;
  1912. m_audio_codecs_ready = m_audio_drivers_ready = m_video_codecs_ready = m_video_drivers_ready = false;
  1913. }
  1914. else if ( m_audio_codecs_ready && re_codec.search (str) >= 0 )
  1915. {
  1916. #ifdef DEBUG_KPLAYER_ENGINE
  1917. kdDebug() << str << "\n";
  1918. #endif
  1919. TQString desc (re_codec.cap(2));
  1920. desc.replace (re_multiple, " ");
  1921. desc.replace (re_trailing, "");
  1922. desc.replace (re_brackets, "");
  1923. desc.replace (re_parentheses, "");
  1924. desc.replace (re_audio, "");
  1925. desc.replace (re_s, "");
  1926. desc.replace (re_layer, "layer ");
  1927. desc.replace (re_speech, "WMA 9 Speech");
  1928. desc.replace (re_macintosh, "Macintosh Audio Comp. and Exp.");
  1929. m_audio_codecs += re_codec.cap(1) + ": " + desc;
  1930. }
  1931. else if ( m_audio_drivers_ready && re_driver.search (str) >= 0 )
  1932. {
  1933. #ifdef DEBUG_KPLAYER_ENGINE
  1934. kdDebug() << str << "\n";
  1935. #endif
  1936. TQString desc (re_driver.cap(2));
  1937. desc.replace (re_multiple, " ");
  1938. desc.replace (re_trailing, "");
  1939. desc.replace (re_brackets, "");
  1940. desc.replace (re_parentheses, "");
  1941. desc.replace (re_audio, "");
  1942. desc.replace (re_s, "");
  1943. desc.replace (re_layer, "layer ");
  1944. desc.replace (re_writer, "");
  1945. m_audio_drivers += re_driver.cap(1) + ": " + desc;
  1946. }
  1947. else if ( m_video_codecs_ready && re_codec.search (str) >= 0 )
  1948. {
  1949. #ifdef DEBUG_KPLAYER_ENGINE
  1950. kdDebug() << str << "\n";
  1951. #endif
  1952. TQString desc (re_codec.cap(2));
  1953. desc.replace (re_multiple, " ");
  1954. desc.replace (re_trailing, "");
  1955. desc.replace (re_brackets, "");
  1956. desc.replace (re_parentheses, "");
  1957. desc.replace (re_video, "");
  1958. desc.replace (re_s, "");
  1959. desc.replace (re_layer, "layer ");
  1960. desc.replace (re_amu, "AMU");
  1961. m_video_codecs += re_codec.cap(1) + ": " + desc;
  1962. }
  1963. else if ( m_video_drivers_ready && re_driver.search (str) >= 0 )
  1964. {
  1965. #ifdef DEBUG_KPLAYER_ENGINE
  1966. kdDebug() << str << "\n";
  1967. #endif
  1968. TQString desc (re_driver.cap(2));
  1969. desc.replace (re_multiple, " ");
  1970. desc.replace (re_trailing, "");
  1971. desc.replace (re_xv, "/XVideo");
  1972. desc.replace (re_vidix, "/VIDIX");
  1973. desc.replace (re_xover, "X11 overlay");
  1974. desc.replace (re_opengl, "OpenGL");
  1975. desc.replace (re_matrox, "Matrox overlay in");
  1976. desc.replace (re_matroxg, "");
  1977. desc.replace (re_brackets, "");
  1978. desc.replace (re_parentheses, "");
  1979. desc.replace (re_video, "");
  1980. desc.replace (re_s, "");
  1981. desc.replace (re_layer, "layer ");
  1982. desc.replace (re_dash, " ");
  1983. m_video_drivers += re_driver.cap(1) + ": " + desc;
  1984. }
  1985. else if ( m_demuxers_ready && re_demuxer.search (str) >= 0 )
  1986. {
  1987. #ifdef DEBUG_KPLAYER_ENGINE
  1988. kdDebug() << str << "\n";
  1989. #endif
  1990. TQString desc (re_demuxer.cap(2));
  1991. desc.replace (re_parentheses, "");
  1992. desc.replace (re_demux, "");
  1993. desc.replace (re_sega, "");
  1994. desc.replace (re_smjpeg, "SMJPEG");
  1995. desc.replace (re_tv_card, "TV card");
  1996. desc.replace (re_lmlm, "");
  1997. if ( desc == "mf" )
  1998. desc = "Image files";
  1999. m_demuxers += re_demuxer.cap(1) + ": " + desc;
  2000. }
  2001. }
  2002. void KPlayerEngine::processExited (TDEProcess* proc)
  2003. {
  2004. delete proc;
  2005. m_audio_codecs.sort();
  2006. m_audio_drivers.sort();
  2007. m_video_codecs.sort();
  2008. m_video_drivers.sort();
  2009. m_demuxers.sort();
  2010. if ( m_audio_codecs_ready || m_audio_drivers_ready || m_video_codecs_ready || m_video_drivers_ready || m_demuxers_ready )
  2011. emit updated();
  2012. }
  2013. void KPlayerEngine::maintainAspect (bool maintain, TQSize aspect)
  2014. {
  2015. #ifdef DEBUG_KPLAYER_ENGINE
  2016. kdDebugTime() << "Engine::maintainAspect (" << maintain << ", " << aspect.width() << "x" << aspect.height() << ")\n";
  2017. #endif
  2018. if ( aspect.isEmpty() )
  2019. maintain = false;
  2020. settings() -> setMaintainAspect (maintain, aspect);
  2021. refreshAspect();
  2022. setDisplaySize();
  2023. }
  2024. void KPlayerEngine::setDisplaySize (bool user_zoom, bool user_resize)
  2025. {
  2026. #ifdef DEBUG_KPLAYER_ENGINE
  2027. kdDebugTime() << "Engine::setDisplaySize (" << user_zoom << ", " << user_resize << ")\n";
  2028. #endif
  2029. if ( ! light() )
  2030. toggleAction ("view_full_screen") -> setChecked (settings() -> fullScreen()
  2031. && toggleAction ("view_full_screen") -> isEnabled());
  2032. m_zooming = true;
  2033. emit syncronize (user_resize);
  2034. m_zooming = false;
  2035. TQSize size (settings() -> adjustDisplaySize (user_zoom, user_resize));
  2036. if ( user_zoom || ! settings() -> constrainedSize() )
  2037. {
  2038. m_zooming = true;
  2039. emit zoom();
  2040. m_zooming = false;
  2041. }
  2042. workspace() -> setDisplaySize (settings() -> fullScreen() || settings() -> maximized()
  2043. || KPlayerEngine::engine() -> light() ? size : settings() -> displaySize());
  2044. enableZoomActions();
  2045. }
  2046. void KPlayerEngine::workspaceResize (bool user)
  2047. {
  2048. static TQTime lasttime;
  2049. int msecs = lasttime.msecsTo (TQTime::currentTime());
  2050. #ifdef DEBUG_KPLAYER_ENGINE
  2051. kdDebugTime() << "KPlayerEngine::workspaceResize " << user << " " << m_zooming << " " << msecs << "\n";
  2052. #endif
  2053. if ( m_zooming /* || msecs >= 0 && msecs < 200 */ )
  2054. return;
  2055. m_zooming = true;
  2056. emit correctSize();
  2057. m_zooming = false;
  2058. setDisplaySize (false, user);
  2059. lasttime = TQTime::currentTime();
  2060. }
  2061. void KPlayerEngine::workspaceResized (void)
  2062. {
  2063. #ifdef DEBUG_KPLAYER_ENGINE
  2064. kdDebugTime() << "Workspace resized event\n";
  2065. #endif
  2066. workspaceResize (false);
  2067. }
  2068. void KPlayerEngine::workspaceUserResize (void)
  2069. {
  2070. #ifdef DEBUG_KPLAYER_ENGINE
  2071. kdDebugTime() << "Workspace user resize event\n";
  2072. #endif
  2073. workspaceResize (! light());
  2074. }
  2075. void KPlayerEngine::clearStoreSections (const TQString& section)
  2076. {
  2077. #ifdef DEBUG_KPLAYER_ENGINE
  2078. kdDebugTime() << "Clearing store section " << section << "\n";
  2079. #endif
  2080. store() -> setGroup (section);
  2081. int children = store() -> readNumEntry ("Children");
  2082. for ( int i = 0; i < children; ++ i )
  2083. {
  2084. store() -> setGroup (section);
  2085. TQString entry (store() -> readEntry ("Child" + TQString::number (i)));
  2086. if ( entry.find ('/') < 0 )
  2087. {
  2088. KURL url (section);
  2089. url.addPath (entry);
  2090. clearStoreSections (url.url());
  2091. }
  2092. }
  2093. store() -> deleteGroup (section);
  2094. }
  2095. void KPlayerEngine::getAlsaVolume (void)
  2096. {
  2097. #ifdef DEBUG_KPLAYER_ENGINE
  2098. kdDebugTime() << "KPlayerEngine::getAlsaVolume\n";
  2099. kdDebugTime() << " Volume " << m_last_volume << "\n";
  2100. kdDebugTime() << " Mute " << configuration() -> mute() << "\n";
  2101. #endif
  2102. if ( m_amixer_running )
  2103. return;
  2104. m_amixer_volume = -1;
  2105. runAmixer ("get");
  2106. }
  2107. void KPlayerEngine::runAmixer (const TQString& command, const TQString& parameter)
  2108. {
  2109. #ifdef DEBUG_KPLAYER_ENGINE
  2110. kdDebugTime() << "KPlayerEngine::runAmixer\n";
  2111. #endif
  2112. m_amixer_found_control = false;
  2113. m_amixer_volume_first = m_amixer_volume_second = -1;
  2114. KPlayerLineOutputProcess* amixer = new KPlayerLineOutputProcess;
  2115. *amixer << "amixer";
  2116. TQString mixer = properties() -> mixerDevice();
  2117. if ( ! mixer.isEmpty() )
  2118. {
  2119. *amixer << "-D" << mixer;
  2120. #ifdef DEBUG_KPLAYER_ENGINE
  2121. kdDebugTime() << " Device " << mixer << "\n";
  2122. #endif
  2123. }
  2124. mixer = properties() -> mixerChannel();
  2125. if ( mixer.isEmpty() )
  2126. mixer = "PCM";
  2127. *amixer << command << mixer;
  2128. #ifdef DEBUG_KPLAYER_ENGINE
  2129. kdDebugTime() << " Command " << command << "\n";
  2130. kdDebugTime() << " Channel " << mixer << "\n";
  2131. #endif
  2132. if ( ! parameter.isEmpty() )
  2133. {
  2134. *amixer << parameter;
  2135. #ifdef DEBUG_KPLAYER_ENGINE
  2136. kdDebugTime() << " Volume " << parameter << "\n";
  2137. #endif
  2138. }
  2139. connect (amixer, SIGNAL (receivedStdoutLine (KPlayerLineOutputProcess*, char*, int)),
  2140. SLOT (amixerOutput (KPlayerLineOutputProcess*, char*, int)));
  2141. connect (amixer, SIGNAL (processExited (TDEProcess*)), SLOT (amixerExited (TDEProcess*)));
  2142. m_amixer_running = amixer -> start (TDEProcess::NotifyOnExit, TDEProcess::All);
  2143. }
  2144. void KPlayerEngine::amixerOutput (KPlayerLineOutputProcess*, char* str, int)
  2145. {
  2146. #ifdef DEBUG_KPLAYER_ENGINE
  2147. kdDebugTime() << " amixer: " << str << "\n";
  2148. #endif
  2149. static TQRegExp re_control ("^Simple mixer control '(.*)'");
  2150. static TQRegExp re_volume ("^ +[^:]+: Playback \\d+ \\[(\\d+)%\\]");
  2151. if ( re_control.search (str) >= 0 )
  2152. {
  2153. #ifdef DEBUG_KPLAYER_ENGINE
  2154. kdDebugTime() << " Control " << re_control.cap(1) << "\n";
  2155. #endif
  2156. TQString mixer = properties() -> mixerChannel();
  2157. if ( mixer.isEmpty() )
  2158. mixer = "PCM";
  2159. m_amixer_found_control = re_control.cap(1) == mixer;
  2160. }
  2161. else if ( m_amixer_found_control && re_volume.search (str) >= 0 )
  2162. {
  2163. #ifdef DEBUG_KPLAYER_ENGINE
  2164. kdDebugTime() << " Volume " << re_volume.cap(1) << "\n";
  2165. #endif
  2166. (m_amixer_volume_first < 0 ? m_amixer_volume_first : m_amixer_volume_second) = re_volume.cap(1).toInt();
  2167. }
  2168. }
  2169. void KPlayerEngine::amixerExited (TDEProcess* proc)
  2170. {
  2171. #ifdef DEBUG_KPLAYER_ENGINE
  2172. kdDebugTime() << "KPlayerEngine::amixerExited\n";
  2173. #endif
  2174. delete proc;
  2175. m_amixer_running = false;
  2176. bool set_volume = m_amixer_volume < 0;
  2177. if ( m_amixer_volume_second >= 0 )
  2178. m_amixer_volume = (m_amixer_volume_first + m_amixer_volume_second) >> 1;
  2179. else if ( m_amixer_volume_first >= 0 )
  2180. m_amixer_volume = m_amixer_volume_first;
  2181. if ( m_amixer_volume >= 0 )
  2182. {
  2183. if ( configuration() -> mute() )
  2184. if ( m_amixer_volume == 0 )
  2185. m_last_volume = 0;
  2186. else
  2187. {
  2188. configuration() -> setMute (false);
  2189. toggleAction ("audio_mute") -> setChecked (false);
  2190. }
  2191. int volume = m_amixer_volume + settings() -> actualVolume() - m_last_volume;
  2192. #ifdef DEBUG_KPLAYER_ENGINE
  2193. kdDebugTime() << " Volume " << m_amixer_volume << "\n";
  2194. kdDebugTime() << " Target " << volume << "\n";
  2195. #endif
  2196. if ( volume != m_amixer_volume && set_volume )
  2197. {
  2198. TQString parameter;
  2199. if ( m_amixer_volume_second < 0 )
  2200. parameter = TQString::number (volume) + "%";
  2201. else
  2202. {
  2203. volume = volume - m_amixer_volume >> 1;
  2204. parameter = TQString::number (m_amixer_volume_first + volume) + "%,"
  2205. + TQString::number (m_amixer_volume_first + volume) + "%";
  2206. }
  2207. runAmixer ("set", parameter);
  2208. }
  2209. else if ( volume != settings() -> volume() && ! configuration() -> mute() )
  2210. {
  2211. properties() -> adjustVolume (volume);
  2212. m_updating = true;
  2213. sliderAction ("audio_volume") -> slider() -> setValue (volume);
  2214. popupAction ("popup_volume") -> slider() -> setValue (volume);
  2215. m_updating = false;
  2216. }
  2217. }
  2218. }