diff options
author | Simon Rettberg | 2018-06-15 14:05:25 +0200 |
---|---|---|
committer | Simon Rettberg | 2018-06-15 14:05:25 +0200 |
commit | ba3c5aa40274c11f9cefd4e9842be3488cad07b4 (patch) | |
tree | 2865703ae78ed397f24fa32fca642332ac7b3a49 /src/filedownloader.cpp | |
parent | fileDownloader.* -> filedownloader.* (diff) | |
download | vmchooser2-ba3c5aa40274c11f9cefd4e9842be3488cad07b4.tar.gz vmchooser2-ba3c5aa40274c11f9cefd4e9842be3488cad07b4.tar.xz vmchooser2-ba3c5aa40274c11f9cefd4e9842be3488cad07b4.zip |
Fix indentation, cleanup, refactoring, deletions
* Remove unused methods for adding hostname and user to xml
* Avoid copying/(de)serializing XML a thousand times
* Fix Session::isValid() or rather make it a bit more usable
(although it's unused currently)
* baseDir is global, not per VSession, which doesn't make any
sense without the legacy approach of recusively loading
one xml file per entry
Diffstat (limited to 'src/filedownloader.cpp')
-rw-r--r-- | src/filedownloader.cpp | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/filedownloader.cpp b/src/filedownloader.cpp index 0af2544..7e2574b 100644 --- a/src/filedownloader.cpp +++ b/src/filedownloader.cpp @@ -15,7 +15,7 @@ static QNetworkAccessManager m_WebCtrl; FileDownloader::FileDownloader(const QUrl& fileUrl, QObject *parent) : - QObject(parent), started(false), url(fileUrl) { + QObject(parent), started(false), url(fileUrl) { } FileDownloader::~FileDownloader() { @@ -23,15 +23,15 @@ FileDownloader::~FileDownloader() { } bool FileDownloader::downloadFile() { - if (this->started) - return true; - QNetworkReply *reply = m_WebCtrl.get(QNetworkRequest(this->url)); - if (reply == NULL) - return false; - this->started = true; - connect(reply, SIGNAL(finished()), SLOT(fileDownloaded())); - connect(reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); - return true; + if (this->started) + return true; + QNetworkReply *reply = m_WebCtrl.get(QNetworkRequest(this->url)); + if (reply == NULL) + return false; + this->started = true; + connect(reply, SIGNAL(finished()), SLOT(fileDownloaded())); + connect(reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); + return true; } /* @@ -39,35 +39,35 @@ bool FileDownloader::downloadFile() { */ void FileDownloader::downloadFailed(QNetworkReply::NetworkError) { - QNetworkReply *reply = (QNetworkReply*)this->sender(); - killReply(reply); - emit downloaded(this->url, QByteArray()); + QNetworkReply *reply = (QNetworkReply*)this->sender(); + killReply(reply); + emit downloaded(this->url, QByteArray()); } void FileDownloader::fileDownloaded() { - QNetworkReply *reply = (QNetworkReply*)this->sender(); - if (reply == NULL) - return; - QByteArray downloadedData(reply->readAll()); - killReply(reply); - //emit a signal - emit downloaded(this->url, downloadedData); + QNetworkReply *reply = (QNetworkReply*)this->sender(); + if (reply == NULL) + return; + QByteArray downloadedData(reply->readAll()); + killReply(reply); + //emit a signal + emit downloaded(this->url, downloadedData); } void FileDownloader::downloadProgress(qint64 received, qint64 totalSize) { - QNetworkReply *reply = (QNetworkReply*)this->sender(); - if (reply == NULL) - return; - if (received > MAXSIZE || totalSize > MAXSIZE) { - killReply(reply); - emit downloaded(this->url, QByteArray()); - } + QNetworkReply *reply = (QNetworkReply*)this->sender(); + if (reply == NULL) + return; + if (received > MAXSIZE || totalSize > MAXSIZE) { + killReply(reply); + emit downloaded(this->url, QByteArray()); + } } void FileDownloader::killReply(QNetworkReply *reply) { - if (reply == NULL) - return; - reply->blockSignals(true); - reply->abort(); - reply->deleteLater(); + if (reply == NULL) + return; + reply->blockSignals(true); + reply->abort(); + reply->deleteLater(); } |