store lamedb ob enigma2 shutdown
[enigma2.git] / main / enigma.cpp
index 81391c3..e669b19 100644 (file)
@@ -1,3 +1,10 @@
+#undef WITH_SDL
+
+#ifdef WITH_SDL
+#error
+#define SDLDC
+#endif
+
 #include <stdio.h>
 #include <libsig_comp.h>
 #include <lib/base/ebase.h>
 
 #include <lib/gdi/grc.h>
 #include <lib/gdi/gfbdc.h>
+#include <lib/gdi/glcddc.h>
+
+#ifdef WITH_SDL
+#error
+#include <lib/gdi/sdl.h>
+#endif
 #include <lib/gdi/font.h> 
 
 #include <lib/gui/ewidget.h>
 #include <lib/gui/ewidgetdesktop.h>
 #include <lib/gui/elabel.h>
+#include <lib/gui/ebutton.h>
 
 #include <lib/gui/ewindow.h>
 
 #include <lib/python/python.h>
+#include <lib/python/connections.h>
+
+#include <lib/gui/elistboxcontent.h>
+
+#include <lib/driver/rc.h>
+
+#include <lib/actions/action.h>
+
+#include <lib/gdi/epng.h>
 
 #ifdef OBJECT_DEBUG
 int object_total_remaining;
@@ -33,6 +56,7 @@ void dumpRegion(const gRegion &region)
        fprintf(stderr, "extends: %d %d -> %d %d (%d rects)\n", 
                region.extends.left(), region.extends.top(),
                region.extends.right(), region.extends.bottom(), region.rects.size());
+#if 0
        for (int y=0; y<region.extends.bottom(); ++y)
        {
                for (int x=0; x<region.extends.right(); ++x)
@@ -45,136 +69,196 @@ void dumpRegion(const gRegion &region)
                }
                fprintf(stderr, "\n");
        }
+#endif
+
 }
 
-int main()
+eWidgetDesktop *wdsk, *lcddsk;
+
+// typedef struct _object PyObject;
+
+void print(int i)
+{
+       printf("C++ says: it's a %d!!!\n", i);
+}
+
+PSignal1<void,int> keyPressed;
+
+PSignal1<void,int> &keyPressedSignal()
+{
+       return keyPressed;
+}
+
+void keyEvent(const eRCKey &key)
+{
+       ePtr<eActionMap> ptr;
+       eActionMap::getInstance(ptr);
+       ptr->keyPressed(0, key.code, key.flags);
+//     if (!key.flags)
+//             keyPressed(key.code);
+}
+
+/************************************************/
+#include <unistd.h>
+#include <lib/components/scan.h>
+#include <lib/dvb/idvb.h>
+#include <lib/dvb/dvb.h>
+#include <lib/dvb/db.h>
+#include <lib/dvb/dvbtime.h>
+#include <lib/dvb/epgcache.h>
+
+class eMain: public eApplication, public Object
+{
+       eInit init;
+       
+       ePtr<eDVBResourceManager> m_mgr;
+       ePtr<eDVBDB> m_dvbdb;
+       ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
+       ePtr<eComponentScan> m_scan;
+       ePtr<eEPGCache> m_epgcache;
+
+public:
+       eMain()
+       {
+               init.setRunlevel(eAutoInitNumbers::main);
+
+                               /* TODO: put into init */
+               m_dvbdb = new eDVBDB();
+               m_mgr = new eDVBResourceManager();
+               m_locale_time_handler = new eDVBLocalTimeHandler();
+               m_epgcache = new eEPGCache();
+               m_mgr->setChannelList(m_dvbdb);
+               
+//             m_scan = new eComponentScan();
+//             m_scan->start();
+
+       }
+       
+       ~eMain()
+       {
+               m_dvbdb->save();
+               m_scan = 0;
+       }
+};
+
+/************************************************/
+
+eLabel *lcd_label, *lcd_clock;
+
+int main(int argc, char **argv)
 {
 #ifdef OBJECT_DEBUG
        atexit(object_dump);
 #endif
-       eInit init;
+
+
+       ePython python;
+       eMain main;
        
-       init.setRunlevel(eAutoInitNumbers::main);
+       int double_buffer = 0;
 
-               // gui stuff
-#if 0
+#if 1
+#ifdef SDLDC
+       ePtr<gSDLDC> my_dc;
+       gSDLDC::getInstance(my_dc);
+#else
        ePtr<gFBDC> my_dc;
        gFBDC::getInstance(my_dc);
-#if 1
-
-       gPainter p(my_dc);
-       
-       gRGB pal[256];
-       pal[0] = 0;
-       pal[1] = 0xff00ff;
-       pal[2] = 0xffFFff;
-       pal[3] = 0x00ff00;
        
-       for (int a=0; a<0x10; ++a)
-               pal[a | 0x10] = (0x111111 * a) | 0xFF;
-       p.setPalette(pal, 0, 256);
+       double_buffer = my_dc->haveDoubleBuffering();
+#endif
 
-       fontRenderClass::getInstance()->AddFont("/dbox2/cdkroot/share/fonts/arial.ttf", "Arial", 100);
+       ePtr<gLCDDC> my_lcd_dc;
+       gLCDDC::getInstance(my_lcd_dc);
 
-#if 0
-       p.resetClip(gRegion(eRect(0, 0, 720, 576)));
-       
-        
-       gRegion c;
-       eDebug("0");
-       int i;
-       
-       c |= eRect(0, 20, 100, 10);
-       c |= eRect(0, 50, 100, 10);
-       c |= eRect(10, 10, 80, 100);
-       
-       c -= eRect(20, 20, 40, 40);
+       fontRenderClass::getInstance()->AddFont(FONTDIR "/arial.ttf", "Arial", 100);
+
+       eWidgetDesktop dsk(eSize(720, 576));
+       eWidgetDesktop dsk_lcd(eSize(132, 64));
        
-       p.setForegroundColor(gColor(3));
-       p.fill(eRect(0, 0, 100, 100));
-       p.fill(eRect(200, 0, 100, 100));
+       if (double_buffer)
+       {
+               eDebug(" - double buffering found, enable buffered graphics mode.");
+               dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
+       }
        
-       for (int a=0; a<c.rects.size(); ++a)
-               eDebug("%d %d -> %d %d", c.rects[a].left(), c.rects[a].top(), c.rects[a].right(), c.rects[a].bottom());
-       eDebug("extends: %d %d %d %d", c.extends.left(), c.extends.top(), c.extends.right(), c.extends.bottom());
-       p.setOffset(ePoint(100, 100));
-       p.clip(c);
-
-       p.setBackgroundColor(gColor(1));
-       p.clear();
-       p.setForegroundColor(gColor(2));
-       p.line(ePoint(0, 0), ePoint(220, 190));
-       p.clippop();
-
-       p.setBackgroundColor(gColor(0x1f));
-       p.setForegroundColor(gColor(0x10));
-
-       ePtr<gFont> fnt = new gFont("Arial", 70);
-       p.setFont(fnt);
-       p.renderText(eRect(100, 100, 500, 200), "Hello welt!");
-#else
-
+       wdsk = &dsk;
+       lcddsk = &dsk_lcd;
 
-       eWidgetDesktop dsk(eSize(720, 576));
        dsk.setDC(my_dc);
+       dsk_lcd.setDC(my_lcd_dc);
 
-       eWindow *bla = new eWindow(&dsk);
-       
-       bla->move(ePoint(100, 100));
-       bla->resize(eSize(200, 200));
-       bla->show();
-
-       eLabel *blablub = new eLabel(bla->child());
-       blablub->setText("hello world");
-       blablub->move(ePoint(0, 0));
-       blablub->resize(eSize(400,400));
+       ePtr<gPixmap> m_pm;
+       loadPNG(m_pm, "data/pal.png");
+       if (!m_pm)
+       {
+               eFatal("hi ghost, please copy pal.png into your ./data, thanks!");
+       } else
+               dsk.setPalette(*m_pm);
 
-#if 0
-       eWidget *bla2 = new eWidget(0);
-       dsk.addRootWidget(bla2, 0);
-       
-       bla2->move(ePoint(160, 160));
-       bla2->resize(eSize(200, 200));
-       bla2->show();
+       dsk.setBackgroundColor(gRGB(0,0,0,0xFF));
 #endif
 
-       dsk.recalcClipRegions();
+               /* redrawing is done in an idle-timer, so we have to set the context */
+       dsk.setRedrawTask(main);
+       dsk_lcd.setRedrawTask(main);
 
-//     dumpRegion(bla->m_visible_region);
-//     dumpRegion(bla2->m_visible_region);
-//     dumpRegion(blablub->m_visible_region);
+       eWindow *lcd_win = new eWindow(&dsk_lcd);
        
-       eDebug("painting!");
-
-       dsk.invalidate(gRegion(eRect(0, 0, 720, 576)));
-       dsk.paint();
-#endif
+       lcd_win->setFlag(eWindow::wfNoBorder);
+       
+       lcd_win->move(ePoint(0, 0));
+       lcd_win->resize(eSize(132, 64));
+       
+       lcd_label = new eLabel(lcd_win);
+       lcd_label->move(ePoint(0, 10));
+       lcd_label->resize(eSize(132, 36));
+       ePtr<gFont> font = new gFont("Arial", 16);
+       lcd_label->setFont(font);
+
+       lcd_clock = new eLabel(lcd_win);
+       lcd_clock->move(ePoint(50, 46));
+       lcd_clock->resize(eSize(132, 20));
+       //ePtr<gFont> clkfont = new gFont("Arial", 18);
+       lcd_clock->setFont(font);
+
+       //lcd_label->setText("bla bla bla, this lcd\nSUCKS!");
+       //lcd_clock->setText("88:88:88");
+
+       lcd_win->show();
+       
+       eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
+       
+       printf("executing main\n");
 
-#else
+       python.execute("mytest", "__main__");
 
-       extern void contentTest();
+//     eApp->exec();
 
-       eDebug("Contenttest");
-       contentTest();
+       return 0;
+}
 
-#endif
+eWidgetDesktop *getDesktop()
+{
+       return wdsk;
+}
 
-       p.resetClip(gRegion(eRect(0, 0, 720, 576)));
-//     p.clear();
-       sleep(1);
-       
-//     blablub->setText("123");
-//     dumpRegion(blablub->m_visible_region);
-//     dumpRegion(dsk.m_dirty_region);
-       dsk.paint();
-       
+void runMainloop()
+{
+       eApp->exec();
+}
 
-#endif
+void quitMainloop()
+{
+       eApp->quit(0);
+}
 
-       ePython python;
-       
-       printf("about to execute TEST :)\n");
-       python.execute("mytest", "test");
+void setLCD(const char *string)
+{
+       lcd_label->setText(string);
+}
 
-       return 0;
+void setLCDClock(const char *string)
+{
+       lcd_clock->setText(string);
 }