diff --git a/kstars/auxiliary/ksutils.cpp b/kstars/auxiliary/ksutils.cpp index f4ee322e4b5ed7b2a5cf898d44b5b80a34a218b6..288c1a3d76b9ae944f37d8935972aaf59cfdb559 100644 --- a/kstars/auxiliary/ksutils.cpp +++ b/kstars/auxiliary/ksutils.cpp @@ -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) diff --git a/kstars/ekos/align/align.cpp b/kstars/ekos/align/align.cpp index e506bd22f81f511c2b84362ee45cd84312ff5482..3aa895c99fd1a0da69f2b310be1bca783aad3a31 100644 --- a/kstars/ekos/align/align.cpp +++ b/kstars/ekos/align/align.cpp @@ -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(); diff --git a/kstars/ekos/align/opsastrometryindexfiles.cpp b/kstars/ekos/align/opsastrometryindexfiles.cpp index 40ab6caef4d2690debb451428802037cb678a9a0..da1dc776590f31fdec28c6fb6c765bc0a5eec170 100644 --- a/kstars/ekos/align/opsastrometryindexfiles.cpp +++ b/kstars/ekos/align/opsastrometryindexfiles.cpp @@ -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(); }