File indexing completed on 2024-07-14 07:17:15

0001 /*
0002     SPDX-FileCopyrightText: 2004 Jason Harris <jharris@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opsadvanced.h"
0008 
0009 #include "kspaths.h"
0010 #include "kstars.h"
0011 #include "ksutils.h"
0012 #include "Options.h"
0013 #include "skymap.h"
0014 #include "ksmessagebox.h"
0015 #include "widgets/timespinbox.h"
0016 
0017 #include <KConfigDialog>
0018 
0019 #include <QCheckBox>
0020 #include <QDesktopServices>
0021 #include <QLabel>
0022 #include <QRadioButton>
0023 
0024 OpsAdvanced::OpsAdvanced() : QFrame(KStars::Instance())
0025 {
0026     setupUi(this);
0027 
0028     //Initialize the timestep value
0029     SlewTimeScale->tsbox()->changeScale(Options::slewTimeScale());
0030 
0031     connect(SlewTimeScale, SIGNAL(scaleChanged(float)), this, SLOT(slotChangeTimeScale(float)));
0032 
0033     connect(kcfg_HideOnSlew, SIGNAL(clicked()), this, SLOT(slotToggleHideOptions()));
0034 
0035     connect(kcfg_VerboseLogging, SIGNAL(toggled(bool)), this, SLOT(slotToggleVerbosityOptions()));
0036 
0037     connect(kcfg_LogToFile, SIGNAL(toggled(bool)), this, SLOT(slotToggleOutputOptions()));
0038 
0039     connect(showLogsB, SIGNAL(clicked()), this, SLOT(slotShowLogFiles()));
0040 
0041     connect(kcfg_ObsListDemoteHole, &QCheckBox::toggled,
0042             [this](bool state)
0043     {
0044         kcfg_ObsListHoleSize->setEnabled(state);
0045     });
0046 
0047     connect(zoomScrollSlider, &QSlider::valueChanged, [&](int value)
0048     {
0049         kcfg_ZoomScrollFactor->setValue(value / 100.0);
0050     });
0051 
0052     connect(purgeAllConfigB, &QPushButton::clicked, this, &OpsAdvanced::slotPurge);
0053 
0054     connect(kcfg_DefaultCursor, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), [](int index)
0055     {
0056         Options::setDefaultCursor(index);
0057         SkyMap::Instance()->setMouseCursorShape(static_cast<SkyMap::Cursor>(index));
0058     });
0059 
0060     //Get a pointer to the KConfigDialog
0061     KConfigDialog *m_ConfigDialog = KConfigDialog::exists("settings");
0062     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
0063     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
0064 }
0065 
0066 void OpsAdvanced::slotChangeTimeScale(float newScale)
0067 {
0068     Options::setSlewTimeScale(newScale);
0069 }
0070 
0071 void OpsAdvanced::slotToggleHideOptions()
0072 {
0073     const auto isOn = kcfg_HideOnSlew->isChecked();
0074     textLabelHideTimeStep->setEnabled(isOn);
0075     SlewTimeScale->setEnabled(isOn);
0076     kcfg_MagLimitHideStar->setEnabled(isOn);
0077     kcfg_HideCBounds->setEnabled(isOn);
0078     kcfg_HideCLines->setEnabled(isOn);
0079     kcfg_HideCNames->setEnabled(isOn);
0080     kcfg_HideGrids->setEnabled(isOn);
0081     kcfg_HideLabels->setEnabled(isOn);
0082     kcfg_HidePlanets->setEnabled(isOn);
0083     kcfg_HideStars->setEnabled(isOn);
0084 }
0085 
0086 void OpsAdvanced::slotToggleVerbosityOptions()
0087 {
0088     if (kcfg_DisableLogging->isChecked())
0089         KSUtils::Logging::Disable();
0090 }
0091 
0092 void OpsAdvanced::slotToggleOutputOptions()
0093 {
0094     if (kcfg_LogToDefault->isChecked())
0095     {
0096         if (kcfg_DisableLogging->isChecked() == false)
0097             KSUtils::Logging::UseDefault();
0098     }
0099     else
0100         KSUtils::Logging::UseFile();
0101 }
0102 
0103 void OpsAdvanced::slotShowLogFiles()
0104 {
0105     QUrl path = QUrl::fromLocalFile(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("logs"));
0106 
0107     QDesktopServices::openUrl(path);
0108 }
0109 
0110 void OpsAdvanced::slotApply()
0111 {
0112     KSUtils::Logging::SyncFilterRules();
0113 }
0114 
0115 void OpsAdvanced::slotPurge()
0116 {
0117     connect(KSMessageBox::Instance(), &KSMessageBox::accepted, this, [this]()
0118     {
0119         KSMessageBox::Instance()->disconnect(this);
0120         QString dbFile = QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("userdb.sqlite");
0121         QFile::remove(dbFile);
0122         QString configFile = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)).filePath("kstarsrc");
0123         QFile::remove(configFile);
0124         configFile = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)).filePath("kstars.notifyrc");
0125         QFile::remove(configFile);
0126 
0127         KSMessageBox::Instance()->info(i18n("Purge complete. Please restart KStars."));
0128     });
0129 
0130     connect(KSMessageBox::Instance(), &KSMessageBox::rejected, this, [this]()
0131     {
0132         KSMessageBox::Instance()->disconnect(this);
0133     });
0134 
0135     KSMessageBox::Instance()->warningContinueCancel(
0136         i18n("Warning! All KStars configuration is going to be purged. This cannot be reversed."),
0137         i18n("Clear Configuration"), 30, false);
0138 
0139 }