variable double_buffer is not used when compiled with SDL
[enigma2.git] / main / enigma.cpp
1 #ifdef WITH_SDL
2 #define SDLDC
3 #endif
4
5 #include <stdio.h>
6 #include <libsig_comp.h>
7 #include <lib/base/ebase.h>
8 #include <lib/base/eerror.h>
9 #include <lib/base/init.h>
10 #include <lib/base/init_num.h>
11
12 #include <unistd.h>
13
14 #include <lib/gdi/grc.h>
15 #include <lib/gdi/gfbdc.h>
16 #include <lib/gdi/glcddc.h>
17
18 #ifdef WITH_SDL
19 #include <lib/gdi/sdl.h>
20 #endif
21 #include <lib/gdi/font.h> 
22
23 #include <lib/gui/ewidget.h>
24 #include <lib/gui/ewidgetdesktop.h>
25 #include <lib/gui/elabel.h>
26 #include <lib/gui/ebutton.h>
27
28 #include <lib/gui/ewindow.h>
29
30 #include <lib/python/python.h>
31 #include <lib/python/connections.h>
32
33 #include <lib/gui/elistboxcontent.h>
34
35 #include <lib/driver/rc.h>
36
37 #include <lib/actions/action.h>
38
39 #include <lib/gdi/epng.h>
40
41 #ifdef OBJECT_DEBUG
42 int object_total_remaining;
43
44 void object_dump()
45 {
46         printf("%d items left\n", object_total_remaining);
47 }
48 #endif
49
50 void dumpRegion(const gRegion &region)
51 {
52         fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
53                 region.extends.left(), region.extends.top(),
54                 region.extends.right(), region.extends.bottom(), region.rects.size());
55 #if 0
56         for (int y=0; y<region.extends.bottom(); ++y)
57         {
58                 for (int x=0; x<region.extends.right(); ++x)
59                 {
60                         unsigned char res = ' ';
61                         for (unsigned int i=0; i < region.rects.size(); ++i)
62                                 if (region.rects[i].contains(ePoint(x, y)))
63                                         res = '0' + i;
64                         fprintf(stderr, "%c", res);
65                 }
66                 fprintf(stderr, "\n");
67         }
68 #endif
69
70 }
71
72 eWidgetDesktop *wdsk, *lcddsk;
73
74 // typedef struct _object PyObject;
75
76 void print(int i)
77 {
78         printf("C++ says: it's a %d!!!\n", i);
79 }
80
81 PSignal1<void,int> keyPressed;
82
83 PSignal1<void,int> &keyPressedSignal()
84 {
85         return keyPressed;
86 }
87
88 void keyEvent(const eRCKey &key)
89 {
90         ePtr<eActionMap> ptr;
91         eActionMap::getInstance(ptr);
92         ptr->keyPressed(0, key.code, key.flags);
93 //      if (!key.flags)
94 //              keyPressed(key.code);
95 }
96
97 /************************************************/
98 #include <unistd.h>
99 #include <lib/components/scan.h>
100 #include <lib/dvb/idvb.h>
101 #include <lib/dvb/dvb.h>
102 #include <lib/dvb/db.h>
103 #include <lib/dvb/dvbtime.h>
104 #include <lib/dvb/epgcache.h>
105
106 class eMain: public eApplication, public Object
107 {
108         eInit init;
109         
110         ePtr<eDVBResourceManager> m_mgr;
111         ePtr<eDVBDB> m_dvbdb;
112         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
113         ePtr<eComponentScan> m_scan;
114         ePtr<eEPGCache> m_epgcache;
115
116 public:
117         eMain()
118         {
119                 init.setRunlevel(eAutoInitNumbers::main);
120
121                                 /* TODO: put into init */
122                 m_dvbdb = new eDVBDB();
123                 m_mgr = new eDVBResourceManager();
124                 m_locale_time_handler = new eDVBLocalTimeHandler();
125                 m_epgcache = new eEPGCache();
126                 m_mgr->setChannelList(m_dvbdb);
127         }
128         
129         ~eMain()
130         {
131                 m_dvbdb->saveServicelist();
132                 m_scan = 0;
133         }
134 };
135
136 /************************************************/
137
138 eLabel *lcd_label, *lcd_clock;
139
140 int exit_code;
141
142 int main(int argc, char **argv)
143 {
144 #ifdef OBJECT_DEBUG
145         atexit(object_dump);
146 #endif
147
148         // set pythonpath if unset
149         setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
150         printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
151
152
153         ePython python;
154         eMain main;
155         
156 #if 1
157 #ifdef SDLDC
158         ePtr<gSDLDC> my_dc;
159         gSDLDC::getInstance(my_dc);
160 #else
161         ePtr<gFBDC> my_dc;
162         gFBDC::getInstance(my_dc);
163         
164         int double_buffer = my_dc->haveDoubleBuffering();
165 #endif
166
167         ePtr<gLCDDC> my_lcd_dc;
168         gLCDDC::getInstance(my_lcd_dc);
169
170         fontRenderClass::getInstance()->AddFont(FONTDIR "/md_khmurabi_10.ttf", "Regular", 100);
171         fontRenderClass::getInstance()->AddFont(FONTDIR "/ae_AlMateen.ttf", "Replacement", 90);
172         eTextPara::setReplacementFont("Replacement");
173         
174                         /* some characters are wrong in the regular font, force them to use the replacement font */
175         for (int i = 0x60c; i <= 0x66d; ++i)
176                 eTextPara::forceReplacementGlyph(i);
177         eTextPara::forceReplacementGlyph(0xfdf2);
178         for (int i = 0xfe80; i < 0xff00; ++i)
179                 eTextPara::forceReplacementGlyph(i);
180         
181
182         eWidgetDesktop dsk(eSize(720, 576));
183         eWidgetDesktop dsk_lcd(eSize(132, 64));
184         
185 /*      if (double_buffer)
186         {
187                 eDebug(" - double buffering found, enable buffered graphics mode.");
188                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
189         } */
190         
191         wdsk = &dsk;
192         lcddsk = &dsk_lcd;
193
194         dsk.setDC(my_dc);
195         dsk_lcd.setDC(my_lcd_dc);
196
197         ePtr<gPixmap> m_pm;
198         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
199         if (!m_pm)
200         {
201                 eFatal("pal.png not found!");
202         } else
203                 dsk.setPalette(*m_pm);
204
205         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
206 #endif
207
208                 /* redrawing is done in an idle-timer, so we have to set the context */
209         dsk.setRedrawTask(main);
210         dsk_lcd.setRedrawTask(main);
211
212         eWindow *lcd_win = new eWindow(&dsk_lcd);
213         
214         lcd_win->setFlag(eWindow::wfNoBorder);
215         
216         lcd_win->move(ePoint(0, 0));
217         lcd_win->resize(eSize(132, 64));
218         
219         lcd_label = new eLabel(lcd_win);
220         lcd_label->move(ePoint(0, 4));
221         lcd_label->resize(eSize(132, 42));
222         ePtr<gFont> font = new gFont("Regular", 19);
223         //ePtr<gFont> font = new gFont("Regular", 16);
224         lcd_label->setFont(font);
225
226         lcd_clock = new eLabel(lcd_win);
227         lcd_clock->move(ePoint(50, 46));
228         lcd_clock->resize(eSize(132, 18));
229         ePtr<gFont> clkfont = new gFont("Regular", 16);
230         lcd_clock->setFont(clkfont);
231
232         //lcd_label->setText("bla bla bla, this lcd\nSUCKS!");
233         //lcd_clock->setText("88:88:88");
234
235         lcd_win->show();
236         
237         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
238         
239         printf("executing main\n");
240
241         python.execute("mytest", "__main__");
242
243         return exit_code;
244 }
245
246 eWidgetDesktop *getDesktop()
247 {
248         return wdsk;
249 }
250
251 eApplication *getApplication()
252 {
253         return eApp;
254 }
255
256 void runMainloop()
257 {
258         exit_code = eApp->runLoop();
259 }
260
261 void quitMainloop(int exitCode)
262 {
263         eApp->quit(exitCode);
264 }
265
266 void setLCD(const char *string)
267 {
268         lcd_label->setText(string);
269 }
270
271 void setLCDClock(const char *string)
272 {
273         lcd_clock->setText(string);
274 }