eb0a1845f472165eec9762edb5ae9d9d75167047
[openblackhole/openblackhole-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         eWidgetDesktop dsk(eSize(720, 576));
160         eWidgetDesktop dsk_lcd(eSize(132, 64));
161         
162         dsk.setStyleID(0);
163         dsk_lcd.setStyleID(1);
164         
165 /*      if (double_buffer)
166         {
167                 eDebug(" - double buffering found, enable buffered graphics mode.");
168                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
169         } */
170         
171         wdsk = &dsk;
172         lcddsk = &dsk_lcd;
173
174         dsk.setDC(my_dc);
175         dsk_lcd.setDC(my_lcd_dc);
176
177         ePtr<gPixmap> m_pm;
178         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
179         if (!m_pm)
180         {
181                 eFatal("pal.png not found!");
182         } else
183                 dsk.setPalette(*m_pm);
184
185         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
186 #endif
187
188                 /* redrawing is done in an idle-timer, so we have to set the context */
189         dsk.setRedrawTask(main);
190         dsk_lcd.setRedrawTask(main);
191         
192         
193         eDebug("Loading spinners...");
194         
195         {
196                 int i;
197                 ePtr<gPixmap> wait[4];
198                 for (i=0; i<4; ++i)
199                 {
200                         char filename[strlen(DATADIR) + 20];
201                         sprintf(filename, DATADIR "/enigma2/wait%d.png", i + 1);
202                         if (loadPNG(wait[i], filename))
203                         {
204                                 eDebug("failed to load %s! (%m)", filename);
205                                 continue;
206                         }
207                 }
208                 my_dc->setSpinner(eRect(100, 100, 105, 105), wait, 4);
209         }
210         
211         gRC::getInstance()->setSpinnerDC(my_dc);
212
213         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
214         
215         printf("executing main\n");
216         
217         bsodCatchSignals();
218
219         setIoPrio(IOPRIO_CLASS_BE, 3);
220
221         python.execute("mytest", "__main__");
222         
223         if (exit_code == 5) /* python crash */
224                 bsodFatal();
225         
226         dsk.paint();
227         dsk_lcd.paint();
228
229         {
230                 gPainter p(my_lcd_dc);
231                 p.resetClip(eRect(0, 0, 132, 64));
232                 p.clear();
233                 p.flush();
234         }
235
236         return exit_code;
237 }
238
239 eWidgetDesktop *getDesktop(int which)
240 {
241         return which ? lcddsk : wdsk;
242 }
243
244 eApplication *getApplication()
245 {
246         return eApp;
247 }
248
249 void runMainloop()
250 {
251         eApp->runLoop();
252 }
253
254 void quitMainloop(int exitCode)
255 {
256         exit_code = exitCode;
257         eApp->quit(0);
258 }