X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/1f5b1a20e4de369c197de1dae8fcb368e3e10b26..064515cf022f9ec6197c355b259960f5cb5d731e:/lib/service/listboxservice.cpp diff --git a/lib/service/listboxservice.cpp b/lib/service/listboxservice.cpp index 07838722..13538e99 100644 --- a/lib/service/listboxservice.cpp +++ b/lib/service/listboxservice.cpp @@ -1,11 +1,31 @@ #include #include +#include +#include +#include +#include -void eListboxServiceContent::setRoot(const eServiceReference &root) +void eListboxServiceContent::addService(const eServiceReference &service) +{ + m_list.push_back(service); +} + +void eListboxServiceContent::FillFinished() +{ + m_size = m_list.size(); + cursorHome(); + + if (m_listbox) + m_listbox->entryReset(); +} + +void eListboxServiceContent::setRoot(const eServiceReference &root, bool justSet) { m_list.clear(); m_root = root; - + + if (justSet) + return; assert(m_service_center); ePtr lst; @@ -15,11 +35,21 @@ void eListboxServiceContent::setRoot(const eServiceReference &root) if (lst->getContent(m_list)) eDebug("getContent failed"); - m_size = m_list.size(); - cursorHome(); - + FillFinished(); +} + +void eListboxServiceContent::setCurrent(const eServiceReference &ref) +{ + int index=0; + for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index) + if ( *i == ref ) + { + m_cursor = i; + m_cursor_number = index; + break; + } if (m_listbox) - m_listbox->entryReset(); + m_listbox->moveSelectionTo(index); } void eListboxServiceContent::getCurrent(eServiceReference &ref) @@ -30,6 +60,33 @@ void eListboxServiceContent::getCurrent(eServiceReference &ref) ref = eServiceReference(); } +int eListboxServiceContent::getNextBeginningWithChar(char c) +{ +// printf("Char: %c\n", c); + int index=0; + for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index) + { + std::string text; + ePtr service_info; + m_service_center->info(*i, service_info); + service_info->getName(*i, text); +// printf("%c\n", text.c_str()[0]); + int idx=0; + int len=text.length(); + while ( idx <= len ) + { + char cc = text[idx++]; + if ( cc >= 33 && cc < 127) + { + if (cc == c) + return index; + break; + } + } + } + return 0; +} + void eListboxServiceContent::initMarked() { m_marked.clear(); @@ -87,7 +144,7 @@ void eListboxServiceContent::setVisualMode(int mode) if (m_visual_mode == visModeSimple) { m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize); - m_element_font[celServiceName] = new gFont("Arial", 14); + m_element_font[celServiceName] = new gFont("Regular", 23); m_element_position[celServiceNumber] = eRect(); m_element_font[celServiceNumber] = 0; m_element_position[celIcon] = eRect(); @@ -108,48 +165,148 @@ void eListboxServiceContent::setElementFont(int element, gFont *font) m_element_font[element] = font; } +void eListboxServiceContent::sort() +{ + ePtr lst; + if (!m_service_center->list(m_root, lst)) + { + m_list.sort(iListableServiceCompare(lst)); + /* FIXME: is this really required or can we somehow keep the current entry? */ + cursorHome(); + if (m_listbox) + m_listbox->entryReset(); + } +} + DEFINE_REF(eListboxServiceContent); eListboxServiceContent::eListboxServiceContent() + :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_numberoffset(0) { - m_visual_mode = visModeSimple; - m_size = 0; cursorHome(); eServiceCenter::getInstance(m_service_center); } void eListboxServiceContent::cursorHome() { - m_cursor = m_list.begin(); - m_cursor_number = 0; + if (m_current_marked && m_saved_cursor == m_list.end()) + { + if (m_cursor_number >= m_size) + { + m_cursor_number = m_size-1; + --m_cursor; + } + while (m_cursor_number) + { + std::iter_swap(m_cursor--, m_cursor); + --m_cursor_number; + if (m_listbox && m_cursor_number) + m_listbox->entryChanged(m_cursor_number); + } + } + else + { + m_cursor = m_list.begin(); + m_cursor_number = 0; + } } void eListboxServiceContent::cursorEnd() { - m_cursor = m_list.end(); - m_cursor_number = m_size; + if (m_current_marked && m_saved_cursor == m_list.end()) + { + while (m_cursor != m_list.end()) + { + list::iterator prev = m_cursor++; + ++m_cursor_number; + if ( prev != m_list.end() && m_cursor != m_list.end() ) + { + std::iter_swap(m_cursor, prev); + if ( m_listbox ) + m_listbox->entryChanged(m_cursor_number); + } + } + } + else + { + m_cursor = m_list.end(); + m_cursor_number = m_size; + } +} + +int eListboxServiceContent::setCurrentMarked(bool state) +{ + bool prev = m_current_marked; + m_current_marked = state; + + if (state != prev && m_listbox) + { + m_listbox->entryChanged(m_cursor_number); + if (!state) + { + ePtr lst; + if (m_service_center->list(m_root, lst)) + eDebug("no list available!"); + else + { + ePtr list; + if (lst->startEdit(list)) + eDebug("no editable list"); + else + { + eServiceReference ref; + getCurrent(ref); + if(!ref) + eDebug("no valid service selected"); + else + { + int pos = cursorGet(); + eDebugNoNewLine("move %s to %d ", ref.toString().c_str(), pos); + if (list->moveService(ref, cursorGet())) + eDebug("failed"); + else + eDebug("ok"); + } + } + } + } + } + + return 0; } int eListboxServiceContent::cursorMove(int count) { + int prev = m_cursor_number, last = m_cursor_number + count; if (count > 0) { - while (count && (m_cursor != m_list.end())) + while(count && m_cursor != m_list.end()) { - ++m_cursor; + list::iterator prev_it = m_cursor++; + if ( m_current_marked && m_cursor != m_list.end() && m_saved_cursor == m_list.end() ) + { + std::iter_swap(prev_it, m_cursor); + if ( m_listbox && prev != m_cursor_number && last != m_cursor_number ) + m_listbox->entryChanged(m_cursor_number); + } ++m_cursor_number; --count; - } + } } else if (count < 0) { - while (count && (m_cursor != m_list.begin())) + while (count && m_cursor != m_list.begin()) { - --m_cursor; + list::iterator prev_it = m_cursor--; + if ( m_current_marked && m_cursor != m_list.end() && prev_it != m_list.end() && m_saved_cursor == m_list.end() ) + { + std::iter_swap(prev_it, m_cursor); + if ( m_listbox && prev != m_cursor_number && last != m_cursor_number ) + m_listbox->entryChanged(m_cursor_number); + } --m_cursor_number; ++count; } } - return 0; } @@ -162,7 +319,6 @@ int eListboxServiceContent::cursorSet(int n) { cursorHome(); cursorMove(n); - return 0; } @@ -181,6 +337,7 @@ void eListboxServiceContent::cursorRestore() { m_cursor = m_saved_cursor; m_cursor_number = m_saved_cursor_number; + m_saved_cursor = m_list.end(); } int eListboxServiceContent::size() @@ -197,7 +354,10 @@ void eListboxServiceContent::setSize(const eSize &size) void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected) { painter.clip(eRect(offset, m_itemsize)); - if (cursorValid() && isMarked(*m_cursor)) + + if (m_current_marked && selected) + style.setStyle(painter, eWindowStyle::styleListboxMarked); + else if (cursorValid() && isMarked(*m_cursor)) style.setStyle(painter, eWindowStyle::styleListboxMarked); else style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal); @@ -208,43 +368,83 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const /* get service information */ ePtr service_info; m_service_center->info(*m_cursor, service_info); - + + if (m_is_playable_ignore.valid() && !service_info->isPlayable(*m_cursor, m_is_playable_ignore)) + painter.setForegroundColor(gRGB(0xbbbbbb)); + for (int e = 0; e < celElements; ++e) { if (!m_element_font[e]) continue; - painter.setFont(m_element_font[e]); - + int flags=gPainter::RT_VALIGN_CENTER; + + eRect area = m_element_position[e]; + std::string text = ""; - + switch (e) { + case celIcon: + // render icon here... + continue; + case celServiceNumber: + { + char bla[10]; + sprintf(bla, "%d", m_numberoffset + m_cursor_number + 1); + text = bla; + flags|=gPainter::RT_HALIGN_RIGHT; + break; + } case celServiceName: { if (service_info) service_info->getName(*m_cursor, text); break; } - case celServiceNumber: + case celServiceInfo: { - char bla[10]; - sprintf(bla, "%d", m_cursor_number + 1); - text = bla; + ePtr evt; + if ( !service_info->getEvent(*m_cursor, evt) ) + text = '(' + evt->getEventName() + ')'; + else + continue; break; } - case celServiceInfo: + } + + eTextPara *para = new eTextPara(area); + + para->setFont(m_element_font[e]); + para->renderString(text); + + if (e == celServiceName) { - text = "now&next"; - break; + eRect bbox = para->getBoundBox(); + int name_width = bbox.width()+10; + m_element_position[celServiceInfo].setLeft(area.left()+name_width); + m_element_position[celServiceInfo].setTop(area.top()); + m_element_position[celServiceInfo].setWidth(area.width()-name_width); + m_element_position[celServiceInfo].setHeight(area.height()); } - case celIcon: - continue; + + if (flags & gPainter::RT_HALIGN_RIGHT) + para->realign(eTextPara::dirRight); + else if (flags & gPainter::RT_HALIGN_CENTER) + para->realign(eTextPara::dirCenter); + else if (flags & gPainter::RT_HALIGN_BLOCK) + para->realign(eTextPara::dirBlock); + + ePoint offs = offset; + + if (flags & gPainter::RT_VALIGN_CENTER) + { + eRect bbox = para->getBoundBox(); + int vcentered_top = (area.height() - bbox.height()) / 2; + int correction = vcentered_top - bbox.top(); + offs += ePoint(0, correction); } - - eRect area = m_element_position[e]; - area.moveBy(offset.x(), offset.y()); - - painter.renderText(area, text); + + painter.renderPara(para, offs); } if (selected) @@ -254,3 +454,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const painter.clippop(); } +void eListboxServiceContent::setIgnoreService( const eServiceReference &service ) +{ + m_is_playable_ignore=service; +}