src/partDownloader.h

changeset 993
23436e487f0c
parent 992
5a10b4e7bf4a
equal deleted inserted replaced
992:5a10b4e7bf4a 993:23436e487f0c
29 class QNetworkAccessManager; 29 class QNetworkAccessManager;
30 class QNetworkRequest; 30 class QNetworkRequest;
31 class QNetworkReply; 31 class QNetworkReply;
32 class QAbstractButton; 32 class QAbstractButton;
33 33
34 // =============================================================================
35 //
36 class PartDownloader : public QDialog, public HierarchyElement 34 class PartDownloader : public QDialog, public HierarchyElement
37 { 35 {
36 Q_OBJECT
37
38 public: 38 public:
39 enum Source 39 enum SourceType
40 { 40 {
41 PartsTracker, 41 PartsTracker,
42 CustomURL, 42 CustomURL,
43 }; 43 };
44 44
55 ProgressColumn, 55 ProgressColumn,
56 }; 56 };
57 57
58 using RequestList = QList<PartDownloadRequest*>; 58 using RequestList = QList<PartDownloadRequest*>;
59 59
60 Q_OBJECT 60 explicit PartDownloader (QWidget* parent = nullptr);
61 PROPERTY (public, LDDocument*, primaryFile, setPrimaryFile, STOCK_WRITE) 61 virtual ~PartDownloader();
62 PROPERTY (public, bool, isAborted, setAborted, STOCK_WRITE)
63 PROPERTY (private, Ui_DownloadFrom*, form, setForm, STOCK_WRITE)
64 PROPERTY (private, QStringList, filesToDownload, setFilesToDownload, STOCK_WRITE)
65 PROPERTY (private, RequestList, requests, setRequests, STOCK_WRITE)
66 PROPERTY (private, QPushButton*, downloadButton, setDownloadButton, STOCK_WRITE)
67 62
68 public: 63 void addFile (LDDocument* f);
69 explicit PartDownloader (QWidget* parent = nullptr); 64 QPushButton* button (Button i);
70 virtual ~PartDownloader(); 65 Q_SLOT void buttonClicked (QAbstractButton* btn);
66 Q_SLOT void checkIfFinished();
67 void checkValidPath();
68 void downloadFile (QString dest, QString url, bool primary);
69 void downloadFromPartsTracker (QString file);
70 QString downloadPath();
71 bool isAborted() const;
72 void modifyDestination (QString& dest) const;
73 LDDocument* primaryFile() const;
74 class QTableWidget* progressTable() const;
75 void setPrimaryFile (LDDocument* document);
76 void setSourceType (SourceType src);
77 Q_SLOT void sourceChanged (int i);
78 SourceType sourceType() const;
79 QString url();
71 80
72 void addFile (LDDocument* f); 81 signals:
73 bool checkValidPath(); 82 void primaryFileDownloaded();
74 void downloadFile (QString dest, QString url, bool primary);
75 void downloadFromPartsTracker (QString file);
76 QPushButton* getButton (Button i);
77 QString getURL();
78 Source getSource() const;
79 void setSource (Source src);
80 void modifyDestination (QString& dest) const;
81
82 QString getDownloadPath();
83 static void staticBegin();
84
85 public slots:
86 void buttonClicked (QAbstractButton* btn);
87 void checkIfFinished();
88 void sourceChanged (int i);
89 83
90 private: 84 private:
91 Source m_source; 85 class Ui_DownloadFrom& ui;
86 QStringList m_filesToDownload;
87 RequestList m_requests;
88 QPushButton* m_downloadButton;
89 SourceType m_source;
92 QList<LDDocument*> m_files; 90 QList<LDDocument*> m_files;
91 LDDocument* m_primaryFile;
92 bool m_isAborted;
93 }; 93 };
94 94
95 class PartDownloadRequest : public QObject 95 class PartDownloadRequest : public QObject
96 { 96 {
97 Q_OBJECT 97 Q_OBJECT
106 }; 106 };
107 107
108 explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent); 108 explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent);
109 virtual ~PartDownloadRequest(); 109 virtual ~PartDownloadRequest();
110 110
111 Q_SLOT void abort();
111 QString destination() const; 112 QString destination() const;
113 Q_SLOT void downloadFinished();
112 bool failed() const; 114 bool failed() const;
113 QString filePath() const; 115 QString filePath() const;
114 bool isFinished() const; 116 bool isFinished() const;
115 bool isFirstUpdate() const; 117 bool isFirstUpdate() const;
116 bool isPrimary() const; 118 bool isPrimary() const;
117 QNetworkReply* networkReply() const; 119 QNetworkReply* networkReply() const;
118 qint64 numBytesRead() const; 120 qint64 numBytesRead() const;
119 qint64 numBytesTotal() const; 121 qint64 numBytesTotal() const;
120 PartDownloader* prompt() const; 122 PartDownloader* prompt() const;
123 Q_SLOT void readFromNetworkReply();
121 void setTableRow (int value); 124 void setTableRow (int value);
122 int tableRow() const; 125 int tableRow() const;
126 Q_SLOT void updateDownloadProgress (qint64 recv, qint64 total);
123 void updateToTable(); 127 void updateToTable();
124 QString url() const; 128 QString url() const;
125
126 public slots:
127 void abort();
128 void downloadFinished();
129 void downloadProgress (qint64 recv, qint64 total);
130 void readyRead();
131 129
132 private: 130 private:
133 int m_tableRow; 131 int m_tableRow;
134 State m_state; 132 State m_state;
135 PartDownloader* m_prompt; 133 PartDownloader* m_prompt;

mercurial