StelSkyCultureMgr.cpp   StelSkyCultureMgr.cpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelLocaleMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QVariant> #include <QVariant>
#include <QDebug> #include <QDebug>
#include <QMap> #include <QMap>
#include <QMapIterator> #include <QMapIterator>
#include <QDir> #include <QDir>
StelSkyCultureMgr::StelSkyCultureMgr() StelSkyCultureMgr::StelSkyCultureMgr()
{ {
setObjectName("StelSkyCultureMgr");
QSet<QString> cultureDirNames = StelFileMgr::listContents("skycultur es",StelFileMgr::Directory); QSet<QString> cultureDirNames = StelFileMgr::listContents("skycultur es",StelFileMgr::Directory);
foreach (const QString& dir, cultureDirNames) foreach (const QString& dir, cultureDirNames)
{ {
QString pdFile = StelFileMgr::findFile("skycultures/" + dir + "/info.ini"); QString pdFile = StelFileMgr::findFile("skycultures/" + dir + "/info.ini");
if (pdFile.isEmpty()) if (pdFile.isEmpty())
{ {
qWarning() << "WARNING: unable to successfully read info.ini file from skyculture dir" << QDir::toNativeSeparators(dir); qWarning() << "WARNING: unable to successfully read info.ini file from skyculture dir" << QDir::toNativeSeparators(dir);
return; return;
} }
skipping to change at line 67 skipping to change at line 70
//! Init itself from a config file. //! Init itself from a config file.
void StelSkyCultureMgr::init() void StelSkyCultureMgr::init()
{ {
defaultSkyCultureID = StelApp::getInstance().getSettings()->value("l ocalization/sky_culture", "western").toString(); defaultSkyCultureID = StelApp::getInstance().getSettings()->value("l ocalization/sky_culture", "western").toString();
setCurrentSkyCultureID(defaultSkyCultureID); setCurrentSkyCultureID(defaultSkyCultureID);
} }
//! Set the current sky culture from the passed directory //! Set the current sky culture from the passed directory
bool StelSkyCultureMgr::setCurrentSkyCultureID(const QString& cultureDir) bool StelSkyCultureMgr::setCurrentSkyCultureID(const QString& cultureDir)
{ {
//prevent unnecessary changes
if(cultureDir==currentSkyCultureDir)
return false;
// make sure culture definition exists before attempting or will die // make sure culture definition exists before attempting or will die
if (directoryToSkyCultureEnglish(cultureDir) == "") if (directoryToSkyCultureEnglish(cultureDir) == "")
{ {
qWarning() << "Invalid sky culture directory: " << QDir::toN ativeSeparators(cultureDir); qWarning() << "Invalid sky culture directory: " << QDir::toN ativeSeparators(cultureDir);
return false; return false;
} }
currentSkyCultureDir = cultureDir; currentSkyCultureDir = cultureDir;
currentSkyCulture = dirToNameEnglish[cultureDir]; currentSkyCulture = dirToNameEnglish[cultureDir];
StelApp::getInstance().updateSkyCulture();
emit currentSkyCultureChanged(currentSkyCultureDir);
return true; return true;
} }
// Set the default sky culture from the ID. // Set the default sky culture from the ID.
bool StelSkyCultureMgr::setDefaultSkyCultureID(const QString& id) bool StelSkyCultureMgr::setDefaultSkyCultureID(const QString& id)
{ {
// make sure culture definition exists before attempting or will die // make sure culture definition exists before attempting or will die
if (directoryToSkyCultureEnglish(id) == "") if (directoryToSkyCultureEnglish(id) == "")
{ {
qWarning() << "Invalid sky culture ID: " << id; qWarning() << "Invalid sky culture ID: " << id;
return false; return false;
} }
defaultSkyCultureID = id; defaultSkyCultureID = id;
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
conf->setValue("localization/sky_culture", id); conf->setValue("localization/sky_culture", id);
emit defaultSkyCultureChanged(id);
return true; return true;
} }
QString StelSkyCultureMgr::getCurrentSkyCultureNameI18() const {return q_(c urrentSkyCulture.englishName);} QString StelSkyCultureMgr::getCurrentSkyCultureNameI18() const {return q_(c urrentSkyCulture.englishName);}
QString StelSkyCultureMgr::getCurrentSkyCultureEnglishName() const {return currentSkyCulture.englishName;} QString StelSkyCultureMgr::getCurrentSkyCultureEnglishName() const {return currentSkyCulture.englishName;}
//! returns newline delimited list of human readable culture names in engli sh //! returns newline delimited list of human readable culture names in engli sh
QString StelSkyCultureMgr::getSkyCultureListEnglish(void) QString StelSkyCultureMgr::getSkyCultureListEnglish(void)
{ {
skipping to change at line 132 skipping to change at line 142
// Sort for GUI use. Note that e.g. German Umlauts are sorted after Z. TODO: Fix this! // Sort for GUI use. Note that e.g. German Umlauts are sorted after Z. TODO: Fix this!
cultures.sort(Qt::CaseInsensitive); cultures.sort(Qt::CaseInsensitive);
return cultures; return cultures;
} }
QStringList StelSkyCultureMgr::getSkyCultureListIDs(void) QStringList StelSkyCultureMgr::getSkyCultureListIDs(void)
{ {
return dirToNameEnglish.keys(); return dirToNameEnglish.keys();
} }
QString StelSkyCultureMgr::getCurrentSkyCultureHtmlDescription() const
{
QString skyCultureId = getCurrentSkyCultureID();
QString lang = StelApp::getInstance().getLocaleMgr().getAppLanguage(
);
if (!QString("pt_BR zh_CN zh_HK zh_TW").contains(lang))
{
lang = lang.split("_").at(0);
}
QString descPath = StelFileMgr::findFile("skycultures/" + skyCulture
Id + "/description."+lang+".utf8");
if (descPath.isEmpty())
{
descPath = StelFileMgr::findFile("skycultures/" + skyCulture
Id + "/description.en.utf8");
if (descPath.isEmpty())
qWarning() << "WARNING: can't find description for s
kyculture" << skyCultureId;
}
if (descPath.isEmpty())
{
return q_("No description");
}
else
{
QFile f(descPath);
QString htmlFile;
if(f.open(QIODevice::ReadOnly))
{
htmlFile = QString::fromUtf8(f.readAll());
f.close();
}
return htmlFile;
}
}
QString StelSkyCultureMgr::directoryToSkyCultureEnglish(const QString& dire ctory) QString StelSkyCultureMgr::directoryToSkyCultureEnglish(const QString& dire ctory)
{ {
return dirToNameEnglish[directory].englishName; return dirToNameEnglish[directory].englishName;
} }
QString StelSkyCultureMgr::directoryToSkyCultureI18(const QString& director y) const QString StelSkyCultureMgr::directoryToSkyCultureI18(const QString& director y) const
{ {
QString culture = dirToNameEnglish[directory].englishName; QString culture = dirToNameEnglish[directory].englishName;
if (culture=="") if (culture=="")
{ {
 End of changes. 6 change blocks. 
1 lines changed or deleted 48 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/