Exoplanets.cpp   Exoplanets.cpp 
skipping to change at line 152 skipping to change at line 152
{ {
upgradeConfigIni(); upgradeConfigIni();
try try
{ {
StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Exoplanets"); StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Exoplanets");
// 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("Exoplanets")) if (!conf->childGroups().contains("Exoplanets"))
{ {
qDebug() << "Exoplanets: no Exoplanets section exist s in main config file - creating with defaults"; qDebug() << "[Exoplanets] No Exoplanets section exis ts in main config file - creating with defaults";
resetConfiguration(); resetConfiguration();
} }
// populate settings from main config file. // populate settings from main config file.
loadConfiguration(); loadConfiguration();
jsonCatalogPath = StelFileMgr::findFile("modules/Exoplanets" , (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/e xoplanets.json"; jsonCatalogPath = StelFileMgr::findFile("modules/Exoplanets" , (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/e xoplanets.json";
if (jsonCatalogPath.isEmpty()) if (jsonCatalogPath.isEmpty())
return; return;
skipping to change at line 175 skipping to change at line 175
// key bindings and other actions // key bindings and other actions
addAction("actionShow_Exoplanets", N_("Exoplanets"), N_("Sho w exoplanets"), "showExoplanets", "Ctrl+Alt+E"); addAction("actionShow_Exoplanets", N_("Exoplanets"), N_("Sho w exoplanets"), "showExoplanets", "Ctrl+Alt+E");
addAction("actionShow_Exoplanets_ConfigDialog", N_("Exoplane ts"), N_("Exoplanets configuration window"), exoplanetsConfigDialog, "visib le", "Alt+E"); addAction("actionShow_Exoplanets_ConfigDialog", N_("Exoplane ts"), N_("Exoplanets configuration window"), exoplanetsConfigDialog, "visib le", "Alt+E");
setFlagShowExoplanets(getEnableAtStartup()); setFlagShowExoplanets(getEnableAtStartup());
setFlagShowExoplanetsButton(flagShowExoplanetsButton); setFlagShowExoplanetsButton(flagShowExoplanetsButton);
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Exoplanets: init error: " << e.what(); qWarning() << "[Exoplanets] 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(jsonCatalogPath).exists()) if(QFileInfo(jsonCatalogPath).exists())
{ {
if (!checkJsonFileFormat() || getJsonFileFormatVersion()<CAT ALOG_FORMAT_VERSION) if (!checkJsonFileFormat() || getJsonFileFormatVersion()<CAT ALOG_FORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Exoplanets: exoplanets.json does not exist - co pying default catalog to " << QDir::toNativeSeparators(jsonCatalogPath); qDebug() << "[Exoplanets] exoplanets.json does not exist - c opying default catalog to " << QDir::toNativeSeparators(jsonCatalogPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Exoplanets: loading catalog file:" << QDir::toNativeSep arators(jsonCatalogPath); qDebug() << "[Exoplanets] loading catalog file:" << QDir::toNativeSe parators(jsonCatalogPath);
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 295 skipping to change at line 295
return result; return result;
} }
StelObjectP Exoplanets::searchByName(const QString& englishName) const StelObjectP Exoplanets::searchByName(const QString& englishName) const
{ {
if (!flagShowExoplanets) if (!flagShowExoplanets)
return NULL; return NULL;
foreach(const ExoplanetP& eps, ep) foreach(const ExoplanetP& eps, ep)
{ {
if (eps->getEnglishName().toUpper() == englishName.toUpper() ) if (eps->getEnglishName().toUpper() == englishName.toUpper() || eps->getDesignation().toUpper() == englishName.toUpper())
return qSharedPointerCast<StelObject>(eps); return qSharedPointerCast<StelObject>(eps);
QStringList ppn = eps->getExoplanetsEnglishNames();
if (!ppn.isEmpty())
{
foreach (const QString &str, ppn)
{
if (str.toUpper() == englishName.toUpper())
return qSharedPointerCast<StelObject
>(eps);
}
}
ppn = eps->getExoplanetsDesignations();
if (!ppn.isEmpty())
{
foreach (const QString &str, ppn)
{
if (str.toUpper() == englishName.toUpper())
return qSharedPointerCast<StelObject
>(eps);
}
}
} }
return NULL; return NULL;
} }
StelObjectP Exoplanets::searchByNameI18n(const QString& nameI18n) const StelObjectP Exoplanets::searchByNameI18n(const QString& nameI18n) const
{ {
if (!flagShowExoplanets) if (!flagShowExoplanets)
return NULL; return NULL;
foreach(const ExoplanetP& eps, ep) foreach(const ExoplanetP& eps, ep)
{ {
if (eps->getNameI18n().toUpper() == nameI18n.toUpper()) if (eps->getNameI18n().toUpper() == nameI18n.toUpper() || ep s->getDesignation().toUpper() == nameI18n.toUpper())
return qSharedPointerCast<StelObject>(eps); return qSharedPointerCast<StelObject>(eps);
}
return NULL;
}
QStringList Exoplanets::listMatchingObjectsI18n(const QString& objPrefix, i
nt maxNbItem, bool useStartOfWords) const
{
QStringList result;
if (!flagShowExoplanets)
return result;
if (maxNbItem==0) QStringList ppn = eps->getExoplanetsNamesI18n();
return result; if (!ppn.isEmpty())
QString epsn;
bool find;
foreach(const ExoplanetP& eps, ep)
{
epsn = eps->getNameI18n();
find = false;
if (useStartOfWords)
{
if (epsn.toUpper().left(objPrefix.length()) == objPr
efix.toUpper())
find = true;
}
else
{ {
if (epsn.contains(objPrefix, Qt::CaseInsensitive)) foreach (const QString &str, ppn)
find = true; {
} if (str.toUpper() == nameI18n.toUpper())
if (find) return qSharedPointerCast<StelObject
{ >(eps);
result << epsn; }
} }
} }
result.sort(); return NULL;
if (result.size()>maxNbItem)
result.erase(result.begin()+maxNbItem, result.end());
return result;
} }
QStringList Exoplanets::listMatchingObjects(const QString& objPrefix, int m axNbItem, bool useStartOfWords) const QStringList Exoplanets::listMatchingObjects(const QString& objPrefix, int m axNbItem, bool useStartOfWords, bool inEnglish) const
{ {
QStringList result; QStringList result;
if (!flagShowExoplanets) if (!flagShowExoplanets || maxNbItem <= 0)
return result; {
if (maxNbItem==0)
return result; return result;
}
QString epsn;
bool find;
foreach(const ExoplanetP& eps, ep) foreach(const ExoplanetP& eps, ep)
{ {
epsn = eps->getNameI18n(); QStringList names;
find = false; if (inEnglish)
if (useStartOfWords)
{ {
if (epsn.toUpper().left(objPrefix.length()) == objPr names.append(eps->getEnglishName());
efix.toUpper()) names.append(eps->getExoplanetsEnglishNames());
find = true;
} }
else else
{ {
if (epsn.contains(objPrefix, Qt::CaseInsensitive)) names.append(eps->getNameI18n());
find = true; names.append(eps->getExoplanetsNamesI18n());
} }
if (find)
foreach (const QString& name, names)
{ {
result << epsn; if (!matchObjectName(name, objPrefix, useStartOfWord
s))
{
continue;
}
result.append(name);
if (result.size() >= maxNbItem)
{
result.sort();
return result;
}
} }
} }
result.sort(); result.sort();
if (result.size()>maxNbItem)
result.erase(result.begin()+maxNbItem, result.end());
return result; return result;
} }
QStringList Exoplanets::listAllObjects(bool inEnglish) const QStringList Exoplanets::listAllObjects(bool inEnglish) const
{ {
QStringList result; QStringList result;
if (!flagShowExoplanets) if (!flagShowExoplanets)
return result; return result;
foreach (const ExoplanetP& planet, ep)
result << planet->getExoplanetsDesignations();
if (inEnglish) if (inEnglish)
{ {
foreach (const ExoplanetP& planet, ep) foreach (const ExoplanetP& planet, ep)
{ result << planet->getExoplanetsEnglishNames();
result << planet->getEnglishName();
}
} }
else else
{ {
foreach (const ExoplanetP& planet, ep) foreach (const ExoplanetP& planet, ep)
{ result << planet->getExoplanetsNamesI18n();
result << planet->getNameI18n();
}
} }
return result; return result;
} }
/* /*
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 Exoplanets::restoreDefaultJsonFile(void) void Exoplanets::restoreDefaultJsonFile(void)
{ {
if (QFileInfo(jsonCatalogPath).exists()) if (QFileInfo(jsonCatalogPath).exists())
backupJsonFile(true); backupJsonFile(true);
QFile src(":/Exoplanets/exoplanets.json"); QFile src(":/Exoplanets/exoplanets.json");
if (!src.copy(jsonCatalogPath)) if (!src.copy(jsonCatalogPath))
{ {
qWarning() << "Exoplanets: cannot copy JSON resource to " + QDir::toNativeSeparators(jsonCatalogPath); qWarning() << "[Exoplanets] Cannot copy JSON resource to " + QDir::toNativeSeparators(jsonCatalogPath);
} }
else else
{ {
qDebug() << "Exoplanets: default exoplanets.json to " << QDi r::toNativeSeparators(jsonCatalogPath); qDebug() << "[Exoplanets] Default exoplanets.json to " << QD ir::toNativeSeparators(jsonCatalogPath);
// 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(jsonCatalogPath); QFile dest(jsonCatalogPath);
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("Exoplanets/last_update"); conf->remove("Exoplanets/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 454 skipping to change at line 448
} }
/* /*
Creates a backup of the exoplanets.json file called exoplanets.json.old Creates a backup of the exoplanets.json file called exoplanets.json.old
*/ */
bool Exoplanets::backupJsonFile(bool deleteOriginal) bool Exoplanets::backupJsonFile(bool deleteOriginal)
{ {
QFile old(jsonCatalogPath); QFile old(jsonCatalogPath);
if (!old.exists()) if (!old.exists())
{ {
qWarning() << "Exoplanets: no file to backup"; qWarning() << "[Exoplanets] No file to backup";
return false; return false;
} }
QString backupPath = jsonCatalogPath + ".old"; QString backupPath = jsonCatalogPath + ".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() << "Exoplanets: WARNING - could n ot remove old exoplanets.json file"; qWarning() << "[Exoplanets] WARNING - could not remove old exoplanets.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Exoplanets: WARNING - failed to copy exoplane ts.json to exoplanets.json.old"; qWarning() << "[Exoplanets] WARNING - failed to copy exoplan ets.json to exoplanets.json.old";
return false; return false;
} }
return true; return true;
} }
/* /*
Read the JSON file and create list of exoplanets. Read the JSON file and create list of exoplanets.
*/ */
void Exoplanets::readJsonFile(void) void Exoplanets::readJsonFile(void)
{ {
setEPMap(loadEPMap()); setEPMap(loadEPMap());
emit(updateStateChanged(updateState)); }
void Exoplanets::reloadCatalog(void)
{
bool hasSelection = false;
StelObjectMgr* objMgr = GETSTELMODULE(StelObjectMgr);
// Whether any exoplanet are selected? Save the current selection...
const QList<StelObjectP> selectedObject = objMgr->getSelectedObject(
"Exoplanet");
if (!selectedObject.isEmpty())
{
// ... unselect current exoplanet.
hasSelection = true;
objMgr->unSelect();
}
readJsonFile();
if (hasSelection)
{
// Restore selection...
objMgr->setSelectedObject(selectedObject);
}
} }
/* /*
Parse JSON file and load exoplanets to map Parse JSON file and load exoplanets to map
*/ */
QVariantMap Exoplanets::loadEPMap(QString path) QVariantMap Exoplanets::loadEPMap(QString path)
{ {
if (path.isEmpty()) if (path.isEmpty())
path = jsonCatalogPath; path = jsonCatalogPath;
QVariantMap map; QVariantMap map;
QFile jsonFile(path); QFile jsonFile(path);
if (!jsonFile.open(QIODevice::ReadOnly)) if (!jsonFile.open(QIODevice::ReadOnly))
qWarning() << "Exoplanets: cannot open " << QDir::toNativeSe parators(path); qWarning() << "[Exoplanets] Cannot open " << QDir::toNativeS eparators(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
*/ */
void Exoplanets::setEPMap(const QVariantMap& map) void Exoplanets::setEPMap(const QVariantMap& map)
{ {
ep.clear(); ep.clear();
PSCount = EPCountAll = EPCountPH = 0; PSCount = EPCountAll = EPCountPH = 0;
EPEccentricityAll.clear();
EPSemiAxisAll.clear();
EPMassAll.clear();
EPRadiusAll.clear();
EPPeriodAll.clear();
EPAngleDistanceAll.clear();
QVariantMap epsMap = map.value("stars").toMap(); QVariantMap epsMap = map.value("stars").toMap();
foreach(QString epsKey, epsMap.keys()) foreach(QString epsKey, epsMap.keys())
{ {
QVariantMap epsData = epsMap.value(epsKey).toMap(); QVariantMap epsData = epsMap.value(epsKey).toMap();
epsData["designation"] = epsKey; epsData["designation"] = epsKey;
PSCount++; PSCount++;
ExoplanetP eps(new Exoplanet(epsData)); ExoplanetP eps(new Exoplanet(epsData));
if (eps->initialized) if (eps->initialized)
{ {
ep.append(eps); ep.append(eps);
EPEccentricityAll.append(eps->getData(0));
EPSemiAxisAll.append(eps->getData(1));
EPMassAll.append(eps->getData(2));
EPRadiusAll.append(eps->getData(3));
EPPeriodAll.append(eps->getData(4));
EPAngleDistanceAll.append(eps->getData(5));
EPCountAll += eps->getCountExoplanets(); EPCountAll += eps->getCountExoplanets();
EPCountPH += eps->getCountHabitableExoplanets(); EPCountPH += eps->getCountHabitableExoplanets();
} }
} }
} }
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: cannot open " << QDir::toNativeSe parators(jsonCatalogPath); qWarning() << "[Exoplanets] Cannot open " << QDir::toNativeS eparators(jsonCatalogPath);
return jsonVersion; return jsonVersion;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&jsonEPCatalogFile).toMap(); map = StelJsonParser::parse(&jsonEPCatalogFile).toMap();
jsonEPCatalogFile.close(); jsonEPCatalogFile.close();
if (map.contains("version")) if (map.contains("version"))
{ {
jsonVersion = map.value("version").toInt(); jsonVersion = map.value("version").toInt();
} }
qDebug() << "Exoplanets: version of the format of the catalog:" << j sonVersion; qDebug() << "[Exoplanets] Version of the format of the catalog:" << jsonVersion;
return jsonVersion; return jsonVersion;
} }
bool Exoplanets::checkJsonFileFormat() bool Exoplanets::checkJsonFileFormat()
{ {
QFile jsonEPCatalogFile(jsonCatalogPath); QFile jsonEPCatalogFile(jsonCatalogPath);
if (!jsonEPCatalogFile.open(QIODevice::ReadOnly)) if (!jsonEPCatalogFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Exoplanets: cannot open " << QDir::toNativeSe parators(jsonCatalogPath); qWarning() << "[Exoplanets] Cannot open " << QDir::toNativeS eparators(jsonCatalogPath);
return false; return false;
} }
QVariantMap map; QVariantMap map;
try try
{ {
map = StelJsonParser::parse(&jsonEPCatalogFile).toMap(); map = StelJsonParser::parse(&jsonEPCatalogFile).toMap();
jsonEPCatalogFile.close(); jsonEPCatalogFile.close();
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "Exoplanets: file format is wrong! Error:" << e. what(); qDebug() << "[Exoplanets] File format is wrong! Error:" << e .what();
return false; return false;
} }
return true; return true;
} }
ExoplanetP Exoplanets::getByID(const QString& id) ExoplanetP Exoplanets::getByID(const QString& id)
{ {
foreach(const ExoplanetP& eps, ep) foreach(const ExoplanetP& eps, ep)
{ {
skipping to change at line 634 skipping to change at line 661
updateUrl = conf->value("url", "http://stellarium.org/json/exoplanet s.json").toString(); updateUrl = conf->value("url", "http://stellarium.org/json/exoplanet s.json").toString();
updateFrequencyHours = conf->value("update_frequency_hours", 72).toI nt(); updateFrequencyHours = conf->value("update_frequency_hours", 72).toI nt();
lastUpdate = QDateTime::fromString(conf->value("last_update", "2012- 05-24T12:00:00").toString(), Qt::ISODate); lastUpdate = QDateTime::fromString(conf->value("last_update", "2012- 05-24T12:00:00").toString(), Qt::ISODate);
updatesEnabled = conf->value("updates_enabled", true).toBool(); updatesEnabled = conf->value("updates_enabled", true).toBool();
setDisplayMode(conf->value("distribution_enabled", false).toBool()); setDisplayMode(conf->value("distribution_enabled", false).toBool());
setTimelineMode(conf->value("timeline_enabled", false).toBool()); setTimelineMode(conf->value("timeline_enabled", false).toBool());
setHabitableMode(conf->value("habitable_enabled", false).toBool()); setHabitableMode(conf->value("habitable_enabled", false).toBool());
enableAtStartup = conf->value("enable_at_startup", false).toBool(); enableAtStartup = conf->value("enable_at_startup", false).toBool();
flagShowExoplanetsButton = conf->value("flag_show_exoplanets_button" , true).toBool(); flagShowExoplanetsButton = conf->value("flag_show_exoplanets_button" , true).toBool();
setMarkerColor(conf->value("exoplanet_marker_color", "0.4,0.9,0.5"). setMarkerColor(StelUtils::strToVec3f(conf->value("exoplanet_marker_c
toString(), false); olor", "0.4,0.9,0.5").toString()), false);
setMarkerColor(conf->value("habitable_exoplanet_marker_color", "1.0, setMarkerColor(StelUtils::strToVec3f(conf->value("habitable_exoplane
0.5,0.0").toString(), true); t_marker_color", "1.0,0.5,0.0").toString()), true);
conf->endGroup(); conf->endGroup();
} }
void Exoplanets::saveConfiguration(void) void Exoplanets::saveConfiguration(void)
{ {
conf->beginGroup("Exoplanets"); conf->beginGroup("Exoplanets");
conf->setValue("url", updateUrl); conf->setValue("url", updateUrl);
conf->setValue("update_frequency_hours", updateFrequencyHours); conf->setValue("update_frequency_hours", updateFrequencyHours);
conf->setValue("updates_enabled", updatesEnabled ); conf->setValue("updates_enabled", updatesEnabled );
conf->setValue("distribution_enabled", getDisplayMode()); conf->setValue("distribution_enabled", getDisplayMode());
conf->setValue("timeline_enabled", getTimelineMode()); conf->setValue("timeline_enabled", getTimelineMode());
conf->setValue("habitable_enabled", getHabitableMode()); conf->setValue("habitable_enabled", getHabitableMode());
conf->setValue("enable_at_startup", enableAtStartup); conf->setValue("enable_at_startup", enableAtStartup);
conf->setValue("flag_show_exoplanets_button", flagShowExoplanetsButt on); conf->setValue("flag_show_exoplanets_button", flagShowExoplanetsButt on);
conf->setValue("habitable_exoplanet_marker_color", getMarkerColor(tr conf->setValue("habitable_exoplanet_marker_color", StelUtils::vec3fT
ue)); oStr(getMarkerColor(true)));
conf->setValue("exoplanet_marker_color", getMarkerColor(false)); conf->setValue("exoplanet_marker_color", StelUtils::vec3fToStr(getMa
rkerColor(false)));
conf->endGroup(); conf->endGroup();
} }
int Exoplanets::getSecondsToUpdate(void) int Exoplanets::getSecondsToUpdate(void)
{ {
QDateTime nextUpdate = lastUpdate.addSecs(updateFrequencyHours * 360 0); QDateTime nextUpdate = lastUpdate.addSecs(updateFrequencyHours * 360 0);
return QDateTime::currentDateTime().secsTo(nextUpdate); return QDateTime::currentDateTime().secsTo(nextUpdate);
} }
void Exoplanets::checkForUpdate(void) void Exoplanets::checkForUpdate(void)
{ {
if (updatesEnabled && lastUpdate.addSecs(updateFrequencyHours * 3600 ) <= QDateTime::currentDateTime()) if (updatesEnabled && lastUpdate.addSecs(updateFrequencyHours * 3600 ) <= QDateTime::currentDateTime())
updateJSON(); updateJSON();
} }
void Exoplanets::updateJSON(void) void Exoplanets::updateJSON(void)
{ {
if (updateState==Exoplanets::Updating) if (updateState==Exoplanets::Updating)
{ {
qWarning() << "Exoplanets: already updating... will not sta rt again current update is complete."; qWarning() << "[Exoplanets] Already updating... will not st art again current update is complete.";
return; return;
} }
else else
{ {
qDebug() << "Exoplanets: starting update..."; qDebug() << "[Exoplanets] Starting update...";
} }
lastUpdate = QDateTime::currentDateTime(); lastUpdate = QDateTime::currentDateTime();
conf->setValue("Exoplanets/last_update", lastUpdate.toString(Qt::ISO Date)); conf->setValue("Exoplanets/last_update", lastUpdate.toString(Qt::ISO Date));
updateState = Exoplanets::Updating; updateState = Exoplanets::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 710 skipping to change at line 737
updateState = Exoplanets::CompleteUpdates; updateState = Exoplanets::CompleteUpdates;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
emit(jsonUpdateComplete()); emit(jsonUpdateComplete());
} }
void Exoplanets::updateDownloadComplete(QNetworkReply* reply) void Exoplanets::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() << "Exoplanets: FAILED to download" << reply->url () << " Error: " << reply->errorString(); qWarning() << "[Exoplanets] FAILED to download" << reply->ur l() << " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
try try
{ {
QString jsonFilePath = StelFileMgr::findFile("module s/Exoplanets", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Direct ory)) + "/exoplanets.json"; QString jsonFilePath = StelFileMgr::findFile("module s/Exoplanets", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Direct ory)) + "/exoplanets.json";
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();
} }
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Exoplanets: cannot write JSON data to file:" << e.what(); qWarning() << "[Exoplanets] Cannot write JSON data t o file:" << e.what();
} }
} }
if (progressBar) if (progressBar)
{ {
progressBar->setValue(100); progressBar->setValue(100);
StelApp::getInstance().removeProgressBar(progressBar); StelApp::getInstance().removeProgressBar(progressBar);
progressBar = NULL; progressBar = NULL;
} }
skipping to change at line 825 skipping to change at line 852
bool Exoplanets::getHabitableMode() bool Exoplanets::getHabitableMode()
{ {
return Exoplanet::habitableMode; return Exoplanet::habitableMode;
} }
void Exoplanets::setHabitableMode(bool b) void Exoplanets::setHabitableMode(bool b)
{ {
Exoplanet::habitableMode=b; Exoplanet::habitableMode=b;
} }
QString Exoplanets::getMarkerColor(bool habitable) Vec3f Exoplanets::getMarkerColor(bool habitable)
{ {
Vec3f c; Vec3f c = Exoplanet::exoplanetMarkerColor;
if (habitable) if (habitable)
c = Exoplanet::habitableExoplanetMarkerColor; c = Exoplanet::habitableExoplanetMarkerColor;
else
c = Exoplanet::exoplanetMarkerColor; return c;
return QString("%1,%2,%3").arg(c[0]).arg(c[1]).arg(c[2]);
} }
void Exoplanets::setMarkerColor(QString c, bool h) void Exoplanets::setMarkerColor(const Vec3f &c, bool h)
{ {
Vec3f nc = StelUtils::strToVec3f(c);
if (h) if (h)
Exoplanet::habitableExoplanetMarkerColor = nc; Exoplanet::habitableExoplanetMarkerColor = c;
else else
Exoplanet::exoplanetMarkerColor = nc; Exoplanet::exoplanetMarkerColor = c;
}
void Exoplanets::setFlagShowExoplanets(bool b)
{
if (b!=flagShowExoplanets)
{
flagShowExoplanets=b;
emit flagExoplanetsVisibilityChanged(b);
}
} }
void Exoplanets::translations() void Exoplanets::translations()
{ {
#if 0 #if 0
// TRANSLATORS: Habitable zone // TRANSLATORS: Habitable zone
N_("Hot"); N_("Hot");
// TRANSLATORS: Habitable zone // TRANSLATORS: Habitable zone
N_("Warm"); N_("Warm");
// TRANSLATORS: Habitable zone // TRANSLATORS: Habitable zone
 End of changes. 50 change blocks. 
103 lines changed or deleted 140 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/