SolarSystemEditor.cpp   SolarSystemEditor.cpp 
skipping to change at line 97 skipping to change at line 97
{ {
//Get a list of the "default" Solar System objects' names: //Get a list of the "default" Solar System objects' names:
//TODO: Use it as validation for the loading of the plug-in //TODO: Use it as validation for the loading of the plug-in
if (QFile::exists(defaultSolarSystemFilePath)) if (QFile::exists(defaultSolarSystemFilePath))
{ {
defaultSsoIdentifiers = listAllLoadedObjectsInFile(defaultSo larSystemFilePath); defaultSsoIdentifiers = listAllLoadedObjectsInFile(defaultSo larSystemFilePath);
} }
else else
{ {
//TODO: Better error message //TODO: Better error message
qDebug() << "Something is horribly wrong:" << StelFileMgr::g etInstallationDir(); qDebug() << "Something is horribly wrong:" << QDir::toNative Separators(StelFileMgr::getInstallationDir());
return; return;
} }
try try
{ {
//Make sure that a user ssystem.ini actually exists //Make sure that a user ssystem.ini actually exists
if (!cloneSolarSystemConfigurationFile()) if (!cloneSolarSystemConfigurationFile())
return; return;
mainWindow = new SolarSystemManagerWindow(); mainWindow = new SolarSystemManagerWindow();
skipping to change at line 198 skipping to change at line 198
//The Solar System MUST be translated before updating the window //The Solar System MUST be translated before updating the window
//TODO: Remove this if/when you merge this module in the Solar Syste m module //TODO: Remove this if/when you merge this module in the Solar Syste m module
solarSystemManager->updateI18n(); solarSystemManager->updateI18n();
} }
bool SolarSystemEditor::cloneSolarSystemConfigurationFile() bool SolarSystemEditor::cloneSolarSystemConfigurationFile()
{ {
QDir userDataDirectory(StelFileMgr::getUserDir()); QDir userDataDirectory(StelFileMgr::getUserDir());
if (!userDataDirectory.exists()) if (!userDataDirectory.exists())
{ {
qDebug() << "Unable to find user data directory:" << userDat aDirectory.absolutePath(); qDebug() << "Unable to find user data directory:" << QDir::t oNativeSeparators(userDataDirectory.absolutePath());
return false; return false;
} }
if (!userDataDirectory.exists("data") && !userDataDirectory.mkdir("d ata")) if (!userDataDirectory.exists("data") && !userDataDirectory.mkdir("d ata"))
{ {
qDebug() << "Unable to create a \"data\" subdirectory in" << userDataDirectory.absolutePath(); qDebug() << "Unable to create a \"data\" subdirectory in" << QDir::toNativeSeparators(userDataDirectory.absolutePath());
return false; return false;
} }
if (QFile::exists(customSolarSystemFilePath)) if (QFile::exists(customSolarSystemFilePath))
{ {
qDebug() << "Using the ssystem.ini file that already exists in the user directory..."; qDebug() << "Using the ssystem.ini file that already exists in the user directory...";
return true; return true;
} }
if (QFile::exists(defaultSolarSystemFilePath)) if (QFile::exists(defaultSolarSystemFilePath))
{ {
qDebug() << "Trying to copy ssystem.ini to" << customSolarSy stemFilePath; qDebug() << "Trying to copy ssystem.ini to" << QDir::toNativ eSeparators(customSolarSystemFilePath);
return QFile::copy(defaultSolarSystemFilePath, customSolarSy stemFilePath); return QFile::copy(defaultSolarSystemFilePath, customSolarSy stemFilePath);
} }
else else
{ {
qDebug() << "This should be impossible."; qDebug() << "This should be impossible.";
return false; return false;
} }
} }
bool SolarSystemEditor::resetSolarSystemConfigurationFile() bool SolarSystemEditor::resetSolarSystemConfigurationFile()
{ {
if (QFile::exists(customSolarSystemFilePath)) if (QFile::exists(customSolarSystemFilePath))
{ {
if (!QFile::remove((customSolarSystemFilePath))) if (!QFile::remove((customSolarSystemFilePath)))
{ {
qWarning() << "Unable to delete" << customSolarSyste mFilePath qWarning() << "Unable to delete" << QDir::toNativeSe parators(customSolarSystemFilePath)
<< endl << "Please remove the file manually ."; << endl << "Please remove the file manually .";
return false; return false;
} }
} }
return cloneSolarSystemConfigurationFile(); return cloneSolarSystemConfigurationFile();
} }
void SolarSystemEditor::resetSolarSystemToDefault() void SolarSystemEditor::resetSolarSystemToDefault()
{ {
skipping to change at line 282 skipping to change at line 282
if (!QFile::exists(filePath)) if (!QFile::exists(filePath))
{ {
//TODO: Message //TODO: Message
return false; return false;
} }
//Is it a valid configuration file? //Is it a valid configuration file?
QSettings settings(filePath, QSettings::IniFormat); QSettings settings(filePath, QSettings::IniFormat);
if (settings.status() != QSettings::NoError) if (settings.status() != QSettings::NoError)
{ {
qWarning() << filePath << "is not a valid configuration file ."; qWarning() << QDir::toNativeSeparators(filePath) << "is not a valid configuration file.";
return false; return false;
} }
//Remove the existingfile //Remove the existingfile
if (QFile::exists(customSolarSystemFilePath)) if (QFile::exists(customSolarSystemFilePath))
{ {
if(!QFile::remove(customSolarSystemFilePath)) if(!QFile::remove(customSolarSystemFilePath))
{ {
//TODO: Message //TODO: Message
return false; return false;
skipping to change at line 372 skipping to change at line 372
//qDebug() << name; //qDebug() << name;
if (defaultSsoIdentifiers.keys().contains(name)) if (defaultSsoIdentifiers.keys().contains(name))
{ {
qWarning() << "You can't delete the default Solar System obj ects for the moment."; qWarning() << "You can't delete the default Solar System obj ects for the moment.";
return false; return false;
} }
//Make sure that the file exists //Make sure that the file exists
if (!QFile::exists(customSolarSystemFilePath)) if (!QFile::exists(customSolarSystemFilePath))
{ {
qDebug() << "Can't remove" << name << "to ssystem.ini: Unabl e to find" << customSolarSystemFilePath; qDebug() << "Can't remove" << name << "to ssystem.ini: Unabl e to find" << QDir::toNativeSeparators(customSolarSystemFilePath);
return false; return false;
} }
//Open the file //Open the file
QSettings settings(customSolarSystemFilePath, QSettings::IniFormat); QSettings settings(customSolarSystemFilePath, QSettings::IniFormat);
if (settings.status() != QSettings::NoError) if (settings.status() != QSettings::NoError)
{ {
qDebug() << "Error opening ssystem.ini:" << customSolarSyste mFilePath; qDebug() << "Error opening ssystem.ini:" << QDir::toNativeSe parators(customSolarSystemFilePath);
return false; return false;
} }
//Remove the section //Remove the section
foreach (QString group, settings.childGroups()) foreach (QString group, settings.childGroups())
{ {
if (settings.value(group + "/name").toString() == name) if (settings.value(group + "/name").toString() == name)
{ {
settings.remove(group); settings.remove(group);
settings.sync(); settings.sync();
skipping to change at line 988 skipping to change at line 988
return result; return result;
} }
QList<SsoElements> SolarSystemEditor::readMpcOneLineCometElementsFromFile(Q String filePath) QList<SsoElements> SolarSystemEditor::readMpcOneLineCometElementsFromFile(Q String filePath)
{ {
QList<SsoElements> objectList; QList<SsoElements> objectList;
if (!QFile::exists(filePath)) if (!QFile::exists(filePath))
{ {
qDebug() << "Can't find" << filePath; qDebug() << "Can't find" << QDir::toNativeSeparators(filePat h);
return objectList; return objectList;
} }
QFile mpcElementsFile(filePath); QFile mpcElementsFile(filePath);
if (mpcElementsFile.open(QFile::ReadOnly | QFile::Text ))//| QFile:: Unbuffered if (mpcElementsFile.open(QFile::ReadOnly | QFile::Text ))//| QFile:: Unbuffered
{ {
int candidatesCount = 0; int candidatesCount = 0;
int lineCount = 0; int lineCount = 0;
while(!mpcElementsFile.atEnd()) while(!mpcElementsFile.atEnd())
skipping to change at line 1028 skipping to change at line 1028
} }
mpcElementsFile.close(); mpcElementsFile.close();
qDebug() << "Done reading comet orbital elements." qDebug() << "Done reading comet orbital elements."
<< "Recognized" << candidatesCount << "candidate ob jects" << "Recognized" << candidatesCount << "candidate ob jects"
<< "out of" << lineCount << "lines."; << "out of" << lineCount << "lines.";
return objectList; return objectList;
} }
else else
{ {
qDebug() << "Unable to open for reading" << filePath; qDebug() << "Unable to open for reading" << QDir::toNativeSe parators(filePath);
qDebug() << "File error:" << mpcElementsFile.errorString(); qDebug() << "File error:" << mpcElementsFile.errorString();
return objectList; return objectList;
} }
return objectList; return objectList;
} }
QList<SsoElements> SolarSystemEditor::readMpcOneLineMinorPlanetElementsFrom File(QString filePath) QList<SsoElements> SolarSystemEditor::readMpcOneLineMinorPlanetElementsFrom File(QString filePath)
{ {
QList<SsoElements> objectList; QList<SsoElements> objectList;
if (!QFile::exists(filePath)) if (!QFile::exists(filePath))
{ {
qDebug() << "Can't find" << filePath; qDebug() << "Can't find" << QDir::toNativeSeparators(filePat h);
return objectList; return objectList;
} }
QFile mpcElementsFile(filePath); QFile mpcElementsFile(filePath);
if (mpcElementsFile.open(QFile::ReadOnly | QFile::Text ))//| QFile:: Unbuffered if (mpcElementsFile.open(QFile::ReadOnly | QFile::Text ))//| QFile:: Unbuffered
{ {
int candidatesCount = 0; int candidatesCount = 0;
int lineCount = 0; int lineCount = 0;
while(!mpcElementsFile.atEnd()) while(!mpcElementsFile.atEnd())
skipping to change at line 1082 skipping to change at line 1082
} }
mpcElementsFile.close(); mpcElementsFile.close();
qDebug() << "Done reading minor planet orbital elements." qDebug() << "Done reading minor planet orbital elements."
<< "Recognized" << candidatesCount << "candidate ob jects" << "Recognized" << candidatesCount << "candidate ob jects"
<< "out of" << lineCount << "lines."; << "out of" << lineCount << "lines.";
return objectList; return objectList;
} }
else else
{ {
qDebug() << "Unable to open for reading" << filePath; qDebug() << "Unable to open for reading" << QDir::toNativeSe parators(filePath);
qDebug() << "File error:" << mpcElementsFile.errorString(); qDebug() << "File error:" << mpcElementsFile.errorString();
return objectList; return objectList;
} }
return objectList; return objectList;
} }
QList<SsoElements> SolarSystemEditor::readXEphemOneLineElementsFromFile(QSt ring filePath) QList<SsoElements> SolarSystemEditor::readXEphemOneLineElementsFromFile(QSt ring filePath)
{ {
QList<SsoElements> objectList; QList<SsoElements> objectList;
if (!QFile::exists(filePath)) if (!QFile::exists(filePath))
{ {
qDebug() << "Can't find" << filePath; qDebug() << "Can't find" << QDir::toNativeSeparators(filePat h);
return objectList; return objectList;
} }
QFile xEphemElementsFile(filePath); QFile xEphemElementsFile(filePath);
if (xEphemElementsFile.open(QFile::ReadOnly | QFile::Text )) if (xEphemElementsFile.open(QFile::ReadOnly | QFile::Text ))
{ {
int candidatesCount = 0; int candidatesCount = 0;
int lineCount = 0; int lineCount = 0;
while(!xEphemElementsFile.atEnd()) while(!xEphemElementsFile.atEnd())
skipping to change at line 1141 skipping to change at line 1141
} }
xEphemElementsFile.close(); xEphemElementsFile.close();
qDebug() << "Done reading minor planet orbital elements." qDebug() << "Done reading minor planet orbital elements."
<< "Recognized" << candidatesCount << "cand idate objects" << "Recognized" << candidatesCount << "cand idate objects"
<< "out of" << lineCount << "lines."; << "out of" << lineCount << "lines.";
return objectList; return objectList;
} }
else else
{ {
qDebug() << "Unable to open for reading" << filePath; qDebug() << "Unable to open for reading" << QDir::toNativeSe parators(filePath);
qDebug() << "File error:" << xEphemElementsFile.errorString( ); qDebug() << "File error:" << xEphemElementsFile.errorString( );
return objectList; return objectList;
} }
return objectList; return objectList;
} }
bool SolarSystemEditor::appendToSolarSystemConfigurationFile(QList<SsoEleme nts> objectList) bool SolarSystemEditor::appendToSolarSystemConfigurationFile(QList<SsoEleme nts> objectList)
{ {
if (objectList.isEmpty()) if (objectList.isEmpty())
{ {
return false; return false;
} }
//Check if the configuration file exists //Check if the configuration file exists
if (!QFile::exists(customSolarSystemFilePath)) if (!QFile::exists(customSolarSystemFilePath))
{ {
qDebug() << "Can't append object data to ssystem.ini: Unable to find" << customSolarSystemFilePath; qDebug() << "Can't append object data to ssystem.ini: Unable to find" << QDir::toNativeSeparators(customSolarSystemFilePath);
return false; return false;
} }
QHash<QString,QString> loadedObjects = listAllLoadedSsoIdentifiers() ; QHash<QString,QString> loadedObjects = listAllLoadedSsoIdentifiers() ;
//Remove duplicates (identified by name, not by section name) //Remove duplicates (identified by name, not by section name)
QSettings * solarSystemSettings = new QSettings(customSolarSystemFil ePath, QSettings::IniFormat); QSettings * solarSystemSettings = new QSettings(customSolarSystemFil ePath, QSettings::IniFormat);
if (solarSystemSettings->status() != QSettings::NoError) if (solarSystemSettings->status() != QSettings::NoError)
{ {
qDebug() << "Error opening ssystem.ini:" << customSolarSyste mFilePath; qDebug() << "Error opening ssystem.ini:" << QDir::toNativeSe parators(customSolarSystemFilePath);
return false; return false;
} }
foreach (SsoElements object, objectList) foreach (SsoElements object, objectList)
{ {
QString name = object.value("name").toString(); QString name = object.value("name").toString();
if (name.isEmpty()) if (name.isEmpty())
continue; continue;
QString group = object.value("section_name").toString(); QString group = object.value("section_name").toString();
if (group.isEmpty()) if (group.isEmpty())
skipping to change at line 1235 skipping to change at line 1235
output.flush(); output.flush();
qDebug() << "Appended successfully" << sectionName; qDebug() << "Appended successfully" << sectionName;
appendedAtLeastOne = true; appendedAtLeastOne = true;
} }
solarSystemConfigurationFile.close(); solarSystemConfigurationFile.close();
return appendedAtLeastOne; return appendedAtLeastOne;
} }
else else
{ {
qDebug() << "Unable to open for writing" << customSolarSyste mFilePath; qDebug() << "Unable to open for writing" << QDir::toNativeSe parators(customSolarSystemFilePath);
return false; return false;
} }
} }
bool SolarSystemEditor::appendToSolarSystemConfigurationFile(SsoElements ob ject) bool SolarSystemEditor::appendToSolarSystemConfigurationFile(SsoElements ob ject)
{ {
if (!object.contains("section_name") || object.value("section_name") .toString().isEmpty()) if (!object.contains("section_name") || object.value("section_name") .toString().isEmpty())
{ {
qDebug() << "appendToSolarSystemConfigurationFile(): Invalid object:" << object; qDebug() << "appendToSolarSystemConfigurationFile(): Invalid object:" << object;
return false; return false;
skipping to change at line 1265 skipping to change at line 1265
if (objectList.isEmpty()) if (objectList.isEmpty())
{ {
//Empty lists can be added without any problem. :) //Empty lists can be added without any problem. :)
qWarning() << "updateSolarSystemConfigurationFile(): The sou rce list is empty."; qWarning() << "updateSolarSystemConfigurationFile(): The sou rce list is empty.";
return true; return true;
} }
//Check if the configuration file exists //Check if the configuration file exists
if (!QFile::exists(customSolarSystemFilePath)) if (!QFile::exists(customSolarSystemFilePath))
{ {
qDebug() << "Can't update ssystem.ini: Unable to find" << cu stomSolarSystemFilePath; qDebug() << "Can't update ssystem.ini: Unable to find" << QD ir::toNativeSeparators(customSolarSystemFilePath);
return false; return false;
} }
QSettings solarSystem(customSolarSystemFilePath, QSettings::IniForma t); QSettings solarSystem(customSolarSystemFilePath, QSettings::IniForma t);
if (solarSystem.status() != QSettings::NoError) if (solarSystem.status() != QSettings::NoError)
{ {
qDebug() << "Error opening ssystem.ini:" << customSolarSyste mFilePath; qDebug() << "Error opening ssystem.ini:" << QDir::toNativeSe parators(customSolarSystemFilePath);
return false; return false;
} }
QStringList existingSections = solarSystem.childGroups(); QStringList existingSections = solarSystem.childGroups();
QHash<QString,QString> loadedObjects = listAllLoadedSsoIdentifiers() ; QHash<QString,QString> loadedObjects = listAllLoadedSsoIdentifiers() ;
//TODO: Move to contstructor? //TODO: Move to contstructor?
QStringList orbitalElementsKeys; QStringList orbitalElementsKeys;
orbitalElementsKeys << "coord_func" orbitalElementsKeys << "coord_func"
<< "orbit_ArgOfPericenter" << "orbit_ArgOfPericenter"
<< "orbit_AscendingNode" << "orbit_AscendingNode"
<< "orbit_Eccentricity" << "orbit_Eccentricity"
 End of changes. 19 change blocks. 
19 lines changed or deleted 19 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/