Pulsars.cpp   Pulsars.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 "LabelMgr.hpp" #include "LabelMgr.hpp"
#include "Pulsar.hpp" #include "Pulsar.hpp"
#include "Pulsars.hpp" #include "Pulsars.hpp"
#include "PulsarsDialog.hpp" #include "PulsarsDialog.hpp"
#include "renderer/StelRenderer.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 <QDir> #include <QDir>
#include <QSettings>
#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 75 skipping to change at line 77
StelPluginInfo PulsarsStelPluginInterface::getPluginInfo() const StelPluginInfo PulsarsStelPluginInterface::getPluginInfo() const
{ {
Q_INIT_RESOURCE(Pulsars); Q_INIT_RESOURCE(Pulsars);
StelPluginInfo info; StelPluginInfo info;
info.id = "Pulsars"; info.id = "Pulsars";
info.displayedName = N_("Pulsars"); info.displayedName = N_("Pulsars");
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 various pul sars, with object information about each one."); info.description = N_("This plugin plots the position of various pul sars, with object information about each one.");
info.version = PULSARS_PLUGIN_VERSION;
return info; return info;
} }
Q_EXPORT_PLUGIN2(Pulsars, PulsarsStelPluginInterface)
/* /*
Constructor Constructor
*/ */
Pulsars::Pulsars() Pulsars::Pulsars()
: texPointer(NULL) : PsrCount(0)
, markerTexture(NULL) , updateState(CompleteNoUpdates)
, downloadMgr(NULL)
, updateTimer(0)
, messageTimer(0)
, updatesEnabled(false)
, updateFrequencyDays(0)
, enableAtStartup(false)
, flagShowPulsars(false) , flagShowPulsars(false)
, flagShowPulsarsButton(false)
, OnIcon(NULL) , OnIcon(NULL)
, OffIcon(NULL) , OffIcon(NULL)
, GlowIcon(NULL) , GlowIcon(NULL)
, toolbarButton(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());
skipping to change at line 117 skipping to change at line 125
delete GlowIcon; delete GlowIcon;
if (OnIcon) if (OnIcon)
delete OnIcon; delete OnIcon;
if (OffIcon) if (OffIcon)
delete OffIcon; delete OffIcon;
} }
void Pulsars::deinit() void Pulsars::deinit()
{ {
psr.clear(); psr.clear();
if(NULL != markerTexture) Pulsar::markerTexture.clear();
{ texPointer.clear();
delete markerTexture;
}
if(NULL != texPointer)
{
delete texPointer;
}
} }
/* /*
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*/ */
double Pulsars::getCallOrder(StelModuleActionName actionName) const double Pulsars::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 151 skipping to change at line 153
{ {
upgradeConfigIni(); 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: no Pulsars section exists in m ain 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";
if (jsonCatalogPath.isEmpty())
return;
texPointer = StelApp::getInstance().getTextureManager().crea
teTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
Pulsar::markerTexture = StelApp::getInstance().getTextureMan
ager().createTexture(":/Pulsars/pulsar.png");
// key bindings and other actions // key bindings and other actions
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() addAction("actionShow_Pulsars", N_("Pulsars"), N_("Show puls
.getGui()); ars"), "pulsarsVisible", "Ctrl+Alt+P");
addAction("actionShow_Pulsars_ConfigDialog", N_("Pulsars"),
N_("Pulsars configuration window"), configDialog, "visible");
GlowIcon = new QPixmap(":/graphicsGui/glow32x32.png"); GlowIcon = new QPixmap(":/graphicGui/glow32x32.png");
OnIcon = new QPixmap(":/Pulsars/btPulsars-on.png"); OnIcon = new QPixmap(":/Pulsars/btPulsars-on.png");
OffIcon = new QPixmap(":/Pulsars/btPulsars-off.png"); OffIcon = new QPixmap(":/Pulsars/btPulsars-off.png");
setFlagShowPulsars(getEnableAtStartup()); setFlagShowPulsars(getEnableAtStartup());
setFlagShowPulsarsButton(flagShowPulsarsButton); setFlagShowPulsarsButton(flagShowPulsarsButton);
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(gui->getGuiAction("actionShow_Pulsars"), SIGNAL(togg
led(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 (!checkJsonFileFormat() || getJsonFileFormatVersion()<CAT ALOG_FORMAT_VERSION) if (!checkJsonFileFormat() || getJsonFileFormatVersion()<CAT ALOG_FORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Pulsars::init pulsars.json does not exist - cop ying default file to " << QDir::toNativeSeparators(jsonCatalogPath); qDebug() << "Pulsars: pulsars.json does not exist - copying default file to" << QDir::toNativeSeparators(jsonCatalogPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Pulsars::init using file: " << QDir::toNativeSeparators (jsonCatalogPath); qDebug() << "Pulsars: loading catalog file:" << QDir::toNativeSepara tors(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);
} }
/* /*
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)
{ {
if (!flagShowPulsars) if (!flagShowPulsars)
return; return;
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000); StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
renderer->setFont(font); StelPainter painter(prj);
painter.setFont(font);
foreach (const PulsarP& pulsar, psr) foreach (const PulsarP& pulsar, psr)
{ {
if (pulsar && pulsar->initialized) if (pulsar && pulsar->initialized)
{ pulsar->draw(core, &painter);
if(NULL == markerTexture)
{
markerTexture = renderer->createTexture(":/P
ulsars/pulsar.png");
}
pulsar->draw(core, renderer, prj, markerTexture);
}
} }
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
{ drawPointer(core, painter);
drawPointer(core, renderer, prj);
}
} }
void Pulsars::drawPointer(StelCore* core, StelRenderer* renderer, StelProje ctorP projector) void Pulsars::drawPointer(StelCore* core, StelPainter& painter)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000)
;
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Pulsar"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Pulsar");
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> 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) if (!flagShowPulsars)
return result; return result;
skipping to change at line 438 skipping to change at line 433
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 " + QDir::toNativeSeparators(jsonCatalogPath); qWarning() << "Pulsars: cannot copy JSON resource to" + QDir ::toNativeSeparators(jsonCatalogPath);
} }
else else
{ {
qDebug() << "Pulsars::init copied default pulsars.json to " << QDir::toNativeSeparators(jsonCatalogPath); qDebug() << "Pulsars: copied default pulsars.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("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 464 skipping to change at line 459
} }
/* /*
Creates a backup of the pulsars.json file called pulsars.json.old Creates a backup of the pulsars.json file called pulsars.json.old
*/ */
bool Pulsars::backupJsonFile(bool deleteOriginal) bool Pulsars::backupJsonFile(bool deleteOriginal)
{ {
QFile old(jsonCatalogPath); QFile old(jsonCatalogPath);
if (!old.exists()) if (!old.exists())
{ {
qWarning() << "Pulsars::backupJsonFile no file to backup"; qWarning() << "Pulsars: 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() << "Pulsars::backupJsonFile WARNI NG - could not remove old pulsars.json file"; qWarning() << "Pulsars: WARNING - could not remove old pulsars.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Pulsars::backupJsonFile WARNING - failed to c opy pulsars.json to pulsars.json.old"; qWarning() << "Pulsars: WARNING - failed to copy pulsars.jso n to pulsars.json.old";
return false; return false;
} }
return true; return true;
} }
/* /*
Read the JSON file and create list of pulsars. Read the JSON file and create list of pulsars.
*/ */
void Pulsars::readJsonFile(void) void Pulsars::readJsonFile(void)
skipping to change at line 511 skipping to change at line 506
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 " << QDir::toNati veSeparators(path); qWarning() << "Pulsars: cannot open" << QDir::toNativeSepara tors(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 Pulsars::setPSRMap(const QVariantMap& map) void Pulsars::setPSRMap(const QVariantMap& map)
{ {
psr.clear(); psr.clear();
PsrCount = 0;
QVariantMap psrMap = map.value("pulsars").toMap(); QVariantMap psrMap = map.value("pulsars").toMap();
foreach(QString psrKey, psrMap.keys()) foreach(QString psrKey, psrMap.keys())
{ {
QVariantMap psrData = psrMap.value(psrKey).toMap(); QVariantMap psrData = psrMap.value(psrKey).toMap();
psrData["designation"] = psrKey; psrData["designation"] = psrKey;
PsrCount++;
PulsarP pulsar(new Pulsar(psrData)); PulsarP pulsar(new Pulsar(psrData));
if (pulsar->initialized) if (pulsar->initialized)
psr.append(pulsar); psr.append(pulsar);
} }
} }
int Pulsars::getJsonFileFormatVersion(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 " << QDir::toNative Separators(jsonCatalogPath); qWarning() << "Pulsars: cannot open" << QDir::toNativeSepara tors(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::getJsonFileFormatVersion() version of format f rom file:" << jsonVersion; qDebug() << "Pulsars: version of the format of the catalog:" << json Version;
return jsonVersion; return jsonVersion;
} }
bool Pulsars::checkJsonFileFormat() bool Pulsars::checkJsonFileFormat()
{ {
QFile jsonPSRCatalogFile(jsonCatalogPath); QFile jsonPSRCatalogFile(jsonCatalogPath);
if (!jsonPSRCatalogFile.open(QIODevice::ReadOnly)) if (!jsonPSRCatalogFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Pulsars::checkJsonFileFormat(): cannot open " << QDir::toNativeSeparators(jsonCatalogPath); qWarning() << "Pulsars: cannot open" << QDir::toNativeSepara tors(jsonCatalogPath);
return false; return false;
} }
QVariantMap map; QVariantMap map;
try try
{ {
map = StelJsonParser::parse(&jsonPSRCatalogFile).toMap(); map = StelJsonParser::parse(&jsonPSRCatalogFile).toMap();
jsonPSRCatalogFile.close(); jsonPSRCatalogFile.close();
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "Pulsars::checkJsonFileFormat(): file format is qDebug() << "Pulsars: file format is wrong! Error:" << e.wha
wrong!"; t();
qDebug() << "Pulsars::checkJsonFileFormat() error:" << e.wha
t();
return false; return false;
} }
return true; return true;
} }
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;
} }
return PulsarP(); return PulsarP();
} }
bool Pulsars::configureGui(bool show) bool Pulsars::configureGui(bool show)
{ {
if (show) if (show)
{ configDialog->setVisible(true);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance()
.getGui());
gui->getGuiAction("actionShow_Pulsars_ConfigDialog")->setChe
cked(true);
}
return true; return true;
} }
void Pulsars::restoreDefaults(void) void Pulsars::restoreDefaults(void)
{ {
restoreDefaultConfigIni(); restoreDefaultConfigIni();
restoreDefaultJsonFile(); restoreDefaultJsonFile();
readJsonFile(); readJsonFile();
readSettingsFromConfig(); readSettingsFromConfig();
} }
skipping to change at line 627 skipping to change at line 621
// 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("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->setValue("flag_show_pulsars_button", true);
conf->setValue("marker_color", "0.4,0.5,1.0");
conf->setValue("glitch_color", "0.2,0.3,1.0");
conf->setValue("use_separate_colors", false);
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 setDisplayMode(conf->value("distribution_enabled", false).toBool());
ool(); setGlitchFlag(conf->value("use_separate_colors", false).toBool());
setMarkerColor(conf->value("marker_color", "0.4,0.5,1.0").toString()
, true);
setMarkerColor(conf->value("glitch_color", "0.2,0.3,1.0").toString()
, false);
enableAtStartup = conf->value("enable_at_startup", false).toBool(); enableAtStartup = conf->value("enable_at_startup", false).toBool();
flagShowPulsarsButton = conf->value("flag_show_pulsars_button", true ).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", getDisplayMode());
conf->setValue("use_separate_colors", getGlitchFlag());
conf->setValue("enable_at_startup", enableAtStartup); conf->setValue("enable_at_startup", enableAtStartup);
conf->setValue("flag_show_pulsars_button", flagShowPulsarsButton); conf->setValue("flag_show_pulsars_button", flagShowPulsarsButton);
conf->setValue("marker_color", getMarkerColor(true));
conf->setValue("glitch_color", getMarkerColor(false));
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 690 skipping to change at line 693
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));
updateState = Pulsars::Updating; updateState = Pulsars::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 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);
updateState = Pulsars::CompleteUpdates; updateState = Pulsars::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: FAILED to download" << reply->url() << " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
try QString jsonFilePath = StelFileMgr::findFile("modules/Pulsar
s", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/p
ulsars.json";
if (jsonFilePath.isEmpty())
{ {
QString jsonFilePath = StelFileMgr::findFile("module qWarning() << "Pulsars: cannot write JSON data to fi
s/Pulsars", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory le:" << QDir::toNativeSeparators(jsonCatalogPath);
)) + "/pulsars.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() << "Pulsars::updateDownloadComplete: cann
ot 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 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)
skipping to change at line 773 skipping to change at line 774
if (!conf->contains("Pulsars/enable_at_startup")) if (!conf->contains("Pulsars/enable_at_startup"))
conf->setValue("Pulsars/enable_at_startup", b); conf->setValue("Pulsars/enable_at_startup", b);
conf->remove("Pulsars/flag_show_pulsars"); conf->remove("Pulsars/flag_show_pulsars");
} }
} }
// Define whether the button toggling pulsars should be visible // Define whether the button toggling pulsars should be visible
void Pulsars::setFlagShowPulsarsButton(bool b) void Pulsars::setFlagShowPulsarsButton(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 pulsars button if (b==true) {
gui->getGuiAction("actionShow_Pulsars")->setChecked( if (toolbarButton==NULL) {
flagShowPulsars); // Create the pulsars button
toolbarButton = new StelButton(NULL, *OnIcon, *OffIc toolbarButton = new StelButton(NULL, *OnIcon
on, *GlowIcon, gui->getGuiAction("actionShow_Pulsars")); , *OffIcon, *GlowIcon, "actionShow_Pulsars");
} }
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr gui->getButtonBar()->addButton(toolbarButton, "065-p
oup"); luginsGroup");
} else { } else {
gui->getButtonBar()->hideButton("actionShow_Pulsars"); gui->getButtonBar()->hideButton("actionShow_Pulsars"
);
}
} }
flagShowPulsarsButton = b; flagShowPulsarsButton = b;
} }
bool Pulsars::getDisplayMode()
{
return Pulsar::distributionMode;
}
void Pulsars::setDisplayMode(bool b)
{
Pulsar::distributionMode=b;
}
bool Pulsars::getGlitchFlag()
{
return Pulsar::glitchFlag;
}
void Pulsars::setGlitchFlag(bool b)
{
Pulsar::glitchFlag=b;
}
QString Pulsars::getMarkerColor(bool mtype)
{
Vec3f c;
if (mtype)
c = Pulsar::markerColor;
else
c = Pulsar::glitchColor;
return QString("%1,%2,%3").arg(c[0]).arg(c[1]).arg(c[2]);
}
void Pulsars::setMarkerColor(QString c, bool mtype)
{
if (mtype)
Pulsar::markerColor = StelUtils::strToVec3f(c);
else
Pulsar::glitchColor = StelUtils::strToVec3f(c);
}
 End of changes. 58 change blocks. 
118 lines changed or deleted 117 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/