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)
10 m_list.push_back(service);
13 void eListboxServiceContent::FillFinished()
15 m_size = m_list.size();
19 m_listbox->entryReset();
22 void eListboxServiceContent::setRoot(const eServiceReference &root, bool justSet)
29 assert(m_service_center);
31 ePtr<iListableService> lst;
32 if (m_service_center->list(m_root, lst))
33 eDebug("no list available!");
35 if (lst->getContent(m_list))
36 eDebug("getContent failed");
41 void eListboxServiceContent::setCurrent(const eServiceReference &ref)
44 for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
48 m_cursor_number = index;
52 m_listbox->moveSelectionTo(index);
55 void eListboxServiceContent::getCurrent(eServiceReference &ref)
60 ref = eServiceReference();
63 int eListboxServiceContent::getNextBeginningWithChar(char c)
65 // printf("Char: %c\n", c);
67 for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
70 ePtr<iStaticServiceInformation> service_info;
71 m_service_center->info(*i, service_info);
72 service_info->getName(*i, text);
73 // printf("%c\n", text.c_str()[0]);
75 int len=text.length();
78 char cc = text[idx++];
79 if ( cc >= 33 && cc < 127)
90 void eListboxServiceContent::initMarked()
95 void eListboxServiceContent::addMarked(const eServiceReference &ref)
99 m_listbox->entryChanged(lookupService(ref));
102 void eListboxServiceContent::removeMarked(const eServiceReference &ref)
106 m_listbox->entryChanged(lookupService(ref));
109 int eListboxServiceContent::isMarked(const eServiceReference &ref)
111 return m_marked.find(ref) != m_marked.end();
114 void eListboxServiceContent::markedQueryStart()
116 m_marked_iterator = m_marked.begin();
119 int eListboxServiceContent::markedQueryNext(eServiceReference &ref)
121 if (m_marked_iterator == m_marked.end())
123 ref = *m_marked_iterator++;
127 int eListboxServiceContent::lookupService(const eServiceReference &ref)
129 /* shortcut for cursor */
130 if (ref == *m_cursor)
131 return m_cursor_number;
132 /* otherwise, search in the list.. */
134 for (list::const_iterator i(m_list.begin()); i != m_list.end(); ++i, ++index);
136 /* this is ok even when the index was not found. */
140 void eListboxServiceContent::setVisualMode(int mode)
142 m_visual_mode = mode;
144 if (m_visual_mode == visModeSimple)
146 m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize);
147 m_element_font[celServiceName] = new gFont("Regular", 23);
148 m_element_position[celServiceNumber] = eRect();
149 m_element_font[celServiceNumber] = 0;
150 m_element_position[celIcon] = eRect();
151 m_element_position[celServiceInfo] = eRect();
152 m_element_font[celServiceInfo] = 0;
156 void eListboxServiceContent::setElementPosition(int element, eRect where)
158 if ((element >= 0) && (element < celElements))
159 m_element_position[element] = where;
162 void eListboxServiceContent::setElementFont(int element, gFont *font)
164 if ((element >= 0) && (element < celElements))
165 m_element_font[element] = font;
168 void eListboxServiceContent::sort()
170 ePtr<iListableService> lst;
171 if (!m_service_center->list(m_root, lst))
173 m_list.sort(iListableServiceCompare(lst));
174 /* FIXME: is this really required or can we somehow keep the current entry? */
177 m_listbox->entryReset();
181 DEFINE_REF(eListboxServiceContent);
183 eListboxServiceContent::eListboxServiceContent()
184 :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_numberoffset(0)
187 eServiceCenter::getInstance(m_service_center);
190 void eListboxServiceContent::cursorHome()
192 if (m_current_marked && m_saved_cursor == m_list.end())
194 if (m_cursor_number >= m_size)
196 m_cursor_number = m_size-1;
199 while (m_cursor_number)
201 std::iter_swap(m_cursor--, m_cursor);
203 if (m_listbox && m_cursor_number)
204 m_listbox->entryChanged(m_cursor_number);
209 m_cursor = m_list.begin();
214 void eListboxServiceContent::cursorEnd()
216 if (m_current_marked && m_saved_cursor == m_list.end())
218 while (m_cursor != m_list.end())
220 list::iterator prev = m_cursor++;
222 if ( prev != m_list.end() && m_cursor != m_list.end() )
224 std::iter_swap(m_cursor, prev);
226 m_listbox->entryChanged(m_cursor_number);
232 m_cursor = m_list.end();
233 m_cursor_number = m_size;
237 int eListboxServiceContent::setCurrentMarked(bool state)
239 bool prev = m_current_marked;
240 m_current_marked = state;
242 if (state != prev && m_listbox)
244 m_listbox->entryChanged(m_cursor_number);
247 ePtr<iListableService> lst;
248 if (m_service_center->list(m_root, lst))
249 eDebug("no list available!");
252 ePtr<iMutableServiceList> list;
253 if (lst->startEdit(list))
254 eDebug("no editable list");
257 eServiceReference ref;
260 eDebug("no valid service selected");
263 int pos = cursorGet();
264 eDebugNoNewLine("move %s to %d ", ref.toString().c_str(), pos);
265 if (list->moveService(ref, cursorGet()))
278 int eListboxServiceContent::cursorMove(int count)
280 int prev = m_cursor_number, last = m_cursor_number + count;
283 while(count && m_cursor != m_list.end())
285 list::iterator prev_it = m_cursor++;
286 if ( m_current_marked && m_cursor != m_list.end() && m_saved_cursor == m_list.end() )
288 std::iter_swap(prev_it, m_cursor);
289 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
290 m_listbox->entryChanged(m_cursor_number);
295 } else if (count < 0)
297 while (count && m_cursor != m_list.begin())
299 list::iterator prev_it = m_cursor--;
300 if ( m_current_marked && m_cursor != m_list.end() && prev_it != m_list.end() && m_saved_cursor == m_list.end() )
302 std::iter_swap(prev_it, m_cursor);
303 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
304 m_listbox->entryChanged(m_cursor_number);
313 int eListboxServiceContent::cursorValid()
315 return m_cursor != m_list.end();
318 int eListboxServiceContent::cursorSet(int n)
325 int eListboxServiceContent::cursorGet()
327 return m_cursor_number;
330 void eListboxServiceContent::cursorSave()
332 m_saved_cursor = m_cursor;
333 m_saved_cursor_number = m_cursor_number;
336 void eListboxServiceContent::cursorRestore()
338 m_cursor = m_saved_cursor;
339 m_cursor_number = m_saved_cursor_number;
340 m_saved_cursor = m_list.end();
343 int eListboxServiceContent::size()
348 void eListboxServiceContent::setSize(const eSize &size)
351 setVisualMode(m_visual_mode);
354 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
356 painter.clip(eRect(offset, m_itemsize));
358 if (m_current_marked && selected)
359 style.setStyle(painter, eWindowStyle::styleListboxMarked);
360 else if (cursorValid() && isMarked(*m_cursor))
361 style.setStyle(painter, selected ? eWindowStyle::styleListboxMarkedAndSelected : eWindowStyle::styleListboxMarked);
363 style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
368 /* get service information */
369 ePtr<iStaticServiceInformation> service_info;
370 m_service_center->info(*m_cursor, service_info);
372 if (m_is_playable_ignore.valid() && service_info && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
373 painter.setForegroundColor(gRGB(0xbbbbbb));
375 for (int e = 0; e < celElements; ++e)
377 if (!m_element_font[e])
379 int flags=gPainter::RT_VALIGN_CENTER;
381 eRect area = m_element_position[e];
383 std::string text = "<n/a>";
388 // render icon here...
390 case celServiceNumber:
393 sprintf(bla, "%d", m_numberoffset + m_cursor_number + 1);
395 flags|=gPainter::RT_HALIGN_RIGHT;
401 service_info->getName(*m_cursor, text);
406 ePtr<eServiceEvent> evt;
407 if ( !service_info->getEvent(*m_cursor, evt) )
408 text = '(' + evt->getEventName() + ')';
415 eTextPara *para = new eTextPara(area);
417 para->setFont(m_element_font[e]);
418 para->renderString(text);
420 if (e == celServiceName)
422 eRect bbox = para->getBoundBox();
423 int name_width = bbox.width()+10;
424 m_element_position[celServiceInfo].setLeft(area.left()+name_width);
425 m_element_position[celServiceInfo].setTop(area.top());
426 m_element_position[celServiceInfo].setWidth(area.width()-name_width);
427 m_element_position[celServiceInfo].setHeight(area.height());
430 if (flags & gPainter::RT_HALIGN_RIGHT)
431 para->realign(eTextPara::dirRight);
432 else if (flags & gPainter::RT_HALIGN_CENTER)
433 para->realign(eTextPara::dirCenter);
434 else if (flags & gPainter::RT_HALIGN_BLOCK)
435 para->realign(eTextPara::dirBlock);
437 ePoint offs = offset;
439 if (flags & gPainter::RT_VALIGN_CENTER)
441 eRect bbox = para->getBoundBox();
442 int vcentered_top = (area.height() - bbox.height()) / 2;
443 int correction = vcentered_top - bbox.top();
444 offs += ePoint(0, correction);
447 painter.renderPara(para, offs);
451 style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
457 void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
459 m_is_playable_ignore=service;