small fix
[enigma2.git] / main / enigma.cpp
1 #ifdef WITH_SDL
2 #define SDLDC
3 #endif
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <libsig_comp.h>
8
9 #include <lib/actions/action.h>
10 #include <lib/driver/rc.h>
11 #include <lib/base/ioprio.h>
12 #include <lib/base/ebase.h>
13 #include <lib/base/eerror.h>
14 #include <lib/base/init.h>
15 #include <lib/base/init_num.h>
16 #include <lib/gdi/gfbdc.h>
17 #include <lib/gdi/glcddc.h>
18 #include <lib/gdi/grc.h>
19 #ifdef WITH_SDL
20 #include <lib/gdi/sdl.h>
21 #endif
22 #include <lib/gdi/epng.h>
23 #include <lib/gdi/font.h> 
24 #include <lib/gui/ebutton.h>
25 #include <lib/gui/elabel.h>
26 #include <lib/gui/elistboxcontent.h>
27 #include <lib/gui/ewidget.h>
28 #include <lib/gui/ewidgetdesktop.h>
29 #include <lib/gui/ewindow.h>
30 #include <lib/python/connections.h>
31 #include <lib/python/python.h>
32
33 #include "bsod.h" 
34
35 #ifdef HAVE_GSTREAMER
36 #include <gst/gst.h>
37 #endif
38
39 #ifdef OBJECT_DEBUG
40 int object_total_remaining;
41
42 void object_dump()
43 {
44         printf("%d items left\n", object_total_remaining);
45 }
46 #endif
47
48 static eWidgetDesktop *wdsk, *lcddsk;
49
50 static int prev_ascii_code;
51
52 int getPrevAsciiCode()
53 {
54         int ret = prev_ascii_code;
55         prev_ascii_code = 0;
56         return ret;
57 }
58
59 void keyEvent(const eRCKey &key)
60 {
61         ePtr<eActionMap> ptr;
62         eActionMap::getInstance(ptr);
63         if (key.flags & eRCKey::flagAscii)
64         {
65                 prev_ascii_code = key.code;
66                 ptr->keyPressed(key.producer->getIdentifier(), 510 /* faked KEY_ASCII */, 0);
67         }
68         else
69                 ptr->keyPressed(key.producer->getIdentifier(), key.code, key.flags);
70 }
71
72 /************************************************/
73 #include <unistd.h>
74 #include <lib/components/scan.h>
75 #include <lib/dvb/idvb.h>
76 #include <lib/dvb/dvb.h>
77 #include <lib/dvb/db.h>
78 #include <lib/dvb/dvbtime.h>
79 #include <lib/dvb/epgcache.h>
80
81 class eMain: public eApplication, public Object
82 {
83         eInit init;
84         
85         ePtr<eDVBResourceManager> m_mgr;
86         ePtr<eDVBDB> m_dvbdb;
87         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
88         ePtr<eComponentScan> m_scan;
89         ePtr<eEPGCache> m_epgcache;
90
91 public:
92         eMain()
93         {
94                 init.setRunlevel(eAutoInitNumbers::main);
95
96                                 /* TODO: put into init */
97                 m_dvbdb = new eDVBDB();
98                 m_mgr = new eDVBResourceManager();
99                 m_locale_time_handler = new eDVBLocalTimeHandler();
100                 m_epgcache = new eEPGCache();
101                 m_mgr->setChannelList(m_dvbdb);
102         }
103         
104         ~eMain()
105         {
106                 m_dvbdb->saveServicelist();
107                 m_scan = 0;
108         }
109 };
110
111 int exit_code;
112
113 int main(int argc, char **argv)
114 {
115 #ifdef MEMLEAK_CHECK
116         atexit(DumpUnfreed);
117 #endif
118
119 #ifdef OBJECT_DEBUG
120         atexit(object_dump);
121 #endif
122
123 #ifdef HAVE_GSTREAMER
124         gst_init(&argc, &argv);
125 #endif
126
127         // set pythonpath if unset
128         setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
129         printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
130         
131         bsodLogInit();
132
133         ePython python;
134         eMain main;
135         
136 #if 1
137 #ifdef SDLDC
138         ePtr<gSDLDC> my_dc;
139         gSDLDC::getInstance(my_dc);
140 #else
141         ePtr<gFBDC> my_dc;
142         gFBDC::getInstance(my_dc);
143         
144         int double_buffer = my_dc->haveDoubleBuffering();
145 #endif
146
147         ePtr<gLCDDC> my_lcd_dc;
148         gLCDDC::getInstance(my_lcd_dc);
149
150
151                 /* ok, this is currently hardcoded for arabic. */
152                         /* some characters are wrong in the regular font, force them to use the replacement font */
153         for (int i = 0x60c; i <= 0x66d; ++i)
154                 eTextPara::forceReplacementGlyph(i);
155         eTextPara::forceReplacementGlyph(0xfdf2);
156         for (int i = 0xfe80; i < 0xff00; ++i)
157                 eTextPara::forceReplacementGlyph(i);
158         
159
160         eWidgetDesktop dsk(eSize(720, 576));
161         eWidgetDesktop dsk_lcd(eSize(132, 64));
162         
163         dsk.setStyleID(0);
164         dsk_lcd.setStyleID(1);
165         
166 /*      if (double_buffer)
167         {
168                 eDebug(" - double buffering found, enable buffered graphics mode.");
169                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
170         } */
171         
172         wdsk = &dsk;
173         lcddsk = &dsk_lcd;
174
175         dsk.setDC(my_dc);
176         dsk_lcd.setDC(my_lcd_dc);
177
178         ePtr<gPixmap> m_pm;
179         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
180         if (!m_pm)
181         {
182                 eFatal("pal.png not found!");
183         } else
184                 dsk.setPalette(*m_pm);
185
186         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
187 #endif
188
189                 /* redrawing is done in an idle-timer, so we have to set the context */
190         dsk.setRedrawTask(main);
191         dsk_lcd.setRedrawTask(main);
192
193         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
194         
195         printf("executing main\n");
196         
197         bsodCatchSignals();
198
199         setIoPrio(IOPRIO_CLASS_BE, 3);
200
201         python.execute("mytest", "__main__");
202         
203         if (exit_code == 5) /* python crash */
204                 bsodFatal();
205         
206         dsk.paint();
207         dsk_lcd.paint();
208
209         {
210                 gPainter p(my_lcd_dc);
211                 p.resetClip(eRect(0, 0, 132, 64));
212                 p.clear();
213                 p.flush();
214         }
215
216         return exit_code;
217 }
218
219 eWidgetDesktop *getDesktop(int which)
220 {
221         return which ? lcddsk : wdsk;
222 }
223
224 eApplication *getApplication()
225 {
226         return eApp;
227 }
228
229 void runMainloop()
230 {
231         eApp->runLoop();
232 }
233
234 void quitMainloop(int exitCode)
235 {
236         exit_code = exitCode;
237         eApp->quit(0);
238 }