Basic Q3A patch downloading.

This commit is contained in:
Jonathan Young 2014-05-13 13:28:20 +10:00
parent 4c88912a0e
commit 8f22984ca1
6 changed files with 132 additions and 2 deletions

View file

@ -1,3 +1,4 @@
#include <QPushButton>
#include "installwizard.h"
#include "ui_installwizard.h"
#include "installwizard_installtype.h"
@ -11,7 +12,17 @@ InstallWizard::InstallWizard(QWidget *parent, Settings *settings) :
ui(new Ui::InstallWizard),
settings(settings)
{
setOptions(QWizard::NoCancelButton | QWizard::HaveCustomButton1);
cancelButton = new QPushButton("Cancel");
setButton(QWizard::CustomButton1, cancelButton);
QList<QWizard::WizardButton> layout;
layout << QWizard::BackButton << QWizard::CustomButton1 << QWizard::Stretch << QWizard::NextButton << QWizard::FinishButton;
setButtonLayout(layout);
ui->setupUi(this);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
setPage(Page_InstallType, new InstallWizard_InstallType(this));
#ifdef Q_OS_WIN32
@ -27,6 +38,16 @@ InstallWizard::~InstallWizard()
delete ui;
}
void InstallWizard::cancel()
{
if (currentId() == Page_Patch)
{
((InstallWizard_Patch *)currentPage())->cancel();
}
reject();
}
void InstallWizard::on_InstallWizard_customButtonClicked(int which)
{
if (which == QWizard::FinishButton)

View file

@ -7,6 +7,7 @@ namespace Ui {
class InstallWizard;
}
class QPushButton;
class Settings;
class InstallWizard : public QWizard
@ -26,10 +27,12 @@ public:
};
private slots:
void cancel();
void on_InstallWizard_customButtonClicked(int which);
private:
Ui::InstallWizard *ui;
QPushButton *cancelButton;
Settings *settings;
};

View file

@ -1,14 +1,82 @@
#include <QNetworkRequest>
#include <QNetworkReply>
#include "installwizard_patch.h"
#include "ui_installwizard_patch.h"
#include "installwizard.h"
InstallWizard_Patch::InstallWizard_Patch(QWidget *parent) :
QWizardPage(parent),
ui(new Ui::InstallWizard_Patch)
ui(new Ui::InstallWizard_Patch),
patchFile(NULL),
networkReply(NULL),
isCancelled(false),
isDownloadFinished(false)
{
ui->setupUi(this);
}
InstallWizard_Patch::~InstallWizard_Patch()
{
delete patchFile;
delete ui;
}
void InstallWizard_Patch::initializePage()
{
isCancelled = isDownloadFinished = false;
patchFile = new QTemporaryFile;
patchFile->open();
networkReply = nam.get(QNetworkRequest(QUrl("http://localhost:8080/linuxq3apoint-1.32b-3.x86.run")));
connect(networkReply, SIGNAL(readyRead()), this, SLOT(downloadRead()));
connect(networkReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
connect(networkReply, SIGNAL(finished()), this, SLOT(downloadFinished()));
}
void InstallWizard_Patch::cleanupPage()
{
cancel();
}
bool InstallWizard_Patch::isComplete() const
{
return isDownloadFinished;
}
void InstallWizard_Patch::cancel()
{
if (isCancelled)
return;
delete patchFile;
patchFile = NULL;
networkReply->abort();
isCancelled = true;
}
void InstallWizard_Patch::downloadRead()
{
patchFile->write(networkReply->readAll());
}
void InstallWizard_Patch::downloadProgress(qint64 bytesRead, qint64 bytesTotal)
{
ui->lblStatus->setText(QString("Downloading %1MB / %2MB").arg(bytesRead / 1024.0 / 1024.0, 0, 'f', 2).arg(bytesTotal / 1024.0 / 1024.0, 0, 'f', 2));
ui->pbProgress->setMaximum((int)bytesTotal);
ui->pbProgress->setValue((int)bytesRead);
}
void InstallWizard_Patch::downloadFinished()
{
Q_ASSERT(networkReply);
if (!isCancelled && networkReply->error())
{
ui->lblStatus->setText(networkReply->errorString());
}
networkReply->deleteLater();
isDownloadFinished = true;
emit completeChanged();
}

View file

@ -1,6 +1,8 @@
#ifndef INSTALLWIZARD_PATCH_H
#define INSTALLWIZARD_PATCH_H
#include <QNetworkAccessManager>
#include <QTemporaryFile>
#include <QWizardPage>
namespace Ui {
@ -14,9 +16,23 @@ class InstallWizard_Patch : public QWizardPage
public:
explicit InstallWizard_Patch(QWidget *parent = 0);
~InstallWizard_Patch();
virtual void initializePage();
virtual void cleanupPage();
virtual bool isComplete() const;
void cancel();
private slots:
void downloadRead();
void downloadProgress(qint64 bytesRead, qint64 bytesTotal);
void downloadFinished();
private:
Ui::InstallWizard_Patch *ui;
QTemporaryFile *patchFile;
QNetworkAccessManager nam;
QNetworkReply *networkReply;
bool isCancelled;
bool isDownloadFinished;
};
#endif // INSTALLWIZARD_PATCH_H

View file

@ -16,6 +16,28 @@
<property name="title">
<string>Installing Patch...</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lblStatus">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="pbProgress">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>

View file

@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets