fix for API < v3, thanks to pieter
[enigma2.git] / lib / service / listboxservice.cpp
index 866963fb352e90b5e0ec8a57c73e8a4a3d073454..32b9007f71c41675f4f22c68e214e58ffb518afb 100644 (file)
@@ -5,9 +5,32 @@
 #include <lib/dvb/pmt.h>
 #include <lib/python/connections.h>
 
-void eListboxServiceContent::addService(const eServiceReference &service)
+void eListboxServiceContent::addService(const eServiceReference &service, bool beforeCurrent)
 {
-       m_list.push_back(service);
+       if (beforeCurrent && m_size)
+       {
+               m_list.insert(m_cursor, service);
+               ++m_size;
+               --m_cursor;
+       }
+       else
+               m_list.push_back(service);
+}
+
+void eListboxServiceContent::removeCurrent()
+{
+       if (m_size && m_listbox)
+       {
+               if (m_cursor_number == m_size-1)
+               {
+                       m_list.erase(m_cursor--);
+                       --m_cursor_number;
+               }
+               else
+                       m_list.erase(m_cursor++);
+               --m_size;
+               m_listbox->entryRemoved(m_cursor_number);
+       }
 }
 
 void eListboxServiceContent::FillFinished()
@@ -87,6 +110,38 @@ int eListboxServiceContent::getNextBeginningWithChar(char c)
        return 0;
 }
 
+int eListboxServiceContent::getPrevMarkerPos()
+{
+       if (!m_listbox)
+               return 0;
+       list::iterator i(m_cursor);
+       int index = m_cursor_number;
+       while (index)
+       {
+               --i;
+               --index;
+               if (i->flags & eServiceReference::isMarker)
+                       break;
+       }
+       return index;
+}
+
+int eListboxServiceContent::getNextMarkerPos()
+{
+       if (!m_listbox)
+               return 0;
+       list::iterator i(m_cursor);
+       int index = m_cursor_number;
+       while (index < (m_size-1))
+       {
+               ++i;
+               ++index;
+               if (i->flags & eServiceReference::isMarker)
+                       break;
+       }
+       return index;
+}
+
 void eListboxServiceContent::initMarked()
 {
        m_marked.clear();
@@ -147,7 +202,6 @@ void eListboxServiceContent::setVisualMode(int mode)
                m_element_font[celServiceName] = new gFont("Regular", 23);
                m_element_position[celServiceNumber] = eRect();
                m_element_font[celServiceNumber] = 0;
-               m_element_position[celIcon] = eRect();
                m_element_position[celServiceInfo] = eRect();
                m_element_font[celServiceInfo] = 0;
        }
@@ -165,6 +219,12 @@ void eListboxServiceContent::setElementFont(int element, gFont *font)
                m_element_font[element] = font;
 }
 
+void eListboxServiceContent::setPixmap(int type, ePtr<gPixmap> &pic)
+{
+       if ((type >=0) && (type < picElements))
+               m_pixmaps[type] = pic;
+}
+
 void eListboxServiceContent::sort()
 {
        ePtr<iListableService> lst;
@@ -191,6 +251,11 @@ void eListboxServiceContent::cursorHome()
 {
        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);
@@ -353,7 +418,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
        if (m_current_marked && selected)
                style.setStyle(painter, eWindowStyle::styleListboxMarked);
        else if (cursorValid() && isMarked(*m_cursor))
-               style.setStyle(painter, eWindowStyle::styleListboxMarked);
+               style.setStyle(painter, selected ? eWindowStyle::styleListboxMarkedAndSelected : eWindowStyle::styleListboxMarked);
        else
                style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
        painter.clear();
@@ -364,82 +429,145 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                ePtr<iStaticServiceInformation> 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))
+               if (m_is_playable_ignore.valid() && service_info && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
                        painter.setForegroundColor(gRGB(0xbbbbbb));
 
+               int xoffset=0;  // used as offset when painting the folder/marker symbol
+
                for (int e = 0; e < celElements; ++e)
                {
-                       if (!m_element_font[e])
-                               continue;
-                       int flags=gPainter::RT_VALIGN_CENTER;
-
-                       eRect area = m_element_position[e];
-
-                       std::string text = "<n/a>";
-
-                       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 (m_element_font[e])
                        {
-                               if (service_info)
-                                       service_info->getName(*m_cursor, text);
-                               break;
-                       }
-                       case celServiceInfo:
-                       {
-                               ePtr<eServiceEvent> evt;
-                               if ( !service_info->getEvent(*m_cursor, evt) )
-                                       text = '(' + evt->getEventName() + ')';
-                               else
-                                       continue;
-                               break;
-                       }
-                       }
+                               int flags=gPainter::RT_VALIGN_CENTER,
+                                       yoffs = 0,
+                                       xoffs = xoffset;
+                               eRect &area = m_element_position[e];
+                               std::string text = "<n/a>";
+                               xoffset=0;
+
+                               switch (e)
+                               {
+                               case celServiceNumber:
+                               {
+                                       if (m_cursor->flags & eServiceReference::isMarker)
+                                               continue;
+                                       char bla[10];
+                               /* how we can do this better? :) */
+                                       int markers_before=0;
+                                       {
+                                               list::iterator tmp=m_cursor;
+                                               while(tmp != m_list.begin())
+                                               {
+                                                       --tmp;
+                                                       if (tmp->flags & eServiceReference::isMarker)
+                                                               ++markers_before;
+                                               }
+                                       }
+                                       sprintf(bla, "%d", m_numberoffset + m_cursor_number + 1 - markers_before);
+                                       text = bla;
+                                       flags|=gPainter::RT_HALIGN_RIGHT;
+                                       break;
+                               }
+                               case celServiceName:
+                               {
+                                       if (service_info)
+                                               service_info->getName(*m_cursor, text);
+                                       break;
+                               }
+                               case celServiceInfo:
+                               {
+                                       ePtr<eServiceEvent> evt;
+                                       if ( !service_info->getEvent(*m_cursor, evt) )
+                                       {
+                                               std::string name = evt->getEventName();
+                                               if (!name.length())
+                                                       continue;
+                                               text = '(' + evt->getEventName() + ')';
+                                       }
+                                       else
+                                               continue;
+                                       break;
+                               }
+                               }
 
-                       eTextPara *para = new eTextPara(area);
+                               eRect tmp = area;
+                               tmp.setWidth(tmp.width()-xoffs);
 
-                       para->setFont(m_element_font[e]);
-                       para->renderString(text);
+                               eTextPara *para = new eTextPara(tmp);
+                               para->setFont(m_element_font[e]);
+                               para->renderString(text.c_str());
 
-                       if (e == celServiceName)
-                       {
-                               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());
-                       }
+                               if (e == celServiceName)
+                               {
+                                       eRect bbox = para->getBoundBox();
+                                       int name_width = bbox.width()+8;
+                                       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());
+                               }
 
-                       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);
+                               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;
+                                       yoffs = vcentered_top - bbox.top();
+                               }
 
-                       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);
+                               painter.renderPara(para, offset+ePoint(xoffs, yoffs));
                        }
+                       else if (e == celServiceTypePixmap || e == celFolderPixmap || e == celMarkerPixmap)
+                       {
+                               int orbpos = m_cursor->getUnsignedData(4) >> 16;
+                               ePtr<gPixmap> &pixmap =
+                                       (e == celFolderPixmap) ? m_pixmaps[picFolder] :
+                                       (e == celMarkerPixmap) ? m_pixmaps[picMarker] :
+                                       (orbpos == 0xFFFF) ? m_pixmaps[picDVB_C] :
+                                       (orbpos == 0xEEEE) ? m_pixmaps[picDVB_T] : m_pixmaps[picDVB_S];
+                               if (pixmap)
+                               {
+                                       eSize pixmap_size = pixmap->size();
+                                       int p = celServiceInfo;
+                                       if (e == celFolderPixmap)
+                                               p = celServiceName;
+                                       else if (e == celMarkerPixmap)
+                                               p = celServiceNumber;
+                                       eRect area = m_element_position[p];
+                                       int correction = (area.height() - pixmap_size.height()) / 2;
+
+                                       if (m_cursor->flags & eServiceReference::flagDirectory)
+                                       {
+                                               if (e != celFolderPixmap)
+                                                       continue;
+                                               xoffset = pixmap_size.width() + 8;
+                                       }
+                                       else if (m_cursor->flags & eServiceReference::isMarker)
+                                       {
+                                               if (e != celMarkerPixmap)
+                                                       continue;
+                                       }
+                                       else
+                                       {
+                                               if (e != celServiceTypePixmap)
+                                                       continue;
+                                               m_element_position[celServiceInfo] = area;
+                                               m_element_position[celServiceInfo].setLeft(area.left() + pixmap_size.width() + 8);
+                                               m_element_position[celServiceInfo].setWidth(area.width() - pixmap_size.width() - 8);
+                                       }
 
-                       painter.renderPara(para, offs);
+                                       area.moveBy(offset);
+                                       painter.clip(area);
+                                       painter.blit(pixmap, offset+ePoint(area.left(), correction), area, gPainter::BT_ALPHATEST);
+                                       painter.clippop();
+                               }
+                       }
                }
                
                if (selected)