From 4fb6c46f7aebe0754647c142bb653185f8139907 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 15 Jun 2018 10:56:20 +0200 Subject: fileDownloader.* -> filedownloader.* --- src/fileDownloader.cpp | 73 ---------------------------------------------- src/fileDownloader.h | 52 --------------------------------- src/filedownloader.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++ src/filedownloader.h | 52 +++++++++++++++++++++++++++++++++ src/sessionsiconholder.cpp | 2 +- src/sessionsiconholder.h | 2 +- 6 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 src/fileDownloader.cpp delete mode 100644 src/fileDownloader.h create mode 100644 src/filedownloader.cpp create mode 100644 src/filedownloader.h diff --git a/src/fileDownloader.cpp b/src/fileDownloader.cpp deleted file mode 100644 index dc53356..0000000 --- a/src/fileDownloader.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * fileDownloader.cpp - * - * Created on: Mar 7, 2014 - * Author: nils - */ - -#include - -#include "fileDownloader.h" - -// Maximum size of download -#define MAXSIZE (200000) - -static QNetworkAccessManager m_WebCtrl; - -FileDownloader::FileDownloader(const QUrl& fileUrl, QObject *parent) : - QObject(parent), started(false), url(fileUrl) { -} - -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; -} - -/* - * Slots from networkreply - */ - -void FileDownloader::downloadFailed(QNetworkReply::NetworkError) { - 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); -} - -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()); - } -} - -void FileDownloader::killReply(QNetworkReply *reply) { - if (reply == NULL) - return; - reply->blockSignals(true); - reply->abort(); - reply->deleteLater(); -} diff --git a/src/fileDownloader.h b/src/fileDownloader.h deleted file mode 100644 index 621f2b7..0000000 --- a/src/fileDownloader.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * fileDownloader.h - * - * Created on: Mar 7, 2014 - * Author: nils - */ - -#ifndef FILEDOWNLOADER_H_ -#define FILEDOWNLOADER_H_ - -#include -#include -#include -#include -#include - -class FileDownloader : public QObject -{ - Q_OBJECT - -public: - - explicit FileDownloader(const QUrl& fileUrl, QObject *parent = 0); - - virtual ~FileDownloader(); - - bool downloadFile(); - -signals: - - /** - * Triggered when the download has finished. - * On error, downloadedData will be empty. - */ - void downloaded(const QUrl& url, const QByteArray& downloadedData); - -private slots: - - void fileDownloaded(); - void downloadFailed(QNetworkReply::NetworkError code); - void downloadProgress(qint64 received, qint64 totalSize); - -private: - - void killReply(QNetworkReply *reply); - - bool started; - QUrl url; - -}; - -#endif /* FILEDOWNLOADER_H_ */ diff --git a/src/filedownloader.cpp b/src/filedownloader.cpp new file mode 100644 index 0000000..0af2544 --- /dev/null +++ b/src/filedownloader.cpp @@ -0,0 +1,73 @@ +/* + * filedownloader.cpp + * + * Created on: Mar 7, 2014 + * Author: nils + */ + +#include + +#include "filedownloader.h" + +// Maximum size of download +#define MAXSIZE (200000) + +static QNetworkAccessManager m_WebCtrl; + +FileDownloader::FileDownloader(const QUrl& fileUrl, QObject *parent) : + QObject(parent), started(false), url(fileUrl) { +} + +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; +} + +/* + * Slots from networkreply + */ + +void FileDownloader::downloadFailed(QNetworkReply::NetworkError) { + 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); +} + +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()); + } +} + +void FileDownloader::killReply(QNetworkReply *reply) { + if (reply == NULL) + return; + reply->blockSignals(true); + reply->abort(); + reply->deleteLater(); +} diff --git a/src/filedownloader.h b/src/filedownloader.h new file mode 100644 index 0000000..2de29ad --- /dev/null +++ b/src/filedownloader.h @@ -0,0 +1,52 @@ +/* + * filedownloader.h + * + * Created on: Mar 7, 2014 + * Author: nils + */ + +#ifndef FILEDOWNLOADER_H_ +#define FILEDOWNLOADER_H_ + +#include +#include +#include +#include +#include + +class FileDownloader : public QObject +{ + Q_OBJECT + +public: + + explicit FileDownloader(const QUrl& fileUrl, QObject *parent = 0); + + virtual ~FileDownloader(); + + bool downloadFile(); + +signals: + + /** + * Triggered when the download has finished. + * On error, downloadedData will be empty. + */ + void downloaded(const QUrl& url, const QByteArray& downloadedData); + +private slots: + + void fileDownloaded(); + void downloadFailed(QNetworkReply::NetworkError code); + void downloadProgress(qint64 received, qint64 totalSize); + +private: + + void killReply(QNetworkReply *reply); + + bool started; + QUrl url; + +}; + +#endif /* FILEDOWNLOADER_H_ */ diff --git a/src/sessionsiconholder.cpp b/src/sessionsiconholder.cpp index 492fe2d..61616ad 100644 --- a/src/sessionsiconholder.cpp +++ b/src/sessionsiconholder.cpp @@ -17,7 +17,7 @@ #include "globals.h" #include "sessionsiconholder.h" #include "sessiontreemodel.h" -#include "fileDownloader.h" +#include "filedownloader.h" SessionsIconHolder* SessionsIconHolder::instance = NULL; diff --git a/src/sessionsiconholder.h b/src/sessionsiconholder.h index a389534..3284bf7 100644 --- a/src/sessionsiconholder.h +++ b/src/sessionsiconholder.h @@ -17,7 +17,7 @@ #include "globals.h" #include "sessionsiconholder.h" -#include "fileDownloader.h" +#include "filedownloader.h" class SessionTreeModel; -- cgit v1.2.3-55-g7522