Advertisement
SharkyEXE

Untitled

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