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