Novae.cpp   Novae.cpp 
skipping to change at line 129 skipping to change at line 129
*/ */
void Novae::init() void Novae::init()
{ {
try try
{ {
StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Novae"); StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Novae");
// 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("Novae")) if (!conf->childGroups().contains("Novae"))
{ {
qDebug() << "Novae: no Novae section exists in main config file - creating with defaults"; qDebug() << "[Novae] no Novae section exists in main config file - creating with defaults";
restoreDefaultConfigIni(); restoreDefaultConfigIni();
} }
// populate settings from main config file. // populate settings from main config file.
readSettingsFromConfig(); readSettingsFromConfig();
novaeJsonPath = StelFileMgr::findFile("modules/Novae", (Stel FileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/novae.js on"; novaeJsonPath = StelFileMgr::findFile("modules/Novae", (Stel FileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/novae.js on";
if (novaeJsonPath.isEmpty()) if (novaeJsonPath.isEmpty())
return; return;
texPointer = StelApp::getInstance().getTextureManager().crea teTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png"); texPointer = StelApp::getInstance().getTextureManager().crea teTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
addAction("actionShow_Novae_ConfigDialog", N_("Bright Novae" ), N_("Bright Novae configuration window"), configDialog, "visible"); addAction("actionShow_Novae_ConfigDialog", N_("Bright Novae" ), N_("Bright Novae configuration window"), configDialog, "visible");
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Novae: init error:" << e.what(); qWarning() << "[Novae] init error:" << e.what();
return; return;
} }
// 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(novaeJsonPath).exists()) if(QFileInfo(novaeJsonPath).exists())
{ {
if (!checkJsonFileFormat() || getJsonFileVersion()<CATALOG_F ORMAT_VERSION) if (!checkJsonFileFormat() || getJsonFileVersion()<CATALOG_F ORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Novae: novae.json does not exist - copying defa ult file to" << QDir::toNativeSeparators(novaeJsonPath); qDebug() << "[Novae] novae.json does not exist - copying def ault file to" << QDir::toNativeSeparators(novaeJsonPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Novae: loading catalog file:" << QDir::toNativeSeparato rs(novaeJsonPath); qDebug() << "[Novae] loading catalog file:" << QDir::toNativeSeparat ors(novaeJsonPath);
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 354 skipping to change at line 354
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 Novae::restoreDefaultJsonFile(void) void Novae::restoreDefaultJsonFile(void)
{ {
if (QFileInfo(novaeJsonPath).exists()) if (QFileInfo(novaeJsonPath).exists())
backupJsonFile(true); backupJsonFile(true);
QFile src(":/Novae/novae.json"); QFile src(":/Novae/novae.json");
if (!src.copy(novaeJsonPath)) if (!src.copy(novaeJsonPath))
{ {
qWarning() << "Novae: cannot copy JSOIN resource to" + QDir: :toNativeSeparators(novaeJsonPath); qWarning() << "[Novae] cannot copy JSOIN resource to" + QDir ::toNativeSeparators(novaeJsonPath);
} }
else else
{ {
qDebug() << "Novae: copied default novae.json to" << QDir::t oNativeSeparators(novaeJsonPath); qDebug() << "[Novae] copied default novae.json to" << QDir:: toNativeSeparators(novaeJsonPath);
// 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(novaeJsonPath); QFile dest(novaeJsonPath);
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("Novae/last_update"); conf->remove("Novae/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 380 skipping to change at line 380
} }
/* /*
Creates a backup of the novae.json file called novae.json.old Creates a backup of the novae.json file called novae.json.old
*/ */
bool Novae::backupJsonFile(bool deleteOriginal) bool Novae::backupJsonFile(bool deleteOriginal)
{ {
QFile old(novaeJsonPath); QFile old(novaeJsonPath);
if (!old.exists()) if (!old.exists())
{ {
qWarning() << "Novae: no file to backup"; qWarning() << "[Novae] no file to backup";
return false; return false;
} }
QString backupPath = novaeJsonPath + ".old"; QString backupPath = novaeJsonPath + ".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() << "Novae: WARNING - could not re move old novae.json file"; qWarning() << "[Novae] WARNING - could not r emove old novae.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Novae: WARNING - failed to copy novae.json to novae.json.old"; qWarning() << "[Novae] WARNING - failed to copy novae.json t o novae.json.old";
return false; return false;
} }
return true; return true;
} }
/* /*
Read the JSON file and create list of novae. Read the JSON file and create list of novae.
*/ */
void Novae::readJsonFile(void) void Novae::readJsonFile(void)
skipping to change at line 427 skipping to change at line 427
Parse JSON file and load novae to map Parse JSON file and load novae to map
*/ */
QVariantMap Novae::loadNovaeMap(QString path) QVariantMap Novae::loadNovaeMap(QString path)
{ {
if (path.isEmpty()) if (path.isEmpty())
path = novaeJsonPath; path = novaeJsonPath;
QVariantMap map; QVariantMap map;
QFile jsonFile(path); QFile jsonFile(path);
if (!jsonFile.open(QIODevice::ReadOnly)) if (!jsonFile.open(QIODevice::ReadOnly))
qWarning() << "Novae: cannot open" << QDir::toNativeSeparato rs(path); qWarning() << "[Novae] cannot open" << QDir::toNativeSeparat ors(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 466 skipping to change at line 466
} }
} }
int Novae::getJsonFileVersion(void) int Novae::getJsonFileVersion(void)
{ {
int jsonVersion = -1; int jsonVersion = -1;
QFile novaeJsonFile(novaeJsonPath); QFile novaeJsonFile(novaeJsonPath);
if (!novaeJsonFile.open(QIODevice::ReadOnly)) if (!novaeJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Novae: cannot open" << QDir::toNativeSeparato rs(novaeJsonPath); qWarning() << "[Novae] cannot open" << QDir::toNativeSeparat ors(novaeJsonPath);
return jsonVersion; return jsonVersion;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&novaeJsonFile).toMap(); map = StelJsonParser::parse(&novaeJsonFile).toMap();
if (map.contains("version")) if (map.contains("version"))
{ {
jsonVersion = map.value("version").toInt(); jsonVersion = map.value("version").toInt();
} }
novaeJsonFile.close(); novaeJsonFile.close();
qDebug() << "Novae: version of the catalog:" << jsonVersion; qDebug() << "[Novae] version of the catalog:" << jsonVersion;
return jsonVersion; return jsonVersion;
} }
bool Novae::checkJsonFileFormat() bool Novae::checkJsonFileFormat()
{ {
QFile novaeJsonFile(novaeJsonPath); QFile novaeJsonFile(novaeJsonPath);
if (!novaeJsonFile.open(QIODevice::ReadOnly)) if (!novaeJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Novae: cannot open" << QDir::toNativeSeparato rs(novaeJsonPath); qWarning() << "[Novae] cannot open" << QDir::toNativeSeparat ors(novaeJsonPath);
return false; return false;
} }
QVariantMap map; QVariantMap map;
try try
{ {
map = StelJsonParser::parse(&novaeJsonFile).toMap(); map = StelJsonParser::parse(&novaeJsonFile).toMap();
novaeJsonFile.close(); novaeJsonFile.close();
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "Novae: file format is wrong! Error:" << e.what( ); qDebug() << "[Novae] file format is wrong! Error:" << e.what ();
return false; return false;
} }
return true; return true;
} }
NovaP Novae::getByID(const QString& id) NovaP Novae::getByID(const QString& id)
{ {
foreach(const NovaP& n, nova) foreach(const NovaP& n, nova)
{ {
skipping to change at line 583 skipping to change at line 583
void Novae::checkForUpdate(void) void Novae::checkForUpdate(void)
{ {
if (updatesEnabled && lastUpdate.addSecs(updateFrequencyDays * 3600 * 24) <= QDateTime::currentDateTime()) if (updatesEnabled && lastUpdate.addSecs(updateFrequencyDays * 3600 * 24) <= QDateTime::currentDateTime())
updateJSON(); updateJSON();
} }
void Novae::updateJSON(void) void Novae::updateJSON(void)
{ {
if (updateState==Novae::Updating) if (updateState==Novae::Updating)
{ {
qWarning() << "Novae: already updating... will not start ag ain current update is complete."; qWarning() << "[Novae] already updating... will not start a gain current update is complete.";
return; return;
} }
else else
{ {
qDebug() << "Novae: starting update..."; qDebug() << "[Novae] starting update...";
} }
lastUpdate = QDateTime::currentDateTime(); lastUpdate = QDateTime::currentDateTime();
conf->setValue("Novae/last_update", lastUpdate.toString(Qt::ISODate) ); conf->setValue("Novae/last_update", lastUpdate.toString(Qt::ISODate) );
updateState = Novae::Updating; updateState = Novae::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 619 skipping to change at line 619
updateState = Novae::CompleteUpdates; updateState = Novae::CompleteUpdates;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
emit(jsonUpdateComplete()); emit(jsonUpdateComplete());
} }
void Novae::updateDownloadComplete(QNetworkReply* reply) void Novae::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() << "Novae: FAILED to download" << reply->url() << " Error: " << reply->errorString(); qWarning() << "[Novae] FAILED to download" << reply->url() < < " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
QString jsonFilePath = StelFileMgr::findFile("modules/Novae" , StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/nov ae.json"; QString jsonFilePath = StelFileMgr::findFile("modules/Novae" , StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/nov ae.json";
if (jsonFilePath.isEmpty()) if (jsonFilePath.isEmpty())
{ {
qWarning() << "Novae: cannot write JSON data to file "; qWarning() << "[Novae] cannot write JSON data to fil e";
} }
else else
{ {
QFile jsonFile(jsonFilePath); QFile jsonFile(jsonFilePath);
if (jsonFile.exists()) if (jsonFile.exists())
jsonFile.remove(); jsonFile.remove();
if(jsonFile.open(QIODevice::WriteOnly | QIODevice::T ext)) if(jsonFile.open(QIODevice::WriteOnly | QIODevice::T ext))
{ {
jsonFile.write(reply->readAll()); jsonFile.write(reply->readAll());
skipping to change at line 649 skipping to change at line 649
} }
} }
} }
if (progressBar) if (progressBar)
{ {
progressBar->setValue(100); progressBar->setValue(100);
StelApp::getInstance().removeProgressBar(progressBar); StelApp::getInstance().removeProgressBar(progressBar);
progressBar = NULL; progressBar = NULL;
} }
readJsonFile();
} }
void Novae::displayMessage(const QString& message, const QString hexColor) void Novae::displayMessage(const QString& message, const QString hexColor)
{ {
messageIDs << GETSTELMODULE(LabelMgr)->labelScreen(message, 30, 30 + (20*messageIDs.count()), true, 16, hexColor); messageIDs << GETSTELMODULE(LabelMgr)->labelScreen(message, 30, 30 + (20*messageIDs.count()), true, 16, hexColor);
messageTimer->start(); messageTimer->start();
} }
void Novae::messageTimeout(void) void Novae::messageTimeout(void)
{ {
skipping to change at line 687 skipping to change at line 689
return out.join(", "); return out.join(", ");
} }
float Novae::getLowerLimitBrightness() float Novae::getLowerLimitBrightness()
{ {
float lowerLimit = 10.f; float lowerLimit = 10.f;
QFile novaeJsonFile(novaeJsonPath); QFile novaeJsonFile(novaeJsonPath);
if (!novaeJsonFile.open(QIODevice::ReadOnly)) if (!novaeJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Novae: cannot open" << QDir::toNativeSeparato rs(novaeJsonPath); qWarning() << "[Novae] cannot open" << QDir::toNativeSeparat ors(novaeJsonPath);
return lowerLimit; return lowerLimit;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&novaeJsonFile).toMap(); map = StelJsonParser::parse(&novaeJsonFile).toMap();
if (map.contains("limit")) if (map.contains("limit"))
{ {
lowerLimit = map.value("limit").toFloat(); lowerLimit = map.value("limit").toFloat();
} }
 End of changes. 20 change blocks. 
19 lines changed or deleted 21 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/