fix: fd leaked when reading recordings.epl
[enigma2.git] / main / enigma.cpp
index 217d71b6e77b41fce0950a23088fed3b08413c48..a370d55c480a227e22651ce7f04f6b1d14573ed4 100644 (file)
@@ -1,35 +1,37 @@
+#ifdef WITH_SDL
 #define SDLDC
 #define SDLDC
+#endif
+
 #include <stdio.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <libsig_comp.h>
 #include <libsig_comp.h>
+
+#include <lib/actions/action.h>
+#include <lib/driver/rc.h>
 #include <lib/base/ebase.h>
 #include <lib/base/eerror.h>
 #include <lib/base/init.h>
 #include <lib/base/init_num.h>
 #include <lib/base/ebase.h>
 #include <lib/base/eerror.h>
 #include <lib/base/init.h>
 #include <lib/base/init_num.h>
-
-#include <unistd.h>
-
-#include <lib/gdi/grc.h>
 #include <lib/gdi/gfbdc.h>
 #include <lib/gdi/gfbdc.h>
+#include <lib/gdi/glcddc.h>
+#include <lib/gdi/grc.h>
+#ifdef WITH_SDL
 #include <lib/gdi/sdl.h>
 #include <lib/gdi/sdl.h>
+#endif
+#include <lib/gdi/epng.h>
 #include <lib/gdi/font.h> 
 #include <lib/gdi/font.h> 
-
+#include <lib/gui/ebutton.h>
+#include <lib/gui/elabel.h>
+#include <lib/gui/elistboxcontent.h>
 #include <lib/gui/ewidget.h>
 #include <lib/gui/ewidgetdesktop.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/gui/ewindow.h>
-
-#include <lib/python/python.h>
 #include <lib/python/connections.h>
 #include <lib/python/connections.h>
+#include <lib/python/python.h>
 
 
-#include <lib/gui/elistboxcontent.h>
-
-#include <lib/driver/rc.h>
-
-#include <lib/actions/action.h>
-
-#include <lib/gdi/epng.h>
+#ifdef HAVE_GSTREAMER
+#include <gst/gst.h>
+#endif
 
 #ifdef OBJECT_DEBUG
 int object_total_remaining;
 
 #ifdef OBJECT_DEBUG
 int object_total_remaining;
@@ -45,6 +47,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());
        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)
        for (int y=0; y<region.extends.bottom(); ++y)
        {
                for (int x=0; x<region.extends.right(); ++x)
@@ -57,9 +60,11 @@ void dumpRegion(const gRegion &region)
                }
                fprintf(stderr, "\n");
        }
                }
                fprintf(stderr, "\n");
        }
+#endif
+
 }
 
 }
 
-eWidgetDesktop *wdsk;
+eWidgetDesktop *wdsk, *lcddsk;
 
 // typedef struct _object PyObject;
 
 
 // typedef struct _object PyObject;
 
@@ -90,6 +95,8 @@ void keyEvent(const eRCKey &key)
 #include <lib/dvb/idvb.h>
 #include <lib/dvb/dvb.h>
 #include <lib/dvb/db.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
 {
 
 class eMain: public eApplication, public Object
 {
@@ -97,9 +104,10 @@ class eMain: public eApplication, public Object
        
        ePtr<eDVBResourceManager> m_mgr;
        ePtr<eDVBDB> m_dvbdb;
        
        ePtr<eDVBResourceManager> m_mgr;
        ePtr<eDVBDB> m_dvbdb;
-
+       ePtr<eDVBLocalTimeHandler> m_locale_time_handler;
        ePtr<eComponentScan> m_scan;
        ePtr<eComponentScan> m_scan;
-       
+       ePtr<eEPGCache> m_epgcache;
+
 public:
        eMain()
        {
 public:
        eMain()
        {
@@ -108,22 +116,21 @@ public:
                                /* TODO: put into init */
                m_dvbdb = new eDVBDB();
                m_mgr = new eDVBResourceManager();
                                /* 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_mgr->setChannelList(m_dvbdb);
-               
-//             m_scan = new eComponentScan();
-//             m_scan->start();
-
        }
        
        ~eMain()
        {
        }
        
        ~eMain()
        {
+               m_dvbdb->saveServicelist();
                m_scan = 0;
        }
 };
 
 /************************************************/
 
                m_scan = 0;
        }
 };
 
 /************************************************/
 
+int exit_code;
 
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
@@ -131,10 +138,18 @@ int main(int argc, char **argv)
        atexit(object_dump);
 #endif
 
        atexit(object_dump);
 #endif
 
+#ifdef HAVE_GSTREAMER
+       gst_init(&argc, &argv);
+#endif
+
+       // set pythonpath if unset
+       setenv("PYTHONPATH", LIBDIR "/enigma2/python", 0);
+       printf("PYTHONPATH: %s\n", getenv("PYTHONPATH"));
+
 
        ePython python;
        eMain main;
 
        ePython python;
        eMain main;
-
+       
 #if 1
 #ifdef SDLDC
        ePtr<gSDLDC> my_dc;
 #if 1
 #ifdef SDLDC
        ePtr<gSDLDC> my_dc;
@@ -142,22 +157,45 @@ int main(int argc, char **argv)
 #else
        ePtr<gFBDC> my_dc;
        gFBDC::getInstance(my_dc);
 #else
        ePtr<gFBDC> my_dc;
        gFBDC::getInstance(my_dc);
+       
+       int double_buffer = my_dc->haveDoubleBuffering();
 #endif
 
 #endif
 
-       fontRenderClass::getInstance()->AddFont("/home/tmbinc/enigma2/fonts/arial.ttf", "Arial", 100);
+       ePtr<gLCDDC> my_lcd_dc;
+       gLCDDC::getInstance(my_lcd_dc);
+
+       fontRenderClass::getInstance()->AddFont(FONTDIR "/md_khmurabi_10.ttf", "Regular", 100);
+       fontRenderClass::getInstance()->AddFont(FONTDIR "/ae_AlMateen.ttf", "Replacement", 90);
+       eTextPara::setReplacementFont("Replacement");
+       
+                       /* some characters are wrong in the regular font, force them to use the replacement font */
+       for (int i = 0x60c; i <= 0x66d; ++i)
+               eTextPara::forceReplacementGlyph(i);
+       eTextPara::forceReplacementGlyph(0xfdf2);
+       for (int i = 0xfe80; i < 0xff00; ++i)
+               eTextPara::forceReplacementGlyph(i);
+       
 
        eWidgetDesktop dsk(eSize(720, 576));
 
        eWidgetDesktop dsk(eSize(720, 576));
+       eWidgetDesktop dsk_lcd(eSize(132, 64));
+       
+/*     if (double_buffer)
+       {
+               eDebug(" - double buffering found, enable buffered graphics mode.");
+               dsk.setCompositionMode(eWidgetDesktop::cmBuffered);
+       } */
        
        wdsk = &dsk;
        
        wdsk = &dsk;
-
+       lcddsk = &dsk_lcd;
 
        dsk.setDC(my_dc);
 
        dsk.setDC(my_dc);
+       dsk_lcd.setDC(my_lcd_dc);
 
        ePtr<gPixmap> m_pm;
 
        ePtr<gPixmap> m_pm;
-       loadPNG(m_pm, "data/pal.png");
+       loadPNG(m_pm, DATADIR "/enigma2/pal.png");
        if (!m_pm)
        {
        if (!m_pm)
        {
-               eFatal("hi ghost, please copy pal.png into your ./data, thanks!");
+               eFatal("pal.png not found!");
        } else
                dsk.setPalette(*m_pm);
 
        } else
                dsk.setPalette(*m_pm);
 
@@ -166,29 +204,52 @@ int main(int argc, char **argv)
 
                /* redrawing is done in an idle-timer, so we have to set the context */
        dsk.setRedrawTask(main);
 
                /* redrawing is done in an idle-timer, so we have to set the context */
        dsk.setRedrawTask(main);
-       
+       dsk_lcd.setRedrawTask(main);
+
        eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
        
        printf("executing main\n");
 
        python.execute("mytest", "__main__");
        eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
        
        printf("executing main\n");
 
        python.execute("mytest", "__main__");
+       
+       dsk.paint();
+       dsk_lcd.paint();
 
 
-//     eApp->exec();
+       {
+               gPainter p(my_lcd_dc);
+               p.resetClip(eRect(0, 0, 132, 64));
+               p.clear();
+               p.flush();
+       }
 
 
-       return 0;
+       return exit_code;
 }
 
 }
 
-eWidgetDesktop *getDesktop()
+eWidgetDesktop *getDesktop(int which)
 {
 {
-       return wdsk;
+       return which ? lcddsk : wdsk;
+}
+
+eApplication *getApplication()
+{
+       return eApp;
 }
 
 void runMainloop()
 {
 }
 
 void runMainloop()
 {
-       eApp->exec();
+       eApp->runLoop();
 }
 
 }
 
-void quitMainloop()
+void quitMainloop(int exitCode)
 {
 {
+       exit_code = exitCode;
        eApp->quit(0);
 }
        eApp->quit(0);
 }
+
+void setLCD(const char *string)
+{
+}
+
+void setLCDClock(const char *string)
+{
+}