1
0

pledit.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*---------------------------------------------------
  2. -----------------------------------------------------
  3. Filename: pledit.m
  4. Version: 3.1
  5. Type: maki
  6. Date: 18. Sep. 2007 - 19:42
  7. Author: Martin Poehlmann aka Deimos
  8. E-Mail: [email protected]
  9. Internet: www.skinconsortium.com
  10. www.martin.deimos.de.vu
  11. -----------------------------------------------------
  12. ---------------------------------------------------*/
  13. #include "lib/std.mi"
  14. //#define DEBUG
  15. #define FILE_NAME "pledit.m"
  16. #include "lib/com/debug.m"
  17. #define PL_GUID "{45F3F7C1-A6F3-4EE6-A15E-125E92FC3F8D}"
  18. #define PLC_POPPLER_POS 200
  19. #include "attribs/init_playlist.m"
  20. Function fitContent (int playlistw, int playlistx);
  21. Function fit (group g, int x, int rx, int y, int ry, int w, int rw, int h, int rh);
  22. Function int updatePoppler(int w);
  23. Function int updateMainPoppler(int w);
  24. Global Frame dualwnd, pl_dualwnd, mainframe;
  25. Global Group g_playlist, g_player, g_sui, g_buttons, g_mcv, g_cover, g_upper, wdh_pl;
  26. Global Button p_enlarge, p_small;
  27. Global Button p_resize;
  28. Global int down_x, down_gx, isresizing;
  29. Global layout normal;
  30. Global Container player;
  31. //Global WindowHolder wdh_pl;
  32. Global Text pl_time;
  33. Global Button pe_add, pe_rem, pe_sel, pe_misc, pe_manage;
  34. Global Boolean startup, isBig, bypass_nocomp;
  35. Global Timer dc_openPl, dc_closePl, dc_loadWnd;
  36. Global Int COMP_Y, COMP_H, SUI_Y, SUI_H, BOTTOMSPACER, MAX_PL_H;
  37. Global Int DEF_PL_W, SIDESPACER;
  38. Global Int min_infowidth;
  39. System.onScriptLoaded ()
  40. {
  41. initAttribs_Playlist();
  42. normal = getScriptGroup();
  43. player = normal.getContainer();
  44. isBig = (getParam() == "big");
  45. if (isBig)
  46. {
  47. mainframe = normal.getObject("player.mainframe.big");
  48. }
  49. else
  50. {
  51. mainframe = normal.getObject("player.mainframe");
  52. }
  53. dualwnd = mainframe.findObject("player.dualwnd");
  54. g_mcv = dualwnd.findObject("player.component.fileinfo");
  55. g_upper = dualwnd.findObject("player.component.playlist.frame");
  56. pl_dualwnd = dualwnd.findObject("playlist.dualwnd");
  57. g_playlist = pl_dualwnd.findObject("player.component.playlist");
  58. g_cover = pl_dualwnd.findObject("player.component.playlist.albumart");
  59. g_player = dualwnd.findObject("player.layout");
  60. g_sui = normal.getObject("sui.content");
  61. g_buttons = g_playlist.getObject("player.component.playlist.buttons");
  62. p_enlarge = g_buttons.getObject("player.playlist.enlarge");
  63. p_small = g_buttons.getObject("player.playlist.small");
  64. p_resize = g_playlist.getObject("player.resize");
  65. wdh_pl = g_playlist.getObject("playlistpro");
  66. pl_time = g_buttons.getObject("PLTime");
  67. pe_add = g_buttons.getObject("player.playlist.add");
  68. pe_rem = g_buttons.getObject("player.playlist.rem");
  69. pe_sel = g_buttons.getObject("player.playlist.sel");
  70. pe_misc = g_buttons.getObject("player.playlist.misc");
  71. pe_manage = g_buttons.getObject("player.playlist.manage");
  72. min_infowidth = stringtoInteger(dualwnd.getXmlParam("maxwidth"));
  73. dc_openPl = new Timer;
  74. dc_openPl.setDelay(1);
  75. dc_closePl = new Timer;
  76. dc_closePl.setDelay(1);
  77. dc_loadWnd = new Timer;
  78. dc_loadWnd.setDelay(1);
  79. // Global Definitions:
  80. DEF_PL_W = g_playlist.getGuiW(); // (-)
  81. SIDESPACER = g_sui.getGuiX(); // (+)
  82. COMP_Y = mainframe.getGuiY(); // (+)
  83. COMP_H = mainframe.getGuiH(); // (+)
  84. SUI_Y = g_sui.getGuiY(); // (+)
  85. SUI_H = g_sui.getGuiH(); // (-)
  86. BOTTOMSPACER = SUI_Y + SUI_H; // (-)
  87. MAX_PL_H = BOTTOMSPACER - COMP_Y; // (-)
  88. startup = 1;
  89. // show playlist album art if checked
  90. playlist_cover_attrib.onDataChanged();
  91. //Bento v0.8 hack
  92. if (mainframe.getPosition() < stringToInteger(mainframe.getXmlParam("minwidth")))
  93. {
  94. mainframe.setPosition(stringToInteger(mainframe.getXmlParam("minwidth")));
  95. }
  96. }
  97. system.onScriptUnloading ()
  98. {
  99. int pos = pl_dualwnd.getPosition();
  100. if (pos > 0) setPrivateInt(getSkinName(), "playlist_cover_poppler", pos);
  101. delete dc_loadWnd;
  102. }
  103. dc_loadWnd.onTimer ()
  104. {
  105. stop();
  106. int pos = dualwnd.getPosition();
  107. if (pos > 0) updatePoppler(pos);
  108. playlist_enlarge_attrib.onDataChanged();
  109. if (dualwnd.getPosition() > 0
  110. #ifdef DOHIDEMCV
  111. || dualwnd.getXMlParam("from") == "left"
  112. #endif
  113. ) dc_openPL.start();
  114. else wdh_pl.hide(); //hideWa2Component(PL_GUID);
  115. }
  116. playlist_enlarge_attrib.onDataChanged ()
  117. {
  118. int pl_w = dualwnd.getPosition();
  119. #ifdef DOHIDEMCV
  120. if (dualwnd.getXmlParam("from") == "left")
  121. {
  122. pl_w = dualwnd.getWidth() - 8;
  123. }
  124. #endif
  125. int pl_x = 0 - ( pl_w + SIDESPACER ); // (-)
  126. if (getData() == "1")
  127. {
  128. int sui_w = pl_x - SIDESPACER; // (-)
  129. dualwnd.setXmlParam("relath", "1");
  130. dualwnd.setXmlParam("h", integerToString(0));
  131. mainframe.setXmlParam("relath", "1");
  132. mainframe.setXmlParam("h", integerToString(MAX_PL_H));
  133. g_sui.setXmlParam("w", integerToString(sui_w-8));
  134. int pos = getPrivateInt(getSkinName(), "playlist_cover_poppler", PLC_POPPLER_POS);
  135. if (playlist_cover_attrib.getData() == "1" && pos > 0 && getPrivateString(getSkinName(), "Component", "Media Library") != "Hidden")
  136. {
  137. g_cover.show();
  138. pl_dualwnd.setPosition (pos);
  139. }
  140. else
  141. {
  142. pl_dualwnd.setPosition (0);
  143. g_cover.hide();
  144. }
  145. p_enlarge.hide();
  146. p_small.show();
  147. }
  148. else
  149. {
  150. int sui_w = 0 - SIDESPACER - SIDESPACER; // (-)
  151. int pc_w = pl_x - SIDESPACER; // (-)
  152. g_cover.hide();
  153. if (playlist_cover_attrib.getData() == "1")
  154. {
  155. int pos = pl_dualwnd.getPosition();
  156. if (pos > 0) setPrivateInt(getSkinName(), "playlist_cover_poppler", pos);
  157. }
  158. pl_dualwnd.setPosition (0);
  159. dualwnd.setXmlParam("h", integerToString(COMP_H-3));
  160. dualwnd.setXmlParam("relath", "0");
  161. mainframe.setXmlParam("h", integerToString(COMP_H));
  162. mainframe.setXmlParam("relath", "0");
  163. g_sui.setXmlParam("w", integerToString(sui_w));
  164. p_enlarge.show();
  165. p_small.hide();
  166. }
  167. }
  168. g_playlist.onResize (int x, int y, int w, int h)
  169. {
  170. int pos = dualwnd.getPosition();
  171. debugString(integerToString(pos), 9);
  172. updateMainPoppler(min_infowidth - pos - 8);
  173. if (pos > 0
  174. #ifdef DOHIDEMCV
  175. || dualwnd.getXMlParam("from") == "left"
  176. #endif
  177. )
  178. {
  179. //setPrivateInt(getSkinName(), "pledit poppler width", dualwnd.getPosition());
  180. if (!wdh_pl.isVisible())
  181. {
  182. setPrivateString(getSkinName(), "Pledit_pos", "top");
  183. g_sui.sendAction("hide_comp", "pe", 0,0,0,0);
  184. dc_openPl.start();
  185. }
  186. if (isBig)
  187. {
  188. if (w > 189)
  189. {
  190. pe_add.show();
  191. pe_rem.show();
  192. pe_sel.show();
  193. pe_misc.show();
  194. pe_manage.show();
  195. }
  196. else if (w <= 189 && w >158)
  197. {
  198. pe_add.show();
  199. pe_rem.show();
  200. pe_sel.show();
  201. pe_misc.show();
  202. pe_manage.hide();
  203. }
  204. else if (w <= 158 && w >127)
  205. {
  206. pe_add.show();
  207. pe_rem.show();
  208. pe_sel.show();
  209. pe_misc.hide();
  210. pe_manage.hide();
  211. }
  212. else if (w <= 127 && w >96)
  213. {
  214. pe_add.show();
  215. pe_rem.show();
  216. pe_sel.hide();
  217. pe_misc.hide();
  218. pe_manage.hide();
  219. }
  220. else if (w <= 96 && w >65)
  221. {
  222. pe_add.show();
  223. pe_rem.hide();
  224. pe_sel.hide();
  225. pe_misc.hide();
  226. pe_manage.hide();
  227. }
  228. else
  229. {
  230. pe_add.hide();
  231. pe_rem.hide();
  232. pe_sel.hide();
  233. pe_misc.hide();
  234. pe_manage.hide();
  235. }
  236. }
  237. else
  238. {
  239. if (w > 146)
  240. {
  241. pe_add.show();
  242. pe_rem.show();
  243. pe_sel.show();
  244. pe_misc.show();
  245. pe_manage.show();
  246. }
  247. else if (w <= 146 && w >122)
  248. {
  249. pe_add.show();
  250. pe_rem.show();
  251. pe_sel.show();
  252. pe_misc.show();
  253. pe_manage.hide();
  254. }
  255. else if (w <= 122 && w >98)
  256. {
  257. pe_add.show();
  258. pe_rem.show();
  259. pe_sel.show();
  260. pe_misc.hide();
  261. pe_manage.hide();
  262. }
  263. else if (w <= 98 && w >74)
  264. {
  265. pe_add.show();
  266. pe_rem.show();
  267. pe_sel.hide();
  268. pe_misc.hide();
  269. pe_manage.hide();
  270. }
  271. else if (w <= 74 && w >50)
  272. {
  273. pe_add.show();
  274. pe_rem.hide();
  275. pe_sel.hide();
  276. pe_misc.hide();
  277. pe_manage.hide();
  278. }
  279. else
  280. {
  281. pe_add.hide();
  282. pe_rem.hide();
  283. pe_sel.hide();
  284. pe_misc.hide();
  285. pe_manage.hide();
  286. }
  287. }
  288. }
  289. else wdh_pl.hide();
  290. if (playlist_enlarge_attrib.getdata() == "1")
  291. {
  292. int sui_w = - g_playlist.getWidth() - (2 * SIDESPACER) - 8;
  293. g_sui.setXmlParam("w", integerToString(sui_w));
  294. if (startup)
  295. {
  296. startup = 0;
  297. mainframe.setXmlParam("relath", "1");
  298. mainframe.setXmlParam("h", integerToString(MAX_PL_H));
  299. dualwnd.setXmlParam("relath", "1");
  300. dualwnd.setXmlParam("h", integerToString(0));
  301. }
  302. }
  303. }
  304. normal.onSetVisible (Boolean onoff)
  305. {
  306. if (onoff)
  307. {
  308. playlist_enlarge_attrib.onDataChanged();
  309. int pos = dualwnd.getPosition();
  310. if (pos > 0
  311. #ifdef DOHIDEMCV
  312. || dualwnd.getXMlParam("from") == "left"
  313. #endif
  314. )
  315. {
  316. updatePoppler(pos);
  317. dc_openPL.start();
  318. }
  319. else wdh_pl.hide();//hideWa2Component(PL_GUID);
  320. }
  321. }
  322. normal.onUserResize (int x, int y, int w, int h)
  323. {
  324. int pos = dualwnd.getPosition();
  325. if (pos > 0) updatePoppler(pos);
  326. }
  327. /** Hide pl_time if it cannot be full displayed */
  328. pl_time.onResize (int x, int y, int w, int h)
  329. {
  330. if (w < getTextWidth())
  331. {
  332. hide();
  333. }
  334. else
  335. {
  336. show();
  337. }
  338. }
  339. pl_time.onTextChanged (String newtxt)
  340. {
  341. if (getWidth() < getTextWidth())
  342. {
  343. hide();
  344. }
  345. else
  346. {
  347. show();
  348. }
  349. }
  350. /** Playlist Component Handling */
  351. System.onGetCancelComponent (String guid, boolean goingvisible)
  352. {
  353. if (getPrivateString(getSkinName(), "Pledit_pos", "top") == "sui")
  354. {
  355. return;
  356. }
  357. debugString(DEBUG_PREFIX "System.onGetCancelComponent ( "+ guid + " , " + integerToString(goingvisible) + " )", D_WTF);
  358. if (guid == PL_GUID)
  359. {
  360. Boolean isShade = player.getCurLayout() != normal;
  361. if (goingvisible == TRUE && !isShade)
  362. {
  363. int poppler_w = getPrivateInt(getSkinName(), "pledit poppler width", 200);
  364. if (poppler_w < 1) poppler_w = 200;
  365. g_playlist.show();
  366. updatePoppler(poppler_w);
  367. dc_openPl.start();
  368. return FALSE;
  369. }
  370. else
  371. {
  372. if (dualwnd.getPosition() > 0) setPrivateInt(getSkinName(), "pledit poppler width", dualwnd.getPosition());
  373. wdh_pl.hide();
  374. dualwnd.setPosition(0);
  375. return FALSE;
  376. }
  377. }
  378. }
  379. normal.onAction (String action, String param, Int x, int y, int p1, int p2, GuiObject source)
  380. {
  381. if (action == "load_comp" && strlower(param) == "pledit")
  382. {
  383. int poppler_w = getPrivateInt(getSkinName(), "pledit poppler width", 200);
  384. if (dualwnd.getPosition() > 0) poppler_w = dualwnd.getPosition();
  385. if (dualwnd.getPosition() == 0) poppler_w = 200;
  386. updatePoppler(poppler_w);
  387. dc_openPl.start();
  388. }
  389. if (action == "hide_comp" && strlower(param) == "pledit")
  390. {
  391. setPrivateInt(getSkinName(), "pledit poppler width", dualwnd.getPosition());
  392. wdh_pl.hide();
  393. dualwnd.setPosition(0);
  394. }
  395. if (action == "pledit_posupdate")
  396. {
  397. int pos = dualwnd.getPosition();
  398. if (pos > 0) updatePoppler(pos);
  399. }
  400. if (action == "sui")
  401. {
  402. if (param == "tonocomp")
  403. {
  404. if (playlist_cover_attrib.getData() == "1")
  405. {
  406. int pos = pl_dualwnd.getPosition();
  407. if (pos > 0) setPrivateInt(getSkinName(), "playlist_cover_poppler", pos);
  408. }
  409. bypass_nocomp = TRUE; //we need to add a bypass otherwise playlist_cover_attrib will be turned OFF
  410. pl_dualwnd.setPosition (0);
  411. g_cover.hide();
  412. bypass_nocomp = FALSE;
  413. }
  414. else if (param == "fromnocomp")
  415. {
  416. playlist_cover_attrib.onDataChanged ();
  417. }
  418. }
  419. }
  420. dualwnd.onAction (String action, String param, Int x, int y, int p1, int p2, GuiObject source)
  421. {
  422. if (action == "set_maxwidth")
  423. {
  424. // update poppler for playlist/infocomp
  425. updatePoppler(dualwnd.getPosition());
  426. // update poppler bands for player/infocomp
  427. min_infowidth = x;
  428. updateMainPoppler(min_infowidth - dualwnd.getPosition() - 8);
  429. }
  430. }
  431. wdh_pl.onSetVisible (Boolean onoff)
  432. {
  433. debugString("wdh_pl set visible: " + integerToString(onoff), 9);
  434. if (onoff)
  435. {
  436. playlist_cover_attrib.onDataChanged();
  437. }
  438. else
  439. {
  440. int pos = pl_dualwnd.getPosition();
  441. if (pos > 0) setPrivateInt(getSkinName(), "playlist_cover_poppler", pos);
  442. }
  443. }
  444. updatePoppler(int w)
  445. {
  446. if (dualwnd.getPosition() == 0 && w == 0) return;
  447. int min_w = stringToInteger(dualwnd.getXmlParam("minwidth"));
  448. int max_w = stringToInteger(dualwnd.getXmlParam("maxwidth"));
  449. if (max_w < 0) max_w = dualwnd.getWidth() + max_w;
  450. debugString("max_w: " + integerToString(max_w), 9);
  451. boolean reset = FALSE;
  452. reset += (w == 0);
  453. reset += (w < min_w);
  454. if (reset) w = min_w;
  455. // Prevent the playlist from overlapping the player
  456. if (w > max_w)
  457. {
  458. w = max_w;
  459. // Resize the player to get more space
  460. if (max_w < min_w)
  461. {
  462. w = min_w;
  463. int mainframe_pos = mainframe.getPosition() - (min_w - max_w); // I need to save this in a variable first, otherwise mainframe.setPos will crash...
  464. mainframe.setPosition(mainframe_pos);
  465. }
  466. }
  467. debugString("set poppler: " + integerToString(w), 9);
  468. dualwnd.setPosition(w);
  469. }
  470. updateMainPoppler (int w)
  471. {
  472. mainframe.setXmlparam("maxwidth", integerToString(w));
  473. }
  474. dc_openPl.onTimer ()
  475. {
  476. dc_openPl.stop();
  477. debugString("dc_openPl called!", 9);
  478. wdh_pl.show();
  479. g_playlist.show();
  480. g_upper.show();
  481. //if (!wdh_pl.isVisible()) debugInt(g_playlist.getWidth());
  482. }
  483. dc_closePl.onTimer ()
  484. {
  485. dc_closePl.stop();
  486. wdh_pl.hide();
  487. }
  488. //----------------------------------------------------------------------------------------------------------------
  489. // Playlist Album Art Handles
  490. //----------------------------------------------------------------------------------------------------------------
  491. Global boolean attrib_bypass = false;
  492. playlist_cover_attrib.onDataChanged ()
  493. {
  494. if (attrib_bypass)
  495. return;
  496. if (playlist_enlarge_attrib.getData() == "0")
  497. return;
  498. if (getData() == "1")
  499. {
  500. int pos = getPrivateInt(getSkinName(), "playlist_cover_poppler", PLC_POPPLER_POS);
  501. if (pos > 0 && getPrivateString(getSkinName(), "Component", "Media Library") != "Hidden")
  502. {
  503. pl_dualwnd.setPosition (pos);
  504. g_cover.show();
  505. }
  506. else
  507. {
  508. pl_dualwnd.setPosition (0);
  509. g_cover.hide();
  510. }
  511. }
  512. else
  513. {
  514. int pos = pl_dualwnd.getPosition();
  515. if (pos > 0) setPrivateInt(getSkinName(), "playlist_cover_poppler", pos);
  516. pl_dualwnd.setPosition(0);
  517. g_cover.hide();
  518. }
  519. }
  520. Global Boolean bypass;
  521. player.onBeforeSwitchToLayout (Layout oldlayout, Layout newlayout)
  522. {
  523. if (oldlayout == normal)
  524. {
  525. bypass = 1;
  526. }
  527. }
  528. g_cover.onSetVisible (Boolean onoff)
  529. {
  530. if (bypass)
  531. {
  532. bypass = 0;
  533. return;
  534. }
  535. if (!onoff && !bypass_nocomp && playlist_cover_attrib.getdata() == "1" && getPrivateString(getSkinName(), "Component", "Media Library") != "Hidden" && playlist_enlarge_attrib.getData() == "1" && dualwnd.getPosition() > 0)
  536. {
  537. playlist_cover_attrib.setdata("0");
  538. }
  539. else if (onoff && !bypass_nocomp && playlist_cover_attrib.getdata() == "0" && dualwnd.getPosition() > 0)
  540. {
  541. attrib_bypass = true;
  542. playlist_cover_attrib.setdata("1");
  543. attrib_bypass = false;
  544. }
  545. }