1 /*
2     SPDX-FileCopyrightText: 2004 Jason Harris <jharris@30doradus.org>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "opsadvanced.h"
8 
9 #include "kspaths.h"
10 #include "kstars.h"
11 #include "ksutils.h"
12 #include "Options.h"
13 #include "skymap.h"
14 #include "ksmessagebox.h"
15 #include "widgets/timespinbox.h"
16 
17 #include <KConfigDialog>
18 
19 #include <QCheckBox>
20 #include <QDesktopServices>
21 #include <QLabel>
22 #include <QRadioButton>
23 
OpsAdvanced()24 OpsAdvanced::OpsAdvanced() : QFrame(KStars::Instance())
25 {
26     setupUi(this);
27 
28     //Initialize the timestep value
29     SlewTimeScale->tsbox()->changeScale(Options::slewTimeScale());
30 
31     connect(SlewTimeScale, SIGNAL(scaleChanged(float)), this, SLOT(slotChangeTimeScale(float)));
32 
33     connect(kcfg_HideOnSlew, SIGNAL(clicked()), this, SLOT(slotToggleHideOptions()));
34 
35     connect(kcfg_VerboseLogging, SIGNAL(toggled(bool)), this, SLOT(slotToggleVerbosityOptions()));
36 
37     connect(kcfg_LogToFile, SIGNAL(toggled(bool)), this, SLOT(slotToggleOutputOptions()));
38 
39     connect(showLogsB, SIGNAL(clicked()), this, SLOT(slotShowLogFiles()));
40 
41     connect(kcfg_ObsListDemoteHole, &QCheckBox::toggled,
42             [this](bool state)
43     {
44         kcfg_ObsListHoleSize->setEnabled(state);
45     });
46 
47     connect(zoomScrollSlider, &QSlider::valueChanged, [&](int value)
48     {
49         kcfg_ZoomScrollFactor->setValue(value / 100.0);
50     });
51 
52     connect(purgeAllConfigB, &QPushButton::clicked, this, &OpsAdvanced::slotPurge);
53 
54     connect(kcfg_DefaultCursor, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), [](int index)
55     {
56         Options::setDefaultCursor(index);
57         SkyMap::Instance()->setMouseCursorShape(static_cast<SkyMap::Cursor>(index));
58     });
59 
60     //Get a pointer to the KConfigDialog
61     KConfigDialog *m_ConfigDialog = KConfigDialog::exists("settings");
62     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
63     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
64 }
65 
slotChangeTimeScale(float newScale)66 void OpsAdvanced::slotChangeTimeScale(float newScale)
67 {
68     Options::setSlewTimeScale(newScale);
69 }
70 
slotToggleHideOptions()71 void OpsAdvanced::slotToggleHideOptions()
72 {
73     textLabelHideTimeStep->setEnabled(kcfg_HideOnSlew->isChecked());
74     SlewTimeScale->setEnabled(kcfg_HideOnSlew->isChecked());
75     HideBox->setEnabled(kcfg_HideOnSlew->isChecked());
76 }
77 
slotToggleVerbosityOptions()78 void OpsAdvanced::slotToggleVerbosityOptions()
79 {
80     if (kcfg_DisableLogging->isChecked())
81         KSUtils::Logging::Disable();
82 }
83 
slotToggleOutputOptions()84 void OpsAdvanced::slotToggleOutputOptions()
85 {
86     if (kcfg_LogToDefault->isChecked())
87     {
88         if (kcfg_DisableLogging->isChecked() == false)
89             KSUtils::Logging::UseDefault();
90     }
91     else
92         KSUtils::Logging::UseFile();
93 }
94 
slotShowLogFiles()95 void OpsAdvanced::slotShowLogFiles()
96 {
97     QUrl path = QUrl::fromLocalFile(QDir(KSPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("logs"));
98 
99     QDesktopServices::openUrl(path);
100 }
101 
slotApply()102 void OpsAdvanced::slotApply()
103 {
104     KSUtils::Logging::SyncFilterRules();
105 }
106 
slotPurge()107 void OpsAdvanced::slotPurge()
108 {
109     connect(KSMessageBox::Instance(), &KSMessageBox::accepted, this, [this]()
110     {
111         KSMessageBox::Instance()->disconnect(this);
112         QString dbFile = QDir(KSPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("userdb.sqlite");
113         QFile::remove(dbFile);
114         QString configFile = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)).filePath("kstarsrc");
115         QFile::remove(configFile);
116         configFile = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)).filePath("kstars.notifyrc");
117         QFile::remove(configFile);
118 
119         KSMessageBox::Instance()->info(i18n("Purge complete. Please restart KStars."));
120     });
121 
122     connect(KSMessageBox::Instance(), &KSMessageBox::rejected, this, [this]()
123     {
124         KSMessageBox::Instance()->disconnect(this);
125     });
126 
127     KSMessageBox::Instance()->warningContinueCancel(
128         i18n("Warning! All KStars configuration is going to be purged. This cannot be reversed."),
129         i18n("Clear Configuration"), 30, false);
130 
131 }
132