StelLocaleMgr.cpp   StelLocaleMgr.cpp 
skipping to change at line 30 skipping to change at line 30
#include <config.h> #include <config.h>
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include <QLocale> #include <QLocale>
#include <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QTextStream>
#include <QFile> #include <QFile>
#include <ctime>
QMap<QString, QString> StelLocaleMgr::countryCodeToStringMap; QMap<QString, QString> StelLocaleMgr::countryCodeToStringMap;
StelLocaleMgr::StelLocaleMgr() : skyTranslator(PACKAGE_NAME, INSTALL_LOCALE DIR, ""), GMTShift(0) StelLocaleMgr::StelLocaleMgr() : skyTranslator("stellarium", StelFileMgr::g etLocaleDir(), ""), GMTShift(0)
{ {
//generateCountryList(); //generateCountryList();
// Load from file // Load from file
QString path; QString path;
try try
{ {
path = StelApp::getInstance().getFileMgr().findFile("data/co untryCodes.dat"); path = StelFileMgr::findFile("data/countryCodes.dat");
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "ERROR - could not find country code data file ." << e.what(); qWarning() << "ERROR - could not find country code data file ." << e.what();
return; return;
} }
QFile file(path); QFile file(path);
file.open(QIODevice::ReadOnly); file.open(QIODevice::ReadOnly);
QDataStream in(&file); // read the data serialized from the file QDataStream in(&file); // read the data serialized from the file
in.setVersion(QDataStream::Qt_4_5);
in >> countryCodeToStringMap; in >> countryCodeToStringMap;
file.close(); file.close();
} }
StelLocaleMgr::~StelLocaleMgr() StelLocaleMgr::~StelLocaleMgr()
{} {}
// Mehtod which generates and save the map between 2 letters country code a nd english country names // Mehtod which generates and save the map between 2 letters country code a nd english country names
void StelLocaleMgr::generateCountryList() void StelLocaleMgr::generateCountryList()
{ {
// Init country codes to string using Qt data (slow) // Load ISO 3166-1 two-letter country codes from file (slow)
for (int i=1;i<165;++i) // The format is "[code][tab][country name containing spaces][newlin
{ e]"
foreach (QLocale::Country c, QLocale::countriesForLanguage(( QFile textFile("data/iso3166-1-alpha-2.utf8");
QLocale::Language)i)) textFile.open(QFile::ReadOnly | QFile::Text);
{ QTextStream list(&textFile);
QLocale ll_CC((QLocale::Language)i, c); QString line;
QString cCode = ll_CC.name().right(2).toLower(); while(!(line = list.readLine()).isNull())
countryCodeToStringMap[cCode]=QLocale::countryToStri {
ng(c); qDebug() << line.section(QChar('\t'), 0, 0) << ":" << line.s
} ection(QChar('\t'), 1, 1);
} countryCodeToStringMap.insert(line.section(QChar('\t'), 0, 0
// Add here missing Qt countries ), line.section(QChar('\t'), 1, 1));
countryCodeToStringMap["cu"]="Cuba"; }
countryCodeToStringMap["mg"]="Madagascar"; textFile.close();
countryCodeToStringMap["rs"]="Serbia";
countryCodeToStringMap["ps"]="Palestinian Territories"; // Save to binary file
countryCodeToStringMap["tm"]="Turkmenistan"; QFile binaryFile("data/countryCodes.dat");
binaryFile.open(QIODevice::WriteOnly);
// Save to file QDataStream out(&binaryFile); // save the data serialized to the
QFile file("countryCodes.dat"); file
file.open(QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_5);
QDataStream out(&file); // save the data serialized to the file
out << countryCodeToStringMap; out << countryCodeToStringMap;
file.close(); binaryFile.close();
} }
void StelLocaleMgr::init() void StelLocaleMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
setSkyLanguage(conf->value("localization/sky_locale", "system").toSt ring()); setSkyLanguage(conf->value("localization/sky_locale", "system").toSt ring());
setAppLanguage(conf->value("localization/app_locale", "system").toSt ring()); setAppLanguage(conf->value("localization/app_locale", "system").toSt ring());
skipping to change at line 130 skipping to change at line 131
} }
} }
} }
/************************************************************************* /*************************************************************************
Set the application locale. This apply to GUI, console messages etc.. Set the application locale. This apply to GUI, console messages etc..
*************************************************************************/ *************************************************************************/
void StelLocaleMgr::setAppLanguage(const QString& newAppLanguageName) void StelLocaleMgr::setAppLanguage(const QString& newAppLanguageName)
{ {
// Update the translator with new locale name // Update the translator with new locale name
StelTranslator::globalTranslator = StelTranslator(PACKAGE_NAME, Stel App::getInstance().getFileMgr().getLocaleDir(), newAppLanguageName); StelTranslator::globalTranslator = StelTranslator("stellarium", Stel FileMgr::getLocaleDir(), newAppLanguageName);
qDebug() << "Application language is " << StelTranslator::globalTran slator.getTrueLocaleName(); qDebug() << "Application language is " << StelTranslator::globalTran slator.getTrueLocaleName();
StelApp::getInstance().updateI18n(); StelApp::getInstance().updateI18n();
} }
/************************************************************************* /*************************************************************************
Set the sky language. Set the sky language.
*************************************************************************/ *************************************************************************/
void StelLocaleMgr::setSkyLanguage(const QString& newSkyLanguageName) void StelLocaleMgr::setSkyLanguage(const QString& newSkyLanguageName)
{ {
// Update the translator with new locale name // Update the translator with new locale name
skyTranslator = StelTranslator(PACKAGE_NAME, StelApp::getInstance(). getFileMgr().getLocaleDir(), newSkyLanguageName); skyTranslator = StelTranslator("stellarium", StelFileMgr::getLocaleD ir(), newSkyLanguageName);
qDebug() << "Sky language is " << skyTranslator.getTrueLocaleName(); qDebug() << "Sky language is " << skyTranslator.getTrueLocaleName();
StelApp::getInstance().updateI18n(); StelApp::getInstance().updateI18n();
} }
/************************************************************************* /*************************************************************************
Get the language currently used for sky objects.. Get the language currently used for sky objects..
*************************************************************************/ *************************************************************************/
QString StelLocaleMgr::getSkyLanguage() const QString StelLocaleMgr::getSkyLanguage() const
{ {
return skyTranslator.getTrueLocaleName(); return skyTranslator.getTrueLocaleName();
skipping to change at line 353 skipping to change at line 354
QMap<QString, QString>::ConstIterator i = countryCodeToStringMap.fin d(countryCode); QMap<QString, QString>::ConstIterator i = countryCodeToStringMap.fin d(countryCode);
return (i!=countryCodeToStringMap.end()) ? i.value() : QString(); return (i!=countryCodeToStringMap.end()) ? i.value() : QString();
} }
// Return a list of all the known country names // Return a list of all the known country names
QStringList StelLocaleMgr::getAllCountryNames() QStringList StelLocaleMgr::getAllCountryNames()
{ {
QStringList res; QStringList res;
for (QMap<QString, QString>::ConstIterator i = countryCodeToStringMa p.begin();i!=countryCodeToStringMap.end();++i) for (QMap<QString, QString>::ConstIterator i = countryCodeToStringMa p.begin();i!=countryCodeToStringMap.end();++i)
res.append(i.value()); res.append(i.value());
res.sort();
return res; return res;
} }
 End of changes. 10 change blocks. 
28 lines changed or deleted 32 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/