Skip to content

Commit

Permalink
Updater: Querying the path of the downloaded file
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 29, 2012
1 parent 7b447b8 commit 927846a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 15 additions & 6 deletions doomsday/engine/portable/src/updater/downloaddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ struct DownloadDialog::Instance
QLabel* progText;
QUrl uri;
de::String savedFilePath;
bool fileReady;
QNetworkReply* reply;
de::String redirected;

Instance(DownloadDialog* d, de::String downloadUri) : self(d), downloading(false), uri(downloadUri), reply(0)
Instance(DownloadDialog* d, de::String downloadUri)
: self(d), downloading(false), uri(downloadUri), fileReady(false), reply(0)
{
QVBoxLayout* mainLayout = new QVBoxLayout;
self->setLayout(mainLayout);
Expand Down Expand Up @@ -61,13 +63,13 @@ struct DownloadDialog::Instance
downloading = true;
redirected.clear();

de::String path = uri.path();
savedFilePath = UpdaterSettings().downloadPath() / path.fileName();

reply = network->get(QNetworkRequest(uri));
QObject::connect(reply, SIGNAL(metaDataChanged()), self, SLOT(replyMetaDataChanged()));
QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)), self, SLOT(progress(qint64,qint64)));

de::String path = uri.path();
savedFilePath = UpdaterSettings().downloadPath() / path.fileName();

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

Expand All @@ -88,6 +90,12 @@ DownloadDialog::~DownloadDialog()
delete d;
}

de::String DownloadDialog::downloadedFilePath() const
{
if(!d->fileReady) return "";
return d->savedFilePath;
}

void DownloadDialog::finished(QNetworkReply* reply)
{
LOG_AS("Download");
Expand All @@ -102,7 +110,7 @@ void DownloadDialog::finished(QNetworkReply* reply)
return;
}

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

if(!d->redirected.isEmpty())
{
Expand Down Expand Up @@ -132,7 +140,7 @@ void DownloadDialog::finished(QNetworkReply* reply)
emit downloadFailed(d->uri.toString());
return;
}
start += 5;
start += 5; // skip: url="
QString equivRefresh = html.mid(start, html.indexOf("\"", start) - start);
equivRefresh.replace("&amp;", "&");

Expand All @@ -157,6 +165,7 @@ void DownloadDialog::finished(QNetworkReply* reply)
emit downloadFailed(d->uri.toString());
}

d->fileReady = true;
d->setProgressText(tr("Ready to install"));
d->install->setEnabled(true);

Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/src/updater/downloaddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class DownloadDialog : public QDialog
public:
explicit DownloadDialog(de::String downloadUri, QWidget *parent = 0);
~DownloadDialog();

/**
* Returns the path of the downloaded file.
*
* @return Path, or an empty string if the download did not finish
* successfully.
*/
de::String downloadedFilePath() const;

signals:
void downloadFailed(QString uri);
Expand Down

0 comments on commit 927846a

Please sign in to comment.