From 82083c353e1e07a1b6e258539677df875abced41 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 11 Nov 2017 19:26:23 +0100 Subject: [PATCH] Main window: implement the logging options dialog. Use it only for log level --- logging/logger.h | 7 ++ sdrbase/settings/mainsettings.h | 7 ++ sdrbase/settings/preferences.cpp | 22 ++++ sdrbase/settings/preferences.h | 11 ++ sdrgui/CMakeLists.txt | 5 +- sdrgui/gui/loggingdialog.cpp | 106 ++++++++++++++++++ sdrgui/gui/loggingdialog.h | 47 ++++++++ sdrgui/gui/loggingdialog.ui | 179 +++++++++++++++++++++++++++++++ sdrgui/mainwindow.cpp | 15 +++ sdrgui/mainwindow.h | 3 + sdrgui/mainwindow.ui | 18 ++++ 11 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 sdrgui/gui/loggingdialog.cpp create mode 100644 sdrgui/gui/loggingdialog.h create mode 100644 sdrgui/gui/loggingdialog.ui diff --git a/logging/logger.h b/logging/logger.h index ea93826cd..9bddf2535 100644 --- a/logging/logger.h +++ b/logging/logger.h @@ -92,6 +92,13 @@ public: */ void installMsgHandler(); + /** + * Sets the minimum message level on the fly + */ + void setMinMessageLevel(const QtMsgType& minMsgLevel) { + minLevel = minMsgLevel; + } + /** Sets a thread-local variable that may be used to decorate log messages. This method is thread safe. diff --git a/sdrbase/settings/mainsettings.h b/sdrbase/settings/mainsettings.h index ea261ca06..7f6a9e64a 100644 --- a/sdrbase/settings/mainsettings.h +++ b/sdrbase/settings/mainsettings.h @@ -33,6 +33,13 @@ public: float getLatitude() const { return m_preferences.getLatitude(); } float getLongitude() const { return m_preferences.getLongitude(); } + void setMinLogLevel(const QtMsgType& minLogLevel) { m_preferences.setMinLogLevel(minLogLevel); } + void setUseLogFile(bool useLogFile) { m_preferences.setUseLogFile(useLogFile); } + void setLogFileName(const QString& value) { m_preferences.setLogFileName(value); } + QtMsgType getMinLogLevel() const { return m_preferences.getMinLogLevel(); } + bool getUseLogFile() const { return m_preferences.getUseLogFile(); } + const QString& getLogFileName() const { return m_preferences.getLogFileName(); } + const AudioDeviceInfo *getAudioDeviceInfo() const { return m_audioDeviceInfo; } void setAudioDeviceInfo(AudioDeviceInfo *audioDeviceInfo) { m_audioDeviceInfo = audioDeviceInfo; } diff --git a/sdrbase/settings/preferences.cpp b/sdrbase/settings/preferences.cpp index e94557921..a28d6846e 100644 --- a/sdrbase/settings/preferences.cpp +++ b/sdrbase/settings/preferences.cpp @@ -15,6 +15,8 @@ void Preferences::resetToDefaults() m_sourceIndex = 0; m_latitude = 0.0; m_longitude = 0.0; + m_useLogFile = false; + m_logFileName = "sdrangel.log"; } QByteArray Preferences::serialize() const @@ -27,11 +29,16 @@ QByteArray Preferences::serialize() const s.writeS32(5, m_sourceIndex); s.writeFloat(6, m_latitude); s.writeFloat(7, m_longitude); + s.writeS32(8, (int) m_minLogLevel); + s.writeBool(9, m_useLogFile); + s.writeString(10, m_logFileName); return s.final(); } bool Preferences::deserialize(const QByteArray& data) { + int tmpInt; + SimpleDeserializer d(data); if(!d.isValid()) { @@ -47,6 +54,21 @@ bool Preferences::deserialize(const QByteArray& data) d.readS32(5, &m_sourceIndex, 0); d.readFloat(6, &m_latitude, 0.0); d.readFloat(7, &m_longitude, 0.0); + + d.readS32(8, &tmpInt, (int) QtDebugMsg); + + if ((tmpInt == (int) QtDebugMsg) || + (tmpInt == (int) QtInfoMsg) || + (tmpInt == (int) QtWarningMsg) || + (tmpInt == (int) QtCriticalMsg) || + (tmpInt == (int) QtFatalMsg)) { + m_minLogLevel = (QtMsgType) tmpInt; + } else { + m_minLogLevel = QtDebugMsg; + } + + d.readBool(9, &m_useLogFile, false); + d.readString(10, &m_logFileName, "sdrangel.log"); return true; } else { resetToDefaults(); diff --git a/sdrbase/settings/preferences.h b/sdrbase/settings/preferences.h index 8bf8ae41a..7f384c992 100644 --- a/sdrbase/settings/preferences.h +++ b/sdrbase/settings/preferences.h @@ -28,6 +28,13 @@ public: float getLatitude() const { return m_latitude; } float getLongitude() const { return m_longitude; } + void setMinLogLevel(const QtMsgType& minLogLevel) { m_minLogLevel = minLogLevel; } + void setUseLogFile(bool useLogFile) { m_useLogFile = useLogFile; } + void setLogFileName(const QString& value) { m_logFileName = value; } + QtMsgType getMinLogLevel() const { return m_minLogLevel; } + bool getUseLogFile() const { return m_useLogFile; } + const QString& getLogFileName() const { return m_logFileName; } + protected: QString m_sourceType; QString m_sourceDevice; @@ -38,6 +45,10 @@ protected: float m_latitude; float m_longitude; + + QtMsgType m_minLogLevel; + bool m_useLogFile; + QString m_logFileName; }; #endif // INCLUDE_PREFERENCES_H diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index b7ecc85d3..38ee8b080 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -25,6 +25,7 @@ set(sdrgui_SOURCES gui/glspectrumgui.cpp gui/indicator.cpp gui/levelmeter.cpp + gui/loggingdialog.cpp gui/mypositiondialog.cpp gui/pluginsdialog.cpp gui/audiodialog.cpp @@ -72,7 +73,8 @@ set(sdrgui_HEADERS gui/glspectrum.h gui/glspectrumgui.h gui/indicator.h - gui/levelmeter.h + gui/levelmeter.h + gui/loggingdialog.h gui/mypositiondialog.h gui/physicalunit.h gui/pluginsdialog.h @@ -121,6 +123,7 @@ set(sdrgui_FORMS gui/samplingdevicedialog.ui gui/myposdialog.ui gui/transverterdialog.ui + gui/loggingdialog.ui ) set(sdrgui_RESOURCES diff --git a/sdrgui/gui/loggingdialog.cpp b/sdrgui/gui/loggingdialog.cpp new file mode 100644 index 000000000..68cf19d66 --- /dev/null +++ b/sdrgui/gui/loggingdialog.cpp @@ -0,0 +1,106 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 F4EXB // +// written by Edouard Griffiths // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "loggingdialog.h" +#include "ui_loggingdialog.h" + +LoggingDialog::LoggingDialog(MainSettings& mainSettings, QWidget* parent) : + QDialog(parent), + ui(new Ui::LoggingDialog), + m_mainSettings(mainSettings) +{ + ui->setupUi(this); + ui->level->setCurrentIndex(msgLevelToIndex(m_mainSettings.getMinLogLevel())); + ui->logToFile->setChecked(m_mainSettings.getUseLogFile()); + ui->logFileNameText->setText(m_mainSettings.getLogFileName()); + m_fileName = m_mainSettings.getLogFileName(); +} + +LoggingDialog::~LoggingDialog() +{ + delete ui; +} + +void LoggingDialog::accept() +{ + m_mainSettings.setMinLogLevel(msgLevelFromIndex(ui->level->currentIndex())); + m_mainSettings.setUseLogFile(ui->logToFile->isChecked()); + m_mainSettings.setLogFileName(m_fileName); + QDialog::accept(); +} + +void LoggingDialog::on_showFileDialog_clicked(bool checked __attribute__((unused))) +{ + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save log file"), ".", tr("Log Files (*.log)")); + + if (fileName != "") + { + qDebug("LoggingDialog::on_showFileDialog_clicked: selected: %s", qPrintable(fileName)); + m_fileName = fileName; + ui->logFileNameText->setText(fileName); + } +} + +QtMsgType LoggingDialog::msgLevelFromIndex(int intMsgLevel) +{ + switch (intMsgLevel) + { + case 0: + return QtDebugMsg; + break; + case 1: + return QtInfoMsg; + break; + case 2: + return QtWarningMsg; + break; + case 3: + return QtCriticalMsg; + break; + default: + return QtDebugMsg; + break; + } +} + +int LoggingDialog::msgLevelToIndex(const QtMsgType& msgLevel) +{ + switch (msgLevel) + { + case QtDebugMsg: + return 0; + break; + case QtInfoMsg: + return 1; + break; + case QtWarningMsg: + return 2; + break; + case QtCriticalMsg: + case QtFatalMsg: + return 3; + break; + default: + return 0; + break; + } +} + + diff --git a/sdrgui/gui/loggingdialog.h b/sdrgui/gui/loggingdialog.h new file mode 100644 index 000000000..043399284 --- /dev/null +++ b/sdrgui/gui/loggingdialog.h @@ -0,0 +1,47 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 F4EXB // +// written by Edouard Griffiths // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRGUI_GUI_LOGGINGDIALOG_H_ +#define SDRGUI_GUI_LOGGINGDIALOG_H_ + +#include +#include "settings/mainsettings.h" + +namespace Ui { + class LoggingDialog; +} + +class LoggingDialog : public QDialog { + Q_OBJECT +public: + explicit LoggingDialog(MainSettings& mainSettings, QWidget* parent = 0); + ~LoggingDialog(); + +private: + Ui::LoggingDialog* ui; + MainSettings& m_mainSettings; + QString m_fileName; + + QtMsgType msgLevelFromIndex(int intMsgLevel); + int msgLevelToIndex(const QtMsgType& msgLevel); + +private slots: + void accept(); + void on_showFileDialog_clicked(bool checked); +}; + +#endif /* SDRGUI_GUI_LOGGINGDIALOG_H_ */ diff --git a/sdrgui/gui/loggingdialog.ui b/sdrgui/gui/loggingdialog.ui new file mode 100644 index 000000000..7274af266 --- /dev/null +++ b/sdrgui/gui/loggingdialog.ui @@ -0,0 +1,179 @@ + + + LoggingDialog + + + + 0 + 0 + 461 + 110 + + + + + Sans Serif + 9 + + + + Logging settings + + + + + + + + Log level + + + + + + + Choose minimum message severity level for logging + + + + Debug + + + + + Info + + + + + Warning + + + + + Error + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 85 + 16777215 + + + + Select to activate file logging + + + Log to file + + + + + + + + 24 + 16777215 + + + + Choose a log file + + + + + + + :/preset-load.png:/preset-load.png + + + + + + + Log file + + + ... + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + buttonBox + + + + + + + buttonBox + accepted() + LoggingDialog + accept() + + + 257 + 194 + + + 157 + 203 + + + + + buttonBox + rejected() + LoggingDialog + reject() + + + 314 + 194 + + + 286 + 203 + + + + + diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index dec296955..114ddbdb3 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -40,6 +40,7 @@ #include "gui/rollupwidget.h" #include "gui/channelwindow.h" #include "gui/audiodialog.h" +#include "gui/loggingdialog.h" #include "gui/samplingdevicecontrol.h" #include "gui/mypositiondialog.h" #include "dsp/dspengine.h" @@ -493,6 +494,8 @@ void MainWindow::loadSettings() { ui->presetTree->setCurrentItem(addPresetToTree(m_settings.getPreset(i))); } + + setLoggingOpions(); } void MainWindow::loadPresetSettings(const Preset* preset, int tabIndex) @@ -847,6 +850,13 @@ void MainWindow::on_action_Audio_triggered() m_dspEngine->setAudioOutputDeviceIndex(m_audioDeviceInfo.getOutputDeviceIndex()); } +void MainWindow::on_action_Logging_triggered() +{ + LoggingDialog loggingDialog(m_settings, this); + loggingDialog.exec(); + setLoggingOpions(); +} + void MainWindow::on_action_My_Position_triggered() { MyPositionDialog myPositionDialog(m_settings, this); @@ -1144,3 +1154,8 @@ void MainWindow::updateStatus() { m_dateTimeWidget->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss t")); } + +void MainWindow::setLoggingOpions() +{ + m_logger->setMinMessageLevel(m_settings.getMinLogLevel()); +} diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index bdb60d8fa..7e5e4d361 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -130,6 +130,8 @@ private: void addSinkDevice(); void removeLastDevice(); + void setLoggingOpions(); + private slots: void handleMessages(); void updateStatus(); @@ -144,6 +146,7 @@ private slots: void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); void on_presetTree_itemActivated(QTreeWidgetItem *item, int column); void on_action_Audio_triggered(); + void on_action_Logging_triggered(); void on_action_DV_Serial_triggered(bool checked); void on_action_My_Position_triggered(); void on_sampleSource_changed(); diff --git a/sdrgui/mainwindow.ui b/sdrgui/mainwindow.ui index ffcaf9775..1709e7756 100644 --- a/sdrgui/mainwindow.ui +++ b/sdrgui/mainwindow.ui @@ -146,6 +146,7 @@ &Preferences + @@ -660,6 +661,9 @@ &Audio + + Audio devices setting + @@ -668,17 +672,31 @@ DV Serial + + Toggle AMBE DV serial device usage + My Position + + Set my geo position + Add sink device + + + Logging + + + Message logging options + + presetDock channelDock