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