add some new (currently unused) source/renderer based elements
[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(0, 510 /* faked KEY_ASCII */, 0);
67         }
68         else
69                 ptr->keyPressed(0, 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
160         eWidgetDesktop dsk(eSize(720, 576));
161         eWidgetDesktop dsk_lcd(eSize(132, 64));
162         
163 /*      if (double_buffer)
164         {
165                 eDebug(" - double buffering found, enable buffered graphics mode.");
166                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
167         } */
168         
169         wdsk = &dsk;
170         lcddsk = &dsk_lcd;
171
172         dsk.setDC(my_dc);
173         dsk_lcd.setDC(my_lcd_dc);
174
175         ePtr<gPixmap> m_pm;
176         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
177         if (!m_pm)
178         {
179                 eFatal("pal.png not found!");
180         } else
181                 dsk.setPalette(*m_pm);
182
183         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
184 #endif
185
186                 /* redrawing is done in an idle-timer, so we have to set the context */
187         dsk.setRedrawTask(main);
188         dsk_lcd.setRedrawTask(main);
189
190         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
191         
192         printf("executing main\n");
193         
194         bsodCatchSignals();
195
196         setIoPrio(IOPRIO_CLASS_BE, 3);
197
198         python.execute("mytest", "__main__");
199         
200         if (exit_code == 5) /* python crash */
201                 bsodFatal();
202         
203         dsk.paint();
204         dsk_lcd.paint();
205
206         {
207                 gPainter p(my_lcd_dc);
208                 p.resetClip(eRect(0, 0, 132, 64));
209                 p.clear();
210                 p.flush();
211         }
212
213         return exit_code;
214 }
215
216 eWidgetDesktop *getDesktop(int which)
217 {
218         return which ? lcddsk : wdsk;
219 }
220
221 eApplication *getApplication()
222 {
223         return eApp;
224 }
225
226 void runMainloop()
227 {
228         eApp->runLoop();
229 }
230
231 void quitMainloop(int exitCode)
232 {
233         exit_code = exitCode;
234         eApp->quit(0);
235 }
236
237 void addFont(const char *filename, const char *alias, int scale_factor, int is_replacement)
238 {
239         fontRenderClass::getInstance()->AddFont(filename, alias, scale_factor);
240         if (is_replacement)
241                 eTextPara::setReplacementFont(alias);
242 }