File indexing completed on 2024-03-24 15:18:16

0001 /*
0002     SPDX-FileCopyrightText: 2008 Jerome SONRIER <jsid@emor3j.fr.eu.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opsxplanet.h"
0008 
0009 #include "kstars.h"
0010 #include "kstarsdata.h"
0011 #include "Options.h"
0012 #include <QDesktopServices>
0013 #include <QFileDialog>
0014 
0015 OpsXplanet::OpsXplanet(KStars *_ks) : QFrame(_ks), ksw(_ks)
0016 {
0017     setupUi(this);
0018 
0019 #ifdef Q_OS_OSX
0020     connect(kcfg_xplanetIsInternal, SIGNAL(clicked()), this, SLOT(toggleXPlanetInternal()));
0021     kcfg_xplanetIsInternal->setToolTip(i18n("Internal or External XPlanet?"));
0022 
0023     if (Options::xplanetIsInternal())
0024         kcfg_XplanetPath->setEnabled(false);
0025 
0026 #else
0027     kcfg_xplanetIsInternal->setVisible(false);
0028 #endif
0029 
0030     // Init projections combobox
0031     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "No projection"), "no projection");
0032     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Ancient"), "ancient");
0033     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Azimuthal"), "azimuthal");
0034     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Bonne"), "bonne");
0035     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Gnomonic"), "gnomonic");
0036     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Hemisphere"), "hemisphere");
0037     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Lambert"), "lambert");
0038     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Mercator"), "mercator");
0039     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Mollweide"), "mollweide");
0040     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Orthographic"), "orthographic");
0041     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Peters"), "peters");
0042     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Polyconic"), "polyconic");
0043     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Rectangular"), "rectangular");
0044     kcfg_XplanetProjection->addItem(i18nc("Map projection method", "TSC"), "tsc");
0045 
0046     // Enable/Disable somme widgets
0047     connect(kcfg_XplanetConfigFile, SIGNAL(toggled(bool)), SLOT(slotConfigFileWidgets(bool)));
0048     connect(kcfg_XplanetStarmap, SIGNAL(toggled(bool)), SLOT(slotStarmapFileWidgets(bool)));
0049     connect(kcfg_XplanetArcFile, SIGNAL(toggled(bool)), SLOT(slotArcFileWidgets(bool)));
0050     connect(kcfg_XplanetLabel, SIGNAL(toggled(bool)), SLOT(slotLabelWidgets(bool)));
0051     connect(kcfg_XplanetMarkerFile, SIGNAL(toggled(bool)), SLOT(slotMarkerFileWidgets(bool)));
0052     connect(kcfg_XplanetMarkerBounds, SIGNAL(toggled(bool)), SLOT(slotMarkerBoundsWidgets(bool)));
0053     connect(kcfg_XplanetProjection, SIGNAL(currentIndexChanged(int)), SLOT(slotProjectionWidgets(int)));
0054     connect(kcfg_XplanetBackground, SIGNAL(toggled(bool)), SLOT(slotBackgroundWidgets(bool)));
0055 
0056     kcfg_XplanetConfigFilePath->setEnabled(Options::xplanetConfigFile());
0057     configFileB->setEnabled(Options::xplanetConfigFile());
0058     configFileB->setIcon(QIcon::fromTheme("document-open-folder"));
0059     configFileB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
0060     connect(configFileB, SIGNAL(clicked()), this, SLOT(slotSelectConfigFile()));
0061     kcfg_XplanetStarmapPath->setEnabled(Options::xplanetStarmap());
0062     starmapFileB->setEnabled(Options::xplanetStarmap());
0063     starmapFileB->setIcon(QIcon::fromTheme("document-open-folder"));
0064     starmapFileB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
0065     connect(starmapFileB, SIGNAL(clicked()), this, SLOT(slotSelectStarMapFile()));
0066     kcfg_XplanetArcFilePath->setEnabled(Options::xplanetArcFile());
0067     arcFileB->setEnabled(Options::xplanetArcFile());
0068     arcFileB->setIcon(QIcon::fromTheme("document-open-folder"));
0069     arcFileB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
0070     connect(arcFileB, SIGNAL(clicked()), this, SLOT(slotSelectArcFile()));
0071     kcfg_XplanetLabelLocalTime->setEnabled(Options::xplanetLabel());
0072     kcfg_XplanetLabelGMT->setEnabled(Options::xplanetLabel());
0073     textLabelXplanetLabelString->setEnabled(Options::xplanetLabel());
0074     kcfg_XplanetLabelString->setEnabled(Options::xplanetLabel());
0075     textLabelXplanetDateFormat->setEnabled(Options::xplanetLabel());
0076     kcfg_XplanetDateFormat->setEnabled(Options::xplanetLabel());
0077     textLabelXplanetFontSize->setEnabled(Options::xplanetLabel());
0078     kcfg_XplanetFontSize->setEnabled(Options::xplanetLabel());
0079     textLabelXplanetColor->setEnabled(Options::xplanetLabel());
0080     kcfg_XplanetColor->setEnabled(Options::xplanetLabel());
0081     textLabelLabelPos->setEnabled(Options::xplanetLabel());
0082     kcfg_XplanetLabelTL->setEnabled(Options::xplanetLabel());
0083     kcfg_XplanetLabelTR->setEnabled(Options::xplanetLabel());
0084     kcfg_XplanetLabelBR->setEnabled(Options::xplanetLabel());
0085     kcfg_XplanetLabelBL->setEnabled(Options::xplanetLabel());
0086     kcfg_XplanetMarkerFilePath->setEnabled(Options::xplanetMarkerFile());
0087     kcfg_XplanetMarkerBounds->setEnabled(Options::xplanetMarkerFile());
0088     if (Options::xplanetMarkerFile() && Options::xplanetMarkerBounds())
0089         kcfg_XplanetMarkerBoundsPath->setEnabled(true);
0090     else
0091         kcfg_XplanetMarkerBoundsPath->setEnabled(false);
0092     if (Options::xplanetProjection() == 0)
0093         groupBoxBackground->setEnabled(false);
0094     kcfg_XplanetBackgroundImage->setEnabled(Options::xplanetBackgroundImage());
0095     kcfg_XplanetBackgroundImagePath->setEnabled(Options::xplanetBackgroundImage());
0096     kcfg_XplanetBackgroundColor->setEnabled(Options::xplanetBackgroundImage());
0097     kcfg_XplanetBackgroundColorValue->setEnabled(Options::xplanetBackgroundImage());
0098     if (Options::xplanetProjection() == 0)
0099         groupBoxBackground->setEnabled(false);
0100 
0101     #ifdef Q_OS_WIN
0102         kcfg_XplanetUseFIFO->setChecked(false);
0103         kcfg_XplanetUseFIFO->setDisabled(true);
0104         kcfg_XplanetUseFIFO->setToolTip(i18n("FIFO files are not supported on Windows"));
0105     #endif
0106 
0107     connect(openXPlanetMaps, SIGNAL(clicked()),this,SLOT(showXPlanetMapsDirectory()));
0108 }
0109 
0110 void OpsXplanet::showXPlanetMapsDirectory()
0111 {
0112 
0113     QString xplanetMapsDir = XPlanetShareDirectory() + QDir::separator() + "images";
0114 
0115     QUrl path = QUrl::fromLocalFile(xplanetMapsDir);
0116     QDesktopServices::openUrl(path);
0117 }
0118 
0119 QString OpsXplanet::XPlanetShareDirectory()
0120 {
0121     #ifdef Q_OS_WIN
0122         const QFileInfo xPlanetLocationInfo(Options::xplanetPath());
0123         return xPlanetLocationInfo.dir().absolutePath() + QDir::separator() + "xplanet";
0124     #endif
0125 
0126     if (Options::xplanetIsInternal())
0127         return QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kstars", QStandardPaths::LocateDirectory) + QDir::separator() + "xplanet" + QDir::separator() + "images";
0128     else
0129         return Options::xplanetPath() + "../share/xplanet";
0130 }
0131 
0132 void OpsXplanet::toggleXPlanetInternal()
0133 {
0134     kcfg_XplanetPath->setEnabled(!kcfg_xplanetIsInternal->isChecked());
0135     if (kcfg_xplanetIsInternal->isChecked())
0136         kcfg_XplanetPath->setText("*Internal XPlanet*");
0137     else
0138         kcfg_XplanetPath->setText(KSUtils::getDefaultPath("XplanetPath"));
0139 }
0140 
0141 void OpsXplanet::slotConfigFileWidgets(bool on)
0142 {
0143     kcfg_XplanetConfigFilePath->setEnabled(on);
0144     configFileB->setEnabled(on);
0145 }
0146 
0147 void OpsXplanet::slotStarmapFileWidgets(bool on)
0148 {
0149     kcfg_XplanetStarmapPath->setEnabled(on);
0150     starmapFileB->setEnabled(on);
0151 }
0152 
0153 void OpsXplanet::slotArcFileWidgets(bool on)
0154 {
0155     kcfg_XplanetArcFilePath->setEnabled(on);
0156     arcFileB->setEnabled(on);
0157 }
0158 
0159 void OpsXplanet::slotLabelWidgets(bool on)
0160 {
0161     kcfg_XplanetLabelLocalTime->setEnabled(on);
0162     kcfg_XplanetLabelGMT->setEnabled(on);
0163     textLabelXplanetLabelString->setEnabled(on);
0164     kcfg_XplanetLabelString->setEnabled(on);
0165     textLabelXplanetDateFormat->setEnabled(on);
0166     kcfg_XplanetDateFormat->setEnabled(on);
0167     textLabelXplanetFontSize->setEnabled(on);
0168     kcfg_XplanetFontSize->setEnabled(on);
0169     textLabelXplanetColor->setEnabled(on);
0170     kcfg_XplanetColor->setEnabled(on);
0171     textLabelLabelPos->setEnabled(on);
0172     kcfg_XplanetLabelTL->setEnabled(on);
0173     kcfg_XplanetLabelTR->setEnabled(on);
0174     kcfg_XplanetLabelBR->setEnabled(on);
0175     kcfg_XplanetLabelBL->setEnabled(on);
0176 }
0177 
0178 void OpsXplanet::slotMarkerFileWidgets(bool on)
0179 {
0180     kcfg_XplanetMarkerFilePath->setEnabled(on);
0181     kcfg_XplanetMarkerBounds->setEnabled(on);
0182     if (kcfg_XplanetMarkerBounds->isChecked())
0183         kcfg_XplanetMarkerBoundsPath->setEnabled(on);
0184 }
0185 
0186 void OpsXplanet::slotMarkerBoundsWidgets(bool on)
0187 {
0188     kcfg_XplanetMarkerBoundsPath->setEnabled(on);
0189 }
0190 
0191 void OpsXplanet::slotProjectionWidgets(int index)
0192 {
0193     if (index == 0)
0194         groupBoxBackground->setEnabled(false);
0195     else
0196         groupBoxBackground->setEnabled(true);
0197 
0198     if (!kcfg_XplanetBackground->isChecked())
0199     {
0200         kcfg_XplanetBackgroundImage->setEnabled(false);
0201         kcfg_XplanetBackgroundImagePath->setEnabled(false);
0202         kcfg_XplanetBackgroundColor->setEnabled(false);
0203         kcfg_XplanetBackgroundColorValue->setEnabled(false);
0204     }
0205 }
0206 
0207 void OpsXplanet::slotBackgroundWidgets(bool on)
0208 {
0209     kcfg_XplanetBackgroundImage->setEnabled(on);
0210     kcfg_XplanetBackgroundImagePath->setEnabled(on);
0211     kcfg_XplanetBackgroundColor->setEnabled(on);
0212     kcfg_XplanetBackgroundColorValue->setEnabled(on);
0213 }
0214 
0215 void OpsXplanet::slotSelectConfigFile()
0216 {
0217     QString xplanetConfig = XPlanetShareDirectory() + QDir::separator() + "config";
0218     QString file =
0219         QFileDialog::getOpenFileName(KStars::Instance(), i18nc("@title:window", "Select XPlanet Config File"), xplanetConfig);
0220 
0221     if (!file.isEmpty())
0222         kcfg_XplanetConfigFilePath->setText(QFileInfo(file).completeBaseName());
0223 
0224 }
0225 
0226 void OpsXplanet::slotSelectStarMapFile()
0227 {
0228     QString xplanetStarMap = XPlanetShareDirectory() + QDir::separator() + "stars";
0229 
0230     QString file =
0231         QFileDialog::getOpenFileName(KStars::Instance(), i18nc("@title:window", "Select XPlanet Star Map File"), xplanetStarMap);
0232 
0233     if (!file.isEmpty())
0234         kcfg_XplanetStarmapPath->setText(QFileInfo(file).completeBaseName());
0235 
0236 }
0237 
0238 void OpsXplanet::slotSelectArcFile()
0239 {
0240 
0241     QString xplanetArc = XPlanetShareDirectory() + QDir::separator() + "arcs";
0242 
0243     QString file =
0244         QFileDialog::getOpenFileName(KStars::Instance(), i18nc("@title:window", "Select XPlanet Arc File"), xplanetArc);
0245 
0246     if (!file.isEmpty())
0247         kcfg_XplanetArcFilePath->setText(QFileInfo(file).completeBaseName());
0248 
0249 }