new fontsize in servicelist
[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                                 const ExtendedEventList *itemlist = eed->getItems();
82                                 for (ExtendedEventConstIterator it = itemlist->begin(); it != itemlist->end(); ++it)
83                                 {
84                                         m_extended_description += convertDVBUTF8((*it)->getItemDescription());
85                                         m_extended_description += ' ';
86                                         m_extended_description += convertDVBUTF8((*it)->getItem());
87                                 }
88                                 break;
89                         }
90                         default:
91                                 break;
92                 }
93         }
94         return retval;
95 }
96
97 RESULT eServiceEvent::parseFrom(Event *evt)
98 {
99         uint16_t stime_mjd = evt->getStartTimeMjd();
100         uint32_t stime_bcd = evt->getStartTimeBcd();
101         uint32_t duration = evt->getDuration();
102         m_begin = parseDVBtime(
103                 stime_mjd >> 8,
104                 stime_mjd&0xFF,
105                 stime_bcd >> 16,
106                 (stime_bcd >> 8)&0xFF,
107                 stime_bcd & 0xFF
108         );
109         m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration);
110         std::string country="de_DE";  // TODO use local data here
111         for (int i=0; i < MAX_LANG; i++)
112                 if (country==ISOtbl[i][0])
113                         if (loadLanguage(evt,ISOtbl[i][1]))
114                                 return 0;
115         if (loadLanguage(evt,"eng"))
116                 return 0;
117         if (loadLanguage(evt,std::string()))
118                 return 0;
119         return 0;
120 }
121
122 std::string eServiceEvent::getBeginTimeString()
123 {
124         tm t;
125         localtime_r(&m_begin, &t);
126         char tmp[13];
127         snprintf(tmp, 13, "%02d.%02d, %02d:%02d",
128                 t.tm_mday, t.tm_mon+1,
129                 t.tm_hour, t.tm_min);
130         return std::string(tmp, 12);
131 }
132
133 DEFINE_REF(eDebugClass);