Supernovae.cpp   Supernovae.cpp 
skipping to change at line 20 skipping to change at line 20
* 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 "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 "LabelMgr.hpp" #include "LabelMgr.hpp"
#include "Supernova.hpp" #include "Supernova.hpp"
#include "Supernovae.hpp" #include "Supernovae.hpp"
#include "renderer/StelRenderer.hpp"
#include "renderer/StelTextureNew.hpp"
#include "SupernovaeDialog.hpp" #include "SupernovaeDialog.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 <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QFile>
#include <QTimer> #include <QTimer>
#include <QVariantMap>
#include <QVariant>
#include <QList> #include <QList>
#include <QSettings>
#include <QSharedPointer> #include <QSharedPointer>
#include <QStringList> #include <QStringList>
#include <QVariant>
#include <QVariantMap>
#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* SupernovaeStelPluginInterface::getStelModule() const StelModule* SupernovaeStelPluginInterface::getStelModule() const
{ {
return new Supernovae(); return new Supernovae();
skipping to change at line 76 skipping to change at line 75
StelPluginInfo SupernovaeStelPluginInterface::getPluginInfo() const StelPluginInfo SupernovaeStelPluginInterface::getPluginInfo() const
{ {
Q_INIT_RESOURCE(Supernovae); Q_INIT_RESOURCE(Supernovae);
StelPluginInfo info; StelPluginInfo info;
info.id = "Supernovae"; info.id = "Supernovae";
info.displayedName = N_("Historical Supernovae"); info.displayedName = N_("Historical Supernovae");
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 allows you to see some bright his torical supernovae."); info.description = N_("This plugin allows you to see some bright his torical supernovae.");
info.version = SUPERNOVAE_PLUGIN_VERSION;
return info; return info;
} }
Q_EXPORT_PLUGIN2(Supernovae, SupernovaeStelPluginInterface)
/* /*
Constructor Constructor
*/ */
Supernovae::Supernovae() Supernovae::Supernovae()
: texPointer(NULL) : SNCount(0)
, updateState(CompleteNoUpdates)
, downloadMgr(NULL)
, progressBar(NULL) , progressBar(NULL)
, updateTimer(0)
, messageTimer(0)
, updatesEnabled(false)
, updateFrequencyDays(0)
{ {
setObjectName("Supernovae"); setObjectName("Supernovae");
configDialog = new SupernovaeDialog(); configDialog = new SupernovaeDialog();
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
*/ */
Supernovae::~Supernovae() Supernovae::~Supernovae()
{ {
delete configDialog; delete configDialog;
} }
void Supernovae::deinit() void Supernovae::deinit()
{ {
if(NULL != texPointer) texPointer.clear();
{
delete texPointer;
}
} }
/* /*
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*/ */
double Supernovae::getCallOrder(StelModuleActionName actionName) const double Supernovae::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Cons tellationMgr")->getCallOrder(actionName)+10.; return StelApp::getInstance().getModuleMgr().getModule("Cons tellationMgr")->getCallOrder(actionName)+10.;
return 0; return 0;
skipping to change at line 132 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::init no Supernovae section exists in main config file - creating with defaults"; qDebug() << "Supernovae: no Supernovae section exist s 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";
// key bindings and other actions if (sneJsonPath.isEmpty())
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() return;
.getGui());
connect(gui->getGuiAction("actionShow_Supernovae_ConfigDialo texPointer = StelApp::getInstance().getTextureManager().crea
g"), SIGNAL(toggled(bool)), configDialog, SLOT(setVisible(bool))); teTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
connect(configDialog, SIGNAL(visibleChanged(bool)), gui->get
GuiAction("actionShow_Supernovae_ConfigDialog"), SLOT(setChecked(bool))); // key bindings and other actions
addAction("actionShow_Supernovae_ConfigDialog", N_("Historic
al Supernovae"), N_("Historical Supernovae configuration window"), configDi
alog, "visible");
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Supernovas::init error: " << e.what(); qWarning() << "Supernovas: 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(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::init supernovae.json does not exist - copying default file to " << QDir::toNativeSeparators(sneJsonPath); qDebug() << "Supernovae: supernovae.json does not exist - co pying default file to" << QDir::toNativeSeparators(sneJsonPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Supernovae::init using file: " << QDir::toNativeSeparat ors(sneJsonPath); qDebug() << "Supernovae: loading catalog file:" << QDir::toNativeSep arators(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
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);
} }
/* /*
Draw our module. This should print name of first SNe in the main window Draw our module. This should print name of first SNe in the main window
*/ */
void Supernovae::draw(StelCore* core, StelRenderer* renderer) void Supernovae::draw(StelCore* core)
{ {
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000); StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
renderer->setFont(font); StelPainter painter(prj);
painter.setFont(font);
foreach (const SupernovaP& sn, snstar) foreach (const SupernovaP& sn, snstar)
{ {
if (sn && sn->initialized) if (sn && sn->initialized)
{ sn->draw(core, painter);
sn->draw(core, renderer, prj);
}
} }
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
{ drawPointer(core, painter);
drawPointer(core, renderer, prj);
}
} }
void Supernovae::drawPointer(StelCore* core, StelRenderer* renderer, StelPr ojectorP projector) void Supernovae::drawPointer(StelCore* core, StelPainter& painter)
{ {
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Supernova"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Supernova");
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]);
if(NULL == texPointer)
{
texPointer = renderer->createTexture("textures/point
eur2.png");
}
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, 26.0f, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal
StelApp::getInstance().getTotalRu transparency mode
nTime() * 40.0f); painter.drawSprite2dMode(screenpos[0], screenpos[1], 13.f, S
telApp::getInstance().getTotalRunTime()*40.);
} }
} }
QList<StelObjectP> Supernovae::searchAround(const Vec3d& av, double limitFo v, const StelCore*) const QList<StelObjectP> Supernovae::searchAround(const Vec3d& av, double limitFo v, const StelCore*) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
Vec3d v(av); Vec3d v(av);
v.normalize(); v.normalize();
double cosLimFov = cos(limitFov * M_PI/180.); double cosLimFov = cos(limitFov * M_PI/180.);
skipping to change at line 388 skipping to change at line 384
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::restoreDefaultJsonFile cannot cop y json resource to " + QDir::toNativeSeparators(sneJsonPath); qWarning() << "Supernovae: cannot copy JSON resource to" + Q Dir::toNativeSeparators(sneJsonPath);
} }
else else
{ {
qDebug() << "Supernovae::init 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 414 skipping to change at line 410
} }
/* /*
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::backupJsonFile 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::backupJsonFile WA RNING - could not remove old supernovas.json file"; qWarning() << "Supernovae: WARNING - could n ot remove old supernovas.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Supernovae::backupJsonFile WARNING - failed t o copy supernovae.json to supernovae.json.old"; qWarning() << "Supernovae: WARNING - failed to copy supernov ae.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 461 skipping to change at line 457
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::loadSNeMap cannot open " << QDir::toN ativeSeparators(path); qWarning() << "Supernovae: cannot open" << QDir::toNativeSep arators(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 Supernovae::setSNeMap(const QVariantMap& map) void Supernovae::setSNeMap(const QVariantMap& map)
{ {
snstar.clear(); snstar.clear();
snlist.clear(); snlist.clear();
SNCount = 0;
QVariantMap sneMap = map.value("supernova").toMap(); QVariantMap sneMap = map.value("supernova").toMap();
foreach(QString sneKey, sneMap.keys()) foreach(QString sneKey, sneMap.keys())
{ {
QVariantMap sneData = sneMap.value(sneKey).toMap(); QVariantMap sneData = sneMap.value(sneKey).toMap();
sneData["designation"] = QString("SN %1").arg(sneKey); sneData["designation"] = QString("SN %1").arg(sneKey);
snlist.insert(sneData.value("designation").toString(), sneDa ta.value("peakJD").toDouble()); snlist.insert(sneData.value("designation").toString(), sneDa ta.value("peakJD").toDouble());
SNCount++;
SupernovaP sn(new Supernova(sneData)); SupernovaP sn(new Supernova(sneData));
if (sn->initialized) if (sn->initialized)
snstar.append(sn); snstar.append(sn);
} }
} }
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::init cannot open " << QDir::toNat iveSeparators(sneJsonPath); qWarning() << "Supernovae: cannot open" << QDir::toNativeSep arators(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::getJsonFileVersion() version from file:" << 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::checkJsonFileFormat(): cannot ope n " << QDir::toNativeSeparators(sneJsonPath); qWarning() << "Supernovae: cannot open " << QDir::toNativeSe parators(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::checkJsonFileFormat(): file format qDebug() << "Supernovae: file format is wrong! Error:" << e.
is wrong!"; what();
qDebug() << "Supernovae::checkJsonFileFormat() 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::init cannot open " << QDir::toNat iveSeparators(sneJsonPath); qWarning() << "Supernovae: cannot open" << QDir::toNativeSep arators(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 572 skipping to change at line 570
{ {
if (sn->initialized && sn->designation == id) if (sn->initialized && sn->designation == id)
return sn; return sn;
} }
return SupernovaP(); return SupernovaP();
} }
bool Supernovae::configureGui(bool show) bool Supernovae::configureGui(bool show)
{ {
if (show) if (show)
{ configDialog->setVisible(true);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance()
.getGui());
gui->getGuiAction("actionShow_Supernovae_ConfigDialog")->set
Checked(true);
}
return true; return true;
} }
void Supernovae::restoreDefaults(void) void Supernovae::restoreDefaults(void)
{ {
restoreDefaultConfigIni(); restoreDefaultConfigIni();
restoreDefaultJsonFile(); restoreDefaultJsonFile();
readJsonFile(); readJsonFile();
readSettingsFromConfig(); readSettingsFromConfig();
} }
skipping to change at line 655 skipping to change at line 649
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().getGui()->addProgressBa r(); progressBar = StelApp::getInstance().addProgressBar();
progressBar->setValue(0); progressBar->setValue(0);
progressBar->setMaximum(100); progressBar->setRange(0, 100);
progressBar->setFormat("Update historical supernovae"); progressBar->setFormat("Update historical supernovae");
progressBar->setVisible(true);
QNetworkRequest request; QNetworkRequest request;
request.setUrl(QUrl(updateUrl)); request.setUrl(QUrl(updateUrl));
request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Historical Supernovae Plugin %1; http://stellarium.org/)").arg(SUPERNOVAE_P LUGIN_VERSION).toUtf8()); request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Historical Supernovae Plugin %1; http://stellarium.org/)").arg(SUPERNOVAE_P LUGIN_VERSION).toUtf8());
downloadMgr->get(request); downloadMgr->get(request);
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::updateDownloadComplete FAILED to download" << reply->url() << " Error: " << reply->errorString(); qWarning() << "Supernovae: FAILED to download" << reply->url () << " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
try QString jsonFilePath = StelFileMgr::findFile("modules/Supern
ovae", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) +
"/supernovae.json";
if (jsonFilePath.isEmpty())
{ {
QString jsonFilePath = StelFileMgr::findFile("module qWarning() << "Supernovae: cannot write JSON data to
s/Supernovae", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Direct file:" << QDir::toNativeSeparators(jsonFilePath);
ory)) + "/supernovae.json"; return;
QFile jsonFile(jsonFilePath); }
if (jsonFile.exists()) QFile jsonFile(jsonFilePath);
jsonFile.remove(); if (jsonFile.exists())
jsonFile.remove();
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)
{
qWarning() << "Supernovae::updateDownloadComplete: c
annot 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 Supernovae::displayMessage(const QString& message, const QString hexCo lor) void Supernovae::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 Supernovae::messageTimeout(void) void Supernovae::messageTimeout(void)
{ {
 End of changes. 56 change blocks. 
93 lines changed or deleted 82 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/