Supernovae.cpp   Supernovae.cpp 
skipping to change at line 133 skipping to change at line 133
*/ */
void Supernovae::init() void Supernovae::init()
{ {
try try
{ {
StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Supernovae"); StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Supernovae");
// If no settings in the main config file, create with defau lts // If no settings in the main config file, create with defau lts
if (!conf->childGroups().contains("Supernovae")) if (!conf->childGroups().contains("Supernovae"))
{ {
qDebug() << "Supernovae: no Supernovae section exist s in main config file - creating with defaults"; qDebug() << "[Supernovae] no Supernovae section exis ts in main config file - creating with defaults";
restoreDefaultConfigIni(); restoreDefaultConfigIni();
} }
// populate settings from main config file. // populate settings from main config file.
readSettingsFromConfig(); readSettingsFromConfig();
sneJsonPath = StelFileMgr::findFile("modules/Supernovae", (S telFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/super novae.json"; sneJsonPath = StelFileMgr::findFile("modules/Supernovae", (S telFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/super novae.json";
if (sneJsonPath.isEmpty()) if (sneJsonPath.isEmpty())
return; return;
skipping to change at line 172 skipping to change at line 172
// 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(sneJsonPath).exists()) if(QFileInfo(sneJsonPath).exists())
{ {
if (!checkJsonFileFormat() || getJsonFileVersion()<CATALOG_F ORMAT_VERSION) if (!checkJsonFileFormat() || getJsonFileVersion()<CATALOG_F ORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Supernovae: supernovae.json does not exist - co pying default file to" << QDir::toNativeSeparators(sneJsonPath); qDebug() << "[Supernovae] supernovae.json does not exist - c opying default file to" << QDir::toNativeSeparators(sneJsonPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Supernovae: loading catalog file:" << QDir::toNativeSep arators(sneJsonPath); qDebug() << "[Supernovae] loading catalog file:" << QDir::toNativeSe parators(sneJsonPath);
readJsonFile(); readJsonFile();
// Set up download manager and the update schedule // Set up download manager and the update schedule
downloadMgr = new QNetworkAccessManager(this); downloadMgr = new QNetworkAccessManager(this);
connect(downloadMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(up dateDownloadComplete(QNetworkReply*))); connect(downloadMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(up dateDownloadComplete(QNetworkReply*)));
updateState = CompleteNoUpdates; updateState = CompleteNoUpdates;
updateTimer = new QTimer(this); updateTimer = new QTimer(this);
updateTimer->setSingleShot(false); // recurring check for update updateTimer->setSingleShot(false); // recurring check for update
updateTimer->setInterval(13000); // check once every 13 seconds to see if it is time for an update updateTimer->setInterval(13000); // check once every 13 seconds to see if it is time for an update
skipping to change at line 314 skipping to change at line 314
Replace the JSON file with the default from the compiled-in resource Replace the JSON file with the default from the compiled-in resource
*/ */
void Supernovae::restoreDefaultJsonFile(void) void Supernovae::restoreDefaultJsonFile(void)
{ {
if (QFileInfo(sneJsonPath).exists()) if (QFileInfo(sneJsonPath).exists())
backupJsonFile(true); backupJsonFile(true);
QFile src(":/Supernovae/supernovae.json"); QFile src(":/Supernovae/supernovae.json");
if (!src.copy(sneJsonPath)) if (!src.copy(sneJsonPath))
{ {
qWarning() << "Supernovae: cannot copy JSON resource to" + Q Dir::toNativeSeparators(sneJsonPath); qWarning() << "[Supernovae] cannot copy JSON resource to" + QDir::toNativeSeparators(sneJsonPath);
} }
else else
{ {
qDebug() << "Supernovae: copied default supernovae.json to" << QDir::toNativeSeparators(sneJsonPath); qDebug() << "[Supernovae] copied default supernovae.json to" << QDir::toNativeSeparators(sneJsonPath);
// The resource is read only, and the new file inherits this ... make sure the new file // The resource is read only, and the new file inherits this ... make sure the new file
// is writable by the Stellarium process so that updates can be done. // is writable by the Stellarium process so that updates can be done.
QFile dest(sneJsonPath); QFile dest(sneJsonPath);
dest.setPermissions(dest.permissions() | QFile::WriteOwner); dest.setPermissions(dest.permissions() | QFile::WriteOwner);
// Make sure that in the case where an online update has pre viously been done, but // Make sure that in the case where an online update has pre viously been done, but
// the json file has been manually removed, that an update i s schreduled in a timely // the json file has been manually removed, that an update i s schreduled in a timely
// manner // manner
conf->remove("Supernovae/last_update"); conf->remove("Supernovae/last_update");
lastUpdate = QDateTime::fromString("2012-05-24T12:00:00", Qt ::ISODate); lastUpdate = QDateTime::fromString("2012-05-24T12:00:00", Qt ::ISODate);
skipping to change at line 340 skipping to change at line 340
} }
/* /*
Creates a backup of the supernovae.json file called supernovae.json.old Creates a backup of the supernovae.json file called supernovae.json.old
*/ */
bool Supernovae::backupJsonFile(bool deleteOriginal) bool Supernovae::backupJsonFile(bool deleteOriginal)
{ {
QFile old(sneJsonPath); QFile old(sneJsonPath);
if (!old.exists()) if (!old.exists())
{ {
qWarning() << "Supernovae: no file to backup"; qWarning() << "[Supernovae] no file to backup";
return false; return false;
} }
QString backupPath = sneJsonPath + ".old"; QString backupPath = sneJsonPath + ".old";
if (QFileInfo(backupPath).exists()) if (QFileInfo(backupPath).exists())
QFile(backupPath).remove(); QFile(backupPath).remove();
if (old.copy(backupPath)) if (old.copy(backupPath))
{ {
if (deleteOriginal) if (deleteOriginal)
{ {
if (!old.remove()) if (!old.remove())
{ {
qWarning() << "Supernovae: WARNING - could n ot remove old supernovas.json file"; qWarning() << "[Supernovae] WARNING - could not remove old supernovas.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Supernovae: WARNING - failed to copy supernov ae.json to supernovae.json.old"; qWarning() << "[Supernovae] WARNING - failed to copy superno vae.json to supernovae.json.old";
return false; return false;
} }
return true; return true;
} }
/* /*
Read the JSON file and create list of supernovaes. Read the JSON file and create list of supernovaes.
*/ */
void Supernovae::readJsonFile(void) void Supernovae::readJsonFile(void)
skipping to change at line 387 skipping to change at line 387
Parse JSON file and load supernovaes to map Parse JSON file and load supernovaes to map
*/ */
QVariantMap Supernovae::loadSNeMap(QString path) QVariantMap Supernovae::loadSNeMap(QString path)
{ {
if (path.isEmpty()) if (path.isEmpty())
path = sneJsonPath; path = sneJsonPath;
QVariantMap map; QVariantMap map;
QFile jsonFile(path); QFile jsonFile(path);
if (!jsonFile.open(QIODevice::ReadOnly)) if (!jsonFile.open(QIODevice::ReadOnly))
qWarning() << "Supernovae: cannot open" << QDir::toNativeSep arators(path); qWarning() << "[Supernovae] cannot open" << QDir::toNativeSe parators(path);
else else
{ {
map = StelJsonParser::parse(jsonFile.readAll()).toMap(); map = StelJsonParser::parse(jsonFile.readAll()).toMap();
jsonFile.close(); jsonFile.close();
} }
return map; return map;
} }
/* /*
Set items for list of struct from data map Set items for list of struct from data map
skipping to change at line 426 skipping to change at line 426
} }
} }
int Supernovae::getJsonFileVersion(void) int Supernovae::getJsonFileVersion(void)
{ {
int jsonVersion = -1; int jsonVersion = -1;
QFile sneJsonFile(sneJsonPath); QFile sneJsonFile(sneJsonPath);
if (!sneJsonFile.open(QIODevice::ReadOnly)) if (!sneJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Supernovae: cannot open" << QDir::toNativeSep arators(sneJsonPath); qWarning() << "[Supernovae] cannot open" << QDir::toNativeSe parators(sneJsonPath);
return jsonVersion; return jsonVersion;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&sneJsonFile).toMap(); map = StelJsonParser::parse(&sneJsonFile).toMap();
if (map.contains("version")) if (map.contains("version"))
{ {
jsonVersion = map.value("version").toInt(); jsonVersion = map.value("version").toInt();
} }
sneJsonFile.close(); sneJsonFile.close();
qDebug() << "Supernovae: version of the catalog:" << jsonVersion; qDebug() << "[Supernovae] version of the catalog:" << jsonVersion;
return jsonVersion; return jsonVersion;
} }
bool Supernovae::checkJsonFileFormat() bool Supernovae::checkJsonFileFormat()
{ {
QFile sneJsonFile(sneJsonPath); QFile sneJsonFile(sneJsonPath);
if (!sneJsonFile.open(QIODevice::ReadOnly)) if (!sneJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Supernovae: cannot open " << QDir::toNativeSe parators(sneJsonPath); qWarning() << "[Supernovae] cannot open " << QDir::toNativeS eparators(sneJsonPath);
return false; return false;
} }
QVariantMap map; QVariantMap map;
try try
{ {
map = StelJsonParser::parse(&sneJsonFile).toMap(); map = StelJsonParser::parse(&sneJsonFile).toMap();
sneJsonFile.close(); sneJsonFile.close();
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "Supernovae: file format is wrong! Error:" << e. what(); qDebug() << "[Supernovae] file format is wrong! Error:" << e .what();
return false; return false;
} }
return true; return true;
} }
float Supernovae::getLowerLimitBrightness() float Supernovae::getLowerLimitBrightness()
{ {
float lowerLimit = 10.f; float lowerLimit = 10.f;
QFile sneJsonFile(sneJsonPath); QFile sneJsonFile(sneJsonPath);
if (!sneJsonFile.open(QIODevice::ReadOnly)) if (!sneJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Supernovae: cannot open" << QDir::toNativeSep arators(sneJsonPath); qWarning() << "[Supernovae] cannot open" << QDir::toNativeSe parators(sneJsonPath);
return lowerLimit; return lowerLimit;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&sneJsonFile).toMap(); map = StelJsonParser::parse(&sneJsonFile).toMap();
if (map.contains("limit")) if (map.contains("limit"))
{ {
lowerLimit = map.value("limit").toFloat(); lowerLimit = map.value("limit").toFloat();
} }
skipping to change at line 564 skipping to change at line 564
void Supernovae::checkForUpdate(void) void Supernovae::checkForUpdate(void)
{ {
if (updatesEnabled && lastUpdate.addSecs(updateFrequencyDays * 3600 * 24) <= QDateTime::currentDateTime()) if (updatesEnabled && lastUpdate.addSecs(updateFrequencyDays * 3600 * 24) <= QDateTime::currentDateTime())
updateJSON(); updateJSON();
} }
void Supernovae::updateJSON(void) void Supernovae::updateJSON(void)
{ {
if (updateState==Supernovae::Updating) if (updateState==Supernovae::Updating)
{ {
qWarning() << "Supernovae: already updating... will not sta rt again current update is complete."; qWarning() << "[Supernovae] already updating... will not st art again current update is complete.";
return; return;
} }
else else
{ {
qDebug() << "Supernovae: starting update..."; qDebug() << "[Supernovae] starting update...";
} }
lastUpdate = QDateTime::currentDateTime(); lastUpdate = QDateTime::currentDateTime();
conf->setValue("Supernovae/last_update", lastUpdate.toString(Qt::ISO Date)); conf->setValue("Supernovae/last_update", lastUpdate.toString(Qt::ISO Date));
updateState = Supernovae::Updating; updateState = Supernovae::Updating;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
if (progressBar==NULL) if (progressBar==NULL)
progressBar = StelApp::getInstance().addProgressBar(); progressBar = StelApp::getInstance().addProgressBar();
skipping to change at line 600 skipping to change at line 600
updateState = Supernovae::CompleteUpdates; updateState = Supernovae::CompleteUpdates;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
emit(jsonUpdateComplete()); emit(jsonUpdateComplete());
} }
void Supernovae::updateDownloadComplete(QNetworkReply* reply) void Supernovae::updateDownloadComplete(QNetworkReply* reply)
{ {
// check the download worked, and save the data to file if this is t he case. // check the download worked, and save the data to file if this is t he case.
if (reply->error() != QNetworkReply::NoError) if (reply->error() != QNetworkReply::NoError)
{ {
qWarning() << "Supernovae: FAILED to download" << reply->url () << " Error: " << reply->errorString(); qWarning() << "[Supernovae] FAILED to download" << reply->ur l() << " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
QString jsonFilePath = StelFileMgr::findFile("modules/Supern ovae", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/supernovae.json"; QString jsonFilePath = StelFileMgr::findFile("modules/Supern ovae", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/supernovae.json";
if (jsonFilePath.isEmpty()) if (jsonFilePath.isEmpty())
{ {
qWarning() << "Supernovae: cannot write JSON data to file:" << QDir::toNativeSeparators(jsonFilePath); qWarning() << "[Supernovae] cannot write JSON data t o file:" << QDir::toNativeSeparators(jsonFilePath);
return; return;
} }
QFile jsonFile(jsonFilePath); QFile jsonFile(jsonFilePath);
if (jsonFile.exists()) if (jsonFile.exists())
jsonFile.remove(); jsonFile.remove();
if(jsonFile.open(QIODevice::WriteOnly | QIODevice::Text)) if(jsonFile.open(QIODevice::WriteOnly | QIODevice::Text))
{ {
jsonFile.write(reply->readAll()); jsonFile.write(reply->readAll());
jsonFile.close(); jsonFile.close();
 End of changes. 18 change blocks. 
18 lines changed or deleted 18 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/