src/download.h

changeset 493
16766ac1bbd9
parent 455
c5d14d112034
child 504
6a1fa662bfc1
equal deleted inserted replaced
492:e964085e6913 493:16766ac1bbd9
32 class QNetworkReply; 32 class QNetworkReply;
33 class QAbstractButton; 33 class QAbstractButton;
34 34
35 // ============================================================================= 35 // =============================================================================
36 // ----------------------------------------------------------------------------- 36 // -----------------------------------------------------------------------------
37 class PartDownloader : public QDialog { 37 class PartDownloader : public QDialog
38 Q_OBJECT 38 { Q_OBJECT
39 PROPERTY (LDFile*, primaryFile, setPrimaryFile) 39 PROPERTY (LDFile*, primaryFile, setPrimaryFile)
40 PROPERTY (bool, aborted, setAborted) 40 PROPERTY (bool, aborted, setAborted)
41 41
42 public: 42 public:
43 constexpr static const char* k_OfficialURL = "http://ldraw.org/library/official/", 43 constexpr static const char* k_UnofficialURL = "http://ldraw.org/library/unofficial/";
44 *k_UnofficialURL = "http://ldraw.org/library/unofficial/"; 44
45 45 enum Source
46 enum Source { 46 { PartsTracker,
47 PartsTracker, 47 CustomURL,
48 CustomURL, 48 };
49 }; 49
50 50 enum Button
51 enum Button { 51 { Download,
52 Download, 52 Abort,
53 Abort, 53 Close
54 Close 54 };
55 }; 55
56 56 enum TableColumn
57 enum TableColumn { 57 { PartLabelColumn,
58 PartLabelColumn, 58 ProgressColumn,
59 ProgressColumn, 59 };
60 }; 60
61 61 explicit PartDownloader (QWidget* parent = null);
62 explicit PartDownloader (QWidget* parent = null); 62 virtual ~PartDownloader();
63 virtual ~PartDownloader(); 63 str getURL() const;
64 str getURL() const; 64 static str getDownloadPath();
65 static str getDownloadPath(); 65 Source getSource() const;
66 Source getSource() const; 66 void downloadFile (str dest, str url, bool primary);
67 void downloadFile (str dest, str url, bool primary); 67 void modifyDest (str& dest) const;
68 void modifyDest (str& dest) const; 68 QPushButton* getButton (Button i);
69 QPushButton* getButton (Button i); 69 static void k_download();
70 static void k_download(); 70
71 71 public slots:
72 public slots: 72 void sourceChanged (int i);
73 void sourceChanged (int i); 73 void checkIfFinished();
74 void checkIfFinished(); 74 void buttonClicked (QAbstractButton* btn);
75 void buttonClicked (QAbstractButton* btn); 75
76 76 protected:
77 protected: 77 Ui_DownloadFrom* ui;
78 Ui_DownloadFrom* ui; 78 friend class PartDownloadRequest;
79 friend class PartDownloadRequest; 79
80 80 private:
81 private: 81 List<str> m_filesToDownload;
82 List<str> m_filesToDownload; 82 List<PartDownloadRequest*> m_requests;
83 List<PartDownloadRequest*> m_requests; 83 QPushButton* m_downloadButton;
84 QPushButton* m_downloadButton;
85 }; 84 };
86 85
87 // ============================================================================= 86 // =============================================================================
88 // ----------------------------------------------------------------------------- 87 // -----------------------------------------------------------------------------
89 class PartDownloadRequest : public QObject { 88 class PartDownloadRequest : public QObject
90 Q_OBJECT 89 { Q_OBJECT
91 PROPERTY (int, tableRow, setTableRow) 90 PROPERTY (int, tableRow, setTableRow)
92 91
93 public: 92 public:
94 enum State { 93 enum State
95 Requesting, 94 { Requesting,
96 Downloading, 95 Downloading,
97 Finished, 96 Finished,
98 Failed, 97 Failed,
99 }; 98 };
100 99
101 explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent); 100 explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent);
102 PartDownloadRequest (const PartDownloadRequest&) = delete; 101 PartDownloadRequest (const PartDownloadRequest&) = delete;
103 virtual ~PartDownloadRequest(); 102 virtual ~PartDownloadRequest();
104 void updateToTable(); 103 void updateToTable();
105 bool isFinished() const; 104 bool isFinished() const;
106 const State& state() const; 105 const State& state() const;
107 106
108 void operator= (const PartDownloadRequest&) = delete; 107 void operator= (const PartDownloadRequest&) = delete;
109 108
110 public slots: 109 public slots:
111 void downloadFinished(); 110 void downloadFinished();
112 void readyRead(); 111 void readyRead();
113 void downloadProgress (qint64 recv, qint64 total); 112 void downloadProgress (qint64 recv, qint64 total);
114 void abort(); 113 void abort();
115 114
116 private: 115 private:
117 PartDownloader* m_prompt; 116 PartDownloader* m_prompt;
118 str m_url, m_dest, m_fpath; 117 str m_url, m_dest, m_fpath;
119 QNetworkAccessManager* m_nam; 118 QNetworkAccessManager* m_nam;
120 QNetworkReply* m_reply; 119 QNetworkReply* m_reply;
121 bool m_firstUpdate; 120 bool m_firstUpdate;
122 State m_state; 121 State m_state;
123 int64 m_bytesRead, m_bytesTotal; 122 int64 m_bytesRead, m_bytesTotal;
124 bool m_primary; 123 bool m_primary;
125 QFile* m_fp; 124 QFile* m_fp;
126 }; 125 };
127 126
128 #endif // LDFORGE_DOWNLOAD_H 127 #endif // LDFORGE_DOWNLOAD_H

mercurial