Commit e39ae400 authored by Robert Lancaster's avatar Robert Lancaster

Updating the Astrometry Config File and Index File Directory options so

that they don't create duplicate entries, they remove nonexistant
directories, and make sure they display the actual paths.
parent 5d7ff49e
...@@ -1468,49 +1468,81 @@ QString getAstrometryConfFilePath() ...@@ -1468,49 +1468,81 @@ QString getAstrometryConfFilePath()
QStringList getAstrometryDataDirs() QStringList getAstrometryDataDirs()
{ {
QStringList dataDirs; QStringList optionsDataDirs = Options::astrometryIndexFolderList();
QString confPath = KSUtils::getAstrometryConfFilePath();
QFile confFile(confPath); bool updated = false;
if (confFile.open(QIODevice::ReadOnly) == false) // Cleaning up the list of directories in options.
for(int dir = 0; dir < optionsDataDirs.count(); dir++)
{ {
bool confFileExists = false; QString optionsDataDirName = optionsDataDirs.at(dir);
if(Options::astrometryConfFileIsInternal()) QDir optionsDataDir(optionsDataDirName);
if(optionsDataDir.exists())
{ {
if(KSUtils::configureLocalAstrometryConfIfNecessary()) //This will replace directory names that aren't the absolute path
if(optionsDataDir.absolutePath() != optionsDataDirName)
{ {
if (confFile.open(QIODevice::ReadOnly)) optionsDataDirs.replace(dir, optionsDataDir.absolutePath());
confFileExists = true; updated = true;
} }
} }
if(!confFileExists) else
{ {
KSNotification::error(i18n("Astrometry configuration file corrupted or missing: %1\nPlease set the " //This removes directories that do not exist.
"configuration file full path in INDI options.", optionsDataDir.remove(optionsDataDirs.at(dir));
confPath)); dir--;
return dataDirs; updated = true;
} }
} }
QTextStream in(&confFile); //This will load the conf file if it exists
QString line; QFile confFile(KSUtils::getAstrometryConfFilePath());
while (!in.atEnd()) if (confFile.open(QIODevice::ReadOnly))
{ {
line = in.readLine(); QStringList confDataDirs;
if (line.isEmpty() || line.startsWith('#')) QTextStream in(&confFile);
continue; QString line;
//This will find the index file paths in the conf file
while (!in.atEnd())
{
line = in.readLine();
if (line.isEmpty() || line.startsWith('#'))
continue;
line = line.trimmed();
if (line.startsWith(QLatin1String("add_path")))
{
confDataDirs << line.mid(9).trimmed();
}
}
line = line.trimmed(); //This will search through the paths and compare them to the index folder list
if (line.startsWith(QLatin1String("add_path"))) //It will add them if they aren't in there.
for(QString astrometryDataDirName : confDataDirs)
{ {
dataDirs << line.mid(9).trimmed(); QDir astrometryDataDir(astrometryDataDirName);
//This rejects any that do not exist
if(!astrometryDataDir.exists())
continue;
QString astrometryDataDirPath = astrometryDataDir.absolutePath();
if( !optionsDataDirs.contains(astrometryDataDirPath ))
{
optionsDataDirs.append(astrometryDataDirPath);
updated = true;
}
} }
} }
// if(dataDirs.size()==0)
// KSNotification::error(i18n("Unable to find data dir in astrometry configuration file."));
return dataDirs; //This will remove any duplicate entries.
if(optionsDataDirs.removeDuplicates() != 0)
updated = true;
//This updates the list in Options if it changed.
if(updated)
Options::setAstrometryIndexFolderList(optionsDataDirs);
return optionsDataDirs;
} }
bool addAstrometryDataDir(QString dataDir) bool addAstrometryDataDir(QString dataDir)
......
...@@ -3194,28 +3194,9 @@ void Align::setSolverAction(int mode) ...@@ -3194,28 +3194,9 @@ void Align::setSolverAction(int mode)
void Align::startSolving() void Align::startSolving()
{ {
// if (m_StellarSolver && m_StellarSolver->isRunning()) // This is needed because they might have directories stored in the config file.
// { // So we can't just use the options folder list.
// if (Options::alignmentLogging())
// appendLogText(i18n("Solver is in progress, please stand by..."));
// return;
// }
//This is needed because they might have directories stored in the config file.
QStringList indexFileDirs = Options::astrometryIndexFolderList();
QStringList astrometryDataDirs = KSUtils::getAstrometryDataDirs(); QStringList astrometryDataDirs = KSUtils::getAstrometryDataDirs();
bool updated = false;
for(auto &dataDir : astrometryDataDirs)
{
if(!indexFileDirs.contains(dataDir))
{
indexFileDirs.append(dataDir);
updated = true;
}
}
if(updated)
Options::setAstrometryIndexFolderList(indexFileDirs);
///
disconnect(alignView, &FITSView::loaded, this, &Align::startSolving); disconnect(alignView, &FITSView::loaded, this, &Align::startSolving);
FITSData *data = alignView->getImageData(); FITSData *data = alignView->getImageData();
......
...@@ -113,34 +113,28 @@ void OpsAstrometryIndexFiles::showEvent(QShowEvent *) ...@@ -113,34 +113,28 @@ void OpsAstrometryIndexFiles::showEvent(QShowEvent *)
void OpsAstrometryIndexFiles::updateIndexDirectoryList() void OpsAstrometryIndexFiles::updateIndexDirectoryList()
{ {
QStringList indexFileDirs = Options::astrometryIndexFolderList(); // This is needed because they might have directories stored in the config file.
// So we can't just use the options folder list.
QStringList astrometryDataDirs = KSUtils::getAstrometryDataDirs(); QStringList astrometryDataDirs = KSUtils::getAstrometryDataDirs();
bool updated = false;
foreach(QString dataDir, astrometryDataDirs)
{
if(!indexFileDirs.contains(dataDir))
{
indexFileDirs.append(dataDir);
updated = true;
}
}
if (indexFileDirs.count() == 0)
return;
if(updated)
Options::setAstrometryIndexFolderList(indexFileDirs);
indexLocations->clear(); indexLocations->clear();
if(indexFileDirs.count() > 1) if(astrometryDataDirs.count() > 1)
indexLocations->addItem("All Sources"); indexLocations->addItem("All Sources");
indexLocations->addItems(indexFileDirs); indexLocations->addItems(astrometryDataDirs);
slotUpdate(); slotUpdate();
} }
void OpsAstrometryIndexFiles::addDirectoryToList(QString directory) void OpsAstrometryIndexFiles::addDirectoryToList(QString directory)
{ {
QDir dir(directory);
if(!dir.exists())
return;
QString directoryPath = dir.absolutePath();
QStringList indexFileDirs = Options::astrometryIndexFolderList(); QStringList indexFileDirs = Options::astrometryIndexFolderList();
if(indexFileDirs.contains(directory)) if(indexFileDirs.contains(directoryPath))
return; return;
indexFileDirs.append(directory); indexFileDirs.append(directoryPath);
Options::setAstrometryIndexFolderList(indexFileDirs); Options::setAstrometryIndexFolderList(indexFileDirs);
updateIndexDirectoryList(); updateIndexDirectoryList();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment