Advertisement
SharkyEXE

Untitled

Apr 11th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.51 KB | None | 0 0
  1. #include <lib/service/listboxservice.h>
  2. #include <lib/service/service.h>
  3. #include <lib/base/estring.h>
  4. #include <lib/gdi/font.h>
  5. #include <lib/gdi/epng.h>
  6. #include <lib/dvb/epgcache.h>
  7. #include <lib/dvb/db.h>
  8. #include <lib/dvb/pmt.h>
  9. #include <lib/nav/core.h>
  10. #include <lib/python/connections.h>
  11. #include <lib/python/python.h>
  12. #include <ctype.h>
  13. #include <string>
  14. #include <regex>
  15.  
  16. ePyObject eListboxServiceContent::m_GetPiconNameFunc;
  17.  
  18. void eListboxServiceContent::addService(const eServiceReference &service, bool beforeCurrent)
  19. {
  20. if (beforeCurrent && m_size)
  21. m_list.insert(m_cursor, service);
  22. else
  23. m_list.push_back(service);
  24. if (m_size++)
  25. {
  26. ++m_cursor_number;
  27. if (m_listbox)
  28. m_listbox->entryAdded(cursorResolve(m_cursor_number-1));
  29. }
  30. else
  31. {
  32. m_cursor = m_list.begin();
  33. m_cursor_number=0;
  34. m_listbox->entryAdded(0);
  35. }
  36. }
  37.  
  38. void eListboxServiceContent::removeCurrent()
  39. {
  40. if (m_size && m_listbox)
  41. {
  42. if (m_cursor_number == --m_size)
  43. {
  44. m_list.erase(m_cursor--);
  45. if (m_size)
  46. {
  47. --m_cursor_number;
  48. m_listbox->entryRemoved(cursorResolve(m_cursor_number+1));
  49. }
  50. else
  51. m_listbox->entryRemoved(cursorResolve(m_cursor_number));
  52. }
  53. else
  54. {
  55. m_list.erase(m_cursor++);
  56. m_listbox->entryRemoved(cursorResolve(m_cursor_number));
  57. }
  58. }
  59. }
  60.  
  61. void eListboxServiceContent::FillFinished()
  62. {
  63. m_size = m_list.size();
  64. cursorHome();
  65.  
  66. if (m_listbox)
  67. m_listbox->entryReset();
  68. }
  69.  
  70. void eListboxServiceContent::setRoot(const eServiceReference &root, bool justSet)
  71. {
  72. m_list.clear();
  73. m_cursor = m_list.end();
  74. m_root = root;
  75.  
  76. if (justSet)
  77. {
  78. m_lst=0;
  79. return;
  80. }
  81. ASSERT(m_service_center);
  82.  
  83. if (m_service_center->list(m_root, m_lst))
  84. eDebug("[eListboxServiceContent] no list available!");
  85. else if (m_lst->getContent(m_list))
  86. eDebug("[eListboxServiceContent] getContent failed");
  87.  
  88. FillFinished();
  89. }
  90.  
  91. bool eListboxServiceContent::setCurrent(const eServiceReference &ref)
  92. {
  93. int index=0;
  94. for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
  95. {
  96. if ( *i == ref )
  97. {
  98. m_cursor = i;
  99. m_cursor_number = index;
  100. if (m_listbox)
  101. {
  102. m_listbox->moveSelectionTo(cursorResolve(index));
  103. return true;
  104. }
  105. break;
  106. }
  107. }
  108. return false;
  109. }
  110.  
  111. void eListboxServiceContent::getCurrent(eServiceReference &ref)
  112. {
  113. if (cursorValid())
  114. ref = *m_cursor;
  115. else
  116. ref = eServiceReference();
  117. }
  118.  
  119. void eListboxServiceContent::getPrev(eServiceReference &ref)
  120. {
  121. if (cursorValid())
  122. {
  123. list::iterator cursor(m_cursor);
  124. if (cursor == m_list.begin())
  125. {
  126. cursor = m_list.end();
  127. }
  128. ref = *(--cursor);
  129. }
  130. else
  131. ref = eServiceReference();
  132. }
  133.  
  134. void eListboxServiceContent::getNext(eServiceReference &ref)
  135. {
  136. if (cursorValid())
  137. {
  138. list::iterator cursor(m_cursor);
  139. cursor++;
  140. if (cursor == m_list.end())
  141. {
  142. cursor = m_list.begin();
  143. }
  144. ref = *(cursor);
  145. }
  146. else
  147. ref = eServiceReference();
  148. }
  149.  
  150. int eListboxServiceContent::getNextBeginningWithChar(char c)
  151. {
  152. // printf("Char: %c\n", c);
  153. int index=0;
  154. for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
  155. {
  156. std::string text;
  157. ePtr<iStaticServiceInformation> service_info;
  158. m_service_center->info(*i, service_info);
  159. service_info->getName(*i, text);
  160. // printf("%c\n", text.c_str()[0]);
  161. int idx=0;
  162. int len=text.length();
  163. while ( idx <= len )
  164. {
  165. char cc = text[idx++];
  166. if (isprint(cc))
  167. {
  168. if (cc == c)
  169. return index;
  170. break;
  171. }
  172. }
  173. }
  174. return 0;
  175. }
  176.  
  177. int eListboxServiceContent::getPrevMarkerPos()
  178. {
  179. if (!m_listbox)
  180. return 0;
  181. list::iterator i(m_cursor);
  182. int index = m_cursor_number;
  183. while (index) // Skip precending markers
  184. {
  185. --i;
  186. --index;
  187. if (! ((i->flags & eServiceReference::isMarker) && !(i->flags & eServiceReference::isInvisible)))
  188. break;
  189. }
  190. while (index)
  191. {
  192. --i;
  193. --index;
  194. if ((i->flags & eServiceReference::isMarker) && !(i->flags & eServiceReference::isInvisible))
  195. break;
  196. }
  197. return cursorResolve(index);
  198. }
  199.  
  200. int eListboxServiceContent::getNextMarkerPos()
  201. {
  202. if (!m_listbox)
  203. return 0;
  204. list::iterator i(m_cursor);
  205. int index = m_cursor_number;
  206. while (index < (m_size-1))
  207. {
  208. ++i;
  209. ++index;
  210. if ((i->flags & eServiceReference::isMarker) && !(i->flags & eServiceReference::isInvisible))
  211. break;
  212. }
  213. return cursorResolve(index);
  214. }
  215.  
  216. void eListboxServiceContent::initMarked()
  217. {
  218. m_marked.clear();
  219. }
  220.  
  221. void eListboxServiceContent::addMarked(const eServiceReference &ref)
  222. {
  223. m_marked.insert(ref);
  224. if (m_listbox)
  225. m_listbox->entryChanged(cursorResolve(lookupService(ref)));
  226. }
  227.  
  228. void eListboxServiceContent::removeMarked(const eServiceReference &ref)
  229. {
  230. m_marked.erase(ref);
  231. if (m_listbox)
  232. m_listbox->entryChanged(cursorResolve(lookupService(ref)));
  233. }
  234.  
  235. int eListboxServiceContent::isMarked(const eServiceReference &ref)
  236. {
  237. return m_marked.find(ref) != m_marked.end();
  238. }
  239.  
  240. void eListboxServiceContent::markedQueryStart()
  241. {
  242. m_marked_iterator = m_marked.begin();
  243. }
  244.  
  245. int eListboxServiceContent::markedQueryNext(eServiceReference &ref)
  246. {
  247. if (m_marked_iterator == m_marked.end())
  248. return -1;
  249. ref = *m_marked_iterator++;
  250. return 0;
  251. }
  252.  
  253. int eListboxServiceContent::lookupService(const eServiceReference &ref)
  254. {
  255. /* shortcut for cursor */
  256. if (ref == *m_cursor)
  257. return m_cursor_number;
  258. /* otherwise, search in the list.. */
  259. int index = 0;
  260. for (list::const_iterator i(m_list.begin()); i != m_list.end(); ++i, ++index);
  261.  
  262. /* this is ok even when the index was not found. */
  263. return index;
  264. }
  265.  
  266. void eListboxServiceContent::setVisualMode(int mode)
  267. {
  268. for (int i=0; i < celElements; ++i)
  269. {
  270. m_element_position[i] = eRect();
  271. m_element_font[i] = 0;
  272. }
  273.  
  274. m_visual_mode = mode;
  275.  
  276. if (m_visual_mode == visModeSimple)
  277. {
  278. m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize);
  279. m_element_font[celServiceName] = new gFont("Regular", 23);
  280. }
  281. }
  282.  
  283. void eListboxServiceContent::setElementPosition(int element, eRect where)
  284. {
  285. if ((element >= 0) && (element < celElements))
  286. m_element_position[element] = where;
  287. }
  288.  
  289. void eListboxServiceContent::setElementFont(int element, gFont *font)
  290. {
  291. if ((element >= 0) && (element < celElements))
  292. m_element_font[element] = font;
  293. }
  294.  
  295. void eListboxServiceContent::setPixmap(int type, ePtr<gPixmap> &pic)
  296. {
  297. if ((type >=0) && (type < picElements))
  298. m_pixmaps[type] = pic;
  299. }
  300.  
  301. void eListboxServiceContent::sort()
  302. {
  303. if (!m_lst)
  304. m_service_center->list(m_root, m_lst);
  305. if (m_lst)
  306. {
  307. m_list.sort(iListableServiceCompare(m_lst));
  308. /* FIXME: is this really required or can we somehow keep the current entry? */
  309. cursorHome();
  310. if (m_listbox)
  311. m_listbox->entryReset();
  312. }
  313. }
  314.  
  315. DEFINE_REF(eListboxServiceContent);
  316.  
  317. eListboxServiceContent::eListboxServiceContent()
  318. :m_visual_mode(visModeSimple),m_cursor_number(0), m_saved_cursor_number(0), m_size(0), m_current_marked(false),
  319. m_itemheight(25), m_hide_number_marker(false), m_service_picon_downsize(0), m_servicetype_icon_mode(0),
  320. m_crypto_icon_mode(0), m_record_indicator_mode(0), m_column_width(0), m_progressbar_height(6), m_progressbar_border_width(2),
  321. m_nonplayable_margins(10), m_items_distances(8)
  322. {
  323. memset(m_color_set, 0, sizeof(m_color_set));
  324. cursorHome();
  325. eServiceCenter::getInstance(m_service_center);
  326. }
  327.  
  328. void eListboxServiceContent::setColor(int color, gRGB &col)
  329. {
  330. if ((color >= 0) && (color < colorElements))
  331. {
  332. m_color_set[color] = true;
  333. m_color[color] = col;
  334. }
  335. }
  336.  
  337. void eListboxServiceContent::swapServices(list::iterator a, list::iterator b)
  338. {
  339. std::iter_swap(a, b);
  340. int temp = a->getChannelNum();
  341. a->setChannelNum(b->getChannelNum());
  342. b->setChannelNum(temp);
  343. }
  344.  
  345. void eListboxServiceContent::cursorHome()
  346. {
  347. if (m_current_marked && m_saved_cursor == m_list.end())
  348. {
  349. if (m_cursor_number >= m_size)
  350. {
  351. m_cursor_number = m_size-1;
  352. --m_cursor;
  353. }
  354. while (m_cursor_number)
  355. {
  356. swapServices(m_cursor--, m_cursor);
  357. --m_cursor_number;
  358. if (m_listbox && m_cursor_number)
  359. m_listbox->entryChanged(cursorResolve(m_cursor_number));
  360. }
  361. }
  362. else
  363. {
  364. m_cursor = m_list.begin();
  365. m_cursor_number = 0;
  366. while (m_cursor != m_list.end())
  367. {
  368. if (!((m_hide_number_marker && (m_cursor->flags & eServiceReference::isNumberedMarker)) || (m_cursor->flags & eServiceReference::isInvisible)))
  369. break;
  370. m_cursor++;
  371. m_cursor_number++;
  372. }
  373. }
  374. }
  375.  
  376. void eListboxServiceContent::cursorEnd()
  377. {
  378. if (m_current_marked && m_saved_cursor == m_list.end())
  379. {
  380. while (m_cursor != m_list.end())
  381. {
  382. list::iterator prev = m_cursor++;
  383. ++m_cursor_number;
  384. if ( prev != m_list.end() && m_cursor != m_list.end() )
  385. {
  386. swapServices(m_cursor, prev);
  387. if ( m_listbox )
  388. m_listbox->entryChanged(cursorResolve(m_cursor_number));
  389. }
  390. }
  391. }
  392. else
  393. {
  394. m_cursor = m_list.end();
  395. m_cursor_number = m_size;
  396. }
  397. }
  398.  
  399. int eListboxServiceContent::setCurrentMarked(bool state)
  400. {
  401. bool prev = m_current_marked;
  402. m_current_marked = state;
  403.  
  404. if (state != prev && m_listbox)
  405. {
  406. m_listbox->entryChanged(cursorResolve(m_cursor_number));
  407. if (!state)
  408. {
  409. if (!m_lst)
  410. m_service_center->list(m_root, m_lst);
  411. if (m_lst)
  412. {
  413. ePtr<iMutableServiceList> list;
  414. if (m_lst->startEdit(list))
  415. eDebug("[eListboxServiceContent] no editable list");
  416. else
  417. {
  418. eServiceReference ref;
  419. getCurrent(ref);
  420. if(!ref)
  421. eDebug("[eListboxServiceContent] no valid service selected");
  422. else
  423. {
  424. int pos = cursorGet();
  425. eDebugNoNewLineStart("[eListboxServiceContent] move %s to %d ", ref.toString().c_str(), pos);
  426. if (list->moveService(ref, cursorGet()))
  427. eDebugNoNewLine("failed\n");
  428. else
  429. eDebugNoNewLine("ok\n");
  430. }
  431. }
  432. }
  433. else
  434. eDebug("[eListboxServiceContent] no list available!");
  435. }
  436. }
  437.  
  438. return 0;
  439. }
  440.  
  441. int eListboxServiceContent::cursorMove(int count)
  442. {
  443. int prev = m_cursor_number, last = m_cursor_number + count;
  444. if (count > 0)
  445. {
  446. while(count && m_cursor != m_list.end())
  447. {
  448. list::iterator prev_it = m_cursor++;
  449. if ( m_current_marked && m_cursor != m_list.end() && m_saved_cursor == m_list.end() )
  450. {
  451. swapServices(prev_it, m_cursor);
  452. if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
  453. m_listbox->entryChanged(cursorResolve(m_cursor_number));
  454. }
  455. ++m_cursor_number;
  456. if (!(m_cursor->flags & eServiceReference::isInvisible))
  457. --count;
  458. }
  459. }
  460. else if (count < 0)
  461. {
  462. while (count && m_cursor != m_list.begin())
  463. {
  464. list::iterator prev_it = m_cursor--;
  465. if ( m_current_marked && m_cursor != m_list.end() && prev_it != m_list.end() && m_saved_cursor == m_list.end() )
  466. {
  467. swapServices(prev_it, m_cursor);
  468. if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
  469. m_listbox->entryChanged(cursorResolve(m_cursor_number));
  470. }
  471. --m_cursor_number;
  472. if (!(m_cursor->flags & eServiceReference::isInvisible))
  473. ++count;
  474. }
  475. while (m_cursor != m_list.end())
  476. {
  477. if (!((m_hide_number_marker && (m_cursor->flags & eServiceReference::isNumberedMarker)) || (m_cursor->flags & eServiceReference::isInvisible)))
  478. break;
  479. m_cursor++;
  480. m_cursor_number++;
  481. }
  482. }
  483. return 0;
  484. }
  485.  
  486. int eListboxServiceContent::cursorValid()
  487. {
  488. return m_cursor != m_list.end();
  489. }
  490.  
  491. int eListboxServiceContent::cursorSet(int n)
  492. {
  493. cursorHome();
  494. cursorMove(n);
  495. return 0;
  496. }
  497.  
  498. int eListboxServiceContent::cursorResolve(int cursor_position)
  499. {
  500. int m_stripped_cursor = 0;
  501. int count = 0;
  502. for (list::iterator i(m_list.begin()); i != m_list.end(); ++i)
  503. {
  504. if (count == cursor_position)
  505. break;
  506.  
  507. count++;
  508.  
  509. if (i->flags & eServiceReference::isInvisible)
  510. continue;
  511. m_stripped_cursor++;
  512. }
  513.  
  514. return m_stripped_cursor;
  515. }
  516.  
  517. int eListboxServiceContent::cursorGet()
  518. {
  519. return cursorResolve(m_cursor_number);
  520. }
  521.  
  522. int eListboxServiceContent::currentCursorSelectable()
  523. {
  524. if (cursorValid())
  525. {
  526. /* don't allow markers to be selected, unless we're in edit mode (because we want to provide some method to the user to remove a marker) */
  527. if (m_cursor->flags & eServiceReference::isMarker && m_marked.empty())
  528. return 0;
  529. else
  530. return 1;
  531. }
  532. return 0;
  533. }
  534.  
  535. void eListboxServiceContent::cursorSave()
  536. {
  537. m_saved_cursor = m_cursor;
  538. m_saved_cursor_number = m_cursor_number;
  539. }
  540.  
  541. void eListboxServiceContent::cursorRestore()
  542. {
  543. m_cursor = m_saved_cursor;
  544. m_cursor_number = m_saved_cursor_number;
  545. m_saved_cursor = m_list.end();
  546. }
  547.  
  548. int eListboxServiceContent::size()
  549. {
  550. int size = 0;
  551. for (list::iterator i(m_list.begin()); i != m_list.end(); ++i)
  552. {
  553. if (i->flags & eServiceReference::isInvisible)
  554. continue;
  555. size++;
  556. }
  557.  
  558. return size;
  559. }
  560.  
  561. void eListboxServiceContent::setSize(const eSize &size)
  562. {
  563. m_itemsize = size;
  564. if (m_visual_mode == visModeSimple)
  565. setVisualMode(m_visual_mode);
  566. }
  567.  
  568. void eListboxServiceContent::setGetPiconNameFunc(ePyObject func)
  569. {
  570. if (m_GetPiconNameFunc)
  571. Py_DECREF(m_GetPiconNameFunc);
  572. m_GetPiconNameFunc = func;
  573. if (m_GetPiconNameFunc)
  574. Py_INCREF(m_GetPiconNameFunc);
  575. }
  576.  
  577. void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
  578. {
  579. m_is_playable_ignore=service;
  580. if (m_listbox && m_listbox->isVisible())
  581. m_listbox->invalidate();
  582. }
  583.  
  584. void eListboxServiceContent::setItemHeight(int height)
  585. {
  586. m_itemheight = height;
  587. if (m_listbox)
  588. m_listbox->setItemHeight(height);
  589. }
  590.  
  591. bool eListboxServiceContent::checkServiceIsRecorded(eServiceReference ref,pNavigation::RecordType type)
  592. {
  593. std::map<ePtr<iRecordableService>, eServiceReference, std::less<iRecordableService*> > recordedServices;
  594. recordedServices = eNavigation::getInstance()->getRecordingsServices(type);
  595. for (std::map<ePtr<iRecordableService>, eServiceReference >::iterator it = recordedServices.begin(); it != recordedServices.end(); ++it)
  596. {
  597. if (ref.flags & eServiceReference::isGroup)
  598. {
  599. ePtr<iDVBChannelList> db;
  600. ePtr<eDVBResourceManager> res;
  601. eDVBResourceManager::getInstance(res);
  602. res->getChannelList(db);
  603. eBouquet *bouquet=0;
  604. db->getBouquet(ref, bouquet);
  605. for (std::list<eServiceReference>::iterator i(bouquet->m_services.begin()); i != bouquet->m_services.end(); ++i)
  606. if (*i == it->second)
  607. return true;
  608. }
  609. else if (ref == it->second)
  610. return true;
  611. }
  612. return false;
  613. }
  614.  
  615. void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
  616. {
  617. painter.clip(eRect(offset, m_itemsize));
  618.  
  619. int marked = 0;
  620.  
  621. if (m_current_marked && selected)
  622. marked = 2;
  623. else if (cursorValid() && isMarked(*m_cursor))
  624. {
  625. if (selected)
  626. marked = 2;
  627. else
  628. marked = 1;
  629. }
  630. else
  631. style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
  632.  
  633. eListboxStyle *local_style = 0;
  634.  
  635. /* get local listbox style, if present */
  636. if (m_listbox)
  637. local_style = m_listbox->getLocalStyle();
  638.  
  639. if (marked == 1) // marked
  640. {
  641. style.setStyle(painter, eWindowStyle::styleListboxMarked);
  642. if (m_color_set[markedForeground])
  643. painter.setForegroundColor(m_color[markedForeground]);
  644. if (m_color_set[markedBackground])
  645. painter.setBackgroundColor(m_color[markedBackground]);
  646. }
  647. else if (marked == 2) // marked and selected
  648. {
  649. style.setStyle(painter, eWindowStyle::styleListboxMarkedAndSelected);
  650. if (m_color_set[markedForegroundSelected])
  651. painter.setForegroundColor(m_color[markedForegroundSelected]);
  652. if (m_color_set[markedBackgroundSelected])
  653. painter.setBackgroundColor(m_color[markedBackgroundSelected]);
  654. }
  655. else if (local_style)
  656. {
  657. if (selected)
  658. {
  659. /* if we have a local background color set, use that. */
  660. if (local_style->m_background_color_selected_set)
  661. painter.setBackgroundColor(local_style->m_background_color_selected);
  662. /* same for foreground */
  663. if (local_style->m_foreground_color_selected_set)
  664. painter.setForegroundColor(local_style->m_foreground_color_selected);
  665. }
  666. else
  667. {
  668. /* if we have a local background color set, use that. */
  669. if (local_style->m_background_color_set)
  670. painter.setBackgroundColor(local_style->m_background_color);
  671. /* same for foreground */
  672. if (local_style->m_foreground_color_set)
  673. painter.setForegroundColor(local_style->m_foreground_color);
  674. }
  675. }
  676.  
  677. if (!local_style || !local_style->m_transparent_background)
  678. /* if we have no transparent background */
  679. {
  680. /* blit background picture, if available (otherwise, clear only) */
  681. if (local_style && local_style->m_background)
  682. painter.blit(local_style->m_background, offset, eRect(), 0);
  683. else
  684. painter.clear();
  685. } else
  686. {
  687. if (local_style->m_background)
  688. painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHABLEND);
  689. else if (selected && !local_style->m_selection)
  690. painter.clear();
  691. }
  692.  
  693. if (cursorValid())
  694. {
  695. /* get service information */
  696. ePtr<iStaticServiceInformation> service_info;
  697. m_service_center->info(*m_cursor, service_info);
  698. eServiceReference ref = *m_cursor;
  699. bool isMarker = ref.flags & eServiceReference::isMarker;
  700. bool isPlayable = !(ref.flags & eServiceReference::isDirectory || isMarker);
  701. bool isRecorded = m_record_indicator_mode && isPlayable && checkServiceIsRecorded(ref,pNavigation::RecordType(pNavigation::isRealRecording|pNavigation::isUnknownRecording));
  702. bool isStreamed = m_record_indicator_mode && isPlayable && checkServiceIsRecorded(ref,pNavigation::isStreaming);
  703. bool isPseudoRecorded = m_record_indicator_mode && isPlayable && checkServiceIsRecorded(ref,pNavigation::isPseudoRecording);
  704. ePtr<eServiceEvent> evt;
  705. bool serviceAvail = true;
  706. bool serviceFallback = false;
  707. int isplayable_value;
  708.  
  709. if (!marked && isPlayable && service_info && m_is_playable_ignore.valid())
  710. {
  711. isplayable_value = service_info->isPlayable(*m_cursor, m_is_playable_ignore);
  712.  
  713. if (isplayable_value == 0) // service unavailable
  714. {
  715. if (m_color_set[serviceNotAvail])
  716. painter.setForegroundColor(m_color[serviceNotAvail]);
  717. else
  718. painter.setForegroundColor(gRGB(0xbbbbbb));
  719. serviceAvail = false;
  720. }
  721. else
  722. {
  723. if (isplayable_value == 2) // fallback receiver service
  724. {
  725. if (m_color_set[serviceItemFallback])
  726. painter.setForegroundColor(m_color[serviceItemFallback]);
  727. serviceFallback = true;
  728. }
  729. }
  730. }
  731. if (m_record_indicator_mode == 3 && isPseudoRecorded)
  732. {
  733. if (m_color_set[servicePseudoRecorded])
  734. painter.setForegroundColor(m_color[servicePseudoRecorded]);
  735. else
  736. painter.setForegroundColor(gRGB(0x41b1ec));
  737. }
  738. if (m_record_indicator_mode == 3 && isStreamed)
  739. {
  740. if (m_color_set[serviceStreamed])
  741. painter.setForegroundColor(m_color[serviceStreamed]);
  742. else
  743. painter.setForegroundColor(gRGB(0xf56712));
  744. }
  745. if (m_record_indicator_mode == 3 && isRecorded)
  746. {
  747. if (m_color_set[serviceRecordingColor])
  748. painter.setForegroundColor(m_color[serviceRecordingColor]);
  749. else if (m_color_set[serviceRecorded])
  750. painter.setForegroundColor(m_color[serviceRecorded]);
  751. else
  752. painter.setForegroundColor(gRGB(0xb40431));
  753. }
  754.  
  755. if (selected && local_style && local_style->m_selection)
  756. painter.blit(local_style->m_selection, offset, eRect(), gPainter::BT_ALPHABLEND);
  757.  
  758. int xoffset=0; // used as offset when painting the folder/marker symbol or the serviceevent progress
  759. time_t now = time(0);
  760.  
  761. for (int e = 0; e != celServiceTypePixmap; ++e)
  762. {
  763. if (m_element_font[e])
  764. {
  765. int flags=gPainter::RT_VALIGN_CENTER;
  766. int yoffs = 0;
  767. eRect area = m_element_position[e];
  768. std::string text = "<n/a>";
  769. switch (e)
  770. {
  771. case celServiceNumber:
  772. {
  773. if (area.width() <= 0)
  774. continue; // no point in going on if we won't paint anything
  775.  
  776. if( m_cursor->getChannelNum() == 0 )
  777. continue;
  778.  
  779. char buffer[15];
  780. snprintf(buffer, sizeof(buffer), "%d", m_cursor->getChannelNum() );
  781. text = buffer;
  782. flags|=gPainter::RT_HALIGN_RIGHT;
  783. if (isPlayable && serviceFallback && selected && m_color_set[serviceSelectedFallback])
  784. painter.setForegroundColor(m_color[serviceSelectedFallback]);
  785. break;
  786. }
  787. case celServiceName:
  788. {
  789. if (service_info)
  790. service_info->getName(*m_cursor, text);
  791. if (!isPlayable)
  792. {
  793. area.setWidth(area.width() + m_element_position[celServiceEventProgressbar].width() + m_nonplayable_margins);
  794. if (m_element_position[celServiceEventProgressbar].left() == 0)
  795. area.setLeft(0);
  796. if (m_element_position[celServiceNumber].width() && m_element_position[celServiceEventProgressbar].left() == m_element_position[celServiceNumber].width() + m_nonplayable_margins)
  797. area.setLeft(m_element_position[celServiceNumber].width() + m_nonplayable_margins);
  798. }
  799. if (!(m_record_indicator_mode == 3 && isRecorded) && isPlayable && serviceFallback && selected && m_color_set[serviceSelectedFallback])
  800. painter.setForegroundColor(m_color[serviceSelectedFallback]);
  801. break;
  802. }
  803. case celServiceInfo:
  804. {
  805. if ( isPlayable && service_info && !service_info->getEvent(*m_cursor, evt) )
  806. {
  807. std::string name = evt->getEventName();
  808. if (name.empty())
  809. continue;
  810. text = evt->getEventName();
  811. if (serviceAvail)
  812. {
  813. if (!selected)
  814. {
  815. if (serviceFallback && m_color_set[eventForegroundFallback]) // fallback receiver
  816. painter.setForegroundColor(m_color[eventForegroundFallback]);
  817. else if(m_color_set[serviceDescriptionColor])
  818. painter.setForegroundColor(m_color[serviceDescriptionColor]);
  819. else if(m_color_set[eventForeground]) //serviceDescriptionColor
  820. painter.setForegroundColor(m_color[eventForeground]);
  821. else //default color (Tulip Tree)
  822. painter.setForegroundColor(gRGB(0xe7b53f));
  823.  
  824. }
  825. else
  826. {
  827. if (serviceFallback && m_color_set[eventForegroundSelectedFallback])
  828. painter.setForegroundColor(m_color[eventForegroundSelectedFallback]);
  829. else if(m_color_set[serviceDescriptionColorSelected])
  830. painter.setForegroundColor(m_color[serviceDescriptionColorSelected]);
  831. else if(m_color_set[eventForeground]) //serviceDescriptionColor
  832. painter.setForegroundColor(m_color[eventForegroundSelected]);
  833. else //default color (Tulip Tree)
  834. painter.setForegroundColor(gRGB(0xe7b53f));
  835.  
  836. }
  837. }
  838. break;
  839. }
  840. continue;
  841. }
  842. case celServiceEventProgressbar:
  843. {
  844. if (area.width() > 0 && isPlayable && service_info && !service_info->getEvent(*m_cursor, evt))
  845. {
  846. char buffer[15];
  847. snprintf(buffer, sizeof(buffer), "%d %%", (int)(100 * (now - evt->getBeginTime()) / evt->getDuration()));
  848. text = buffer;
  849. flags|=gPainter::RT_HALIGN_RIGHT;
  850. break;
  851. }
  852. continue;
  853. }
  854. }
  855.  
  856. eRect tmp = area;
  857. int xoffs = 0;
  858. ePtr<gPixmap> piconPixmap;
  859.  
  860. if (e == celServiceName)
  861. {
  862. //picon stuff
  863. if (isPlayable && PyCallable_Check(m_GetPiconNameFunc))
  864. {
  865. ePyObject pArgs = PyTuple_New(1);
  866. PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(ref.toString().c_str()));
  867. ePyObject pRet = PyObject_CallObject(m_GetPiconNameFunc, pArgs);
  868. Py_DECREF(pArgs);
  869. if (pRet)
  870. {
  871. if (PyString_Check(pRet))
  872. {
  873. std::string piconFilename = PyString_AS_STRING(pRet);
  874. if (!piconFilename.empty())
  875. loadPNG(piconPixmap, piconFilename.c_str());
  876. }
  877. Py_DECREF(pRet);
  878. }
  879. }
  880. xoffs = xoffset;
  881. tmp.setWidth(((!isPlayable || m_column_width == -1 || (!piconPixmap && !m_column_width)) ? tmp.width() : m_column_width) - xoffs);
  882. }
  883.  
  884. eTextPara *para = new eTextPara(tmp);
  885. para->setFont(m_element_font[e]);
  886. //std::string text = text;
  887. std::regex rgx("\| \d+\+$");text = std::regex_replace(text, rgx, "", std::regex_constants::format_first_only);
  888. para->renderString(text.c_str());
  889.  
  890. if (e == celServiceName)
  891. {
  892. eRect bbox = para->getBoundBox();
  893.  
  894. int servicenameWidth = ((!isPlayable || m_column_width == -1 || (!piconPixmap && !m_column_width)) ? bbox.width() : m_column_width);
  895. m_element_position[celServiceInfo].setLeft(area.left() + servicenameWidth + m_items_distances + xoffs);
  896. m_element_position[celServiceInfo].setTop(area.top());
  897. m_element_position[celServiceInfo].setWidth(area.width() - (servicenameWidth + m_items_distances + xoffs));
  898. m_element_position[celServiceInfo].setHeight(area.height());
  899.  
  900. if (isPlayable)
  901. {
  902. //picon stuff
  903. if (PyCallable_Check(m_GetPiconNameFunc) and (m_column_width || piconPixmap))
  904. {
  905. eRect area = m_element_position[celServiceInfo];
  906. /* PIcons are usually about 100:60. Make it a
  907. * bit wider in case the icons are diffently
  908. * shaped, and to add a bit of margin between
  909. * icon and text. */
  910. const int iconWidth = (area.height() + m_service_picon_downsize * 2) * 1.67 + m_items_distances;
  911. m_element_position[celServiceInfo].setLeft(area.left() + iconWidth);
  912. m_element_position[celServiceInfo].setWidth(area.width() - iconWidth);
  913. area = m_element_position[celServiceName];
  914. xoffs += iconWidth;
  915. if (piconPixmap)
  916. {
  917. area.moveBy(offset);
  918. painter.clip(area);
  919. painter.blitScale(piconPixmap,
  920. eRect(area.left(), area.top() - m_service_picon_downsize, iconWidth, area.height() + m_service_picon_downsize * 2),
  921. area,
  922. gPainter::BT_ALPHABLEND | gPainter::BT_KEEP_ASPECT_RATIO);
  923. painter.clippop();
  924. }
  925. }
  926.  
  927. //service type marker stuff
  928. if (m_servicetype_icon_mode)
  929. {
  930. int orbpos = m_cursor->getUnsignedData(4) >> 16;
  931. const char *filename = ref.path.c_str();
  932. ePtr<gPixmap> &pixmap =
  933. (m_cursor->flags & eServiceReference::isGroup) ? m_pixmaps[picServiceGroup] :
  934. (strstr(filename, "://")) ? m_pixmaps[picStream] :
  935. (orbpos == 0xFFFF) ? m_pixmaps[picDVB_C] :
  936. (orbpos == 0xEEEE) ? m_pixmaps[picDVB_T] : m_pixmaps[picDVB_S];
  937. if (pixmap)
  938. {
  939. eSize pixmap_size = pixmap->size();
  940. eRect area = m_element_position[celServiceInfo];
  941. m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + m_items_distances);
  942. m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - m_items_distances);
  943. int offs = 0;
  944. if (m_servicetype_icon_mode == 1)
  945. {
  946. area = m_element_position[celServiceName];
  947. offs = xoffs;
  948. xoffs += pixmap_size.width() + m_items_distances;
  949. }
  950. else if (m_crypto_icon_mode == 1 && m_pixmaps[picCrypto])
  951. offs = offs + m_pixmaps[picCrypto]->size().width() + m_items_distances;
  952. int correction = (area.height() - pixmap_size.height()) / 2;
  953. area.moveBy(offset);
  954. painter.clip(area);
  955. painter.blit(pixmap, ePoint(area.left() + offs, offset.y() + correction), area, gPainter::BT_ALPHABLEND);
  956. painter.clippop();
  957. }
  958. }
  959.  
  960. //crypto icon stuff
  961. if (m_crypto_icon_mode && m_pixmaps[picCrypto])
  962. {
  963. eSize pixmap_size = m_pixmaps[picCrypto]->size();
  964. eRect area = m_element_position[celServiceInfo];
  965. int offs = 0;
  966. if (m_crypto_icon_mode == 1)
  967. {
  968. m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + m_items_distances);
  969. m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - m_items_distances);
  970. area = m_element_position[celServiceName];
  971. offs = xoffs;
  972. xoffs += pixmap_size.width() + m_items_distances;
  973. }
  974. int correction = (area.height() - pixmap_size.height()) / 2;
  975. area.moveBy(offset);
  976. if (service_info && service_info->isCrypted())
  977. {
  978. if (m_crypto_icon_mode == 2)
  979. {
  980. m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + m_items_distances);
  981. m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - m_items_distances);
  982. }
  983. painter.clip(area);
  984. painter.blit(m_pixmaps[picCrypto], ePoint(area.left() + offs, offset.y() + correction), area, gPainter::BT_ALPHABLEND);
  985. painter.clippop();
  986. }
  987. }
  988.  
  989. //record icon stuff
  990. if (isRecorded && m_record_indicator_mode < 3 && m_pixmaps[picRecord])
  991. {
  992. eSize pixmap_size = m_pixmaps[picRecord]->size();
  993. eRect area = m_element_position[celServiceInfo];
  994. int offs = 0;
  995. if (m_record_indicator_mode == 1)
  996. {
  997. m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + m_items_distances);
  998. m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - m_items_distances);
  999. area = m_element_position[celServiceName];
  1000. offs = xoffs;
  1001. xoffs += pixmap_size.width() + m_items_distances;
  1002. }
  1003. int correction = (area.height() - pixmap_size.height()) / 2;
  1004. area.moveBy(offset);
  1005. if (m_record_indicator_mode == 2)
  1006. {
  1007. m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + m_items_distances);
  1008. m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - m_items_distances);
  1009. }
  1010. painter.clip(area);
  1011. painter.blit(m_pixmaps[picRecord], ePoint(area.left() + offs, offset.y() + correction), area, gPainter::BT_ALPHABLEND);
  1012. painter.clippop();
  1013. }
  1014. }
  1015. }
  1016.  
  1017. if (flags & gPainter::RT_HALIGN_RIGHT)
  1018. para->realign(eTextPara::dirRight);
  1019. else if (flags & gPainter::RT_HALIGN_CENTER)
  1020. para->realign(eTextPara::dirCenter);
  1021. else if (flags & gPainter::RT_HALIGN_BLOCK)
  1022. para->realign(eTextPara::dirBlock);
  1023.  
  1024. if (flags & gPainter::RT_VALIGN_CENTER)
  1025. {
  1026. eRect bbox = para->getBoundBox();
  1027. yoffs = (area.height() - bbox.height()) / 2 - bbox.top();
  1028. }
  1029.  
  1030. painter.renderPara(para, offset+ePoint(xoffs, yoffs));
  1031. }
  1032. else if ((e == celFolderPixmap && m_cursor->flags & eServiceReference::isDirectory) ||
  1033. (e == celMarkerPixmap && m_cursor->flags & eServiceReference::isMarker &&
  1034. !(m_cursor->flags & eServiceReference::isNumberedMarker)))
  1035. {
  1036. ePtr<gPixmap> &pixmap =
  1037. (e == celFolderPixmap) ? m_pixmaps[picFolder] : m_pixmaps[picMarker];
  1038. if (pixmap)
  1039. {
  1040. eSize pixmap_size = pixmap->size();
  1041. eRect area = m_element_position[e == celFolderPixmap ? celServiceName: celServiceNumber];
  1042. int correction = (area.height() - pixmap_size.height()) / 2;
  1043. if (e == celFolderPixmap)
  1044. if (m_element_position[celServiceEventProgressbar].left() == 0)
  1045. area.setLeft(0);
  1046. xoffset = pixmap_size.width() + m_items_distances;
  1047. area.moveBy(offset);
  1048. painter.clip(area);
  1049. painter.blit(pixmap, ePoint(area.left(), offset.y() + correction), area, gPainter::BT_ALPHABLEND);
  1050. painter.clippop();
  1051. }
  1052. }
  1053. }
  1054. if (selected && (!local_style || !local_style->m_selection))
  1055. style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
  1056.  
  1057. eRect area = m_element_position[celServiceEventProgressbar];
  1058. if (area.width() > 0 && evt && !m_element_font[celServiceEventProgressbar])
  1059. {
  1060. int pb_xpos = area.left();
  1061. int pb_ypos = offset.y() + (m_itemsize.height() - m_progressbar_height - 2 * m_progressbar_border_width) / 2;
  1062. int pb_width = area.width()- 2 * m_progressbar_border_width;
  1063. gRGB ProgressbarBorderColor = 0xdfdfdf;
  1064. int evt_done = pb_width * (now - evt->getBeginTime()) / evt->getDuration();
  1065.  
  1066. // the progress data...
  1067. eRect tmp = eRect(pb_xpos + m_progressbar_border_width, pb_ypos + m_progressbar_border_width, evt_done, m_progressbar_height);
  1068. ePtr<gPixmap> &pixmap = m_pixmaps[picServiceEventProgressbar];
  1069. if (pixmap) {
  1070. painter.clip(tmp);
  1071. painter.blit(pixmap, ePoint(pb_xpos + m_progressbar_border_width, pb_ypos + m_progressbar_border_width), tmp, gPainter::BT_ALPHABLEND);
  1072. painter.clippop();
  1073. }
  1074. else {
  1075. if (!selected && m_color_set[serviceEventProgressbarColor])
  1076. painter.setForegroundColor(m_color[serviceEventProgressbarColor]);
  1077. else if (selected && m_color_set[serviceEventProgressbarColorSelected])
  1078. painter.setForegroundColor(m_color[serviceEventProgressbarColorSelected]);
  1079. painter.fill(tmp);
  1080. }
  1081.  
  1082. // the progressbar border
  1083. if (!selected) {
  1084. if (m_color_set[serviceEventProgressbarBorderColor])
  1085. ProgressbarBorderColor = m_color[serviceEventProgressbarBorderColor];
  1086. else if (m_color_set[eventborderForeground])
  1087. ProgressbarBorderColor = m_color[eventborderForeground];
  1088. }
  1089. else { /* !selected */
  1090. if (m_color_set[serviceEventProgressbarBorderColorSelected])
  1091. ProgressbarBorderColor = m_color[serviceEventProgressbarBorderColorSelected];
  1092. else if (m_color_set[eventborderForegroundSelected])
  1093. ProgressbarBorderColor = m_color[eventborderForegroundSelected];
  1094. }
  1095. painter.setForegroundColor(ProgressbarBorderColor);
  1096.  
  1097. painter.fill(eRect(pb_xpos, pb_ypos, pb_width + 2 * m_progressbar_border_width, m_progressbar_border_width));
  1098. painter.fill(eRect(pb_xpos, pb_ypos + m_progressbar_border_width + m_progressbar_height, pb_width + 2 * m_progressbar_border_width, m_progressbar_border_width));
  1099. painter.fill(eRect(pb_xpos, pb_ypos + m_progressbar_border_width, m_progressbar_border_width, m_progressbar_height));
  1100. painter.fill(eRect(pb_xpos + m_progressbar_border_width + pb_width, pb_ypos + m_progressbar_border_width, m_progressbar_border_width, m_progressbar_height));
  1101. }
  1102. }
  1103. painter.clippop();
  1104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement