lib/dvb/sec.cpp: fixed typo (LOF/tuner frequency check was broken since latest unicab...
[enigma2.git] / lib / service / listboxservice.cpp
index f6d9e78bae92d026188a3e6ae2a0f44b7358f67a..cc8c32b50e64c6123fd4f58761f0f6eea059b9e9 100644 (file)
@@ -8,28 +8,43 @@
 void eListboxServiceContent::addService(const eServiceReference &service, bool beforeCurrent)
 {
        if (beforeCurrent && m_size)
 void eListboxServiceContent::addService(const eServiceReference &service, bool beforeCurrent)
 {
        if (beforeCurrent && m_size)
-       {
                m_list.insert(m_cursor, service);
                m_list.insert(m_cursor, service);
-               --m_cursor;
-       }
        else
                m_list.push_back(service);
        else
                m_list.push_back(service);
-       ++m_size;
+       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)
        {
-               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_size;
-               m_listbox->entryRemoved(m_cursor_number);
+                       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!");
@@ -195,16 +210,18 @@ int eListboxServiceContent::lookupService(const eServiceReference &ref)
 
 void eListboxServiceContent::setVisualMode(int mode)
 {
 
 void eListboxServiceContent::setVisualMode(int mode)
 {
+       for (int i=0; i < celElements; ++i)
+       {
+               m_element_position[i] = eRect();
+               m_element_font[i] = 0;
+       }
+
        m_visual_mode = mode;
        m_visual_mode = mode;
-       
+
        if (m_visual_mode == visModeSimple)
        {
                m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize);
                m_element_font[celServiceName] = new gFont("Regular", 23);
        if (m_visual_mode == visModeSimple)
        {
                m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize);
                m_element_font[celServiceName] = new gFont("Regular", 23);
-               m_element_position[celServiceNumber] = eRect();
-               m_element_font[celServiceNumber] = 0;
-               m_element_position[celServiceInfo] = eRect();
-               m_element_font[celServiceInfo] = 0;
        }
 }
 
        }
 }
 
@@ -243,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())
@@ -411,35 +438,114 @@ int eListboxServiceContent::size()
 void eListboxServiceContent::setSize(const eSize &size)
 {
        m_itemsize = size;
 void eListboxServiceContent::setSize(const eSize &size)
 {
        m_itemsize = size;
-       setVisualMode(m_visual_mode);
+       if (m_visual_mode == visModeSimple)
+               setVisualMode(m_visual_mode);
 }
 
 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
 {
        painter.clip(eRect(offset, m_itemsize));
 
 }
 
 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
 {
        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 */
                ePtr<iStaticServiceInformation> service_info;
                m_service_center->info(*m_cursor, service_info);
                eServiceReference ref = *m_cursor;
        if (cursorValid())
        {
                        /* get service information */
                ePtr<iStaticServiceInformation> service_info;
                m_service_center->info(*m_cursor, service_info);
                eServiceReference ref = *m_cursor;
-               bool checkPlayable =
-                       (ref.flags & eServiceReference::flagDirectory) != eServiceReference::flagDirectory ||
-                       (ref.flags & eServiceReference::isGroup);
+               bool isMarker = ref.flags & eServiceReference::isMarker;
+               bool isPlayable = !(ref.flags & eServiceReference::isDirectory || isMarker);
+               bool paintProgress = false;
+               ePtr<eServiceEvent> evt;
+
+               bool serviceAvail = true;
+
+               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));
+                       serviceAvail = false;
+               }
 
 
-               if (checkPlayable && m_is_playable_ignore.valid() && service_info && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
-                       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 or the serviceevent progress
 
                for (int e = 0; e < celElements; ++e)
                {
 
                for (int e = 0; e < celElements; ++e)
                {
@@ -483,13 +589,19 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                }
                                case celServiceInfo:
                                {
                                }
                                case celServiceInfo:
                                {
-                                       ePtr<eServiceEvent> evt;
-                                       if ( !service_info->getEvent(*m_cursor, evt) )
+                                       if ( isPlayable && !service_info->getEvent(*m_cursor, evt) )
                                        {
                                                std::string name = evt->getEventName();
                                                if (!name.length())
                                                        continue;
                                                text = '(' + evt->getEventName() + ')';
                                        {
                                                std::string name = evt->getEventName();
                                                if (!name.length())
                                                        continue;
                                                text = '(' + evt->getEventName() + ')';
+                                               if (serviceAvail)
+                                               {
+                                                       if (!selected && m_color_set[serviceDescriptionColor])
+                                                               painter.setForegroundColor(m_color[serviceDescriptionColor]);
+                                                       else if (selected && m_color_set[serviceDescriptionColorSelected])
+                                                               painter.setForegroundColor(m_color[serviceDescriptionColorSelected]);
+                                               }
                                        }
                                        else
                                                continue;
                                        }
                                        else
                                                continue;
@@ -508,9 +620,9 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                {
                                        eRect bbox = para->getBoundBox();
                                        int name_width = bbox.width()+8;
                                {
                                        eRect bbox = para->getBoundBox();
                                        int name_width = bbox.width()+8;
-                                       m_element_position[celServiceInfo].setLeft(area.left()+name_width);
+                                       m_element_position[celServiceInfo].setLeft(area.left()+name_width+xoffs);
                                        m_element_position[celServiceInfo].setTop(area.top());
                                        m_element_position[celServiceInfo].setTop(area.top());
-                                       m_element_position[celServiceInfo].setWidth(area.width()-name_width);
+                                       m_element_position[celServiceInfo].setWidth(area.width()-(name_width+xoffs));
                                        m_element_position[celServiceInfo].setHeight(area.height());
                                }
 
                                        m_element_position[celServiceInfo].setHeight(area.height());
                                }
 
@@ -536,6 +648,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)
@@ -549,7 +662,15 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                        eRect area = m_element_position[p];
                                        int correction = (area.height() - pixmap_size.height()) / 2;
 
                                        eRect area = m_element_position[p];
                                        int correction = (area.height() - pixmap_size.height()) / 2;
 
-                                       if (m_cursor->flags & eServiceReference::flagDirectory)
+                                       if (isPlayable)
+                                       {
+                                               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);
+                                       }
+                                       else if (m_cursor->flags & eServiceReference::isDirectory)
                                        {
                                                if (e != celFolderPixmap)
                                                        continue;
                                        {
                                                if (e != celFolderPixmap)
                                                        continue;
@@ -561,13 +682,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                                        continue;
                                        }
                                        else
                                                        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);
-                                       }
+                                               eFatal("unknown service type in listboxservice");
 
                                        area.moveBy(offset);
                                        painter.clip(area);
 
                                        area.moveBy(offset);
                                        painter.clip(area);
@@ -575,16 +690,75 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                        painter.clippop();
                                }
                        }
                                        painter.clippop();
                                }
                        }
+                       else if (e == celServiceEventProgressbar)
+                       {
+                               eRect area = m_element_position[celServiceEventProgressbar];
+                               if (area.width() > 0 && (isPlayable || isMarker))
+                               {
+                                       // we schedule it to paint it as last element.. so we dont need to reset fore/background color
+                                       paintProgress = isPlayable;
+                                       xoffset = area.width() + 10;
+                               }
+                       }
                }
                }
-               
-               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);
+               if (paintProgress && evt)
+               {
+                       eRect area = m_element_position[celServiceEventProgressbar];
+                       if (!selected && m_color_set[serviceEventProgressbarBorderColor])
+                               painter.setForegroundColor(m_color[serviceEventProgressbarBorderColor]);
+                       else if (selected && m_color_set[serviceEventProgressbarBorderColorSelected])
+                               painter.setForegroundColor(m_color[serviceEventProgressbarBorderColorSelected]);
+
+                       int border = 1;
+                       int progressH = 6;
+                       int progressX = area.left() + offset.x();
+                       int progressW = area.width() - 2 * border;
+                       int progressT = offset.y() + (m_itemsize.height() - progressH - 2*border) / 2;
+
+                       // paint progressbar frame
+                       painter.fill(eRect(progressX, progressT, area.width(), border));
+                       painter.fill(eRect(progressX, progressT + border, border, progressH));
+                       painter.fill(eRect(progressX, progressT + progressH + border, area.width(), border));
+                       painter.fill(eRect(progressX + area.width() - border, progressT + border, border, progressH));
+
+                       // calculate value
+                       time_t now = time(0);
+                       int value = progressW * (now - evt->getBeginTime()) / evt->getDuration();
+
+                       eRect tmp = eRect(progressX + border, progressT + border, value, progressH);
+                       ePtr<gPixmap> &pixmap = m_pixmaps[picServiceEventProgressbar];
+                       if (pixmap)
+                       {
+                               area.moveBy(offset);
+                               painter.clip(area);
+                               painter.blit(pixmap, ePoint(progressX + border, progressT + border), tmp, gPainter::BT_ALPHATEST);
+                               painter.clippop();
+                       }
+                       else
+                       {
+                               if (!selected && m_color_set[serviceEventProgressbarColor])
+                                       painter.setForegroundColor(m_color[serviceEventProgressbarColor]);
+                               else if (selected && m_color_set[serviceEventProgressbarColorSelected])
+                                       painter.setForegroundColor(m_color[serviceEventProgressbarColorSelected]);
+                               painter.fill(tmp);
+                       }
+               }
        }
        }
-       
        painter.clippop();
 }
 
 void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
 {
        m_is_playable_ignore=service;
        painter.clippop();
 }
 
 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);
 }
 }