summaryrefslogblamecommitdiffstats
path: root/src/FileDownloader.h
blob: d64445f2d51d094f717309975fd4b3825be35761 (plain) (tree)


















                                     
 
       
 
                                                                      
 
                              
 
                        

        
 



                                                
                                                                       


              


                                                             


        



                                         



                              
/*
 * FileDownloader.h
 *
 *  Created on: Mar 7, 2014
 *      Author: nils
 */

#ifndef FILEDOWNLOADER_H_
#define FILEDOWNLOADER_H_

#include <QObject>
#include <QByteArray>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

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_ */