diff --git a/kstars/auxiliary/ksutils.h b/kstars/auxiliary/ksutils.h --- a/kstars/auxiliary/ksutils.h +++ b/kstars/auxiliary/ksutils.h @@ -250,7 +250,9 @@ #ifdef Q_OS_OSX void copyResourcesFolderFromAppBundle(QString folder); bool copyDataFolderFromAppBundleIfNeeded(); //The boolean returns true if the data folders are good to go. -void configureDefaultAstrometry(); +bool getAstrometryDataDir(QString &dataDir); +bool setAstrometryDataDir(QString dataDir); +bool configureAstrometry(); bool copyRecursively(QString sourceFolder, QString destFolder); #endif diff --git a/kstars/auxiliary/ksutils.cpp b/kstars/auxiliary/ksutils.cpp --- a/kstars/auxiliary/ksutils.cpp +++ b/kstars/auxiliary/ksutils.cpp @@ -1097,6 +1097,16 @@ else return snap + "/etc/astrometry.cfg"; } + else if (option == "AstrometryIndexFileLocation") + { +#ifdef Q_OS_OSX + return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Astrometry/"; +#endif + if (flat.isEmpty() == false) + return flat + "/usr/share/astrometry/"; + else + return snap + "/usr/share/astrometry/"; + } else if (option == "XplanetPath") { #ifdef Q_OS_OSX @@ -1172,67 +1182,151 @@ return true; //This means the data directory was good to go from the start and the wizard did not run. } -void configureDefaultAstrometry() +bool getAstrometryDataDir(QString &dataDir) { - QDir writableDir; - QString astrometryPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Astrometry/"; - if (!astrometryPath.isEmpty()) + QString confPath; + + if (Options::astrometryConfFileIsInternal()) + confPath = QCoreApplication::applicationDirPath() + "/astrometry/bin/astrometry.cfg"; + else + confPath = Options::astrometryConfFile(); + + QFile confFile(confPath); + + if (confFile.open(QIODevice::ReadOnly) == false) { - writableDir.mkdir(astrometryPath); - astrometryPath = - QStandardPaths::locate(QStandardPaths::GenericDataLocation, "Astrometry", QStandardPaths::LocateDirectory); - if (astrometryPath.isEmpty()) - KMessageBox::sorry( - 0, i18n("The Astrometry Index File Directory does not exist and was not able to be created.")); - else + KMessageBox::error(nullptr, i18n("Astrometry configuration file corrupted or missing: %1\nPlease set the " + "configuration file full path in INDI options.", + Options::astrometryConfFile())); + return false; + } + + QTextStream in(&confFile); + QString line; + while (!in.atEnd()) + { + line = in.readLine(); + if (line.isEmpty() || line.startsWith('#')) + continue; + + line = line.trimmed(); + if (line.startsWith(QLatin1String("add_path"))) { - QString confPath = QCoreApplication::applicationDirPath() + "/astrometry/bin/astrometry.cfg"; - QFile confFile(confPath); - QString contents; - if (confFile.open(QIODevice::ReadOnly) == false) - KMessageBox::error(0, i18n("Internal Astrometry Configuration File Read Error.")); - else + dataDir = line.trimmed().mid(9).trimmed(); + return true; + } + } + + KMessageBox::error(nullptr, i18n("Unable to find data dir in astrometry configuration file.")); + return false; +} + +bool setAstrometryDataDir(QString dataDir) +{ + if(Options::astrometryIndexFileLocation()!=dataDir) + Options::setAstrometryIndexFileLocation(dataDir); + QString confPath; + if (Options::astrometryConfFileIsInternal()) + confPath = QCoreApplication::applicationDirPath() + "/astrometry/bin/astrometry.cfg"; + else + confPath = Options::astrometryConfFile(); + + QFile confFile(confPath); + QString contents; + if (confFile.open(QIODevice::ReadOnly) == false) + { + KMessageBox::error(0, i18n("Astrometry Configuration File Read Error.")); + return false; + } + else + { + QTextStream in(&confFile); + QString line; + bool foundPathBefore = false; + bool fileNeedsUpdating = false; + while (!in.atEnd()) + { + line = in.readLine(); + if (line.trimmed().startsWith(QLatin1String("add_path"))) { - QTextStream in(&confFile); - QString line; - bool foundPathBefore = false; - bool fileNeedsUpdating = false; - while (!in.atEnd()) + if (!foundPathBefore) //This will ensure there is not more than one add_path line in the file. { - line = in.readLine(); - if (line.trimmed().startsWith(QLatin1String("add_path"))) + foundPathBefore = true; + QString dataDirInFile = line.trimmed().mid(9).trimmed(); + if (dataDirInFile != dataDir) //Update to the correct path. { - if (!foundPathBefore) //This will ensure there is not more than one add_path line in the file. - { - foundPathBefore = true; - QString dataDir = line.trimmed().mid(9).trimmed(); - if (dataDir != astrometryPath) //Update to the correct path. - { - contents += "add_path " + astrometryPath + '\n'; - fileNeedsUpdating = true; - } - } - } - else - { - contents += line + '\n'; + contents += "add_path " + dataDir + '\n'; + fileNeedsUpdating = true; } } + } + else + { + contents += line + '\n'; + } + } + confFile.close(); + if (fileNeedsUpdating) + { + if (confFile.open(QIODevice::WriteOnly) == false) + { + KMessageBox::error(0, i18n("Internal Astrometry Configuration File Write Error.")); + return false; + } + else + { + QTextStream out(&confFile); + out << contents; confFile.close(); - if (fileNeedsUpdating) - { - if (confFile.open(QIODevice::WriteOnly) == false) - KMessageBox::error(0, i18n("Internal Astrometry Configuration File Write Error.")); - else - { - QTextStream out(&confFile); - out << contents; - confFile.close(); - } - } } } } + return true; +} + +bool configureAstrometry() +{ + QString astrometryDataDir; + if (KSUtils::getAstrometryDataDir(astrometryDataDir) == false) + return false; + if(Options::astrometryIndexFileLocation()!=astrometryDataDir) + { + if (KMessageBox::warningYesNo( + nullptr, i18n("The Astrometry Index File Location Stored in KStars: \n %1 \n does not match the Index file location in the config file: \n %2 \n Do you want to update the config file?", Options::astrometryIndexFileLocation(), astrometryDataDir), + i18n("Update Config File?")) == KMessageBox::Yes) + { + astrometryDataDir=Options::astrometryIndexFileLocation(); + setAstrometryDataDir(astrometryDataDir); + } + else + { + return false; + } + } + if (QDir(astrometryDataDir).exists() == false) + { + if (KMessageBox::warningYesNo( + nullptr, i18n("The selected Astrometry Index File Location:\n %1 \n does not exist. Do you want to make the directory?", astrometryDataDir), + i18n("Make Astrometry Index File Directory?")) == KMessageBox::Yes) + { + if(QDir(astrometryDataDir).mkdir(astrometryDataDir)) + { + KMessageBox::information(nullptr, i18n("The Astrometry Index File Location was created.")); + } + else + { + KMessageBox::sorry(nullptr, i18n("The Astrometry Index File Directory does not exist and was not able to be created.")); + } + } + else + { + + return false; + } + } + + //If the Index File Directories match and the directory exists, we are good to go. + return true; } bool copyRecursively(QString sourceFolder, QString destFolder) diff --git a/kstars/ekos/align/offlineastrometryparser.cpp b/kstars/ekos/align/offlineastrometryparser.cpp --- a/kstars/ekos/align/offlineastrometryparser.cpp +++ b/kstars/ekos/align/offlineastrometryparser.cpp @@ -51,7 +51,17 @@ { #ifdef Q_OS_OSX if (Options::astrometryConfFileIsInternal()) - KSUtils::configureDefaultAstrometry(); + { + if(KSUtils::configureAstrometry()==false) + { + KMessageBox::information( + nullptr, + i18n( + "Failed to properly configure astrometry config file. Please click the options button in the lower right of the Astrometry Tab in Ekos to correct your settings. Then try starting Ekos again."), + i18n("Astrometry Config File Error"), "astrometry_configuration_failure_warning"); + return false; + } + } #endif if (astrometryFilesOK) @@ -63,7 +73,7 @@ KMessageBox::information( nullptr, i18n( - "Failed to find astrometry.net binaries. Please ensure astrometry.net is installed and try again."), + "Failed to find astrometry.net binaries. Please click the options button in the lower right of the Astrometry Tab in Ekos to correct your settings and make sure that astrometry.net is installed. Then try starting Ekos again."), i18n("Missing astrometry files"), "missing_astrometry_binaries_warning"); return false; @@ -157,7 +167,7 @@ QString astrometryDataDir; bool indexesOK = true; - if (getAstrometryDataDir(astrometryDataDir) == false) + if (KSUtils::getAstrometryDataDir(astrometryDataDir) == false) return; QStringList nameFilter("*.fits"); diff --git a/kstars/ekos/align/opsastrometrycfg.h b/kstars/ekos/align/opsastrometrycfg.h --- a/kstars/ekos/align/opsastrometrycfg.h +++ b/kstars/ekos/align/opsastrometrycfg.h @@ -21,6 +21,7 @@ private slots: void slotLoadCFG(); + void slotSetAstrometryIndexFileLocation(); void slotApply(); void slotCFGEditorUpdated(); diff --git a/kstars/ekos/align/opsastrometrycfg.cpp b/kstars/ekos/align/opsastrometrycfg.cpp --- a/kstars/ekos/align/opsastrometrycfg.cpp +++ b/kstars/ekos/align/opsastrometrycfg.cpp @@ -3,6 +3,7 @@ #include "align.h" #include "kstars.h" +#include "ksutils.h" #include "Options.h" #include "ui_opsastrometrycfg.h" @@ -25,6 +26,7 @@ connect(astrometryCFGDisplay, SIGNAL(textChanged()), SLOT(slotCFGEditorUpdated())); connect(loadCFG, SIGNAL(clicked()), this, SLOT(slotLoadCFG())); + connect(setIndexFileB, SIGNAL(clicked()), this, SLOT(slotSetAstrometryIndexFileLocation())); slotLoadCFG(); } @@ -59,6 +61,12 @@ confFile.close(); } +void OpsAstrometryCfg::slotSetAstrometryIndexFileLocation() +{ + KSUtils::setAstrometryDataDir(kcfg_AstrometryIndexFileLocation->text()); + slotLoadCFG(); +} + void OpsAstrometryCfg::slotApply() { if (currentCFGText != astrometryCFGDisplay->toPlainText()) @@ -80,6 +88,10 @@ confFile.close(); KMessageBox::information(0, i18n("Astrometry.cfg successfully saved.")); currentCFGText = astrometryCFGDisplay->toPlainText(); + QString astrometryDataDir; + KSUtils::getAstrometryDataDir(astrometryDataDir); + if(astrometryDataDir!=kcfg_AstrometryIndexFileLocation->text()) + kcfg_AstrometryIndexFileLocation->setText(astrometryDataDir); } } } diff --git a/kstars/ekos/align/opsastrometrycfg.ui b/kstars/ekos/align/opsastrometrycfg.ui --- a/kstars/ekos/align/opsastrometrycfg.ui +++ b/kstars/ekos/align/opsastrometrycfg.ui @@ -51,6 +51,43 @@ + + + + + + <html><head/><body><p>This is the absolute location of the Astrometry.cfg file on the filesystem.</p></body></html> + + + Index File Location: + + + + + + + true + + + false + + + <html><head/><body><p>This is the absolute location of the Astrometry.cfg file on the filesystem.</p></body></html> + + + + + + + <html><head/><body><p>This button will let you reload the Astrometry.cfg file in the event that something was changed outside of KStars.</p></body></html> + + + Set + + + + + diff --git a/kstars/kstars.cpp b/kstars/kstars.cpp --- a/kstars/kstars.cpp +++ b/kstars/kstars.cpp @@ -108,6 +108,14 @@ QString path = env.value("PATH", ""); env.insert("PATH", "/usr/bin:/usr/local/bin:\"" + QCoreApplication::applicationDirPath() + "\":" + path); + //This Environment variable is needed sometimes in Craft built Mac KStars when running in Craft because it cannot find the qml directory inside craft. + //This should not cause any issues for any other installation since the original path is preserved. + QString qtDIR = env.value("QTDIR", ""); + QString currentQMLPath = env.value("QML2_IMPORT_PATH", ""); + QString newQMLPath = qtDIR + "/qml:" + qtDIR + "/lib/qml:" + currentQMLPath; + qputenv("QML2_IMPORT_PATH", newQMLPath.toLatin1()); + env.insert("QML2_IMPORT_PATH", newQMLPath); + QProcess dbusCheck; dbusCheck.setProcessEnvironment(env); diff --git a/kstars/kstars.kcfg b/kstars/kstars.kcfg --- a/kstars/kstars.kcfg +++ b/kstars/kstars.kcfg @@ -1901,6 +1901,11 @@ Path to astrometry.net file location. KSUtils::getDefaultPath("AstrometryConfFile") + + + Astrometry.net Index files Location. + KSUtils::getDefaultPath("AstrometryIndexFileLocation") + false