klog
utilities.h
1 #ifndef KLOG_UTILITIES_H
2 #define KLOG_UTILITIES_H
3 /***************************************************************************
4  utilities.h - description
5  -------------------
6  begin : jun 2015
7  copyright : (C) 2015 by Jaime Robles
8  email : jaime@robles.es
9  ***************************************************************************/
10 
11 /*****************************************************************************
12  * This file is part of KLog. *
13  * *
14  * KLog is free software: you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation, either version 3 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * KLog is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with KLog. If not, see <https://www.gnu.org/licenses/>. *
26  * *
27  *****************************************************************************/
28 /*
29  This class implements general use utilities that can be used from any other class
30  Anything that is not directly related with a class itself and could be used from different
31  classes should be here.
32 
33  This class should not need to query the DB neither the DataProxy Class
34 */
35 #include <QDesktopServices>
36 #include <QDir>
37 #include <QFile>
38 #include <QInputDialog>
39 #include <QLineEdit>
40 #include <QObject>
41 #include <QString>
42 #include <QtGlobal>
43 #include <iostream>
44 //#include <QtWidgets>
45 #include <QPalette>
46 #include <QSettings>
47 #include <QtDebug>
48 #include "adif.h"
49 #include "global.h" // Remove when all deprecated functions are removed
50 #include "klogdefinitions.h"
51 #include "locator.h"
52 //#include "dataproxy_sqlite.h"
53 
54 class Utilities : public QObject {
55  Q_OBJECT
56  friend class tst_Utilities;
57 
58 public:
59  Utilities(const QString &_parentName);
60  ~Utilities();
61  //void setDarkMode(const QString &_dm);
62  //bool isDarkMode();
63 
64 
65  //void setSpecialCalls (const QStringList &_p);
66 
67  int getProgresStepForDialog(int totalSteps);
68  bool trueOrFalse(const QString &_s); // reads a String and return true if s.upper()== TRUE :-)
69  QChar boolToCharToSQLite(const bool _b);
70  QString boolToQString(const bool _b);
71  QString checkAndFixASCIIinADIF(const QString &_data);
72  QString getAgent(const QString &_klogversion);
73  QString getGlobalAgent(const QString &_klogversion);
74  // qOperatingSystemVersion getOS();
75  //Devel or debug functions - Not adding any feature to the user
76  void printQString(const QStringList &_qs);
77 
78  QString getKLogDBFile();
79  QString getKLogDBBackupFile();
80  bool QStringToBool(const QString &_s);
81 
82  // qString getKLogDatabaseFile(const QString &_file);
83  bool fileExists(const QString &_fileName);
84 
85  QString getTQSLsFileName();
86  QString getTQSLsPath(); // Depending on the OS where are usually installed the executables
87  QString getHomeDir();
88  QString getCfgFile();
89  QString getCTYFile();
90  QString getDebugLogFile();
91  QString getSaveSpotsLogFile();
92  QString getBackupADIFile();
93  QString getClubLogFile();
94  QString getEQSLFile();
95  QString getLoTWAdifFile();
96  QString getClearSQLi(QString _s);
97  void setVersion(const QString &_v);
98  QString getVersion();
99  double getVersionDouble();
100 
101  QDate getDefaultDate();
102  QString getDefaultRST(const QString &_m);
103  QStringList getDefaultLogFields();
104  QString getDefaultModeForFreq(const double _f);
105 
106  int getNormalizedDXCCValue(const int _dxcc);
107 
108  // Validations
109  bool isValidDate(const QDate _d);
110  bool isValidDateTime(const QString &_d);
111  //bool isValidCall(const QString &_c, bool _force=false); // To be replaced by Callsign::isValid
112 
113  //bool isSameFreq(const double fr1, const double fr2);
114 
115  bool isValidFreq(const QString &_b);
116  bool isValidGrid(const QString &_b);
117  bool isValidGrid_ext(const QString &_b);
118  bool isValidVUCCGrids(const QString &_b);
119  bool isValidRST(const QString &_b);
120  bool isValidPower(const QString &_b);
121  bool isValidComment(const QString &_b);
122  bool isValidName(const QString &_b);
123  bool isValidADIFField(const QString &_b);
124  bool isValidQSL_Rcvd(const QString &c);
125  bool isValidQSL_Sent(const QString &c);
126  bool isValidUpload_Status(const QString &c);
127  bool isValidIOTA(const QString &_c);
128  //bool isValidFISTS(const QString &c);
129 
130  bool isValidTimeFromString(const QString &_s);
131  bool isValidDateFromString(const QString &_s);
132  bool isValidDateTimeFromString(const QString &_s);
133  bool isValidDXCC(const int _d);
134  bool isValidAntPath(const QString &_s);
135  bool isValidARRLSect(const QString &_s);
136  bool isValidPropMode(const QString &_s);
137  bool isValidEmail(const QString &_s);
138  QStringList getValidADIFFieldAndData(const QString &_b);
139  bool areThoseListsTheSame(const QStringList &_list1, const QStringList &_list2);
140  // qString getADIFField(const QString &_fieldName, const QString &_data);
141 
142  KLOG_DEPRECATED QString getMainCallFromComplexCall(const QString &_complexCall); //TODO: To be replaced by QString Callsign::getHostFullPrefix(bool getHomeIfEmpty=true);
143  QString getAValidCall (const QString &_wrongCall);
144  QString getPrefixFromCall(const QString &_c, bool withAreaNumber = false);
145  int getAreaNumberFromCall(const QString &_c);
146 
147  int getIOTAIdFromIOTA(const QString &_iota); // Returns the numbert IOTA id
148 
149  // Write DATE/TIME to DB
150  QString getDateTimeSQLiteStringFromDateTime(const QDateTime &_d);
151  QString getDateSQLiteStringFromDate(const QDate &_d);
152 
153  // Read from DB
154  QDateTime getDateTimeFromSQLiteString(const QString &_s);
155  QTime getTimeFromSQLiteString(const QString &_s);
156  QDate getDateFromSQliteString(const QString &_s);
157 
158  // Translate the LOG table fields into human readable
159  QString getLogColumnName(const QString &_column);
160  QString getLogColumnDBName(const QString &_column);
161 
162  // Creates the ADIF DATE & TIME formats
163  QString getADIFDateFromQDateTime(const QDateTime &_d); // Will produce the ADIF DATE format: "YYYYMMDD"
164  QString getADIFDateFromQDate(const QDate &_d); // Will produce the ADIF DATE format: "YYYYMMDD"
165  QString getADIFTimeFromQDateTime(const QDateTime &_d); // Will produce the ADIF TIME format: "HHMMSS"
166  QString getADIFTimeFromQTime(const QTime &_d); // Will produce the ADIF TIME format: "HHMMSS"
167 
168  // Parse Date & Time from ADIF
169  QDate getDateFromADIFDateString(const QString &_s); // Expects an ADIF DATE format string: "YYYYMMDD"
170  QTime getTimeFromADIFTimeString(const QString &_s); // Expects and ADIF TIME format String "HHMMSS" or "HHMM"
171 
172  // Parse date fromLoTW
173  QDate getDateFromLoTWQSLDateString(const QString &_s);
174 
175 
176  // Creates the Cabrillo DATE & TIME (http://wwrof.org/cabrillo/)
177  QString getCabrilloDateFromQDate(const QDate &_d); // Will produce the Cabrillo DATE format: "YYYY-MM-DD"
178  QString getCabrilloTimeFromQDateTime(const QDateTime &_d); // Will produce the Cabrillo TIME format: "HHMM"
179 
180  QString getOnlineServiceName(OnLineProvider _service);
181 
182  //bool isValidDistance(const double _d);
183  bool isValidSponsor(const QString &_s);
184 
185  QString debugLevelToString(DebugLogLevel _l);
186  DebugLogLevel stringToDebugLevel(const QString &_s);
187  bool isValidLogLevel(const QString &_s);
188  QStringList getDebugLevels();
189  void setLogLevel(DebugLogLevel _l);
190  void openQrzcom(const QString _call);
191  void printCommandHelp();
192  // qPalette getPalete(bool _ok);
193 signals:
194  void debugLog (QString _func, QString _msg, DebugLogLevel _level);
195 
196 private:
197  void init(); // Check if it is really needed or can be removed
198  void InitializeHash();
199  void setLogColumnNames(); // Creates the map of column Names (should be called from init() )
200  QString getKLogDefaultDatabaseFile();
201  //bool isCountrySuffix (const QString &_c);
202 
203  //bool isAKnownCall(const QString &_c);
204 
205  // qStringList getPrefixRunningTheCall(const QString &_c, bool withAreaNumber = false);
206  //Goes char by char identifying the prefix and area Number
207 
208  // qPair<QString, QString> getCallParts(const QString &_c);
209 
210  void setARRLSect();
211 
212  void setSponsorsList();
213  // qString getCheckedComplexCall(const QString &_c);
214  void logEvent(const QString &_func, const QString &_msg, DebugLogLevel _level);
215  //bool darkMode;
216  QString getDBPath();
217  // qString dbPath;
218  QString softwareVersion;
219  QString parentName; // The class that instanciated this object.
220 
221  QStringList ARRL_sects, sponsorsList, logLevels;
222  DebugLogLevel logLevel;
223  //KLOG_DEPRECATED QStringList specialCalls; // To be moved to World class
224  QMap<QString, QString> columnNames;
225  bool validateCalls;
226  QHash<QString, QString> ADIFHash; // Name, type
227 };
228 
229 #endif // UTILITIES_H
230 
231 
Definition: utilities.h:54
Definition: tst_utilities.cpp:34