mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 09:48:45 -05:00
Confirm redownload of files if less than 100 days old
This commit is contained in:
parent
51bf8a6b21
commit
6aa2943849
@ -26,6 +26,7 @@
|
||||
#include <QQmlContext>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ui_adsbdemodgui.h"
|
||||
@ -1214,6 +1215,9 @@ void ADSBDemodGUI::on_getOSNDB_clicked(bool checked)
|
||||
{
|
||||
// Don't try to download while already in progress
|
||||
if (m_progressDialog == nullptr)
|
||||
{
|
||||
QString osnDBFilename = getOSNDBFilename();
|
||||
if (confirmDownload(osnDBFilename))
|
||||
{
|
||||
// Download Opensky network database to a file
|
||||
QUrl dbURL(QString(OSNDB_URL));
|
||||
@ -1221,15 +1225,19 @@ void ADSBDemodGUI::on_getOSNDB_clicked(bool checked)
|
||||
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
m_progressDialog->setCancelButton(nullptr);
|
||||
m_progressDialog->setLabelText(QString("Downloading %1.").arg(OSNDB_URL));
|
||||
QNetworkReply *reply = m_dlm.download(dbURL, getOSNDBFilename());
|
||||
QNetworkReply *reply = m_dlm.download(dbURL, osnDBFilename);
|
||||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBDemodGUI::on_getAirportDB_clicked(bool checked)
|
||||
{
|
||||
// Don't try to download while already in progress
|
||||
if (m_progressDialog == nullptr)
|
||||
{
|
||||
QString airportDBFile = getAirportDBFilename();
|
||||
if (confirmDownload(airportDBFile))
|
||||
{
|
||||
// Download Opensky network database to a file
|
||||
QUrl dbURL(QString(AIRPORTS_URL));
|
||||
@ -1237,9 +1245,10 @@ void ADSBDemodGUI::on_getAirportDB_clicked(bool checked)
|
||||
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
m_progressDialog->setCancelButton(nullptr);
|
||||
m_progressDialog->setLabelText(QString("Downloading %1.").arg(AIRPORTS_URL));
|
||||
QNetworkReply *reply = m_dlm.download(dbURL, getAirportDBFilename());
|
||||
QNetworkReply *reply = m_dlm.download(dbURL, airportDBFile);
|
||||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBDemodGUI::on_flightPaths_clicked(bool checked)
|
||||
@ -1276,6 +1285,38 @@ QString ADSBDemodGUI::getFastDBFilename()
|
||||
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)
|
||||
{
|
||||
m_aircraftInfo = AircraftInformation::readOSNDB(filename);
|
||||
|
@ -508,6 +508,8 @@ private:
|
||||
QString getAirportFrequenciesDBFilename();
|
||||
QString getOSNDBFilename();
|
||||
QString getFastDBFilename();
|
||||
qint64 ADSBDemodGUI::fileAgeInDays(QString filename);
|
||||
bool ADSBDemodGUI::confirmDownload(QString filename);
|
||||
void readAirportDB(const QString& filename);
|
||||
void readAirportFrequenciesDB(const QString& filename);
|
||||
bool readOSNDB(const QString& filename);
|
||||
|
Loading…
Reference in New Issue
Block a user