lib/python/Components/Ipkg.py: small fix for opkg
[enigma2.git] / lib / service / listboxservice.cpp
index d87e3155e0369709284a54402348ebf8185507e7..05aaf73148bbaed3857ddf005f112f406817c912 100644 (file)
@@ -11,25 +11,40 @@ void eListboxServiceContent::addService(const eServiceReference &service, bool b
                m_list.insert(m_cursor, service);
        else
                m_list.push_back(service);
                m_list.insert(m_cursor, service);
        else
                m_list.push_back(service);
-       ++m_size;
-       ++m_cursor_number;
-       if (m_listbox)
-               m_listbox->entryAdded(m_cursor_number-1);
+       if (m_size++)
+       {
+               ++m_cursor_number;
+               if (m_listbox)
+                       m_listbox->entryAdded(m_cursor_number-1);
+       }
+       else
+       {
+               m_cursor = m_list.begin();
+               m_cursor_number=0;
+               m_listbox->entryAdded(0);
+       }
 }
 
 void eListboxServiceContent::removeCurrent()
 {
        if (m_size && m_listbox)
        {
 }
 
 void eListboxServiceContent::removeCurrent()
 {
        if (m_size && m_listbox)
        {
-               --m_size;
-               if (m_cursor_number == m_size-1)
+               if (m_cursor_number == --m_size)
                {
                        m_list.erase(m_cursor--);
                {
                        m_list.erase(m_cursor--);
-                       --m_cursor_number;
+                       if (m_size)
+                       {
+                               --m_cursor_number;
+                               m_listbox->entryRemoved(m_cursor_number+1);
+                       }
+                       else
+                               m_listbox->entryRemoved(m_cursor_number);
                }
                else
                }
                else
+               {
                        m_list.erase(m_cursor++);
                        m_list.erase(m_cursor++);
-               m_listbox->entryRemoved(m_cursor_number+1);
+                       m_listbox->entryRemoved(m_cursor_number);
+               }
        }
 }
 
        }
 }
 
@@ -52,7 +67,7 @@ void eListboxServiceContent::setRoot(const eServiceReference &root, bool justSet
                m_lst=0;
                return;
        }
                m_lst=0;
                return;
        }
-       assert(m_service_center);
+       ASSERT(m_service_center);
        
        if (m_service_center->list(m_root, m_lst))
                eDebug("no list available!");
        
        if (m_service_center->list(m_root, m_lst))
                eDebug("no list available!");
@@ -245,12 +260,22 @@ void eListboxServiceContent::sort()
 DEFINE_REF(eListboxServiceContent);
 
 eListboxServiceContent::eListboxServiceContent()
 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), m_current_marked(false), m_numberoffset(0), m_itemheight(25)
 {
 {
+       memset(m_color_set, 0, sizeof(m_color_set));
        cursorHome();
        eServiceCenter::getInstance(m_service_center);
 }
 
        cursorHome();
        eServiceCenter::getInstance(m_service_center);
 }
 
+void eListboxServiceContent::setColor(int color, gRGB &col)
+{
+       if ((color >= 0) && (color < colorElements))
+       {
+               m_color_set[color] = true;
+               m_color[color] = col;
+       }
+}
+
 void eListboxServiceContent::cursorHome()
 {
        if (m_current_marked && m_saved_cursor == m_list.end())
 void eListboxServiceContent::cursorHome()
 {
        if (m_current_marked && m_saved_cursor == m_list.end())
@@ -421,14 +446,80 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
 {
        painter.clip(eRect(offset, m_itemsize));
 
 {
        painter.clip(eRect(offset, m_itemsize));
 
+       int marked = 0;
+
        if (m_current_marked && selected)
        if (m_current_marked && selected)
-               style.setStyle(painter, eWindowStyle::styleListboxMarked);
+               marked = 2;
        else if (cursorValid() && isMarked(*m_cursor))
        else if (cursorValid() && isMarked(*m_cursor))
-               style.setStyle(painter, selected ? eWindowStyle::styleListboxMarkedAndSelected : eWindowStyle::styleListboxMarked);
+       {
+               if (selected)
+                       marked = 2;
+               else
+                       marked = 1;
+       }
        else
                style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
        else
                style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
-       painter.clear();
-       
+
+       eListboxStyle *local_style = 0;
+
+               /* get local listbox style, if present */
+       if (m_listbox)
+               local_style = m_listbox->getLocalStyle();
+
+       if (marked == 1)  // marked
+       {
+               style.setStyle(painter, eWindowStyle::styleListboxMarked);
+               if (m_color_set[markedForeground])
+                       painter.setForegroundColor(m_color[markedForeground]);
+               if (m_color_set[markedBackground])
+                       painter.setBackgroundColor(m_color[markedBackground]);
+       }
+       else if (marked == 2) // marked and selected
+       {
+               style.setStyle(painter, eWindowStyle::styleListboxMarkedAndSelected);
+               if (m_color_set[markedForegroundSelected])
+                       painter.setForegroundColor(m_color[markedForegroundSelected]);
+               if (m_color_set[markedBackgroundSelected])
+                       painter.setBackgroundColor(m_color[markedBackgroundSelected]);
+       }
+       else if (local_style)
+       {
+               if (selected)
+               {
+                       /* if we have a local background color set, use that. */
+                       if (local_style->m_background_color_selected_set)
+                               painter.setBackgroundColor(local_style->m_background_color_selected);
+                       /* same for foreground */
+                       if (local_style->m_foreground_color_selected_set)
+                               painter.setForegroundColor(local_style->m_foreground_color_selected);
+               }
+               else
+               {
+                       /* if we have a local background color set, use that. */
+                       if (local_style->m_background_color_set)
+                               painter.setBackgroundColor(local_style->m_background_color);
+                       /* same for foreground */
+                       if (local_style->m_foreground_color_set)
+                               painter.setForegroundColor(local_style->m_foreground_color);
+               }
+       }
+
+       if (!local_style || !local_style->m_transparent_background)
+               /* if we have no transparent background */
+       {
+               /* blit background picture, if available (otherwise, clear only) */
+               if (local_style && local_style->m_background)
+                       painter.blit(local_style->m_background, offset, eRect(), 0);
+               else
+                       painter.clear();
+       } else
+       {
+               if (local_style->m_background)
+                       painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHATEST);
+               else if (selected && !local_style->m_selection)
+                       painter.clear();
+       }
+
        if (cursorValid())
        {
                        /* get service information */
        if (cursorValid())
        {
                        /* get service information */
@@ -437,8 +528,16 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                eServiceReference ref = *m_cursor;
                bool isPlayable = !(ref.flags & eServiceReference::isDirectory || ref.flags & eServiceReference::isMarker);
 
                eServiceReference ref = *m_cursor;
                bool isPlayable = !(ref.flags & eServiceReference::isDirectory || ref.flags & eServiceReference::isMarker);
 
-               if (isPlayable && m_is_playable_ignore.valid() && service_info && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
-                       painter.setForegroundColor(gRGB(0xbbbbbb));
+               if (!marked && isPlayable && service_info && m_is_playable_ignore.valid() && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
+               {
+                       if (m_color_set[serviceNotAvail])
+                               painter.setForegroundColor(m_color[serviceNotAvail]);
+                       else
+                               painter.setForegroundColor(gRGB(0xbbbbbb));
+               }
+
+               if (selected && local_style && local_style->m_selection)
+                       painter.blit(local_style->m_selection, offset, eRect(), gPainter::BT_ALPHATEST);
 
                int xoffset=0;  // used as offset when painting the folder/marker symbol
 
 
                int xoffset=0;  // used as offset when painting the folder/marker symbol
 
@@ -485,7 +584,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                case celServiceInfo:
                                {
                                        ePtr<eServiceEvent> evt;
                                case celServiceInfo:
                                {
                                        ePtr<eServiceEvent> evt;
-                                       if ( service_info && !service_info->getEvent(*m_cursor, evt) )
+                                       if ( isPlayable && service_info && !service_info->getEvent(*m_cursor, evt) )
                                        {
                                                std::string name = evt->getEventName();
                                                if (!name.length())
                                        {
                                                std::string name = evt->getEventName();
                                                if (!name.length())
@@ -537,6 +636,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                ePtr<gPixmap> &pixmap =
                                        (e == celFolderPixmap) ? m_pixmaps[picFolder] :
                                        (e == celMarkerPixmap) ? m_pixmaps[picMarker] :
                                ePtr<gPixmap> &pixmap =
                                        (e == celFolderPixmap) ? m_pixmaps[picFolder] :
                                        (e == celMarkerPixmap) ? m_pixmaps[picMarker] :
+                                       (m_cursor->flags & eServiceReference::isGroup) ? m_pixmaps[picServiceGroup] :
                                        (orbpos == 0xFFFF) ? m_pixmaps[picDVB_C] :
                                        (orbpos == 0xEEEE) ? m_pixmaps[picDVB_T] : m_pixmaps[picDVB_S];
                                if (pixmap)
                                        (orbpos == 0xFFFF) ? m_pixmaps[picDVB_C] :
                                        (orbpos == 0xEEEE) ? m_pixmaps[picDVB_T] : m_pixmaps[picDVB_S];
                                if (pixmap)
@@ -580,7 +680,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                        }
                }
                
                        }
                }
                
-               if (selected)
+               if (selected && (!local_style || !local_style->m_selection))
                        style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
        }
        
                        style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
        }
        
@@ -590,4 +690,13 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
 void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
 {
        m_is_playable_ignore=service;
 void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
 {
        m_is_playable_ignore=service;
+       if (m_listbox && m_listbox->isVisible())
+               m_listbox->invalidate();
+}
+
+void eListboxServiceContent::setItemHeight(int height)
+{
+       m_itemheight = height;
+       if (m_listbox)
+               m_listbox->setItemHeight(height);
 }
 }