add epgcache
[enigma2.git] / main / enigma.cpp
1 #define SDLDC
2 #include <stdio.h>
3 #include <libsig_comp.h>
4 #include <lib/base/ebase.h>
5 #include <lib/base/eerror.h>
6 #include <lib/base/init.h>
7 #include <lib/base/init_num.h>
8
9 #include <unistd.h>
10
11 #include <lib/gdi/grc.h>
12 #include <lib/gdi/gfbdc.h>
13 #include <lib/gdi/sdl.h>
14 #include <lib/gdi/font.h> 
15
16 #include <lib/gui/ewidget.h>
17 #include <lib/gui/ewidgetdesktop.h>
18 #include <lib/gui/elabel.h>
19 #include <lib/gui/ebutton.h>
20
21 #include <lib/gui/ewindow.h>
22
23 #include <lib/python/python.h>
24 #include <lib/python/connections.h>
25
26 #include <lib/gui/elistboxcontent.h>
27
28 #include <lib/driver/rc.h>
29
30 #include <lib/actions/action.h>
31
32 #include <lib/gdi/epng.h>
33
34 #ifdef OBJECT_DEBUG
35 int object_total_remaining;
36
37 void object_dump()
38 {
39         printf("%d items left\n", object_total_remaining);
40 }
41 #endif
42
43 void dumpRegion(const gRegion &region)
44 {
45         fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
46                 region.extends.left(), region.extends.top(),
47                 region.extends.right(), region.extends.bottom(), region.rects.size());
48         for (int y=0; y<region.extends.bottom(); ++y)
49         {
50                 for (int x=0; x<region.extends.right(); ++x)
51                 {
52                         unsigned char res = ' ';
53                         for (unsigned int i=0; i < region.rects.size(); ++i)
54                                 if (region.rects[i].contains(ePoint(x, y)))
55                                         res = '0' + i;
56                         fprintf(stderr, "%c", res);
57                 }
58                 fprintf(stderr, "\n");
59         }
60 }
61
62 eWidgetDesktop *wdsk;
63
64 // typedef struct _object PyObject;
65
66 void print(int i)
67 {
68         printf("C++ says: it's a %d!!!\n", i);
69 }
70
71 PSignal1<void,int> keyPressed;
72
73 PSignal1<void,int> &keyPressedSignal()
74 {
75         return keyPressed;
76 }
77
78 void keyEvent(const eRCKey &key)
79 {
80         ePtr<eActionMap> ptr;
81         eActionMap::getInstance(ptr);
82         ptr->keyPressed(0, key.code, key.flags);
83 //      if (!key.flags)
84 //              keyPressed(key.code);
85 }
86
87 /************************************************/
88 #include <unistd.h>
89 #include <lib/components/scan.h>
90 #include <lib/dvb/idvb.h>
91 #include <lib/dvb/dvb.h>
92 #include <lib/dvb/db.h>
93 #include <lib/dvb/dvbtime.h>
94 #include <lib/dvb/epgcache.h>
95
96 class eMain: public eApplication, public Object
97 {
98         eInit init;
99         
100         ePtr<eDVBResourceManager> m_mgr;
101         ePtr<eDVBDB> m_dvbdb;
102         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
103         ePtr<eComponentScan> m_scan;
104         ePtr<eEPGCache> m_epgcache;
105
106 public:
107         eMain()
108         {
109                 init.setRunlevel(eAutoInitNumbers::main);
110
111                                 /* TODO: put into init */
112                 m_dvbdb = new eDVBDB();
113                 m_mgr = new eDVBResourceManager();
114                 m_locale_time_handler = new eDVBLocalTimeHandler();
115                 m_epgcache = new eEPGCache();
116                 m_mgr->setChannelList(m_dvbdb);
117                 
118 //              m_scan = new eComponentScan();
119 //              m_scan->start();
120
121         }
122         
123         ~eMain()
124         {
125                 m_scan = 0;
126         }
127 };
128
129 /************************************************/
130
131
132 int main(int argc, char **argv)
133 {
134 #ifdef OBJECT_DEBUG
135         atexit(object_dump);
136 #endif
137
138
139         ePython python;
140         eMain main;
141
142 #if 1
143 #ifdef SDLDC
144         ePtr<gSDLDC> my_dc;
145         gSDLDC::getInstance(my_dc);
146 #else
147         ePtr<gFBDC> my_dc;
148         gFBDC::getInstance(my_dc);
149 #endif
150
151         fontRenderClass::getInstance()->AddFont("/home/tmbinc/enigma2/fonts/arial.ttf", "Arial", 100);
152
153         eWidgetDesktop dsk(eSize(720, 576));
154         
155         wdsk = &dsk;
156
157
158         dsk.setDC(my_dc);
159
160         ePtr<gPixmap> m_pm;
161         loadPNG(m_pm, "data/pal.png");
162         if (!m_pm)
163         {
164                 eFatal("hi ghost, please copy pal.png into your ./data, thanks!");
165         } else
166                 dsk.setPalette(*m_pm);
167
168         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
169 #endif
170
171                 /* redrawing is done in an idle-timer, so we have to set the context */
172         dsk.setRedrawTask(main);
173         
174         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
175         
176         printf("executing main\n");
177
178         python.execute("mytest", "__main__");
179
180 //      eApp->exec();
181
182         return 0;
183 }
184
185 eWidgetDesktop *getDesktop()
186 {
187         return wdsk;
188 }
189
190 void runMainloop()
191 {
192         eApp->exec();
193 }
194
195 void quitMainloop()
196 {
197         eApp->quit(0);
198 }