Kstars

opslogs.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "opslogs.h"
8
9#include "kstars.h"
10#include "Options.h"
11#include "auxiliary/kspaths.h"
12#include "indi/indilistener.h"
13
14#include <KConfigDialog>
15#include <KFormat>
16#include <KMessageBox>
17
18#include <QFrame>
19#include <QUrl>
20#include <QDesktopServices>
21
22#include <basedevice.h>
23
24namespace Ekos
25{
26OpsLogs::OpsLogs() : QFrame(KStars::Instance())
27{
28 setupUi(this);
29
30 refreshInterface();
31
32 //Get a pointer to the KConfigDialog
33 KConfigDialog *m_ConfigDialog = KConfigDialog::exists("logssettings");
34 connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(refreshInterface()));
35 connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(refreshInterface()));
36
37 connect(clearLogsB, SIGNAL(clicked()), this, SLOT(slotClearLogs()));
38 connect(kcfg_VerboseLogging, SIGNAL(toggled(bool)), this, SLOT(slotToggleVerbosityOptions()));
39
40 connect(kcfg_LogToFile, SIGNAL(toggled(bool)), this, SLOT(slotToggleOutputOptions()));
41
42 connect(showLogsB, &QPushButton::clicked, []()
43 {
44 QDesktopServices::openUrl(QUrl::fromLocalFile(QDir(KSPaths::writableLocation(
45 QStandardPaths::AppLocalDataLocation)).filePath("logs")));
46 });
47
48 for (auto &b : modulesGroup->buttons())
49 b->setEnabled(kcfg_VerboseLogging->isChecked());
50 for (auto &b : driversGroup->buttons())
51 b->setEnabled(kcfg_VerboseLogging->isChecked());
52
53 qint64 totalSize = getDirSize(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("logs"));
54 totalSize += getDirSize(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("autofocus"));
55
56 clearLogsB->setToolTip(i18n("Clear all logs (%1)", KFormat().formatByteSize(totalSize)));
57
58}
59
60void OpsLogs::slotToggleVerbosityOptions()
61{
62 if (kcfg_DisableLogging->isChecked())
64
65 foreach (QAbstractButton *b, modulesGroup->buttons())
66 {
67 b->setEnabled(kcfg_VerboseLogging->isChecked());
68 // If verbose is not checked, CLEAR all selections
69 b->setChecked(kcfg_VerboseLogging->isChecked() ? b->isChecked() : false);
70 }
71
72 foreach (QAbstractButton *b, driversGroup->buttons())
73 {
74 b->setEnabled(kcfg_VerboseLogging->isChecked());
75 // If verbose is not checked, CLEAR all selections
76 b->setChecked(kcfg_VerboseLogging->isChecked() ? b->isChecked() : false);
77 }
78}
79
80void OpsLogs::slotToggleOutputOptions()
81{
82 if (kcfg_LogToDefault->isChecked())
83 {
84 if (kcfg_DisableLogging->isChecked() == false)
86 }
87 else
89}
90
91void OpsLogs::refreshInterface()
92{
93 uint16_t previousInterface = m_INDIDebugInterface;
94
95 m_INDIDebugInterface = 0;
96
97 if (Options::iNDIMountLogging())
98 m_INDIDebugInterface |= INDI::BaseDevice::TELESCOPE_INTERFACE;
99 if (Options::iNDICCDLogging())
100 m_INDIDebugInterface |= INDI::BaseDevice::CCD_INTERFACE;
101 if (Options::iNDIFocuserLogging())
102 m_INDIDebugInterface |= INDI::BaseDevice::FOCUSER_INTERFACE;
103 if (Options::iNDIFilterWheelLogging())
104 m_INDIDebugInterface |= INDI::BaseDevice::FILTER_INTERFACE;
105 if (Options::iNDIDomeLogging())
106 m_INDIDebugInterface |= INDI::BaseDevice::DOME_INTERFACE;
107 if (Options::iNDIWeatherLogging())
108 m_INDIDebugInterface |= INDI::BaseDevice::WEATHER_INTERFACE;
109 if (Options::iNDIDetectorLogging())
110 m_INDIDebugInterface |= INDI::BaseDevice::DETECTOR_INTERFACE;
111 if (Options::iNDIRotatorLogging())
112 m_INDIDebugInterface |= INDI::BaseDevice::ROTATOR_INTERFACE;
113 if (Options::iNDIGPSLogging())
114 m_INDIDebugInterface |= INDI::BaseDevice::GPS_INTERFACE;
115 if (Options::iNDIAOLogging())
116 m_INDIDebugInterface |= INDI::BaseDevice::AO_INTERFACE;
117 if (Options::iNDIAuxiliaryLogging())
118 m_INDIDebugInterface |= INDI::BaseDevice::AUX_INTERFACE;
119
120 Options::setINDILogging((m_INDIDebugInterface > 0));
121
122 m_SettingsChanged = (previousInterface != m_INDIDebugInterface);
123}
124
125// Following 2 functions from Stackoverflow #47854288
126qint64 OpsLogs::getDirSize(const QString &dirPath)
127{
128 qint64 size = 0;
129 QDir dir(dirPath);
130
132
133 for (QString &filePath : dir.entryList(fileFilters))
134 {
135 QFileInfo fi(dir, filePath);
136
137 size += fi.size();
138 }
139
141
142 for (QString &childDirPath : dir.entryList(dirFilters))
143 size += getDirSize(dirPath + QDir::separator() + childDirPath);
144
145 return size;
146}
147
148void OpsLogs::slotClearLogs()
149{
150 if (KMessageBox::warningContinueCancel(nullptr, i18n("Are you sure you want to delete all logs?")) == KMessageBox::Continue)
151 {
152 QDir logDir(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("logs"));
153 logDir.removeRecursively();
154 logDir.mkpath(".");
155
156 QDir autoFocusDir(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("autofocus"));
157 autoFocusDir.removeRecursively();
158 autoFocusDir.mkpath(".");
159
160 clearLogsB->setToolTip(i18n("Clear all logs"));
161 }
162}
163
164}
static KConfigDialog * exists(const QString &name)
QPushButton * button(QDialogButtonBox::StandardButton which) const
static void UseDefault()
Use the default logging mechanism.
Definition ksutils.cpp:1023
static void Disable()
Disable logging.
Definition ksutils.cpp:1028
static void UseFile()
Store all logs into the specified file.
Definition ksutils.cpp:926
This is the main window for KStars.
Definition kstars.h:89
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
ButtonCode warningContinueCancel(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
KIOCORE_EXPORT QString dir(const QString &fileClass)
void setChecked(bool)
void clicked(bool checked)
bool openUrl(const QUrl &url)
QChar separator()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromLocalFile(const QString &localFile)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.