Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / LangInfo.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "settings/lib/ISettingCallback.h"
23 #include "utils/StdString.h"
24
25 #include <map>
26
27 #ifdef TARGET_WINDOWS
28 #ifdef GetDateFormat
29 #undef GetDateFormat
30 #endif // GetDateFormat
31 #ifdef GetTimeFormat
32 #undef GetTimeFormat
33 #endif // GetTimeFormat
34 #endif // TARGET_WINDOWS
35
36 class TiXmlNode;
37
38 class CLangInfo : public ISettingCallback
39 {
40 public:
41   CLangInfo();
42   virtual ~CLangInfo();
43
44   virtual void OnSettingChanged(const CSetting *setting);
45
46   bool Load(const std::string& strFileName, bool onlyCheckLanguage = false);
47
48   CStdString GetGuiCharSet() const;
49   CStdString GetSubtitleCharSet() const;
50
51   // three char language code (not win32 specific)
52   const CStdString& GetLanguageCode() const { return m_languageCodeGeneral; }
53
54   bool SetLanguage(const std::string &strLanguage);
55   bool CheckLoadLanguage(const std::string &language);
56
57   const CStdString& GetAudioLanguage() const;
58   // language can either be a two char language code as defined in ISO639
59   // or a three char language code
60   // or a language name in english (as used by XBMC)
61   void SetAudioLanguage(const std::string& language);
62   
63   // three char language code (not win32 specific)
64   const CStdString& GetSubtitleLanguage() const;
65   // language can either be a two char language code as defined in ISO639
66   // or a three char language code
67   // or a language name in english (as used by XBMC)
68   void SetSubtitleLanguage(const std::string& language);
69
70   const std::string GetDVDMenuLanguage() const;
71   const std::string GetDVDAudioLanguage() const;
72   const std::string GetDVDSubtitleLanguage() const;
73   const CStdString& GetTimeZone() const;
74
75   const CStdString& GetRegionLocale() const;
76   const std::string GetLanguageLocale(bool twochar = false) const;
77
78   bool ForceUnicodeFont() const { return m_currentRegion->m_forceUnicodeFont; }
79
80   const CStdString& GetDateFormat(bool bLongDate=false) const;
81
82   typedef enum _MERIDIEM_SYMBOL
83   {
84     MERIDIEM_SYMBOL_PM=0,
85     MERIDIEM_SYMBOL_AM,
86     MERIDIEM_SYMBOL_MAX
87   } MERIDIEM_SYMBOL;
88
89   const CStdString& GetTimeFormat() const;
90   const CStdString& GetMeridiemSymbol(MERIDIEM_SYMBOL symbol) const;
91
92   typedef enum _TEMP_UNIT
93   {
94     TEMP_UNIT_FAHRENHEIT=0,
95     TEMP_UNIT_KELVIN,
96     TEMP_UNIT_CELSIUS,
97     TEMP_UNIT_REAUMUR,
98     TEMP_UNIT_RANKINE,
99     TEMP_UNIT_ROMER,
100     TEMP_UNIT_DELISLE,
101     TEMP_UNIT_NEWTON
102   } TEMP_UNIT;
103
104   const CStdString& GetTempUnitString() const;
105   CLangInfo::TEMP_UNIT GetTempUnit() const;
106
107
108   typedef enum _SPEED_UNIT
109   {
110     SPEED_UNIT_KMH=0, // kilemetre per hour
111     SPEED_UNIT_MPMIN, // metres per minute
112     SPEED_UNIT_MPS, // metres per second
113     SPEED_UNIT_FTH, // feet per hour
114     SPEED_UNIT_FTMIN, // feet per minute
115     SPEED_UNIT_FTS, // feet per second
116     SPEED_UNIT_MPH, // miles per hour
117     SPEED_UNIT_KTS, // knots
118     SPEED_UNIT_BEAUFORT, // beaufort
119     SPEED_UNIT_INCHPS, // inch per second
120     SPEED_UNIT_YARDPS, // yard per second
121     SPEED_UNIT_FPF // Furlong per Fortnight
122   } SPEED_UNIT;
123
124   const CStdString& GetSpeedUnitString() const;
125   CLangInfo::SPEED_UNIT GetSpeedUnit() const;
126
127   void GetRegionNames(CStdStringArray& array);
128   void SetCurrentRegion(const CStdString& strName);
129   const CStdString& GetCurrentRegion() const;
130
131   static bool CheckLanguage(const std::string& language);
132
133   static void LoadTokens(const TiXmlNode* pTokens, std::vector<CStdString>& vecTokens);
134
135   static void SettingOptionsLanguagesFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
136   static void SettingOptionsStreamLanguagesFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
137   static void SettingOptionsRegionsFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
138
139 protected:
140   void SetDefaults();
141
142   class CRegion
143   {
144   public:
145     CRegion(const CRegion& region);
146     CRegion();
147     virtual ~CRegion();
148     void SetDefaults();
149     void SetTempUnit(const CStdString& strUnit);
150     void SetSpeedUnit(const CStdString& strUnit);
151     void SetTimeZone(const CStdString& strTimeZone);
152     void SetGlobalLocale();
153     CStdString m_strGuiCharSet;
154     CStdString m_strSubtitleCharSet;
155     CStdString m_strDVDMenuLanguage;
156     CStdString m_strDVDAudioLanguage;
157     CStdString m_strDVDSubtitleLanguage;
158     CStdString m_strLangLocaleName;
159     std::string m_strLangLocaleCodeTwoChar;
160     CStdString m_strRegionLocaleName;
161     bool m_forceUnicodeFont;
162     CStdString m_strName;
163     CStdString m_strDateFormatLong;
164     CStdString m_strDateFormatShort;
165     CStdString m_strTimeFormat;
166     CStdString m_strMeridiemSymbols[MERIDIEM_SYMBOL_MAX];
167     CStdString m_strTimeZone;
168
169     TEMP_UNIT m_tempUnit;
170     SPEED_UNIT m_speedUnit;
171   };
172
173
174   typedef std::map<CStdString, CRegion> MAPREGIONS;
175   typedef std::map<CStdString, CRegion>::iterator ITMAPREGIONS;
176   typedef std::pair<CStdString, CRegion> PAIR_REGIONS;
177   MAPREGIONS m_regions;
178   CRegion* m_currentRegion; // points to the current region
179   CRegion m_defaultRegion; // default, will be used if no region available via langinfo.xml
180
181   CStdString m_audioLanguage;
182   CStdString m_subtitleLanguage;
183   // this is the general (not win32-specific) three char language code
184   CStdString m_languageCodeGeneral;
185 };
186
187
188 extern CLangInfo g_langInfo;