Pulsars.cpp   Pulsars.cpp 
skipping to change at line 52 skipping to change at line 52
#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 <QSettings>
#include <QSharedPointer> #include <QSharedPointer>
#include <QStringList> #include <QStringList>
#include <QDir>
#define CATALOG_FORMAT_VERSION 2 /* Version of format of catalog */ #define CATALOG_FORMAT_VERSION 2 /* 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* PulsarsStelPluginInterface::getStelModule() const StelModule* PulsarsStelPluginInterface::getStelModule() const
{ {
return new Pulsars(); return new Pulsars();
skipping to change at line 85 skipping to change at line 86
} }
Q_EXPORT_PLUGIN2(Pulsars, PulsarsStelPluginInterface) Q_EXPORT_PLUGIN2(Pulsars, PulsarsStelPluginInterface)
/* /*
Constructor Constructor
*/ */
Pulsars::Pulsars() Pulsars::Pulsars()
: texPointer(NULL) : texPointer(NULL)
, markerTexture(NULL) , markerTexture(NULL)
, flagShowPulsars(false)
, OnIcon(NULL)
, OffIcon(NULL)
, GlowIcon(NULL)
, toolbarButton(NULL)
, progressBar(NULL) , progressBar(NULL)
{ {
setObjectName("Pulsars"); setObjectName("Pulsars");
configDialog = new PulsarsDialog(); configDialog = new PulsarsDialog();
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
*/ */
Pulsars::~Pulsars() Pulsars::~Pulsars()
{ {
delete configDialog; delete configDialog;
if (GlowIcon)
delete GlowIcon;
if (OnIcon)
delete OnIcon;
if (OffIcon)
delete OffIcon;
} }
void Pulsars::deinit() void Pulsars::deinit()
{ {
psr.clear(); psr.clear();
if(NULL != markerTexture) if(NULL != markerTexture)
{ {
delete markerTexture; delete markerTexture;
} }
if(NULL != texPointer) if(NULL != texPointer)
skipping to change at line 129 skipping to change at line 142
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;
} }
/* /*
Init our module Init our module
*/ */
void Pulsars::init() void Pulsars::init()
{ {
upgradeConfigIni();
try try
{ {
StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Pulsars"); StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Pulsars");
// 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("Pulsars")) if (!conf->childGroups().contains("Pulsars"))
{ {
qDebug() << "Pulsars::init no Pulsars section exists in main config file - creating with defaults"; qDebug() << "Pulsars::init no Pulsars 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();
jsonCatalogPath = StelFileMgr::findFile("modules/Pulsars", ( StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/puls ars.json"; jsonCatalogPath = StelFileMgr::findFile("modules/Pulsars", ( StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/puls ars.json";
// key bindings and other actions // key bindings and other actions
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui()); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui());
GlowIcon = new QPixmap(":/graphicsGui/glow32x32.png");
OnIcon = new QPixmap(":/Pulsars/btPulsars-on.png");
OffIcon = new QPixmap(":/Pulsars/btPulsars-off.png");
setFlagShowPulsars(getEnableAtStartup());
setFlagShowPulsarsButton(flagShowPulsarsButton);
connect(gui->getGuiAction("actionShow_Pulsars_ConfigDialog") , SIGNAL(toggled(bool)), configDialog, SLOT(setVisible(bool))); connect(gui->getGuiAction("actionShow_Pulsars_ConfigDialog") , SIGNAL(toggled(bool)), configDialog, SLOT(setVisible(bool)));
connect(configDialog, SIGNAL(visibleChanged(bool)), gui->get GuiAction("actionShow_Pulsars_ConfigDialog"), SLOT(setChecked(bool))); connect(configDialog, SIGNAL(visibleChanged(bool)), gui->get GuiAction("actionShow_Pulsars_ConfigDialog"), SLOT(setChecked(bool)));
if (flagShowPulsarsButton)
{
connect(gui->getGuiAction("actionShow_Pulsars"), SIG
NAL(toggled(bool)), this, SLOT(setFlagShowPulsars(bool)));
}
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Pulsars::init error: " << e.what(); qWarning() << "Pulsars::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 (getJsonFileVersion() < CATALOG_FORMAT_VERSION) if (getJsonFileFormatVersion() < CATALOG_FORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Pulsars::init pulsars.json does not exist - cop ying default file to " << jsonCatalogPath; qDebug() << "Pulsars::init pulsars.json does not exist - cop ying default file to " << QDir::toNativeSeparators(jsonCatalogPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Pulsars::init using pulsars.json file: " << jsonCatalog Path; qDebug() << "Pulsars::init using file: " << QDir::toNativeSeparators (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 200 skipping to change at line 226
updateTimer->start(); updateTimer->start();
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
} }
/* /*
Draw our module. This should print name of first PSR in the main window Draw our module. This should print name of first PSR in the main window
*/ */
void Pulsars::draw(StelCore* core, StelRenderer* renderer) void Pulsars::draw(StelCore* core, StelRenderer* renderer)
{ {
if (!flagShowPulsars)
return;
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000); StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
renderer->setFont(font); renderer->setFont(font);
foreach (const PulsarP& pulsar, psr) foreach (const PulsarP& pulsar, psr)
{ {
if (pulsar && pulsar->initialized) if (pulsar && pulsar->initialized)
{ {
if(NULL == markerTexture) if(NULL == markerTexture)
{ {
markerTexture = renderer->createTexture(":/P ulsars/pulsar.png"); markerTexture = renderer->createTexture(":/P ulsars/pulsar.png");
skipping to change at line 253 skipping to change at line 282
renderer->setBlendMode(BlendMode_Alpha); renderer->setBlendMode(BlendMode_Alpha);
renderer->drawTexturedRect(screenpos[0] - 13.0f, screenpos[1 ] - 13.0f, 26.0f, 26.0f, renderer->drawTexturedRect(screenpos[0] - 13.0f, screenpos[1 ] - 13.0f, 26.0f, 26.0f,
StelApp::getInstance().getTotalRu nTime() * 40.0f); StelApp::getInstance().getTotalRu nTime() * 40.0f);
} }
} }
QList<StelObjectP> Pulsars::searchAround(const Vec3d& av, double limitFov, const StelCore*) const QList<StelObjectP> Pulsars::searchAround(const Vec3d& av, double limitFov, const StelCore*) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!flagShowPulsars)
return 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.);
Vec3d equPos; Vec3d equPos;
foreach(const PulsarP& pulsar, psr) foreach(const PulsarP& pulsar, psr)
{ {
if (pulsar->initialized) if (pulsar->initialized)
{ {
equPos = pulsar->XYZ; equPos = pulsar->XYZ;
skipping to change at line 276 skipping to change at line 308
result.append(qSharedPointerCast<StelObject> (pulsar)); result.append(qSharedPointerCast<StelObject> (pulsar));
} }
} }
} }
return result; return result;
} }
StelObjectP Pulsars::searchByName(const QString& englishName) const StelObjectP Pulsars::searchByName(const QString& englishName) const
{ {
QString objw = englishName.toUpper(); if (!flagShowPulsars)
return NULL;
foreach(const PulsarP& pulsar, psr) foreach(const PulsarP& pulsar, psr)
{ {
if (pulsar->getEnglishName().toUpper() == englishName) if (pulsar->getEnglishName().toUpper() == englishName.toUppe r())
return qSharedPointerCast<StelObject>(pulsar); return qSharedPointerCast<StelObject>(pulsar);
} }
return NULL; return NULL;
} }
StelObjectP Pulsars::searchByNameI18n(const QString& nameI18n) const StelObjectP Pulsars::searchByNameI18n(const QString& nameI18n) const
{ {
QString objw = nameI18n.toUpper(); if (!flagShowPulsars)
return NULL;
foreach(const PulsarP& pulsar, psr) foreach(const PulsarP& pulsar, psr)
{ {
if (pulsar->getNameI18n().toUpper() == nameI18n) if (pulsar->getNameI18n().toUpper() == nameI18n.toUpper())
return qSharedPointerCast<StelObject>(pulsar); return qSharedPointerCast<StelObject>(pulsar);
} }
return NULL; return NULL;
} }
QStringList Pulsars::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const QStringList Pulsars::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (!flagShowPulsars)
return result;
QString objw = objPrefix.toUpper(); if (maxNbItem==0)
return result;
QString psrn;
foreach(const PulsarP& pulsar, psr) foreach(const PulsarP& pulsar, psr)
{ {
if (pulsar->getNameI18n().toUpper().left(objw.length()) == o psrn = pulsar->getNameI18n();
bjw) if (psrn.contains(objPrefix, Qt::CaseInsensitive))
{ {
result << pulsar->getNameI18n().toUpper(); result << psrn;
} }
} }
result.sort(); result.sort();
if (result.size()>maxNbItem) result.erase(result.begin()+maxNbItem, if (result.size()>maxNbItem)
result.end()); result.erase(result.begin()+maxNbItem, result.end());
return result; return result;
} }
QStringList Pulsars::listMatchingObjects(const QString& objPrefix, int maxN bItem) const QStringList Pulsars::listMatchingObjects(const QString& objPrefix, int maxN bItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (!flagShowPulsars)
return result;
QString objw = objPrefix.toUpper(); if (maxNbItem==0)
return result;
QString psrn;
foreach(const PulsarP& pulsar, psr) foreach(const PulsarP& pulsar, psr)
{ {
if (pulsar->getEnglishName().toUpper().left(objw.length()) = psrn = pulsar->getEnglishName();
= objw) if (psrn.contains(objPrefix, Qt::CaseInsensitive))
{ {
result << pulsar->getEnglishName().toUpper() ; result << psrn;
} }
} }
result.sort(); result.sort();
if (result.size()>maxNbItem) result.erase(result.begin()+maxNbItem, if (result.size()>maxNbItem)
result.end()); result.erase(result.begin()+maxNbItem, result.end());
return result; return result;
} }
QStringList Pulsars::listAllObjects(bool inEnglish) const QStringList Pulsars::listAllObjects(bool inEnglish) const
{ {
QStringList result; QStringList result;
if (inEnglish) if (inEnglish)
{ {
foreach(const PulsarP& pulsar, psr) foreach(const PulsarP& pulsar, psr)
skipping to change at line 372 skipping to change at line 417
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 Pulsars::restoreDefaultJsonFile(void) void Pulsars::restoreDefaultJsonFile(void)
{ {
if (QFileInfo(jsonCatalogPath).exists()) if (QFileInfo(jsonCatalogPath).exists())
backupJsonFile(true); backupJsonFile(true);
QFile src(":/Pulsars/pulsars.json"); QFile src(":/Pulsars/pulsars.json");
if (!src.copy(jsonCatalogPath)) if (!src.copy(jsonCatalogPath))
{ {
qWarning() << "Pulsars::restoreDefaultJsonFile cannot copy j son resource to " + jsonCatalogPath; qWarning() << "Pulsars::restoreDefaultJsonFile cannot copy j son resource to " + QDir::toNativeSeparators(jsonCatalogPath);
} }
else else
{ {
qDebug() << "Pulsars::init copied default pulsars.json to " << jsonCatalogPath; qDebug() << "Pulsars::init copied default pulsars.json to " << QDir::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("Pulsars/last_update"); conf->remove("Pulsars/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 445 skipping to change at line 490
Parse JSON file and load pulsars to map Parse JSON file and load pulsars to map
*/ */
QVariantMap Pulsars::loadPSRMap(QString path) QVariantMap Pulsars::loadPSRMap(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() << "Pulsars::loadPSRMap cannot open " << path; qWarning() << "Pulsars::loadPSRMap cannot open " << QDir::toNati veSeparators(path);
else else
map = StelJsonParser::parse(jsonFile.readAll()).toMap(); map = StelJsonParser::parse(jsonFile.readAll()).toMap();
jsonFile.close(); jsonFile.close();
return map; return map;
} }
/* /*
Set items for list of struct from data map Set items for list of struct from data map
*/ */
skipping to change at line 472 skipping to change at line 517
QVariantMap psrData = psrMap.value(psrKey).toMap(); QVariantMap psrData = psrMap.value(psrKey).toMap();
psrData["designation"] = psrKey; psrData["designation"] = psrKey;
PulsarP pulsar(new Pulsar(psrData)); PulsarP pulsar(new Pulsar(psrData));
if (pulsar->initialized) if (pulsar->initialized)
psr.append(pulsar); psr.append(pulsar);
} }
} }
int Pulsars::getJsonFileVersion(void) int Pulsars::getJsonFileFormatVersion(void)
{ {
int jsonVersion = -1; int jsonVersion = -1;
QFile jsonPSRCatalogFile(jsonCatalogPath); QFile jsonPSRCatalogFile(jsonCatalogPath);
if (!jsonPSRCatalogFile.open(QIODevice::ReadOnly)) if (!jsonPSRCatalogFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Pulsars::init cannot open " << jsonCatalogPat h; qWarning() << "Pulsars::init cannot open " << QDir::toNative Separators(jsonCatalogPath);
return jsonVersion; return jsonVersion;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&jsonPSRCatalogFile).toMap(); map = StelJsonParser::parse(&jsonPSRCatalogFile).toMap();
if (map.contains("version")) if (map.contains("version"))
{ {
jsonVersion = map.value("version").toInt(); jsonVersion = map.value("version").toInt();
} }
jsonPSRCatalogFile.close(); jsonPSRCatalogFile.close();
qDebug() << "Pulsars::getJsonFileVersion() version from file:" << js onVersion; qDebug() << "Pulsars::getJsonFileFormatVersion() version of format f rom file:" << jsonVersion;
return jsonVersion; return jsonVersion;
} }
PulsarP Pulsars::getByID(const QString& id) PulsarP Pulsars::getByID(const QString& id)
{ {
foreach(const PulsarP& pulsar, psr) foreach(const PulsarP& pulsar, psr)
{ {
if (pulsar->initialized && pulsar->designation == id) if (pulsar->initialized && pulsar->designation == id)
return pulsar; return pulsar;
} }
skipping to change at line 531 skipping to change at line 576
} }
void Pulsars::restoreDefaultConfigIni(void) void Pulsars::restoreDefaultConfigIni(void)
{ {
conf->beginGroup("Pulsars"); conf->beginGroup("Pulsars");
// delete all existing Pulsars settings... // delete all existing Pulsars settings...
conf->remove(""); conf->remove("");
conf->setValue("distribution_enabled", false); conf->setValue("distribution_enabled", false);
conf->setValue("enable_at_startup", false);
conf->setValue("updates_enabled", true); conf->setValue("updates_enabled", true);
conf->setValue("url", "http://stellarium.org/json/pulsars.json"); conf->setValue("url", "http://stellarium.org/json/pulsars.json");
conf->setValue("update_frequency_days", 100); conf->setValue("update_frequency_days", 100);
conf->setValue("flag_show_pulsars_button", true);
conf->endGroup(); conf->endGroup();
} }
void Pulsars::readSettingsFromConfig(void) void Pulsars::readSettingsFromConfig(void)
{ {
conf->beginGroup("Pulsars"); conf->beginGroup("Pulsars");
updateUrl = conf->value("url", "http://stellarium.org/json/pulsars.j son").toString(); updateUrl = conf->value("url", "http://stellarium.org/json/pulsars.j son").toString();
updateFrequencyDays = conf->value("update_frequency_days", 100).toIn t(); updateFrequencyDays = conf->value("update_frequency_days", 100).toIn t();
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 ool(); distributionEnabled = conf->value("distribution_enabled", false).toB ool();
enableAtStartup = conf->value("enable_at_startup", false).toBool();
flagShowPulsarsButton = conf->value("flag_show_pulsars_button", true
).toBool();
conf->endGroup(); conf->endGroup();
} }
void Pulsars::saveSettingsToConfig(void) void Pulsars::saveSettingsToConfig(void)
{ {
conf->beginGroup("Pulsars"); conf->beginGroup("Pulsars");
conf->setValue("url", updateUrl); conf->setValue("url", updateUrl);
conf->setValue("update_frequency_days", updateFrequencyDays); conf->setValue("update_frequency_days", updateFrequencyDays);
conf->setValue("updates_enabled", updatesEnabled ); conf->setValue("updates_enabled", updatesEnabled );
conf->setValue("distribution_enabled", distributionEnabled); conf->setValue("distribution_enabled", distributionEnabled);
conf->setValue("enable_at_startup", enableAtStartup);
conf->setValue("flag_show_pulsars_button", flagShowPulsarsButton);
conf->endGroup(); conf->endGroup();
} }
int Pulsars::getSecondsToUpdate(void) int Pulsars::getSecondsToUpdate(void)
{ {
QDateTime nextUpdate = lastUpdate.addSecs(updateFrequencyDays * 3600 * 24); QDateTime nextUpdate = lastUpdate.addSecs(updateFrequencyDays * 3600 * 24);
return QDateTime::currentDateTime().secsTo(nextUpdate); return QDateTime::currentDateTime().secsTo(nextUpdate);
} }
skipping to change at line 589 skipping to change at line 640
return; return;
} }
else else
{ {
qDebug() << "Pulsars: starting update..."; qDebug() << "Pulsars: starting update...";
} }
lastUpdate = QDateTime::currentDateTime(); lastUpdate = QDateTime::currentDateTime();
conf->setValue("Pulsars/last_update", lastUpdate.toString(Qt::ISODat e)); conf->setValue("Pulsars/last_update", lastUpdate.toString(Qt::ISODat e));
emit(jsonUpdateComplete());
updateState = Pulsars::Updating; updateState = Pulsars::Updating;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
updateFile.clear();
if (progressBar==NULL) if (progressBar==NULL)
progressBar = StelApp::getInstance().getGui()->addProgressBa r(); progressBar = StelApp::getInstance().getGui()->addProgressBa r();
progressBar->setValue(0); progressBar->setValue(0);
progressBar->setMaximum(updateUrl.size()); progressBar->setMaximum(100);
progressBar->setVisible(true);
progressBar->setFormat("Update pulsars"); progressBar->setFormat("Update pulsars");
progressBar->setVisible(true);
QNetworkRequest request; QNetworkRequest request;
request.setUrl(QUrl(updateUrl)); request.setUrl(QUrl(updateUrl));
request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Pulsars Plugin %1; http://stellarium.org/)").arg(PULSARS_PLUGIN_VERSION).to Utf8()); request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Pulsars Plugin %1; http://stellarium.org/)").arg(PULSARS_PLUGIN_VERSION).to Utf8());
downloadMgr->get(request); downloadMgr->get(request);
progressBar->setValue(100); updateState = Pulsars::CompleteUpdates;
delete progressBar;
progressBar = NULL;
updateState = CompleteUpdates;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
emit(jsonUpdateComplete()); emit(jsonUpdateComplete());
} }
void Pulsars::updateDownloadComplete(QNetworkReply* reply) void Pulsars::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() << "Pulsars::updateDownloadComplete FAILED to dow nload" << reply->url() << " Error: " << reply->errorString(); qWarning() << "Pulsars::updateDownloadComplete FAILED to dow nload" << reply->url() << " Error: " << reply->errorString();
skipping to change at line 648 skipping to change at line 690
jsonFile.close(); jsonFile.close();
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Pulsars::updateDownloadComplete: cann ot write JSON data to file:" << e.what(); qWarning() << "Pulsars::updateDownloadComplete: cann ot write JSON data to file:" << e.what();
} }
} }
if (progressBar) if (progressBar)
{
progressBar->setValue(100); progressBar->setValue(100);
delete progressBar;
progressBar = NULL;
}
} }
void Pulsars::displayMessage(const QString& message, const QString hexColor ) void Pulsars::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 Pulsars::messageTimeout(void) void Pulsars::messageTimeout(void)
{ {
foreach(int i, messageIDs) foreach(int i, messageIDs)
{ {
GETSTELMODULE(LabelMgr)->deleteLabel(i); GETSTELMODULE(LabelMgr)->deleteLabel(i);
} }
} }
void Pulsars::upgradeConfigIni(void)
{
// Upgrade settings for Pulsars plugin
if (conf->contains("Pulsars/flag_show_pulsars"))
{
bool b = conf->value("Pulsars/flag_show_pulsars", false).toB
ool();
if (!conf->contains("Pulsars/enable_at_startup"))
conf->setValue("Pulsars/enable_at_startup", b);
conf->remove("Pulsars/flag_show_pulsars");
}
}
// Define whether the button toggling pulsars should be visible
void Pulsars::setFlagShowPulsarsButton(bool b)
{
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui(
));
if (b==true) {
if (toolbarButton==NULL) {
// Create the pulsars button
gui->getGuiAction("actionShow_Pulsars")->setChecked(
flagShowPulsars);
toolbarButton = new StelButton(NULL, *OnIcon, *OffIc
on, *GlowIcon, gui->getGuiAction("actionShow_Pulsars"));
}
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr
oup");
} else {
gui->getButtonBar()->hideButton("actionShow_Pulsars");
}
flagShowPulsarsButton = b;
}
 End of changes. 46 change blocks. 
39 lines changed or deleted 83 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/