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