Skip to content

Commit

Permalink
Updater: Handle failed download; support i18n for UI strings
Browse files Browse the repository at this point in the history
The progress status message will display the error message.
All strings in the Updater are now translated using QObject::tr() to
allow i18n in the future.
  • Loading branch information
skyjake committed May 28, 2012
1 parent d85f9bc commit 6b92eb1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
25 changes: 19 additions & 6 deletions doomsday/engine/portable/src/updater/downloaddialog.cpp
Expand Up @@ -35,16 +35,17 @@ struct DownloadDialog::Instance
bar->setRange(0, 100);

QDialogButtonBox* bbox = new QDialogButtonBox;
install = bbox->addButton("Install", QDialogButtonBox::AcceptRole);
install = bbox->addButton(tr("Install"), QDialogButtonBox::AcceptRole);
install->setEnabled(false);
QPushButton* cancel = bbox->addButton(QDialogButtonBox::Cancel);
QObject::connect(install, SIGNAL(clicked()), self, SLOT(accept()));
QObject::connect(cancel, SIGNAL(clicked()), self, SLOT(reject()));

mainLayout->addWidget(new QLabel(QString("Downloading update from <b>%1</b>...").arg(uri.host())));
mainLayout->addWidget(new QLabel(QString(tr("Downloading update from <b>%1</b>...")).arg(uri.host())));
mainLayout->addWidget(bar);

progText = new QLabel("<small>Connecting...</small>");
progText = new QLabel;
setProgressText(tr("Connecting..."));
mainLayout->addWidget(progText);

mainLayout->addWidget(bbox);
Expand All @@ -69,6 +70,11 @@ struct DownloadDialog::Instance

LOG_INFO("Downloading %s, saving as: %s") << uri.toString() << savedFilePath;
}

void setProgressText(de::String text)
{
progText->setText("<small>" + text + "</small>");
}
};

DownloadDialog::DownloadDialog(de::String downloadUri, QWidget *parent)
Expand All @@ -89,6 +95,13 @@ void DownloadDialog::finished(QNetworkReply* reply)
reply->deleteLater();
d->reply = 0;

if(reply->error() != QNetworkReply::NoError)
{
LOG_WARNING("Failure: ") << reply->errorString();
d->setProgressText(reply->errorString());
return;
}

/// @todo If/when we include WebKit, this can be done more intelligent using QWebPage. -jk

if(!d->redirected.isEmpty())
Expand Down Expand Up @@ -144,7 +157,7 @@ void DownloadDialog::finished(QNetworkReply* reply)
emit downloadFailed(d->uri.toString());
}

d->progText->setText("<small>Ready to install</small>");
d->setProgressText(tr("Ready to install"));
d->install->setEnabled(true);

LOG_DEBUG("Request finished.");
Expand All @@ -154,11 +167,11 @@ void DownloadDialog::progress(qint64 received, qint64 total)
{
LOG_AS("Download");

if(d->downloading)
if(d->downloading && total > 0)
{
d->bar->setValue(received * 100 / total);
const double MB = 1.0e6; // MiB would be 2^20
d->progText->setText(QString("<small>Received %1 MB out of total %2 MB</small>")
d->setProgressText(QString(tr("Received %1 MB out of total %2 MB"))
.arg(received/MB, 0, 'f', 1).arg(total/MB, 0, 'f', 1));
}
}
Expand Down
24 changes: 12 additions & 12 deletions doomsday/engine/portable/src/updater/updateavailabledialog.cpp
Expand Up @@ -36,50 +36,50 @@ struct UpdateAvailableDialog::Instance
if(! (latestVersion > currentVersion))
{
askUpgrade = true;
info->setText(QString("<span style=\"font-weight:bold; font-size:%1pt;\">"
"There is an update available.</span>"
"<p>The latest %2 release is %3, while you are "
"running %4.")
info->setText(QString("<span style=\"font-weight:bold; font-size:%1pt;\">" +
tr("There is an update available.") + "</span><p>" +
tr("The latest %2 release is %3, while you are running %4."))
.arg(bigFontSize)
.arg(channel)
.arg(latestVersion.asText())
.arg(currentVersion.asText()));
}
else
{
info->setText(QString("<span style=\"font-weight:bold; font-size:%1pt;\">You are up to date.</span>"
"<p>The installed %2 is the latest available %3 build.")
info->setText(QString("<span style=\"font-weight:bold; font-size:%1pt;\">" +
tr("You are up to date.") + "</span><p>" +
tr("The installed %2 is the latest available %3 build."))
.arg(bigFontSize)
.arg(currentVersion.asText())
.arg(channel));
}

neverCheck = new QCheckBox("N&ever check for updates automatically");
neverCheck = new QCheckBox(tr("N&ever check for updates automatically"));
neverCheck->setChecked(UpdaterSettings().onlyCheckManually());
QObject::connect(neverCheck, SIGNAL(toggled(bool)), self, SLOT(neverCheckToggled(bool)));

QDialogButtonBox* bbox = new QDialogButtonBox;

if(!askUpgrade)
{
QPushButton* ok = bbox->addButton("&Close", QDialogButtonBox::AcceptRole);
QPushButton* ok = bbox->addButton(tr("&Close"), QDialogButtonBox::AcceptRole);
QObject::connect(ok, SIGNAL(clicked()), self, SLOT(reject()));
}
else
{
QPushButton* yes = bbox->addButton("&Download and install", QDialogButtonBox::YesRole);
QPushButton* no = bbox->addButton("&Not now", QDialogButtonBox::NoRole);
QPushButton* yes = bbox->addButton(tr("&Download and install"), QDialogButtonBox::YesRole);
QPushButton* no = bbox->addButton(tr("&Not now"), QDialogButtonBox::NoRole);
QObject::connect(yes, SIGNAL(clicked()), self, SLOT(accept()));
QObject::connect(no, SIGNAL(clicked()), self, SLOT(reject()));
}

QPushButton* cfg = bbox->addButton("&Settings...", QDialogButtonBox::ActionRole);
QPushButton* cfg = bbox->addButton(tr("&Settings..."), QDialogButtonBox::ActionRole);
QObject::connect(cfg, SIGNAL(clicked()), self, SLOT(editSettings()));
cfg->setAutoDefault(false);

if(askUpgrade)
{
QPushButton* whatsNew = bbox->addButton("&What's new?", QDialogButtonBox::HelpRole);
QPushButton* whatsNew = bbox->addButton(tr("&What's new?"), QDialogButtonBox::HelpRole);
QObject::connect(whatsNew, SIGNAL(clicked()), self, SLOT(showWhatsNew()));
whatsNew->setAutoDefault(false);
}
Expand Down
26 changes: 13 additions & 13 deletions doomsday/engine/portable/src/updater/updatersettingsdialog.cpp
Expand Up @@ -27,28 +27,28 @@ struct UpdaterSettingsDialog::Instance
QFormLayout* form = new QFormLayout;
mainLayout->addLayout(form);

neverCheck = new QCheckBox("Never check for updates automatically");
neverCheck = new QCheckBox(tr("Never check for updates automatically"));
form->addRow(neverCheck);

freqList = new QComboBox;
freqList->addItem("Daily", UpdaterSettings::Daily);
freqList->addItem("Biweekly", UpdaterSettings::Biweekly);
freqList->addItem("Weekly", UpdaterSettings::Weekly);
freqList->addItem("Monthly", UpdaterSettings::Monthly);
form->addRow("Check for updates:", freqList);
freqList->addItem(tr("Daily"), UpdaterSettings::Daily);
freqList->addItem(tr("Biweekly"), UpdaterSettings::Biweekly);
freqList->addItem(tr("Weekly"), UpdaterSettings::Weekly);
freqList->addItem(tr("Monthly"), UpdaterSettings::Monthly);
form->addRow(tr("Check for updates:"), freqList);

channelList = new QComboBox;
channelList->addItem("Stable", UpdaterSettings::Stable);
channelList->addItem("Unstable/Candidate", UpdaterSettings::Unstable);
form->addRow("Release type:", channelList);
channelList->addItem(tr("Stable"), UpdaterSettings::Stable);
channelList->addItem(tr("Unstable/Candidate"), UpdaterSettings::Unstable);
form->addRow(tr("Release type:"), channelList);

pathList = new QComboBox;
pathList->addItem(QDesktopServices::displayName(QDesktopServices::TempLocation),
UpdaterSettings::defaultDownloadPath());
pathList->addItem("Select folder...", "");
form->addRow("Download location:", pathList);
pathList->addItem(tr("Select folder..."), "");
form->addRow(tr("Download location:"), pathList);

deleteAfter = new QCheckBox("Delete file after install");
deleteAfter = new QCheckBox(tr("Delete file after install"));
form->addRow(new QWidget, deleteAfter);

QDialogButtonBox* bbox = new QDialogButtonBox;
Expand Down Expand Up @@ -141,7 +141,7 @@ void UpdaterSettingsDialog::pathActivated(int index)
QString path = d->pathList->itemData(index).toString();
if(path.isEmpty())
{
QString dir = QFileDialog::getExistingDirectory(this, "Download Folder", QDir::homePath());
QString dir = QFileDialog::getExistingDirectory(this, tr("Download Folder"), QDir::homePath());
if(!dir.isEmpty())
{
d->setDownloadPath(dir);
Expand Down

0 comments on commit 6b92eb1

Please sign in to comment.