Merge pull request #1445 from Karlson2k/win32_xml_fix
[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/ISettingCallback.h"
23 #include "utils/StdString.h"
24
25 #include <map>
26
27 class TiXmlNode;
28
29 class CLangInfo : public ISettingCallback
30 {
31 public:
32   CLangInfo();
33   virtual ~CLangInfo();
34
35   virtual void OnSettingChanged(const CSetting *setting);
36
37   bool Load(const CStdString& strFileName);
38
39   CStdString GetGuiCharSet() const;
40   CStdString GetSubtitleCharSet() const;
41
42   // three char language code (not win32 specific)
43   const CStdString& GetLanguageCode() const { return m_languageCodeGeneral; }
44
45   bool SetLanguage(const std::string &strLanguage);
46
47   const CStdString& GetAudioLanguage() const;
48   // language can either be a two char language code as defined in ISO639
49   // or a three char language code
50   // or a language name in english (as used by XBMC)
51   void SetAudioLanguage(const CStdString &language);
52   
53   // three char language code (not win32 specific)
54   const CStdString& GetSubtitleLanguage() const;
55   // language can either be a two char language code as defined in ISO639
56   // or a three char language code
57   // or a language name in english (as used by XBMC)
58   void SetSubtitleLanguage(const CStdString &language);
59
60   const CStdString& GetDVDMenuLanguage() const;
61   const CStdString& GetDVDAudioLanguage() const;
62   const CStdString& GetDVDSubtitleLanguage() const;
63   const CStdString& GetTimeZone() const;
64
65   const CStdString& GetRegionLocale() const;
66   const CStdString& GetLanguageLocale() const;
67
68   bool ForceUnicodeFont() const { return m_currentRegion->m_forceUnicodeFont; }
69
70   const CStdString& GetDateFormat(bool bLongDate=false) const;
71
72   typedef enum _MERIDIEM_SYMBOL
73   {
74     MERIDIEM_SYMBOL_PM=0,
75     MERIDIEM_SYMBOL_AM,
76     MERIDIEM_SYMBOL_MAX
77   } MERIDIEM_SYMBOL;
78
79   const CStdString& GetTimeFormat() const;
80   const CStdString& GetMeridiemSymbol(MERIDIEM_SYMBOL symbol) const;
81
82   typedef enum _TEMP_UNIT
83   {
84     TEMP_UNIT_FAHRENHEIT=0,
85     TEMP_UNIT_KELVIN,
86     TEMP_UNIT_CELSIUS,
87     TEMP_UNIT_REAUMUR,
88     TEMP_UNIT_RANKINE,
89     TEMP_UNIT_ROMER,
90     TEMP_UNIT_DELISLE,
91     TEMP_UNIT_NEWTON
92   } TEMP_UNIT;
93
94   const CStdString& GetTempUnitString() const;
95   CLangInfo::TEMP_UNIT GetTempUnit() const;
96
97
98   typedef enum _SPEED_UNIT
99   {
100     SPEED_UNIT_KMH=0, // kilemetre per hour
101     SPEED_UNIT_MPMIN, // metres per minute
102     SPEED_UNIT_MPS, // metres per second
103     SPEED_UNIT_FTH, // feet per hour
104     SPEED_UNIT_FTMIN, // feet per minute
105     SPEED_UNIT_FTS, // feet per second
106     SPEED_UNIT_MPH, // miles per hour
107     SPEED_UNIT_KTS, // knots
108     SPEED_UNIT_BEAUFORT, // beaufort
109     SPEED_UNIT_INCHPS, // inch per second
110     SPEED_UNIT_YARDPS, // yard per second
111     SPEED_UNIT_FPF // Furlong per Fortnight
112   } SPEED_UNIT;
113
114   const CStdString& GetSpeedUnitString() const;
115   CLangInfo::SPEED_UNIT GetSpeedUnit() const;
116
117   void GetRegionNames(CStdStringArray& array);
118   void SetCurrentRegion(const CStdString& strName);
119   const CStdString& GetCurrentRegion() const;
120
121   static void LoadTokens(const TiXmlNode* pTokens, std::vector<CStdString>& vecTokens);
122
123   static void SettingOptionsLanguagesFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
124   static void SettingOptionsStreamLanguagesFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
125   static void SettingOptionsRegionsFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current);
126
127 protected:
128   void SetDefaults();
129
130   class CRegion
131   {
132   public:
133     CRegion(const CRegion& region);
134     CRegion();
135     virtual ~CRegion();
136     void SetDefaults();
137     void SetTempUnit(const CStdString& strUnit);
138     void SetSpeedUnit(const CStdString& strUnit);
139     void SetTimeZone(const CStdString& strTimeZone);
140     void SetGlobalLocale();
141     CStdString m_strGuiCharSet;
142     CStdString m_strSubtitleCharSet;
143     CStdString m_strDVDMenuLanguage;
144     CStdString m_strDVDAudioLanguage;
145     CStdString m_strDVDSubtitleLanguage;
146     CStdString m_strLangLocaleName;
147     CStdString m_strRegionLocaleName;
148     bool m_forceUnicodeFont;
149     CStdString m_strName;
150     CStdString m_strDateFormatLong;
151     CStdString m_strDateFormatShort;
152     CStdString m_strTimeFormat;
153     CStdString m_strMeridiemSymbols[MERIDIEM_SYMBOL_MAX];
154     CStdString m_strTimeZone;
155
156     TEMP_UNIT m_tempUnit;
157     SPEED_UNIT m_speedUnit;
158   };
159
160
161   typedef std::map<CStdString, CRegion> MAPREGIONS;
162   typedef std::map<CStdString, CRegion>::iterator ITMAPREGIONS;
163   typedef std::pair<CStdString, CRegion> PAIR_REGIONS;
164   MAPREGIONS m_regions;
165   CRegion* m_currentRegion; // points to the current region
166   CRegion m_defaultRegion; // default, will be used if no region available via langinfo.xml
167
168   CStdString m_audioLanguage;
169   CStdString m_subtitleLanguage;
170   // this is the general (not win32-specific) three char language code
171   CStdString m_languageCodeGeneral;
172 };
173
174
175 extern CLangInfo g_langInfo;