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()
QStringList getAstrometryDataDirs()
{
QStringList dataDirs;
QString confPath = KSUtils::getAstrometryConfFilePath();
QStringList optionsDataDirs = Options::astrometryIndexFolderList();
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;
if(Options::astrometryConfFileIsInternal())
QString optionsDataDirName = optionsDataDirs.at(dir);
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))
confFileExists = true;
optionsDataDirs.replace(dir, optionsDataDir.absolutePath());
updated = true;
}
}
if(!confFileExists)
else
{
KSNotification::error(i18n("Astrometry configuration file corrupted or missing: %1\nPlease set the "
"configuration file full path in INDI options.",
confPath));
return dataDirs;
//This removes directories that do not exist.
optionsDataDir.remove(optionsDataDirs.at(dir));
dir--;
updated = true;
}
}
QTextStream in(&confFile);
QString line;
while (!in.atEnd())
//This will load the conf file if it exists
QFile confFile(KSUtils::getAstrometryConfFilePath());
if (confFile.open(QIODevice::ReadOnly))
{
line = in.readLine();
if (line.isEmpty() || line.startsWith('#'))
continue;
QStringList confDataDirs;
QTextStream in(&confFile);
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();
if (line.startsWith(QLatin1String("add_path")))
//This will search through the paths and compare them to the index folder list
//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)
......
......@@ -3194,28 +3194,9 @@ void Align::setSolverAction(int mode)
void Align::startSolving()
{
// if (m_StellarSolver && m_StellarSolver->isRunning())
// {
// 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();
// 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();
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);
FITSData *data = alignView->getImageData();
......
......@@ -113,34 +113,28 @@ void OpsAstrometryIndexFiles::showEvent(QShowEvent *)
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();
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();
if(indexFileDirs.count() > 1)
if(astrometryDataDirs.count() > 1)
indexLocations->addItem("All Sources");
indexLocations->addItems(indexFileDirs);
indexLocations->addItems(astrometryDataDirs);
slotUpdate();
}
void OpsAstrometryIndexFiles::addDirectoryToList(QString directory)
{
QDir dir(directory);
if(!dir.exists())
return;
QString directoryPath = dir.absolutePath();
QStringList indexFileDirs = Options::astrometryIndexFolderList();
if(indexFileDirs.contains(directory))
if(indexFileDirs.contains(directoryPath))
return;
indexFileDirs.append(directory);
indexFileDirs.append(directoryPath);
Options::setAstrometryIndexFolderList(indexFileDirs);
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