add function to get a comparable service reference string (useable to
[enigma2.git] / main / enigma.cpp
index b6c5730..5a22110 100644 (file)
@@ -1,46 +1,40 @@
-#undef WITH_SDL
-
 #ifdef WITH_SDL
-#error
 #define SDLDC
 #endif
 
 #include <stdio.h>
+#include <unistd.h>
 #include <libsig_comp.h>
+
+#include <lib/actions/action.h>
+#include <lib/driver/rc.h>
+#include <lib/base/ioprio.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/glcddc.h>
-
+#include <lib/gdi/grc.h>
 #ifdef WITH_SDL
-#error
 #include <lib/gdi/sdl.h>
 #endif
+#include <lib/gdi/epng.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/elabel.h>
-#include <lib/gui/ebutton.h>
-
 #include <lib/gui/ewindow.h>
-
-#include <lib/python/python.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 "bsod.h" 
 
-#include <lib/gdi/epng.h>
+#ifdef HAVE_GSTREAMER
+#include <gst/gst.h>
+#endif
 
 #ifdef OBJECT_DEBUG
 int object_total_remaining;
@@ -51,51 +45,28 @@ void object_dump()
 }
 #endif
 
-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)
-               {
-                       unsigned char res = ' ';
-                       for (unsigned int i=0; i < region.rects.size(); ++i)
-                               if (region.rects[i].contains(ePoint(x, y)))
-                                       res = '0' + i;
-                       fprintf(stderr, "%c", res);
-               }
-               fprintf(stderr, "\n");
-       }
-#endif
-
-}
+static eWidgetDesktop *wdsk, *lcddsk;
 
-eWidgetDesktop *wdsk, *lcddsk;
+static int prev_ascii_code;
 
-// 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()
+int getPrevAsciiCode()
 {
-       return keyPressed;
+       int ret = prev_ascii_code;
+       prev_ascii_code = 0;
+       return ret;
 }
 
 void keyEvent(const eRCKey &key)
 {
        ePtr<eActionMap> ptr;
        eActionMap::getInstance(ptr);
-       ptr->keyPressed(0, key.code, key.flags);
-//     if (!key.flags)
-//             keyPressed(key.code);
+       if (key.flags & eRCKey::flagAscii)
+       {
+               prev_ascii_code = key.code;
+               ptr->keyPressed(0, 510 /* faked KEY_ASCII */, 0);
+       }
+       else
+               ptr->keyPressed(0, key.code, key.flags);
 }
 
 /************************************************/
@@ -128,41 +99,40 @@ public:
                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_dvbdb->saveServicelist();
                m_scan = 0;
        }
 };
 
-/************************************************/
-
-eLabel *lcd_label, *lcd_clock;
-
 int exit_code;
 
 int main(int argc, char **argv)
 {
+#ifdef MEMLEAK_CHECK
+       atexit(DumpUnfreed);
+#endif
+
 #ifdef OBJECT_DEBUG
        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"));
-
+       
+       bsodLogInit();
 
        ePython python;
        eMain main;
        
-       int double_buffer = 0;
-
 #if 1
 #ifdef SDLDC
        ePtr<gSDLDC> my_dc;
@@ -171,13 +141,21 @@ int main(int argc, char **argv)
        ePtr<gFBDC> my_dc;
        gFBDC::getInstance(my_dc);
        
-       double_buffer = my_dc->haveDoubleBuffering();
+       int double_buffer = my_dc->haveDoubleBuffering();
 #endif
 
        ePtr<gLCDDC> my_lcd_dc;
        gLCDDC::getInstance(my_lcd_dc);
 
-       fontRenderClass::getInstance()->AddFont(FONTDIR "/md_khmurabi_10.ttf", "Regular", 100);
+
+               /* ok, this is currently hardcoded for arabic. */
+                       /* 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_lcd(eSize(132, 64));
@@ -209,63 +187,56 @@ int main(int argc, char **argv)
        dsk.setRedrawTask(main);
        dsk_lcd.setRedrawTask(main);
 
-       eWindow *lcd_win = new eWindow(&dsk_lcd);
-       
-       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, 4));
-       lcd_label->resize(eSize(132, 42));
-       ePtr<gFont> font = new gFont("Regular", 19);
-       //ePtr<gFont> font = new gFont("Regular", 16);
-       lcd_label->setFont(font);
-
-       lcd_clock = new eLabel(lcd_win);
-       lcd_clock->move(ePoint(50, 46));
-       lcd_clock->resize(eSize(132, 18));
-       ePtr<gFont> clkfont = new gFont("Regular", 16);
-       lcd_clock->setFont(clkfont);
-
-       //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");
+       
+       bsodCatchSignals();
+
+       setIoPrio(IOPRIO_CLASS_BE, 3);
 
        python.execute("mytest", "__main__");
+       
+       if (exit_code == 5) /* python crash */
+               bsodFatal();
+       
+       dsk.paint();
+       dsk_lcd.paint();
 
-//     eApp->exec();
+       {
+               gPainter p(my_lcd_dc);
+               p.resetClip(eRect(0, 0, 132, 64));
+               p.clear();
+               p.flush();
+       }
 
        return exit_code;
 }
 
-eWidgetDesktop *getDesktop()
+eWidgetDesktop *getDesktop(int which)
 {
-       return wdsk;
+       return which ? lcddsk : wdsk;
 }
 
-void runMainloop()
+eApplication *getApplication()
 {
-       exit_code = eApp->exec();
+       return eApp;
 }
 
-void quitMainloop(int exitCode)
+void runMainloop()
 {
-       eApp->quit(exitCode);
+       eApp->runLoop();
 }
 
-void setLCD(const char *string)
+void quitMainloop(int exitCode)
 {
-       lcd_label->setText(string);
+       exit_code = exitCode;
+       eApp->quit(0);
 }
 
-void setLCDClock(const char *string)
+void addFont(const char *filename, const char *alias, int scale_factor, int is_replacement)
 {
-       lcd_clock->setText(string);
+       fontRenderClass::getInstance()->AddFont(filename, alias, scale_factor);
+       if (is_replacement)
+               eTextPara::setReplacementFont(alias);
 }