- fix when not enough framebuffer memory available
[enigma2.git] / main / enigma.cpp
1 #undef WITH_SDL
2 #ifdef WITH_SDL
3 #error
4 #define SDLDC
5 #endif
6 #include <stdio.h>
7 #include <libsig_comp.h>
8 #include <lib/base/ebase.h>
9 #include <lib/base/eerror.h>
10 #include <lib/base/init.h>
11 #include <lib/base/init_num.h>
12
13 #include <unistd.h>
14
15 #include <lib/gdi/grc.h>
16 #include <lib/gdi/gfbdc.h>
17 #ifdef WITH_SDL
18 #error
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;
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 //              m_scan = new eComponentScan();
129 //              m_scan->start();
130
131         }
132         
133         ~eMain()
134         {
135                 m_scan = 0;
136         }
137 };
138
139 /************************************************/
140
141
142 int main(int argc, char **argv)
143 {
144 #ifdef OBJECT_DEBUG
145         atexit(object_dump);
146 #endif
147
148
149         ePython python;
150         eMain main;
151         
152         int double_buffer = 0;
153
154 #if 1
155 #ifdef SDLDC
156         ePtr<gSDLDC> my_dc;
157         gSDLDC::getInstance(my_dc);
158 #else
159         ePtr<gFBDC> my_dc;
160         gFBDC::getInstance(my_dc);
161         
162         double_buffer = my_dc->haveDoubleBuffering();
163 #endif
164
165         fontRenderClass::getInstance()->AddFont(FONTDIR "/arial.ttf", "Arial", 100);
166
167         eWidgetDesktop dsk(eSize(720, 576));
168         
169         if (double_buffer)
170         {
171                 eDebug(" - double buffering found, enable buffered graphics mode.");
172                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
173         }
174         
175         wdsk = &dsk;
176
177         dsk.setDC(my_dc);
178
179         ePtr<gPixmap> m_pm;
180         loadPNG(m_pm, "data/pal.png");
181         if (!m_pm)
182         {
183                 eFatal("hi ghost, please copy pal.png into your ./data, thanks!");
184         } else
185                 dsk.setPalette(*m_pm);
186
187         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
188 #endif
189
190                 /* redrawing is done in an idle-timer, so we have to set the context */
191         dsk.setRedrawTask(main);
192         
193         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
194         
195         printf("executing main\n");
196
197         python.execute("mytest", "__main__");
198
199 //      eApp->exec();
200
201         return 0;
202 }
203
204 eWidgetDesktop *getDesktop()
205 {
206         return wdsk;
207 }
208
209 void runMainloop()
210 {
211         eApp->exec();
212 }
213
214 void quitMainloop()
215 {
216         eApp->quit(0);
217 }