Fix build issues

This commit is contained in:
Alex Spataru 2017-10-15 10:02:35 -05:00
parent 3642b4f5f3
commit a3e9ef2d1f
3 changed files with 39 additions and 21 deletions

View File

@ -56,8 +56,11 @@ Downloader::Downloader (QWidget* parent) : QWidget (parent)
m_startTime = 0;
m_useCustomProcedures = false;
/* Set download directory */
m_downloadDir = QDir::homePath() + "/Downloads/";
/* Make the window look like a modal dialog */
setWindowIcon (QIcon ());
setWindowIcon (QIcon());
setWindowFlags (Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
/* Configure the appearance and behavior of the buttons */
@ -112,9 +115,14 @@ void Downloader::startDownload (const QUrl& url)
m_ui->downloadLabel->setText (tr ("Downloading updates"));
m_ui->timeLabel->setText (tr ("Time remaining") + ": " + tr ("unknown"));
/* Configure the network request */
QNetworkRequest request (url);
if (!m_userAgentString.isEmpty())
request.setRawHeader ("User-Agent", m_userAgentString.toUtf8());
/* Start download */
m_reply = m_manager->get (request);
m_startTime = QDateTime::currentDateTime().toTime_t();
m_reply = m_manager->get (QNetworkRequest (url));
/* Ensure that downloads directory exists */
if (!m_downloadDir.exists())
@ -146,6 +154,29 @@ void Downloader::setFileName (const QString& file)
m_fileName = "QSU_Update.bin";
}
/**
* Changes the user-agent string used to communicate with the remote HTTP server
*/
void Downloader::setUserAgentString (const QString& agent)
{
m_userAgentString = agent;
}
void Downloader::finished()
{
/* Rename file */
QFile::rename (m_downloadDir.filePath (m_fileName + PARTIAL_DOWN),
m_downloadDir.filePath (m_fileName));
/* Notify application */
emit downloadFinished (m_url, m_downloadDir.filePath (m_fileName));
/* Install the update */
m_reply->close();
installUpdate();
setVisible (false);
}
/**
* Opens the downloaded file.
* \note If the downloaded file is not found, then the function will alert the
@ -155,7 +186,7 @@ void Downloader::openDownload()
{
if (!m_fileName.isEmpty())
QDesktopServices::openUrl (QUrl::fromLocalFile (m_downloadDir.filePath (
m_fileName)));
m_fileName)));
else {
QMessageBox::critical (this,
@ -243,7 +274,7 @@ void Downloader::saveFile (qint64 received, qint64 total)
/* Check if we need to redirect */
QUrl url = m_reply->attribute (
QNetworkRequest::RedirectionTargetAttribute).toUrl();
QNetworkRequest::RedirectionTargetAttribute).toUrl();
if (!url.isEmpty()) {
startDownload (url);
return;
@ -318,21 +349,6 @@ void Downloader::updateProgress (qint64 received, qint64 total)
}
}
void Downloader::finished()
{
/* Rename file */
QFile::rename (m_downloadDir.filePath (m_fileName + PARTIAL_DOWN),
m_downloadDir.filePath (m_fileName));
/* Notify application */
emit downloadFinished (m_url, m_downloadDir.filePath (m_fileName));
/* Install the update */
m_reply->close();
installUpdate();
setVisible(false);
}
/**
* Uses two time samples (from the current time and a previous sample) to
* calculate how many bytes have been downloaded.

View File

@ -65,28 +65,30 @@ public slots:
void setUrlId (const QString& url);
void startDownload (const QUrl& url);
void setFileName (const QString& file);
void setUserAgentString (const QString& agent);
void setUseCustomInstallProcedures (const bool custom);
private slots:
void finished();
void openDownload();
void installUpdate();
void cancelDownload();
void saveFile (qint64 received, qint64 total);
void calculateSizes (qint64 received, qint64 total);
void updateProgress (qint64 received, qint64 total);
void finished ();
void calculateTimeRemaining (qint64 received, qint64 total);
private:
qreal round (const qreal& input);
private:
QDir m_downloadDir;
QString m_url;
uint m_startTime;
QDir m_downloadDir;
QString m_fileName;
Ui::Downloader* m_ui;
QNetworkReply* m_reply;
QString m_userAgentString;
bool m_useCustomProcedures;
QNetworkAccessManager* m_manager;
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB