1 /*
2     SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
3     SPDX-FileCopyrightText: 2017 Robert Lancaster <rlancaste@gmail.com>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "opsprograms.h"
9 
10 #include "align.h"
11 #include "fov.h"
12 #include "kstars.h"
13 #include "ksnotification.h"
14 #include "Options.h"
15 
16 #include <stellarsolver.h>
17 #include <KConfigDialog>
18 #include <QProcess>
19 
20 namespace Ekos
21 {
OpsPrograms(Align * parent)22 OpsPrograms::OpsPrograms(Align *parent) : QWidget(KStars::Instance())
23 {
24     setupUi(this);
25 
26     alignModule = parent;
27 
28     connect(defaultPathSelector, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
29             &OpsPrograms::loadDefaultPaths);
30 
31     //Get a pointer to the KConfigDialog
32     m_ConfigDialog = KConfigDialog::exists("alignsettings");
33 
34     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
35     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
36 
37     connect(kcfg_AstrometryConfFileIsInternal, SIGNAL(clicked()), this, SLOT(toggleConfigInternal()));
38     kcfg_AstrometryConfFileIsInternal->setToolTip(i18n("Internal or External astrometry.cfg?"));
39     if (Options::astrometryConfFileIsInternal())
40         kcfg_AstrometryConfFile->setEnabled(false);
41 
42 #ifdef Q_OS_OSX
43     connect(kcfg_AstrometrySolverIsInternal, SIGNAL(clicked()), this, SLOT(toggleSolverInternal()));
44     kcfg_AstrometrySolverIsInternal->setToolTip(i18n("Internal or External Plate Solver?"));
45     if (Options::astrometrySolverIsInternal())
46         kcfg_AstrometrySolverBinary->setEnabled(false);
47 
48     connect(kcfg_AstrometryWCSIsInternal, SIGNAL(clicked()), this, SLOT(toggleWCSInternal()));
49     kcfg_AstrometryWCSIsInternal->setToolTip(i18n("Internal or External wcsinfo?"));
50     if (Options::astrometryWCSIsInternal())
51         kcfg_AstrometryWCSInfo->setEnabled(false);
52 
53     connect(kcfg_SextractorIsInternal, SIGNAL(clicked()), this, SLOT(toggleSextractorInternal()));
54     kcfg_SextractorIsInternal->setToolTip(i18n("Internal or External sextractor?"));
55     if (Options::sextractorIsInternal())
56         kcfg_SextractorBinary->setEnabled(false);
57 
58 #else
59     kcfg_AstrometrySolverIsInternal->setVisible(false);
60     kcfg_AstrometryWCSIsInternal->setVisible(false);
61     kcfg_SextractorIsInternal->setVisible(false);
62 #endif
63 
64 }
65 
toggleSolverInternal()66 void OpsPrograms::toggleSolverInternal()
67 {
68     kcfg_AstrometrySolverBinary->setEnabled(!kcfg_AstrometrySolverIsInternal->isChecked());
69     if (kcfg_AstrometrySolverIsInternal->isChecked())
70         kcfg_AstrometrySolverBinary->setText("*Internal Solver*");
71     else
72         kcfg_AstrometrySolverBinary->setText(KSUtils::getDefaultPath("AstrometrySolverBinary"));
73 }
74 
toggleConfigInternal()75 void OpsPrograms::toggleConfigInternal()
76 {
77     kcfg_AstrometryConfFile->setEnabled(!kcfg_AstrometryConfFileIsInternal->isChecked());
78     if (kcfg_AstrometryConfFileIsInternal->isChecked())
79         kcfg_AstrometryConfFile->setText("*Internal astrometry.cfg*");
80     else
81         kcfg_AstrometryConfFile->setText(KSUtils::getDefaultPath("AstrometryConfFile"));
82 }
83 
toggleWCSInternal()84 void OpsPrograms::toggleWCSInternal()
85 {
86     kcfg_AstrometryWCSInfo->setEnabled(!kcfg_AstrometryWCSIsInternal->isChecked());
87     if (kcfg_AstrometryWCSIsInternal->isChecked())
88         kcfg_AstrometryWCSInfo->setText("*Internal wcsinfo*");
89     else
90         kcfg_AstrometryWCSInfo->setText(KSUtils::getDefaultPath("AstrometryWCSInfo"));
91 }
92 
toggleSextractorInternal()93 void OpsPrograms::toggleSextractorInternal()
94 {
95     kcfg_SextractorBinary->setEnabled(!kcfg_SextractorIsInternal->isChecked());
96     if (kcfg_SextractorIsInternal->isChecked())
97         kcfg_SextractorBinary->setText("*Internal Sextractor*");
98     else
99         kcfg_SextractorBinary->setText(KSUtils::getDefaultPath("SextractorBinary"));
100 }
101 
slotApply()102 void OpsPrograms::slotApply()
103 {
104     emit settingsUpdated();
105 }
106 
loadDefaultPaths(int option)107 void OpsPrograms::loadDefaultPaths(int option)
108 {
109     ExternalProgramPaths paths;
110 
111     switch(option)
112     {
113         case 0:
114             return;
115             break;
116         case 1:
117             paths = StellarSolver::getLinuxDefaultPaths();
118             break;
119         case 2:
120             paths = StellarSolver::getLinuxInternalPaths();
121             break;
122         case 3:
123             paths = StellarSolver::getMacHomebrewPaths();
124             break;
125         case 4:
126             paths = StellarSolver::getMacInternalPaths();
127             break;
128         case 5:
129             paths = StellarSolver::getWinANSVRPaths();
130             break;
131         case 6:
132             paths = StellarSolver::getWinCygwinPaths();
133             break;
134         default:
135             paths = StellarSolver::getLinuxDefaultPaths();
136             break;
137     }
138 
139     if( ! kcfg_SextractorIsInternal->isChecked())
140         kcfg_SextractorBinary->setText(paths.sextractorBinaryPath);
141     if( ! kcfg_AstrometryConfFileIsInternal->isChecked())
142         kcfg_AstrometryConfFile->setText(paths.confPath);
143     if( ! kcfg_AstrometrySolverIsInternal->isChecked())
144         kcfg_AstrometrySolverBinary->setText(paths.solverPath);
145     kcfg_ASTAPExecutable->setText(paths.astapBinaryPath);
146     if( ! kcfg_AstrometryWCSIsInternal->isChecked())
147         kcfg_AstrometryWCSInfo->setText(paths.wcsPath);
148 
149     defaultPathSelector->setCurrentIndex(0);
150 }
151 }
152