| 
									
										
										
										
											2014-05-18 16:52:39 +01: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 04:47:23 +02:00
										 |  |  | 	m_sourceIndex = 0; | 
					
						
							| 
									
										
										
										
											2021-12-05 12:35:39 +01: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 12:35:39 +01:00
										 |  |  |     m_altitude = 0.0f; | 
					
						
							| 
									
										
										
										
											2017-11-11 19:26:23 +01:00
										 |  |  | 	m_useLogFile = false; | 
					
						
							|  |  |  | 	m_logFileName = "sdrangel.log"; | 
					
						
							| 
									
										
										
										
											2017-11-12 02:23:55 +01:00
										 |  |  | 	m_consoleMinLogLevel = QtDebugMsg; | 
					
						
							|  |  |  |     m_fileMinLogLevel = QtDebugMsg; | 
					
						
							| 
									
										
										
										
											2022-06-18 12:35:44 +01:00
										 |  |  |     m_multisampling = 0; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray Preferences::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SimpleSerializer s(1); | 
					
						
							| 
									
										
										
										
											2022-03-20 12:23:50 +01:00
										 |  |  | 	s.writeString((int) SourceDevice, m_sourceDevice); | 
					
						
							|  |  |  | 	s.writeString((int) AudioType, m_audioType); | 
					
						
							|  |  |  | 	s.writeString((int) AudioDevice, m_audioDevice); | 
					
						
							|  |  |  | 	s.writeS32((int) SourceIndex, m_sourceIndex); | 
					
						
							|  |  |  | 	s.writeFloat((int) Latitude, m_latitude); | 
					
						
							|  |  |  | 	s.writeFloat((int) Longitude, m_longitude); | 
					
						
							|  |  |  | 	s.writeS32((int) ConsoleMinLogLevel, (int) m_consoleMinLogLevel); | 
					
						
							|  |  |  | 	s.writeBool((int) UseLogFile, m_useLogFile); | 
					
						
							|  |  |  | 	s.writeString((int) LogFileName, m_logFileName); | 
					
						
							|  |  |  |     s.writeS32((int) FileMinLogLevel, (int) m_fileMinLogLevel); | 
					
						
							|  |  |  |     s.writeString((int) StationName, m_stationName); | 
					
						
							|  |  |  |     s.writeFloat((int) Altitude, m_altitude); | 
					
						
							|  |  |  | 	s.writeS32((int) SourceItemIndex, m_sourceItemIndex); | 
					
						
							| 
									
										
										
										
											2022-06-18 12:35:44 +01:00
										 |  |  |     s.writeS32((int) Multisampling, m_multisampling); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	return s.final(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool Preferences::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-11 19:26:23 +01:00
										 |  |  |     int tmpInt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	SimpleDeserializer d(data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!d.isValid()) { | 
					
						
							|  |  |  | 		resetToDefaults(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-12 02:23:55 +01:00
										 |  |  | 	if(d.getVersion() == 1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2022-03-20 12:23:50 +01:00
										 |  |  | 		d.readString((int) SourceDevice, &m_sourceDevice); | 
					
						
							|  |  |  | 		d.readString((int) AudioType, &m_audioType); | 
					
						
							|  |  |  | 		d.readString((int) AudioDevice, &m_audioDevice); | 
					
						
							|  |  |  | 		d.readS32((int) SourceIndex, &m_sourceIndex, 0); | 
					
						
							|  |  |  | 		d.readFloat((int) Latitude, &m_latitude, 0.0f); | 
					
						
							|  |  |  | 		d.readFloat((int) Longitude, &m_longitude, 0.0f); | 
					
						
							| 
									
										
										
										
											2017-11-11 19:26:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 12:23:50 +01:00
										 |  |  | 		d.readS32((int) ConsoleMinLogLevel, &tmpInt, (int) QtDebugMsg); | 
					
						
							| 
									
										
										
										
											2017-11-11 19:26:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ((tmpInt == (int) QtDebugMsg) || | 
					
						
							|  |  |  | 		    (tmpInt == (int) QtInfoMsg) || | 
					
						
							|  |  |  | 		    (tmpInt == (int) QtWarningMsg) || | 
					
						
							|  |  |  | 		    (tmpInt == (int) QtCriticalMsg) || | 
					
						
							|  |  |  | 		    (tmpInt == (int) QtFatalMsg)) { | 
					
						
							| 
									
										
										
										
											2017-11-12 02:23:55 +01:00
										 |  |  |             m_consoleMinLogLevel = (QtMsgType) tmpInt; | 
					
						
							| 
									
										
										
										
											2017-11-11 19:26:23 +01:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-11-12 02:23:55 +01:00
										 |  |  | 		    m_consoleMinLogLevel = QtDebugMsg; | 
					
						
							| 
									
										
										
										
											2017-11-11 19:26:23 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 12:23:50 +01:00
										 |  |  | 		d.readBool((int) UseLogFile, &m_useLogFile, false); | 
					
						
							|  |  |  | 		d.readString((int) LogFileName, &m_logFileName, "sdrangel.log"); | 
					
						
							| 
									
										
										
										
											2017-11-12 02:23:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 12:23:50 +01:00
										 |  |  |         d.readS32((int) FileMinLogLevel, &tmpInt, (int) QtDebugMsg); | 
					
						
							|  |  |  |         d.readString((int) StationName, &m_stationName, "Home"); | 
					
						
							|  |  |  |         d.readFloat((int) Altitude, &m_altitude, 0.0f); | 
					
						
							|  |  |  | 		d.readS32((int) SourceItemIndex, &m_sourceItemIndex, 0); | 
					
						
							| 
									
										
										
										
											2017-11-12 02:23:55 +01: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; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-18 12:35:44 +01:00
										 |  |  |         d.readS32((int) Multisampling, &m_multisampling, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2017-11-12 02:23:55 +01:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		resetToDefaults(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |