Merge branch 'bug_514_new_proc_oled_brightness_path'
[enigma2.git] / lib / service / event.cpp
index 2d0f83a47833547a0cd74137fa6019181e637732..949e150a7a4e1a562262bf43d9c5d074165ade44 100644 (file)
 #include <dvbsi++/component_descriptor.h>
 #include <dvbsi++/descriptor_tag.h>
 
+#include <sys/types.h>
+#include <fcntl.h>
+
+// static members / methods
+std::string eServiceEvent::m_language = "de_DE";
+
+void eServiceEvent::setEPGLanguage( const std::string language )
+{
+       m_language = language;
+}
+///////////////////////////
+
 DEFINE_REF(eServiceEvent);
 DEFINE_REF(eComponentData);
 
@@ -72,9 +84,11 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid)
                                const ShortEventDescriptor *sed = (ShortEventDescriptor*)*desc;
                                const std::string &cc = sed->getIso639LanguageCode();
                                int table=encodingHandler.getCountryCodeDefaultMapping(cc);
-                               if (lang.empty() || cc == lang)
+                               if (lang.empty())
+                                       lang = cc;  // use first found language
+                               if (cc == lang)
                                {
-                                       m_event_name = convertDVBUTF8(sed->getEventName(), table, tsidonid);
+                                       m_event_name = convertDVBUTF8(replace_all(replace_all(sed->getEventName(), "\n", " "), "\t", " "), table, tsidonid);
                                        m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid);
                                        retval=1;
                                }
@@ -85,7 +99,9 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid)
                                const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc;
                                const std::string &cc = eed->getIso639LanguageCode();
                                int table=encodingHandler.getCountryCodeDefaultMapping(cc);
-                               if (lang.empty() || cc == lang)
+                               if (lang.empty())
+                                       lang = cc;  // use first found language
+                               if (cc == lang)
                                {
                                        m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid);
                                        retval=1;
@@ -138,7 +154,7 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid)
                                                dvb_ref.setOriginalNetworkID(ld->getOriginalNetworkId());
                                                dvb_ref.setServiceID(ld->getServiceId());
                                                const PrivateDataByteVector *privateData = ld->getPrivateDataBytes();
-                                               dvb_ref.name = convertDVBUTF8((const unsigned char*)&((*privateData)[0]), privateData->size(), 0, tsidonid);
+                                               dvb_ref.name = convertDVBUTF8((const unsigned char*)&((*privateData)[0]), privateData->size(), 1, tsidonid);
                                                m_linkage_services.push_back(ref);
                                        }
                                        break;
@@ -165,9 +181,8 @@ RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid)
        );
        m_event_id = evt->getEventId();
        m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration);
-       std::string country="de_DE";  // TODO use local data here
        for (int i=0; i < MAX_LANG; i++)
-               if (country==ISOtbl[i][0])
+               if (m_language==ISOtbl[i][0])
                        if (loadLanguage(evt, ISOtbl[i][1], tsidonid))
                                return 0;
        if (loadLanguage(evt, "eng", tsidonid))
@@ -177,6 +192,27 @@ RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid)
        return 0;
 }
 
+RESULT eServiceEvent::parseFrom(const std::string filename, int tsidonid)
+{
+       if (!filename.empty())
+       {
+               int fd = ::open( filename.c_str(), O_RDONLY );
+               if ( fd > -1 )
+               {
+                       __u8 buf[4096];
+                       int rd = ::read(fd, buf, 4096);
+                       ::close(fd);
+                       if ( rd > 12 /*EIT_LOOP_SIZE*/ )
+                       {
+                               Event ev(buf);
+                               parseFrom(&ev, tsidonid);
+                               return 0;
+                       }
+               }
+       }
+       return -1;
+}
+
 std::string eServiceEvent::getBeginTimeString() const
 {
        tm t;
@@ -204,6 +240,23 @@ RESULT eServiceEvent::getComponentData(ePtr<eComponentData> &dest, int tagnum) c
        return -1;
 }
 
+PyObject *eServiceEvent::getComponentData() const
+{
+       ePyObject ret = PyList_New(m_component_data.size());
+       int cnt=0;
+       for (std::list<eComponentData>::const_iterator it(m_component_data.begin()); it != m_component_data.end(); ++it)
+       {
+               ePyObject tuple = PyTuple_New(5);
+               PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(it->m_componentTag));
+               PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->m_componentType));
+               PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->m_streamContent));
+               PyTuple_SET_ITEM(tuple, 3, PyString_FromString(it->m_iso639LanguageCode.c_str()));
+               PyTuple_SET_ITEM(tuple, 4, PyString_FromString(it->m_text.c_str()));
+               PyList_SET_ITEM(ret, cnt++, tuple);
+       }
+       return ret;
+}
+
 RESULT eServiceEvent::getLinkageService(eServiceReference &service, eServiceReference &parent, int num) const
 {
        std::list<eServiceReference>::const_iterator it =
@@ -238,4 +291,9 @@ RESULT eServiceEvent::getLinkageService(eServiceReference &service, eServiceRefe
        return -1;
 }
 
+void setServiceEventLanguage(const std::string language)
+{
+       eServiceEvent::setEPGLanguage(language);
+}
+
 DEFINE_REF(eDebugClass);