KMPlayer – media player
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

2347 rindas
93KB

  1. /***************************************************************************
  2. kmplayerapp.cpp - description
  3. -------------------
  4. begin : Sat Dec 7 16:14:51 CET 2002
  5. copyright : (C) 2002 by Koos Vriezen
  6. email :
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #undef Always
  17. #include <unistd.h>
  18. // include files for QT
  19. #include <tqdatastream.h>
  20. #include <tqregexp.h>
  21. #include <tqiodevice.h>
  22. #include <tqprinter.h>
  23. #include <tqcursor.h>
  24. #include <tqpainter.h>
  25. #include <tqcheckbox.h>
  26. #include <tqpushbutton.h>
  27. #include <tqkeysequence.h>
  28. #include <tqapplication.h>
  29. #include <tqslider.h>
  30. #include <tqlayout.h>
  31. #include <tqwhatsthis.h>
  32. #include <tqtimer.h>
  33. #include <tqfile.h>
  34. #include <tqmetaobject.h>
  35. // include files for KDE
  36. #include <tdeversion.h>
  37. #include <kstandarddirs.h>
  38. #include <kiconloader.h>
  39. #include <tdemessagebox.h>
  40. #include <tdefiledialog.h>
  41. #include <klineeditdlg.h>
  42. #include <tdemenubar.h>
  43. #include <kstatusbar.h>
  44. #include <kurldrag.h>
  45. #include <tdelocale.h>
  46. #include <tdeconfig.h>
  47. #include <kstdaction.h>
  48. #include <kdebug.h>
  49. #include <dcopclient.h>
  50. #include <tdepopupmenu.h>
  51. #include <kurlrequester.h>
  52. #include <klineedit.h>
  53. #include <kkeydialog.h>
  54. #include <ksystemtray.h>
  55. #include <kedittoolbar.h>
  56. // application specific includes
  57. #include "kmplayer.h"
  58. #include "kmplayerview.h"
  59. #include "playlistview.h"
  60. #include "viewarea.h"
  61. #include "kmplayercontrolpanel.h"
  62. #include "kmplayerpartbase.h"
  63. #include "kmplayerprocess.h"
  64. #include "kmplayerappsource.h"
  65. #include "kmplayertvsource.h"
  66. #include "kmplayerbroadcast.h"
  67. #include "kmplayervdr.h"
  68. #include "kmplayerconfig.h"
  69. #include <X11/Xlib.h>
  70. #ifdef HAVE_XTEST
  71. #include <X11/keysym.h>
  72. #include <X11/extensions/XTest.h>
  73. #endif
  74. static const int DVDNav_start = 1;
  75. static const int DVDNav_previous = 2;
  76. static const int DVDNav_next = 3;
  77. static const int DVDNav_root = 4;
  78. static const int DVDNav_up = 5;
  79. extern const char * strMPlayerGroup;
  80. static const short id_node_recent_document = 31;
  81. static const short id_node_recent_node = 32;
  82. static const short id_node_disk_document = 33;
  83. static const short id_node_disk_node = 34;
  84. class KMPLAYER_NO_EXPORT ListsSource : public KMPlayer::URLSource {
  85. public:
  86. KDE_NO_CDTOR_EXPORT ListsSource (KMPlayer::PartBase * p)
  87. : KMPlayer::URLSource (p, "lists://") {}
  88. void jump (KMPlayer::NodePtr e);
  89. void activate ();
  90. void setDocument (KMPlayer::NodePtr doc, KMPlayer::NodePtr cur);
  91. TQString prettyName () { return m_document->mrl ()->pretty_name; }
  92. };
  93. class KMPLAYER_NO_EXPORT Recents : public FileDocument {
  94. public:
  95. Recents (KMPlayerApp *a);
  96. void defer ();
  97. void activate ();
  98. void childDone (KMPlayer::NodePtr);
  99. KMPlayer::NodePtr childFromTag (const TQString & tag);
  100. KDE_NO_EXPORT const char * nodeName () const { return "playlist"; }
  101. KMPlayerApp * app;
  102. };
  103. class KMPLAYER_NO_EXPORT Recent : public KMPlayer::Mrl {
  104. public:
  105. Recent (KMPlayer::NodePtr & doc, KMPlayerApp *a, const TQString &url = TQString());
  106. void activate ();
  107. void closed ();
  108. KDE_NO_EXPORT const char * nodeName () const { return "item"; }
  109. KMPlayerApp * app;
  110. };
  111. class KMPLAYER_NO_EXPORT Group : public KMPlayer::Mrl {
  112. public:
  113. Group (KMPlayer::NodePtr &doc, KMPlayerApp *a, const TQString &pn=TQString());
  114. KMPlayer::NodePtr childFromTag (const TQString & tag);
  115. void defer () {} // TODO lazy loading of largish sub trees
  116. void closed ();
  117. KDE_NO_EXPORT const char * nodeName () const { return "group"; }
  118. KMPlayerApp * app;
  119. };
  120. class KMPLAYER_NO_EXPORT Playlist : public FileDocument {
  121. public:
  122. Playlist (KMPlayerApp *a, KMPlayer::PlayListNotify *n, bool plmod = false);
  123. void childDone (KMPlayer::NodePtr);
  124. void defer ();
  125. void activate ();
  126. KMPlayer::NodePtr childFromTag (const TQString & tag);
  127. KDE_NO_EXPORT const char * nodeName () const { return "playlist"; }
  128. KMPlayerApp * app;
  129. bool playmode;
  130. };
  131. class KMPLAYER_NO_EXPORT PlaylistItemBase : public KMPlayer::Mrl {
  132. public:
  133. PlaylistItemBase (KMPlayer::NodePtr &d, short id, KMPlayerApp *a, bool pm);
  134. void activate ();
  135. void closed ();
  136. KMPlayerApp * app;
  137. bool playmode;
  138. };
  139. class KMPLAYER_NO_EXPORT PlaylistItem : public PlaylistItemBase {
  140. public:
  141. PlaylistItem (KMPlayer::NodePtr & doc, KMPlayerApp *a, bool playmode, const TQString &url = TQString());
  142. void closed ();
  143. void begin ();
  144. PlayType playType () { return play_type_unknown; }
  145. void setNodeName (const TQString &);
  146. const char * nodeName () const KDE_NO_EXPORT { return "item"; }
  147. };
  148. class KMPLAYER_NO_EXPORT PlaylistGroup : public KMPlayer::Mrl {
  149. public:
  150. PlaylistGroup (KMPlayer::NodePtr &doc, KMPlayerApp *a, const TQString &pn);
  151. PlaylistGroup (KMPlayer::NodePtr &doc, KMPlayerApp *a, bool plmode=false);
  152. KMPlayer::NodePtr childFromTag (const TQString & tag);
  153. void closed ();
  154. void setNodeName (const TQString &);
  155. KDE_NO_EXPORT const char * nodeName () const { return "group"; }
  156. KMPlayerApp * app;
  157. bool playmode;
  158. };
  159. class KMPLAYER_NO_EXPORT HtmlObject : public PlaylistItemBase {
  160. public:
  161. HtmlObject (KMPlayer::NodePtr & doc, KMPlayerApp *a, bool playmode);
  162. void activate ();
  163. void closed ();
  164. KMPlayer::NodePtr childFromTag (const TQString & tag);
  165. const char * nodeName () const KDE_NO_EXPORT { return "object"; }
  166. };
  167. KDE_NO_EXPORT void ListsSource::jump (KMPlayer::NodePtr e) {
  168. if (e->document()->firstChild ())
  169. Source::jump (e);
  170. else
  171. e->activate ();
  172. }
  173. KDE_NO_EXPORT void ListsSource::activate () {
  174. playCurrent ();
  175. }
  176. KDE_NO_EXPORT void ListsSource::setDocument (KMPlayer::NodePtr doc, KMPlayer::NodePtr cur) {
  177. if (m_document)
  178. m_document->document()->dispose ();
  179. m_document = doc;
  180. m_current = cur;
  181. //kdDebug () << "setDocument: " << m_document->outerXML () << endl;
  182. }
  183. KDE_NO_CDTOR_EXPORT FileDocument::FileDocument (short i, const TQString &s, KMPlayer::PlayListNotify * n)
  184. : KMPlayer::Document (s, n) {
  185. id = i;
  186. }
  187. KDE_NO_EXPORT KMPlayer::NodePtr FileDocument::childFromTag(const TQString &tag) {
  188. if (tag == TQString::fromLatin1 (nodeName ()))
  189. return this;
  190. return 0L;
  191. }
  192. void FileDocument::readFromFile (const TQString & fn) {
  193. TQFile file (fn);
  194. kdDebug () << "readFromFile " << fn << endl;
  195. if (file.exists ()) {
  196. file.open (IO_ReadOnly);
  197. TQTextStream inxml (&file);
  198. KMPlayer::readXML (this, inxml, TQString (), false);
  199. normalize ();
  200. }
  201. }
  202. void FileDocument::writeToFile (const TQString & fn) {
  203. TQFile file (fn);
  204. kdDebug () << "writeToFile " << fn << endl;
  205. file.open (IO_WriteOnly);
  206. TQCString utf = outerXML ().utf8 ();
  207. file.writeBlock (utf, utf.length ());
  208. }
  209. KDE_NO_CDTOR_EXPORT Recents::Recents (KMPlayerApp *a)
  210. : FileDocument (id_node_recent_document, "recents://"),
  211. app(a) {
  212. pretty_name = i18n ("Most Recent");
  213. }
  214. KDE_NO_EXPORT void Recents::activate () {
  215. if (!resolved)
  216. defer ();
  217. }
  218. KDE_NO_EXPORT void Recents::defer () {
  219. if (!resolved) {
  220. resolved = true;
  221. readFromFile (locateLocal ("data", "kmplayer/recent.xml"));
  222. }
  223. }
  224. KDE_NO_EXPORT KMPlayer::NodePtr Recents::childFromTag (const TQString & tag) {
  225. // kdDebug () << nodeName () << " childFromTag " << tag << endl;
  226. if (tag == TQString::fromLatin1 ("item"))
  227. return new Recent (m_doc, app);
  228. else if (tag == TQString::fromLatin1 ("group"))
  229. return new Group (m_doc, app);
  230. return FileDocument::childFromTag (tag);
  231. }
  232. KDE_NO_EXPORT void Recents::childDone (KMPlayer::NodePtr) {
  233. finish ();
  234. }
  235. KDE_NO_CDTOR_EXPORT
  236. Recent::Recent (KMPlayer::NodePtr & doc, KMPlayerApp * a, const TQString &url)
  237. : KMPlayer::Mrl (doc, id_node_recent_node), app (a) {
  238. src = url;
  239. setAttribute (KMPlayer::StringPool::attr_url, url);
  240. }
  241. KDE_NO_EXPORT void Recent::closed () {
  242. if (src.isEmpty ())
  243. src = getAttribute (KMPlayer::StringPool::attr_url);
  244. }
  245. KDE_NO_EXPORT void Recent::activate () {
  246. app->openDocumentFile (KURL (src));
  247. }
  248. KDE_NO_CDTOR_EXPORT
  249. Group::Group (KMPlayer::NodePtr & doc, KMPlayerApp * a, const TQString & pn)
  250. : KMPlayer::Mrl (doc, KMPlayer::id_node_group_node), app (a) {
  251. pretty_name = pn;
  252. if (!pn.isEmpty ())
  253. setAttribute (KMPlayer::StringPool::attr_title, pn);
  254. }
  255. KDE_NO_EXPORT KMPlayer::NodePtr Group::childFromTag (const TQString & tag) {
  256. if (tag == TQString::fromLatin1 ("item"))
  257. return new Recent (m_doc, app);
  258. else if (tag == TQString::fromLatin1 ("group"))
  259. return new Group (m_doc, app);
  260. return 0L;
  261. }
  262. KDE_NO_EXPORT void Group::closed () {
  263. if (pretty_name.isEmpty ())
  264. pretty_name = getAttribute (KMPlayer::StringPool::attr_title);
  265. }
  266. KDE_NO_EXPORT void Playlist::defer () {
  267. if (playmode)
  268. KMPlayer::Document::defer ();
  269. else if (!resolved) {
  270. resolved = true;
  271. readFromFile (locateLocal ("data", "kmplayer/playlist.xml"));
  272. }
  273. }
  274. KDE_NO_EXPORT void Playlist::activate () {
  275. if (playmode)
  276. KMPlayer::Document::activate ();
  277. else if (!resolved)
  278. defer ();
  279. }
  280. KDE_NO_CDTOR_EXPORT Playlist::Playlist (KMPlayerApp *a, KMPlayer::PlayListNotify *n, bool plmode)
  281. : FileDocument (KMPlayer::id_node_playlist_document, "Playlist://", n),
  282. app(a),
  283. playmode (plmode) {
  284. pretty_name = i18n ("Persistent Playlists");
  285. }
  286. KDE_NO_EXPORT KMPlayer::NodePtr Playlist::childFromTag (const TQString & tag) {
  287. // kdDebug () << nodeName () << " childFromTag " << tag << endl;
  288. const char * name = tag.ascii ();
  289. if (!strcmp (name, "item"))
  290. return new PlaylistItem (m_doc, app, playmode);
  291. else if (!strcmp (name, "group"))
  292. return new PlaylistGroup (m_doc, app, playmode);
  293. else if (!strcmp (name, "object"))
  294. return new HtmlObject (m_doc, app, playmode);
  295. return FileDocument::childFromTag (tag);
  296. }
  297. KDE_NO_EXPORT void Playlist::childDone (KMPlayer::NodePtr c) {
  298. if (!playmode)
  299. finish ();
  300. else
  301. FileDocument::childDone (c);
  302. }
  303. KDE_NO_CDTOR_EXPORT
  304. PlaylistItemBase::PlaylistItemBase (KMPlayer::NodePtr &d, short i, KMPlayerApp *a, bool pm)
  305. : KMPlayer::Mrl (d, i), app (a), playmode (pm) {
  306. }
  307. KDE_NO_EXPORT void PlaylistItemBase::activate () {
  308. if (playmode) {
  309. Mrl::activate ();
  310. } else {
  311. ListsSource * source = static_cast <ListsSource *> (app->player ()->sources () ["listssource"]);
  312. KMPlayer::NodePtr pl = new Playlist (app, source, true);
  313. TQString data;
  314. TQString pn;
  315. if (parentNode ()->id == KMPlayer::id_node_group_node) {
  316. data = parentNode ()->innerXML ();
  317. pn = parentNode ()->mrl ()->pretty_name;
  318. } else {
  319. data = outerXML ();
  320. pn = pretty_name.isEmpty () ? src : pretty_name;
  321. }
  322. pl->mrl ()->pretty_name = pn;
  323. //kdDebug () << "cloning to " << data << endl;
  324. TQTextStream inxml (data, IO_ReadOnly);
  325. KMPlayer::readXML (pl, inxml, TQString (), false);
  326. pl->normalize ();
  327. KMPlayer::NodePtr cur = pl->firstChild ();
  328. pl->mrl ()->resolved = !!cur;
  329. if (parentNode ()->id == KMPlayer::id_node_group_node && cur) {
  330. KMPlayer::NodePtr sister = parentNode ()->firstChild ();
  331. while (sister && cur && sister.ptr () != this) {
  332. sister = sister->nextSibling ();
  333. cur = cur->nextSibling ();
  334. }
  335. }
  336. bool reset_only = source == app->player ()->source ();
  337. if (reset_only)
  338. app->player ()->stop ();
  339. source->setDocument (pl, cur);
  340. if (reset_only) {
  341. source->activate ();
  342. app->setCaption (pn);
  343. } else
  344. app->player ()->setSource (source);
  345. }
  346. }
  347. void PlaylistItemBase::closed () {
  348. if (pretty_name.isEmpty ())
  349. pretty_name = getAttribute (KMPlayer::StringPool::attr_title);
  350. }
  351. KDE_NO_CDTOR_EXPORT
  352. PlaylistItem::PlaylistItem (KMPlayer::NodePtr & doc, KMPlayerApp *a, bool pm, const TQString &url)
  353. : PlaylistItemBase (doc, KMPlayer::id_node_playlist_item, a, pm) {
  354. src = url;
  355. setAttribute (KMPlayer::StringPool::attr_url, url);
  356. }
  357. KDE_NO_EXPORT void PlaylistItem::closed () {
  358. if (src.isEmpty ())
  359. src = getAttribute (KMPlayer::StringPool::attr_url);
  360. PlaylistItemBase::closed ();
  361. }
  362. KDE_NO_EXPORT void PlaylistItem::begin () {
  363. if (playmode && firstChild ())
  364. firstChild ()->activate ();
  365. else
  366. Mrl::begin ();
  367. }
  368. KDE_NO_EXPORT void PlaylistItem::setNodeName (const TQString & s) {
  369. src = s;
  370. setAttribute (KMPlayer::StringPool::attr_url, s);
  371. }
  372. KDE_NO_CDTOR_EXPORT
  373. PlaylistGroup::PlaylistGroup (KMPlayer::NodePtr & doc, KMPlayerApp * a, const TQString & pn)
  374. : KMPlayer::Mrl (doc, KMPlayer::id_node_group_node), app (a), playmode (false) {
  375. pretty_name = pn;
  376. if (!pn.isEmpty ())
  377. setAttribute (KMPlayer::StringPool::attr_title, pn);
  378. }
  379. KDE_NO_CDTOR_EXPORT
  380. PlaylistGroup::PlaylistGroup (KMPlayer::NodePtr & doc, KMPlayerApp * a, bool lm)
  381. : KMPlayer::Mrl (doc, KMPlayer::id_node_group_node), app (a), playmode (lm) {
  382. }
  383. KDE_NO_EXPORT KMPlayer::NodePtr PlaylistGroup::childFromTag (const TQString & tag) {
  384. const char * name = tag.ascii ();
  385. if (!strcmp (name, "item"))
  386. return new PlaylistItem (m_doc, app, playmode);
  387. else if (!strcmp (name, "group"))
  388. return new PlaylistGroup (m_doc, app, playmode);
  389. else if (!strcmp (name, "object"))
  390. return new HtmlObject (m_doc, app, playmode);
  391. return 0L;
  392. }
  393. KDE_NO_EXPORT void PlaylistGroup::closed () {
  394. if (pretty_name.isEmpty ())
  395. pretty_name = getAttribute (KMPlayer::StringPool::attr_title);
  396. }
  397. KDE_NO_EXPORT void PlaylistGroup::setNodeName (const TQString & t) {
  398. pretty_name = t;
  399. setAttribute (KMPlayer::StringPool::attr_title, t);
  400. }
  401. KDE_NO_CDTOR_EXPORT
  402. HtmlObject::HtmlObject (KMPlayer::NodePtr &doc, KMPlayerApp *a, bool pm)
  403. : PlaylistItemBase (doc, KMPlayer::id_node_html_object, a, pm) {}
  404. KDE_NO_EXPORT void HtmlObject::activate () {
  405. if (playmode)
  406. KMPlayer::Mrl::activate ();
  407. else
  408. PlaylistItemBase::activate ();
  409. }
  410. KDE_NO_EXPORT void HtmlObject::closed () {
  411. for (Node *n = firstChild ().ptr (); n; n = n->nextSibling ().ptr ()) {
  412. if (n->id == KMPlayer::id_node_param) {
  413. KMPlayer::Element *e = static_cast <KMPlayer::Element *> (n);
  414. TQString name = e->getAttribute (KMPlayer::StringPool::attr_name);
  415. if (name == "type")
  416. mimetype = e->getAttribute (KMPlayer::StringPool::attr_value);
  417. else if (name == "movie")
  418. src = e->getAttribute (KMPlayer::StringPool::attr_value);
  419. } else if (n->id == KMPlayer::id_node_html_embed) {
  420. KMPlayer::Element *e = static_cast <KMPlayer::Element *> (n);
  421. TQString type = e->getAttribute (KMPlayer::StringPool::attr_type);
  422. if (!type.isEmpty ())
  423. mimetype = type;
  424. TQString asrc = e->getAttribute (KMPlayer::StringPool::attr_src);
  425. if (!asrc.isEmpty ())
  426. src = asrc;
  427. }
  428. }
  429. PlaylistItemBase::closed ();
  430. }
  431. KDE_NO_EXPORT KMPlayer::NodePtr HtmlObject::childFromTag (const TQString & tag) {
  432. const char *name = tag.ascii ();
  433. if (!strcasecmp (name, "param"))
  434. return new KMPlayer::DarkNode (m_doc, name, KMPlayer::id_node_param);
  435. else if (!strcasecmp (name, "embed"))
  436. return new KMPlayer::DarkNode(m_doc, name,KMPlayer::id_node_html_embed);
  437. return NULL;
  438. }
  439. KDE_NO_CDTOR_EXPORT KMPlayerApp::KMPlayerApp(TQWidget* , const char* name)
  440. : TDEMainWindow(0, name),
  441. config (kapp->config ()),
  442. m_systray (0L),
  443. m_player (new KMPlayer::PartBase (this, 0L, 0L, 0L, config)),
  444. m_view (static_cast <KMPlayer::View*> (m_player->view())),
  445. m_dvdmenu (new TQPopupMenu (this)),
  446. m_dvdnavmenu (new TQPopupMenu (this)),
  447. m_vcdmenu (new TQPopupMenu (this)),
  448. m_audiocdmenu (new TQPopupMenu (this)),
  449. m_tvmenu (new TQPopupMenu (this)),
  450. m_ffserverconfig (new KMPlayerFFServerConfig),
  451. m_broadcastconfig (new KMPlayerBroadcastConfig (m_player, m_ffserverconfig)),
  452. edit_tree_id (-1),
  453. last_time_left (0),
  454. m_played_intro (false),
  455. m_played_exit (false),
  456. m_minimal_mode (false)
  457. {
  458. setCentralWidget (m_view);
  459. connect (m_broadcastconfig, TQT_SIGNAL (broadcastStarted()), TQT_TQOBJECT(this), TQT_SLOT (broadcastStarted()));
  460. connect (m_broadcastconfig, TQT_SIGNAL (broadcastStopped()), TQT_TQOBJECT(this), TQT_SLOT (broadcastStopped()));
  461. initStatusBar();
  462. #ifdef HAVE_DBUS
  463. m_player->setServiceName (TQString ("org.kde.kmplayer-%1").arg (getpid ()));
  464. #endif
  465. m_player->init (actionCollection ());
  466. m_player->players () ["xvideo"] = new XVideo(m_player,m_player->settings());
  467. m_player->setProcess ("mplayer");
  468. m_player->setRecorder ("mencoder");
  469. ListsSource * lstsrc = new ListsSource (m_player);
  470. m_player->sources () ["listssource"] = lstsrc;
  471. m_player->sources () ["dvdsource"] = new ::KMPlayerDVDSource(this, m_dvdmenu);
  472. m_player->sources () ["dvdnavsource"] = new KMPlayerDVDNavSource (this, m_dvdnavmenu);
  473. m_player->sources () ["vcdsource"] = new KMPlayerVCDSource(this, m_vcdmenu);
  474. m_player->sources () ["audiocdsource"] = new KMPlayerAudioCDSource (this, m_audiocdmenu);
  475. m_player->sources () ["pipesource"] = new KMPlayerPipeSource (this);
  476. m_player->sources () ["tvsource"] = new KMPlayerTVSource (this, m_tvmenu);
  477. m_player->sources () ["vdrsource"] = new KMPlayerVDRSource (this);
  478. m_player->setSource (m_player->sources () ["urlsource"]);
  479. initActions();
  480. initView();
  481. haveXTest = false;
  482. #ifdef HAVE_XTEST
  483. int dummy_event, dummy_error, dummy_major, dummy_minor;
  484. if (XTestQueryExtension(x11Display(), &dummy_event, &dummy_error, &dummy_major, &dummy_minor)) {
  485. fakeKeycode = XKeysymToKeycode(x11Display(), XK_Shift_L);
  486. if (fakeKeycode != 0)
  487. haveXTest = true;
  488. }
  489. #endif
  490. /** TWin are you there? **/
  491. m_haveKWin = TDEApplication::dcopClient()->isApplicationRegistered("twin");
  492. if (m_haveKWin)
  493. kdDebug() << "Window manager: TWin found" << endl;
  494. else
  495. kdDebug() << "Window manager: not TWin - using save fullscreen mode" << endl;
  496. connect(&m_screensaverTimer, TQT_SIGNAL(timeout()), TQT_TQOBJECT(this), TQT_SLOT(slotFakeKeyEvent()));
  497. m_screensaverTimer.start( 55000 );
  498. //setAutoSaveSettings();
  499. playlist = new Playlist (this, lstsrc);
  500. playlist_id = m_view->playList ()->addTree (playlist, "listssource", "player_playlist", KMPlayer::PlayListView::AllowDrag | KMPlayer::PlayListView::AllowDrops | KMPlayer::PlayListView::TreeEdit | KMPlayer::PlayListView::Moveable | KMPlayer::PlayListView::Deleteable);
  501. readOptions();
  502. }
  503. KDE_NO_CDTOR_EXPORT KMPlayerApp::~KMPlayerApp () {
  504. delete m_broadcastconfig;
  505. if (recents)
  506. recents->document ()->dispose ();
  507. if (playlist)
  508. playlist->document ()->dispose ();
  509. }
  510. KDE_NO_EXPORT void KMPlayerApp::initActions () {
  511. TDEActionCollection * ac = actionCollection ();
  512. fileNewWindow = new TDEAction(i18n("New &Window"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(slotFileNewWindow()), ac, "new_window");
  513. fileOpen = KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(slotFileOpen()), ac, "open");
  514. fileOpenRecent = KStdAction::openRecent(TQT_TQOBJECT(this), TQT_SLOT(slotFileOpenRecent(const KURL&)), ac, "open_recent");
  515. KStdAction::saveAs (TQT_TQOBJECT(this), TQT_SLOT (slotSaveAs ()), ac, "save_as");
  516. new TDEAction (i18n ("Clear &History"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT (slotClearHistory ()), ac, "clear_history");
  517. fileClose = KStdAction::close (TQT_TQOBJECT(this), TQT_SLOT (slotFileClose ()), ac);
  518. fileQuit = KStdAction::quit (TQT_TQOBJECT(this), TQT_SLOT (slotFileQuit ()), ac);
  519. new TDEAction (i18n ("&Open DVD"), TQString ("media-optical-dvd-mounted"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT(openDVD ()), ac, "opendvd");
  520. new TDEAction (i18n ("&Open VCD"), TQString ("media-optical-cdrom-mounted"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT(openVCD ()), ac, "openvcd");
  521. new TDEAction (i18n ("&Open Audio CD"), TQString ("media-optical-cdrom-mounted"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT(openAudioCD ()), ac, "openaudiocd");
  522. new TDEAction (i18n ("&Open Pipe..."), TQString ("pipe"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT(openPipe ()), ac, "source_pipe");
  523. //TDEGlobal::iconLoader ()->loadIconSet (TQString ("tv"), TDEIcon::Small, 0,true)
  524. new TDEAction (i18n ("&Connect"), TQString ("connect_established"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT (openVDR ()), ac, "vdr_connect");
  525. editVolumeInc = new TDEAction (i18n ("Increase Volume"), TQString ("player_volume"), TDEShortcut (), m_player, TQT_SLOT (increaseVolume ()), ac, "edit_volume_up");
  526. editVolumeDec = new TDEAction (i18n ("Decrease Volume"), TQString ("player_volume"), TDEShortcut (), m_player, TQT_SLOT(decreaseVolume ()), ac, "edit_volume_down");
  527. toggleView = new TDEAction (i18n ("C&onsole"), TQString ("konsole"), TDEShortcut (), TQT_TQOBJECT(m_player->view()), TQT_SLOT (toggleVideoConsoleWindow ()), ac, "view_video");
  528. //new TDEAction (i18n ("V&ideo"), TQString (video-x-generic"), TDEShortcut (), m_view, TQT_SLOT (toggleVideoConsoleWindow ()), ac, "view_video");
  529. new TDEAction (i18n ("Pla&y List"), TQString ("player_playlist"), TDEShortcut (), m_player, TQT_SLOT (showPlayListWindow ()), ac, "view_playlist");
  530. new TDEAction (i18n ("Minimal mode"), TQString ("application-x-zerosize"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT (slotMinimalMode ()), ac, "view_minimal");
  531. new TDEAction (i18n ("50%"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT (zoom50 ()), ac, "view_zoom_50");
  532. new TDEAction (i18n ("100%"), TQString ("zoom-fit-best"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT (zoom100 ()), ac, "view_zoom_100");
  533. new TDEAction (i18n ("150%"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT (zoom150 ()), ac, "view_zoom_150");
  534. new TDEAction (i18n ("200%"), 0, TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT (zoom200 ()), ac, "view_zoom_200");
  535. new TDEAction (i18n ("300%"), 0, TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT (zoom300 ()), ac, "view_zoom_300");
  536. viewEditMode = new TDEToggleAction (i18n ("&Edit mode"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT (editMode ()), ac, "edit_mode");
  537. viewSyncEditMode = new TDEAction (i18n ("Sync &with playlist"), TQString ("reload"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT (syncEditMode ()), ac, "sync_edit_mode");
  538. viewSyncEditMode->setEnabled (false);
  539. new TDEAction (i18n ("Show Popup Menu"), TDEShortcut (), TQT_TQOBJECT(m_view->controlPanel ()), TQT_SLOT (showPopupMenu ()), ac, "view_show_popup_menu");
  540. new TDEAction (i18n ("Show Language Menu"), TDEShortcut (TQt::Key_L), TQT_TQOBJECT(m_view->controlPanel ()), TQT_SLOT (showLanguageMenu ()), ac, "view_show_lang_menu");
  541. viewKeepRatio = new TDEToggleAction (i18n ("&Keep Width/Height Ratio"), 0, TQT_TQOBJECT(this), TQT_SLOT (keepSizeRatio ()), ac, "view_keep_ratio");
  542. #if KDE_IS_VERSION(3,1,90)
  543. viewFullscreen = KStdAction::fullScreen (TQT_TQOBJECT(this), TQT_SLOT(fullScreen ()), ac, 0, "view_fullscreen");
  544. #else
  545. viewFullscreen = new TDEAction (i18n("&Full Screen"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(fullScreen ()), ac, "view_fullscreen");
  546. #endif
  547. /*TDEAction *playact =*/ new TDEAction (i18n ("P&lay"), TQString ("media-playback-start"), TDEShortcut (), m_player, TQT_SLOT (play ()), ac, "play");
  548. /*TDEAction *pauseact =*/ new TDEAction (i18n ("&Pause"), TQString ("media-playback-pause"), TDEShortcut (), m_player, TQT_SLOT (pause ()), ac, "pause");
  549. /*TDEAction *stopact =*/ new TDEAction (i18n ("&Stop"), TQString ("media-playback-stop"), TDEShortcut (), m_player, TQT_SLOT (stop ()), ac, "stop");
  550. /*TDEAction *artsctrl =*/ new TDEAction (i18n ("&Arts Control"), TQString ("player_volume"), TDEShortcut (), TQT_TQOBJECT(this), TQT_SLOT (startArtsControl ()), ac, "view_arts_control");
  551. viewToolBar = KStdAction::showToolbar(TQT_TQOBJECT(this), TQT_SLOT(slotViewToolBar()), ac, "showtoolbar");
  552. viewStatusBar =KStdAction::showStatusbar(TQT_TQOBJECT(this),TQT_SLOT(slotViewStatusBar()),ac, "showstatusbar");
  553. viewMenuBar = KStdAction::showMenubar(TQT_TQOBJECT(this), TQT_SLOT(slotViewMenuBar()), ac, "showmenu");
  554. KStdAction::preferences(m_player, TQT_SLOT(showConfigDialog()), ac,"configure");
  555. fileNewWindow->setStatusText(i18n("Opens a new application window"));
  556. fileOpen->setStatusText(i18n("Opens an existing file"));
  557. fileOpenRecent->setStatusText(i18n("Opens a recently used file"));
  558. fileClose->setStatusText(i18n("Closes the actual source"));
  559. fileQuit->setStatusText(i18n("Quits the application"));
  560. //viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
  561. viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));
  562. viewMenuBar->setStatusText(i18n("Enables/disables the menubar"));
  563. KStdAction::keyBindings( TQT_TQOBJECT(this), TQT_SLOT(slotConfigureKeys()), ac, "configkeys");
  564. KStdAction::configureToolbars (TQT_TQOBJECT(this), TQT_SLOT (slotConfigureToolbars ()), ac, "configtoolbars");
  565. }
  566. KDE_NO_EXPORT void KMPlayerApp::initStatusBar () {
  567. KStatusBar *sb = statusBar ();
  568. sb->insertItem (i18n ("Ready."), id_status_msg);
  569. sb->insertItem (TQString ("--:--"), id_status_timer, 0, true);
  570. }
  571. KDE_NO_EXPORT void KMPlayerApp::initMenu () {
  572. createGUI (); // first build the one from the kmplayerui.rc
  573. TQPopupMenu * bookmarkmenu = m_view->controlPanel()->bookmarkMenu ();
  574. m_view->controlPanel()->popupMenu ()->removeItem (KMPlayer::ControlPanel::menu_bookmark);
  575. menuBar ()->insertItem (i18n ("&Bookmarks"), bookmarkmenu, -1, 2);
  576. m_sourcemenu = menuBar ()->findItem (menuBar ()->idAt (0));
  577. m_sourcemenu->setText (i18n ("S&ource"));
  578. m_sourcemenu->popup ()->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("media-optical-dvd-mounted"), TDEIcon::Small, 0, true), i18n ("&DVD"), m_dvdmenu, -1, 5);
  579. m_dvdmenu->clear ();
  580. #ifdef HAVE_XINE
  581. m_dvdnavmenu->clear ();
  582. m_dvdnavmenu->insertItem (i18n ("&Start"), TQT_TQOBJECT(this), TQT_SLOT (dvdNav ()));
  583. m_dvdmenu->insertItem (i18n ("&DVD Navigator"), m_dvdnavmenu, -1, 1);
  584. m_dvdmenu->insertItem (i18n ("&Open DVD"), TQT_TQOBJECT(this), TQT_SLOT(openDVD ()), 0,-1, 2);
  585. #else
  586. m_dvdmenu->insertItem (i18n ("&Open DVD"), TQT_TQOBJECT(this), TQT_SLOT(openDVD ()), 0,-1, 1);
  587. #endif
  588. m_sourcemenu->popup ()->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("media-optical-cdrom-mounted"), TDEIcon::Small, 0, true), i18n ("V&CD"), m_vcdmenu, -1, 6);
  589. m_vcdmenu->clear ();
  590. m_sourcemenu->popup ()->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("tv"), TDEIcon::Small, 0, true), i18n ("&TV"), m_tvmenu, -1, 8);
  591. m_vcdmenu->insertItem (i18n ("&Open VCD"), TQT_TQOBJECT(this), TQT_SLOT(openVCD ()), 0,-1, 1);
  592. m_sourcemenu->popup ()->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("media-optical-cdrom-mounted"), TDEIcon::Small, 0, true), i18n ("&Audio CD"), m_audiocdmenu, -1, 7);
  593. m_audiocdmenu->insertItem (i18n ("&Open Audio CD"), TQT_TQOBJECT(this), TQT_SLOT(openAudioCD ()), 0,-1, 1);
  594. }
  595. KDE_NO_EXPORT void KMPlayerApp::initView () {
  596. //m_view->docArea ()->readDockConfig (config, TQString ("Window Layout"));
  597. m_player->connectPanel (m_view->controlPanel ());
  598. initMenu ();
  599. new TDEAction (i18n ("Increase Volume"), editVolumeInc->shortcut (), m_player, TQT_SLOT (increaseVolume ()), m_view->viewArea ()->actionCollection (), "edit_volume_up");
  600. new TDEAction (i18n ("Decrease Volume"), editVolumeDec->shortcut (), m_player, TQT_SLOT(decreaseVolume ()), m_view->viewArea ()->actionCollection (), "edit_volume_down");
  601. connect (m_player->settings (), TQT_SIGNAL (configChanged ()),
  602. TQT_TQOBJECT(this), TQT_SLOT (configChanged ()));
  603. connect (m_player, TQT_SIGNAL (loading (int)),
  604. TQT_TQOBJECT(this), TQT_SLOT (loadingProgress (int)));
  605. connect (m_player, TQT_SIGNAL (positioned (int, int)),
  606. TQT_TQOBJECT(this), TQT_SLOT (positioned (int, int)));
  607. connect (m_player, TQT_SIGNAL (statusUpdated (const TQString &)),
  608. TQT_TQOBJECT(this), TQT_SLOT (slotStatusMsg (const TQString &)));
  609. connect (m_view, TQT_SIGNAL (windowVideoConsoleToggled (int)),
  610. TQT_TQOBJECT(this), TQT_SLOT (windowVideoConsoleToggled (int)));
  611. connect (m_player, TQT_SIGNAL (sourceChanged (KMPlayer::Source *, KMPlayer::Source *)), TQT_TQOBJECT(this), TQT_SLOT (slotSourceChanged(KMPlayer::Source *, KMPlayer::Source *)));
  612. m_view->controlPanel ()->zoomMenu ()->connectItem (KMPlayer::ControlPanel::menu_zoom50,
  613. TQT_TQOBJECT(this), TQT_SLOT (zoom50 ()));
  614. m_view->controlPanel ()->zoomMenu ()->connectItem (KMPlayer::ControlPanel::menu_zoom100,
  615. TQT_TQOBJECT(this), TQT_SLOT (zoom100 ()));
  616. m_view->controlPanel ()->zoomMenu ()->connectItem (KMPlayer::ControlPanel::menu_zoom150,
  617. TQT_TQOBJECT(this), TQT_SLOT (zoom150 ()));
  618. m_view->controlPanel ()->zoomMenu ()->connectItem (KMPlayer::ControlPanel::menu_zoom200,
  619. TQT_TQOBJECT(this), TQT_SLOT (zoom200 ()));
  620. m_view->controlPanel ()->zoomMenu ()->connectItem (KMPlayer::ControlPanel::menu_zoom300,
  621. TQT_TQOBJECT(this), TQT_SLOT (zoom300 ()));
  622. connect (m_view->controlPanel()->broadcastButton (), TQT_SIGNAL (clicked ()),
  623. TQT_TQOBJECT(this), TQT_SLOT (broadcastClicked ()));
  624. m_auto_resize = m_player->settings ()->autoresize;
  625. if (m_auto_resize)
  626. connect (m_player, TQT_SIGNAL (sourceDimensionChanged ()),
  627. TQT_TQOBJECT(this), TQT_SLOT (zoom100 ()));
  628. connect (m_view, TQT_SIGNAL (fullScreenChanged ()),
  629. TQT_TQOBJECT(this), TQT_SLOT (fullScreen ()));
  630. connect (m_player, TQT_SIGNAL (toggleMinimalMode ()),
  631. TQT_TQOBJECT(this), TQT_SLOT (slotMinimalMode ()));
  632. connect (m_view->playList (), TQT_SIGNAL (selectionChanged (TQListViewItem *)),
  633. TQT_TQOBJECT(this), TQT_SLOT (playListItemSelected (TQListViewItem *)));
  634. connect (m_view->playList(), TQT_SIGNAL (dropped (TQDropEvent*, TQListViewItem*)),
  635. TQT_TQOBJECT(this), TQT_SLOT (playListItemDropped (TQDropEvent *, TQListViewItem *)));
  636. connect (m_view->playList(), TQT_SIGNAL (moved ()),
  637. TQT_TQOBJECT(this), TQT_SLOT (playListItemMoved ()));
  638. connect (m_view->playList(), TQT_SIGNAL (prepareMenu (KMPlayer::PlayListItem *, TQPopupMenu *)), TQT_TQOBJECT(this), TQT_SLOT (preparePlaylistMenu (KMPlayer::PlayListItem *, TQPopupMenu *)));
  639. m_dropmenu = new TQPopupMenu (m_view->playList ());
  640. m_dropmenu->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("player_playlist"), TDEIcon::Small, 0, true), i18n ("&Add to list"), TQT_TQOBJECT(this), TQT_SLOT (menuDropInList ()));
  641. m_dropmenu->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("folder_grey"), TDEIcon::Small, 0, true), i18n ("Add in new &Group"), TQT_TQOBJECT(this), TQT_SLOT (menuDropInGroup ()));
  642. m_dropmenu->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("edit-copy"), TDEIcon::Small, 0, true), i18n ("&Copy here"), TQT_TQOBJECT(this), TQT_SLOT (menuCopyDrop ()));
  643. m_dropmenu->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("edit-delete"), TDEIcon::Small, 0, true), i18n ("&Delete"), TQT_TQOBJECT(this), TQT_SLOT (menuDeleteNode ()));
  644. /*TQPopupMenu * viewmenu = new TQPopupMenu;
  645. viewmenu->insertItem (i18n ("Full Screen"), TQT_TQOBJECT(this), TQT_SLOT(fullScreen ()),
  646. TQKeySequence ("CTRL + Key_F"));
  647. menuBar ()->insertItem (i18n ("&View"), viewmenu, -1, 2);*/
  648. //toolBar("mainToolBar")->hide();
  649. setAcceptDrops (true);
  650. }
  651. void KMPlayerApp::slotFakeKeyEvent()
  652. {
  653. if ( m_player && m_player->isPlaying() && !m_player->isPaused())
  654. if (m_haveKWin) {
  655. // use a better method if we're in a tde environment
  656. kdDebug() << "KMPlayer: Fake mouse movement\n";
  657. XWarpPointer(x11Display(), None, None, 0, 0, 0, 0, 0, 0);
  658. XFlush(x11Display());
  659. } else {
  660. if(haveXTest) {
  661. #ifdef HAVE_XTEST
  662. kdDebug() << "KMPlayer: Fake key press\n";
  663. XTestFakeKeyEvent(x11Display(), fakeKeycode, true, 0);
  664. XTestFakeKeyEvent(x11Display(), fakeKeycode, false, 0);
  665. XFlush(x11Display());
  666. #endif
  667. }
  668. }
  669. }
  670. KDE_NO_EXPORT void KMPlayerApp::loadingProgress (int perc) {
  671. if (perc < 100)
  672. statusBar ()->changeItem (TQString ("%1%").arg (perc), id_status_timer);
  673. else
  674. statusBar ()->changeItem (TQString ("--:--"), id_status_timer);
  675. }
  676. KDE_NO_EXPORT void KMPlayerApp::positioned (int pos, int length) {
  677. int left = (length - pos) / 10;
  678. if (left != last_time_left) {
  679. last_time_left = left;
  680. TQString text ("--:--");
  681. if (left > 0) {
  682. int h = left / 3600;
  683. int m = (left % 3600) / 60;
  684. int s = left % 60;
  685. if (h > 0)
  686. text.sprintf ("%d:%02d:%02d", h, m, s);
  687. else
  688. text.sprintf ("%02d:%02d", m, s);
  689. }
  690. statusBar ()->changeItem (text, id_status_timer);
  691. }
  692. }
  693. KDE_NO_EXPORT void KMPlayerApp::windowVideoConsoleToggled (int wt) {
  694. if (wt == int (KMPlayer::View::WT_Video)) {
  695. toggleView->setText (i18n ("C&onsole"));
  696. toggleView->setIcon (TQString ("konsole"));
  697. } else {
  698. toggleView->setText (i18n ("V&ideo"));
  699. toggleView->setIcon (TQString ("video-x-generic"));
  700. }
  701. }
  702. KDE_NO_EXPORT void KMPlayerApp::playerStarted () {
  703. KMPlayer::Source * source = m_player->source ();
  704. if (!strcmp (source->name (), "urlsource")) {
  705. KURL url = source->url ();
  706. if (url.url ().startsWith ("lists"))
  707. return;
  708. if (url.isEmpty () && m_player->process ()->mrl ())
  709. url = KURL (m_player->process ()->mrl ()->mrl ()->src);
  710. recentFiles ()->addURL (url);
  711. recents->defer (); // make sure it's loaded
  712. recents->insertBefore (new Recent (recents, this, url.url ()), recents->firstChild ());
  713. KMPlayer::NodePtr c = recents->firstChild ()->nextSibling ();
  714. int count = 1;
  715. KMPlayer::NodePtr more;
  716. while (c) {
  717. if (c->id == id_node_recent_node &&
  718. c->mrl ()->src == url.url ()) {
  719. KMPlayer::NodePtr tmp = c->nextSibling ();
  720. recents->removeChild (c);
  721. c = tmp;
  722. } else {
  723. if (c->id == KMPlayer::id_node_group_node)
  724. more = c;
  725. c = c->nextSibling ();
  726. count++;
  727. }
  728. }
  729. if (!more && count > 10) {
  730. more = new Group (recents, this, i18n ("More..."));
  731. recents->appendChild (more);
  732. }
  733. if (more) {
  734. KMPlayer::NodePtr item;
  735. if (count > 10) {
  736. KMPlayer::NodePtr item = more->previousSibling ();
  737. recents->removeChild (item);
  738. more->insertBefore (item, more->firstChild ());
  739. }
  740. if (more->firstChild ())
  741. c = more->firstChild ()->nextSibling ();
  742. count = 0;
  743. while (c) {
  744. if (c->id == id_node_recent_node &&
  745. c->mrl ()->src == url.url ()) {
  746. KMPlayer::NodePtr tmp = c->nextSibling ();
  747. more->removeChild (c);
  748. c = tmp;
  749. } else {
  750. c = c->nextSibling ();
  751. count++;
  752. }
  753. }
  754. if (count > 50)
  755. more->removeChild (more->lastChild ());
  756. }
  757. m_view->playList ()->updateTree (recents_id, recents, 0, false, false);
  758. }
  759. }
  760. KDE_NO_EXPORT void KMPlayerApp::slotSourceChanged (KMPlayer::Source *olds, KMPlayer::Source * news) {
  761. if (olds) {
  762. disconnect (olds, TQT_SIGNAL (titleChanged (const TQString &)), this,
  763. TQT_SLOT (setCaption (const TQString &)));
  764. disconnect (olds, TQT_SIGNAL (startPlaying ()),
  765. TQT_TQOBJECT(this), TQT_SLOT (playerStarted ()));
  766. }
  767. if (news) {
  768. setCaption (news->prettyName (), false);
  769. connect (news, TQT_SIGNAL (titleChanged (const TQString &)),
  770. TQT_TQOBJECT(this), TQT_SLOT (setCaption (const TQString &)));
  771. connect (news, TQT_SIGNAL (startPlaying ()),
  772. TQT_TQOBJECT(this), TQT_SLOT (playerStarted ()));
  773. viewSyncEditMode->setEnabled (m_view->editMode () ||
  774. !strcmp (m_player->source ()->name (), "urlsource"));
  775. }
  776. }
  777. KDE_NO_EXPORT void KMPlayerApp::dvdNav () {
  778. slotStatusMsg(i18n("DVD Navigation..."));
  779. m_player->setSource (m_player->sources () ["dvdnavsource"]);
  780. slotStatusMsg(i18n("Ready"));
  781. }
  782. KDE_NO_EXPORT void KMPlayerApp::openDVD () {
  783. slotStatusMsg(i18n("Opening DVD..."));
  784. m_player->setSource (m_player->sources () ["dvdsource"]);
  785. }
  786. KDE_NO_EXPORT void KMPlayerApp::openVCD () {
  787. slotStatusMsg(i18n("Opening VCD..."));
  788. m_player->setSource (m_player->sources () ["vcdsource"]);
  789. }
  790. KDE_NO_EXPORT void KMPlayerApp::openAudioCD () {
  791. slotStatusMsg(i18n("Opening Audio CD..."));
  792. m_player->setSource (m_player->sources () ["audiocdsource"]);
  793. }
  794. KDE_NO_EXPORT void KMPlayerApp::openPipe () {
  795. slotStatusMsg(i18n("Opening pipe..."));
  796. bool ok;
  797. TQString cmd = KLineEditDlg::getText (i18n("Read From Pipe"),
  798. i18n ("Enter a command that will output an audio/video stream\nto the stdout. This will be piped to a player's stdin.\n\nCommand:"), m_player->sources () ["pipesource"]->pipeCmd (), &ok, m_player->view());
  799. if (!ok) {
  800. slotStatusMsg (i18n ("Ready."));
  801. return;
  802. }
  803. static_cast <KMPlayerPipeSource *> (m_player->sources () ["pipesource"])->setCommand (cmd);
  804. m_player->setSource (m_player->sources () ["pipesource"]);
  805. }
  806. KDE_NO_EXPORT void KMPlayerApp::openVDR () {
  807. slotStatusMsg(i18n("Opening VDR..."));
  808. if (!strcmp (m_player->source ()->name (), "vdrsource") && m_player->process ()->playing ())
  809. static_cast<KMPlayerVDRSource *>(m_player->source())->toggleConnected();
  810. else
  811. m_player->setSource (m_player->sources () ["vdrsource"]);
  812. }
  813. #ifdef HAVE_CAIRO
  814. struct IntroSource : public KMPlayer::Source {
  815. KMPlayerApp * m_app;
  816. IntroSource (KMPlayer::PartBase *p, KMPlayerApp * a)
  817. : KMPlayer::Source (i18n ("Intro"), p, "introsource"), m_app (a) {}
  818. KDE_NO_EXPORT bool hasLength () { return false; }
  819. KDE_NO_EXPORT bool isSeekable () { return false; }
  820. KDE_NO_EXPORT TQString prettyName () { return i18n ("Intro"); }
  821. void activate ();
  822. void deactivate ();
  823. void stateElementChanged (KMPlayer::Node * node, KMPlayer::Node::State os, KMPlayer::Node::State ns);
  824. bool deactivated;
  825. bool finished;
  826. };
  827. KDE_NO_EXPORT void IntroSource::activate () {
  828. if (m_player->settings ()->autoresize)
  829. m_app->disconnect(m_player, TQT_SIGNAL(sourceDimensionChanged()),m_app,TQT_SLOT(zoom100()));
  830. m_document = new KMPlayer::Document (TQString (""), this);
  831. TQString introfile = locate ("data", "kmplayer/intro.xml");
  832. TQFile file (introfile);
  833. if (file.exists () && file.open (IO_ReadOnly)) {
  834. TQTextStream ts (&file);
  835. KMPlayer::readXML (m_document, ts, TQString (), false);
  836. } else {
  837. TQString smil = TQString::fromLatin1 (
  838. "<smil><head><layout>"
  839. "<root-layout width='320' height='240' background-color='black'/>"
  840. "<region id='image1' left='31.25%' top='25%' width='37.5%' height='50%' z-order='1'/>"
  841. "<region id='reg1' top='10%' height='80%' z-order='2'>"
  842. "<region id='image2' left='128' top='72' width='64' bottom='56'/>"
  843. "</region>"
  844. "</layout>"
  845. "<transition id='fadein-1' dur='0.6' type='fade'/>"
  846. "<transition id='iris1' dur='0.3' type='irisWipe'/>"
  847. "</head>"
  848. "<body>"
  849. "<excl>"
  850. "<par>"
  851. "<img src='%1' region='image1' dur='.6' fit='fill' transOut='iris1'/>"
  852. "<img region='image2' src='%2' begin='0.3' dur='0.6' fit='hidden' fill='freeze' transIn='fadein-1'/>"
  853. "</par>"
  854. "<seq begin='reg1.activateEvent'/>"
  855. "</excl>"
  856. "</body></smil>"
  857. ).arg (locate ("data", "kmplayer/noise.gif")).arg (TDEGlobal::iconLoader()->iconPath (TQString::fromLatin1 ("kmplayer"), -64));
  858. TQTextStream ts (smil.utf8 (), IO_ReadOnly);
  859. KMPlayer::readXML (m_document, ts, TQString (), false);
  860. }
  861. //m_document->normalize ();
  862. m_current = m_document; //mrl->self ();
  863. if (m_document && m_document->firstChild ()) {
  864. KMPlayer::Mrl * mrl = m_document->firstChild ()->mrl ();
  865. if (mrl) {
  866. Source::setDimensions (m_document->firstChild (), mrl->width, mrl->height);
  867. m_player->updateTree ();
  868. m_current->activate ();
  869. emit startPlaying ();
  870. }
  871. }
  872. deactivated = finished = false;
  873. }
  874. KDE_NO_EXPORT void IntroSource::stateElementChanged (KMPlayer::Node * node, KMPlayer::Node::State, KMPlayer::Node::State new_state) {
  875. if (new_state == KMPlayer::Node::state_deactivated &&
  876. m_document == node) {
  877. m_document->reset ();
  878. finished = true;
  879. if (m_player->view ())
  880. m_app->restoreFromConfig ();
  881. emit stopPlaying ();
  882. if (!deactivated) // replace introsource with urlsource
  883. m_player->openURL (KURL ());
  884. }
  885. }
  886. KDE_NO_EXPORT void IntroSource::deactivate () {
  887. deactivated = true;
  888. if (m_player->settings ()->autoresize)
  889. m_app->connect(m_player, TQT_SIGNAL(sourceDimensionChanged()),m_app,TQT_SLOT(zoom100()));
  890. if (!finished && m_document) // user opens a source while introducing
  891. m_document->reset ();
  892. }
  893. #endif
  894. KDE_NO_EXPORT void KMPlayerApp::restoreFromConfig () {
  895. if (m_player->view ()) {
  896. m_view->docArea ()->hide ();
  897. m_view->docArea ()->readDockConfig (m_player->config (), TQString ("Window Layout"));
  898. m_view->docArea ()->show ();
  899. m_view->layout ()->activate ();
  900. }
  901. }
  902. KDE_NO_EXPORT void KMPlayerApp::openDocumentFile (const KURL& url)
  903. {
  904. if (!m_played_intro) {
  905. m_played_intro = true;
  906. KMPlayer::Source * src = m_player->sources () ["urlsource"];
  907. if (url.isEmpty () && src->document () &&
  908. src->document ()->hasChildNodes ()) {
  909. restoreFromConfig ();
  910. m_player->setSource (src);
  911. return;
  912. #ifdef HAVE_CAIRO
  913. } else if (!m_player->settings ()->no_intro && url.isEmpty ()) {
  914. m_player->setSource (new IntroSource (m_player, this));
  915. return;
  916. #endif
  917. } else {
  918. m_played_exit = true; // no intro, so no exit as well
  919. restoreFromConfig ();
  920. }
  921. }
  922. slotStatusMsg(i18n("Opening file..."));
  923. m_player->openURL (url);
  924. if (m_broadcastconfig->broadcasting () && url.url() == m_broadcastconfig->serverURL ()) {
  925. // speed up replay
  926. FFServerSetting & ffs = m_broadcastconfig->ffserversettings;
  927. KMPlayer::Source * source = m_player->source ();
  928. if (!ffs.width.isEmpty () && !ffs.height.isEmpty ()) {
  929. source->setWidth (ffs.width.toInt ());
  930. source->setHeight (ffs.height.toInt ());
  931. }
  932. source->setIdentified ();
  933. }
  934. slotStatusMsg (i18n ("Ready."));
  935. }
  936. KDE_NO_EXPORT void KMPlayerApp::addURL (const KURL& url) {
  937. KMPlayer::Source * src = m_player->sources () ["urlsource"];
  938. KMPlayer::NodePtr d = src->document ();
  939. if (d)
  940. d->appendChild (new KMPlayer::GenericURL (d, url.url ()));
  941. }
  942. KDE_NO_EXPORT void KMPlayerApp::saveProperties (TDEConfig * config) {
  943. config->writeEntry ("URL", m_player->source ()->url ().url ());
  944. config->writeEntry ("Visible", isVisible ());
  945. }
  946. KDE_NO_EXPORT void KMPlayerApp::readProperties (TDEConfig * config) {
  947. KURL url (config->readEntry ("URL", TQString ()));
  948. openDocumentFile (url);
  949. if (!config->readBoolEntry ("Visible", true) && m_systray)
  950. hide ();
  951. }
  952. KDE_NO_EXPORT void KMPlayerApp::resizePlayer (int percentage) {
  953. KMPlayer::Source * source = m_player->source ();
  954. if (!source)
  955. return;
  956. int w, h;
  957. source->dimensions (w, h);
  958. if (w == 0 && h == 0) {
  959. w = 320;
  960. h = 240;
  961. } else
  962. h = m_view->viewer ()->heightForWidth (w);
  963. //kdDebug () << "KMPlayerApp::resizePlayer (" << w << "," << h << ")" << endl;
  964. if (w > 0 && h > 0) {
  965. if (m_view->controlPanel ()->isVisible ())
  966. h += m_view->controlPanel ()->size ().height ();
  967. TQSize s1 = size ();
  968. TQSize s2 = m_view->viewArea ()->size ();
  969. w += s1.width () - s2.width ();
  970. h += s1.height () - s2.height ();
  971. w = int (1.0 * w * percentage/100.0);
  972. h = int (1.0 * h * percentage/100.0);
  973. TQSize s = sizeForCentralWidgetSize (TQSize (w, h));
  974. if (s.width () != width () || s.height () != height ()) {
  975. TQSize oldsize = m_view->viewArea ()->size ();
  976. resize (s);
  977. }
  978. }
  979. }
  980. KDE_NO_EXPORT void KMPlayerApp::zoom50 () {
  981. resizePlayer (50);
  982. }
  983. KDE_NO_EXPORT void KMPlayerApp::zoom100 () {
  984. resizePlayer (100);
  985. }
  986. KDE_NO_EXPORT void KMPlayerApp::zoom150 () {
  987. resizePlayer (150);
  988. }
  989. KDE_NO_EXPORT void KMPlayerApp::zoom200 () {
  990. resizePlayer (200);
  991. }
  992. KDE_NO_EXPORT void KMPlayerApp::zoom300 () {
  993. resizePlayer (300);
  994. }
  995. KDE_NO_EXPORT void KMPlayerApp::editMode () {
  996. m_view->docArea ()->hide ();
  997. bool editmode = !m_view->editMode ();
  998. KMPlayer::PlayListItem * pi = m_view->playList ()->currentPlayListItem ();
  999. if (!pi || !pi->node)
  1000. editmode = false;
  1001. m_view->docArea ()->show ();
  1002. viewEditMode->setChecked (editmode);
  1003. KMPlayer::RootPlayListItem * ri = (edit_tree_id > 0 && !editmode)
  1004. ? m_view->playList ()->rootItem (edit_tree_id)
  1005. : m_view->playList ()->rootItem (pi);
  1006. if (editmode) {
  1007. edit_tree_id = ri->id;
  1008. m_view->setEditMode (ri, true);
  1009. m_view->setInfoMessage (pi->node->innerXML ());
  1010. viewSyncEditMode->setEnabled (true);
  1011. } else {
  1012. m_view->setEditMode (ri, false);
  1013. edit_tree_id = -1;
  1014. viewSyncEditMode->setEnabled (!strcmp (m_player->source ()->name (), "urlsource"));
  1015. }
  1016. }
  1017. KDE_NO_EXPORT void KMPlayerApp::syncEditMode () {
  1018. if (edit_tree_id > -1) {
  1019. KMPlayer::PlayListItem *si = m_view->playList()->selectedPlayListItem();
  1020. if (si && si->node) {
  1021. si->node->clearChildren ();
  1022. TQString txt = m_view->infoPanel ()->text ();
  1023. TQTextStream ts (txt, IO_ReadOnly);
  1024. KMPlayer::readXML (si->node, ts, TQString (), false);
  1025. m_view->playList ()->updateTree (edit_tree_id, si->node->document(), si->node, true, false);
  1026. }
  1027. } else
  1028. m_player->openURL (m_player->source ()->url ());
  1029. }
  1030. KDE_NO_EXPORT void KMPlayerApp::showBroadcastConfig () {
  1031. m_player->settings ()->addPage (m_broadcastconfig);
  1032. m_player->settings ()->addPage (m_ffserverconfig);
  1033. }
  1034. KDE_NO_EXPORT void KMPlayerApp::hideBroadcastConfig () {
  1035. m_player->settings ()->removePage (m_broadcastconfig);
  1036. m_player->settings ()->removePage (m_ffserverconfig);
  1037. }
  1038. KDE_NO_EXPORT void KMPlayerApp::broadcastClicked () {
  1039. if (m_broadcastconfig->broadcasting ())
  1040. m_broadcastconfig->stopServer ();
  1041. else {
  1042. m_player->settings ()->show ("BroadcastPage");
  1043. m_view->controlPanel()->broadcastButton ()->toggle ();
  1044. }
  1045. }
  1046. KDE_NO_EXPORT void KMPlayerApp::broadcastStarted () {
  1047. if (!m_view->controlPanel()->broadcastButton ()->isOn ())
  1048. m_view->controlPanel()->broadcastButton ()->toggle ();
  1049. }
  1050. KDE_NO_EXPORT void KMPlayerApp::broadcastStopped () {
  1051. if (m_view->controlPanel()->broadcastButton ()->isOn ())
  1052. m_view->controlPanel()->broadcastButton ()->toggle ();
  1053. if (m_player->source () != m_player->sources () ["tvsource"])
  1054. m_view->controlPanel()->broadcastButton ()->hide ();
  1055. setCursor (TQCursor (TQt::ArrowCursor));
  1056. }
  1057. KDE_NO_EXPORT bool KMPlayerApp::broadcasting () const {
  1058. return m_broadcastconfig->broadcasting ();
  1059. }
  1060. KDE_NO_EXPORT void KMPlayerApp::saveOptions()
  1061. {
  1062. config->setGroup ("General Options");
  1063. if (m_player->settings ()->remembersize)
  1064. config->writeEntry ("Geometry", size());
  1065. config->writeEntry ("Show Toolbar", viewToolBar->isChecked());
  1066. config->writeEntry ("ToolBarPos", (int) toolBar("mainToolBar")->barPos());
  1067. config->writeEntry ("Show Statusbar",viewStatusBar->isChecked());
  1068. config->writeEntry ("Show Menubar",viewMenuBar->isChecked());
  1069. if (!m_player->sources () ["pipesource"]->pipeCmd ().isEmpty ()) {
  1070. config->setGroup ("Pipe Command");
  1071. config->writeEntry ("Command1", m_player->sources () ["pipesource"]->pipeCmd ());
  1072. }
  1073. m_view->setInfoMessage (TQString ());
  1074. m_view->docArea ()->writeDockConfig (config, TQString ("Window Layout"));
  1075. Recents * rc = static_cast <Recents *> (recents.ptr ());
  1076. if (rc && rc->resolved) {
  1077. fileOpenRecent->saveEntries (config,"Recent Files");
  1078. rc->writeToFile (locateLocal ("data", "kmplayer/recent.xml"));
  1079. }
  1080. Playlist * pl = static_cast <Playlist *> (playlist.ptr ());
  1081. if (pl && pl->resolved)
  1082. pl->writeToFile (locateLocal ("data", "kmplayer/playlist.xml"));
  1083. }
  1084. KDE_NO_EXPORT void KMPlayerApp::readOptions() {
  1085. config->setGroup("General Options");
  1086. // bar position settings
  1087. TDEToolBar::BarPosition toolBarPos;
  1088. toolBarPos=(TDEToolBar::BarPosition) config->readNumEntry("ToolBarPos", TDEToolBar::Top);
  1089. toolBar("mainToolBar")->setBarPos(toolBarPos);
  1090. // bar status settings
  1091. viewToolBar->setChecked (config->readBoolEntry("Show Toolbar", true));
  1092. slotViewToolBar();
  1093. bool bViewStatusbar = config->readBoolEntry("Show Statusbar", true);
  1094. viewStatusBar->setChecked(bViewStatusbar);
  1095. slotViewStatusBar();
  1096. viewMenuBar->setChecked (config->readBoolEntry("Show Menubar", true));
  1097. slotViewMenuBar();
  1098. TQSize size = config->readSizeEntry ("Geometry");
  1099. if (!size.isEmpty ())
  1100. resize (size);
  1101. else if (m_player->settings ()->remembersize)
  1102. resize (TQSize (640, 480));
  1103. config->setGroup ("Pipe Command");
  1104. static_cast <KMPlayerPipeSource *> (m_player->sources () ["pipesource"])->setCommand (config->readEntry ("Command1", ""));
  1105. // initialize the recent file list
  1106. if (!recents) {
  1107. fileOpenRecent->loadEntries(config,"Recent Files");
  1108. recents = new Recents (this);
  1109. recents_id = m_view->playList ()->addTree (recents, "listssource", "history", KMPlayer::PlayListView::AllowDrag);
  1110. }
  1111. configChanged ();
  1112. }
  1113. #include <netwm.h>
  1114. #undef Always
  1115. #undef Never
  1116. #undef Status
  1117. #undef Unsorted
  1118. #undef Bool
  1119. KDE_NO_EXPORT void KMPlayerApp::minimalMode (bool by_user) {
  1120. unsigned long props = NET::WMWindowType;
  1121. NETWinInfo winfo (tqt_xdisplay (), winId (), tqt_xrootwin (), props);
  1122. if (m_minimal_mode) {
  1123. readOptions ();
  1124. if (by_user)
  1125. disconnect (m_view->controlPanel ()->button (KMPlayer::ControlPanel::button_playlist), TQT_SIGNAL (clicked ()), TQT_TQOBJECT(this), TQT_SLOT (slotMinimalMode ()));
  1126. restoreFromConfig ();
  1127. } else {
  1128. saveOptions ();
  1129. menuBar()->hide();
  1130. toolBar("mainToolBar")->hide();
  1131. statusBar()->hide();
  1132. if (by_user)
  1133. connect (m_view->controlPanel ()->button (KMPlayer::ControlPanel::button_playlist), TQT_SIGNAL (clicked ()), TQT_TQOBJECT(this), TQT_SLOT (slotMinimalMode ()));
  1134. }
  1135. m_view->viewArea ()->minimalMode ();
  1136. m_minimal_mode = !m_minimal_mode;
  1137. }
  1138. KDE_NO_EXPORT void KMPlayerApp::slotMinimalMode () {
  1139. minimalMode (true);
  1140. }
  1141. #ifdef HAVE_CAIRO
  1142. struct ExitSource : public KMPlayer::Source {
  1143. KDE_NO_CDTOR_EXPORT ExitSource (KMPlayer::PartBase *p)
  1144. : KMPlayer::Source (i18n ("Exit"), p, "exitsource") {}
  1145. KDE_NO_EXPORT TQString prettyName () { return i18n ("Exit"); }
  1146. KDE_NO_EXPORT bool hasLength () { return false; }
  1147. KDE_NO_EXPORT bool isSeekable () { return false; }
  1148. void activate ();
  1149. KDE_NO_EXPORT void deactivate () {}
  1150. void stateElementChanged (KMPlayer::Node * node, KMPlayer::Node::State os, KMPlayer::Node::State ns);
  1151. };
  1152. KDE_NO_EXPORT void ExitSource::activate () {
  1153. m_document = new KMPlayer::Document (TQString (""), this);
  1154. TQString exitfile = locate ("data", "kmplayer/exit.xml");
  1155. TQFile file (exitfile);
  1156. if (file.exists () && file.open (IO_ReadOnly)) {
  1157. TQTextStream ts (&file);
  1158. KMPlayer::readXML (m_document, ts, TQString (), false);
  1159. } else {
  1160. TQString smil = TQString::fromLatin1 ("<smil><head><layout>"
  1161. "<root-layout width='320' height='240' background-color='black'/>"
  1162. "<region id='reg1' top='10%' height='80%' z-order='2'>"
  1163. "<region id='image' left='128' top='72' width='64' bottom='56'/>"
  1164. "</region></layout>"
  1165. "<transition id='pw' dur='0.3' type='pushWipe' subtype='fromBottom'/>"
  1166. "</head><body>"
  1167. "<par>"
  1168. //"<animate target='reg1' attribute='background-color' calcMode='discrete' values='#FFFFFF;#E4E4E4;#CCCCCC;#B4B4B4;#9E9E9E;#8A8A8A;#777777;#656565;#555555;#464646;#393939;#2D2D2D;#222222;#191919;#111111;#0B0B0B;#060606;#020202;#000000;#000000' dur='0.6'/>"
  1169. "<img src='%2' id='img1' region='image' dur='0.4' fit='hidden' transOut='pw'/>"
  1170. "</par>"
  1171. "</body></smil>").arg (TDEGlobal::iconLoader()->iconPath (TQString::fromLatin1 ("kmplayer"), -64));
  1172. TQTextStream ts (smil.utf8 (), IO_ReadOnly);
  1173. KMPlayer::readXML (m_document, ts, TQString (), false);
  1174. }
  1175. //m_document->normalize ();
  1176. m_current = m_document;
  1177. if (m_document && m_document->firstChild ()) {
  1178. KMPlayer::Mrl * mrl = m_document->firstChild ()->mrl ();
  1179. if (mrl) {
  1180. setDimensions (m_document->firstChild (), mrl->width, mrl->height);
  1181. m_player->updateTree ();
  1182. m_current->activate ();
  1183. emit startPlaying ();
  1184. return;
  1185. }
  1186. }
  1187. tqApp->quit ();
  1188. }
  1189. KDE_NO_EXPORT void ExitSource::stateElementChanged (KMPlayer::Node * node, KMPlayer::Node::State, KMPlayer::Node::State new_state) {
  1190. if (new_state == KMPlayer::Node::state_deactivated &&
  1191. m_document == node &&
  1192. m_player->view ())
  1193. m_player->view ()->topLevelWidget ()->close ();
  1194. }
  1195. #endif
  1196. KDE_NO_EXPORT bool KMPlayerApp::queryClose () {
  1197. // KMPlayerVDRSource has to wait for pending commands like mute and quit
  1198. m_player->stop ();
  1199. static_cast <KMPlayerVDRSource *> (m_player->sources () ["vdrsource"])->waitForConnectionClose ();
  1200. // is arts control still running
  1201. if (!m_dcopName.isEmpty ()) {
  1202. TQCString replytype;
  1203. TQByteArray data, replydata;
  1204. kapp->dcopClient ()->call (m_dcopName, "MainApplication-Interface", "quit()", data, replytype, replydata);
  1205. }
  1206. if (m_played_exit || m_player->settings ()->no_intro || kapp->sessionSaving() )
  1207. return true;
  1208. if (m_auto_resize)
  1209. disconnect(m_player, TQT_SIGNAL(sourceDimensionChanged()),this,TQT_SLOT(zoom100()));
  1210. m_played_exit = true;
  1211. if (!m_minimal_mode)
  1212. minimalMode (false);
  1213. #ifdef HAVE_CAIRO
  1214. m_player->setSource (new ExitSource (m_player));
  1215. return false;
  1216. #else
  1217. return true;
  1218. #endif
  1219. }
  1220. KDE_NO_EXPORT bool KMPlayerApp::queryExit()
  1221. {
  1222. if (!m_minimal_mode)
  1223. saveOptions();
  1224. disconnect (m_player->settings (), TQT_SIGNAL (configChanged ()),
  1225. TQT_TQOBJECT(this), TQT_SLOT (configChanged ()));
  1226. m_player->settings ()->writeConfig ();
  1227. return true;
  1228. }
  1229. KDE_NO_EXPORT void KMPlayerApp::slotFileNewWindow()
  1230. {
  1231. slotStatusMsg(i18n("Opening a new application window..."));
  1232. KMPlayerApp *new_window= new KMPlayerApp();
  1233. new_window->show();
  1234. slotStatusMsg(i18n("Ready."));
  1235. }
  1236. KDE_NO_EXPORT void KMPlayerApp::slotFileOpen () {
  1237. KURL::List urls = KFileDialog::getOpenURLs (TQString (), i18n ("*|All Files"), this, i18n ("Open File"));
  1238. if (urls.size () == 1) {
  1239. openDocumentFile (urls [0]);
  1240. } else if (urls.size () > 1) {
  1241. m_player->openURL (KURL ());
  1242. for (unsigned int i = 0; i < urls.size (); i++)
  1243. addURL (urls [i]);
  1244. }
  1245. }
  1246. KDE_NO_EXPORT void KMPlayerApp::slotFileOpenRecent(const KURL& url)
  1247. {
  1248. slotStatusMsg(i18n("Opening file..."));
  1249. openDocumentFile (url);
  1250. }
  1251. KDE_NO_EXPORT void KMPlayerApp::slotSaveAs () {
  1252. TQString url = KFileDialog::getSaveFileName (TQString (), TQString (), this, i18n ("Save File"));
  1253. if (!url.isEmpty ()) {
  1254. TQFile file (url);
  1255. if (!file.open (IO_WriteOnly)) {
  1256. KMessageBox::error (this, i18n ("Error opening file %1.\n%2.").arg (url).arg (file.errorString ()), i18n("Error"));
  1257. return;
  1258. }
  1259. if (m_player->source ()) {
  1260. KMPlayer::NodePtr doc = m_player->source ()->document ();
  1261. if (doc) {
  1262. TQTextStream ts (&file);
  1263. ts.setEncoding (TQTextStream::UnicodeUTF8);
  1264. ts << TQString ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  1265. if (doc->childNodes ()->length () == 1)
  1266. ts << doc->innerXML ();
  1267. else
  1268. ts << doc->outerXML ();
  1269. }
  1270. }
  1271. file.close ();
  1272. }
  1273. }
  1274. KDE_NO_EXPORT void KMPlayerApp::slotClearHistory () {
  1275. //fileOpenRecent->clearURLList ();
  1276. int mi = fileOpenRecent->maxItems ();
  1277. fileOpenRecent->setMaxItems (0);
  1278. fileOpenRecent->setMaxItems (mi);
  1279. m_player->settings ()->urllist.clear ();
  1280. m_player->settings ()->sub_urllist.clear ();
  1281. if (recents) { // small window this check fails and thus ClearHistory fails
  1282. recents->defer (); // make sure it's loaded
  1283. recents->clear ();
  1284. m_view->playList ()->updateTree (recents_id, recents, 0, false, false);
  1285. }
  1286. }
  1287. KDE_NO_EXPORT void KMPlayerApp::slotFileClose()
  1288. {
  1289. slotStatusMsg(i18n("Closing file..."));
  1290. m_player->stop ();
  1291. slotStatusMsg(i18n("Ready."));
  1292. }
  1293. KDE_NO_EXPORT void KMPlayerApp::slotFileQuit()
  1294. {
  1295. slotStatusMsg(i18n("Exiting..."));
  1296. // whoever implemented this should fix it too, work around ..
  1297. if (memberList->count () > 1)
  1298. deleteLater ();
  1299. else
  1300. tqApp->quit ();
  1301. // close the first window, the list makes the next one the first again.
  1302. // This ensures that queryClose() is called on each window to ask for closing
  1303. /*TDEMainWindow* w;
  1304. if(memberList)
  1305. {
  1306. for(w=memberList->first(); w!=0; w=memberList->first())
  1307. {
  1308. // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog,
  1309. // the window and the application stay open.
  1310. if(!w->close())
  1311. break;
  1312. }
  1313. }*/
  1314. }
  1315. KDE_NO_EXPORT void KMPlayerApp::slotPreferences () {
  1316. m_player->showConfigDialog ();
  1317. }
  1318. KDE_NO_EXPORT void KMPlayerApp::slotConfigureKeys () {
  1319. KKeyDialog::configure( actionCollection(), this );
  1320. }
  1321. KDE_NO_EXPORT void KMPlayerApp::slotConfigureToolbars () {
  1322. KEditToolbar dlg (actionCollection ());
  1323. if (dlg.exec ())
  1324. initMenu (); // also add custom popups //createGUI ();
  1325. }
  1326. KDE_NO_EXPORT void KMPlayerApp::slotViewToolBar() {
  1327. m_showToolbar = viewToolBar->isChecked();
  1328. if(m_showToolbar)
  1329. toolBar("mainToolBar")->show();
  1330. else
  1331. toolBar("mainToolBar")->hide();
  1332. }
  1333. KDE_NO_EXPORT void KMPlayerApp::slotViewStatusBar() {
  1334. m_showStatusbar = viewStatusBar->isChecked();
  1335. if(m_showStatusbar)
  1336. statusBar()->show();
  1337. else
  1338. statusBar()->hide();
  1339. }
  1340. KDE_NO_EXPORT void KMPlayerApp::slotViewMenuBar() {
  1341. m_showMenubar = viewMenuBar->isChecked();
  1342. if (m_showMenubar) {
  1343. menuBar()->show();
  1344. slotStatusMsg(i18n("Ready"));
  1345. } else {
  1346. menuBar()->hide();
  1347. slotStatusMsg (i18n ("Show Menubar with %1").arg(viewMenuBar->shortcutText()));
  1348. if (!m_showStatusbar) {
  1349. statusBar()->show();
  1350. TQTimer::singleShot (3000, statusBar(), TQT_SLOT (hide ()));
  1351. }
  1352. }
  1353. }
  1354. KDE_NO_EXPORT void KMPlayerApp::slotStatusMsg (const TQString &text) {
  1355. KStatusBar * sb = statusBar ();
  1356. sb->clear ();
  1357. sb->changeItem (text, id_status_msg);
  1358. }
  1359. KDE_NO_EXPORT void KMPlayerApp::fullScreen () {
  1360. // if (TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender ()))->metaObject ()->inherits ("TDEAction"))
  1361. if (TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender ()))->inherits ("TDEAction"))
  1362. m_view->fullScreen();
  1363. #if KDE_IS_VERSION(3,1,90)
  1364. viewFullscreen->setChecked (m_view->isFullScreen ());
  1365. #endif
  1366. if (m_view->isFullScreen())
  1367. hide ();
  1368. else {
  1369. show ();
  1370. setGeometry (m_view->viewArea ()->topWindowRect ());
  1371. }
  1372. }
  1373. KDE_NO_EXPORT void KMPlayerApp::playListItemSelected (TQListViewItem * item) {
  1374. KMPlayer::PlayListItem * vi = static_cast <KMPlayer::PlayListItem *> (item);
  1375. if (edit_tree_id > -1) {
  1376. if (vi->playListView ()->rootItem (item)->id != edit_tree_id)
  1377. editMode ();
  1378. m_view->setInfoMessage (edit_tree_id > -1 ? vi->node->innerXML () : TQString ());
  1379. }
  1380. viewEditMode->setEnabled (vi->playListView ()->rootItem (item)->flags & KMPlayer::PlayListView::TreeEdit);
  1381. }
  1382. KDE_NO_EXPORT
  1383. void KMPlayerApp::playListItemDropped (TQDropEvent * de, TQListViewItem * after) {
  1384. if (!after) { // could still be a descendent
  1385. after = m_view->playList()->itemAt (m_view->playList()->contentsToViewport (de->pos ()));
  1386. if (after) {
  1387. TQListViewItem * p = after->itemAbove ();
  1388. if (p && p->nextSibling () != after)
  1389. after = after->parent ();
  1390. }
  1391. }
  1392. if (!after)
  1393. return;
  1394. KMPlayer::RootPlayListItem *ritem = m_view->playList()->rootItem(after);
  1395. if (ritem->id == 0)
  1396. return;
  1397. manip_node = 0L;
  1398. m_drop_list.clear ();
  1399. m_drop_after = after;
  1400. KMPlayer::NodePtr after_node = static_cast<KMPlayer::PlayListItem*> (after)->node;
  1401. if (after_node->id == KMPlayer::id_node_playlist_document ||
  1402. after_node->id == KMPlayer::id_node_group_node)
  1403. after_node->defer (); // make sure it has loaded
  1404. if (de->source () == m_view->playList() &&
  1405. m_view->playList()->lastDragTreeId () == playlist_id)
  1406. manip_node = m_view->playList()->lastDragNode ();
  1407. if (!manip_node && ritem->id == playlist_id) {
  1408. if (KURLDrag::canDecode (de)) {
  1409. KURLDrag::decode (de, m_drop_list);
  1410. } else if (TQTextDrag::canDecode (de)) {
  1411. TQString text;
  1412. TQTextDrag::decode (de, text);
  1413. m_drop_list.push_back (KURL (text));
  1414. }
  1415. }
  1416. m_dropmenu->changeItem (m_dropmenu->idAt (0),
  1417. !!manip_node ? i18n ("Move here") : i18n ("&Add to list"));
  1418. m_dropmenu->setItemVisible (m_dropmenu->idAt (3), !!manip_node);
  1419. m_dropmenu->setItemVisible (m_dropmenu->idAt (2), (manip_node && manip_node->isPlayable ()));
  1420. if (manip_node || m_drop_list.size () > 0)
  1421. m_dropmenu->exec (m_view->playList ()->mapToGlobal (m_view->playList ()->contentsToViewport (de->pos ())));
  1422. }
  1423. KDE_NO_EXPORT void KMPlayerApp::menuDropInList () {
  1424. KMPlayer::NodePtr n = static_cast<KMPlayer::PlayListItem*>(m_drop_after)->node;
  1425. KMPlayer::NodePtr pi;
  1426. for (int i = m_drop_list.size (); n && (i > 0 || manip_node); i--) {
  1427. if (manip_node && manip_node->parentNode ()) {
  1428. pi = manip_node;
  1429. manip_node = 0L;
  1430. pi->parentNode ()->removeChild (pi);
  1431. } else
  1432. pi = new PlaylistItem(playlist, this,false, m_drop_list[i-1].url());
  1433. if (n == playlist || m_drop_after->isOpen ())
  1434. n->insertBefore (pi, n->firstChild ());
  1435. else
  1436. n->parentNode ()->insertBefore (pi, n->nextSibling ());
  1437. }
  1438. m_view->playList()->updateTree (playlist_id, playlist, pi, true, false);
  1439. }
  1440. KDE_NO_EXPORT void KMPlayerApp::menuDropInGroup () {
  1441. KMPlayer::NodePtr n = static_cast<KMPlayer::PlayListItem*>(m_drop_after)->node;
  1442. if (!n)
  1443. return;
  1444. KMPlayer::NodePtr g = new PlaylistGroup (playlist, this, i18n("New group"));
  1445. if (n == playlist || m_drop_after->isOpen ())
  1446. n->insertBefore (g, n->firstChild ());
  1447. else
  1448. n->parentNode ()->insertBefore (g, n->nextSibling ());
  1449. KMPlayer::NodePtr pi;
  1450. for (int i = 0; i < m_drop_list.size () || manip_node; ++i) {
  1451. if (manip_node && manip_node->parentNode ()) {
  1452. pi = manip_node;
  1453. manip_node = 0L;
  1454. pi->parentNode ()->removeChild (pi);
  1455. } else
  1456. pi = new PlaylistItem (playlist,this, false, m_drop_list[i].url ());
  1457. g->appendChild (pi);
  1458. }
  1459. m_view->playList()->updateTree (playlist_id, playlist, pi, true, false);
  1460. }
  1461. KDE_NO_EXPORT void KMPlayerApp::menuCopyDrop () {
  1462. KMPlayer::NodePtr n = static_cast<KMPlayer::PlayListItem*>(m_drop_after)->node;
  1463. if (n && manip_node) {
  1464. KMPlayer::NodePtr pi = new PlaylistItem (playlist, this, false, manip_node->mrl ()->src);
  1465. if (n == playlist || m_drop_after->isOpen ())
  1466. n->insertBefore (pi, n->firstChild ());
  1467. else
  1468. n->parentNode ()->insertBefore (pi, n->nextSibling ());
  1469. m_view->playList()->updateTree (playlist_id, playlist, pi, true, false);
  1470. }
  1471. }
  1472. KDE_NO_EXPORT void KMPlayerApp::menuDeleteNode () {
  1473. KMPlayer::NodePtr n;
  1474. if (manip_node && manip_node->parentNode ()) {
  1475. n = manip_node->previousSibling() ? manip_node->previousSibling() : manip_node->parentNode ();
  1476. manip_node->parentNode ()->removeChild (manip_node);
  1477. }
  1478. m_view->playList()->updateTree (manip_tree_id, 0L, n, true, false);
  1479. }
  1480. KDE_NO_EXPORT void KMPlayerApp::menuMoveUpNode () {
  1481. KMPlayer::NodePtr n = manip_node;
  1482. if (n && n->parentNode () && n->previousSibling ()) {
  1483. KMPlayer::NodePtr prev = n->previousSibling ();
  1484. n->parentNode ()->removeChild (n);
  1485. prev->parentNode ()->insertBefore (n, prev);
  1486. }
  1487. m_view->playList()->updateTree (manip_tree_id, 0L, n, true, false);
  1488. }
  1489. KDE_NO_EXPORT void KMPlayerApp::menuMoveDownNode () {
  1490. KMPlayer::NodePtr n = manip_node;
  1491. if (n && n->parentNode () && n->nextSibling ()) {
  1492. KMPlayer::NodePtr next = n->nextSibling ();
  1493. n->parentNode ()->removeChild (n);
  1494. next->parentNode ()->insertBefore (n, next->nextSibling ());
  1495. }
  1496. m_view->playList()->updateTree (manip_tree_id, 0L, n, true, false);
  1497. }
  1498. KDE_NO_EXPORT void KMPlayerApp::playListItemMoved () {
  1499. KMPlayer::PlayListItem * si = m_view->playList ()->selectedPlayListItem ();
  1500. KMPlayer::RootPlayListItem * ri = m_view->playList ()->rootItem (si);
  1501. kdDebug() << "playListItemMoved " << (ri->id == playlist_id) << !! si->node << endl;
  1502. if (ri->id == playlist_id && si->node) {
  1503. KMPlayer::NodePtr p = si->node->parentNode ();
  1504. if (p) {
  1505. p->removeChild (si->node);
  1506. m_view->playList()->updateTree(playlist_id,playlist,0L,false,false);
  1507. }
  1508. }
  1509. }
  1510. KDE_NO_EXPORT void KMPlayerApp::preparePlaylistMenu (KMPlayer::PlayListItem * item, TQPopupMenu * pm) {
  1511. KMPlayer::RootPlayListItem * ri = m_view->playList ()->rootItem (item);
  1512. if (item->node &&
  1513. ri->flags & (KMPlayer::PlayListView::Moveable | KMPlayer::PlayListView::Deleteable)) {
  1514. manip_tree_id = ri->id;
  1515. pm->insertSeparator ();
  1516. manip_node = item->node;
  1517. if (ri->flags & KMPlayer::PlayListView::Deleteable)
  1518. pm->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("edit-delete"), TDEIcon::Small, 0, true), i18n ("&Delete item"), TQT_TQOBJECT(this), TQT_SLOT (menuDeleteNode ()));
  1519. if (ri->flags & KMPlayer::PlayListView::Moveable) {
  1520. if (manip_node->previousSibling ())
  1521. pm->insertItem (TDEGlobal::iconLoader ()->loadIconSet (TQString ("go-up"), TDEIcon::Small, 0, true), i18n ("&Move up"), TQT_TQOBJECT(this), TQT_SLOT (menuMoveUpNode ()));
  1522. if (manip_node->nextSibling ())
  1523. pm->insertItem (TDEGlobal::iconLoader()->loadIconSet (TQString ("go-down"), TDEIcon::Small, 0, true), i18n ("Move &down"), TQT_TQOBJECT(this), TQT_SLOT (menuMoveDownNode ()));
  1524. }
  1525. }
  1526. }
  1527. KDE_NO_EXPORT void KMPlayerApp::startArtsControl () {
  1528. TQCString fApp, fObj;
  1529. TQByteArray data, replydata;
  1530. QCStringList apps = kapp->dcopClient ()->registeredApplications();
  1531. QCStringList::ConstIterator end( apps.end() );
  1532. for( QCStringList::ConstIterator it = apps.begin(); it != end; ++it)
  1533. if (!strncmp ((*it).data (), "artscontrol", 11)) {
  1534. kapp->dcopClient ()->findObject
  1535. (*it, "artscontrol-mainwindow#1", "raise()", data, fApp, fObj);
  1536. return;
  1537. }
  1538. TQStringList args;
  1539. TQCString replytype;
  1540. TQDataStream stream (data, IO_WriteOnly);
  1541. stream << TQString ("aRts Control Tool") << args;
  1542. if (kapp->dcopClient ()->call ("tdelauncher", "tdelauncher", "start_service_by_name(TQString,TQStringList)", data, replytype, replydata)) {
  1543. int result;
  1544. TQDataStream replystream (replydata, IO_ReadOnly);
  1545. replystream >> result >> m_dcopName;
  1546. }
  1547. }
  1548. KDE_NO_EXPORT void KMPlayerApp::configChanged () {
  1549. viewKeepRatio->setChecked (m_player->settings ()->sizeratio);
  1550. if (m_player->settings ()->docksystray && !m_systray) {
  1551. m_systray = new KSystemTray (this);
  1552. m_systray->setPixmap (TDEGlobal::iconLoader ()->loadIcon (TQString ("kmplayer"), TDEIcon::NoGroup, 22));
  1553. m_systray->show ();
  1554. } else if (!m_player->settings ()->docksystray && m_systray) {
  1555. delete m_systray;
  1556. m_systray = 0L;
  1557. }
  1558. if (m_player->settings ()->autoresize && !m_auto_resize)
  1559. connect(m_player,TQT_SIGNAL(sourceDimensionChanged()),this,TQT_SLOT(zoom100()));
  1560. else if (!m_player->settings ()->autoresize && m_auto_resize)
  1561. disconnect(m_player, TQT_SIGNAL(sourceDimensionChanged()),this,TQT_SLOT(zoom100()));
  1562. m_auto_resize = m_player->settings ()->autoresize;
  1563. static_cast <KMPlayerTVSource *> (m_player->sources () ["tvsource"])->buildMenu ();
  1564. }
  1565. KDE_NO_EXPORT void KMPlayerApp::keepSizeRatio () {
  1566. m_view->setKeepSizeRatio (!m_view->keepSizeRatio ());
  1567. m_player->settings ()->sizeratio = m_view->keepSizeRatio ();
  1568. viewKeepRatio->setChecked (m_view->keepSizeRatio ());
  1569. }
  1570. //-----------------------------------------------------------------------------
  1571. KDE_NO_CDTOR_EXPORT KMPlayerMenuSource::KMPlayerMenuSource (const TQString & n, KMPlayerApp * a, TQPopupMenu * m, const char * src)
  1572. : KMPlayer::Source (n, a->player (), src), m_menu (m), m_app (a) {
  1573. }
  1574. KDE_NO_CDTOR_EXPORT KMPlayerMenuSource::~KMPlayerMenuSource () {
  1575. }
  1576. KDE_NO_EXPORT void KMPlayerMenuSource::menuItemClicked (TQPopupMenu * menu, int id) {
  1577. int unsetmenuid = -1;
  1578. for (unsigned i = 0; i < menu->count(); i++) {
  1579. int menuid = menu->idAt (i);
  1580. if (menu->isItemChecked (menuid)) {
  1581. menu->setItemChecked (menuid, false);
  1582. unsetmenuid = menuid;
  1583. break;
  1584. }
  1585. }
  1586. if (unsetmenuid != id)
  1587. menu->setItemChecked (id, true);
  1588. }
  1589. //-----------------------------------------------------------------------------
  1590. KDE_NO_CDTOR_EXPORT KMPlayerPrefSourcePageDVD::KMPlayerPrefSourcePageDVD (TQWidget * parent)
  1591. : TQFrame(parent) {
  1592. TQVBoxLayout *layout = new TQVBoxLayout (this, 5, 2);
  1593. autoPlayDVD = new TQCheckBox (i18n ("Auto play after opening DVD"), this, 0);
  1594. TQWhatsThis::add(autoPlayDVD, i18n ("Start playing DVD right after opening DVD"));
  1595. TQLabel *dvdDevicePathLabel = new TQLabel (i18n("DVD device:"), this, 0);
  1596. dvddevice = new KURLRequester ("/dev/dvd", this, 0);
  1597. TQWhatsThis::add(dvddevice, i18n ("Path to your DVD device, you must have read rights to this device"));
  1598. layout->addWidget (autoPlayDVD);
  1599. layout->addItem (new TQSpacerItem (0, 10, TQSizePolicy::Minimum, TQSizePolicy::Minimum));
  1600. layout->addWidget (dvdDevicePathLabel);
  1601. layout->addWidget (dvddevice);
  1602. layout->addItem (new TQSpacerItem (0, 0, TQSizePolicy::Minimum, TQSizePolicy::Expanding));
  1603. }
  1604. //-----------------------------------------------------------------------------
  1605. class KMPLAYER_NO_EXPORT Disks : public KMPlayer::Document {
  1606. public:
  1607. Disks (KMPlayerApp * a);
  1608. void childDone (KMPlayer::NodePtr);
  1609. KMPlayerApp * app;
  1610. };
  1611. class KMPLAYER_NO_EXPORT Disk : public KMPlayer::Mrl {
  1612. public:
  1613. Disk (KMPlayer::NodePtr & doc, KMPlayerApp *a, const TQString &url, const TQString &pn);
  1614. void activate ();
  1615. KMPlayerApp * app;
  1616. };
  1617. KDE_NO_CDTOR_EXPORT Disks::Disks (KMPlayerApp * a)
  1618. : KMPlayer::Document ("disks://", 0L), app (a) {
  1619. id = id_node_disk_document;
  1620. pretty_name = i18n ("Optical Disks");
  1621. }
  1622. KDE_NO_EXPORT void Disks::childDone (KMPlayer::NodePtr) {
  1623. finish ();
  1624. }
  1625. KDE_NO_CDTOR_EXPORT Disk::Disk (KMPlayer::NodePtr & doc, KMPlayerApp * a, const TQString &url, const TQString &pn)
  1626. : KMPlayer::Mrl (doc, id_node_disk_node), app (a) {
  1627. src = url;
  1628. pretty_name = pn;
  1629. }
  1630. KDE_NO_EXPORT void Disk::activate () {
  1631. const char * sn;
  1632. if (src.startsWith ("cdda"))
  1633. sn = "audiocdsource";
  1634. else if (src.startsWith ("vcd"))
  1635. sn = "vcdsource";
  1636. else
  1637. sn = "dvdsource";
  1638. app->player ()->setSource (app->player ()->sources () [sn]);
  1639. }
  1640. //-----------------------------------------------------------------------------
  1641. KDE_NO_CDTOR_EXPORT KMPlayerDVDSource::KMPlayerDVDSource (KMPlayerApp * a, TQPopupMenu * m)
  1642. : KMPlayerMenuSource (i18n ("DVD"), a, m, "dvdsource"), m_configpage (0L) {
  1643. m_menu->insertTearOffHandle ();
  1644. m_dvdtitlemenu = new TQPopupMenu (m_app);
  1645. m_dvdsubtitlemenu = new TQPopupMenu (m_app);
  1646. m_dvdchaptermenu = new TQPopupMenu (m_app);
  1647. m_dvdlanguagemenu = new TQPopupMenu (m_app);
  1648. m_dvdtitlemenu->setCheckable (true);
  1649. m_dvdsubtitlemenu->setCheckable (true);
  1650. m_dvdchaptermenu->setCheckable (true);
  1651. m_dvdlanguagemenu->setCheckable (true);
  1652. setURL (KURL ("dvd://"));
  1653. m_player->settings ()->addPage (this);
  1654. disks = new Disks (a);
  1655. disks->appendChild (new Disk (disks, a, "cdda://", i18n ("CDROM - Audio Compact Disk")));
  1656. disks->appendChild (new Disk (disks, a, "vcd://", i18n ("VCD - Video Compact Disk")));
  1657. disks->appendChild (new Disk (disks, a, "dvd://", i18n ("DVD - Digital Video Disk")));
  1658. m_app->view()->playList()->addTree (disks, "listssource", "media-optical-cdrom-mounted", 0);
  1659. }
  1660. KDE_NO_CDTOR_EXPORT KMPlayerDVDSource::~KMPlayerDVDSource () {
  1661. disks->document ()->dispose ();
  1662. }
  1663. KDE_NO_EXPORT bool KMPlayerDVDSource::processOutput (const TQString & str) {
  1664. if (KMPlayer::Source::processOutput (str))
  1665. return true;
  1666. if (m_identified)
  1667. return false;
  1668. //kdDebug () << "scanning " << cstr << endl;
  1669. TQRegExp * patterns = static_cast <KMPlayer::MPlayer *> (m_player->players () ["mplayer"])->configPage ()->m_patterns;
  1670. TQRegExp & langRegExp = patterns[KMPlayer::MPlayerPreferencesPage::pat_dvdlang];
  1671. TQRegExp & subtitleRegExp = patterns[KMPlayer::MPlayerPreferencesPage::pat_dvdsub];
  1672. TQRegExp & titleRegExp = patterns[KMPlayer::MPlayerPreferencesPage::pat_dvdtitle];
  1673. TQRegExp & chapterRegExp = patterns[KMPlayer::MPlayerPreferencesPage::pat_dvdchapter];
  1674. bool post090 = m_player->settings ()->mplayerpost090;
  1675. if (!post090 && subtitleRegExp.search (str) > -1) {
  1676. bool ok;
  1677. int sub_id = subtitleRegExp.cap (1).toInt (&ok);
  1678. TQString sub_title = ok ? subtitleRegExp.cap (2) : subtitleRegExp.cap(1);
  1679. if (!ok)
  1680. sub_id = subtitleRegExp.cap (2).toInt (&ok);
  1681. m_dvdsubtitlemenu->insertItem (sub_title, sub_id);
  1682. kdDebug () << "subtitle sid:" << sub_id << " lang:" << sub_title <<endl;
  1683. } else if (!post090 && langRegExp.search (str) > -1) {
  1684. bool ok;
  1685. int lang_id = langRegExp.cap (1).toInt (&ok);
  1686. TQString lang_title = ok ? langRegExp.cap (2) : langRegExp.cap (1);
  1687. if (!ok)
  1688. lang_id = langRegExp.cap (2).toInt (&ok);
  1689. m_dvdlanguagemenu->insertItem (lang_title, lang_id);
  1690. kdDebug () << "lang aid:" << lang_id << " lang:" << lang_title << endl;
  1691. } else if (titleRegExp.search (str) > -1) {
  1692. kdDebug () << "title " << titleRegExp.cap (1) << endl;
  1693. unsigned ts = titleRegExp.cap (1).toInt ();
  1694. if ( ts > 100) ts = 100;
  1695. for (unsigned t = 1; t <= ts; t++)
  1696. m_dvdtitlemenu->insertItem (TQString::number (t), t);
  1697. } else if (chapterRegExp.search (str) > -1) {
  1698. kdDebug () << "chapter " << chapterRegExp.cap (1) << endl;
  1699. unsigned chs = chapterRegExp.cap (1).toInt ();
  1700. if ( chs > 100) chs = 100;
  1701. for (unsigned c = 1; c <= chs; c++)
  1702. m_dvdchaptermenu->insertItem (TQString::number (c), c);
  1703. } else
  1704. return false;
  1705. return true;
  1706. }
  1707. KDE_NO_EXPORT void KMPlayerDVDSource::activate () {
  1708. m_start_play = m_auto_play;
  1709. m_current_title = -1;
  1710. setURL (KURL ("dvd://"));
  1711. buildArguments ();
  1712. m_menu->insertItem (i18n ("&Titles"), m_dvdtitlemenu);
  1713. m_menu->insertItem (i18n ("&Chapters"), m_dvdchaptermenu);
  1714. if (!m_player->settings ()->mplayerpost090) {
  1715. m_menu->insertItem (i18n ("Audio &Language"), m_dvdlanguagemenu);
  1716. m_menu->insertItem (i18n ("&SubTitles"), m_dvdsubtitlemenu);
  1717. connect (m_dvdsubtitlemenu, TQT_SIGNAL (activated (int)),
  1718. TQT_TQOBJECT(this), TQT_SLOT (subtitleMenuClicked (int)));
  1719. connect (m_dvdlanguagemenu, TQT_SIGNAL (activated (int)),
  1720. TQT_TQOBJECT(this), TQT_SLOT (languageMenuClicked (int)));
  1721. }
  1722. connect (m_dvdtitlemenu, TQT_SIGNAL (activated (int)),
  1723. TQT_TQOBJECT(this), TQT_SLOT (titleMenuClicked (int)));
  1724. connect (m_dvdchaptermenu, TQT_SIGNAL (activated (int)),
  1725. TQT_TQOBJECT(this), TQT_SLOT (chapterMenuClicked (int)));
  1726. if (m_start_play)
  1727. TQTimer::singleShot (0, m_player, TQT_SLOT (play ()));
  1728. }
  1729. KDE_NO_EXPORT void KMPlayerDVDSource::setIdentified (bool b) {
  1730. KMPlayer::Source::setIdentified (b);
  1731. m_start_play = true;
  1732. if (m_current_title < 0 || m_current_title >= int (m_dvdtitlemenu->count()))
  1733. m_current_title = 0;
  1734. if (m_dvdtitlemenu->count ())
  1735. m_dvdtitlemenu->setItemChecked (m_current_title, true);
  1736. else
  1737. m_current_title = -1; // hmmm
  1738. if (m_dvdchaptermenu->count ()) m_dvdchaptermenu->setItemChecked (0, true);
  1739. // TODO remember lang/subtitles settings
  1740. if (m_dvdlanguagemenu->count())
  1741. m_dvdlanguagemenu->setItemChecked (m_dvdlanguagemenu->idAt (0), true);
  1742. buildArguments ();
  1743. m_app->slotStatusMsg (i18n ("Ready."));
  1744. }
  1745. KDE_NO_EXPORT void KMPlayerDVDSource::deactivate () {
  1746. if (m_player->view ()) {
  1747. m_dvdtitlemenu->clear ();
  1748. m_dvdsubtitlemenu->clear ();
  1749. m_dvdchaptermenu->clear ();
  1750. m_dvdlanguagemenu->clear ();
  1751. m_menu->removeItemAt (m_menu->count () - 1);
  1752. m_menu->removeItemAt (m_menu->count () - 1);
  1753. if (!m_player->settings ()->mplayerpost090) {
  1754. m_menu->removeItemAt (m_menu->count () - 1);
  1755. m_menu->removeItemAt (m_menu->count () - 1);
  1756. disconnect (m_dvdsubtitlemenu, TQT_SIGNAL (activated (int)),
  1757. TQT_TQOBJECT(this), TQT_SLOT (subtitleMenuClicked (int)));
  1758. disconnect (m_dvdlanguagemenu, TQT_SIGNAL (activated (int)),
  1759. TQT_TQOBJECT(this), TQT_SLOT (languageMenuClicked (int)));
  1760. }
  1761. disconnect (m_dvdtitlemenu, TQT_SIGNAL (activated (int)),
  1762. TQT_TQOBJECT(this), TQT_SLOT (titleMenuClicked (int)));
  1763. disconnect (m_dvdchaptermenu, TQT_SIGNAL (activated (int)),
  1764. TQT_TQOBJECT(this), TQT_SLOT (chapterMenuClicked (int)));
  1765. }
  1766. }
  1767. KDE_NO_EXPORT void KMPlayerDVDSource::buildArguments () {
  1768. TQString url ("dvd://");
  1769. if (m_document) {
  1770. if (m_current_title > 0)
  1771. url += TQString::number (m_current_title);
  1772. m_document->mrl ()->src = url;
  1773. } else
  1774. setURL (KURL (url));
  1775. m_options = TQString (m_identified ? "" : "-v ");
  1776. if (m_identified) {
  1777. for (unsigned i = 0; i < m_dvdsubtitlemenu->count (); i++)
  1778. if (m_dvdsubtitlemenu->isItemChecked (m_dvdsubtitlemenu->idAt (i)))
  1779. m_options += "-sid " + TQString::number (m_dvdsubtitlemenu->idAt(i));
  1780. for (unsigned i = 0; i < m_dvdchaptermenu->count (); i++)
  1781. if (m_dvdchaptermenu->isItemChecked (i))
  1782. m_options += TQString (" -chapter %1").arg (i);
  1783. for (unsigned i = 0; i < m_dvdlanguagemenu->count (); i++)
  1784. if (m_dvdlanguagemenu->isItemChecked (m_dvdlanguagemenu->idAt (i)))
  1785. m_options += " -aid " + TQString::number(m_dvdlanguagemenu->idAt(i));
  1786. if (m_player->settings ()->dvddevice.length () > 0)
  1787. m_options += TQString(" -dvd-device ") + m_player->settings()->dvddevice;
  1788. }
  1789. m_recordcmd = m_options + TQString (" -vf scale -zoom");
  1790. }
  1791. KDE_NO_EXPORT TQString KMPlayerDVDSource::filterOptions () {
  1792. KMPlayer::Settings * settings = m_player->settings ();
  1793. if (!settings->disableppauto)
  1794. return KMPlayer::Source::filterOptions ();
  1795. return TQString ("");
  1796. }
  1797. KDE_NO_EXPORT void KMPlayerDVDSource::titleMenuClicked (int id) {
  1798. if (m_current_title != id) {
  1799. m_player->stop ();
  1800. m_current_title = id;
  1801. m_identified = false;
  1802. buildArguments ();
  1803. m_dvdtitlemenu->clear ();
  1804. m_dvdsubtitlemenu->clear ();
  1805. m_dvdchaptermenu->clear ();
  1806. m_dvdlanguagemenu->clear ();
  1807. if (m_start_play)
  1808. TQTimer::singleShot (0, m_player, TQT_SLOT (play ()));
  1809. }
  1810. }
  1811. KDE_NO_EXPORT void KMPlayerDVDSource::play () {
  1812. buildArguments ();
  1813. if (m_start_play) {
  1814. m_player->stop ();
  1815. TQTimer::singleShot (0, m_player, TQT_SLOT (play ()));
  1816. }
  1817. }
  1818. KDE_NO_EXPORT void KMPlayerDVDSource::subtitleMenuClicked (int id) {
  1819. menuItemClicked (m_dvdsubtitlemenu, id);
  1820. play ();
  1821. }
  1822. KDE_NO_EXPORT void KMPlayerDVDSource::languageMenuClicked (int id) {
  1823. menuItemClicked (m_dvdlanguagemenu, id);
  1824. play ();
  1825. }
  1826. KDE_NO_EXPORT void KMPlayerDVDSource::chapterMenuClicked (int id) {
  1827. menuItemClicked (m_dvdchaptermenu, id);
  1828. play ();
  1829. }
  1830. KDE_NO_EXPORT TQString KMPlayerDVDSource::prettyName () {
  1831. return i18n ("DVD");
  1832. }
  1833. static const char * strPlayDVD = "Immediately Play DVD";
  1834. KDE_NO_EXPORT void KMPlayerDVDSource::write (TDEConfig * config) {
  1835. config->setGroup (strMPlayerGroup);
  1836. config->writeEntry (strPlayDVD, m_auto_play);
  1837. }
  1838. KDE_NO_EXPORT void KMPlayerDVDSource::read (TDEConfig * config) {
  1839. config->setGroup (strMPlayerGroup);
  1840. m_auto_play = config->readBoolEntry (strPlayDVD, true);
  1841. }
  1842. KDE_NO_EXPORT void KMPlayerDVDSource::sync (bool fromUI) {
  1843. if (fromUI) {
  1844. m_auto_play = m_configpage->autoPlayDVD->isChecked ();
  1845. m_player->settings ()->dvddevice = m_configpage->dvddevice->lineEdit()->text ();
  1846. } else {
  1847. m_configpage->autoPlayDVD->setChecked (m_auto_play);
  1848. m_configpage->dvddevice->lineEdit()->setText (m_player->settings ()->dvddevice);
  1849. }
  1850. }
  1851. KDE_NO_EXPORT void KMPlayerDVDSource::prefLocation (TQString & item, TQString & icon, TQString & tab) {
  1852. item = i18n ("Source");
  1853. icon = TQString ("text-x-src");
  1854. tab = i18n ("DVD");
  1855. }
  1856. KDE_NO_EXPORT TQFrame * KMPlayerDVDSource::prefPage (TQWidget * parent) {
  1857. m_configpage = new KMPlayerPrefSourcePageDVD (parent);
  1858. return m_configpage;
  1859. }
  1860. //-----------------------------------------------------------------------------
  1861. KDE_NO_CDTOR_EXPORT KMPlayerDVDNavSource::KMPlayerDVDNavSource (KMPlayerApp * app, TQPopupMenu * m)
  1862. : KMPlayerMenuSource (i18n ("DVDNav"), app, m, "dvdnavsource") {
  1863. m_menu->insertTearOffHandle (-1, 0);
  1864. setURL (KURL ("dvd://"));
  1865. }
  1866. KDE_NO_CDTOR_EXPORT KMPlayerDVDNavSource::~KMPlayerDVDNavSource () {}
  1867. KDE_NO_EXPORT void KMPlayerDVDNavSource::activate () {
  1868. setURL (KURL ("dvd://"));
  1869. play ();
  1870. }
  1871. KDE_NO_EXPORT void KMPlayerDVDNavSource::deactivate () {
  1872. }
  1873. KDE_NO_EXPORT void KMPlayerDVDNavSource::play () {
  1874. if (!m_menu->findItem (DVDNav_previous)) {
  1875. m_menu->insertItem (i18n ("&Previous"), TQT_TQOBJECT(this), TQT_SLOT (navMenuClicked (int)), 0, DVDNav_previous);
  1876. m_menu->insertItem (i18n ("&Next"), TQT_TQOBJECT(this), TQT_SLOT (navMenuClicked (int)), 0, DVDNav_next);
  1877. m_menu->insertItem (i18n ("&Root"), TQT_TQOBJECT(this), TQT_SLOT (navMenuClicked (int)), 0, DVDNav_root);
  1878. m_menu->insertItem (i18n ("&Up"), TQT_TQOBJECT(this), TQT_SLOT (navMenuClicked (int)), 0, DVDNav_up);
  1879. }
  1880. TQTimer::singleShot (0, m_player, TQT_SLOT (play ()));
  1881. connect (TQT_TQOBJECT(this), TQT_SIGNAL (stopPlaying ()), TQT_TQOBJECT(this), TQT_SLOT(finished ()));
  1882. }
  1883. KDE_NO_EXPORT void KMPlayerDVDNavSource::finished () {
  1884. disconnect (TQT_TQOBJECT(this), TQT_SIGNAL (stopPlaying ()), TQT_TQOBJECT(this), TQT_SLOT(finished ()));
  1885. m_menu->removeItem (DVDNav_previous);
  1886. m_menu->removeItem (DVDNav_next);
  1887. m_menu->removeItem (DVDNav_root);
  1888. m_menu->removeItem (DVDNav_up);
  1889. }
  1890. KDE_NO_EXPORT void KMPlayerDVDNavSource::navMenuClicked (int id) {
  1891. switch (id) {
  1892. case DVDNav_start:
  1893. break;
  1894. case DVDNav_previous:
  1895. m_app->view ()->viewer ()->sendKeyEvent ('p');
  1896. break;
  1897. case DVDNav_next:
  1898. m_app->view ()->viewer ()->sendKeyEvent ('n');
  1899. break;
  1900. case DVDNav_root:
  1901. m_app->view ()->viewer ()->sendKeyEvent ('r');
  1902. break;
  1903. case DVDNav_up:
  1904. m_app->view ()->viewer ()->sendKeyEvent ('u');
  1905. break;
  1906. }
  1907. }
  1908. KDE_NO_EXPORT TQString KMPlayerDVDNavSource::prettyName () {
  1909. return i18n ("DVD");
  1910. }
  1911. //-----------------------------------------------------------------------------
  1912. KDE_NO_CDTOR_EXPORT KMPlayerPrefSourcePageVCD::KMPlayerPrefSourcePageVCD (TQWidget * parent)
  1913. : TQFrame (parent) {
  1914. TQVBoxLayout *layout = new TQVBoxLayout (this, 5, 2);
  1915. autoPlayVCD = new TQCheckBox (i18n ("Auto play after opening a VCD"), this, 0);
  1916. TQWhatsThis::add(autoPlayVCD, i18n ("Start playing VCD right after opening VCD"));
  1917. TQLabel *vcdDevicePathLabel = new TQLabel (i18n ("VCD (CDROM) device:"), this, 0);
  1918. vcddevice= new KURLRequester ("/dev/cdrom", this, 0);
  1919. TQWhatsThis::add(vcddevice, i18n ("Path to your CDROM/DVD device, you must have read rights to this device"));
  1920. layout->addWidget (autoPlayVCD);
  1921. layout->addItem (new TQSpacerItem (0, 10, TQSizePolicy::Minimum, TQSizePolicy::Minimum));
  1922. layout->addWidget (vcdDevicePathLabel);
  1923. layout->addWidget (vcddevice);
  1924. layout->addItem (new TQSpacerItem (0, 0, TQSizePolicy::Minimum, TQSizePolicy::Expanding));
  1925. }
  1926. //-----------------------------------------------------------------------------
  1927. KDE_NO_CDTOR_EXPORT KMPlayerVCDSource::KMPlayerVCDSource (KMPlayerApp * a, TQPopupMenu * m)
  1928. : KMPlayerMenuSource (i18n ("VCD"), a, m, "vcdsource"), m_configpage (0L) {
  1929. m_player->settings ()->addPage (this);
  1930. setURL (KURL ("vcd://"));
  1931. }
  1932. KDE_NO_CDTOR_EXPORT KMPlayerVCDSource::~KMPlayerVCDSource () {
  1933. }
  1934. KDE_NO_EXPORT bool KMPlayerVCDSource::processOutput (const TQString & str) {
  1935. if (KMPlayer::Source::processOutput (str))
  1936. return true;
  1937. if (m_identified)
  1938. return false;
  1939. //kdDebug () << "scanning " << cstr << endl;
  1940. TQRegExp * patterns = static_cast<KMPlayer::MPlayer *> (m_player->players () ["mplayer"])->configPage ()->m_patterns;
  1941. TQRegExp & trackRegExp = patterns [KMPlayer::MPlayerPreferencesPage::pat_vcdtrack];
  1942. if (trackRegExp.search (str) > -1) {
  1943. m_document->state = KMPlayer::Element::state_deferred;
  1944. m_document->appendChild (new KMPlayer::GenericMrl (m_document, TQString ("vcd://") + trackRegExp.cap (1), i18n ("Track ") + trackRegExp.cap (1)));
  1945. kdDebug () << "track " << trackRegExp.cap (1) << endl;
  1946. return true;
  1947. }
  1948. return false;
  1949. }
  1950. KDE_NO_EXPORT void KMPlayerVCDSource::activate () {
  1951. m_player->stop ();
  1952. init ();
  1953. m_start_play = m_auto_play;
  1954. setURL (KURL ("vcd://"));
  1955. buildArguments ();
  1956. if (m_start_play)
  1957. TQTimer::singleShot (0, m_player, TQT_SLOT (play ()));
  1958. }
  1959. KDE_NO_EXPORT void KMPlayerVCDSource::deactivate () {
  1960. }
  1961. KDE_NO_EXPORT void KMPlayerVCDSource::setIdentified (bool b) {
  1962. KMPlayer::Source::setIdentified (b);
  1963. if (!m_current || !m_document->hasChildNodes ())
  1964. m_current = m_document;
  1965. m_player->updateTree ();
  1966. buildArguments ();
  1967. if (m_current->state == KMPlayer::Element::state_deferred)
  1968. m_current->undefer ();
  1969. m_app->slotStatusMsg (i18n ("Ready."));
  1970. }
  1971. KDE_NO_EXPORT void KMPlayerVCDSource::buildArguments () {
  1972. TQString url ("vcd://");
  1973. if (m_current && m_current != m_document)
  1974. url += m_current->mrl ()->src;
  1975. m_options.truncate (0);
  1976. if (m_player->settings ()->vcddevice.length () > 0)
  1977. m_options+=TQString(" -cdrom-device ") + m_player->settings()->vcddevice;
  1978. m_recordcmd = m_options;
  1979. }
  1980. KDE_NO_EXPORT TQString KMPlayerVCDSource::prettyName () {
  1981. return i18n ("VCD");
  1982. }
  1983. static const char * strPlayVCD = "Immediately Play VCD";
  1984. KDE_NO_EXPORT void KMPlayerVCDSource::write (TDEConfig * config) {
  1985. config->setGroup (strMPlayerGroup);
  1986. config->writeEntry (strPlayVCD, m_auto_play);
  1987. }
  1988. KDE_NO_EXPORT void KMPlayerVCDSource::read (TDEConfig * config) {
  1989. config->setGroup (strMPlayerGroup);
  1990. m_auto_play = config->readBoolEntry (strPlayVCD, true);
  1991. }
  1992. KDE_NO_EXPORT void KMPlayerVCDSource::sync (bool fromUI) {
  1993. if (fromUI) {
  1994. m_auto_play = m_configpage->autoPlayVCD->isChecked ();
  1995. m_player->settings ()->vcddevice = m_configpage->vcddevice->lineEdit()->text ();
  1996. } else {
  1997. m_configpage->autoPlayVCD->setChecked (m_auto_play);
  1998. m_configpage->vcddevice->lineEdit()->setText (m_player->settings ()->vcddevice);
  1999. }
  2000. }
  2001. KDE_NO_EXPORT void KMPlayerVCDSource::prefLocation (TQString & item, TQString & icon, TQString & tab) {
  2002. item = i18n ("Source");
  2003. icon = TQString ("text-x-src");
  2004. tab = i18n ("VCD");
  2005. }
  2006. KDE_NO_EXPORT TQFrame * KMPlayerVCDSource::prefPage (TQWidget * parent) {
  2007. m_configpage = new KMPlayerPrefSourcePageVCD (parent);
  2008. return m_configpage;
  2009. }
  2010. //-----------------------------------------------------------------------------
  2011. KDE_NO_CDTOR_EXPORT KMPlayerAudioCDSource::KMPlayerAudioCDSource (KMPlayerApp * a, TQPopupMenu * m)
  2012. : KMPlayerMenuSource (i18n ("Audio CD"), a, m, "audiocdsource") {
  2013. setURL (KURL ("cdda://"));
  2014. }
  2015. KDE_NO_CDTOR_EXPORT KMPlayerAudioCDSource::~KMPlayerAudioCDSource () {
  2016. }
  2017. KDE_NO_EXPORT bool KMPlayerAudioCDSource::processOutput (const TQString & str) {
  2018. if (KMPlayer::Source::processOutput (str))
  2019. return true;
  2020. if (m_identified)
  2021. return false;
  2022. //kdDebug () << "scanning " << str << endl;
  2023. TQRegExp * patterns = static_cast<KMPlayer::MPlayer *> (m_player->players () ["mplayer"])->configPage ()->m_patterns;
  2024. TQRegExp & trackRegExp = patterns [KMPlayer::MPlayerPreferencesPage::pat_cdromtracks];
  2025. if (trackRegExp.search (str) > -1) {
  2026. //if (m_document->state != KMPlayer::Element::state_deferred)
  2027. // m_document->defer ();
  2028. int nt = trackRegExp.cap (1).toInt ();
  2029. kdDebug () << "tracks " << trackRegExp.cap (1) << endl;
  2030. for (int i = 0; i < nt; i++)
  2031. m_document->appendChild (new KMPlayer::GenericMrl (m_document, TQString ("cdda://%1").arg (i+1), i18n ("Track %1").arg (i+1)));
  2032. return true;
  2033. }
  2034. return false;
  2035. }
  2036. KDE_NO_EXPORT void KMPlayerAudioCDSource::activate () {
  2037. m_player->stop ();
  2038. init ();
  2039. //m_start_play = m_auto_play;
  2040. setURL (KURL ("cdda://"));
  2041. buildArguments ();
  2042. //if (m_start_play)
  2043. TQTimer::singleShot (0, m_player, TQT_SLOT (play ()));
  2044. }
  2045. KDE_NO_EXPORT void KMPlayerAudioCDSource::deactivate () {
  2046. }
  2047. KDE_NO_EXPORT void KMPlayerAudioCDSource::setIdentified (bool b) {
  2048. KMPlayer::Source::setIdentified (b);
  2049. if (!m_current || !m_document->hasChildNodes ())
  2050. m_current = m_document;
  2051. buildArguments ();
  2052. if (m_current == m_document && m_document->hasChildNodes ()) {
  2053. m_back_request = m_document->firstChild ();
  2054. m_player->process ()->stop ();
  2055. }
  2056. m_player->updateTree ();
  2057. //if (m_current->state == KMPlayer::Element::state_deferred)
  2058. // m_current->undefer ();
  2059. m_app->slotStatusMsg (i18n ("Ready."));
  2060. }
  2061. KDE_NO_EXPORT void KMPlayerAudioCDSource::buildArguments () {
  2062. TQString url ("cdda://");
  2063. if (m_current && m_current != m_document)
  2064. url += m_current->mrl ()->src;
  2065. m_options = "-cdda speed=3";
  2066. if (m_player->settings ()->vcddevice.length () > 0)
  2067. m_options+=TQString(" -cdrom-device ") + m_player->settings()->vcddevice;
  2068. m_recordcmd = m_options;
  2069. }
  2070. KDE_NO_EXPORT TQString KMPlayerAudioCDSource::prettyName () {
  2071. return i18n ("Audio CD");
  2072. }
  2073. //-----------------------------------------------------------------------------
  2074. KDE_NO_CDTOR_EXPORT KMPlayerPipeSource::KMPlayerPipeSource (KMPlayerApp * a)
  2075. : KMPlayer::Source (i18n ("Pipe"), a->player (), "pipesource"), m_app (a) {
  2076. }
  2077. KDE_NO_CDTOR_EXPORT KMPlayerPipeSource::~KMPlayerPipeSource () {
  2078. }
  2079. KDE_NO_EXPORT bool KMPlayerPipeSource::hasLength () {
  2080. return false;
  2081. }
  2082. KDE_NO_EXPORT bool KMPlayerPipeSource::isSeekable () {
  2083. return false;
  2084. }
  2085. KDE_NO_EXPORT void KMPlayerPipeSource::activate () {
  2086. // dangerous !! if (!m_url.protocol ().compare ("kmplayer"))
  2087. // m_pipecmd = KURL::decode_string (m_url.path ()).mid (1);
  2088. setURL (KURL ("stdin://"));
  2089. KMPlayer::GenericMrl * gen = new KMPlayer::GenericMrl (m_document, TQString ("stdin://"), m_pipecmd);
  2090. gen->bookmarkable = false;
  2091. m_document->appendChild (gen);
  2092. m_recordcmd = m_options = TQString ("-"); // or m_url?
  2093. m_identified = true;
  2094. reset ();
  2095. TQTimer::singleShot (0, m_player, TQT_SLOT (play ()));
  2096. m_app->slotStatusMsg (i18n ("Ready."));
  2097. }
  2098. KDE_NO_EXPORT void KMPlayerPipeSource::deactivate () {
  2099. }
  2100. KDE_NO_EXPORT TQString KMPlayerPipeSource::prettyName () {
  2101. return i18n ("Pipe - %1").arg (m_pipecmd);
  2102. }
  2103. KDE_NO_EXPORT void KMPlayerPipeSource::setCommand (const TQString & cmd) {
  2104. m_pipecmd = cmd;
  2105. if (m_document)
  2106. m_document->mrl ()->pretty_name = cmd;
  2107. }
  2108. #include "kmplayer.moc"
  2109. #include "kmplayerappsource.moc"