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