1 #ifndef FILEMANAGER_H 2 #define FILEMANAGER_H 3 4 /*************************************************************************** 5 filemanager.h - description 6 ------------------- 7 begin : sept 2011 8 copyright : (C) 2011 by Jaime Robles 9 email : jaime@robles.es 10 ***************************************************************************/ 11 12 /***************************************************************************** 13 * This file is part of KLog. * 14 * * 15 * KLog is free software: you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation, either version 3 of the License, or * 18 * (at your option) any later version. * 19 * * 20 * KLog is distributed in the hope that it will be useful, * 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 23 * GNU General Public License for more details. * 24 * * 25 * You should have received a copy of the GNU General Public License * 26 * along with KLog. If not, see <https://www.gnu.org/licenses/>. * 27 * * 28 *****************************************************************************/ 29 30 #include <QObject> 31 //#include <QtWidgets> 32 33 #include <QString> 34 #include <QFileDialog> 35 #include <QFile> 36 #include <QSqlQuery> 37 #include <QStringList> 38 #include <QSqlRecord> 39 #include <QProgressDialog> 40 #include <QMessageBox> 41 #include <QDateTime> 42 #include "world.h" 43 #include "awards.h" 44 #include "database.h" 45 #include "dataproxy_sqlite.h" 46 #include "dataproxy_sqlite.h" 47 #include "utilities.h" 48 #include "qso.h" 49 50 51 /* 52 enum 53 { 54 CQZones = 40, 55 ITUZones = 90, 56 DXCCEntities = 521 // http://www.adif.org/adif302.htm#Country%20Codes 57 }; 58 */ 59 //enum ExportMode {ModeLotW, ModeADIF}; 60 61 class FileManager : public QWidget 62 { 63 Q_OBJECT 64 public: 65 FileManager(DataProxy_SQLite *dp); 66 //FileManager(DataProxy_SQLite *dp, const QString &_klogDir); 67 FileManager(DataProxy_SQLite *dp, const QString &_klogDir, const QString &_softVersion); 68 //FileManager(DataProxy_SQLite *dp, const QString &_softVersion); 69 ~FileManager(); 70 //bool readAdif(const QString& tfileName, const int logN); 71 bool adifReadLog(const QString& tfileName, const int logN); 72 QList<int> adifLoTWReadLog2(const QString& fileName, const int logN); 73 QList<int> adifLoTWReadLog(const QString& tfileName, const int logN); 74 //QList<int> adifLoTWLogExport(const QString& _fileName, const QString &_callsign, const QDate &_startDate, const QDate &_endDate, const int _logN); 75 //QList<int> (const QString& _fileName, const QString &_callsign, const QDate &_startDate, const QDate &_endDate, const int _logN, const bool LoTWOnly); 76 77 bool adifQSOsExport(const QString& _fileName, QList<int> _qsos); 78 QList<int> adifLogExportReturnList(const QString& _fileName, const QString &_callsign, const QDate &_startDate, const QDate &_endDate, const int _logN, const ExportMode _em); 79 bool adifLogExport(const QString& _fileName, const int _logN); 80 bool adifLogExportMarked(const QString& _fileName); 81 bool adifReqQSLExport(const QString& _fileName); 82 //bool cabrilloLogExport(const QString& _fileName, const QString &_contestType, const int logNconst); 83 bool modifySetupFile(const QString& _filename, const QString &_field, const QString &_value); 84 void setVersion(const QString &_version); 85 QDateTime getDateTimeOfLastBackup(); 86 void setStationCallSign(const QString& _st); 87 void setDuplicatedQSOSlot (const int _secs); 88 89 90 private: 91 92 bool adifLogExportToFile(const QString& _fileName, const int _logN, bool justMarked, bool _qslRequested, bool _lotw); 93 //bool cabrilloLogExportToFile(const QString& _fileName, const int logNconst); 94 //bool cabrilloLogExportCQWWToFile(const QString& _fileName, const int logNconst); 95 //bool adifCheckMoreThanOneLog(QFile &_f); 96 int howManyLogsInFile(QFile & _f); 97 bool fillHashLog(QFile & _f); 98 QStringList getListOfLogsInFile(QFile & _f); 99 bool writeBackupDate(); 100 bool getStationCallsignFromUser(const QString &_qrzDX, const QDate &_dt); 101 bool showInvalidCallMessage(const QString &_call); 102 void showError (const QString &_txt); 103 104 bool askUserToUseAlwaysSameAnswer(); 105 bool askUserToAddThisQSOToLog(const QString &_call, const QDateTime _datetime, const QString &_mode, const QString &_band, const double _freq, const QDate _qslrdate); 106 107 //QString checkAndFixASCIIinADIF(_data); 108 109 bool processQsoReadingADIF(const QStringList &_line, const int logNumber);//, const bool _keepLogsInFile); 110 void queryPreparation(const int _logN); 111 112 bool checkADIFValidFormat(const QStringList &_qs); 113 114 QStringList readAdifField (const QString &_field); 115 // void writeAdifField(const QString &_field, const QString &_data); // It should possibly receive also the QTextStream 116 QString prepareStringLog(); 117 118 void writeQuery(QSqlQuery query, QTextStream &out, const ExportMode _em, const bool _justMarked, const bool _onlyRequested, const int _logN); 119 void writeADIFHeader(QTextStream &out, const ExportMode _em, const int _numberOfQsos); 120 121 bool dbCreated; 122 DataBase *db; 123 124 //float softwareVersion; 125 //DataProxy_SQLite *dataProxy; 126 DataProxy_SQLite *dataProxy;//, *dataProxyPrepared; 127 128 Utilities *util; 129 //QSO *qso; 130 131 bool rstTXDefault, rstRXDefault; // If true and a log is not including RST, 59 is automatically added 132 133 134 //bool printQs(const QString &_q, const QStringList _line); 135 bool printQs(const QStringList &_line); 136 //int confirmed; 137 QString klogDir; 138 QString klogVersion; 139 QString defaultStationCallsign; 140 141 bool ignoreUnknownAlways; // When importing ADIF, ignore all unknown fields. 142 bool usePreviousStationCallsignAnswerAlways; // When importing ADIF, ignore all unknown fields. 143 bool noMoreQso; 144 int duplicatedQSOSlotInSecs; 145 146 World *world; 147 Awards *awards; 148 //QSqlDatabase db; 149 150 QHash<int, int> hashLogs; // to create different logs when importing a ADIF file 151 152 QSqlQuery preparedQuery; 153 154 int constrid; // Just an id for the constructor to check who is being executed at one specific time 155 156 157 signals: 158 void addQSOToList(QStringList _qso); 159 void queryError(QString _functionFailed, QString errorCodeS, QString nativeError, QString failedQuery); // To alert about any failed query execution 160 161 }; 162 #endif // FILEMANAGER_H 163