Supernovae.cpp   Supernovae.cpp 
skipping to change at line 53 skipping to change at line 53
#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>
#include <QVariantMap> #include <QVariantMap>
#include <QDir>
#define CATALOG_FORMAT_VERSION 1 /* Version of format of catalog */ #define CATALOG_FORMAT_VERSION 1 /* Version of format of catalog */
/* /*
This method is the one called automatically by the StelModuleMgr just This method is the one called automatically by the StelModuleMgr just
after loading the dynamic library after loading the dynamic library
*/ */
StelModule* SupernovaeStelPluginInterface::getStelModule() const StelModule* SupernovaeStelPluginInterface::getStelModule() const
{ {
return new Supernovae(); return new Supernovae();
skipping to change at line 168 skipping to change at line 169
// If the json file does not already exist, create it from the resou rce in the Qt resource // If the json file does not already exist, create it from the resou rce in the Qt resource
if(QFileInfo(sneJsonPath).exists()) if(QFileInfo(sneJsonPath).exists())
{ {
if (getJsonFileVersion() < CATALOG_FORMAT_VERSION) if (getJsonFileVersion() < CATALOG_FORMAT_VERSION)
{ {
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
} }
else else
{ {
qDebug() << "Supernovae::init supernovae.json does not exist - copying default file to " << sneJsonPath; qDebug() << "Supernovae::init supernovae.json does not exist - copying default file to " << QDir::toNativeSeparators(sneJsonPath);
restoreDefaultJsonFile(); restoreDefaultJsonFile();
} }
qDebug() << "Supernovae::init using supernovae.json file: " << sneJs onPath; qDebug() << "Supernovae::init using file: " << QDir::toNativeSeparat ors(sneJsonPath);
readJsonFile(); readJsonFile();
// Set up download manager and the update schedule // Set up download manager and the update schedule
downloadMgr = new QNetworkAccessManager(this); downloadMgr = new QNetworkAccessManager(this);
connect(downloadMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(up dateDownloadComplete(QNetworkReply*))); connect(downloadMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(up dateDownloadComplete(QNetworkReply*)));
updateState = CompleteNoUpdates; updateState = CompleteNoUpdates;
updateTimer = new QTimer(this); updateTimer = new QTimer(this);
updateTimer->setSingleShot(false); // recurring check for update updateTimer->setSingleShot(false); // recurring check for update
updateTimer->setInterval(13000); // check once every 13 seconds to see if it is time for an update updateTimer->setInterval(13000); // check once every 13 seconds to see if it is time for an update
skipping to change at line 266 skipping to change at line 267
result.append(qSharedPointerCast<StelObject> (sn)); result.append(qSharedPointerCast<StelObject> (sn));
} }
} }
} }
return result; return result;
} }
StelObjectP Supernovae::searchByName(const QString& englishName) const StelObjectP Supernovae::searchByName(const QString& englishName) const
{ {
QString objw = englishName.toUpper();
foreach(const SupernovaP& sn, snstar) foreach(const SupernovaP& sn, snstar)
{ {
if (sn->getEnglishName().toUpper() == englishName) if (sn->getEnglishName().toUpper() == englishName.toUpper())
return qSharedPointerCast<StelObject>(sn); return qSharedPointerCast<StelObject>(sn);
} }
return NULL; return NULL;
} }
StelObjectP Supernovae::searchByNameI18n(const QString& nameI18n) const StelObjectP Supernovae::searchByNameI18n(const QString& nameI18n) const
{ {
QString objw = nameI18n.toUpper();
foreach(const SupernovaP& sn, snstar) foreach(const SupernovaP& sn, snstar)
{ {
if (sn->getNameI18n().toUpper() == nameI18n) if (sn->getNameI18n().toUpper() == nameI18n.toUpper())
return qSharedPointerCast<StelObject>(sn); return qSharedPointerCast<StelObject>(sn);
} }
return NULL; return NULL;
} }
QStringList Supernovae::listMatchingObjectsI18n(const QString& objPrefix, i nt maxNbItem) const QStringList Supernovae::listMatchingObjectsI18n(const QString& objPrefix, i nt maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0)
return result;
QString objw = objPrefix.toUpper();
QString snn;
foreach(const SupernovaP& sn, snstar) foreach(const SupernovaP& sn, snstar)
{ {
if (sn->getNameI18n().toUpper().left(objw.length()) == objw) snn = sn->getNameI18n();
if (snn.contains(objPrefix, Qt::CaseInsensitive))
{ {
result << sn->getNameI18n().toUpper(); result << snn;
} }
} }
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 Supernovae::listMatchingObjects(const QString& objPrefix, int m axNbItem) const QStringList Supernovae::listMatchingObjects(const QString& objPrefix, int m axNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0)
return result;
QString objw = objPrefix.toUpper();
QString snn;
foreach(const SupernovaP& sn, snstar) foreach(const SupernovaP& sn, snstar)
{ {
if (sn->getEnglishName().toUpper().left(objw.length()) == ob snn = sn->getEnglishName();
jw) if (snn.contains(objPrefix, Qt::CaseInsensitive))
{ {
result << sn->getEnglishName().toUpper(); result << snn;
} }
} }
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 Supernovae::listAllObjects(bool inEnglish) const QStringList Supernovae::listAllObjects(bool inEnglish) const
{ {
QStringList result; QStringList result;
if (inEnglish) if (inEnglish)
{ {
foreach (const SupernovaP& sn, snstar) foreach (const SupernovaP& sn, snstar)
skipping to change at line 362 skipping to change at line 364
Replace the JSON file with the default from the compiled-in resource Replace the JSON file with the default from the compiled-in resource
*/ */
void Supernovae::restoreDefaultJsonFile(void) void Supernovae::restoreDefaultJsonFile(void)
{ {
if (QFileInfo(sneJsonPath).exists()) if (QFileInfo(sneJsonPath).exists())
backupJsonFile(true); backupJsonFile(true);
QFile src(":/Supernovae/supernovae.json"); QFile src(":/Supernovae/supernovae.json");
if (!src.copy(sneJsonPath)) if (!src.copy(sneJsonPath))
{ {
qWarning() << "Supernovae::restoreDefaultJsonFile cannot cop y json resource to " + sneJsonPath; qWarning() << "Supernovae::restoreDefaultJsonFile cannot cop y json resource to " + QDir::toNativeSeparators(sneJsonPath);
} }
else else
{ {
qDebug() << "Supernovae::init copied default supernovae.json to " << sneJsonPath; qDebug() << "Supernovae::init copied default supernovae.json to " << QDir::toNativeSeparators(sneJsonPath);
// The resource is read only, and the new file inherits this ... make sure the new file // The resource is read only, and the new file inherits this ... make sure the new file
// is writable by the Stellarium process so that updates can be done. // is writable by the Stellarium process so that updates can be done.
QFile dest(sneJsonPath); QFile dest(sneJsonPath);
dest.setPermissions(dest.permissions() | QFile::WriteOwner); dest.setPermissions(dest.permissions() | QFile::WriteOwner);
// Make sure that in the case where an online update has pre viously been done, but // Make sure that in the case where an online update has pre viously been done, but
// the json file has been manually removed, that an update i s schreduled in a timely // the json file has been manually removed, that an update i s schreduled in a timely
// manner // manner
conf->remove("Supernovae/last_update"); conf->remove("Supernovae/last_update");
lastUpdate = QDateTime::fromString("2012-05-24T12:00:00", Qt ::ISODate); lastUpdate = QDateTime::fromString("2012-05-24T12:00:00", Qt ::ISODate);
skipping to change at line 435 skipping to change at line 437
Parse JSON file and load supernovaes to map Parse JSON file and load supernovaes to map
*/ */
QVariantMap Supernovae::loadSNeMap(QString path) QVariantMap Supernovae::loadSNeMap(QString path)
{ {
if (path.isEmpty()) if (path.isEmpty())
path = sneJsonPath; path = sneJsonPath;
QVariantMap map; QVariantMap map;
QFile jsonFile(path); QFile jsonFile(path);
if (!jsonFile.open(QIODevice::ReadOnly)) if (!jsonFile.open(QIODevice::ReadOnly))
qWarning() << "Supernovae::loadSNeMap cannot open " << path; qWarning() << "Supernovae::loadSNeMap cannot open " << QDir::toN ativeSeparators(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 471 skipping to change at line 473
} }
} }
int Supernovae::getJsonFileVersion(void) int Supernovae::getJsonFileVersion(void)
{ {
int jsonVersion = -1; int jsonVersion = -1;
QFile sneJsonFile(sneJsonPath); QFile sneJsonFile(sneJsonPath);
if (!sneJsonFile.open(QIODevice::ReadOnly)) if (!sneJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Supernovae::init cannot open " << sneJsonPath ; qWarning() << "Supernovae::init cannot open " << QDir::toNat iveSeparators(sneJsonPath);
return jsonVersion; return jsonVersion;
} }
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&sneJsonFile).toMap(); map = StelJsonParser::parse(&sneJsonFile).toMap();
if (map.contains("version")) if (map.contains("version"))
{ {
jsonVersion = map.value("version").toInt(); jsonVersion = map.value("version").toInt();
} }
skipping to change at line 579 skipping to change at line 581
return; return;
} }
else else
{ {
qDebug() << "Supernovae: starting update..."; qDebug() << "Supernovae: starting update...";
} }
lastUpdate = QDateTime::currentDateTime(); lastUpdate = QDateTime::currentDateTime();
conf->setValue("Supernovae/last_update", lastUpdate.toString(Qt::ISO Date)); conf->setValue("Supernovae/last_update", lastUpdate.toString(Qt::ISO Date));
emit(jsonUpdateComplete());
updateState = Supernovae::Updating; updateState = Supernovae::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 historical supernovae"); progressBar->setFormat("Update historical supernovae");
progressBar->setVisible(true);
QNetworkRequest request; QNetworkRequest request;
request.setUrl(QUrl(updateUrl)); request.setUrl(QUrl(updateUrl));
request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Historical Supernovae Plugin %1; http://stellarium.org/)").arg(SUPERNOVAE_P LUGIN_VERSION).toUtf8()); request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Historical Supernovae Plugin %1; http://stellarium.org/)").arg(SUPERNOVAE_P LUGIN_VERSION).toUtf8());
downloadMgr->get(request); downloadMgr->get(request);
progressBar->setValue(100); updateState = Supernovae::CompleteUpdates;
delete progressBar;
progressBar = NULL;
updateState = CompleteUpdates;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
emit(jsonUpdateComplete()); emit(jsonUpdateComplete());
} }
void Supernovae::updateDownloadComplete(QNetworkReply* reply) void Supernovae::updateDownloadComplete(QNetworkReply* reply)
{ {
// check the download worked, and save the data to file if this is t he case. // check the download worked, and save the data to file if this is t he case.
if (reply->error() != QNetworkReply::NoError) if (reply->error() != QNetworkReply::NoError)
{ {
qWarning() << "Supernovae::updateDownloadComplete FAILED to download" << reply->url() << " Error: " << reply->errorString(); qWarning() << "Supernovae::updateDownloadComplete FAILED to download" << reply->url() << " Error: " << reply->errorString();
skipping to change at line 638 skipping to change at line 631
jsonFile.close(); jsonFile.close();
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Supernovae::updateDownloadComplete: c annot write JSON data to file:" << e.what(); qWarning() << "Supernovae::updateDownloadComplete: c annot write JSON data to file:" << e.what();
} }
} }
if (progressBar) if (progressBar)
{
progressBar->setValue(100); progressBar->setValue(100);
delete progressBar;
progressBar = NULL;
}
} }
void Supernovae::displayMessage(const QString& message, const QString hexCo lor) void Supernovae::displayMessage(const QString& message, const QString hexCo lor)
{ {
messageIDs << GETSTELMODULE(LabelMgr)->labelScreen(message, 30, 30 + (20*messageIDs.count()), true, 16, hexColor); messageIDs << GETSTELMODULE(LabelMgr)->labelScreen(message, 30, 30 + (20*messageIDs.count()), true, 16, hexColor);
messageTimer->start(); messageTimer->start();
} }
void Supernovae::messageTimeout(void) void Supernovae::messageTimeout(void)
{ {
 End of changes. 29 change blocks. 
38 lines changed or deleted 32 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/