More UI changes

This commit is contained in:
Alex Spataru 2014-11-08 20:36:47 -06:00
parent bbe47f426a
commit 07fb53334f
2 changed files with 18 additions and 27 deletions

View File

@ -15,11 +15,9 @@ DownloadDialog::DownloadDialog(QWidget *parent) :
{
// Setup the UI
ui->setupUi(this);
ui->installButton->setEnabled(false);
// Connect SIGNALS/SLOTS
connect(ui->installButton, SIGNAL(clicked()), this, SLOT(openDownload()));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancelDownload()));
connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(cancelDownload()));
// Initialize the network access manager
m_manager = new QNetworkAccessManager(this);
@ -40,8 +38,7 @@ void DownloadDialog::beginDownload(const QUrl &url)
// Reset the UI
ui->progressBar->setValue(0);
ui->installButton->setEnabled(false);
ui->cancelButton->setText(tr("Cancel"));
ui->stopButton->setText(tr("Stop"));
ui->downloadLabel->setText(tr("Downloading updates"));
ui->timeLabel->setText(tr("Time remaining") + ": " + tr("unknown"));
@ -65,13 +62,11 @@ void DownloadDialog::openDownload()
if (!m_path.isEmpty()) {
QString url = m_path;
// Build a correct URL to open local files
if (url.startsWith("/"))
url = "file://" + url;
else
url = "file:///" + url;
// Let the system open the downloaded file
QDesktopServices::openUrl(url);
}
@ -82,29 +77,31 @@ void DownloadDialog::openDownload()
void DownloadDialog::cancelDownload()
{
QMessageBox _message;
_message.setWindowTitle(tr("Updater"));
_message.setIcon(QMessageBox::Question);
_message.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
_message.setText(tr("Are you sure you want to cancel the download?"));
if (!m_reply->isFinished()) {
QMessageBox _message;
_message.setWindowTitle(tr("Updater"));
_message.setIcon(QMessageBox::Question);
_message.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
_message.setText(tr("Are you sure you want to cancel the download?"));
if (_message.exec() == QMessageBox::Yes) {
if (_message.exec() == QMessageBox::Yes) {
hide();
m_reply->abort();
}
} else {
hide();
m_reply->abort();
}
}
void DownloadDialog::downloadFinished()
{
ui->timeLabel->setText(NULL);
ui->installButton->setEnabled(true);
ui->cancelButton->setText(tr("Close"));
ui->stopButton->setText(tr("Close"));
ui->downloadLabel->setText(tr("Download complete!"));
ui->timeLabel->setText(tr("The installer will open in a separate window..."));
QByteArray data = m_reply->readAll();
if (!data.isEmpty()) {
// Create a QFile with the name of the downloaded file
QStringList list = m_reply->url().toString().split("/");
QFile file(QDir::tempPath() + "/" + list.at(list.count() - 1));
@ -118,6 +115,7 @@ void DownloadDialog::downloadFinished()
}
file.close();
openDownload();
}
else {

View File

@ -160,16 +160,9 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<widget class="QPushButton" name="stopButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="installButton">
<property name="text">
<string>Install</string>
<string>Stop</string>
</property>
</widget>
</item>