69 |
69 |
70 // ============================================================================= |
70 // ============================================================================= |
71 // |
71 // |
72 PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent) |
72 PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent) |
73 { |
73 { |
74 setInterface (new Ui_DownloadFrom); |
74 setForm (new Ui_DownloadFrom); |
75 interface()->setupUi (this); |
75 form()->setupUi (this); |
76 interface()->fname->setFocus(); |
76 form()->fname->setFocus(); |
77 interface()->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch); |
77 |
|
78 #ifdef USE_QT5 |
|
79 form()->progress->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch); |
|
80 #else |
|
81 form()->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch); |
|
82 #endif |
78 |
83 |
79 setDownloadButton (new QPushButton (tr ("Download"))); |
84 setDownloadButton (new QPushButton (tr ("Download"))); |
80 interface()->buttonBox->addButton (downloadButton(), QDialogButtonBox::ActionRole); |
85 form()->buttonBox->addButton (downloadButton(), QDialogButtonBox::ActionRole); |
81 getButton (Abort)->setEnabled (false); |
86 getButton (Abort)->setEnabled (false); |
82 |
87 |
83 connect (interface()->source, SIGNAL (currentIndexChanged (int)), |
88 connect (form()->source, SIGNAL (currentIndexChanged (int)), |
84 this, SLOT (sourceChanged (int))); |
89 this, SLOT (sourceChanged (int))); |
85 connect (interface()->buttonBox, SIGNAL (clicked (QAbstractButton*)), |
90 connect (form()->buttonBox, SIGNAL (clicked (QAbstractButton*)), |
86 this, SLOT (buttonClicked (QAbstractButton*))); |
91 this, SLOT (buttonClicked (QAbstractButton*))); |
87 } |
92 } |
88 |
93 |
89 // ============================================================================= |
94 // ============================================================================= |
90 // |
95 // |
91 PartDownloader::~PartDownloader() |
96 PartDownloader::~PartDownloader() |
92 { |
97 { |
93 delete interface(); |
98 delete form(); |
94 } |
99 } |
95 |
100 |
96 // ============================================================================= |
101 // ============================================================================= |
97 // |
102 // |
98 QString PartDownloader::getURL() |
103 QString PartDownloader::getURL() |
181 |
186 |
182 // ============================================================================= |
187 // ============================================================================= |
183 // |
188 // |
184 PartDownloader::Source PartDownloader::getSource() const |
189 PartDownloader::Source PartDownloader::getSource() const |
185 { |
190 { |
186 return (Source) interface()->source->currentIndex(); |
191 return (Source) form()->source->currentIndex(); |
187 } |
192 } |
188 |
193 |
189 // ============================================================================= |
194 // ============================================================================= |
190 // |
195 // |
191 void PartDownloader::sourceChanged (int i) |
196 void PartDownloader::sourceChanged (int i) |
192 { |
197 { |
193 if (i == CustomURL) |
198 if (i == CustomURL) |
194 interface()->fileNameLabel->setText (tr ("URL:")); |
199 form()->fileNameLabel->setText (tr ("URL:")); |
195 else |
200 else |
196 interface()->fileNameLabel->setText (tr ("File name:")); |
201 form()->fileNameLabel->setText (tr ("File name:")); |
197 } |
202 } |
198 |
203 |
199 // ============================================================================= |
204 // ============================================================================= |
200 // |
205 // |
201 void PartDownloader::buttonClicked (QAbstractButton* btn) |
206 void PartDownloader::buttonClicked (QAbstractButton* btn) |
211 for (PartDownloadRequest* req : requests()) |
216 for (PartDownloadRequest* req : requests()) |
212 req->abort(); |
217 req->abort(); |
213 } |
218 } |
214 elif (btn == getButton (Download)) |
219 elif (btn == getButton (Download)) |
215 { |
220 { |
216 QString dest = interface()->fname->text(); |
221 QString dest = form()->fname->text(); |
217 setPrimaryFile (LDDocumentPtr()); |
222 setPrimaryFile (LDDocumentPtr()); |
218 setAborted (false); |
223 setAborted (false); |
219 |
224 |
220 if (getSource() == CustomURL) |
225 if (getSource() == CustomURL) |
221 dest = basename (getURL()); |
226 dest = basename (getURL()); |
228 if (not confirm (tr ("Overwrite?"), overwritemsg)) |
233 if (not confirm (tr ("Overwrite?"), overwritemsg)) |
229 return; |
234 return; |
230 } |
235 } |
231 |
236 |
232 downloadButton()->setEnabled (false); |
237 downloadButton()->setEnabled (false); |
233 interface()->progress->setEnabled (true); |
238 form()->progress->setEnabled (true); |
234 interface()->fname->setEnabled (false); |
239 form()->fname->setEnabled (false); |
235 interface()->source->setEnabled (false); |
240 form()->source->setEnabled (false); |
236 downloadFile (dest, getURL(), true); |
241 downloadFile (dest, getURL(), true); |
237 getButton (Close)->setEnabled (false); |
242 getButton (Close)->setEnabled (false); |
238 getButton (Abort)->setEnabled (true); |
243 getButton (Abort)->setEnabled (true); |
239 getButton (Download)->setEnabled (false); |
244 getButton (Download)->setEnabled (false); |
240 } |
245 } |
242 |
247 |
243 // ============================================================================= |
248 // ============================================================================= |
244 // |
249 // |
245 void PartDownloader::downloadFile (QString dest, QString url, bool primary) |
250 void PartDownloader::downloadFile (QString dest, QString url, bool primary) |
246 { |
251 { |
247 const int row = interface()->progress->rowCount(); |
252 const int row = form()->progress->rowCount(); |
248 |
253 |
249 // Don't download files repeadetly. |
254 // Don't download files repeadetly. |
250 if (filesToDownload().indexOf (dest) != -1) |
255 if (filesToDownload().indexOf (dest) != -1) |
251 return; |
256 return; |
252 |
257 |
253 modifyDestination (dest); |
258 modifyDestination (dest); |
254 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); |
259 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); |
255 m_filesToDownload << dest; |
260 m_filesToDownload << dest; |
256 m_requests << req; |
261 m_requests << req; |
257 interface()->progress->insertRow (row); |
262 form()->progress->insertRow (row); |
258 req->setTableRow (row); |
263 req->setTableRow (row); |
259 req->updateToTable(); |
264 req->updateToTable(); |
260 } |
265 } |
261 |
266 |
262 // ============================================================================= |
267 // ============================================================================= |
363 // |
368 // |
364 void PartDownloadRequest::updateToTable() |
369 void PartDownloadRequest::updateToTable() |
365 { |
370 { |
366 int const labelcol = PartDownloader::PartLabelColumn; |
371 int const labelcol = PartDownloader::PartLabelColumn; |
367 int const progcol = PartDownloader::ProgressColumn; |
372 int const progcol = PartDownloader::ProgressColumn; |
368 QTableWidget* table = prompt()->interface()->progress; |
373 QTableWidget* table = prompt()->form()->progress; |
369 QProgressBar* prog; |
374 QProgressBar* prog; |
370 |
375 |
371 switch (state()) |
376 switch (state()) |
372 { |
377 { |
373 case DLRQ_Requesting: |
378 case DLRQ_Requesting: |