1 #include <lib/service/listboxservice.h>
2 #include <lib/service/service.h>
3 #include <lib/gdi/font.h>
4 #include <lib/dvb/epgcache.h>
5 #include <lib/dvb/pmt.h>
6 #include <lib/python/connections.h>
8 void eListboxServiceContent::addService(const eServiceReference &service, bool beforeCurrent)
10 if (beforeCurrent && m_size)
11 m_list.insert(m_cursor, service);
13 m_list.push_back(service);
18 m_listbox->entryAdded(m_cursor_number-1);
22 m_cursor = m_list.begin();
24 m_listbox->entryAdded(0);
28 void eListboxServiceContent::removeCurrent()
30 if (m_size && m_listbox)
32 if (m_cursor_number == --m_size)
34 m_list.erase(m_cursor--);
38 m_listbox->entryRemoved(m_cursor_number+1);
41 m_listbox->entryRemoved(m_cursor_number);
45 m_list.erase(m_cursor++);
46 m_listbox->entryRemoved(m_cursor_number);
51 void eListboxServiceContent::FillFinished()
53 m_size = m_list.size();
57 m_listbox->entryReset();
60 void eListboxServiceContent::setRoot(const eServiceReference &root, bool justSet)
70 ASSERT(m_service_center);
72 if (m_service_center->list(m_root, m_lst))
73 eDebug("no list available!");
74 else if (m_lst->getContent(m_list))
75 eDebug("getContent failed");
80 void eListboxServiceContent::setCurrent(const eServiceReference &ref)
83 for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
87 m_cursor_number = index;
91 m_listbox->moveSelectionTo(index);
94 void eListboxServiceContent::getCurrent(eServiceReference &ref)
99 ref = eServiceReference();
102 int eListboxServiceContent::getNextBeginningWithChar(char c)
104 // printf("Char: %c\n", c);
106 for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
109 ePtr<iStaticServiceInformation> service_info;
110 m_service_center->info(*i, service_info);
111 service_info->getName(*i, text);
112 // printf("%c\n", text.c_str()[0]);
114 int len=text.length();
117 char cc = text[idx++];
118 if ( cc >= 33 && cc < 127)
129 int eListboxServiceContent::getPrevMarkerPos()
133 list::iterator i(m_cursor);
134 int index = m_cursor_number;
139 if (i->flags & eServiceReference::isMarker)
145 int eListboxServiceContent::getNextMarkerPos()
149 list::iterator i(m_cursor);
150 int index = m_cursor_number;
151 while (index < (m_size-1))
155 if (i->flags & eServiceReference::isMarker)
161 void eListboxServiceContent::initMarked()
166 void eListboxServiceContent::addMarked(const eServiceReference &ref)
168 m_marked.insert(ref);
170 m_listbox->entryChanged(lookupService(ref));
173 void eListboxServiceContent::removeMarked(const eServiceReference &ref)
177 m_listbox->entryChanged(lookupService(ref));
180 int eListboxServiceContent::isMarked(const eServiceReference &ref)
182 return m_marked.find(ref) != m_marked.end();
185 void eListboxServiceContent::markedQueryStart()
187 m_marked_iterator = m_marked.begin();
190 int eListboxServiceContent::markedQueryNext(eServiceReference &ref)
192 if (m_marked_iterator == m_marked.end())
194 ref = *m_marked_iterator++;
198 int eListboxServiceContent::lookupService(const eServiceReference &ref)
200 /* shortcut for cursor */
201 if (ref == *m_cursor)
202 return m_cursor_number;
203 /* otherwise, search in the list.. */
205 for (list::const_iterator i(m_list.begin()); i != m_list.end(); ++i, ++index);
207 /* this is ok even when the index was not found. */
211 void eListboxServiceContent::setVisualMode(int mode)
213 for (int i=0; i < celElements; ++i)
215 m_element_position[i] = eRect();
216 m_element_font[i] = 0;
219 m_visual_mode = mode;
221 if (m_visual_mode == visModeSimple)
223 m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize);
224 m_element_font[celServiceName] = new gFont("Regular", 23);
228 void eListboxServiceContent::setElementPosition(int element, eRect where)
230 if ((element >= 0) && (element < celElements))
231 m_element_position[element] = where;
234 void eListboxServiceContent::setElementFont(int element, gFont *font)
236 if ((element >= 0) && (element < celElements))
237 m_element_font[element] = font;
240 void eListboxServiceContent::setPixmap(int type, ePtr<gPixmap> &pic)
242 if ((type >=0) && (type < picElements))
243 m_pixmaps[type] = pic;
246 void eListboxServiceContent::sort()
249 m_service_center->list(m_root, m_lst);
252 m_list.sort(iListableServiceCompare(m_lst));
253 /* FIXME: is this really required or can we somehow keep the current entry? */
256 m_listbox->entryReset();
260 DEFINE_REF(eListboxServiceContent);
262 eListboxServiceContent::eListboxServiceContent()
263 :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_numberoffset(0), m_itemheight(25)
265 memset(m_color_set, 0, sizeof(m_color_set));
267 eServiceCenter::getInstance(m_service_center);
270 void eListboxServiceContent::setColor(int color, gRGB &col)
272 if ((color >= 0) && (color < colorElements))
274 m_color_set[color] = true;
275 m_color[color] = col;
279 void eListboxServiceContent::cursorHome()
281 if (m_current_marked && m_saved_cursor == m_list.end())
283 if (m_cursor_number >= m_size)
285 m_cursor_number = m_size-1;
288 while (m_cursor_number)
290 std::iter_swap(m_cursor--, m_cursor);
292 if (m_listbox && m_cursor_number)
293 m_listbox->entryChanged(m_cursor_number);
298 m_cursor = m_list.begin();
303 void eListboxServiceContent::cursorEnd()
305 if (m_current_marked && m_saved_cursor == m_list.end())
307 while (m_cursor != m_list.end())
309 list::iterator prev = m_cursor++;
311 if ( prev != m_list.end() && m_cursor != m_list.end() )
313 std::iter_swap(m_cursor, prev);
315 m_listbox->entryChanged(m_cursor_number);
321 m_cursor = m_list.end();
322 m_cursor_number = m_size;
326 int eListboxServiceContent::setCurrentMarked(bool state)
328 bool prev = m_current_marked;
329 m_current_marked = state;
331 if (state != prev && m_listbox)
333 m_listbox->entryChanged(m_cursor_number);
337 m_service_center->list(m_root, m_lst);
340 ePtr<iMutableServiceList> list;
341 if (m_lst->startEdit(list))
342 eDebug("no editable list");
345 eServiceReference ref;
348 eDebug("no valid service selected");
351 int pos = cursorGet();
352 eDebugNoNewLine("move %s to %d ", ref.toString().c_str(), pos);
353 if (list->moveService(ref, cursorGet()))
361 eDebug("no list available!");
368 int eListboxServiceContent::cursorMove(int count)
370 int prev = m_cursor_number, last = m_cursor_number + count;
373 while(count && m_cursor != m_list.end())
375 list::iterator prev_it = m_cursor++;
376 if ( m_current_marked && m_cursor != m_list.end() && m_saved_cursor == m_list.end() )
378 std::iter_swap(prev_it, m_cursor);
379 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
380 m_listbox->entryChanged(m_cursor_number);
385 } else if (count < 0)
387 while (count && m_cursor != m_list.begin())
389 list::iterator prev_it = m_cursor--;
390 if ( m_current_marked && m_cursor != m_list.end() && prev_it != m_list.end() && m_saved_cursor == m_list.end() )
392 std::iter_swap(prev_it, m_cursor);
393 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
394 m_listbox->entryChanged(m_cursor_number);
403 int eListboxServiceContent::cursorValid()
405 return m_cursor != m_list.end();
408 int eListboxServiceContent::cursorSet(int n)
415 int eListboxServiceContent::cursorGet()
417 return m_cursor_number;
420 void eListboxServiceContent::cursorSave()
422 m_saved_cursor = m_cursor;
423 m_saved_cursor_number = m_cursor_number;
426 void eListboxServiceContent::cursorRestore()
428 m_cursor = m_saved_cursor;
429 m_cursor_number = m_saved_cursor_number;
430 m_saved_cursor = m_list.end();
433 int eListboxServiceContent::size()
438 void eListboxServiceContent::setSize(const eSize &size)
441 if (m_visual_mode == visModeSimple)
442 setVisualMode(m_visual_mode);
445 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
447 painter.clip(eRect(offset, m_itemsize));
451 if (m_current_marked && selected)
453 else if (cursorValid() && isMarked(*m_cursor))
461 style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
463 eListboxStyle *local_style = 0;
465 /* get local listbox style, if present */
467 local_style = m_listbox->getLocalStyle();
469 if (marked == 1) // marked
471 style.setStyle(painter, eWindowStyle::styleListboxMarked);
472 if (m_color_set[markedForeground])
473 painter.setForegroundColor(m_color[markedForeground]);
474 if (m_color_set[markedBackground])
475 painter.setBackgroundColor(m_color[markedBackground]);
477 else if (marked == 2) // marked and selected
479 style.setStyle(painter, eWindowStyle::styleListboxMarkedAndSelected);
480 if (m_color_set[markedForegroundSelected])
481 painter.setForegroundColor(m_color[markedForegroundSelected]);
482 if (m_color_set[markedBackgroundSelected])
483 painter.setBackgroundColor(m_color[markedBackgroundSelected]);
485 else if (local_style)
489 /* if we have a local background color set, use that. */
490 if (local_style->m_background_color_selected_set)
491 painter.setBackgroundColor(local_style->m_background_color_selected);
492 /* same for foreground */
493 if (local_style->m_foreground_color_selected_set)
494 painter.setForegroundColor(local_style->m_foreground_color_selected);
498 /* if we have a local background color set, use that. */
499 if (local_style->m_background_color_set)
500 painter.setBackgroundColor(local_style->m_background_color);
501 /* same for foreground */
502 if (local_style->m_foreground_color_set)
503 painter.setForegroundColor(local_style->m_foreground_color);
507 if (!local_style || !local_style->m_transparent_background)
508 /* if we have no transparent background */
510 /* blit background picture, if available (otherwise, clear only) */
511 if (local_style && local_style->m_background)
512 painter.blit(local_style->m_background, offset, eRect(), 0);
517 if (local_style->m_background)
518 painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHATEST);
519 else if (selected && !local_style->m_selection)
525 /* get service information */
526 ePtr<iStaticServiceInformation> service_info;
527 m_service_center->info(*m_cursor, service_info);
528 eServiceReference ref = *m_cursor;
529 bool isMarker = ref.flags & eServiceReference::isMarker;
530 bool isPlayable = !(ref.flags & eServiceReference::isDirectory || isMarker);
531 ePtr<eServiceEvent> evt;
533 if (!marked && isPlayable && service_info && m_is_playable_ignore.valid() && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
535 if (m_color_set[serviceNotAvail])
536 painter.setForegroundColor(m_color[serviceNotAvail]);
538 painter.setForegroundColor(gRGB(0xbbbbbb));
541 if (selected && local_style && local_style->m_selection)
542 painter.blit(local_style->m_selection, offset, eRect(), gPainter::BT_ALPHATEST);
544 int xoffset=0; // used as offset when painting the folder/marker symbol or the serviceevent progress
546 for (int e = 0; e < celElements; ++e)
548 if (m_element_font[e])
550 int flags=gPainter::RT_VALIGN_CENTER,
553 eRect &area = m_element_position[e];
554 std::string text = "<n/a>";
559 case celServiceNumber:
561 if (m_cursor->flags & eServiceReference::isMarker)
564 /* how we can do this better? :) */
565 int markers_before=0;
567 list::iterator tmp=m_cursor;
568 while(tmp != m_list.begin())
571 if (tmp->flags & eServiceReference::isMarker)
575 sprintf(bla, "%d", m_numberoffset + m_cursor_number + 1 - markers_before);
577 flags|=gPainter::RT_HALIGN_RIGHT;
583 service_info->getName(*m_cursor, text);
588 if ( isPlayable && evt )
590 std::string name = evt->getEventName();
593 text = '(' + evt->getEventName() + ')';
602 tmp.setWidth(tmp.width()-xoffs);
604 eTextPara *para = new eTextPara(tmp);
605 para->setFont(m_element_font[e]);
606 para->renderString(text.c_str());
608 if (e == celServiceName)
610 eRect bbox = para->getBoundBox();
611 int name_width = bbox.width()+8;
612 m_element_position[celServiceInfo].setLeft(area.left()+name_width+xoffs);
613 m_element_position[celServiceInfo].setTop(area.top());
614 m_element_position[celServiceInfo].setWidth(area.width()-(name_width+xoffs));
615 m_element_position[celServiceInfo].setHeight(area.height());
618 if (flags & gPainter::RT_HALIGN_RIGHT)
619 para->realign(eTextPara::dirRight);
620 else if (flags & gPainter::RT_HALIGN_CENTER)
621 para->realign(eTextPara::dirCenter);
622 else if (flags & gPainter::RT_HALIGN_BLOCK)
623 para->realign(eTextPara::dirBlock);
625 if (flags & gPainter::RT_VALIGN_CENTER)
627 eRect bbox = para->getBoundBox();
628 int vcentered_top = (area.height() - bbox.height()) / 2;
629 yoffs = vcentered_top - bbox.top();
632 painter.renderPara(para, offset+ePoint(xoffs, yoffs));
634 else if (e == celServiceTypePixmap || e == celFolderPixmap || e == celMarkerPixmap)
636 int orbpos = m_cursor->getUnsignedData(4) >> 16;
637 ePtr<gPixmap> &pixmap =
638 (e == celFolderPixmap) ? m_pixmaps[picFolder] :
639 (e == celMarkerPixmap) ? m_pixmaps[picMarker] :
640 (m_cursor->flags & eServiceReference::isGroup) ? m_pixmaps[picServiceGroup] :
641 (orbpos == 0xFFFF) ? m_pixmaps[picDVB_C] :
642 (orbpos == 0xEEEE) ? m_pixmaps[picDVB_T] : m_pixmaps[picDVB_S];
645 eSize pixmap_size = pixmap->size();
646 int p = celServiceInfo;
647 if (e == celFolderPixmap)
649 else if (e == celMarkerPixmap)
650 p = celServiceNumber;
651 eRect area = m_element_position[p];
652 int correction = (area.height() - pixmap_size.height()) / 2;
656 if (e != celServiceTypePixmap)
658 m_element_position[celServiceInfo] = area;
659 m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + 8);
660 m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - 8);
662 else if (m_cursor->flags & eServiceReference::isDirectory)
664 if (e != celFolderPixmap)
666 xoffset = pixmap_size.width() + 8;
668 else if (m_cursor->flags & eServiceReference::isMarker)
670 if (e != celMarkerPixmap)
674 eFatal("unknown service type in listboxservice");
678 painter.blit(pixmap, offset+ePoint(area.left(), correction), area, gPainter::BT_ALPHATEST);
682 else if (e == celServiceEventProgressbar)
684 int p = celServiceEventProgressbar;
685 eRect area = m_element_position[p];
686 if (area.width() > 0 && (isPlayable || isMarker))
689 if ( isPlayable && service_info && !service_info->getEvent(*m_cursor, evt) )
691 if (!selected && m_color_set[serviceEventProgressbarBorderColor])
692 painter.setForegroundColor(m_color[serviceEventProgressbarBorderColor]);
693 else if (selected && m_color_set[serviceEventProgressbarBorderColorSelected])
694 painter.setForegroundColor(m_color[serviceEventProgressbarBorderColorSelected]);
698 int progressX = area.left() + offset.x();
699 int progressW = area.width() - 2 * border;
700 int progressT = offset.y() + (m_itemsize.height() - progressH - 2*border) / 2;
702 // paint progressbar frame
703 painter.fill(eRect(progressX, progressT, area.width(), border));
704 painter.fill(eRect(progressX, progressT + border, border, progressH));
705 painter.fill(eRect(progressX, progressT + progressH + border, area.width(), border));
706 painter.fill(eRect(progressX + area.width() - border, progressT + border, border, progressH));
709 time_t now = time(0);
710 int value = progressW * (now - evt->getBeginTime()) / evt->getDuration();
712 eRect tmp = eRect(progressX + border, progressT + border, value, progressH);
713 ePtr<gPixmap> &pixmap = m_pixmaps[picServiceEventProgressbar];
718 painter.blit(pixmap, ePoint(progressX + border, progressT + border), tmp, gPainter::BT_ALPHATEST);
723 if (!selected && m_color_set[serviceEventProgressbarColor])
724 painter.setForegroundColor(m_color[serviceEventProgressbarColor]);
725 else if (selected && m_color_set[serviceEventProgressbarColorSelected])
726 painter.setForegroundColor(m_color[serviceEventProgressbarColorSelected]);
730 xoffset = area.width() + 10;
734 if (selected && (!local_style || !local_style->m_selection))
735 style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
741 void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
743 m_is_playable_ignore=service;
744 if (m_listbox && m_listbox->isVisible())
745 m_listbox->invalidate();
748 void eListboxServiceContent::setItemHeight(int height)
750 m_itemheight = height;
752 m_listbox->setItemHeight(height);