2014-05-18 15:52:39 +00:00
|
|
|
#include "settings/preferences.h"
|
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
|
|
|
|
Preferences::Preferences()
|
|
|
|
{
|
|
|
|
resetToDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::resetToDefaults()
|
|
|
|
{
|
|
|
|
m_sourceDevice.clear();
|
|
|
|
m_audioType.clear();
|
|
|
|
m_audioDevice.clear();
|
2015-10-05 02:47:23 +00:00
|
|
|
m_sourceIndex = 0;
|
2021-12-05 11:35:39 +00:00
|
|
|
m_sourceItemIndex = 0;
|
|
|
|
m_stationName = "Home";
|
2020-10-27 16:22:10 +00:00
|
|
|
m_latitude = 49.012423; // Set an interesting location so map doesn't open up in the middle of the ocean
|
|
|
|
m_longitude = 8.418125;
|
2021-12-05 11:35:39 +00:00
|
|
|
m_altitude = 0.0f;
|
2017-11-11 18:26:23 +00:00
|
|
|
m_useLogFile = false;
|
|
|
|
m_logFileName = "sdrangel.log";
|
2017-11-12 01:23:55 +00:00
|
|
|
m_consoleMinLogLevel = QtDebugMsg;
|
|
|
|
m_fileMinLogLevel = QtDebugMsg;
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Preferences::serialize() const
|
|
|
|
{
|
|
|
|
SimpleSerializer s(1);
|
|
|
|
s.writeString(2, m_sourceDevice);
|
|
|
|
s.writeString(3, m_audioType);
|
|
|
|
s.writeString(4, m_audioDevice);
|
2015-10-02 00:22:56 +00:00
|
|
|
s.writeS32(5, m_sourceIndex);
|
2016-09-28 11:38:38 +00:00
|
|
|
s.writeFloat(6, m_latitude);
|
|
|
|
s.writeFloat(7, m_longitude);
|
2017-11-12 01:23:55 +00:00
|
|
|
s.writeS32(8, (int) m_consoleMinLogLevel);
|
2017-11-11 18:26:23 +00:00
|
|
|
s.writeBool(9, m_useLogFile);
|
|
|
|
s.writeString(10, m_logFileName);
|
2017-11-12 01:23:55 +00:00
|
|
|
s.writeS32(11, (int) m_fileMinLogLevel);
|
2021-12-05 11:35:39 +00:00
|
|
|
s.writeString(12, m_stationName);
|
|
|
|
s.writeFloat(13, m_altitude);
|
|
|
|
s.writeS32(14, m_sourceItemIndex);
|
2014-05-18 15:52:39 +00:00
|
|
|
return s.final();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Preferences::deserialize(const QByteArray& data)
|
|
|
|
{
|
2017-11-11 18:26:23 +00:00
|
|
|
int tmpInt;
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
SimpleDeserializer d(data);
|
|
|
|
|
|
|
|
if(!d.isValid()) {
|
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-12 01:23:55 +00:00
|
|
|
if(d.getVersion() == 1)
|
|
|
|
{
|
2014-05-18 15:52:39 +00:00
|
|
|
d.readString(2, &m_sourceDevice);
|
|
|
|
d.readString(3, &m_audioType);
|
|
|
|
d.readString(4, &m_audioDevice);
|
2015-10-05 02:47:23 +00:00
|
|
|
d.readS32(5, &m_sourceIndex, 0);
|
2020-10-27 16:22:10 +00:00
|
|
|
d.readFloat(6, &m_latitude, 0.0f);
|
|
|
|
d.readFloat(7, &m_longitude, 0.0f);
|
2017-11-11 18:26:23 +00:00
|
|
|
|
|
|
|
d.readS32(8, &tmpInt, (int) QtDebugMsg);
|
|
|
|
|
|
|
|
if ((tmpInt == (int) QtDebugMsg) ||
|
|
|
|
(tmpInt == (int) QtInfoMsg) ||
|
|
|
|
(tmpInt == (int) QtWarningMsg) ||
|
|
|
|
(tmpInt == (int) QtCriticalMsg) ||
|
|
|
|
(tmpInt == (int) QtFatalMsg)) {
|
2017-11-12 01:23:55 +00:00
|
|
|
m_consoleMinLogLevel = (QtMsgType) tmpInt;
|
2017-11-11 18:26:23 +00:00
|
|
|
} else {
|
2017-11-12 01:23:55 +00:00
|
|
|
m_consoleMinLogLevel = QtDebugMsg;
|
2017-11-11 18:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
d.readBool(9, &m_useLogFile, false);
|
|
|
|
d.readString(10, &m_logFileName, "sdrangel.log");
|
2017-11-12 01:23:55 +00:00
|
|
|
|
|
|
|
d.readS32(11, &tmpInt, (int) QtDebugMsg);
|
2020-10-27 16:22:10 +00:00
|
|
|
d.readString(12, &m_stationName, "Home");
|
|
|
|
d.readFloat(13, &m_altitude, 0.0f);
|
2021-12-05 11:35:39 +00:00
|
|
|
d.readS32(14, &m_sourceItemIndex, 0);
|
2017-11-12 01:23:55 +00:00
|
|
|
|
|
|
|
if ((tmpInt == (int) QtDebugMsg) ||
|
|
|
|
(tmpInt == (int) QtInfoMsg) ||
|
|
|
|
(tmpInt == (int) QtWarningMsg) ||
|
|
|
|
(tmpInt == (int) QtCriticalMsg) ||
|
|
|
|
(tmpInt == (int) QtFatalMsg)) {
|
|
|
|
m_fileMinLogLevel = (QtMsgType) tmpInt;
|
|
|
|
} else {
|
|
|
|
m_fileMinLogLevel = QtDebugMsg;
|
|
|
|
}
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
return true;
|
2017-11-12 01:23:55 +00:00
|
|
|
} else
|
|
|
|
{
|
2014-05-18 15:52:39 +00:00
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|