just show hdd info when there is one
[enigma2.git] / lib / components / listboxepg.cpp
1 #include <lib/components/listboxepg.h>
2 #include <lib/dvb/epgcache.h>
3 #include <lib/service/service.h>
4
5 void eListboxEPGContent::setRoot(const eServiceReference &root)
6 {
7         eEPGCache *epg=eEPGCache::getInstance();
8         if ( epg )
9         {
10                 m_list.clear();
11                 m_root = root;
12
13                 epg->Lock();
14                 if (!epg->startTimeQuery(root))
15                 {
16                         ePtr<eServiceEvent> ptr;
17                         while( !epg->getNextTimeEntry(ptr) )
18                                 m_list.push_back(ptr);
19                 }
20                 else
21                         eDebug("startTimeQuery failed %s", root.toString().c_str());
22                 epg->Unlock();
23
24                 m_size = m_list.size();
25                 cursorHome();
26
27                 if (m_listbox)
28                         m_listbox->entryReset();
29         }
30 }
31
32 RESULT eListboxEPGContent::getCurrent(ePtr<eServiceEvent> &evt)
33 {
34         if (cursorValid())
35         {
36                 evt = *m_cursor;
37                 return 0;
38         }
39         else
40                 evt = 0;
41         return -1;
42 }
43
44 void eListboxEPGContent::setElementPosition(int element, eRect where)
45 {
46         if ((element >= 0) && (element < celElements))
47                 m_element_position[element] = where;
48 }
49
50 void eListboxEPGContent::setElementFont(int element, gFont *font)
51 {
52         if ((element >= 0) && (element < celElements))
53                 m_element_font[element] = font;
54 }
55
56 void eListboxEPGContent::sort()
57 {
58 #if 0
59         ePtr<iListableService> lst;
60         if (!m_service_center->list(m_root, lst))
61         {
62                 m_list.sort(iListableServiceCompare(lst));
63                         /* FIXME: is this really required or can we somehow keep the current entry? */
64                 cursorHome();
65                 if (m_listbox)
66                         m_listbox->entryReset();
67         }
68 #endif
69 }
70
71 DEFINE_REF(eListboxEPGContent);
72
73 eListboxEPGContent::eListboxEPGContent()
74         :m_size(0)
75 {
76         cursorHome();
77 }
78
79 void eListboxEPGContent::cursorHome()
80 {
81         m_cursor = m_list.begin();
82         m_cursor_number = 0;
83 }
84
85 void eListboxEPGContent::cursorEnd()
86 {
87         m_cursor = m_list.end();
88         m_cursor_number = m_size;
89 }
90
91 int eListboxEPGContent::cursorMove(int count)
92 {
93         list::iterator old = m_cursor;
94
95         if (count > 0)
96         {
97                 while(count && (m_cursor != m_list.end()))
98                 {
99                         ++m_cursor;
100                         ++m_cursor_number;
101                         --count;
102                 }
103         } else if (count < 0)
104         {
105                 while (count && (m_cursor != m_list.begin()))
106                 {
107                         --m_cursor;
108                         --m_cursor_number;
109                         ++count;
110                 }
111         }
112
113         return 0;
114 }
115
116 int eListboxEPGContent::cursorValid()
117 {
118         return m_cursor != m_list.end();
119 }
120
121 int eListboxEPGContent::cursorSet(int n)
122 {
123         cursorHome();
124         cursorMove(n);
125
126         return 0;
127 }
128
129 int eListboxEPGContent::cursorGet()
130 {
131         return m_cursor_number;
132 }
133
134 void eListboxEPGContent::cursorSave()
135 {
136         m_saved_cursor = m_cursor;
137         m_saved_cursor_number = m_cursor_number;
138 }
139
140 void eListboxEPGContent::cursorRestore()
141 {
142         m_cursor = m_saved_cursor;
143         m_cursor_number = m_saved_cursor_number;
144         m_saved_cursor = m_list.end();
145 }
146
147 int eListboxEPGContent::size()
148 {
149         return m_size;
150 }
151
152 void eListboxEPGContent::setSize(const eSize &size)
153 {
154         m_itemsize = size;
155         eSize s = m_itemsize;
156         s.setWidth(size.width()/20*5);
157         m_element_position[celBeginTime] = eRect(ePoint(0, 0), s);
158         m_element_font[celBeginTime] = new gFont("Arial", 22);
159         s.setWidth(size.width()/20*15);
160         m_element_position[celTitle] = eRect(ePoint(size.width()/20*5, 0), s);
161         m_element_font[celTitle] = new gFont("Arial", 22);
162 }
163
164 void eListboxEPGContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
165 {
166         painter.clip(eRect(offset, m_itemsize));
167         style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
168         painter.clear();
169
170         if (cursorValid())
171         {
172                 for (int e = 0; e < celElements; ++e)
173                 {
174                         if (!m_element_font[e])
175                                 continue;
176
177                         painter.setFont(m_element_font[e]);
178
179                         std::string text = "<n/a>";
180
181                         switch (e)
182                         {
183                         case celBeginTime:
184                         {
185                                 text=(*m_cursor)->getBeginTimeString();
186                                 break;
187                         }
188                         case celTitle:
189                         {
190                                 text = (*m_cursor)->m_event_name;
191                                 break;
192                         }
193                         }
194                         
195                         eRect area = m_element_position[e];
196                         area.moveBy(offset.x(), offset.y());
197                         
198                         painter.renderText(area, text);
199                 }
200                 
201                 if (selected)
202                         style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
203         }
204         painter.clippop();
205 }
206