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)
12 m_list.insert(m_cursor, service);
16 m_list.push_back(service);
20 void eListboxServiceContent::removeCurrent()
22 if (m_size && m_listbox)
24 if (m_cursor_number == m_size-1)
26 m_list.erase(m_cursor--);
30 m_list.erase(m_cursor++);
32 m_listbox->entryRemoved(m_cursor_number);
36 void eListboxServiceContent::FillFinished()
38 m_size = m_list.size();
42 m_listbox->entryReset();
45 void eListboxServiceContent::setRoot(const eServiceReference &root, bool justSet)
55 assert(m_service_center);
57 if (m_service_center->list(m_root, m_lst))
58 eDebug("no list available!");
59 else if (m_lst->getContent(m_list))
60 eDebug("getContent failed");
65 void eListboxServiceContent::setCurrent(const eServiceReference &ref)
68 for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
72 m_cursor_number = index;
76 m_listbox->moveSelectionTo(index);
79 void eListboxServiceContent::getCurrent(eServiceReference &ref)
84 ref = eServiceReference();
87 int eListboxServiceContent::getNextBeginningWithChar(char c)
89 // printf("Char: %c\n", c);
91 for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
94 ePtr<iStaticServiceInformation> service_info;
95 m_service_center->info(*i, service_info);
96 service_info->getName(*i, text);
97 // printf("%c\n", text.c_str()[0]);
99 int len=text.length();
102 char cc = text[idx++];
103 if ( cc >= 33 && cc < 127)
114 int eListboxServiceContent::getPrevMarkerPos()
118 list::iterator i(m_cursor);
119 int index = m_cursor_number;
124 if (i->flags & eServiceReference::isMarker)
130 int eListboxServiceContent::getNextMarkerPos()
134 list::iterator i(m_cursor);
135 int index = m_cursor_number;
136 while (index < (m_size-1))
140 if (i->flags & eServiceReference::isMarker)
146 void eListboxServiceContent::initMarked()
151 void eListboxServiceContent::addMarked(const eServiceReference &ref)
153 m_marked.insert(ref);
155 m_listbox->entryChanged(lookupService(ref));
158 void eListboxServiceContent::removeMarked(const eServiceReference &ref)
162 m_listbox->entryChanged(lookupService(ref));
165 int eListboxServiceContent::isMarked(const eServiceReference &ref)
167 return m_marked.find(ref) != m_marked.end();
170 void eListboxServiceContent::markedQueryStart()
172 m_marked_iterator = m_marked.begin();
175 int eListboxServiceContent::markedQueryNext(eServiceReference &ref)
177 if (m_marked_iterator == m_marked.end())
179 ref = *m_marked_iterator++;
183 int eListboxServiceContent::lookupService(const eServiceReference &ref)
185 /* shortcut for cursor */
186 if (ref == *m_cursor)
187 return m_cursor_number;
188 /* otherwise, search in the list.. */
190 for (list::const_iterator i(m_list.begin()); i != m_list.end(); ++i, ++index);
192 /* this is ok even when the index was not found. */
196 void eListboxServiceContent::setVisualMode(int mode)
198 m_visual_mode = mode;
200 if (m_visual_mode == visModeSimple)
202 m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize);
203 m_element_font[celServiceName] = new gFont("Regular", 23);
204 m_element_position[celServiceNumber] = eRect();
205 m_element_font[celServiceNumber] = 0;
206 m_element_position[celServiceInfo] = eRect();
207 m_element_font[celServiceInfo] = 0;
211 void eListboxServiceContent::setElementPosition(int element, eRect where)
213 if ((element >= 0) && (element < celElements))
214 m_element_position[element] = where;
217 void eListboxServiceContent::setElementFont(int element, gFont *font)
219 if ((element >= 0) && (element < celElements))
220 m_element_font[element] = font;
223 void eListboxServiceContent::setPixmap(int type, ePtr<gPixmap> &pic)
225 if ((type >=0) && (type < picElements))
226 m_pixmaps[type] = pic;
229 void eListboxServiceContent::sort()
232 m_service_center->list(m_root, m_lst);
235 m_list.sort(iListableServiceCompare(m_lst));
236 /* FIXME: is this really required or can we somehow keep the current entry? */
239 m_listbox->entryReset();
243 DEFINE_REF(eListboxServiceContent);
245 eListboxServiceContent::eListboxServiceContent()
246 :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_numberoffset(0)
249 eServiceCenter::getInstance(m_service_center);
252 void eListboxServiceContent::cursorHome()
254 if (m_current_marked && m_saved_cursor == m_list.end())
256 if (m_cursor_number >= m_size)
258 m_cursor_number = m_size-1;
261 while (m_cursor_number)
263 std::iter_swap(m_cursor--, m_cursor);
265 if (m_listbox && m_cursor_number)
266 m_listbox->entryChanged(m_cursor_number);
271 m_cursor = m_list.begin();
276 void eListboxServiceContent::cursorEnd()
278 if (m_current_marked && m_saved_cursor == m_list.end())
280 while (m_cursor != m_list.end())
282 list::iterator prev = m_cursor++;
284 if ( prev != m_list.end() && m_cursor != m_list.end() )
286 std::iter_swap(m_cursor, prev);
288 m_listbox->entryChanged(m_cursor_number);
294 m_cursor = m_list.end();
295 m_cursor_number = m_size;
299 int eListboxServiceContent::setCurrentMarked(bool state)
301 bool prev = m_current_marked;
302 m_current_marked = state;
304 if (state != prev && m_listbox)
306 m_listbox->entryChanged(m_cursor_number);
310 m_service_center->list(m_root, m_lst);
313 ePtr<iMutableServiceList> list;
314 if (m_lst->startEdit(list))
315 eDebug("no editable list");
318 eServiceReference ref;
321 eDebug("no valid service selected");
324 int pos = cursorGet();
325 eDebugNoNewLine("move %s to %d ", ref.toString().c_str(), pos);
326 if (list->moveService(ref, cursorGet()))
334 eDebug("no list available!");
341 int eListboxServiceContent::cursorMove(int count)
343 int prev = m_cursor_number, last = m_cursor_number + count;
346 while(count && m_cursor != m_list.end())
348 list::iterator prev_it = m_cursor++;
349 if ( m_current_marked && m_cursor != m_list.end() && m_saved_cursor == m_list.end() )
351 std::iter_swap(prev_it, m_cursor);
352 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
353 m_listbox->entryChanged(m_cursor_number);
358 } else if (count < 0)
360 while (count && m_cursor != m_list.begin())
362 list::iterator prev_it = m_cursor--;
363 if ( m_current_marked && m_cursor != m_list.end() && prev_it != m_list.end() && m_saved_cursor == m_list.end() )
365 std::iter_swap(prev_it, m_cursor);
366 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
367 m_listbox->entryChanged(m_cursor_number);
376 int eListboxServiceContent::cursorValid()
378 return m_cursor != m_list.end();
381 int eListboxServiceContent::cursorSet(int n)
388 int eListboxServiceContent::cursorGet()
390 return m_cursor_number;
393 void eListboxServiceContent::cursorSave()
395 m_saved_cursor = m_cursor;
396 m_saved_cursor_number = m_cursor_number;
399 void eListboxServiceContent::cursorRestore()
401 m_cursor = m_saved_cursor;
402 m_cursor_number = m_saved_cursor_number;
403 m_saved_cursor = m_list.end();
406 int eListboxServiceContent::size()
411 void eListboxServiceContent::setSize(const eSize &size)
414 setVisualMode(m_visual_mode);
417 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
419 painter.clip(eRect(offset, m_itemsize));
421 if (m_current_marked && selected)
422 style.setStyle(painter, eWindowStyle::styleListboxMarked);
423 else if (cursorValid() && isMarked(*m_cursor))
424 style.setStyle(painter, selected ? eWindowStyle::styleListboxMarkedAndSelected : eWindowStyle::styleListboxMarked);
426 style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
431 /* get service information */
432 ePtr<iStaticServiceInformation> service_info;
433 m_service_center->info(*m_cursor, service_info);
434 eServiceReference ref = *m_cursor;
436 (ref.flags & eServiceReference::flagDirectory) != eServiceReference::flagDirectory ||
437 (ref.flags & eServiceReference::isGroup);
439 if (checkPlayable && m_is_playable_ignore.valid() && service_info && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
440 painter.setForegroundColor(gRGB(0xbbbbbb));
442 int xoffset=0; // used as offset when painting the folder/marker symbol
444 for (int e = 0; e < celElements; ++e)
446 if (m_element_font[e])
448 int flags=gPainter::RT_VALIGN_CENTER,
451 eRect &area = m_element_position[e];
452 std::string text = "<n/a>";
457 case celServiceNumber:
459 if (m_cursor->flags & eServiceReference::isMarker)
462 /* how we can do this better? :) */
463 int markers_before=0;
465 list::iterator tmp=m_cursor;
466 while(tmp != m_list.begin())
469 if (tmp->flags & eServiceReference::isMarker)
473 sprintf(bla, "%d", m_numberoffset + m_cursor_number + 1 - markers_before);
475 flags|=gPainter::RT_HALIGN_RIGHT;
481 service_info->getName(*m_cursor, text);
486 ePtr<eServiceEvent> evt;
487 if ( !service_info->getEvent(*m_cursor, evt) )
489 std::string name = evt->getEventName();
492 text = '(' + evt->getEventName() + ')';
501 tmp.setWidth(tmp.width()-xoffs);
503 eTextPara *para = new eTextPara(tmp);
504 para->setFont(m_element_font[e]);
505 para->renderString(text.c_str());
507 if (e == celServiceName)
509 eRect bbox = para->getBoundBox();
510 int name_width = bbox.width()+8;
511 m_element_position[celServiceInfo].setLeft(area.left()+name_width);
512 m_element_position[celServiceInfo].setTop(area.top());
513 m_element_position[celServiceInfo].setWidth(area.width()-name_width);
514 m_element_position[celServiceInfo].setHeight(area.height());
517 if (flags & gPainter::RT_HALIGN_RIGHT)
518 para->realign(eTextPara::dirRight);
519 else if (flags & gPainter::RT_HALIGN_CENTER)
520 para->realign(eTextPara::dirCenter);
521 else if (flags & gPainter::RT_HALIGN_BLOCK)
522 para->realign(eTextPara::dirBlock);
524 if (flags & gPainter::RT_VALIGN_CENTER)
526 eRect bbox = para->getBoundBox();
527 int vcentered_top = (area.height() - bbox.height()) / 2;
528 yoffs = vcentered_top - bbox.top();
531 painter.renderPara(para, offset+ePoint(xoffs, yoffs));
533 else if (e == celServiceTypePixmap || e == celFolderPixmap || e == celMarkerPixmap)
535 int orbpos = m_cursor->getUnsignedData(4) >> 16;
536 ePtr<gPixmap> &pixmap =
537 (e == celFolderPixmap) ? m_pixmaps[picFolder] :
538 (e == celMarkerPixmap) ? m_pixmaps[picMarker] :
539 (orbpos == 0xFFFF) ? m_pixmaps[picDVB_C] :
540 (orbpos == 0xEEEE) ? m_pixmaps[picDVB_T] : m_pixmaps[picDVB_S];
543 eSize pixmap_size = pixmap->size();
544 int p = celServiceInfo;
545 if (e == celFolderPixmap)
547 else if (e == celMarkerPixmap)
548 p = celServiceNumber;
549 eRect area = m_element_position[p];
550 int correction = (area.height() - pixmap_size.height()) / 2;
552 if (m_cursor->flags & eServiceReference::flagDirectory)
554 if (e != celFolderPixmap)
556 xoffset = pixmap_size.width() + 8;
558 else if (m_cursor->flags & eServiceReference::isMarker)
560 if (e != celMarkerPixmap)
565 if (e != celServiceTypePixmap)
567 m_element_position[celServiceInfo] = area;
568 m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + 8);
569 m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - 8);
574 painter.blit(pixmap, offset+ePoint(area.left(), correction), area, gPainter::BT_ALPHATEST);
581 style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
587 void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
589 m_is_playable_ignore=service;