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