kopia lustrzana https://github.com/f4exb/sdrangel
Confirm redownload of files if less than 100 days old
rodzic
51bf8a6b21
commit
6aa2943849
|
@ -26,6 +26,7 @@
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "ui_adsbdemodgui.h"
|
#include "ui_adsbdemodgui.h"
|
||||||
|
@ -1215,14 +1216,18 @@ void ADSBDemodGUI::on_getOSNDB_clicked(bool checked)
|
||||||
// Don't try to download while already in progress
|
// Don't try to download while already in progress
|
||||||
if (m_progressDialog == nullptr)
|
if (m_progressDialog == nullptr)
|
||||||
{
|
{
|
||||||
// Download Opensky network database to a file
|
QString osnDBFilename = getOSNDBFilename();
|
||||||
QUrl dbURL(QString(OSNDB_URL));
|
if (confirmDownload(osnDBFilename))
|
||||||
m_progressDialog = new QProgressDialog(this);
|
{
|
||||||
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
// Download Opensky network database to a file
|
||||||
m_progressDialog->setCancelButton(nullptr);
|
QUrl dbURL(QString(OSNDB_URL));
|
||||||
m_progressDialog->setLabelText(QString("Downloading %1.").arg(OSNDB_URL));
|
m_progressDialog = new QProgressDialog(this);
|
||||||
QNetworkReply *reply = m_dlm.download(dbURL, getOSNDBFilename());
|
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64)));
|
m_progressDialog->setCancelButton(nullptr);
|
||||||
|
m_progressDialog->setLabelText(QString("Downloading %1.").arg(OSNDB_URL));
|
||||||
|
QNetworkReply *reply = m_dlm.download(dbURL, osnDBFilename);
|
||||||
|
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1231,14 +1236,18 @@ void ADSBDemodGUI::on_getAirportDB_clicked(bool checked)
|
||||||
// Don't try to download while already in progress
|
// Don't try to download while already in progress
|
||||||
if (m_progressDialog == nullptr)
|
if (m_progressDialog == nullptr)
|
||||||
{
|
{
|
||||||
// Download Opensky network database to a file
|
QString airportDBFile = getAirportDBFilename();
|
||||||
QUrl dbURL(QString(AIRPORTS_URL));
|
if (confirmDownload(airportDBFile))
|
||||||
m_progressDialog = new QProgressDialog(this);
|
{
|
||||||
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
// Download Opensky network database to a file
|
||||||
m_progressDialog->setCancelButton(nullptr);
|
QUrl dbURL(QString(AIRPORTS_URL));
|
||||||
m_progressDialog->setLabelText(QString("Downloading %1.").arg(AIRPORTS_URL));
|
m_progressDialog = new QProgressDialog(this);
|
||||||
QNetworkReply *reply = m_dlm.download(dbURL, getAirportDBFilename());
|
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64)));
|
m_progressDialog->setCancelButton(nullptr);
|
||||||
|
m_progressDialog->setLabelText(QString("Downloading %1.").arg(AIRPORTS_URL));
|
||||||
|
QNetworkReply *reply = m_dlm.download(dbURL, airportDBFile);
|
||||||
|
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1276,6 +1285,38 @@ QString ADSBDemodGUI::getFastDBFilename()
|
||||||
return getDataDir() + "/aircraftDatabaseFast.csv";
|
return getDataDir() + "/aircraftDatabaseFast.csv";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 ADSBDemodGUI::fileAgeInDays(QString filename)
|
||||||
|
{
|
||||||
|
QFile file(filename);
|
||||||
|
if (file.exists())
|
||||||
|
{
|
||||||
|
QDateTime modified = file.fileTime(QFileDevice::FileModificationTime);
|
||||||
|
if (modified.isValid())
|
||||||
|
return modified.daysTo(QDateTime::currentDateTime());
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ADSBDemodGUI::confirmDownload(QString filename)
|
||||||
|
{
|
||||||
|
qint64 age = fileAgeInDays(filename);
|
||||||
|
if ((age == -1) || (age > 100))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::StandardButton reply;
|
||||||
|
if (age == 0)
|
||||||
|
reply = QMessageBox::question(this, "Confirm download", "This file was last downloaded today. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No);
|
||||||
|
else if (age == 1)
|
||||||
|
reply = QMessageBox::question(this, "Confirm download", "This file was last downloaded yesterday. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No);
|
||||||
|
else
|
||||||
|
reply = QMessageBox::question(this, "Confirm download", QString("This file was last downloaded %1 days ago. Are you sure you wish to redownload this file?").arg(age), QMessageBox::Yes|QMessageBox::No);
|
||||||
|
return reply == QMessageBox::Yes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ADSBDemodGUI::readOSNDB(const QString& filename)
|
bool ADSBDemodGUI::readOSNDB(const QString& filename)
|
||||||
{
|
{
|
||||||
m_aircraftInfo = AircraftInformation::readOSNDB(filename);
|
m_aircraftInfo = AircraftInformation::readOSNDB(filename);
|
||||||
|
|
|
@ -508,6 +508,8 @@ private:
|
||||||
QString getAirportFrequenciesDBFilename();
|
QString getAirportFrequenciesDBFilename();
|
||||||
QString getOSNDBFilename();
|
QString getOSNDBFilename();
|
||||||
QString getFastDBFilename();
|
QString getFastDBFilename();
|
||||||
|
qint64 ADSBDemodGUI::fileAgeInDays(QString filename);
|
||||||
|
bool ADSBDemodGUI::confirmDownload(QString filename);
|
||||||
void readAirportDB(const QString& filename);
|
void readAirportDB(const QString& filename);
|
||||||
void readAirportFrequenciesDB(const QString& filename);
|
void readAirportFrequenciesDB(const QString& filename);
|
||||||
bool readOSNDB(const QString& filename);
|
bool readOSNDB(const QString& filename);
|
||||||
|
|
Ładowanie…
Reference in New Issue