mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-23 10:05:46 -05:00
HTTPDownloadManagerGUI - Support retrying downloads. Remove close dialog buttons that don't work.
This commit is contained in:
parent
f026733bae
commit
a0dbe2adaf
@ -24,17 +24,24 @@
|
|||||||
HttpDownloadManagerGUI::HttpDownloadManagerGUI()
|
HttpDownloadManagerGUI::HttpDownloadManagerGUI()
|
||||||
{
|
{
|
||||||
connect(this, &HttpDownloadManager::downloadComplete, this, &HttpDownloadManagerGUI::downloadCompleteGUI);
|
connect(this, &HttpDownloadManager::downloadComplete, this, &HttpDownloadManagerGUI::downloadCompleteGUI);
|
||||||
|
connect(this, &HttpDownloadManager::retryDownload, this, &HttpDownloadManagerGUI::retryDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply *HttpDownloadManagerGUI::download(const QUrl &url, const QString &filename, QWidget *parent)
|
QNetworkReply *HttpDownloadManagerGUI::download(const QUrl &url, const QString &filename, QWidget *parent)
|
||||||
{
|
{
|
||||||
|
m_filenames.append(filename);
|
||||||
QNetworkReply *reply = HttpDownloadManager::download(url, filename);
|
QNetworkReply *reply = HttpDownloadManager::download(url, filename);
|
||||||
if (parent != nullptr)
|
if (parent != nullptr)
|
||||||
{
|
{
|
||||||
QProgressDialog *progressDialog = new QProgressDialog(parent);
|
QProgressDialog *progressDialog = new QProgressDialog(parent);
|
||||||
progressDialog->setCancelButton(nullptr);
|
progressDialog->setCancelButton(nullptr);
|
||||||
progressDialog->setMinimumDuration(500);
|
progressDialog->setMinimumDuration(500);
|
||||||
progressDialog->setLabelText(QString("Downloading %1.").arg(url.toString()));
|
progressDialog->setLabelText(QString("Downloading: %1\nTo: %2.").arg(url.toString(), filename));
|
||||||
|
Qt::WindowFlags flags = progressDialog->windowFlags();
|
||||||
|
flags |= Qt::CustomizeWindowHint;
|
||||||
|
flags &= ~Qt::WindowCloseButtonHint;
|
||||||
|
flags &= ~Qt::WindowContextHelpButtonHint;
|
||||||
|
progressDialog->setWindowFlags(flags);
|
||||||
m_progressDialogs.append(progressDialog);
|
m_progressDialogs.append(progressDialog);
|
||||||
connect(reply, &QNetworkReply::downloadProgress, this, [progressDialog](qint64 bytesRead, qint64 totalBytes) {
|
connect(reply, &QNetworkReply::downloadProgress, this, [progressDialog](qint64 bytesRead, qint64 totalBytes) {
|
||||||
if (progressDialog)
|
if (progressDialog)
|
||||||
@ -45,7 +52,9 @@ QNetworkReply *HttpDownloadManagerGUI::download(const QUrl &url, const QString &
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_progressDialogs.append(nullptr);
|
m_progressDialogs.append(nullptr);
|
||||||
|
}
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,16 +63,19 @@ bool HttpDownloadManagerGUI::confirmDownload(const QString& filename, QWidget *p
|
|||||||
{
|
{
|
||||||
qint64 age = HttpDownloadManager::fileAgeInDays(filename);
|
qint64 age = HttpDownloadManager::fileAgeInDays(filename);
|
||||||
if ((age == -1) || (age > maxAge))
|
if ((age == -1) || (age > maxAge))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox::StandardButton reply;
|
QMessageBox::StandardButton reply;
|
||||||
if (age == 0)
|
if (age == 0) {
|
||||||
reply = QMessageBox::question(parent, "Confirm download", "This file was last downloaded today. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No);
|
reply = QMessageBox::question(parent, "Confirm download", "This file was last downloaded today. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No);
|
||||||
else if (age == 1)
|
} else if (age == 1) {
|
||||||
reply = QMessageBox::question(parent, "Confirm download", "This file was last downloaded yesterday. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No);
|
reply = QMessageBox::question(parent, "Confirm download", "This file was last downloaded yesterday. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No);
|
||||||
else
|
} else {
|
||||||
reply = QMessageBox::question(parent, "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);
|
reply = QMessageBox::question(parent, "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;
|
return reply == QMessageBox::Yes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,8 +83,8 @@ bool HttpDownloadManagerGUI::confirmDownload(const QString& filename, QWidget *p
|
|||||||
void HttpDownloadManagerGUI::downloadCompleteGUI(const QString& filename, bool success)
|
void HttpDownloadManagerGUI::downloadCompleteGUI(const QString& filename, bool success)
|
||||||
{
|
{
|
||||||
(void) success;
|
(void) success;
|
||||||
int idx = m_filenames.indexOf(filename);
|
|
||||||
|
|
||||||
|
int idx = m_filenames.indexOf(filename);
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
{
|
{
|
||||||
QProgressDialog *progressDialog = m_progressDialogs[idx];
|
QProgressDialog *progressDialog = m_progressDialogs[idx];
|
||||||
@ -85,3 +97,22 @@ void HttpDownloadManagerGUI::downloadCompleteGUI(const QString& filename, bool s
|
|||||||
m_progressDialogs.remove(idx);
|
m_progressDialogs.remove(idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpDownloadManagerGUI::retryDownload(const QString &filename, QNetworkReply *oldReply, QNetworkReply *newReply)
|
||||||
|
{
|
||||||
|
int idx = m_filenames.indexOf(filename);
|
||||||
|
if (idx >= 0)
|
||||||
|
{
|
||||||
|
QProgressDialog *progressDialog = m_progressDialogs[idx];
|
||||||
|
if (progressDialog != nullptr)
|
||||||
|
{
|
||||||
|
connect(newReply, &QNetworkReply::downloadProgress, this, [progressDialog](qint64 bytesRead, qint64 totalBytes) {
|
||||||
|
if (progressDialog)
|
||||||
|
{
|
||||||
|
progressDialog->setMaximum(totalBytes);
|
||||||
|
progressDialog->setValue(bytesRead);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -40,6 +40,8 @@ private:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void downloadCompleteGUI(const QString &filename, bool success);
|
void downloadCompleteGUI(const QString &filename, bool success);
|
||||||
|
void retryDownload(const QString &filename, QNetworkReply *oldReply, QNetworkReply *newReply);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* INCLUDE_HTTPDOWNLOADMANAGERGUI_H */
|
#endif /* INCLUDE_HTTPDOWNLOADMANAGERGUI_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user