Exoplanets.cpp   Exoplanets.cpp 
skipping to change at line 19 skipping to change at line 19
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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 "config.h"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelPainter.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelTextureMgr.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "renderer/StelRenderer.hpp"
#include "renderer/StelTextureNew.hpp"
#include "LabelMgr.hpp" #include "LabelMgr.hpp"
#include "Exoplanets.hpp" #include "Exoplanets.hpp"
#include "Exoplanet.hpp" #include "Exoplanet.hpp"
#include "ExoplanetsDialog.hpp" #include "ExoplanetsDialog.hpp"
#include "StelActionMgr.hpp"
#include "StelProgressController.hpp"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QKeyEvent> #include <QKeyEvent>
#include <QAction>
#include <QProgressBar>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QFile> #include <QFile>
#include <QTimer> #include <QTimer>
#include <QVariantMap> #include <QVariantMap>
#include <QVariant> #include <QVariant>
#include <QList> #include <QList>
#include <QSettings>
#include <QSharedPointer> #include <QSharedPointer>
#include <QStringList> #include <QStringList>
#include <QPixmap> #include <QPixmap>
#include <QDir> #include <QDir>
#include <QSettings>
#define CATALOG_FORMAT_VERSION 1 /* Version of format of catalog */ #define CATALOG_FORMAT_VERSION 1 /* Version of format of catalog */
/* /*
This method is the one called automatically by the StelModuleMgr just This method is the one called automatically by the StelModuleMgr just
after loading the dynamic library after loading the dynamic library
*/ */
StelModule* ExoplanetsStelPluginInterface::getStelModule() const StelModule* ExoplanetsStelPluginInterface::getStelModule() const
{ {
return new Exoplanets(); return new Exoplanets();
skipping to change at line 77 skipping to change at line 79
StelPluginInfo ExoplanetsStelPluginInterface::getPluginInfo() const StelPluginInfo ExoplanetsStelPluginInterface::getPluginInfo() const
{ {
Q_INIT_RESOURCE(Exoplanets); Q_INIT_RESOURCE(Exoplanets);
StelPluginInfo info; StelPluginInfo info;
info.id = "Exoplanets"; info.id = "Exoplanets";
info.displayedName = N_("Exoplanets"); info.displayedName = N_("Exoplanets");
info.authors = "Alexander Wolf"; info.authors = "Alexander Wolf";
info.contact = "alex.v.wolf@gmail.com"; info.contact = "alex.v.wolf@gmail.com";
info.description = N_("This plugin plots the position of stars with exoplanets. Exoplanets data is derived from the 'Extrasolar Planets Encyclo paedia' at exoplanet.eu"); info.description = N_("This plugin plots the position of stars with exoplanets. Exoplanets data is derived from the 'Extrasolar Planets Encyclo paedia' at exoplanet.eu");
info.version = EXOPLANETS_PLUGIN_VERSION;
return info; return info;
} }
Q_EXPORT_PLUGIN2(Exoplanets, ExoplanetsStelPluginInterface)
/* /*
Constructor Constructor
*/ */
Exoplanets::Exoplanets() Exoplanets::Exoplanets()
: texPointer(NULL) : PSCount(0)
, markerTexture(NULL) , EPCountAll(0)
, EPCountPH(0)
, updateState(CompleteNoUpdates)
, downloadMgr(NULL)
, updateTimer(0)
, messageTimer(0)
, updatesEnabled(false)
, updateFrequencyHours(0)
, enableAtStartup(false)
, flagShowExoplanets(false) , flagShowExoplanets(false)
, OnIcon(NULL) , flagShowExoplanetsButton(false)
, OffIcon(NULL)
, GlowIcon(NULL)
, toolbarButton(NULL) , toolbarButton(NULL)
, progressBar(NULL) , progressBar(NULL)
{ {
setObjectName("Exoplanets"); setObjectName("Exoplanets");
exoplanetsConfigDialog = new ExoplanetsDialog(); exoplanetsConfigDialog = new ExoplanetsDialog();
conf = StelApp::getInstance().getSettings(); conf = StelApp::getInstance().getSettings();
font.setPixelSize(conf->value("gui/base_font_size", 13).toInt()); font.setPixelSize(conf->value("gui/base_font_size", 13).toInt());
} }
/* /*
Destructor Destructor
*/ */
Exoplanets::~Exoplanets() Exoplanets::~Exoplanets()
{ {
StelApp::getInstance().getStelObjectMgr().unSelect(); StelApp::getInstance().getStelObjectMgr().unSelect();
delete exoplanetsConfigDialog; delete exoplanetsConfigDialog;
if (GlowIcon)
delete GlowIcon;
if (OnIcon)
delete OnIcon;
if (OffIcon)
delete OffIcon;
} }
void Exoplanets::deinit() void Exoplanets::deinit()
{ {
ep.clear(); ep.clear();
if(NULL != texPointer) {delete texPointer;} Exoplanet::markerTexture.clear();
if(NULL != markerTexture) {delete markerTexture;} texPointer.clear();
} }
void Exoplanets::update(double) //deltaTime void Exoplanets::update(double) //deltaTime
{ {
// //
} }
/* /*
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*/ */
skipping to change at line 154 skipping to change at line 154
{ {
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::init no Exoplanets section qDebug() << "Exoplanets: no Exoplanets section exist
exists in main config file - creating with defaults"; s in main config file - creating with defaults";
restoreDefaultConfigIni(); resetConfiguration();
} }
// populate settings from main config file. // populate settings from main config file.
readSettingsFromConfig(); 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())
return;
// key bindings and other actions texPointer = StelApp::getInstance().getTextureManager().crea
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() teTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
.getGui()); Exoplanet::markerTexture = StelApp::getInstance().getTexture
Manager().createTexture(":/Exoplanets/exoplanet.png");
GlowIcon = new QPixmap(":/graphicsGui/glow32x32.png"); // key bindings and other actions
OnIcon = new QPixmap(":/Exoplanets/btExoplanets-on.png"); addAction("actionShow_Exoplanets", N_("Exoplanets"), N_("Sho
OffIcon = new QPixmap(":/Exoplanets/btExoplanets-off.png"); w exoplanets"), "showExoplanets", "Ctrl+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);
connect(gui->getGuiAction("actionShow_Exoplanets_ConfigDialo
g"), SIGNAL(toggled(bool)), exoplanetsConfigDialog, SLOT(setVisible(bool)))
;
connect(exoplanetsConfigDialog, SIGNAL(visibleChanged(bool))
, gui->getGuiAction("actionShow_Exoplanets_ConfigDialog"), SLOT(setChecked(
bool)));
connect(gui->getGuiAction("actionShow_Exoplanets"), SIGNAL(t
oggled(bool)), this, SLOT(setFlagShowExoplanets(bool)));
} }
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::init exoplanets.json does not exist - copying default file to " << QDir::toNativeSeparators(jsonCatalogPath); qDebug() << "Exoplanets: exoplanets.json does not exist - co pying default catalog to " << QDir::toNativeSeparators(jsonCatalogPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Exoplanets::init using file: " << QDir::toNativeSeparat ors(jsonCatalogPath); qDebug() << "Exoplanets: loading catalog file:" << QDir::toNativeSep arators(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
connect(updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdate()) ); connect(updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdate()) );
updateTimer->start(); updateTimer->start();
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
} }
/* void Exoplanets::draw(StelCore* core)
Draw our module. This should print name of first PSR in the main window
*/
void Exoplanets::draw(StelCore* core, StelRenderer* renderer)
{ {
if (!flagShowExoplanets) if (!flagShowExoplanets)
return; return;
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000); StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
renderer->setFont(font); StelPainter painter(prj);
painter.setFont(font);
if(NULL == texPointer)
{
Q_ASSERT_X(NULL == markerTexture, Q_FUNC_INFO, "Textures nee
d to be created simultaneously");
texPointer = renderer->createTexture("textures/pointeur2.
png");
markerTexture = renderer->createTexture(":/Exoplanets/exopla
net.png");
}
foreach (const ExoplanetP& eps, ep) foreach (const ExoplanetP& eps, ep)
{ {
if (eps && eps->initialized) if (eps && eps->initialized)
eps->draw(core, renderer, prj, markerTexture); eps->draw(core, &painter);
} }
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
drawPointer(core, renderer, prj); drawPointer(core, painter);
} }
void Exoplanets::drawPointer(StelCore* core, StelRenderer* renderer, StelPr ojectorP projector) void Exoplanets::drawPointer(StelCore* core, StelPainter& painter)
{ {
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Exoplanet"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Exoplanet");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(core); Vec3d pos=obj->getJ2000EquatorialPos(core);
Vec3d screenpos; Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!projector->project(pos, screenpos)) if (!painter.getProjector()->project(pos, screenpos))
return; return;
const Vec3f& c(obj->getInfoColor()); const Vec3f& c(obj->getInfoColor());
renderer->setGlobalColor(c[0],c[1],c[2]); painter.setColor(c[0],c[1],c[2]);
texPointer->bind(); texPointer->bind();
renderer->setBlendMode(BlendMode_Alpha); painter.enableTexture2d(true);
renderer->drawTexturedRect(screenpos[0] - 13.0f, screenpos[1 glEnable(GL_BLEND);
] - 13.0f, 26.0f, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal
26.0f, StelApp::getInstance().get transparency mode
TotalRunTime() * 40.0f); painter.drawSprite2dMode(screenpos[0], screenpos[1], 13.f, S
telApp::getInstance().getTotalRunTime()*40.);
} }
} }
QList<StelObjectP> Exoplanets::searchAround(const Vec3d& av, double limitFo v, const StelCore*) const QList<StelObjectP> Exoplanets::searchAround(const Vec3d& av, double limitFo v, const StelCore*) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!flagShowExoplanets) if (!flagShowExoplanets)
return result; return result;
skipping to change at line 437 skipping to change at line 427
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::restoreDefaultJsonFile cannot cop y json resource to " + QDir::toNativeSeparators(jsonCatalogPath); qWarning() << "Exoplanets: cannot copy JSON resource to " + QDir::toNativeSeparators(jsonCatalogPath);
} }
else else
{ {
qDebug() << "Exoplanets::init copied default exoplanets.json to " << QDir::toNativeSeparators(jsonCatalogPath); qDebug() << "Exoplanets: default exoplanets.json to " << QDi r::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 463 skipping to change at line 453
} }
/* /*
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::backupJsonFile 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::backupJsonFile WA RNING - could not remove old exoplanets.json file"; qWarning() << "Exoplanets: WARNING - could n ot remove old exoplanets.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Exoplanets::backupJsonFile WARNING - failed t o copy exoplanets.json to exoplanets.json.old"; qWarning() << "Exoplanets: WARNING - failed to copy exoplane ts.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));
} }
/* /*
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::loadEPMap cannot open " << QDir::toNa tiveSeparators(path); qWarning() << "Exoplanets: 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
*/ */
void Exoplanets::setEPMap(const QVariantMap& map) void Exoplanets::setEPMap(const QVariantMap& map)
{ {
ep.clear(); ep.clear();
PSCount = EPCountAll = EPCountPH = 0;
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++;
ExoplanetP eps(new Exoplanet(epsData)); ExoplanetP eps(new Exoplanet(epsData));
if (eps->initialized) if (eps->initialized)
{
ep.append(eps); ep.append(eps);
EPCountAll += eps->getCountExoplanets();
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::getJsonFileFormatVersion() cannot open " << QDir::toNativeSeparators(jsonCatalogPath); qWarning() << "Exoplanets: cannot open " << QDir::toNativeSe parators(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::getJsonFileFormatVersion() version of forma t from file:" << jsonVersion; qDebug() << "Exoplanets: version of the format of the catalog:" << j sonVersion;
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::checkJsonFileFormat(): cannot ope n " << QDir::toNativeSeparators(jsonCatalogPath); qWarning() << "Exoplanets: cannot open " << QDir::toNativeSe parators(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::checkJsonFileFormat(): file format qDebug() << "Exoplanets: file format is wrong! Error:" << e.
is wrong!"; what();
qDebug() << "Exoplanets::checkJsonFileFormat() 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)
{ {
if (eps->initialized && eps->designation == id) if (eps->initialized && eps->designation == id)
return eps; return eps;
} }
return ExoplanetP(); return ExoplanetP();
} }
bool Exoplanets::configureGui(bool show) bool Exoplanets::configureGui(bool show)
{ {
if (show) if (show)
{ exoplanetsConfigDialog->setVisible(true);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance()
.getGui());
gui->getGuiAction("actionShow_Exoplanets_ConfigDialog")->set
Checked(true);
}
return true; return true;
} }
void Exoplanets::restoreDefaults(void) void Exoplanets::restoreDefaults(void)
{ {
restoreDefaultConfigIni(); resetConfiguration();
restoreDefaultJsonFile(); restoreDefaultJsonFile();
readJsonFile(); readJsonFile();
readSettingsFromConfig(); loadConfiguration();
} }
void Exoplanets::restoreDefaultConfigIni(void) void Exoplanets::resetConfiguration(void)
{ {
conf->beginGroup("Exoplanets"); conf->beginGroup("Exoplanets");
// delete all existing Exoplanets settings... // delete all existing Exoplanets settings...
conf->remove(""); conf->remove("");
conf->setValue("distribution_enabled", false);
conf->setValue("timeline_enabled", false);
conf->setValue("enable_at_startup", false);
conf->setValue("updates_enabled", true);
conf->setValue("url", "http://stellarium.org/json/exoplanets.json");
conf->setValue("update_frequency_hours", 72);
conf->setValue("flag_show_exoplanets_button", true);
conf->endGroup(); conf->endGroup();
// Load the default values...
loadConfiguration();
// ... then save them.
saveConfiguration();
} }
void Exoplanets::readSettingsFromConfig(void) void Exoplanets::loadConfiguration(void)
{ {
conf->beginGroup("Exoplanets"); conf->beginGroup("Exoplanets");
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();
distributionEnabled = conf->value("distribution_enabled", false).toB setDisplayMode(conf->value("distribution_enabled", false).toBool());
ool(); setTimelineMode(conf->value("timeline_enabled", false).toBool());
timelineEnabled = conf->value("timeline_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").
toString(), false);
setMarkerColor(conf->value("habitable_exoplanet_marker_color", "1.0,
0.5,0.0").toString(), true);
conf->endGroup(); conf->endGroup();
} }
void Exoplanets::saveSettingsToConfig(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", distributionEnabled); conf->setValue("distribution_enabled", getDisplayMode());
conf->setValue("timeline_enabled", timelineEnabled); conf->setValue("timeline_enabled", getTimelineMode());
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
ue));
conf->setValue("exoplanet_marker_color", getMarkerColor(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);
} }
skipping to change at line 692 skipping to change at line 688
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().getGui()->addProgressBa r(); progressBar = StelApp::getInstance().addProgressBar();
progressBar->setValue(0); progressBar->setValue(0);
progressBar->setMaximum(100); progressBar->setRange(0, 100);
progressBar->setFormat("Update exoplanets"); progressBar->setFormat("Update exoplanets");
progressBar->setVisible(true);
QNetworkRequest request; QNetworkRequest request;
request.setUrl(QUrl(updateUrl)); request.setUrl(QUrl(updateUrl));
request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Exoplanets Plugin %1; http://stellarium.org/)").arg(EXOPLANETS_PLUGIN_VERSI ON).toUtf8()); request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Exoplanets Plugin %1; http://stellarium.org/)").arg(EXOPLANETS_PLUGIN_VERSI ON).toUtf8());
downloadMgr->get(request); downloadMgr->get(request);
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::updateDownloadComplete FAILED to download" << reply->url() << " Error: " << reply->errorString(); qWarning() << "Exoplanets: FAILED to download" << reply->url () << " 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();
jsonFile.open(QIODevice::WriteOnly | QIODevice::Text if (jsonFile.open(QIODevice::WriteOnly | QIODevice::
); Text))
jsonFile.write(reply->readAll()); {
jsonFile.close(); jsonFile.write(reply->readAll());
jsonFile.close();
}
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Exoplanets::updateDownloadComplete: c annot write JSON data to file:" << e.what(); qWarning() << "Exoplanets: cannot write JSON data to file:" << e.what();
} }
} }
if (progressBar) if (progressBar)
{ {
progressBar->setValue(100); progressBar->setValue(100);
delete progressBar; StelApp::getInstance().removeProgressBar(progressBar);
progressBar = NULL; progressBar = NULL;
} }
readJsonFile();
} }
void Exoplanets::displayMessage(const QString& message, const QString hexCo lor) void Exoplanets::displayMessage(const QString& message, const QString hexCo lor)
{ {
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 Exoplanets::messageTimeout(void) void Exoplanets::messageTimeout(void)
{ {
skipping to change at line 775 skipping to change at line 774
if (!conf->contains("Exoplanets/enable_at_startup")) if (!conf->contains("Exoplanets/enable_at_startup"))
conf->setValue("Exoplanets/enable_at_startup", b); conf->setValue("Exoplanets/enable_at_startup", b);
conf->remove("Exoplanets/flag_show_exoplanets"); conf->remove("Exoplanets/flag_show_exoplanets");
} }
} }
// Define whether the button toggling exoplanets should be visible // Define whether the button toggling exoplanets should be visible
void Exoplanets::setFlagShowExoplanetsButton(bool b) void Exoplanets::setFlagShowExoplanetsButton(bool b)
{ {
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( )); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( ));
if (b==true) { if (gui!=NULL)
if (toolbarButton==NULL) { {
// Create the exoplanets button if (b==true)
gui->getGuiAction("actionShow_Exoplanets")->setCheck {
ed(flagShowExoplanets); if (toolbarButton==NULL) {
toolbarButton = new StelButton(NULL, *OnIcon, *OffIc // Create the exoplanets button
on, *GlowIcon, gui->getGuiAction("actionShow_Exoplanets")); toolbarButton = new StelButton(NULL,
} QPixmap(":/Ex
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr oplanets/btExoplanets-on.png"),
oup"); QPixmap(":/Ex
} else { oplanets/btExoplanets-off.png"),
gui->getButtonBar()->hideButton("actionShow_Exoplanets"); QPixmap(":/gr
aphicGui/glow32x32.png"),
"actionShow_E
xoplanets");
}
gui->getButtonBar()->addButton(toolbarButton, "065-p
luginsGroup");
} else {
gui->getButtonBar()->hideButton("actionShow_Exoplane
ts");
}
} }
flagShowExoplanetsButton = b; flagShowExoplanetsButton = b;
} }
bool Exoplanets::getDisplayMode()
{
return Exoplanet::distributionMode;
}
void Exoplanets::setDisplayMode(bool b)
{
Exoplanet::distributionMode=b;
}
bool Exoplanets::getTimelineMode()
{
return Exoplanet::timelineMode;
}
void Exoplanets::setTimelineMode(bool b)
{
Exoplanet::timelineMode=b;
}
bool Exoplanets::getHabitableMode()
{
return Exoplanet::habitableMode;
}
void Exoplanets::setHabitableMode(bool b)
{
Exoplanet::habitableMode=b;
}
QString Exoplanets::getMarkerColor(bool habitable)
{
Vec3f c;
if (habitable)
c = Exoplanet::habitableExoplanetMarkerColor;
else
c = Exoplanet::exoplanetMarkerColor;
return QString("%1,%2,%3").arg(c[0]).arg(c[1]).arg(c[2]);
}
void Exoplanets::setMarkerColor(QString c, bool h)
{
Vec3f nc = StelUtils::strToVec3f(c);
if (h)
Exoplanet::habitableExoplanetMarkerColor = nc;
else
Exoplanet::exoplanetMarkerColor = nc;
}
 End of changes. 69 change blocks. 
131 lines changed or deleted 135 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/