3
* Copyright (C) 2006 Fabien Chereau
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "StelSkyCultureMgr.hpp"
21
#include "StelFileMgr.hpp"
22
#include "Translator.hpp"
23
#include "InitParser.hpp"
24
#include "StelApp.hpp"
32
StelSkyCultureMgr::StelSkyCultureMgr()
34
QSet<QString> cultureDirNames;
35
StelFileMgr& fileMan(StelApp::getInstance().getFileMgr());
39
cultureDirNames = fileMan.listContents("skycultures",StelFileMgr::DIRECTORY);
43
cerr << "ERROR while trying list sky cultures:" << e.what() << endl;
46
for(QSet<QString>::iterator dir=cultureDirNames.begin(); dir!=cultureDirNames.end(); dir++)
51
pd.load(fileMan.findFile("skycultures/" + *dir + "/info.ini"));
52
dirToNameEnglish[*dir] = pd.get_str("info:name");
56
qWarning() << "WARNING: unable to successfully read info.ini file from skyculture dir" << *dir;
62
StelSkyCultureMgr::~StelSkyCultureMgr()
67
//! Init itself from a config file.
68
void StelSkyCultureMgr::init(const InitParser& conf)
70
QString tmp = conf.get_str("localization", "sky_culture", "western").c_str();
71
setSkyCultureDir(tmp);
74
//! Set the current sky culture from the passed directory
75
bool StelSkyCultureMgr::setSkyCultureDir(const QString& cultureDir)
77
// make sure culture definition exists before attempting or will die
78
if(directoryToSkyCultureEnglish(cultureDir) == "")
80
qWarning() << "Invalid sky culture directory: " << cultureDir;
83
skyCultureDir = cultureDir;
84
StelApp::getInstance().updateSkyCulture();
88
//! returns newline delimited list of human readable culture names in english
89
string StelSkyCultureMgr::getSkyCultureListEnglish(void)
92
for ( map<QString, string>::const_iterator iter = dirToNameEnglish.begin(); iter != dirToNameEnglish.end(); ++iter )
94
cultures += iter->second + "\n";
99
//! returns newline delimited list of human readable culture names translated to current locale
100
wstring StelSkyCultureMgr::getSkyCultureListI18(void)
103
for ( map<QString, string>::const_iterator iter = dirToNameEnglish.begin(); iter != dirToNameEnglish.end(); ++iter )
105
if (iter != dirToNameEnglish.begin()) cultures += L"\n";
106
cultures += _(iter->second);
108
//wcout << cultures << endl;
112
//! returns newline delimited hash of human readable culture names translated to current locale
113
//! and the directory names
114
wstring StelSkyCultureMgr::getSkyCultureHash(void) const
117
for ( map<QString, string>::const_iterator iter = dirToNameEnglish.begin(); iter != dirToNameEnglish.end(); ++iter )
120
// weed out invalid hash entries from invalid culture lookups in hash
121
// TODO how to keep hash clean in the first place
122
if(iter->second == "") continue;
124
cultures += _(iter->second);
125
cultures += wstring(L"\n") + (iter->first).toStdWString() + L"\n";
127
// wcout << cultures << endl;
131
wstring StelSkyCultureMgr::getSkyCulture() const
133
return directoryToSkyCultureI18(skyCultureDir);
137
string StelSkyCultureMgr::directoryToSkyCultureEnglish(const QString& directory)
139
return dirToNameEnglish[directory];
142
wstring StelSkyCultureMgr::directoryToSkyCultureI18(const QString& directory) const
144
map<QString, string>::const_iterator i = dirToNameEnglish.find(directory);
145
if (i==dirToNameEnglish.end())
147
qWarning() << "WARNING: StelSkyCultureMgr::directoryToSkyCultureI18(\""
148
<< directory << "\"): could not find directory";
155
QString StelSkyCultureMgr::skyCultureToDirectory(const wstring& cultureName)
157
for ( map<QString, string>::const_iterator iter = dirToNameEnglish.begin(); iter != dirToNameEnglish.end(); ++iter )
159
if (_(iter->second) == cultureName) return iter->first;