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;
53 void eListboxServiceContent::getCurrent(eServiceReference &ref)
58 ref = eServiceReference();
61 int eListboxServiceContent::getNextBeginningWithChar(char c)
63 // printf("Char: %c\n", c);
65 for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index)
68 ePtr<iStaticServiceInformation> service_info;
69 m_service_center->info(*i, service_info);
70 service_info->getName(*i, text);
71 // printf("%c\n", text.c_str()[0]);
73 int len=text.length();
76 char cc = text[idx++];
77 if ( cc >= 33 && cc < 127)
88 void eListboxServiceContent::initMarked()
93 void eListboxServiceContent::addMarked(const eServiceReference &ref)
97 m_listbox->entryChanged(lookupService(ref));
100 void eListboxServiceContent::removeMarked(const eServiceReference &ref)
104 m_listbox->entryChanged(lookupService(ref));
107 int eListboxServiceContent::isMarked(const eServiceReference &ref)
109 return m_marked.find(ref) != m_marked.end();
112 void eListboxServiceContent::markedQueryStart()
114 m_marked_iterator = m_marked.begin();
117 int eListboxServiceContent::markedQueryNext(eServiceReference &ref)
119 if (m_marked_iterator == m_marked.end())
121 ref = *m_marked_iterator++;
125 int eListboxServiceContent::lookupService(const eServiceReference &ref)
127 /* shortcut for cursor */
128 if (ref == *m_cursor)
129 return m_cursor_number;
130 /* otherwise, search in the list.. */
132 for (list::const_iterator i(m_list.begin()); i != m_list.end(); ++i, ++index);
134 /* this is ok even when the index was not found. */
138 void eListboxServiceContent::setVisualMode(int mode)
140 m_visual_mode = mode;
142 if (m_visual_mode == visModeSimple)
144 m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize);
145 m_element_font[celServiceName] = new gFont("Regular", 23);
146 m_element_position[celServiceNumber] = eRect();
147 m_element_font[celServiceNumber] = 0;
148 m_element_position[celIcon] = eRect();
149 m_element_position[celServiceInfo] = eRect();
150 m_element_font[celServiceInfo] = 0;
154 void eListboxServiceContent::setElementPosition(int element, eRect where)
156 if ((element >= 0) && (element < celElements))
157 m_element_position[element] = where;
160 void eListboxServiceContent::setElementFont(int element, gFont *font)
162 if ((element >= 0) && (element < celElements))
163 m_element_font[element] = font;
166 void eListboxServiceContent::sort()
168 ePtr<iListableService> lst;
169 if (!m_service_center->list(m_root, lst))
171 m_list.sort(iListableServiceCompare(lst));
172 /* FIXME: is this really required or can we somehow keep the current entry? */
175 m_listbox->entryReset();
179 DEFINE_REF(eListboxServiceContent);
181 eListboxServiceContent::eListboxServiceContent()
182 :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_numberoffset(0)
185 eServiceCenter::getInstance(m_service_center);
188 void eListboxServiceContent::cursorHome()
190 if (m_current_marked && m_saved_cursor == m_list.end())
192 while (m_cursor_number)
194 std::iter_swap(m_cursor--, m_cursor);
196 if (m_listbox && m_cursor_number)
197 m_listbox->entryChanged(m_cursor_number);
202 m_cursor = m_list.begin();
207 void eListboxServiceContent::cursorEnd()
209 if (m_current_marked && m_saved_cursor == m_list.end())
211 while (m_cursor != m_list.end())
213 list::iterator prev = m_cursor++;
215 if ( prev != m_list.end() && m_cursor != m_list.end() )
217 std::iter_swap(m_cursor, prev);
219 m_listbox->entryChanged(m_cursor_number);
225 m_cursor = m_list.end();
226 m_cursor_number = m_size;
230 int eListboxServiceContent::setCurrentMarked(bool state)
232 bool prev = m_current_marked;
233 m_current_marked = state;
235 if (state != prev && m_listbox)
237 m_listbox->entryChanged(m_cursor_number);
240 ePtr<iListableService> lst;
241 if (m_service_center->list(m_root, lst))
242 eDebug("no list available!");
245 ePtr<iMutableServiceList> list;
246 if (lst->startEdit(list))
247 eDebug("no editable list");
250 eServiceReference ref;
253 eDebug("no valid service selected");
256 int pos = cursorGet();
257 eDebugNoNewLine("move %s to %d ", ref.toString().c_str(), pos);
258 if (list->moveService(ref, cursorGet()))
271 int eListboxServiceContent::cursorMove(int count)
273 int prev = m_cursor_number, last = m_cursor_number + count;
276 while(count && m_cursor != m_list.end())
278 list::iterator prev_it = m_cursor++;
279 if ( m_current_marked && m_cursor != m_list.end() && m_saved_cursor == m_list.end() )
281 std::iter_swap(prev_it, m_cursor);
282 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
283 m_listbox->entryChanged(m_cursor_number);
288 } else if (count < 0)
290 while (count && m_cursor != m_list.begin())
292 list::iterator prev_it = m_cursor--;
293 if ( m_current_marked && m_cursor != m_list.end() && prev_it != m_list.end() && m_saved_cursor == m_list.end() )
295 std::iter_swap(prev_it, m_cursor);
296 if ( m_listbox && prev != m_cursor_number && last != m_cursor_number )
297 m_listbox->entryChanged(m_cursor_number);
306 int eListboxServiceContent::cursorValid()
308 return m_cursor != m_list.end();
311 int eListboxServiceContent::cursorSet(int n)
318 int eListboxServiceContent::cursorGet()
320 return m_cursor_number;
323 void eListboxServiceContent::cursorSave()
325 m_saved_cursor = m_cursor;
326 m_saved_cursor_number = m_cursor_number;
329 void eListboxServiceContent::cursorRestore()
331 m_cursor = m_saved_cursor;
332 m_cursor_number = m_saved_cursor_number;
333 m_saved_cursor = m_list.end();
336 int eListboxServiceContent::size()
341 void eListboxServiceContent::setSize(const eSize &size)
344 setVisualMode(m_visual_mode);
347 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
349 painter.clip(eRect(offset, m_itemsize));
351 if (m_current_marked && selected)
352 style.setStyle(painter, eWindowStyle::styleListboxMarked);
353 else if (cursorValid() && isMarked(*m_cursor))
354 style.setStyle(painter, eWindowStyle::styleListboxMarked);
356 style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
361 /* get service information */
362 ePtr<iStaticServiceInformation> service_info;
363 m_service_center->info(*m_cursor, service_info);
365 if (m_is_playable_ignore.valid() && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
366 painter.setForegroundColor(gRGB(0xbbbbbb));
368 for (int e = 0; e < celElements; ++e)
370 if (!m_element_font[e])
372 int flags=gPainter::RT_VALIGN_CENTER;
374 eRect area = m_element_position[e];
376 std::string text = "<n/a>";
381 // render icon here...
383 case celServiceNumber:
386 sprintf(bla, "%d", m_numberoffset + m_cursor_number + 1);
388 flags|=gPainter::RT_HALIGN_RIGHT;
394 service_info->getName(*m_cursor, text);
399 ePtr<eServiceEvent> evt;
400 if ( !service_info->getEvent(*m_cursor, evt) )
401 text = '(' + evt->getEventName() + ')';
408 eTextPara *para = new eTextPara(area);
410 para->setFont(m_element_font[e]);
411 para->renderString(text);
413 if (e == celServiceName)
415 eRect bbox = para->getBoundBox();
416 int name_width = bbox.width()+10;
417 m_element_position[celServiceInfo].setLeft(area.left()+name_width);
418 m_element_position[celServiceInfo].setTop(area.top());
419 m_element_position[celServiceInfo].setWidth(area.width()-name_width);
420 m_element_position[celServiceInfo].setHeight(area.height());
423 if (flags & gPainter::RT_HALIGN_RIGHT)
424 para->realign(eTextPara::dirRight);
425 else if (flags & gPainter::RT_HALIGN_CENTER)
426 para->realign(eTextPara::dirCenter);
427 else if (flags & gPainter::RT_HALIGN_BLOCK)
428 para->realign(eTextPara::dirBlock);
430 ePoint offs = offset;
432 if (flags & gPainter::RT_VALIGN_CENTER)
434 eRect bbox = para->getBoundBox();
435 int vcentered_top = (area.height() - bbox.height()) / 2;
436 int correction = vcentered_top - bbox.top();
437 offs += ePoint(0, correction);
440 painter.renderPara(para, offs);
444 style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
450 void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
452 m_is_playable_ignore=service;