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