export eDVBDB to python ( for reloadServicelist and reloadBouquets )
[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         
133         ~eMain()
134         {
135                 m_dvbdb->saveServicelist();
136                 m_scan = 0;
137         }
138 };
139
140 /************************************************/
141
142 eLabel *lcd_label, *lcd_clock;
143
144 int exit_code;
145
146 int main(int argc, char **argv)
147 {
148 #ifdef OBJECT_DEBUG
149         atexit(object_dump);
150 #endif
151
152         // set pythonpath if unset
153         setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
154         printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
155
156
157         ePython python;
158         eMain main;
159         
160         int double_buffer = 0;
161
162 #if 1
163 #ifdef SDLDC
164         ePtr<gSDLDC> my_dc;
165         gSDLDC::getInstance(my_dc);
166 #else
167         ePtr<gFBDC> my_dc;
168         gFBDC::getInstance(my_dc);
169         
170         double_buffer = my_dc->haveDoubleBuffering();
171 #endif
172
173         ePtr<gLCDDC> my_lcd_dc;
174         gLCDDC::getInstance(my_lcd_dc);
175
176         fontRenderClass::getInstance()->AddFont(FONTDIR "/md_khmurabi_10.ttf", "Regular", 100);
177
178         eWidgetDesktop dsk(eSize(720, 576));
179         eWidgetDesktop dsk_lcd(eSize(132, 64));
180         
181 /*      if (double_buffer)
182         {
183                 eDebug(" - double buffering found, enable buffered graphics mode.");
184                 dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
185         } */
186         
187         wdsk = &dsk;
188         lcddsk = &dsk_lcd;
189
190         dsk.setDC(my_dc);
191         dsk_lcd.setDC(my_lcd_dc);
192
193         ePtr<gPixmap> m_pm;
194         loadPNG(m_pm, DATADIR "/enigma2/pal.png");
195         if (!m_pm)
196         {
197                 eFatal("pal.png not found!");
198         } else
199                 dsk.setPalette(*m_pm);
200
201         dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
202 #endif
203
204                 /* redrawing is done in an idle-timer, so we have to set the context */
205         dsk.setRedrawTask(main);
206         dsk_lcd.setRedrawTask(main);
207
208         eWindow *lcd_win = new eWindow(&dsk_lcd);
209         
210         lcd_win->setFlag(eWindow::wfNoBorder);
211         
212         lcd_win->move(ePoint(0, 0));
213         lcd_win->resize(eSize(132, 64));
214         
215         lcd_label = new eLabel(lcd_win);
216         lcd_label->move(ePoint(0, 4));
217         lcd_label->resize(eSize(132, 42));
218         ePtr<gFont> font = new gFont("Regular", 19);
219         //ePtr<gFont> font = new gFont("Regular", 16);
220         lcd_label->setFont(font);
221
222         lcd_clock = new eLabel(lcd_win);
223         lcd_clock->move(ePoint(50, 46));
224         lcd_clock->resize(eSize(132, 18));
225         ePtr<gFont> clkfont = new gFont("Regular", 16);
226         lcd_clock->setFont(clkfont);
227
228         //lcd_label->setText("bla bla bla, this lcd\nSUCKS!");
229         //lcd_clock->setText("88:88:88");
230
231         lcd_win->show();
232         
233         eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
234         
235         printf("executing main\n");
236
237         python.execute("mytest", "__main__");
238
239 //      eApp->exec();
240
241         return exit_code;
242 }
243
244 eWidgetDesktop *getDesktop()
245 {
246         return wdsk;
247 }
248
249 void runMainloop()
250 {
251         exit_code = eApp->exec();
252 }
253
254 void quitMainloop(int exitCode)
255 {
256         eApp->quit(exitCode);
257 }
258
259 void setLCD(const char *string)
260 {
261         lcd_label->setText(string);
262 }
263
264 void setLCDClock(const char *string)
265 {
266         lcd_clock->setText(string);
267 }