Novae.cpp   Novae.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 "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 "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelPainter.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelTextureMgr.hpp"
#include "LabelMgr.hpp" #include "LabelMgr.hpp"
#include "Nova.hpp" #include "Nova.hpp"
#include "Novae.hpp" #include "Novae.hpp"
#include "renderer/StelRenderer.hpp"
#include "renderer/StelTextureNew.hpp"
#include "NovaeDialog.hpp" #include "NovaeDialog.hpp"
#include "StelProgressController.hpp"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QKeyEvent> #include <QKeyEvent>
#include <QAction>
#include <QProgressBar> #include <QProgressBar>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QTimer> #include <QTimer>
#include <QList> #include <QList>
#include <QSettings> #include <QSettings>
#include <QSharedPointer> #include <QSharedPointer>
#include <QStringList> #include <QStringList>
#include <QVariant> #include <QVariant>
skipping to change at line 76 skipping to change at line 78
StelPluginInfo NovaeStelPluginInterface::getPluginInfo() const StelPluginInfo NovaeStelPluginInterface::getPluginInfo() const
{ {
Q_INIT_RESOURCE(Novae); Q_INIT_RESOURCE(Novae);
StelPluginInfo info; StelPluginInfo info;
info.id = "Novae"; info.id = "Novae";
info.displayedName = N_("Bright Novae"); info.displayedName = N_("Bright Novae");
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_("A plugin that shows some bright novae in the Milky Way galaxy."); info.description = N_("A plugin that shows some bright novae in the Milky Way galaxy.");
info.version = NOVAE_PLUGIN_VERSION;
return info; return info;
} }
Q_EXPORT_PLUGIN2(Novae, NovaeStelPluginInterface)
/* /*
Constructor Constructor
*/ */
Novae::Novae() Novae::Novae()
: texPointer(NULL) : NovaCnt(0)
, texPointer(NULL)
, updateState(CompleteNoUpdates)
, downloadMgr(NULL)
, progressBar(NULL) , progressBar(NULL)
, updateTimer(NULL)
, messageTimer(NULL)
, updatesEnabled(false)
, updateFrequencyDays(0)
{ {
setObjectName("Novae"); setObjectName("Novae");
configDialog = new NovaeDialog(); configDialog = new NovaeDialog();
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
*/ */
Novae::~Novae() Novae::~Novae()
{ {
delete configDialog; delete configDialog;
} }
void Novae::deinit()
{
if(NULL != texPointer)
{
delete texPointer;
}
}
/* /*
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*/ */
double Novae::getCallOrder(StelModuleActionName actionName) const double Novae::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 132
*/ */
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::init 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";
// key bindings and other actions if (novaeJsonPath.isEmpty())
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() return;
.getGui());
connect(gui->getGuiAction("actionShow_Novae_ConfigDialog"), texPointer = StelApp::getInstance().getTextureManager().crea
SIGNAL(toggled(bool)), configDialog, SLOT(setVisible(bool))); teTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
connect(configDialog, SIGNAL(visibleChanged(bool)), gui->get addAction("actionShow_Novae_ConfigDialog", N_("Bright Novae"
GuiAction("actionShow_Novae_ConfigDialog"), SLOT(setChecked(bool))); ), N_("Bright Novae configuration window"), configDialog, "visible");
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Novas::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::init novae.json does not exist - copying default file to " << QDir::toNativeSeparators(novaeJsonPath); qDebug() << "Novae: novae.json does not exist - copying defa ult file to" << QDir::toNativeSeparators(novaeJsonPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Novae::init using file: " << QDir::toNativeSeparators(n ovaeJsonPath); qDebug() << "Novae: loading catalog file:" << QDir::toNativeSeparato rs(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
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 Nova in the main window Draw our module. This should print name of first Nova in the main window
*/ */
void Novae::draw(StelCore* core, StelRenderer* renderer) void Novae::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 NovaP& n, nova) foreach (const NovaP& n, nova)
{ {
if (n && n->initialized) if (n && n->initialized)
{ {
n->draw(core, renderer, prj); n->draw(core, &painter);
} }
} }
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
{ {
drawPointer(core, renderer, prj); drawPointer(core, painter);
} }
} }
void Novae::drawPointer(StelCore* core, StelRenderer* renderer, StelProject orP projector) void Novae::drawPointer(StelCore* core, StelPainter &painter)
{ {
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Nova"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Nova");
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> Novae::searchAround(const Vec3d& av, double limitFov, co nst StelCore*) const QList<StelObjectP> Novae::searchAround(const Vec3d& av, double limitFov, co nst 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 405 skipping to change at line 401
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::restoreDefaultJsonFile cannot copy jso n resource to " + QDir::toNativeSeparators(novaeJsonPath); qWarning() << "Novae: cannot copy JSOIN resource to" + QDir: :toNativeSeparators(novaeJsonPath);
} }
else else
{ {
qDebug() << "Novae::init copied default novae.json to " << Q Dir::toNativeSeparators(novaeJsonPath); qDebug() << "Novae: copied default novae.json to" << QDir::t oNativeSeparators(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 431 skipping to change at line 427
} }
/* /*
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::backupJsonFile 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::backupJsonFile WARNING - could not remove old novae.json file"; qWarning() << "Novae: WARNING - could not re move old novae.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Novae::backupJsonFile WARNING - failed to cop y novae.json to novae.json.old"; qWarning() << "Novae: WARNING - failed to copy novae.json to 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 478 skipping to change at line 474
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::loadNovaeMap cannot open " << QDir::toNati veSeparators(path); qWarning() << "Novae: cannot open" << QDir::toNativeSeparato rs(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 Novae::setNovaeMap(const QVariantMap& map) void Novae::setNovaeMap(const QVariantMap& map)
{ {
nova.clear(); nova.clear();
novalist.clear(); novalist.clear();
NovaCnt=0;
QVariantMap novaeMap = map.value("nova").toMap(); QVariantMap novaeMap = map.value("nova").toMap();
foreach(QString novaeKey, novaeMap.keys()) foreach(QString novaeKey, novaeMap.keys())
{ {
QVariantMap novaeData = novaeMap.value(novaeKey).toMap(); QVariantMap novaeData = novaeMap.value(novaeKey).toMap();
novaeData["designation"] = QString("%1").arg(novaeKey); novaeData["designation"] = QString("%1").arg(novaeKey);
novalist.insert(novaeData.value("designation").toString(), n novalist.insert(novaeData.value("name").toString(), novaeDat
ovaeData.value("peakJD").toDouble()); a.value("peakJD").toDouble());
NovaCnt++;
NovaP n(new Nova(novaeData)); NovaP n(new Nova(novaeData));
if (n->initialized) if (n->initialized)
nova.append(n); nova.append(n);
} }
} }
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::init cannot open " << QDir::toNativeSe parators(novaeJsonPath); qWarning() << "Novae: cannot open" << QDir::toNativeSeparato rs(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::getJsonFileVersion() version from file:" << json Version; 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::checkJsonFileFormat(): cannot open " < < QDir::toNativeSeparators(novaeJsonPath); qWarning() << "Novae: cannot open" << QDir::toNativeSeparato rs(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::checkJsonFileFormat(): file format is wr qDebug() << "Novae: file format is wrong! Error:" << e.what(
ong!"; );
qDebug() << "Novae::checkJsonFileFormat() 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)
{ {
if (n->initialized && n->designation == id) if (n->initialized && n->designation == id)
return n; return n;
} }
return NovaP(); return NovaP();
} }
bool Novae::configureGui(bool show) bool Novae::configureGui(bool show)
{ {
if (show) if (show)
{ configDialog->setVisible(true);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance()
.getGui());
gui->getGuiAction("actionShow_Novae_ConfigDialog")->setCheck
ed(true);
}
return true; return true;
} }
void Novae::restoreDefaults(void) void Novae::restoreDefaults(void)
{ {
restoreDefaultConfigIni(); restoreDefaultConfigIni();
restoreDefaultJsonFile(); restoreDefaultJsonFile();
readJsonFile(); readJsonFile();
readSettingsFromConfig(); readSettingsFromConfig();
} }
skipping to change at line 651 skipping to change at line 645
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().getGui()->addProgressBa r(); progressBar = StelApp::getInstance().addProgressBar();
progressBar->setValue(0); progressBar->setValue(0);
progressBar->setMaximum(100); progressBar->setRange(0, 100);
progressBar->setFormat("Update novae"); progressBar->setFormat("Update novae");
progressBar->setVisible(true);
QNetworkRequest request; QNetworkRequest request;
request.setUrl(QUrl(updateUrl)); request.setUrl(QUrl(updateUrl));
request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Bright Novae Plugin %1; http://stellarium.org/)").arg(NOVAE_PLUGIN_VERSION) .toUtf8()); request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Bright Novae Plugin %1; http://stellarium.org/)").arg(NOVAE_PLUGIN_VERSION) .toUtf8());
downloadMgr->get(request); downloadMgr->get(request);
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::updateDownloadComplete FAILED to downl oad" << reply->url() << " Error: " << reply->errorString(); qWarning() << "Novae: FAILED to download" << reply->url() << " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
try QString jsonFilePath = StelFileMgr::findFile("modules/Novae"
, StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/nov
ae.json";
if (jsonFilePath.isEmpty())
{
qWarning() << "Novae: cannot write JSON data to file
";
}
else
{ {
QString jsonFilePath = StelFileMgr::findFile("module s/Novae", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/novae.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::T
); ext))
jsonFile.write(reply->readAll()); {
jsonFile.close(); jsonFile.write(reply->readAll());
} jsonFile.close();
catch (std::runtime_error &e) }
{
qWarning() << "Novae::updateDownloadComplete: 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;
} }
} }
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)
{ {
foreach(int i, messageIDs) foreach(int i, messageIDs)
{ {
GETSTELMODULE(LabelMgr)->deleteLabel(i); GETSTELMODULE(LabelMgr)->deleteLabel(i);
} }
} }
QString Novae::getNovaeList()
{
QString smonth[] = {q_("January"), q_("February"), q_("March"), q_("
April"), q_("May"), q_("June"), q_("July"), q_("August"), q_("September"),
q_("October"), q_("November"), q_("December")};
QStringList out;
int year, month, day;
QList<double> vals = novalist.values();
qSort(vals);
foreach(double val, vals)
{
StelUtils::getDateFromJulianDay(val, &year, &month, &day);
out << QString("%1 (%2 %3 %4)").arg(novalist.key(val)).arg(d
ay).arg(smonth[month-1]).arg(year);
}
return out.join(", ");
}
float Novae::getLowerLimitBrightness()
{
float lowerLimit = 10.f;
QFile novaeJsonFile(novaeJsonPath);
if (!novaeJsonFile.open(QIODevice::ReadOnly))
{
qWarning() << "Novae: cannot open" << QDir::toNativeSeparato
rs(novaeJsonPath);
return lowerLimit;
}
QVariantMap map;
map = StelJsonParser::parse(&novaeJsonFile).toMap();
if (map.contains("limit"))
{
lowerLimit = map.value("limit").toFloat();
}
novaeJsonFile.close();
return lowerLimit;
}
 End of changes. 50 change blocks. 
86 lines changed or deleted 77 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/