Advertisement
SharkyEXE

Untitled

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