language update: sv, cs
[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         static eRCKey last(0, 0, 0);
62         static int num_repeat;
63
64         ePtr<eActionMap> ptr;
65         eActionMap::getInstance(ptr);
66
67         if ((key.code == last.code) && (key.producer == last.producer) && key.flags & eRCKey::flagRepeat)
68                 num_repeat++;
69         else
70         {
71                 num_repeat = 0;
72                 last = key;
73         }
74
75         if (num_repeat == 4)
76         {
77                 ptr->keyPressed(key.producer->getIdentifier(), key.code, eRCKey::flagLong);
78                 num_repeat++;
79         }
80
81         if (key.flags & eRCKey::flagAscii)
82         {
83                 prev_ascii_code = key.code;
84                 ptr->keyPressed(key.producer->getIdentifier(), 510 /* faked KEY_ASCII */, 0);
85         }
86         else
87                 ptr->keyPressed(key.producer->getIdentifier(), key.code, key.flags);
88 }
89
90 /************************************************/
91 #include <unistd.h>
92 #include <lib/components/scan.h>
93 #include <lib/dvb/idvb.h>
94 #include <lib/dvb/dvb.h>
95 #include <lib/dvb/db.h>
96 #include <lib/dvb/dvbtime.h>
97 #include <lib/dvb/epgcache.h>
98
99 class eMain: public eApplication, public Object
100 {
101         eInit init;
102
103         ePtr<eDVBDB> m_dvbdb;
104         ePtr<eDVBResourceManager> m_mgr;
105         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
106         ePtr<eEPGCache> m_epgcache;
107
108 public:
109         eMain()
110         {
111                 init.setRunlevel(eAutoInitNumbers::main);
112                 /* TODO: put into init */
113                 m_dvbdb = new eDVBDB();
114                 m_mgr = new eDVBResourceManager();
115                 m_locale_time_handler = new eDVBLocalTimeHandler();
116                 m_epgcache = new eEPGCache();
117                 m_mgr->setChannelList(m_dvbdb);
118         }
119         
120         ~eMain()
121         {
122                 m_dvbdb->saveServicelist();
123                 m_mgr->releaseCachedChannel();
124         }
125 };
126
127 int exit_code;
128
129 int main(int argc, char **argv)
130 {
131 #ifdef MEMLEAK_CHECK
132         atexit(DumpUnfreed);
133 #endif
134
135 #ifdef OBJECT_DEBUG
136         atexit(object_dump);
137 #endif
138
139 #ifdef HAVE_GSTREAMER
140         gst_init(&argc, &argv);
141 #endif
142
143         // set pythonpath if unset
144         setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
145         printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
146         
147         bsodLogInit();
148
149         ePython python;
150         eMain main;
151
152 #if 1
153 #ifdef SDLDC
154         ePtr<gSDLDC> my_dc;
155         gSDLDC::getInstance(my_dc);
156 #else
157         ePtr<gFBDC> my_dc;
158         gFBDC::getInstance(my_dc);
159         
160         int double_buffer = my_dc->haveDoubleBuffering();
161 #endif
162
163         ePtr<gLCDDC> my_lcd_dc;
164         gLCDDC::getInstance(my_lcd_dc);
165
166
167                 /* ok, this is currently hardcoded for arabic. */
168                         /* some characters are wrong in the regular font, force them to use the replacement font */
169         for (int i = 0x60c; i <= 0x66d; ++i)
170                 eTextPara::forceReplacementGlyph(i);
171         eTextPara::forceReplacementGlyph(0xfdf2);
172         for (int i = 0xfe80; i < 0xff00; ++i)
173                 eTextPara::forceReplacementGlyph(i);
174
175         eWidgetDesktop dsk(eSize(720, 576));
176         eWidgetDesktop dsk_lcd(eSize(132, 64));
177         
178         dsk.setStyleID(0);
179         dsk_lcd.setStyleID(1);
180         
181 /*      if (double_buffer)
182         {
183                 eDebug(" - double buffering found, enable buffered graphics mode.");
184                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
185         } */
186         
187         wdsk = &dsk;
188         lcddsk = &dsk_lcd;
189
190         dsk.setDC(my_dc);
191         dsk_lcd.setDC(my_lcd_dc);
192
193         ePtr<gPixmap> m_pm;
194         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
195         if (!m_pm)
196         {
197                 eFatal("pal.png not found!");
198         } else
199                 dsk.setPalette(*m_pm);
200
201         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
202 #endif
203
204                 /* redrawing is done in an idle-timer, so we have to set the context */
205         dsk.setRedrawTask(main);
206         dsk_lcd.setRedrawTask(main);
207         
208         
209         eDebug("Loading spinners...");
210         
211         {
212                 int i;
213 #define MAX_SPINNER 64
214                 ePtr<gPixmap> wait[MAX_SPINNER];
215                 for (i=0; i<MAX_SPINNER; ++i)
216                 {
217                         char filename[strlen(DATADIR) + 20];
218                         sprintf(filename, DATADIR "/enigma2/wait%d.png", i + 1);
219                         loadPNG(wait[i], filename);
220                         
221                         if (!wait[i])
222                         {
223                                 if (!i)
224                                         eDebug("failed to load %s! (%m)", filename);
225                                 else
226                                         eDebug("found %d spinner!\n", i);
227                                 break;
228                         }
229                 }
230                 if (i)
231                         my_dc->setSpinner(eRect(ePoint(100, 100), wait[0]->size()), wait, i);
232                 else
233                         my_dc->setSpinner(eRect(100, 100, 0, 0), wait, 1);
234         }
235         
236         gRC::getInstance()->setSpinnerDC(my_dc);
237
238         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
239         
240         printf("executing main\n");
241         
242         bsodCatchSignals();
243
244         setIoPrio(IOPRIO_CLASS_BE, 3);
245
246         python.execute("mytest", "__main__");
247         
248         if (exit_code == 5) /* python crash */
249         {
250                 eDebug("(exit code 5)");
251                 bsodFatal();
252         }
253         
254         dsk.paint();
255         dsk_lcd.paint();
256
257         {
258                 gPainter p(my_lcd_dc);
259                 p.resetClip(eRect(0, 0, 132, 64));
260                 p.clear();
261         }
262
263         return exit_code;
264 }
265
266 eWidgetDesktop *getDesktop(int which)
267 {
268         return which ? lcddsk : wdsk;
269 }
270
271 eApplication *getApplication()
272 {
273         return eApp;
274 }
275
276 void runMainloop()
277 {
278         eApp->runLoop();
279 }
280
281 void quitMainloop(int exitCode)
282 {
283         exit_code = exitCode;
284         eApp->quit(0);
285 }
286
287 #include "version.h"
288
289 const char *getEnigmaVersionString()
290 {
291         return 
292 #ifdef ENIGMA2_CHECKOUT_TAG
293                 ENIGMA2_CHECKOUT_TAG
294 #else
295                 "HEAD"
296 #endif
297                         "-" __DATE__;
298 }