Exoplanets.cpp   Exoplanets.cpp 
skipping to change at line 193 skipping to change at line 193
// A timer for hiding alert messages // A timer for hiding alert messages
messageTimer = new QTimer(this); messageTimer = new QTimer(this);
messageTimer->setSingleShot(true); // recurring check for update messageTimer->setSingleShot(true); // recurring check for update
messageTimer->setInterval(9000); // 6 seconds should be enough time messageTimer->setInterval(9000); // 6 seconds should be enough time
messageTimer->stop(); messageTimer->stop();
connect(messageTimer, SIGNAL(timeout()), this, SLOT(messageTimeout() )); connect(messageTimer, SIGNAL(timeout()), this, SLOT(messageTimeout() ));
// If the json file does not already exist, create it from the resou rce in the Qt resource // If the json file does not already exist, create it from the resou rce in the Qt resource
if(QFileInfo(jsonCatalogPath).exists()) if(QFileInfo(jsonCatalogPath).exists())
{ {
if (getJsonFileFormatVersion() < CATALOG_FORMAT_VERSION) if (!checkJsonFileFormat() || getJsonFileFormatVersion()<CAT ALOG_FORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Exoplanets::init exoplanets.json does not exist - copying default file to " << QDir::toNativeSeparators(jsonCatalogPath); qDebug() << "Exoplanets::init exoplanets.json does not exist - copying default file to " << QDir::toNativeSeparators(jsonCatalogPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
skipping to change at line 543 skipping to change at line 543
} }
} }
int Exoplanets::getJsonFileFormatVersion(void) int Exoplanets::getJsonFileFormatVersion(void)
{ {
int jsonVersion = -1; int jsonVersion = -1;
QFile jsonEPCatalogFile(jsonCatalogPath); QFile jsonEPCatalogFile(jsonCatalogPath);
if (!jsonEPCatalogFile.open(QIODevice::ReadOnly)) if (!jsonEPCatalogFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Exoplanets::init cannot open " << QDir::toNat iveSeparators(jsonCatalogPath); qWarning() << "Exoplanets::getJsonFileFormatVersion() cannot open " << QDir::toNativeSeparators(jsonCatalogPath);
return jsonVersion; return jsonVersion;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&jsonEPCatalogFile).toMap(); map = StelJsonParser::parse(&jsonEPCatalogFile).toMap();
jsonEPCatalogFile.close();
if (map.contains("version")) if (map.contains("version"))
{ {
jsonVersion = map.value("version").toInt(); jsonVersion = map.value("version").toInt();
} }
jsonEPCatalogFile.close();
qDebug() << "Exoplanets::getJsonFileFormatVersion() version of forma t from file:" << jsonVersion; qDebug() << "Exoplanets::getJsonFileFormatVersion() version of forma t from file:" << jsonVersion;
return jsonVersion; return jsonVersion;
} }
bool Exoplanets::checkJsonFileFormat()
{
QFile jsonEPCatalogFile(jsonCatalogPath);
if (!jsonEPCatalogFile.open(QIODevice::ReadOnly))
{
qWarning() << "Exoplanets::checkJsonFileFormat(): cannot ope
n " << QDir::toNativeSeparators(jsonCatalogPath);
return false;
}
QVariantMap map;
try
{
map = StelJsonParser::parse(&jsonEPCatalogFile).toMap();
jsonEPCatalogFile.close();
}
catch (std::runtime_error& e)
{
qDebug() << "Exoplanets::checkJsonFileFormat(): file format
is wrong!";
qDebug() << "Exoplanets::checkJsonFileFormat() error:" << e.
what();
return false;
}
return true;
}
ExoplanetP Exoplanets::getByID(const QString& id) ExoplanetP Exoplanets::getByID(const QString& id)
{ {
foreach(const ExoplanetP& eps, ep) foreach(const ExoplanetP& eps, ep)
{ {
if (eps->initialized && eps->designation == id) if (eps->initialized && eps->designation == id)
return eps; return eps;
} }
return ExoplanetP(); return ExoplanetP();
} }
 End of changes. 5 change blocks. 
3 lines changed or deleted 31 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/