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