you can now delete characters in the timerentry description with the mute-key
[enigma2.git] / lib / base / encoding.cpp
1 #include <lib/base/encoding.h>
2 #include <lib/base/eerror.h>
3 #include <config.h>
4
5 eDVBTextEncodingHandler encodingHandler;  // the one and only instance
6
7 eDVBTextEncodingHandler::eDVBTextEncodingHandler()
8 {
9         const char * file=DATADIR "/enigma2/encoding.conf";
10         FILE *f = fopen(file, "rt");
11         if (f)
12         {
13                 char *line = (char*) malloc(256);
14                 size_t bufsize=256;
15                 char countrycode[256];
16                 while( getline(&line, &bufsize, f) != -1 )
17                 {
18                         if ( line[0] == '#' )
19                                 continue;
20                         int tsid, onid, encoding;
21                         if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 )
22                                 m_CountryCodeDefaultMapping[countrycode]=encoding;
23                         else if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 )
24                                         ||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) )
25                                 m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding;
26                         else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 )
27                                         ||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) )
28                                 m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid);
29                         else
30                                 eDebug("couldn't parse %s", line);
31                 }
32                 fclose(f);
33                 free(line);
34         }
35         else
36                 eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file);
37 }
38
39 void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table)
40 {
41         std::map<int, int>::iterator it =
42                 m_TransponderDefaultMapping.find(tsidonid);
43         if ( it != m_TransponderDefaultMapping.end() )
44                 table = it->second;
45 }
46
47 bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid)
48 {
49         return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end();
50 }
51
52 int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code )
53 {
54         std::map<std::string, int>::iterator it =
55                 m_CountryCodeDefaultMapping.find(country_code);
56         if ( it != m_CountryCodeDefaultMapping.end() )
57                 return it->second;
58         return 0;  // ISO8859-1 / Latin1
59 }