add xml stuff
[enigma2.git] / main / enigma.cpp
1 #ifdef WITH_SDL
2 #define SDLDC
3 #endif
4 #include <stdio.h>
5 #include <libsig_comp.h>
6 #include <lib/base/ebase.h>
7 #include <lib/base/eerror.h>
8 #include <lib/base/init.h>
9 #include <lib/base/init_num.h>
10
11 #include <unistd.h>
12
13 #include <lib/gdi/grc.h>
14 #include <lib/gdi/gfbdc.h>
15 #ifdef WITH_SDL
16 #include <lib/gdi/sdl.h>
17 #endif
18 #include <lib/gdi/font.h> 
19
20 #include <lib/gui/ewidget.h>
21 #include <lib/gui/ewidgetdesktop.h>
22 #include <lib/gui/elabel.h>
23 #include <lib/gui/ebutton.h>
24
25 #include <lib/gui/ewindow.h>
26
27 #include <lib/python/python.h>
28 #include <lib/python/connections.h>
29
30 #include <lib/gui/elistboxcontent.h>
31
32 #include <lib/driver/rc.h>
33
34 #include <lib/actions/action.h>
35
36 #include <lib/gdi/epng.h>
37
38 #ifdef OBJECT_DEBUG
39 int object_total_remaining;
40
41 void object_dump()
42 {
43         printf("%d items left\n", object_total_remaining);
44 }
45 #endif
46
47 void dumpRegion(const gRegion &region)
48 {
49         fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
50                 region.extends.left(), region.extends.top(),
51                 region.extends.right(), region.extends.bottom(), region.rects.size());
52         for (int y=0; y<region.extends.bottom(); ++y)
53         {
54                 for (int x=0; x<region.extends.right(); ++x)
55                 {
56                         unsigned char res = ' ';
57                         for (unsigned int i=0; i < region.rects.size(); ++i)
58                                 if (region.rects[i].contains(ePoint(x, y)))
59                                         res = '0' + i;
60                         fprintf(stderr, "%c", res);
61                 }
62                 fprintf(stderr, "\n");
63         }
64 }
65
66 eWidgetDesktop *wdsk;
67
68 // typedef struct _object PyObject;
69
70 void print(int i)
71 {
72         printf("C++ says: it's a %d!!!\n", i);
73 }
74
75 PSignal1<void,int> keyPressed;
76
77 PSignal1<void,int> &keyPressedSignal()
78 {
79         return keyPressed;
80 }
81
82 void keyEvent(const eRCKey &key)
83 {
84         ePtr<eActionMap> ptr;
85         eActionMap::getInstance(ptr);
86         ptr->keyPressed(0, key.code, key.flags);
87 //      if (!key.flags)
88 //              keyPressed(key.code);
89 }
90
91 /************************************************/
92 #include <unistd.h>
93 #include <lib/components/scan.h>
94 #include <lib/dvb/idvb.h>
95 #include <lib/dvb/dvb.h>
96 #include <lib/dvb/db.h>
97 #include <lib/dvb/dvbtime.h>
98 #include <lib/dvb/epgcache.h>
99
100 class eMain: public eApplication, public Object
101 {
102         eInit init;
103         
104         ePtr<eDVBResourceManager> m_mgr;
105         ePtr<eDVBDB> m_dvbdb;
106         ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
107         ePtr<eComponentScan> m_scan;
108         ePtr<eEPGCache> m_epgcache;
109
110 public:
111         eMain()
112         {
113                 init.setRunlevel(eAutoInitNumbers::main);
114
115                                 /* TODO: put into init */
116                 m_dvbdb = new eDVBDB();
117                 m_mgr = new eDVBResourceManager();
118                 m_locale_time_handler = new eDVBLocalTimeHandler();
119                 m_epgcache = new eEPGCache();
120                 m_mgr->setChannelList(m_dvbdb);
121                 
122 //              m_scan = new eComponentScan();
123 //              m_scan->start();
124
125         }
126         
127         ~eMain()
128         {
129                 m_scan = 0;
130         }
131 };
132
133 /************************************************/
134
135
136 int main(int argc, char **argv)
137 {
138 #ifdef OBJECT_DEBUG
139         atexit(object_dump);
140 #endif
141
142
143         ePython python;
144         eMain main;
145
146 #if 1
147 #ifdef SDLDC
148         ePtr<gSDLDC> my_dc;
149         gSDLDC::getInstance(my_dc);
150 #else
151         ePtr<gFBDC> my_dc;
152         gFBDC::getInstance(my_dc);
153 #endif
154
155         fontRenderClass::getInstance()->AddFont(FONTDIR "/arial.ttf", "Arial", 100);
156
157         eWidgetDesktop dsk(eSize(720, 576));
158         
159         wdsk = &dsk;
160
161
162         dsk.setDC(my_dc);
163
164         ePtr<gPixmap> m_pm;
165         loadPNG(m_pm, "data/pal.png");
166         if (!m_pm)
167         {
168                 eFatal("hi ghost, please copy pal.png into your ./data, thanks!");
169         } else
170                 dsk.setPalette(*m_pm);
171
172         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
173 #endif
174
175                 /* redrawing is done in an idle-timer, so we have to set the context */
176         dsk.setRedrawTask(main);
177         
178         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
179         
180         printf("executing main\n");
181
182         python.execute("mytest", "__main__");
183
184 //      eApp->exec();
185
186         return 0;
187 }
188
189 eWidgetDesktop *getDesktop()
190 {
191         return wdsk;
192 }
193
194 void runMainloop()
195 {
196         eApp->exec();
197 }
198
199 void quitMainloop()
200 {
201         eApp->quit(0);
202 }