add 'weight' for menu entries (including plugins), so they can be sorted, patch by...
[enigma2.git] / lib / service / listboxservice.cpp
index c9f0aedee87b4bd82276bb5ebb3d6f4af0b01f10..b6d07f4467cabb37d0957e91d1c6f895aa45b243 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);
+               }
        }
 }
 
        }
 }
 
@@ -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,7 +260,7 @@ 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)
 {
        cursorHome();
        eServiceCenter::getInstance(m_service_center);
 {
        cursorHome();
        eServiceCenter::getInstance(m_service_center);
@@ -411,7 +428,8 @@ 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)
 }
 
 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
@@ -434,7 +452,7 @@ 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))
+               if (isPlayable && 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
                        painter.setForegroundColor(gRGB(0xbbbbbb));
 
                int xoffset=0;  // used as offset when painting the folder/marker symbol
@@ -482,7 +500,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                                case celServiceInfo:
                                {
                                        ePtr<eServiceEvent> evt;
                                case celServiceInfo:
                                {
                                        ePtr<eServiceEvent> evt;
-                                       if ( !service_info->getEvent(*m_cursor, evt) )
+                                       if ( service_info && !service_info->getEvent(*m_cursor, evt) )
                                        {
                                                std::string name = evt->getEventName();
                                                if (!name.length())
                                        {
                                                std::string name = evt->getEventName();
                                                if (!name.length())
@@ -534,6 +552,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)
@@ -588,3 +607,10 @@ void eListboxServiceContent::setIgnoreService( const eServiceReference &service
 {
        m_is_playable_ignore=service;
 }
 {
        m_is_playable_ignore=service;
 }
+
+int eListboxServiceContent::setItemHeight(int height)
+{
+       m_itemheight = height;
+       if (m_listbox)
+               m_listbox->setItemHeight(height);
+}