Main window: implement the logging options dialog. Use it only for log level

pull/127/head
f4exb 2017-11-11 19:26:23 +01:00
rodzic d110a3749d
commit 82083c353e
11 zmienionych plików z 419 dodań i 1 usunięć

Wyświetl plik

@ -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.

Wyświetl plik

@ -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; }

Wyświetl plik

@ -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();

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QFileDialog>
#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;
}
}

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRGUI_GUI_LOGGINGDIALOG_H_
#define SDRGUI_GUI_LOGGINGDIALOG_H_
#include <QDialog>
#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_ */

Wyświetl plik

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LoggingDialog</class>
<widget class="QDialog" name="LoggingDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>461</width>
<height>110</height>
</rect>
</property>
<property name="font">
<font>
<family>Sans Serif</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="windowTitle">
<string>Logging settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="levelLayout">
<item>
<widget class="QLabel" name="levelLabel">
<property name="text">
<string>Log level</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="level">
<property name="toolTip">
<string>Choose minimum message severity level for logging</string>
</property>
<item>
<property name="text">
<string>Debug</string>
</property>
</item>
<item>
<property name="text">
<string>Info</string>
</property>
</item>
<item>
<property name="text">
<string>Warning</string>
</property>
</item>
<item>
<property name="text">
<string>Error</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="logFileLayout">
<item>
<widget class="QCheckBox" name="logToFile">
<property name="maximumSize">
<size>
<width>85</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Select to activate file logging</string>
</property>
<property name="text">
<string>Log to file</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="showFileDialog">
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Choose a log file</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/res.qrc">
<normaloff>:/preset-load.png</normaloff>:/preset-load.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="logFileNameText">
<property name="toolTip">
<string>Log file</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="../resources/res.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LoggingDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>194</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>203</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LoggingDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>314</x>
<y>194</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>203</y>
</hint>
</hints>
</connection>
</connections>
</ui>

Wyświetl plik

@ -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());
}

Wyświetl plik

@ -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();

Wyświetl plik

@ -146,6 +146,7 @@
<string>&amp;Preferences</string>
</property>
<addaction name="action_Audio"/>
<addaction name="action_Logging"/>
<addaction name="action_DV_Serial"/>
<addaction name="action_My_Position"/>
</widget>
@ -660,6 +661,9 @@
<property name="text">
<string>&amp;Audio</string>
</property>
<property name="toolTip">
<string>Audio devices setting</string>
</property>
</action>
<action name="action_DV_Serial">
<property name="checkable">
@ -668,17 +672,31 @@
<property name="text">
<string>DV Serial</string>
</property>
<property name="toolTip">
<string>Toggle AMBE DV serial device usage</string>
</property>
</action>
<action name="action_My_Position">
<property name="text">
<string>My Position</string>
</property>
<property name="toolTip">
<string>Set my geo position</string>
</property>
</action>
<action name="action_addSinkDevice">
<property name="text">
<string>Add sink device</string>
</property>
</action>
<action name="action_Logging">
<property name="text">
<string>Logging</string>
</property>
<property name="toolTip">
<string>Message logging options</string>
</property>
</action>
<zorder>presetDock</zorder>
<zorder>channelDock</zorder>
</widget>