Stellarium 0.15.0
StelLocaleMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2006 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELLOCALEMGR_HPP_
21 #define _STELLOCALEMGR_HPP_
22 
23 #include "StelTranslator.hpp"
24 
29 {
30 public:
31  StelLocaleMgr();
32  ~StelLocaleMgr();
33 
38  void init();
39 
41  // MESSAGES TRANSLATIONS
47 
51  void setAppLanguage(const QString& newAppLangName, bool refreshAll=true);
52 
54  const StelTranslator& getAppStelTranslator() const;
55 
59  QString getSkyLanguage() const;
60 
65  void setSkyLanguage(const QString& newSkyLangName, bool refreshAll=true);
66 
68  const StelTranslator &getSkyTranslator() const;
69 
71  // DATE & TIME LOCALIZATION
80  QString getTimeFormatStr(void) const {return sTimeFormatToString(timeFormat);}
83  void setTimeFormatStr(const QString& tf) {timeFormat=stringToSTimeFormat(tf);}
92  QString getDateFormatStr(void) const {return sDateFormatToString(dateFormat);}
93  void setDateFormatStr(const QString& df) {dateFormat=stringToSDateFormat(df);}
94 
96  QString getQtDateFormatStr(void) const;
97 
101  void setCustomTimezone(QString tZ) { setCustomTzName(tZ); }
102 
105  enum STimeFormat {
109  };
110 
113  enum SDateFormat {
118  };
119 
121  QString getPrintableDateLocal(double JD) const;
122 
124  QString getPrintableTimeLocal(double JD) const;
125 
127  QString getPrintableTimeZoneLocal(double JD) const;
128 
131  {
135  };
136 
138  void setGMTShift(int t)
139  {
140  GMTShift=t;
141  }
143  float getGMTShift(double JD = 0) const;
145  void setCustomTzName(const QString& tzname);
147  QString getCustomTzName(void) const
148  {
149  return customTzName;
150  }
152  STzFormat getTzFormat(void) const
153  {
154  return timeZoneMode;
155  }
156 
159  QString getISO8601TimeLocal(double JD) const;
160 
166  double getJdFromISO8601TimeLocal(const QString& str, bool* ok) const;
167 
169  static QString countryCodeToString(const QString& countryCode);
170 
172  static QStringList getAllCountryNames();
173 
174 private:
175  // The translator used for astronomical object naming
176  StelTranslator* skyTranslator;
177 
178  // Date and time variables
179  STimeFormat timeFormat;
180  SDateFormat dateFormat;
181  STzFormat timeZoneMode; // Can be the system default or a user defined value
182 
183  QString customTzName; // Something like "Europe/Paris"
184  float GMTShift; // Time shift between GMT time and local time in hour. (positive for Est of GMT)
185 
186  // Convert the time format enum to its associated string and reverse
187  STimeFormat stringToSTimeFormat(const QString&) const;
188  QString sTimeFormatToString(STimeFormat) const;
189 
190  // Convert the date format enum to its associated string and reverse
191  SDateFormat stringToSDateFormat(const QString& df) const;
192  QString sDateFormatToString(SDateFormat df) const;
193 
194  static QMap<QString, QString> countryCodeToStringMap;
195 
196  static void generateCountryList();
197 };
198 
199 #endif // _STELLOCALEMGR_HPP_
float getGMTShift(double JD=0) const
Get the current time shift in hours at observator time zone with respect to GMT time.
const StelTranslator & getSkyTranslator() const
Get a reference to the StelTranslator object currently used for sky objects.
const QString & getTrueLocaleName() const
Get true translator locale name.
e.g. "05-07-1998" for July 5th 1998
Class used to translate strings to any language.
void setGMTShift(int t)
Get the current time shift at observator time zone with respect to GMT time.
STzFormat getTzFormat(void) const
Get the current timezone format mode.
Use the system default date format.
e.g. "07-05-1998" for July 5th 1998
double getJdFromISO8601TimeLocal(const QString &str, bool *ok) const
Return the JD time for a local time ISO 8601 format that is: Y-m-dTH:M:S, but Y can be a large number...
void setCustomTzName(const QString &tzname)
Set the timezone by a TZ-style string (see tzset in the libc manual).
void setTimeFormatStr(const QString &tf)
Set the time format from a format string.
QString getDateFormatStr(void) const
Get the format string which describes the current date format.
Manage i18n operations such as message translation and date/time localization.
use the system default format.
SDateFormat
The date display format.
static StelTranslator * globalTranslator
Used as a global translator by the whole app.
const StelTranslator & getAppStelTranslator() const
Get the StelTranslator object currently used for global application.
static QString countryCodeToString(const QString &countryCode)
Convert a 2 letter country code to string.
void setCustomTimezone(QString tZ)
Set the time zone.
QString getCustomTzName(void) const
Get the timezone name (a TZ-style string - see tzset in the libc manual).
User-specified timezone.
12 hour clock, e.g. "06:22:00 pm"
void setAppLanguage(const QString &newAppLangName, bool refreshAll=true)
Set the application language.
Define some translation macros.
QString getPrintableTimeZoneLocal(double JD) const
Get a localized, formatted string representation of the time zone of a Julian date.
STimeFormat
The time display format.
QString getTimeFormatStr(void) const
Get the format string which describes the current time format.
QString getPrintableTimeLocal(double JD) const
Get a localized, formatted string representation of the time component of a Julian date...
QString getAppLanguage() const
Get the application language currently used for GUI etc.
void init()
Initialize object.
e.g. "1998-07-05" for July 5th 1998
static QStringList getAllCountryNames()
Return an alphabetically ordered list of all the known country names.
QString getQtDateFormatStr(void) const
Get the format string which describes the current date format (Qt style).
QString getPrintableDateLocal(double JD) const
Get a localized, formatted string representation of the date component of a Julian date...
QString getSkyLanguage() const
Get the language currently used for sky objects.
24 hour clock, e.g. "18:22:00"
void setSkyLanguage(const QString &newSkyLangName, bool refreshAll=true)
Set the sky language and reload the sky object names with the new translation.
QString getISO8601TimeLocal(double JD) const
Return the time in ISO 8601 format that is : Y-m-dTH:M:S.