add ability to access eDVBLocalTimeHandler from python
[enigma2.git] / main / enigma.cpp
1 #undef WITH_SDL
2
3 #ifdef WITH_SDL
4 #error
5 #define SDLDC
6 #endif
7
8 #include <stdio.h>
9 #include <libsig_comp.h>
10 #include <lib/base/ebase.h>
11 #include <lib/base/eerror.h>
12 #include <lib/base/init.h>
13 #include <lib/base/init_num.h>
14
15 #include <unistd.h>
16
17 #include <lib/gdi/grc.h>
18 #include <lib/gdi/gfbdc.h>
19 #include <lib/gdi/glcddc.h>
20
21 #ifdef WITH_SDL
22 #error
23 #include <lib/gdi/sdl.h>
24 #endif
25 #include <lib/gdi/font.h> 
26
27 #include <lib/gui/ewidget.h>
28 #include <lib/gui/ewidgetdesktop.h>
29 #include <lib/gui/elabel.h>
30 #include <lib/gui/ebutton.h>
31
32 #include <lib/gui/ewindow.h>
33
34 #include <lib/python/python.h>
35 #include <lib/python/connections.h>
36
37 #include <lib/gui/elistboxcontent.h>
38
39 #include <lib/driver/rc.h>
40
41 #include <lib/actions/action.h>
42
43 #include <lib/gdi/epng.h>
44
45 #ifdef OBJECT_DEBUG
46 int object_total_remaining;
47
48 void object_dump()
49 {
50         printf("%d items left\n", object_total_remaining);
51 }
52 #endif
53
54 void dumpRegion(const gRegion &region)
55 {
56         fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
57                 region.extends.left(), region.extends.top(),
58                 region.extends.right(), region.extends.bottom(), region.rects.size());
59 #if 0
60         for (int y=0; y<region.extends.bottom(); ++y)
61         {
62                 for (int x=0; x<region.extends.right(); ++x)
63                 {
64                         unsigned char res = ' ';
65                         for (unsigned int i=0; i < region.rects.size(); ++i)
66                                 if (region.rects[i].contains(ePoint(x, y)))
67                                         res = '0' + i;
68                         fprintf(stderr, "%c", res);
69                 }
70                 fprintf(stderr, "\n");
71         }
72 #endif
73
74 }
75
76 eWidgetDesktop *wdsk, *lcddsk;
77
78 // typedef struct _object PyObject;
79
80 void print(int i)
81 {
82         printf("C++ says: it's a %d!!!\n", i);
83 }
84
85 PSignal1<void,int> keyPressed;
86
87 PSignal1<void,int> &keyPressedSignal()
88 {
89         return keyPressed;
90 }
91
92 void keyEvent(const eRCKey &key)
93 {
94         ePtr<eActionMap> ptr;
95         eActionMap::getInstance(ptr);
96         ptr->keyPressed(0, key.code, key.flags);
97 //      if (!key.flags)
98 //              keyPressed(key.code);
99 }
100
101 /************************************************/
102 #include <unistd.h>
103 #include <lib/components/scan.h>
104 #include <lib/dvb/idvb.h>
105 #include <lib/dvb/dvb.h>
106 #include <lib/dvb/db.h>
107 #include <lib/dvb/dvbtime.h>
108 #include <lib/dvb/epgcache.h>
109
110 class eMain: public eApplication, public Object
111 {
112         eInit init;
113         
114         ePtr<eDVBResourceManager> m_mgr;
115         ePtr<eDVBDB> m_dvbdb;
116         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
117         ePtr<eComponentScan> m_scan;
118         ePtr<eEPGCache> m_epgcache;
119
120 public:
121         eMain()
122         {
123                 init.setRunlevel(eAutoInitNumbers::main);
124
125                                 /* TODO: put into init */
126                 m_dvbdb = new eDVBDB();
127                 m_mgr = new eDVBResourceManager();
128                 m_locale_time_handler = new eDVBLocalTimeHandler();
129                 m_epgcache = new eEPGCache();
130                 m_mgr->setChannelList(m_dvbdb);
131                 
132 //              m_scan = new eComponentScan();
133 //              m_scan->start();
134
135         }
136         
137         ~eMain()
138         {
139                 m_dvbdb->save();
140                 m_scan = 0;
141         }
142 };
143
144 /************************************************/
145
146 eLabel *lcd_label, *lcd_clock;
147
148 int exit_code;
149
150 int main(int argc, char **argv)
151 {
152 #ifdef OBJECT_DEBUG
153         atexit(object_dump);
154 #endif
155
156         // set pythonpath if unset
157         setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
158         printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
159
160
161         ePython python;
162         eMain main;
163         
164         int double_buffer = 0;
165
166 #if 1
167 #ifdef SDLDC
168         ePtr<gSDLDC> my_dc;
169         gSDLDC::getInstance(my_dc);
170 #else
171         ePtr<gFBDC> my_dc;
172         gFBDC::getInstance(my_dc);
173         
174         double_buffer = my_dc->haveDoubleBuffering();
175 #endif
176
177         ePtr<gLCDDC> my_lcd_dc;
178         gLCDDC::getInstance(my_lcd_dc);
179
180         fontRenderClass::getInstance()->AddFont(FONTDIR "/md_khmurabi_10.ttf", "Regular", 100);
181
182         eWidgetDesktop dsk(eSize(720, 576));
183         eWidgetDesktop dsk_lcd(eSize(132, 64));
184         
185 /*      if (double_buffer)
186         {
187                 eDebug(" - double buffering found, enable buffered graphics mode.");
188                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
189         } */
190         
191         wdsk = &dsk;
192         lcddsk = &dsk_lcd;
193
194         dsk.setDC(my_dc);
195         dsk_lcd.setDC(my_lcd_dc);
196
197         ePtr<gPixmap> m_pm;
198         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
199         if (!m_pm)
200         {
201                 eFatal("pal.png not found!");
202         } else
203                 dsk.setPalette(*m_pm);
204
205         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
206 #endif
207
208                 /* redrawing is done in an idle-timer, so we have to set the context */
209         dsk.setRedrawTask(main);
210         dsk_lcd.setRedrawTask(main);
211
212         eWindow *lcd_win = new eWindow(&dsk_lcd);
213         
214         lcd_win->setFlag(eWindow::wfNoBorder);
215         
216         lcd_win->move(ePoint(0, 0));
217         lcd_win->resize(eSize(132, 64));
218         
219         lcd_label = new eLabel(lcd_win);
220         lcd_label->move(ePoint(0, 4));
221         lcd_label->resize(eSize(132, 42));
222         ePtr<gFont> font = new gFont("Regular", 19);
223         //ePtr<gFont> font = new gFont("Regular", 16);
224         lcd_label->setFont(font);
225
226         lcd_clock = new eLabel(lcd_win);
227         lcd_clock->move(ePoint(50, 46));
228         lcd_clock->resize(eSize(132, 18));
229         ePtr<gFont> clkfont = new gFont("Regular", 16);
230         lcd_clock->setFont(clkfont);
231
232         //lcd_label->setText("bla bla bla, this lcd\nSUCKS!");
233         //lcd_clock->setText("88:88:88");
234
235         lcd_win->show();
236         
237         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
238         
239         printf("executing main\n");
240
241         python.execute("mytest", "__main__");
242
243 //      eApp->exec();
244
245         return exit_code;
246 }
247
248 eWidgetDesktop *getDesktop()
249 {
250         return wdsk;
251 }
252
253 void runMainloop()
254 {
255         exit_code = eApp->exec();
256 }
257
258 void quitMainloop(int exitCode)
259 {
260         eApp->quit(exitCode);
261 }
262
263 void setLCD(const char *string)
264 {
265         lcd_label->setText(string);
266 }
267
268 void setLCDClock(const char *string)
269 {
270         lcd_clock->setText(string);
271 }