684c9e5e93418d6aa9a7a6b3b89f434ed4522e83
[enigma2.git] / lib / service / event.cpp
1 #include <lib/service/event.h>
2 #include <lib/base/estring.h>
3 #include <lib/dvb/dvbtime.h>
4 #include <dvbsi++/event_information_section.h>
5 #include <dvbsi++/short_event_descriptor.h>
6 #include <dvbsi++/extended_event_descriptor.h>
7 #include <dvbsi++/descriptor_tag.h>
8
9 DEFINE_REF(eServiceEvent);
10
11 const char MAX_LANG = 37;
12 /* OSD language (see /share/locales/locales) to iso639 conversion table */
13 std::string ISOtbl[MAX_LANG][2] =
14 {
15         {"ar_AE","ara"},
16         {"C","eng"},
17         {"cs_CZ","ces"},     /* or 'cze' */
18         {"cs_CZ","cze"},
19         {"da_DK","dan"},
20         {"de_DE","deu"},     /* also 'ger' is valid iso639 code!! */
21         {"de_DE","ger"},
22         {"el_GR","gre"},     /* also 'ell' is valid */
23         {"el_GR","ell"},
24         {"es_ES","esl"},     /* also 'spa' is ok */
25         {"es_ES","spa"},
26         {"et_EE","est"},
27         {"fi_FI","fin"},
28         {"fr_FR","fra"},
29         {"hr_HR","hrv"},     /* or 'scr' */
30         {"hr_HR","scr"},
31         {"hu_HU","hun"},
32         {"is_IS","isl"},     /* or 'ice' */
33         {"is_IS","ice"},
34         {"it_IT","ita"},
35         {"lt_LT","lit"},
36         {"nl_NL","nld"},     /* or 'dut' */
37         {"nl_NL","dut"},
38         {"no_NO","nor"},
39         {"pl_PL","pol"},
40         {"pt_PT","por"},
41         {"ro_RO","ron"},     /* or 'rum' */
42         {"ro_RO","rum"},
43         {"ru_RU","rus"},
44         {"sk_SK","slk"},     /* or 'slo' */
45         {"sk_SK","slo"},
46         {"sl_SI","slv"},
47         {"sr_YU","srp"},     /* or 'scc' */
48         {"sr_YU","scc"},
49         {"sv_SE","swe"},
50         {"tr_TR","tur"},
51         {"ur_IN","urd"}
52 };
53
54 /* search for the presence of language from given EIT event descriptors*/
55 bool eServiceEvent::loadLanguage(Event *evt, std::string lang)
56 {
57         bool retval=0;
58         for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
59         {
60                 switch ((*desc)->getTag())
61                 {
62                         case SHORT_EVENT_DESCRIPTOR:
63                         {
64                                 const ShortEventDescriptor *sed = (ShortEventDescriptor*)*desc;
65                                 if (lang.empty() || sed->getIso639LanguageCode() == lang)
66                                 {
67                                         m_event_name = convertDVBUTF8(sed->getEventName());
68                                         m_short_description = convertDVBUTF8(sed->getText());
69                                         retval=1;
70                                 }
71                                 break;
72                         }
73                         case EXTENDED_EVENT_DESCRIPTOR:
74                         {
75                                 const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc;
76                                 if (lang.empty() || eed->getIso639LanguageCode() == lang)
77                                 {
78                                         m_extended_description += convertDVBUTF8(eed->getText());
79                                         retval=1;
80                                 }
81 #if 0
82                                 const ExtendedEventList *itemlist = eed->getItems();
83                                 for (ExtendedEventConstIterator it = itemlist->begin(); it != itemlist->end(); ++it)
84                                 {
85                                         m_extended_description += '\n';
86                                         m_extended_description += convertDVBUTF8((*it)->getItemDescription());
87                                         m_extended_description += ' ';
88                                         m_extended_description += convertDVBUTF8((*it)->getItem());
89                                 }
90 #endif
91                                 break;
92                         }
93                         default:
94                                 break;
95                 }
96         }
97         if ( m_extended_description.find(m_short_description) == 0 )
98                 m_short_description="";
99         return retval;
100 }
101
102 RESULT eServiceEvent::parseFrom(Event *evt)
103 {
104         uint16_t stime_mjd = evt->getStartTimeMjd();
105         uint32_t stime_bcd = evt->getStartTimeBcd();
106         uint32_t duration = evt->getDuration();
107         m_begin = parseDVBtime(
108                 stime_mjd >> 8,
109                 stime_mjd&0xFF,
110                 stime_bcd >> 16,
111                 (stime_bcd >> 8)&0xFF,
112                 stime_bcd & 0xFF
113         );
114         m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration);
115         std::string country="de_DE";  // TODO use local data here
116         for (int i=0; i < MAX_LANG; i++)
117                 if (country==ISOtbl[i][0])
118                         if (loadLanguage(evt,ISOtbl[i][1]))
119                                 return 0;
120         if (loadLanguage(evt,"eng"))
121                 return 0;
122         if (loadLanguage(evt,std::string()))
123                 return 0;
124         return 0;
125 }
126
127 std::string eServiceEvent::getBeginTimeString()
128 {
129         tm t;
130         localtime_r(&m_begin, &t);
131         char tmp[13];
132         snprintf(tmp, 13, "%02d.%02d, %02d:%02d",
133                 t.tm_mday, t.tm_mon+1,
134                 t.tm_hour, t.tm_min);
135         return std::string(tmp, 12);
136 }
137
138 DEFINE_REF(eDebugClass);