| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | #include "logbook.h"
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QFontMetrics>
 | 
					
						
							|  |  |  | #include <QStandardPaths>
 | 
					
						
							|  |  |  | #include <QDir>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-04 13:52:52 -04:00
										 |  |  |   auto logFileName = "js8call_log.adi"; | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |   auto countryFileName = "cty.dat"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LogBook::init() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}; | 
					
						
							|  |  |  |   QString countryDataFilename; | 
					
						
							|  |  |  |   if (dataPath.exists (countryFileName)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       // User override
 | 
					
						
							|  |  |  |       countryDataFilename = dataPath.absoluteFilePath (countryFileName); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       countryDataFilename = QString {":/"} + countryFileName; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _countries.init(countryDataFilename); | 
					
						
							|  |  |  |   _countries.load(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _worked.init(_countries.getCountryNames()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _log.init(dataPath.absoluteFilePath (logFileName)); | 
					
						
							|  |  |  |   _log.load(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _setAlreadyWorkedFromLog(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LogBook::_setAlreadyWorkedFromLog() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   QList<QString> calls = _log.getCallList(); | 
					
						
							|  |  |  |   QString c; | 
					
						
							|  |  |  |   foreach(c,calls) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       QString countryName = _countries.find(c); | 
					
						
							|  |  |  |       if (countryName.length() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           _worked.setAsWorked(countryName); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 17:02:14 -05:00
										 |  |  | bool LogBook::hasWorkedBefore(const QString &call, const QString &band){ | 
					
						
							|  |  |  |     return _log.match(call, band); | 
					
						
							| 
									
										
										
										
											2018-10-30 20:50:31 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | void LogBook::match(/*in*/const QString call, | 
					
						
							|  |  |  |                     /*out*/ QString &countryName, | 
					
						
							|  |  |  |                     bool &callWorkedBefore, | 
					
						
							|  |  |  |                     bool &countryWorkedBefore) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-10 23:48:56 -04:00
										 |  |  |     if(call.isEmpty()){ | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-10 23:48:56 -04:00
										 |  |  |     QString currentBand = "";  // match any band
 | 
					
						
							|  |  |  |     callWorkedBefore = _log.match(call, currentBand); | 
					
						
							|  |  |  |     countryName = _countries.find(call); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (countryName.length() > 0){  //  country was found
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |         countryWorkedBefore = _worked.getHasWorked(countryName); | 
					
						
							| 
									
										
										
										
											2019-03-10 23:48:56 -04:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         countryName = "where?"; //error: prefix not found
 | 
					
						
							|  |  |  |         countryWorkedBefore = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool LogBook::findCallDetails( | 
					
						
							|  |  |  |                     /*in*/ | 
					
						
							|  |  |  |                     const QString call, | 
					
						
							|  |  |  |                     /*out*/ | 
					
						
							| 
									
										
										
										
											2019-06-13 09:35:53 -04:00
										 |  |  |                     QString &grid, | 
					
						
							| 
									
										
										
										
											2019-03-10 23:48:56 -04:00
										 |  |  |                     QString &date, | 
					
						
							|  |  |  |                     QString &name, | 
					
						
							|  |  |  |                     QString &comment) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if(call.isEmpty()){ | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto qsos = _log.find(call); | 
					
						
							|  |  |  |     if(qsos.isEmpty()){ | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-10 23:48:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     foreach(auto qso, qsos){ | 
					
						
							| 
									
										
										
										
											2019-06-13 09:35:53 -04:00
										 |  |  |         if(grid.isEmpty() && !qso.grid.isEmpty()) grid = qso.grid; | 
					
						
							| 
									
										
										
										
											2019-03-10 23:48:56 -04:00
										 |  |  |         if(date.isEmpty() && !qso.date.isEmpty()) date = qso.date; | 
					
						
							|  |  |  |         if(name.isEmpty() && !qso.name.isEmpty()) name = qso.name; | 
					
						
							|  |  |  |         if(comment.isEmpty() && !qso.comment.isEmpty()) comment = qso.comment; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-13 09:35:53 -04:00
										 |  |  | void LogBook::addAsWorked(const QString call, const QString band, const QString mode, const QString submode, const QString grid, const QString date, const QString name, const QString comment) | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-13 09:35:53 -04:00
										 |  |  |   _log.add(call,band,mode,submode,grid,date,name,comment); | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |   QString countryName = _countries.find(call); | 
					
						
							|  |  |  |   if (countryName.length() > 0) | 
					
						
							|  |  |  |     _worked.setAsWorked(countryName); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |