Quasars.cpp   Quasars.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 "Quasar.hpp" #include "Quasar.hpp"
#include "Quasars.hpp" #include "Quasars.hpp"
#include "renderer/StelRenderer.hpp"
#include "QuasarsDialog.hpp" #include "QuasarsDialog.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* QuasarsStelPluginInterface::getStelModule() const StelModule* QuasarsStelPluginInterface::getStelModule() const
{ {
return new Quasars(); return new Quasars();
skipping to change at line 75 skipping to change at line 77
StelPluginInfo QuasarsStelPluginInterface::getPluginInfo() const StelPluginInfo QuasarsStelPluginInterface::getPluginInfo() const
{ {
Q_INIT_RESOURCE(Quasars); Q_INIT_RESOURCE(Quasars);
StelPluginInfo info; StelPluginInfo info;
info.id = "Quasars"; info.id = "Quasars";
info.displayedName = N_("Quasars"); info.displayedName = N_("Quasars");
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 quasars brighter tha n 16 visual magnitude. A catalogue of quasars compiled from 'Quasars and Ac tive Galactic Nuclei' (13th Ed.) (Veron+ 2010) =2010A&A...518A..10V"); info.description = N_("A plugin that shows some quasars brighter tha n 16 visual magnitude. A catalogue of quasars compiled from 'Quasars and Ac tive Galactic Nuclei' (13th Ed.) (Veron+ 2010) =2010A&A...518A..10V");
info.version = QUASARS_PLUGIN_VERSION;
return info; return info;
} }
Q_EXPORT_PLUGIN2(Quasars, QuasarsStelPluginInterface)
/* /*
Constructor Constructor
*/ */
Quasars::Quasars() Quasars::Quasars()
: texPointer(NULL) : QsrCount(0)
, markerTexture(NULL) , updateState(CompleteNoUpdates)
, downloadMgr(NULL)
, updateTimer(0)
, messageTimer(0)
, updatesEnabled(false)
, updateFrequencyDays(0)
, enableAtStartup(false)
, flagShowQuasars(false) , flagShowQuasars(false)
, flagShowQuasarsButton(false)
, OnIcon(NULL) , OnIcon(NULL)
, OffIcon(NULL) , OffIcon(NULL)
, GlowIcon(NULL) , GlowIcon(NULL)
, toolbarButton(NULL) , toolbarButton(NULL)
, progressBar(NULL) , progressBar(NULL)
{ {
setObjectName("Quasars"); setObjectName("Quasars");
configDialog = new QuasarsDialog(); configDialog = new QuasarsDialog();
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
*/ */
skipping to change at line 116 skipping to change at line 125
if (GlowIcon) if (GlowIcon)
delete GlowIcon; delete GlowIcon;
if (OnIcon) if (OnIcon)
delete OnIcon; delete OnIcon;
if (OffIcon) if (OffIcon)
delete OffIcon; delete OffIcon;
} }
void Quasars::deinit() void Quasars::deinit()
{ {
if(NULL != texPointer) {delete texPointer;}
if(NULL != markerTexture) {delete markerTexture;}
texPointer = markerTexture = NULL;
QSO.clear(); QSO.clear();
Quasar::markerTexture.clear();
texPointer.clear();
} }
/* /*
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*/ */
double Quasars::getCallOrder(StelModuleActionName actionName) const double Quasars::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 146 skipping to change at line 154
{ {
upgradeConfigIni(); upgradeConfigIni();
try try
{ {
StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Quasars"); StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/modules/Quasars");
// 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("Quasars")) if (!conf->childGroups().contains("Quasars"))
{ {
qDebug() << "Quasars::init no Quasars section exists in main config file - creating with defaults"; qDebug() << "Quasars: no Quasars 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();
catalogJsonPath = StelFileMgr::findFile("modules/Quasars", ( StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/quas ars.json"; catalogJsonPath = StelFileMgr::findFile("modules/Quasars", ( StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/quas ars.json";
if (catalogJsonPath.isEmpty())
return;
texPointer = StelApp::getInstance().getTextureManager().crea
teTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
Quasar::markerTexture = StelApp::getInstance().getTextureMan
ager().createTexture(":/Quasars/quasar.png");
// key bindings and other actions // key bindings and other actions
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() addAction("actionShow_Quasars", N_("Quasars"), N_("Show quas
.getGui()); ars"), "quasarsVisible", "Ctrl+Alt+Q");
addAction("actionShow_Quasars_ConfigDialog", N_("Quasars"),
N_("Quasars configuration window"), configDialog, "visible");
GlowIcon = new QPixmap(":/graphicsGui/glow32x32.png"); GlowIcon = new QPixmap(":/graphicGui/glow32x32.png");
OnIcon = new QPixmap(":/Quasars/btQuasars-on.png"); OnIcon = new QPixmap(":/Quasars/btQuasars-on.png");
OffIcon = new QPixmap(":/Quasars/btQuasars-off.png"); OffIcon = new QPixmap(":/Quasars/btQuasars-off.png");
setFlagShowQuasars(getEnableAtStartup()); setFlagShowQuasars(getEnableAtStartup());
setFlagShowQuasarsButton(flagShowQuasarsButton); setFlagShowQuasarsButton(flagShowQuasarsButton);
connect(gui->getGuiAction("actionShow_Quasars_ConfigDialog")
, SIGNAL(toggled(bool)), configDialog, SLOT(setVisible(bool)));
connect(configDialog, SIGNAL(visibleChanged(bool)), gui->get
GuiAction("actionShow_Quasars_ConfigDialog"), SLOT(setChecked(bool)));
connect(gui->getGuiAction("actionShow_Quasars"), SIGNAL(togg
led(bool)), this, SLOT(setFlagShowQuasars(bool)));
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Quasars::init error: " << e.what(); qWarning() << "Quasars: 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(catalogJsonPath).exists()) if(QFileInfo(catalogJsonPath).exists())
{ {
if (!checkJsonFileFormat() || getJsonFileFormatVersion()<CAT ALOG_FORMAT_VERSION) if (!checkJsonFileFormat() || getJsonFileFormatVersion()<CAT ALOG_FORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Quasars::init quasars.json does not exist - cop ying default file to " << QDir::toNativeSeparators(catalogJsonPath); qDebug() << "Quasars: quasars.json does not exist - copying default file to" << QDir::toNativeSeparators(catalogJsonPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Quasars::init using file: " << QDir::toNativeSeparators (catalogJsonPath); qDebug() << "Quasars: loading catalog file:" << QDir::toNativeSepara tors(catalogJsonPath);
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 QSO in the main window Draw our module. This should print name of first QSO in the main window
*/ */
void Quasars::draw(StelCore* core, class StelRenderer* renderer) void Quasars::draw(StelCore* core)
{ {
if (!flagShowQuasars) if (!flagShowQuasars)
return; return;
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000); StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
renderer->setFont(font); StelPainter painter(prj);
painter.setFont(font);
if(NULL == markerTexture)
{
markerTexture = renderer->createTexture(":/Quasars/quasar.pn
g");
}
foreach (const QuasarP& quasar, QSO) foreach (const QuasarP& quasar, QSO)
{ {
if (quasar && quasar->initialized) if (quasar && quasar->initialized)
{ quasar->draw(core, painter);
quasar->draw(core, renderer, prj, markerTexture);
}
} }
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
{ drawPointer(core, painter);
drawPointer(core, renderer, prj);
}
} }
void Quasars::drawPointer(StelCore* core, StelRenderer* renderer, StelProje ctorP projector) void Quasars::drawPointer(StelCore* core, StelPainter& painter)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000)
;
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Quasar"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Quasar");
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;
}
if(NULL == texPointer)
{
texPointer = renderer->createTexture("textures/point
eur2.png");
}
const Vec3f& c(obj->getInfoColor()); const Vec3f& c(obj->getInfoColor());
renderer->setGlobalColor(c[0], c[1], c[2]); painter.setColor(c[0],c[1],c[2]);
texPointer->bind(); texPointer->bind();
renderer->setBlendMode(BlendMode_Alpha); painter.enableTexture2d(true);
renderer->drawTexturedRect(screenPos[0] - 13.0f, screenPos[1 glEnable(GL_BLEND);
] - 13.0f, 26.0f, 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> Quasars::searchAround(const Vec3d& av, double limitFov, const StelCore*) const QList<StelObjectP> Quasars::searchAround(const Vec3d& av, double limitFov, const StelCore*) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!flagShowQuasars) if (!flagShowQuasars)
return result; return result;
skipping to change at line 434 skipping to change at line 434
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 Quasars::restoreDefaultJsonFile(void) void Quasars::restoreDefaultJsonFile(void)
{ {
if (QFileInfo(catalogJsonPath).exists()) if (QFileInfo(catalogJsonPath).exists())
backupJsonFile(true); backupJsonFile(true);
QFile src(":/Quasars/quasars.json"); QFile src(":/Quasars/quasars.json");
if (!src.copy(catalogJsonPath)) if (!src.copy(catalogJsonPath))
{ {
qWarning() << "Quasars::restoreDefaultJsonFile cannot copy j son resource to " + QDir::toNativeSeparators(catalogJsonPath); qWarning() << "Quasars: cannot copy json resource to" + QDir ::toNativeSeparators(catalogJsonPath);
} }
else else
{ {
qDebug() << "Quasars::init copied default catalog.json to " << QDir::toNativeSeparators(catalogJsonPath); qDebug() << "Quasars: copied default quasars.json to" << QDi r::toNativeSeparators(catalogJsonPath);
// 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(catalogJsonPath); QFile dest(catalogJsonPath);
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("Quasars/last_update"); conf->remove("Quasars/last_update");
lastUpdate = QDateTime::fromString("2012-05-24T12:00:00", Qt ::ISODate); lastUpdate = QDateTime::fromString("2012-05-24T12:00:00", Qt ::ISODate);
} }
} }
/* /*
Creates a backup of the Quasars.json file called Quasars.json.old Creates a backup of the quasars.json file called quasars.json.old
*/ */
bool Quasars::backupJsonFile(bool deleteOriginal) bool Quasars::backupJsonFile(bool deleteOriginal)
{ {
QFile old(catalogJsonPath); QFile old(catalogJsonPath);
if (!old.exists()) if (!old.exists())
{ {
qWarning() << "Quasars::backupJsonFile no file to backup"; qWarning() << "Quasars: no file to backup";
return false; return false;
} }
QString backupPath = catalogJsonPath + ".old"; QString backupPath = catalogJsonPath + ".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() << "Quasars::backupJsonFile WARNI NG - could not remove old quasars.json file"; qWarning() << "Quasars: WARNING - could not remove old quasars.json file";
return false; return false;
} }
} }
} }
else else
{ {
qWarning() << "Quasars::backupJsonFile WARNING - failed to c opy quasars.json to quasars.json.old"; qWarning() << "Quasars: WARNING - failed to copy quasars.jso n to quasars.json.old";
return false; return false;
} }
return true; return true;
} }
/* /*
Read the JSON file and create list of quasars. Read the JSON file and create list of quasars.
*/ */
void Quasars::readJsonFile(void) void Quasars::readJsonFile(void)
skipping to change at line 508 skipping to change at line 508
Parse JSON file and load quasarss to map Parse JSON file and load quasarss to map
*/ */
QVariantMap Quasars::loadQSOMap(QString path) QVariantMap Quasars::loadQSOMap(QString path)
{ {
if (path.isEmpty()) if (path.isEmpty())
path = catalogJsonPath; path = catalogJsonPath;
QVariantMap map; QVariantMap map;
QFile jsonFile(path); QFile jsonFile(path);
if (!jsonFile.open(QIODevice::ReadOnly)) if (!jsonFile.open(QIODevice::ReadOnly))
qWarning() << "Quasars::loadQSOMap cannot open " << QDir::toNati veSeparators(path); qWarning() << "Quasars: 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 Quasars::setQSOMap(const QVariantMap& map) void Quasars::setQSOMap(const QVariantMap& map)
{ {
QSO.clear(); QSO.clear();
QsrCount = 0;
QVariantMap qsoMap = map.value("quasars").toMap(); QVariantMap qsoMap = map.value("quasars").toMap();
foreach(QString qsoKey, qsoMap.keys()) foreach(QString qsoKey, qsoMap.keys())
{ {
QVariantMap qsoData = qsoMap.value(qsoKey).toMap(); QVariantMap qsoData = qsoMap.value(qsoKey).toMap();
qsoData["designation"] = qsoKey; qsoData["designation"] = qsoKey;
QsrCount++;
QuasarP quasar(new Quasar(qsoData)); QuasarP quasar(new Quasar(qsoData));
if (quasar->initialized) if (quasar->initialized)
QSO.append(quasar); QSO.append(quasar);
} }
} }
int Quasars::getJsonFileFormatVersion(void) int Quasars::getJsonFileFormatVersion(void)
{ {
int jsonVersion = -1; int jsonVersion = -1;
QFile catalogJsonFile(catalogJsonPath); QFile catalogJsonFile(catalogJsonPath);
if (!catalogJsonFile.open(QIODevice::ReadOnly)) if (!catalogJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Quasars::init cannot open " << QDir::toNative Separators(catalogJsonPath); qWarning() << "Quasars: cannot open" << QDir::toNativeSepara tors(catalogJsonPath);
return jsonVersion; return jsonVersion;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&catalogJsonFile).toMap(); map = StelJsonParser::parse(&catalogJsonFile).toMap();
if (map.contains("version")) if (map.contains("version"))
{ {
jsonVersion = map.value("version").toInt(); jsonVersion = map.value("version").toInt();
} }
catalogJsonFile.close(); catalogJsonFile.close();
qDebug() << "Quasars::getJsonFileFormatVersion() version of format f rom file:" << jsonVersion; qDebug() << "Quasars: version of the format of the catalog:" << json Version;
return jsonVersion; return jsonVersion;
} }
bool Quasars::checkJsonFileFormat() bool Quasars::checkJsonFileFormat()
{ {
QFile catalogJsonFile(catalogJsonPath); QFile catalogJsonFile(catalogJsonPath);
if (!catalogJsonFile.open(QIODevice::ReadOnly)) if (!catalogJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Quasars::checkJsonFileFormat(): cannot open " << QDir::toNativeSeparators(catalogJsonPath); qWarning() << "Quasars: cannot open" << QDir::toNativeSepara tors(catalogJsonPath);
return false; return false;
} }
QVariantMap map; QVariantMap map;
try try
{ {
map = StelJsonParser::parse(&catalogJsonFile).toMap(); map = StelJsonParser::parse(&catalogJsonFile).toMap();
catalogJsonFile.close(); catalogJsonFile.close();
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "Quasars::checkJsonFileFormat(): file format is qDebug() << "Quasars: file format is wrong! Error:" << e.wha
wrong!"; t();
qDebug() << "Quasars::checkJsonFileFormat() error:" << e.wha
t();
return false; return false;
} }
return true; return true;
} }
QuasarP Quasars::getByID(const QString& id) QuasarP Quasars::getByID(const QString& id)
{ {
foreach(const QuasarP& quasar, QSO) foreach(const QuasarP& quasar, QSO)
{ {
if (quasar->initialized && quasar->designation == id) if (quasar->initialized && quasar->designation == id)
return quasar; return quasar;
} }
return QuasarP(); return QuasarP();
} }
bool Quasars::configureGui(bool show) bool Quasars::configureGui(bool show)
{ {
if (show) if (show)
{ configDialog->setVisible(true);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance()
.getGui());
gui->getGuiAction("actionShow_Quasars_ConfigDialog")->setChe
cked(true);
}
return true; return true;
} }
void Quasars::restoreDefaults(void) void Quasars::restoreDefaults(void)
{ {
restoreDefaultConfigIni(); restoreDefaultConfigIni();
restoreDefaultJsonFile(); restoreDefaultJsonFile();
readJsonFile(); readJsonFile();
readSettingsFromConfig(); readSettingsFromConfig();
} }
skipping to change at line 624 skipping to change at line 623
// delete all existing Quasars settings... // delete all existing Quasars 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/quasars.json"); conf->setValue("url", "http://stellarium.org/json/quasars.json");
conf->setValue("update_frequency_days", 100); conf->setValue("update_frequency_days", 100);
conf->setValue("flag_show_quasars_button", true); conf->setValue("flag_show_quasars_button", true);
conf->setValue("marker_color", "1.0,0.5,0.4");
conf->endGroup(); conf->endGroup();
} }
void Quasars::readSettingsFromConfig(void) void Quasars::readSettingsFromConfig(void)
{ {
conf->beginGroup("Quasars"); conf->beginGroup("Quasars");
updateUrl = conf->value("url", "http://stellarium.org/json/quasars.j son").toString(); updateUrl = conf->value("url", "http://stellarium.org/json/quasars.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(); setMarkerColor(conf->value("marker_color", "1.0,0.5,0.4").toString()
);
enableAtStartup = conf->value("enable_at_startup", false).toBool(); enableAtStartup = conf->value("enable_at_startup", false).toBool();
flagShowQuasarsButton = conf->value("flag_show_quasars_button", true ).toBool(); flagShowQuasarsButton = conf->value("flag_show_quasars_button", true ).toBool();
conf->endGroup(); conf->endGroup();
} }
void Quasars::saveSettingsToConfig(void) void Quasars::saveSettingsToConfig(void)
{ {
conf->beginGroup("Quasars"); conf->beginGroup("Quasars");
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("enable_at_startup", enableAtStartup); conf->setValue("enable_at_startup", enableAtStartup);
conf->setValue("flag_show_quasars_button", flagShowQuasarsButton); conf->setValue("flag_show_quasars_button", flagShowQuasarsButton);
conf->setValue("marker_color", getMarkerColor());
conf->endGroup(); conf->endGroup();
} }
int Quasars::getSecondsToUpdate(void) int Quasars::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 687 skipping to change at line 689
qDebug() << "Quasars: starting update..."; qDebug() << "Quasars: starting update...";
} }
lastUpdate = QDateTime::currentDateTime(); lastUpdate = QDateTime::currentDateTime();
conf->setValue("Quasars/last_update", lastUpdate.toString(Qt::ISODat e)); conf->setValue("Quasars/last_update", lastUpdate.toString(Qt::ISODat e));
updateState = Quasars::Updating; updateState = Quasars::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 quasars"); progressBar->setFormat("Update quasars");
progressBar->setVisible(true);
QNetworkRequest request; QNetworkRequest request;
request.setUrl(QUrl(updateUrl)); request.setUrl(QUrl(updateUrl));
request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Quasars Plugin %1; http://stellarium.org/)").arg(QUASARS_PLUGIN_VERSION).to Utf8()); request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Quasars Plugin %1; http://stellarium.org/)").arg(QUASARS_PLUGIN_VERSION).to Utf8());
downloadMgr->get(request); downloadMgr->get(request);
updateState = Quasars::CompleteUpdates; updateState = Quasars::CompleteUpdates;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
emit(jsonUpdateComplete()); emit(jsonUpdateComplete());
} }
void Quasars::updateDownloadComplete(QNetworkReply* reply) void Quasars::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() << "Quasars::updateDownloadComplete FAILED to dow nload" << reply->url() << " Error: " << reply->errorString(); qWarning() << "Quasars: FAILED to download" << reply->url() << " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
try QString jsonFilePath = StelFileMgr::findFile("modules/Quasar
s", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory)) + "/q
uasars.json";
if (jsonFilePath.isEmpty())
{ {
QString jsonFilePath = StelFileMgr::findFile("module qWarning() << "Quasars: cannot write JSON data to fi
s/Quasars", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Directory le:" << QDir::toNativeSeparators(jsonFilePath);
)) + "/quasars.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() << "Quasars::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 Quasars::displayMessage(const QString& message, const QString hexColor ) void Quasars::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();
} }
skipping to change at line 770 skipping to change at line 770
if (!conf->contains("Quasars/enable_at_startup")) if (!conf->contains("Quasars/enable_at_startup"))
conf->setValue("Quasars/enable_at_startup", b); conf->setValue("Quasars/enable_at_startup", b);
conf->remove("Quasars/flag_show_quasars"); conf->remove("Quasars/flag_show_quasars");
} }
} }
// Define whether the button toggling quasars should be visible // Define whether the button toggling quasars should be visible
void Quasars::setFlagShowQuasarsButton(bool b) void Quasars::setFlagShowQuasarsButton(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 quasars button if (b==true) {
gui->getGuiAction("actionShow_Quasars")->setChecked( if (toolbarButton==NULL) {
flagShowQuasars); // Create the quasars button
toolbarButton = new StelButton(NULL, *OnIcon, *OffIc toolbarButton = new StelButton(NULL, *OnIcon
on, *GlowIcon, gui->getGuiAction("actionShow_Quasars")); , *OffIcon, *GlowIcon, "actionShow_Quasars");
} }
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr gui->getButtonBar()->addButton(toolbarButton, "065-p
oup"); luginsGroup");
} else { } else {
gui->getButtonBar()->hideButton("actionShow_Quasars"); gui->getButtonBar()->hideButton("actionShow_Quasars"
);
}
} }
flagShowQuasarsButton = b; flagShowQuasarsButton = b;
} }
bool Quasars::getDisplayMode()
{
return Quasar::distributionMode;
}
void Quasars::setDisplayMode(bool b)
{
Quasar::distributionMode=b;
}
QString Quasars::getMarkerColor()
{
Vec3f c = Quasar::markerColor;
return QString("%1,%2,%3").arg(c[0]).arg(c[1]).arg(c[2]);
}
void Quasars::setMarkerColor(QString c)
{
Quasar::markerColor = StelUtils::strToVec3f(c);
}
 End of changes. 68 change blocks. 
117 lines changed or deleted 114 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/