1 #ifndef WORLD_H
2 #define WORLD_H
3 /***************************************************************************
4                           world.h  -  description
5                              -------------------
6     begin                : sept 2011
7     copyright            : (C) 2011 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 //#include <QtWidgets>
30 #include <QString>
31 #include <QFile>
32 #include <QStringList>
33 #include <QSqlRelationalTableModel>
34 #include <QSqlQuery>
35 #include <QSqlError>
36 #include <QProgressBar>
37 #include <QProgressDialog>
38 #include <QtGlobal>
39 #include <QtDebug>
40 
41 #include "locator.h"
42 #include "dataproxy_sqlite.h"
43 //#include "klogdefinitions.h"
44 //#include "awards.h"
45 
46 
47 class QStringList;
48 
49 enum
50 {
51     Entity_Name = 1,
52     Entity_Continent = 2
53 };
54 
55 class World : public QWidget
56 {
57     //friend class Awards;
58     Q_OBJECT
59 
60 public:
61     World(DataProxy_SQLite *dp, const QString &_parentFunction);
62     World(DataProxy_SQLite *dp, const QString &_klogDir, const QString &_parentFunction);
63     World(DataProxy_SQLite *dp, const QString &_klogDir, const QString &_klogVer, const QString &_parentFunction);
64 
65     ~World();
66     bool create(const QString &_worldFile);
67     bool recreate(const QString &_worldFile);
68 
69     QString getQRZEntityName(const QString &_qrz);
70     QString getEntityName(const int _entityN);
71 
72     QString getQRZEntityMainPrefix(const QString &_qrz);
73     QString getEntityMainPrefix(const int _entityN);
74 
75     QString getQRZContinentNumber(const QString &_qrz); // Returns the continent id number
76     int getContinentNumber(const int _enti); // Returns the continent id number
77 
78     QString getQRZContinentShortName(const QString &_qrz); // Returns the continent shortName (EU, AF, ...)
79     QString getContinentShortName(const int _enti);
80 
81     QString getQRZLocator(const QString &_qrz); // Returns the entity locator
82     QString getLocator(const int _entityN); // Returns the entity locator
83 
84     double getQRZLongitude(const QString &_qrz); // Returns the longitude of the Entity
85     double getLongitude(const int _enti); // Returns the longitude of the Entity
86 
87     double getQRZLatitude(const QString &_qrz); // Returns the latitude of the Entity
88     double getLatitude(const int _enti); // Returns the latitude of the Entity
89 
90     int getEntityCqz(const int _enti);
91     int getQRZCqz(const QString &_qrz);
92     //int getPrefixCQz(const QString &_p);
93 
94     int getQRZItuz(const QString &_qrz);
95     int getEntityItuz(const int _enti);
96 
97     int getQRZARRLId(const QString &_qrz); //Returns the ARRL id of the Entity from a QRZ & Returns -1 if not found.
98     bool isNewCQz(const int _cqz);
99     bool isNewEntity(const int _entityN);
100     //int getBandIdFromFreq(const QString fr);
101 
102     QString getQRZEntityPrefixes(const QString &_qrz);
103     QString getEntityPrefixes(const int _enti);
104 
105     bool checkQRZValidFormat(const QString &_qrz);
106 
107     QStringList getEntitiesNames();
108     int getHowManyEntities();
109     bool hasSpecialEntities();
110 
111 private slots:
112 
113 
114 private:
115     //void identifyOS();
116     bool insertSpecialEntities();
117     int getPrefixId(const QString &_qrz);
118     //bool readCTYDAT();
119     bool readCTYCSV(const QString &_worldFile);
120     QStringList processLine(const QString &_line);
121     QStringList processLineP(const QString &_line, const int _processingEntity);
122     void createWorldModel();
123     QStringList readZones(const QString &pref, const int _cq, const int _itu);
124     QString changeSlashAndFindPrefix(const QString &_qrz); // Changes the \ into / and find the country prefix
125 
126     int progressBarPosition;
127 
128     bool created;
129     QString klogDir, klogVersion;
130     int cqz, ituz, numberOfEntities;
131     QString entityName;
132     QString currentPrefix; // Used in the progressBar
133 
134     bool ret;
135     QStringList list, prefixAndZones;
136     QString continentName, prefix;
137     int continentId;
138     double lat, lon, utc;
139     //int utc;
140     //QString line;
141     //bool readingDataOfAnEntity;
142     int nullValue;
143 
144 
145     QSqlRelationalTableModel *worldModel;
146     //QProgressBar *progressBar;
147 
148     Locator *locator;
149     DataProxy_SQLite *dataProxy;
150 
151     int constrid; // Just an id for the constructor to check who is being executed at one specific time
152     //Awards *awards;
153     //FLAGS
154     //QString flagsDir;
155     //FLAGS-END
156 signals:
157     //void qsoFound(const QStringList _qs); // Each: QString with format: Fieldname:value
158     void queryError(QString functionFailed, QString errorCodeS, QString nativeError, QString failedQuery); // To alert about any failed query execution
159 };
160 
161 
162 #endif // WORLD_H
163