add c++ stuff for epglist
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 10 Nov 2005 15:20:18 +0000 (15:20 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 10 Nov 2005 15:20:18 +0000 (15:20 +0000)
lib/components/Makefile.am
lib/components/listboxepg.cpp [new file with mode: 0644]
lib/components/listboxepg.h [new file with mode: 0644]

index d40a166..c25791a 100644 (file)
@@ -3,5 +3,5 @@ INCLUDES = \
 
 noinst_LIBRARIES = libenigma_components.a
 
-libenigma_components_a_SOURCES = scan.cpp
+libenigma_components_a_SOURCES = scan.cpp listboxepg.cpp
        
\ No newline at end of file
diff --git a/lib/components/listboxepg.cpp b/lib/components/listboxepg.cpp
new file mode 100644 (file)
index 0000000..a8edd28
--- /dev/null
@@ -0,0 +1,203 @@
+#include <lib/components/listboxepg.h>
+#include <lib/dvb/epgcache.h>
+#include <lib/service/service.h>
+
+void eListboxEPGContent::setRoot(const eServiceReference &root)
+{
+       eEPGCache *epg=NULL;
+       if ( !eEPGCache::getInstance(epg) )
+       {
+               m_list.clear();
+               m_root = root;
+
+               epg->Lock();
+               epg->startTimeQuery(root);
+               ePtr<eServiceEvent> ptr;
+               while( !epg->getNextTimeEntry(ptr) )
+                       m_list.push_back(ptr);
+
+               m_size = m_list.size();
+               cursorHome();
+
+               if (m_listbox)
+                       m_listbox->entryReset();
+       }
+}
+
+void eListboxEPGContent::getCurrent(ePtr<eServiceEvent>& evt)
+{
+       if (cursorValid())
+               evt = *m_cursor;
+       else
+               evt = 0;
+}
+
+void eListboxEPGContent::setElementPosition(int element, eRect where)
+{
+       if ((element >= 0) && (element < celElements))
+               m_element_position[element] = where;
+}
+
+void eListboxEPGContent::setElementFont(int element, gFont *font)
+{
+       if ((element >= 0) && (element < celElements))
+               m_element_font[element] = font;
+}
+
+void eListboxEPGContent::sort()
+{
+#if 0
+       ePtr<iListableService> 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();
+               if (m_listbox)
+                       m_listbox->entryReset();
+       }
+#endif
+}
+
+DEFINE_REF(eListboxEPGContent);
+
+eListboxEPGContent::eListboxEPGContent()
+       :m_size(0)
+{
+       cursorHome();
+}
+
+void eListboxEPGContent::cursorHome()
+{
+       m_cursor = m_list.begin();
+       m_cursor_number = 0;
+}
+
+void eListboxEPGContent::cursorEnd()
+{
+       m_cursor = m_list.end();
+       m_cursor_number = m_size;
+}
+
+int eListboxEPGContent::cursorMove(int count)
+{
+       list::iterator old = m_cursor;
+
+       if (count > 0)
+       {
+               while(count && (m_cursor != m_list.end()))
+               {
+                       ++m_cursor;
+                       ++m_cursor_number;
+                       --count;
+               }
+       } else if (count < 0)
+       {
+               while (count && (m_cursor != m_list.begin()))
+               {
+                       --m_cursor;
+                       --m_cursor_number;
+                       ++count;
+               }
+       }
+
+       return 0;
+}
+
+int eListboxEPGContent::cursorValid()
+{
+       return m_cursor != m_list.end();
+}
+
+int eListboxEPGContent::cursorSet(int n)
+{
+       cursorHome();
+       cursorMove(n);
+
+       return 0;
+}
+
+int eListboxEPGContent::cursorGet()
+{
+       return m_cursor_number;
+}
+
+void eListboxEPGContent::cursorSave()
+{
+       m_saved_cursor = m_cursor;
+       m_saved_cursor_number = m_cursor_number;
+}
+
+void eListboxEPGContent::cursorRestore()
+{
+       m_cursor = m_saved_cursor;
+       m_cursor_number = m_saved_cursor_number;
+       m_saved_cursor = m_list.end();
+}
+
+int eListboxEPGContent::size()
+{
+       return m_size;
+}
+
+void eListboxEPGContent::setSize(const eSize &size)
+{
+       m_itemsize = size;
+       eSize s = m_itemsize;
+       s.setWidth((size.width()/4)-10);
+       m_element_position[celBeginTime] = eRect(ePoint(0, 0), s);
+       m_element_font[celBeginTime] = new gFont("Arial", 14);
+       s.setWidth(size.width()/4*3);
+       m_element_position[celTitle] = eRect(ePoint(size.width()/4, 0), s);
+       m_element_font[celTitle] = new gFont("Arial", 14);
+}
+
+void eListboxEPGContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
+{
+       painter.clip(eRect(offset, m_itemsize));
+       style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
+       painter.clear();
+
+       if (cursorValid())
+       {
+               for (int e = 0; e < celElements; ++e)
+               {
+                       if (!m_element_font[e])
+                               continue;
+
+                       painter.setFont(m_element_font[e]);
+
+                       std::string text = "<n/a>";
+
+                       switch (e)
+                       {
+                       case celBeginTime:
+                       {
+                               tm t;
+                               localtime_r(&(*m_cursor)->m_begin, &t);
+                               char tmp[13];
+                               snprintf(tmp, 13, "%02d.%02d, %02d:%02d",
+                                       t.tm_mday, t.tm_mon+1,
+                                       t.tm_hour, t.tm_min);
+                               text=tmp;
+                               break;
+                       }
+                       case celTitle:
+                       {
+                               text = (*m_cursor)->m_event_name;
+                               break;
+                       }
+                       }
+                       
+                       eRect area = m_element_position[e];
+                       area.moveBy(offset.x(), offset.y());
+                       
+                       painter.renderText(area, text);
+               }
+               
+               if (selected)
+                       style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
+       }
+       painter.clippop();
+}
+
diff --git a/lib/components/listboxepg.h b/lib/components/listboxepg.h
new file mode 100644 (file)
index 0000000..abbdc48
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef __lib_components_listboxepg_h
+#define __lib_components_listboxepg_h
+
+#include <lib/gui/elistbox.h>
+#include <lib/service/iservice.h>
+
+#include <set>
+
+class eListboxEPGContent: public virtual iListboxContent
+{
+       DECLARE_REF(eListboxEPGContent);
+public:
+       eListboxEPGContent();
+       void setRoot(const eServiceReference &ref);
+       void getCurrent(ePtr<eServiceEvent>&);
+
+               /* only in complex mode: */
+       enum {
+               celBeginTime,
+               celTitle,
+               celElements
+       };
+
+       void setElementPosition(int element, eRect where);
+       void setElementFont(int element, gFont *font);
+
+       void sort();
+
+protected:
+       void cursorHome();
+       void cursorEnd();
+       int cursorMove(int count=1);
+       int cursorValid();
+       int cursorSet(int n);
+       int cursorGet();
+
+       void cursorSave();
+       void cursorRestore();
+       int size();
+       
+       // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though
+       void setSize(const eSize &size);
+
+               /* the following functions always refer to the selected item */
+       void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected);
+
+       eRect m_element_position[celElements];
+       ePtr<gFont> m_element_font[celElements];
+private:
+       typedef std::list<ePtr<eServiceEvent> > list;
+
+       list m_list;
+       list::iterator m_cursor, m_saved_cursor;
+
+       int m_cursor_number, m_saved_cursor_number;
+       int m_size;
+
+       eSize m_itemsize;
+
+       eServiceReference m_root;
+};
+
+#endif