OpenTX 2.0 downloads from Companion should be working now

This commit is contained in:
bsongis
2014-05-20 14:53:59 +02:00
parent a178d6b326
commit 73faca60d7
11 changed files with 118 additions and 138 deletions
+34 -36
View File
@@ -5,43 +5,41 @@
#include <QTime>
#include "helpers.h"
downloadDialog::downloadDialog(QWidget *parent, QString src, QString tgt) :
QDialog(parent),
ui(new Ui::downloadDialog)
downloadDialog::downloadDialog(QWidget *parent, QString src, QString tgt):
QDialog(parent),
ui(new Ui::downloadDialog),
file(NULL)
{
ui->setupUi(this);
this->setWindowIcon(CompanionIcon("fwpreferences.png"));
setWindowIcon(CompanionIcon("fwpreferences.png"));
ui->progressBar->setValue(1);
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(0);
if(tgt.isEmpty())
{
setWindowTitle(src);
return; // just show wait dialog.
if (tgt.isEmpty()) {
setWindowTitle(src);
return; // just show wait dialog.
}
file = new QFile(tgt);
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::critical(this, "Companion",
tr("Unable to save the file %1: %2.")
.arg(tgt).arg(file->errorString()));
QTimer::singleShot(0, this, SLOT(fileError()));
} else {
reply = qnam.get(QNetworkRequest(QUrl(src)));
connect(reply, SIGNAL(finished()),
this, SLOT(httpFinished()));
connect(reply, SIGNAL(readyRead()),
this, SLOT(httpReadyRead()));
connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(updateDataReadProgress(qint64,qint64)));
QMessageBox::critical(this, "Companion",
tr("Unable to save the file %1: %2.")
.arg(tgt).arg(file->errorString()));
QTimer::singleShot(0, this, SLOT(fileError()));
}
else {
reply = qnam.get(QNetworkRequest(QUrl(src)));
connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDataReadProgress(qint64,qint64)));
}
}
downloadDialog::~downloadDialog()
{
delete ui;
delete ui;
delete file;
}
void downloadDialog::httpFinished()
@@ -50,8 +48,7 @@ void downloadDialog::httpFinished()
file->close();
bool ok = true;
if (reply->error())
{
if (reply->error()) {
file->remove();
QMessageBox::information(this, tr("Companion"),
tr("Download failed: %1.")
@@ -62,31 +59,32 @@ void downloadDialog::httpFinished()
reply->deleteLater();
reply = 0;
delete file;
file = 0;
file = NULL;
if(ok)
accept();
if (ok)
accept();
else
reject();
reject();
}
void downloadDialog::httpReadyRead()
{
if (file)
file->write(reply->readAll());
if (file) {
file->write(reply->readAll());
}
}
void downloadDialog::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
{
ui->progressBar->setMaximum(totalBytes);
ui->progressBar->setValue(bytesRead);
ui->progressBar->setMaximum(totalBytes);
ui->progressBar->setValue(bytesRead);
}
void downloadDialog::fileError()
{
delete file;
file = 0;
reject();
delete file;
file = NULL;
reject();
}
void downloadDialog::closeEvent( QCloseEvent * event)