881047dfac137d7b420f3691ae60ef54b5b60d22
[vuplus_dvbapp] / lib / service / listboxservice.cpp
1 #include <lib/service/listboxservice.h>
2 #include <lib/service/service.h>
3
4 void eListboxServiceContent::setRoot(const eServiceReference &root)
5 {
6         m_root = root;
7         
8         assert(m_service_center);
9         
10         ePtr<iListableService> lst;
11         if (m_service_center->list(m_root, lst))
12                 eDebug("no list available!");
13         else
14                 if (lst->getContent(m_list))
15                         eDebug("getContent failed");
16
17         m_size = m_list.size();
18         cursorHome();
19 }
20
21 void eListboxServiceContent::getCurrent(eServiceReference &ref)
22 {
23         if (cursorValid())
24                 ref = *m_cursor;
25         else
26                 ref = eServiceReference();
27 }
28
29 DEFINE_REF(eListboxServiceContent);
30
31 eListboxServiceContent::eListboxServiceContent()
32 {
33         m_size = 0;
34         cursorHome();
35         eServiceCenter::getInstance(m_service_center);
36 }
37
38 void eListboxServiceContent::cursorHome()
39 {
40         m_cursor = m_list.begin();
41         m_cursor_number = 0;
42 }
43
44 void eListboxServiceContent::cursorEnd()
45 {
46         m_cursor = m_list.end();
47         m_cursor_number = m_size;
48 }
49
50 int eListboxServiceContent::cursorMove(int count)
51 {
52         if (count > 0)
53         {
54                 while (count && (m_cursor != m_list.end()))
55                 {
56                         ++m_cursor;
57                         ++m_cursor_number;
58                         --count;
59                 }
60         } else if (count < 0)
61         {
62                 while (count && (m_cursor != m_list.begin()))
63                 {
64                         --m_cursor;
65                         --m_cursor_number;
66                         ++count;
67                 }
68         }
69         
70         return 0;
71 }
72
73 int eListboxServiceContent::cursorValid()
74 {
75         return m_cursor != m_list.end();
76 }
77
78 int eListboxServiceContent::cursorSet(int n)
79 {
80         cursorHome();
81         cursorMove(n);
82         
83         return 0;
84 }
85
86 int eListboxServiceContent::cursorGet()
87 {
88         return m_cursor_number;
89 }
90
91 void eListboxServiceContent::cursorSave()
92 {
93         m_saved_cursor = m_cursor;
94         m_saved_cursor_number = m_cursor_number;
95 }
96
97 void eListboxServiceContent::cursorRestore()
98 {
99         m_cursor = m_saved_cursor;
100         m_cursor_number = m_saved_cursor_number;
101 }
102
103 int eListboxServiceContent::size()
104 {
105         return m_size;
106 }
107         
108 void eListboxServiceContent::setSize(const eSize &size)
109 {
110         m_itemsize = size;
111 }
112
113 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
114 {
115         ePtr<gFont> fnt = new gFont("Arial", 14);
116         painter.clip(eRect(offset, m_itemsize));
117         style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
118         painter.clear();
119         
120         if (cursorValid())
121         {
122                 painter.setFont(fnt);
123                 
124                 ePoint text_offset = offset + (selected ? ePoint(2, 2) : ePoint(1, 1));
125                 
126                         /* get name of service */
127                 ePtr<iStaticServiceInformation> service_info;
128                 m_service_center->info(*m_cursor, service_info);
129                 std::string name = "<n/a>";
130                 
131                 if (service_info)
132                         service_info->getName(*m_cursor, name);
133                 
134                 painter.renderText(eRect(text_offset, m_itemsize), name);
135                 
136                 if (selected)
137                         style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
138         }
139         
140         painter.clippop();
141 }
142