fix wrap around with enabled movemode
[enigma2.git] / lib / service / listboxservice.cpp
index 9eafc85..13538e9 100644 (file)
@@ -2,12 +2,30 @@
 #include <lib/service/service.h>
 #include <lib/gdi/font.h>
 #include <lib/dvb/epgcache.h>
+#include <lib/dvb/pmt.h>
+#include <lib/python/connections.h>
 
-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<iListableService> lst;
@@ -17,11 +35,7 @@ void eListboxServiceContent::setRoot(const eServiceReference &root)
                if (lst->getContent(m_list))
                        eDebug("getContent failed");
 
-       m_size = m_list.size();
-       cursorHome();
-       
-       if (m_listbox)
-               m_listbox->entryReset();
+       FillFinished();
 }
 
 void eListboxServiceContent::setCurrent(const eServiceReference &ref)
@@ -34,6 +48,8 @@ void eListboxServiceContent::setCurrent(const eServiceReference &ref)
                        m_cursor_number = index;
                        break;
                }
+       if (m_listbox)
+               m_listbox->moveSelectionTo(index);
 }
 
 void eListboxServiceContent::getCurrent(eServiceReference &ref)
@@ -44,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<iStaticServiceInformation> 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();
@@ -101,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", 23);
+               m_element_font[celServiceName] = new gFont("Regular", 23);
                m_element_position[celServiceNumber] = eRect();
                m_element_font[celServiceNumber] = 0;
                m_element_position[celIcon] = eRect();
@@ -125,8 +168,8 @@ void eListboxServiceContent::setElementFont(int element, gFont *font)
 void eListboxServiceContent::sort()
 {
        ePtr<iListableService> lst;
-  if (!m_service_center->list(m_root, 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();
@@ -138,7 +181,7 @@ void eListboxServiceContent::sort()
 DEFINE_REF(eListboxServiceContent);
 
 eListboxServiceContent::eListboxServiceContent()
-       :epgcache(eEPGCache::getInstance()), 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)
 {
        cursorHome();
        eServiceCenter::getInstance(m_service_center);
@@ -148,6 +191,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);
@@ -271,7 +319,6 @@ int eListboxServiceContent::cursorSet(int n)
 {
        cursorHome();
        cursorMove(n);
-       
        return 0;
 }
 
@@ -321,7 +368,10 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                        /* get service information */
                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))
+                       painter.setForegroundColor(gRGB(0xbbbbbb));
+
                for (int e = 0; e < celElements; ++e)
                {
                        if (!m_element_font[e])
@@ -354,8 +404,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                        case celServiceInfo:
                        {
                                ePtr<eServiceEvent> evt;
-                               time_t t=-1;
-                               if ( !epgcache->lookupEventTime(*m_cursor, t, evt) )
+                               if ( !service_info->getEvent(*m_cursor, evt) )
                                        text = '(' + evt->getEventName() + ')';
                                else
                                        continue;
@@ -405,3 +454,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
        painter.clippop();
 }
 
+void eListboxServiceContent::setIgnoreService( const eServiceReference &service )
+{
+       m_is_playable_ignore=service;
+}