downloadfile.h 1.21 KB
/*
* @file doanlowdfile.h
* @author 袁爱玲
* @version 0.1
* @date 2014.1.26
* @details 下载资源
* @history
*/
#ifndef DOWNLOADFILE_H
#define DOWNLOADFILE_H

#include <QObject>
#include <QNetworkReply>
#include <QFile>


struct downFile{
    QUrl url;
    QString filename;
    int fid;
};

class IDownloadFile : public QObject
{
    Q_OBJECT
public:
    IDownloadFile();
    void cancelDownload();
    void downloadFile(QUrl url,QString filename,int fid);
    static IDownloadFile *Instance();
    void addDownloadFile(QUrl url,QString filename,int fid);

public slots:
    void httpReadyRead();
    void httpFinished();
    void errorReturn(QNetworkReply::NetworkError);
    void startDownload();

signals:
    void writeok(int);
    void downloadError(int);
    void startDownloadFile();
    void downloadFileEnd();

private:
    QUrl url;
    QNetworkAccessManager qnam;
    QNetworkReply *reply;
    QFile *file;
    int httpGetId;
    int fid;
    bool httpRequestAborted;
    QMap<int,QString> downfileMap;//下载的文件
public:
    QString filename;
    QString d_type;
    static IDownloadFile *m_downloadFile;
    int downloadNum;
    struct downFile downFileMsg[20];
    bool downloadFlag;
};

#endif // DOWNLOADFILE_H