1 /***************************************************************************
2                           elogclublog.cpp  -  description
3                              -------------------
4     begin                : feb 2015
5     copyright            : (C) 2015 by Jaime Robles
6     email                : jaime@robles.es
7  ***************************************************************************/
8 
9 /*****************************************************************************
10  * This file is part of KLog.                                                *
11  *                                                                           *
12  *    KLog is free software: you can redistribute it and/or modify           *
13  *    it under the terms of the GNU General Public License as published by   *
14  *    the Free Software Foundation, either version 3 of the License, or      *
15  *    (at your option) any later version.                                    *
16  *                                                                           *
17  *    KLog is distributed in the hope that it will be useful,                *
18  *    but WITHOUT ANY WARRANTY; without even the implied warranty of         *
19  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
20  *    GNU General Public License for more details.                           *
21  *                                                                           *
22  *    You should have received a copy of the GNU General Public License      *
23  *    along with KLog.  If not, see <https://www.gnu.org/licenses/>.         *
24  *                                                                           *
25  *****************************************************************************/
26 
27 #include "elogclublog.h"
28 #include <QCoreApplication>
29 #include <QUrl>
30 #include <QNetworkRequest>
31 #include <QFile>
32 //#include <QDebug>
33 
34 //https://clublog.freshdesk.com/support/solutions/59800
35 
eLogClubLog()36 eLogClubLog::eLogClubLog()
37 {
38      //qDebug()<< "eLogClubLog::eLogClubLog"  << QT_ENDL;
39 
40     //email = QString();
41     //pass = QString();
42     qsos.clear();
43     api = "9467beee93377e82a276b0a777d388b5c933d044";
44     currentQSO = -1;
45     manager = new QNetworkAccessManager(this);
46     connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotQsoUploadFinished(QNetworkReply*)));
47     //stationCallsign = QString();
48     uploadingFile = false;
49     util = new Utilities;
50      //qDebug()<< "eLogClubLog::eLogClubLog - END"  << QT_ENDL;
51 }
52 
~eLogClubLog()53 eLogClubLog::~eLogClubLog()
54 {
55          //qDebug()<< "eLogClubLog::~eLogClubLog"  << QT_ENDL;
56 }
57 
58 
slotQsoUploadFinished(QNetworkReply * data)59  void eLogClubLog::slotQsoUploadFinished(QNetworkReply *data)
60 {
61      //qDebug()<< "eLogClubLog::slotQsoUploadFinished"  << QT_ENDL;
62 
63     result = data->error();
64      //qDebug()<< "eLogClubLog::slotQsoUploadFinished - Result = " << QString::number(result) << QT_ENDL;
65 
66     const QByteArray sdata = data->readAll();
67 
68     QString text = QString();
69 
70     if (currentQSO>0)
71     {
72         emit actionReturnDownload(result, currentQSO);
73         currentQSO = -1;
74     }
75 
76 
77     if (result == QNetworkReply::NoError)
78     {
79 
80         text = "ClubLog: " + prepareToTranslate(sdata);
81          //qDebug()<< sdata;
82          //qDebug()<< "eLogClubLog::slotQsoUploadFinished - NO ERROR" << QT_ENDL;
83         if (uploadingFile)
84         {
85             uploadingFile = false;
86             emit signalFileUploaded(result, qsos);
87             qsos.clear();
88             return;
89         }
90 
91 
92     }
93     else if (result == QNetworkReply::HostNotFoundError)
94     {
95          //qDebug()<< "eLogClubLog::slotQsoUploadFinished - Result = Host Not found! = " << QString::number(result)  << QT_ENDL;
96         text = "ClubLog: " + tr("Host not found!");
97         //TODO: Mark the previous QSO as not sent to clublog
98     }
99     else if (result == QNetworkReply::TimeoutError)
100     {
101          //qDebug()<< "eLogClubLog::slotQsoUploadFinished - Result = Time out error! = " << QString::number(result)  << QT_ENDL;
102         text = "ClubLog: " + tr("Timeout error!");
103         //TODO: Mark the previous QSO as not sent to clublog
104     }
105     /*
106     else if (result == 201)
107     {
108         text = "ClubLog: " + tr("It seems to be a CREDENTIALS ERROR; check your email and password.");
109 
110         int i = QMessageBox::warning(nullptr, tr("KLog - ClubLog"),
111                                        tr("It seems that your ClubLog credentials are not correct.") + "\n" +
112                                           tr("Please check your credentials in the setup. ClubLog uploads will be disabled."),
113                                        QMessageBox::Ok);
114         emit disableClubLogAction(true);
115     }
116     else if (result == 202)
117     {
118          //qDebug()<< "eLogClubLog::slotQsoUploadFinished - Result = Password Error! = " << QString::number(result)  << QT_ENDL;
119         text = "ClubLog: " + tr("It seems to be a PASSWORD ERROR; check your password.");
120 
121         int i = QMessageBox::warning(nullptr, tr("KLog - ClubLog"),
122                                        tr("It seems that your ClubLog password is not correct.") + "\n" +
123                                           tr("Please check your password in the setup. ClubLog uploads will be disabled."),
124                                        QMessageBox::Ok);
125 
126         emit disableClubLogAction(true);
127         //TODO: Mark the previous QSO as not sent to clublog
128     }
129 
130     */
131     else if (result == 203)
132     {
133         text = "ClubLog: " + tr("QSO dupe or not existing (#%1)... ").arg(result);
134         QMessageBox::warning(nullptr, tr("KLog - ClubLog"),
135                                        tr("We have received an undefined error from Clublog (%1)").arg(result) + "\n" +
136                                           tr("This error may be caused for the QSO being duplicated or, if removing, trying to remove a non existing QSO."),
137                                        QMessageBox::Ok);
138     }
139     else
140     {
141          //qDebug()<< "eLogClubLog::slotQsoUploadFinished - Result = UNDEFINED = " << QString::number(result)  << QT_ENDL;
142         text = "ClubLog: " + tr("Undefined error number (#%1)... ").arg(result);
143         QMessageBox::warning(nullptr, tr("KLog - ClubLog"),
144                                        tr("We have received an undefined error from Clublog (%1)").arg(result) + "\n" +
145                                           tr("Please check your config in the setup and contact the KLog development team if you can't fix it. ClubLog uploads will be disabled."),
146                                        QMessageBox::Ok);
147         emit disableClubLogAction(true);
148         //TODO: Mark the previous QSO as not sent to clublog
149     }
150 
151      //qDebug()<< "eLogClubLog::slotQsoUploadFinished - Result = " << QString::number(result) << QT_ENDL;
152      //qDebug()<< "eLogClubLog::slotQsoUploadFinished - Result Text = " << text << QT_ENDL;
153     //emit done();
154     //emit signalFileUploaded(result, qsos);
155     emit showMessage(text);
156 
157 }
158 
slotFileUploadFinished(QNetworkReply * data)159 void eLogClubLog::slotFileUploadFinished(QNetworkReply *data)
160 {
161         //qDebug()<< "eLogClubLog::slotFileUploadFinished"  << QT_ENDL;
162 
163     result = data->error();
164          //qDebug()<< "eLogClubLog::slotFileUploadFinished - Result = " << QString::number(result) << QT_ENDL;
165 
166     const QByteArray sdata = data->readAll();
167 
168     QString text;
169 
170 
171     if (result == QNetworkReply::NoError)
172     {
173 
174         text = "ClubLog: " + prepareToTranslate(sdata);
175             //qDebug()<< "eLogClubLog::slotFileUploadFinished - Result = NoError = " << QString::number(result)  << QT_ENDL;
176             //qDebug()<< sdata;
177     }
178     else if (result == QNetworkReply::HostNotFoundError)
179     {
180             //qDebug()<< "eLogClubLog::slotFileUploadFinished - Result = Host Not found! = " << QString::number(result)  << QT_ENDL;
181         text = "ClubLog: " + tr("Host not found!");
182     }
183     else if (result == QNetworkReply::TimeoutError)
184     {
185             //qDebug()<< "eLogClubLog::slotFileUploadFinished - Result = Time out error! = " << QString::number(result)  << QT_ENDL;
186         text = "ClubLog: " + tr("Timeout error!");
187     }
188     else
189     {
190             //qDebug()<< "eLogClubLog::slotFileUploadFinished - Result = UNDEFINED = " << QString::number(result)  << QT_ENDL;
191         text = "ClubLog: " + tr("Undefined error...");
192     }
193 
194          //qDebug()<< "eLogClubLog::slotFileUploadFinished - Result = " << QString::number(result) << QT_ENDL;
195     //emit done();
196     emit  showMessage(text);
197 }
198 
downloadProgress(qint64 received,qint64 total)199 void eLogClubLog::downloadProgress(qint64 received, qint64 total) {
200         //qDebug()<< "eLogClubLog::downloadProgress: " << QString::number(received) << "/" << QString::number(total) << QT_ENDL;
201 
202         //qDebug()<< received << total;
203     emit actionShowProgres(received, total);
204 }
205 
slotErrorManagement(QNetworkReply::NetworkError networkError)206 void eLogClubLog::slotErrorManagement(QNetworkReply::NetworkError networkError)
207 {
208         //qDebug()<< "eLogClubLog::slotErrorManagement: " << QString::number(networkError) << QT_ENDL;
209     result = networkError;
210 
211     if (result == QNetworkReply::NoError)
212     {
213     }
214     else if (result == QNetworkReply::HostNotFoundError)
215     {
216              //qDebug()<< "eLogClubLog::slotErrorManagement: Host not found" << QT_ENDL;
217     }
218     else
219     {
220              //qDebug()<< "eLogClubLog::slotErrorManagement: ERROR!" << QT_ENDL;
221     }
222 
223     //actionError(result);
224 }
225 
226 
sendQSO(QStringList _qso)227 int eLogClubLog::sendQSO(QStringList _qso)
228 {
229      //qDebug() << "eLogClubLog::sendQSO: " << email << "/" << pass << "/" << api  << QT_ENDL;
230       //qDebug()<< "eLogClubLog::sendQSO:: length = " << QString::number(_qso.length()) << QT_ENDL;
231     // First Data in the QStringList is the QSO id, not to be sent to clublog but used in the signal actionReturnDownload(const int _i, const int _qsoId);
232    for(int i = 0; i<_qso.length(); i++)
233     {
234         //qDebug()<< "eLogClubLog::sendQSO = qso-at: "<< QString::number(i) << "- " << _qso.at(i) << QT_ENDL;
235     }
236     if (_qso.length()!=18)
237     {
238          //qDebug() << "eLogClubLog::sendQSO:: length - END" << QT_ENDL;
239         return -1;
240     }
241 
242     currentQSO = (_qso.at(0)).toInt();
243     _qso.removeFirst();
244     //_qso.removeFirst();
245     //qDebug()<< "eLogClubLog::sendQSO CALL TO USE (before checking): " << _qso.at(16) << QT_ENDL;
246     //qDebug()<< "eLogClubLog::sendQSO default StationCallsign): " << stationCallsign << QT_ENDL;
247 
248     QString tempCall = _qso.at(16);
249     if (tempCall.length()<1)
250     {
251         tempCall = stationCallsign;
252     }
253     //qDebug()<< "eLogClubLog::sendQSO CALL TO USE: " << tempCall << QT_ENDL;
254     _qso.removeLast();
255 
256     QString qso = getClubLogAdif(_qso);
257      //qDebug()<< "eLogClubLog::sendQSO: " << qso << QT_ENDL;
258     QUrlQuery params;
259     params.addQueryItem("adif",qso);
260     //qDebug() << "eLogClubLog::sendQSO: QSO: " << qso << QT_ENDL;
261      //qDebug() << "eLogClubLog::sendQSO: END" << QT_ENDL;
262     uploadingFile = false;
263     return sendDataParams(tempCall, params, true);
264     //return sendData(tempCall, qso);
265 
266 }
267 /*
268 int eLogClubLog::deleteQSOid(const int _qsoId)
269 {
270     //qDebug()<< "eLogClubLog::deleteQSOid: " << QString::number(_qsoId) << QT_ENDL;
271    // email, password, callsign, dxcall, datetime, bandid, api
272     QString dxcall, datatime, bandid;
273     QUrlQuery params;
274     params
275 
276 }
277 */
278 
sendDataParams(const QString & _clublogCall,const QUrlQuery & _params,bool _adding)279 int eLogClubLog::sendDataParams(const QString &_clublogCall, const QUrlQuery &_params, bool _adding)
280 {
281      //qDebug()<< "eLogClubLog::sendDataParams: Call: " << _clublogCall << QT_ENDL;
282      //qDebug()<< "eLogClubLog::sendDataParams: Params: " << _params.query(QUrl::FullyEncoded).toUtf8() << QT_ENDL;
283      //qDebug()<< "eLogClubLog::sendDataParams: email = " << email << QT_ENDL;
284      //qDebug()<< "eLogClubLog::sendDataParams: Pass = " << pass << QT_ENDL;
285 
286     QUrl serviceUrl;
287     if (_adding)
288     {
289      serviceUrl = QUrl("https://secure.clublog.org/realtime.php");
290     }
291     else
292     {
293      serviceUrl = QUrl("https://secure.clublog.org/delete.php");
294     }
295 
296     QByteArray postData;
297 
298     QUrlQuery params;
299     params.addQueryItem("email",email);
300     params.addQueryItem("password",pass);
301 
302     if  (_clublogCall.length()>2)
303     {
304         params.addQueryItem("callsign",_clublogCall);
305           //qDebug()<< "eLogClubLog::sendDataParams - callsign 1: " << _clublogCall << QT_ENDL;
306     }
307     else
308     {
309         params.addQueryItem("callsign",stationCallsign);
310     }
311 
312      //qDebug()<< "eLogClubLog::sendDataParams - query before send/delete: " << params.query(QUrl::FullyEncoded).toUtf8() << QT_ENDL;
313     if (_adding)
314     {
315         params.addQueryItem("api",api);
316         postData = params.query(QUrl::FullyEncoded).toUtf8();
317         postData = postData + "&" + _params.query(QUrl::FullyEncoded).toUtf8();
318         params.setQuery(postData);
319 
320         //TODO: ADD the params
321     }
322     else
323     {
324         //TODO: ADD the params
325         postData = params.query(QUrl::FullyEncoded).toUtf8();
326         postData = postData + "&" + _params.query(QUrl::FullyEncoded).toUtf8() ;
327         params.setQuery(postData);
328         params.addQueryItem("api",api);
329     }
330 
331 
332     postData = params.query(QUrl::FullyEncoded).toUtf8();
333 
334     QNetworkRequest request(serviceUrl);
335     request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
336 
337 
338 
339     manager->post(request, postData);
340      //qDebug()<< "eLogClubLog::sendDataParams - END" << QT_ENDL;
341     return -1;
342 }
343 
344 /*
345 int eLogClubLog::sendData(const QString &_clublogCall, const QString &_q)
346 {
347      //qDebug()<< "eLogClubLog::sendData: " << _q << QT_ENDL;
348 
349     QUrl serviceUrl = QUrl("https://secure.clublog.org/realtime.php");
350     QByteArray postData;
351 
352     //QByteArray postData;
353 
354     QUrlQuery params;
355     params.addQueryItem("email",email);
356     params.addQueryItem("password",pass);
357     if  (_clublogCall.length()>2)
358     {
359         params.addQueryItem("callsign",_clublogCall);
360             //qDebug()<< "eLogClubLog::sendData - callsign 1: " << _clublogCall << QT_ENDL;
361     }
362     else
363     {
364         params.addQueryItem("callsign",stationCallsign);
365         //ERROR
366     }
367 
368     params.addQueryItem("api",api);
369     params.addQueryItem("adif",_q);
370 
371     postData = params.query(QUrl::FullyEncoded).toUtf8();
372       //qDebug()<< "eLogClubLog::sendData - query: " << postData << QT_ENDL;
373     //postData = params.encodedQuery();
374 
375     // Call the webservice
376     //QNetworkAccessManager *networkManager = new QNetworkAccessManager;
377 
378     QNetworkRequest request(serviceUrl);
379     request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
380 
381     //connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotQsoUploadFinished(QNetworkReply*)));
382 
383     manager->post(request, postData);
384 
385     return -1;
386 
387 }
388 
389 */
getClubLogAdif(const QStringList _q)390 QString eLogClubLog::getClubLogAdif(const QStringList _q)
391 
392 {
393      //qDebug() << "eLogClubLog::getClubLogAdif: " << QString::number(_q.length()) << QT_ENDL;
394     // _qso must include 16 ordered fields than can be empty or contain data. This function builds the ADIF QSO
395 /* http://clublog.freshdesk.com/support/solutions/articles/53202-which-adif-fields-does-club-log-use-
396 ClubLog only accepts the following ADIF fields:
397 QSO_DATE
398 TIME_ON
399 TIME_OFF (this is stored independently and used for log matching as well as ADIF exports)
400 QSLRDATE
401 QSLSDATE
402 CALL
403 OPERATOR
404 MODE
405 BAND
406 BAND_RX
407 FREQ
408 QSL_RCVD
409 LOTW_QSL_RCVD
410 QSL_SENT
411 DXCC
412 PROP_MODE
413 CREDIT_GRANTED
414 RST_SENT
415 RST_RCVD
416 NOTES
417 */
418     if (_q.length()!=16)
419     {
420         return QString();
421     }
422     for (int i = 0; i< _q.length(); i++)
423     {
424          //qDebug()<< QString("eLogClubLog::getClubLogAdif: (%1): %2").arg(i).arg(_q.at(i)) << QT_ENDL;
425     }
426 
427     QString qso, aux1;
428     qso.clear();
429     aux1 = _q.at(0);
430      //qDebug()<< "eLogClubLog::getClubLogAdif: Date: " << _q.at(0)  << QT_ENDL;
431     if (QDate::fromString(aux1, "yyyyMMdd").isValid()){
432 
433         qso = "<QSO_DATE:" + QString::number(aux1.length()) + ">" +  aux1  +  " ";
434     }
435     else
436     {
437          //qDebug() << "eLogClubLog::getClubLogAdif: END error " << QT_ENDL;
438         return QString();
439     }
440 
441     //qso = "<QSO_DATE:" + QString::number((_q.at(0)).length()) + ">" + _q.at(0) + " ";
442     qso = qso + "<TIME_ON:" + QString::number((_q.at(1)).length()) + ">" + _q.at(1) + " ";
443       //qDebug()<< "eLogClubLog::getClubLogAdif: 10"  << QT_ENDL;
444     if ((_q.at(2)).length()>0)
445     {
446         qso = qso + "<QSLRDATE:" + QString::number((_q.at(2)).length()) + ">" + _q.at(2) + " ";
447     }
448       //qDebug()<< "eLogClubLog::getClubLogAdif: 20"  << QT_ENDL;
449     if ((_q.at(3)).length()>0)
450     {
451         qso = qso + "<QSLSDATE:" + QString::number((_q.at(3)).length()) + ">" + _q.at(3) + " ";
452     }
453 
454       //qDebug()<< "eLogClubLog::getClubLogAdif: 30"  << QT_ENDL;
455     qso = qso + "<CALL:" + QString::number((_q.at(4)).length()) + ">" + _q.at(4) + " ";
456       //qDebug()<< "eLogClubLog::getClubLogAdif: 40"  << QT_ENDL;
457     if ((_q.at(5)).length()>0)
458     {
459         qso = qso + "<OPERATOR:" + QString::number((_q.at(5)).length()) + ">" + _q.at(5) + " ";
460     }
461       //qDebug()<< "eLogClubLog::getClubLogAdif: 50"  << QT_ENDL;
462     qso = qso + "<MODE:" + QString::number((_q.at(6)).length()) + ">" + _q.at(6) + " ";
463       //qDebug()<< "eLogClubLog::getClubLogAdif: 60"  << QT_ENDL;
464     qso = qso + "<BAND:" + QString::number((_q.at(7)).length()) + ">" + _q.at(7) + " ";
465       //qDebug()<< "eLogClubLog::getClubLogAdif: 70"  << QT_ENDL;
466     if ((_q.at(8)).length()> 2)
467     {
468         qso = qso + "<BAND_RX:" + QString::number((_q.at(8)).length()) + ">" + _q.at(8) + " ";
469     }
470 
471     if ((_q.at(9)).length()> 2)
472     {
473         qso = qso + "<FREQ:" + QString::number((_q.at(9)).length()) + ">" + _q.at(9) + " ";
474     }
475 
476 
477       //qDebug()<< "eLogClubLog::getClubLogAdif: 90"  << QT_ENDL;
478     qso = qso + "<QSL_RCVD:" + QString::number((_q.at(10)).length()) + ">" + _q.at(10) + " ";
479       //qDebug()<< "eLogClubLog::getClubLogAdif: 100"  << QT_ENDL;
480     qso = qso + "<LOTW_QSL_RCVD:" + QString::number((_q.at(11)).length()) + ">" + _q.at(11) + " ";
481      //qDebug()<< "eLogClubLog::getClubLogAdif: 110"  << QT_ENDL;
482     //qso = qso + "<QSL_SENT:" + QString::number((_q.at(12)).length()) + ">" + _q.at(12) + " ";
483       //qDebug()<< "eLogClubLog::getClubLogAdif: 120"  << QT_ENDL;
484     if ((_q.at(13)).toInt()> 0)
485     {
486         qso = qso + "<DXCC:" + QString::number((_q.at(13)).length()) + ">" + _q.at(13) + " ";
487     }
488 
489 
490       //qDebug()<< "eLogClubLog::getClubLogAdif: 130'"  << QT_ENDL;
491     if ((_q.at(14)).toInt()> 0)
492     {
493         qso = qso + "<PROP_MODE:" + QString::number((_q.at(14)).length()) + ">" + _q.at(14) + " ";
494     }
495 
496       //qDebug()<< "eLogClubLog::getClubLogAdif: 140"  << QT_ENDL;
497     if ((_q.at(15)).length()>0)
498     {
499         qso = qso + "<CREDIT_GRANTED:" + QString::number((_q.at(15)).length()) + ">" + _q.at(15) + " ";
500     }
501 
502       //qDebug()<< "eLogClubLog::getClubLogAdif: 150"  << QT_ENDL;
503     qso = qso + "<EOR>";
504      //qDebug()<< "eLogClubLog:: - QSO: "  << qso << QT_ENDL;
505       //qDebug()<< "eLogClubLog::getClubLogAdif: 100"  << QT_ENDL;
506     return qso;
507 }
508 
setCredentials(const QString & _email,const QString & _pass,const QString & _defaultStationCallsign)509 void eLogClubLog::setCredentials(const QString &_email, const QString &_pass, const QString &_defaultStationCallsign)
510 {
511      //qDebug()<< "eLogClubLog::setCredentials: email: " << _email << " / Pass: " << _pass << " / StationCallsign: " << _defaultStationCallsign << QT_ENDL;
512     stationCallsign = _defaultStationCallsign;
513     email = _email;
514     pass = _pass;
515 }
516 
517 
518 
deleteQSO(QStringList _qso)519 int eLogClubLog::deleteQSO(QStringList _qso)
520 {
521      //qDebug()<< "eLogClubLog::deleteQSO: length = " << QString::number(_qso.length()) << QT_ENDL;
522      //qDebug()<< "eLogClubLog::deleteQSO: " << email << "/" << pass << "/" << api  << QT_ENDL;
523      //qDebug()<< "eLogClubLog::deleteQSO: email = " << email << QT_ENDL;
524      //qDebug()<< "eLogClubLog::deleteQSO: Pass = " << pass << QT_ENDL;
525 
526     // email, password, callsign, dxcall, datetime (sqlite format, not ADIF), bandid (only the number, not ADIF), api
527     if (_qso.length()!=18)
528     {
529         return -1;
530     }
531     for (int i = 0; i<_qso.length(); i++)
532     {
533          //qDebug()<< QString("eLogClubLog::deleteQSO: qso.at(%1) = %2").arg(i).arg(_qso.at(i)) << QT_ENDL;
534     }
535 
536     QString dxcall, sdateTime, bandid;
537 
538     QString tempCall = _qso.at(17);
539     if (tempCall.length()<1)
540     {
541         tempCall = stationCallsign;
542     }
543 
544 
545     dxcall = _qso.at(5);
546     QDateTime dateTime;
547     dateTime.setDate(QDate::fromString(_qso.at(1), "yyyyMMdd"));
548     dateTime.setTime(QTime::fromString(_qso.at(2), "HHmmss"));
549     if (!dateTime.isValid())
550     {
551         return -1;
552     }
553 
554     sdateTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");
555      //qDebug()<< QString("eLogClubLog::deleteQSO: DateTime = %1").arg(sdateTime) << QT_ENDL;
556       //qDebug()<< QString("eLogClubLog::deleteQSO: band-1: ") << _qso.at(8) << QT_ENDL;
557     bandid = (_qso.at(8)).chopped(1);
558       //qDebug()<< QString("eLogClubLog::deleteQSO: band-2: ") << bandid << QT_ENDL;
559     bool ok;
560     bandid.toInt(&ok);
561     if (!ok)
562     { // This check is to capture potential QSOs in 222Mhz (AKA 1.25)
563         bandid = bandid.chopped(1);
564          //qDebug()<< QString("eLogClubLog::deleteQSO: band-3: ") << bandid << QT_ENDL;
565     }
566      //qDebug()<< QString("eLogClubLog::deleteQSO: bandid = %1").arg(bandid) << QT_ENDL;
567     if (bandid.toInt()<=0)
568     {
569         return -2;
570     }
571 
572     QUrlQuery params;
573     params.addQueryItem("dxcall", dxcall);
574     params.addQueryItem("datetime", sdateTime);
575     params.addQueryItem("bandid", bandid);
576     //params.addQueryItem("adif",qso);
577     uploadingFile = false;
578     return sendDataParams(tempCall, params, false);
579 
580     //return sendData(qso);
581 
582 }
583 
prepareToTranslate(const QString & _m)584 QString eLogClubLog::prepareToTranslate(const QString &_m)
585 {
586         //qDebug()<< "eLogClubLog:: = prepareToTranslate" << _m << QT_ENDL;
587     if (_m == "Callsign missing")
588     {
589         return tr("Callsign missing");
590     }
591     else if (_m == "Invalid callsign")
592     {
593         return tr("Invalid callsign");
594     }
595     else if (_m == "Skipping SWL callsign")
596     {
597         return tr("Skipping SWL callsign");
598     }
599     else if (_m == "Callsign is your own call")
600     {
601         return tr("Callsign is your own call");
602     }
603     else if (_m == "Invalid callsign with no DXCC mapping")
604     {
605         return tr("Invalid callsign with no DXCC mapping");
606     }
607     else if (_m == "Updated QSO")
608     {
609         return tr("Updated QSO");
610     }
611     else if (_m == "Invalid ADIF record")
612     {
613         return tr("Invalid ADIF record");
614     }
615     else if (_m == "Missing ADIF record")
616     {
617         return tr("Missing ADIF record");
618     }
619     else if (_m == "Test mode - parameters ok, no action taken")
620     {
621         return tr("Test mode - parameters ok, no action taken");
622     }
623     else if (_m == "Excessive API Usage")
624     {
625         return tr("Excessive API Usage");
626     }
627     else if (_m == "Internal Error")
628     {
629         return tr("Internal Error");
630     }
631     else if (_m == "Rejected")
632     {
633         return tr("Rejected");
634     }
635     else if (_m == "QSO Duplicate")
636     {
637         return tr("QSO Duplicate");
638     }
639     else if (_m == "QSO Modified")
640     {
641         return tr("QSO Modified");
642     }
643     else if (_m == "Missing Login")
644     {
645         return tr("Missing Login");
646     }
647     else if (_m == "QSO OK")
648     {
649         return tr("QSO OK");
650     }
651     else if (_m == "Upload denied")
652     {
653         return tr("Upload denied");
654     }
655     else if (_m == "No callsign selected")
656     {
657         return tr("No callsign selected");
658     }
659     else if (_m == "No match found")
660     {
661         return tr("No match found");
662     }
663     else if (_m == "Dropped QSO")
664     {
665         return tr("Dropped QSO");
666     }
667     else if (_m == "OK")
668     {
669         return tr("OK");
670     }
671     else if (_m == "Login rejected")
672     {
673         return tr("Login rejected");
674     }
675     else if (_m == "Upload denied")
676     {
677         return tr("Upload denied");
678     }
679     else if (_m == "Rejected: Callsign is your own call")
680     {
681         return tr("Rejected: Callsign is your own call");
682     }
683     else
684     {
685         return _m;
686     }
687 }
688 
689 
modifyQSO(QStringList _oldQSO,QStringList _newQSO)690 int eLogClubLog::modifyQSO (QStringList _oldQSO, QStringList _newQSO)
691 {
692       //qDebug()<< QString("eLogClubLog::modifyQSO") << QT_ENDL;
693    int x = -1;
694 
695     x = deleteQSO(_oldQSO);
696     x = sendQSO(_newQSO);
697     return x;
698 }
699 
sendLogFile(const QString & _file,QList<int> _qso,bool _overwrite)700 void eLogClubLog::sendLogFile(const QString &_file, QList<int> _qso, bool _overwrite)
701 {
702       //qDebug()<< "eLogClubLog::sendLogFile: " << _file << QT_ENDL;
703     qsos.clear();
704     qsos.append(_qso);
705     QUrl serviceUrl;
706     serviceUrl = QUrl("https://clublog.org/putlogs.php");
707 
708     QByteArray postData;
709 
710     QUrlQuery params;
711 
712     // FIRST PARAMS is the file
713     QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
714 
715     QByteArray blob;
716 
717     //QFile *file = new QFile("_file");
718     QFile *file = new QFile(util->getClubLogFile());
719     if (file->open(QIODevice::ReadOnly))        /* Flawfinder: ignore */
720     {
721          blob = file->readAll();
722 
723     }
724     else
725     {
726           //qDebug()<< "eLogClubLog::sendLogFile: ERROR File not opened" << QT_ENDL;
727         return;
728     }
729     file->close();
730     // The rest of the form goes as usual
731       //qDebug()<< "eLogClubLog::sendLogFile: email: " << email << QT_ENDL;
732       //qDebug()<< "eLogClubLog::sendLogFile: pass: " << pass << QT_ENDL;
733       //qDebug()<< "eLogClubLog::sendLogFile: stationcall: " << stationCallsign << QT_ENDL;
734       //qDebug()<< "eLogClubLog::sendLogFile: api: " << api << QT_ENDL;
735 
736     QHttpPart emailPart;
737     emailPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"email\""));
738     emailPart.setBody(email.toUtf8());
739 
740     QHttpPart passPart;
741     passPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"password\""));
742     passPart.setBody(pass.toUtf8());
743 
744     QHttpPart callPart;
745     callPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"callsign\""));
746     callPart.setBody(stationCallsign.toUtf8());
747 
748     QHttpPart apiPart;
749     apiPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"api\""));
750     apiPart.setBody(api.toUtf8());
751     QString one;
752     if (_overwrite)
753     {
754         one  = QString("1");
755     }
756     else
757     {
758         one = QString("0");
759     }
760     //QString one = QString("1");
761     QHttpPart clearPart;
762     clearPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"clear\""));
763     clearPart.setBody(one.toUtf8());
764 
765     QHttpPart filePart;
766     QString aux = QString("form-data; name=\"file\"; filename=\"%1\"").arg(_file);
767     filePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
768     filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(aux));
769     filePart.setBody(blob);
770 
771     multiPart->append(filePart);
772     multiPart->append(emailPart);
773     multiPart->append(passPart);
774     multiPart->append(callPart);
775     multiPart->append(clearPart);
776     multiPart->append(apiPart);
777 
778 
779     uploadingFile = true;
780 
781     QNetworkRequest request(serviceUrl);
782     manager->post(request, multiPart);
783     //multiPart->setParent(reply);
784 
785       //qDebug()<< "eLogClubLog::sendLogFile - END" << QT_ENDL;
786 
787 }
788 
789 
790