Tianchi  v0.0.2 build 20130701
C++ library for Qt with VC & mingW
tcdownloadhttp.h
1 // **************************************************************************
2 // Tianchi C++ library for Qt (open source)
3 // 天池共享源码库
4 // 版权所有 (C) 天池共享源码库开发组
5 // 授权协议:请阅读天池共享源码库附带的授权协议
6 // **************************************************************************
7 // 文档说明:HTTP 文件多线程下载器
8 // ==========================================================================
9 // 开发日志:
10 // 日期 人员 说明
11 // --------------------------------------------------------------------------
12 // 2013.04.19 圣域天子 建立
13 //
14 // ==========================================================================
16 #ifndef TIANCHI_TCDOWNLOADHTTP_H
17 #define TIANCHI_TCDOWNLOADHTTP_H
18 
19 #include <tianchi/tcglobal.h>
20 #include <QtCore>
21 #include <QtNetwork>
22 
27 class TIANCHI_API TcDownload : public QObject
28 {
29  Q_OBJECT
30 public:
31  TcDownload(int index, QObject *parent = 0);
32  void StartDownload(const QUrl &url, QFile* file,
33  qint64 startPoint=0, qint64 endPoint=-1);
34 
35 Q_SIGNALS:
36  void DownloadFinished();
37 
38 public Q_SLOTS:
39  void FinishedSlot();
40  void HttpReadyRead();
41 
42 private:
43  QNetworkAccessManager m_Qnam;
44  QNetworkReply* m_Reply;
45  QFile* m_File;
46 
47  const int m_Index;
48  qint64 m_HaveDoneBytes;
49  qint64 m_StartPoint;
50  qint64 m_EndPoint;
51 
52 };
53 
54 // 用于管理文件的下载
56 class TIANCHI_API TcDownloadList : public QObject
57 {
58  Q_OBJECT
59 public:
60  TcDownloadList(QObject *parent = 0);
61 
62  void StartFileDownload(const QString &url, int count);
63  qint64 GetFileSize(QUrl url);
64 
65 Q_SIGNALS:
66  void FileDownloadFinished();
67 
68 private Q_SLOTS:
69  void SubPartFinished();
70 
71 private:
72  int m_DownloadCount;
73  int m_FinishedNum;
74  int m_FileSize;
75  QUrl m_Url;
76  QFile *m_File;
77 };
78 
79 #endif // TIANCHI_DOWNLOADHTTP_H