Skip to content

Commit

Permalink
Clublog RT: RT Update is divided into the stages Delete and Insert
Browse files Browse the repository at this point in the history
it was found that if a QSO is updated and the change is, for example,
in Mode, then Clublog does not update the QSO but adds this QSO.
The Delete/Insert series should suppress this.
  • Loading branch information
foldynl committed Feb 3, 2024
1 parent 2bdac4b commit 6703d18
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
66 changes: 51 additions & 15 deletions core/ClubLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void ClubLog::sendRealtimeRequest(const OnlineCommand command,
{
FCT_IDENTIFICATION;

static QRegularExpression rx("[a-zA-Z]");

qCDebug(function_parameters) << command << uploadCallsign;// << record;

if ( !isUploadImmediatelyEnabled() )
Expand All @@ -132,28 +134,28 @@ void ClubLog::sendRealtimeRequest(const OnlineCommand command,
|| password.isEmpty() )
return;

QUrl url;
QUrlQuery query;
query.addQueryItem("email", email);
query.addQueryItem("callsign", uploadCallsign);
query.addQueryItem("password", password);
query.addQueryItem("api", API_KEY);

QByteArray data;
QTextStream stream(&data, QIODevice::ReadWrite);
AdiFormat adi(stream);
adi.exportContact(record);
stream.flush();
data.replace("\n", " ");
QUrl url;
static QRegularExpression rx("[a-zA-Z]");

switch (command)
{
case ClubLog::INSERT_QSO:
case ClubLog::UPDATE_QSO:
{
url.setUrl(API_LIVE_UPLOAD_URL);
QByteArray data;
QTextStream stream(&data, QIODevice::ReadWrite);
AdiFormat adi(stream);
adi.exportContact(record);
stream.flush();
data.replace("\n", " ");
query.addQueryItem("adif", data);
}
break;
case ClubLog::UPDATE_QSO:
case ClubLog::DELETE_QSO:
url.setUrl(API_LIVE_DELETE_URL);
query.addQueryItem("dxcall", record.value("callsign").toByteArray());
Expand All @@ -170,10 +172,25 @@ void ClubLog::sendRealtimeRequest(const OnlineCommand command,
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QNetworkReply *currentReply = nam->post(request, query.query(QUrl::FullyEncoded).toUtf8());
currentReply->setProperty("messageType", ( command == ClubLog::DELETE_QSO ) ? QVariant("realtimeDelete")
: QVariant("realtimeUpdate"));

QVariant messageType;
switch ( command )
{
case ClubLog::INSERT_QSO:
messageType = "realtimeInsert";
currentReply->setProperty("dxcall", record.value("callsign"));
break;
case ClubLog::UPDATE_QSO:
messageType = "realtimeUpdate";
RTupdatesInProgress.insert(record.value("id").toULongLong(), record);
break;
case ClubLog::DELETE_QSO:
messageType = "realtimeDelete";
break;
}

currentReply->setProperty("contactID", record.value("id"));
currentReply->setProperty("dxcall", record.value("callsign"));
currentReply->setProperty("messageType", messageType);
currentReply->setProperty("uploadCallsign", uploadCallsign);
activeReplies << currentReply;
}
Expand Down Expand Up @@ -280,9 +297,9 @@ void ClubLog::processReply(QNetworkReply* reply)
emit uploadFileOK("OK");
}
/******************/
/* realtimeUpdate */
/* realtimeInsert */
/******************/
else if ( messageType == "realtimeUpdate" )
else if ( messageType == "realtimeInsert" )
{
query_updateRT.bindValue(":id", reply->property("contactID"));
query_updateRT.bindValue(":callsign", reply->property("dxcall")); //to be sure that the QSO with the ID is still the same sa before sending
Expand All @@ -296,6 +313,24 @@ void ClubLog::processReply(QNetworkReply* reply)
}
}
/******************/
/* realtimeUpdate */
/******************/
else if ( messageType == "realtimeUpdate")
{
QSqlRecord insertRecord = RTupdatesInProgress.take(reply->property("contactID").toULongLong());

if ( insertRecord != QSqlRecord() )
{
sendRealtimeRequest(ClubLog::INSERT_QSO,
insertRecord,
reply->property("uploadCallsign").toString());
}
else
{
qWarning() << "Cannot find record for update in Update In-Progress Table";
}
}
/******************/
/* realtimeDelete */
/******************/
else if ( messageType == "realtimeDelete")
Expand Down Expand Up @@ -329,6 +364,7 @@ void ClubLog::abortRequest()
i.remove();
}
}
RTupdatesInProgress.clear();
}

void ClubLog::insertQSOImmediately(const QSqlRecord &record)
Expand Down
2 changes: 2 additions & 0 deletions core/ClubLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QObject>
#include <QSqlRecord>
#include <QSqlQuery>
#include <QHash>

class QNetworkReply;
class QNetworkAccessManager;
Expand Down Expand Up @@ -55,6 +56,7 @@ public slots:
const QString generateUploadCallsign(const QSqlRecord &record) const;
QSqlRecord stripRecord(const QSqlRecord&);
QSqlQuery query_updateRT;
QHash<unsigned long long, QSqlRecord> RTupdatesInProgress;

const static QString SECURE_STORAGE_KEY;
const static QString CONFIG_EMAIL_KEY;
Expand Down

0 comments on commit 6703d18

Please sign in to comment.