src/partDownloader.cc

changeset 867
557cb07dbe57
parent 865
6d68840fcb26
child 882
2f3cc8e045d5
equal deleted inserted replaced
866:4951b737f8cb 867:557cb07dbe57
67 return path; 67 return path;
68 } 68 }
69 69
70 // ============================================================================= 70 // =============================================================================
71 // 71 //
72 PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent) 72 PartDownloader::PartDownloader (QWidget* parent) :
73 QDialog (parent),
74 m_source (Source (0))
73 { 75 {
74 setForm (new Ui_DownloadFrom); 76 setForm (new Ui_DownloadFrom);
75 form()->setupUi (this); 77 form()->setupUi (this);
76 form()->fname->setFocus(); 78 form()->fname->setFocus();
77 79
186 188
187 // ============================================================================= 189 // =============================================================================
188 // 190 //
189 PartDownloader::Source PartDownloader::getSource() const 191 PartDownloader::Source PartDownloader::getSource() const
190 { 192 {
191 return (Source) form()->source->currentIndex(); 193 return m_source;
194 }
195
196 // =============================================================================
197 //
198 void PartDownloader::setSource (Source src)
199 {
200 m_source = src;
201 form()->source->setCurrentIndex (int (src));
192 } 202 }
193 203
194 // ============================================================================= 204 // =============================================================================
195 // 205 //
196 void PartDownloader::sourceChanged (int i) 206 void PartDownloader::sourceChanged (int i)
197 { 207 {
198 if (i == CustomURL) 208 if (i == CustomURL)
199 form()->fileNameLabel->setText (tr ("URL:")); 209 form()->fileNameLabel->setText (tr ("URL:"));
200 else 210 else
201 form()->fileNameLabel->setText (tr ("File name:")); 211 form()->fileNameLabel->setText (tr ("File name:"));
212
213 m_source = Source (i);
202 } 214 }
203 215
204 // ============================================================================= 216 // =============================================================================
205 // 217 //
206 void PartDownloader::buttonClicked (QAbstractButton* btn) 218 void PartDownloader::buttonClicked (QAbstractButton* btn)
232 const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest); 244 const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest);
233 if (not Confirm (tr ("Overwrite?"), overwritemsg)) 245 if (not Confirm (tr ("Overwrite?"), overwritemsg))
234 return; 246 return;
235 } 247 }
236 248
237 downloadButton()->setEnabled (false);
238 form()->progress->setEnabled (true);
239 form()->fname->setEnabled (false);
240 form()->source->setEnabled (false);
241 downloadFile (dest, getURL(), true); 249 downloadFile (dest, getURL(), true);
242 getButton (Close)->setEnabled (false);
243 getButton (Abort)->setEnabled (true);
244 getButton (Download)->setEnabled (false);
245 } 250 }
246 } 251 }
247 252
248 // ============================================================================= 253 // =============================================================================
249 // 254 //
253 258
254 // Don't download files repeadetly. 259 // Don't download files repeadetly.
255 if (filesToDownload().indexOf (dest) != -1) 260 if (filesToDownload().indexOf (dest) != -1)
256 return; 261 return;
257 262
263 print ("Downloading %1 from %2\n", dest, url);
258 modifyDestination (dest); 264 modifyDestination (dest);
259 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); 265 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this);
260 m_filesToDownload << dest; 266 m_filesToDownload << dest;
261 m_requests << req; 267 m_requests << req;
262 form()->progress->insertRow (row); 268 form()->progress->insertRow (row);
263 req->setTableRow (row); 269 req->setTableRow (row);
264 req->updateToTable(); 270 req->updateToTable();
271 downloadButton()->setEnabled (false);
272 form()->progress->setEnabled (true);
273 form()->fname->setEnabled (false);
274 form()->source->setEnabled (false);
275 getButton (Close)->setEnabled (false);
276 getButton (Abort)->setEnabled (true);
277 getButton (Download)->setEnabled (false);
278 }
279
280 // =============================================================================
281 //
282 void PartDownloader::downloadFromPartsTracker (QString file)
283 {
284 modifyDestination (file);
285 downloadFile (file, g_unofficialLibraryURL + file, false);
265 } 286 }
266 287
267 // ============================================================================= 288 // =============================================================================
268 // 289 //
269 void PartDownloader::checkIfFinished() 290 void PartDownloader::checkIfFinished()
287 308
288 // Update everything now 309 // Update everything now
289 if (primaryFile() != null) 310 if (primaryFile() != null)
290 { 311 {
291 LDDocument::setCurrent (primaryFile()); 312 LDDocument::setCurrent (primaryFile());
292 ReloadAllSubfiles();
293 g_win->doFullRefresh(); 313 g_win->doFullRefresh();
294 g_win->R()->resetAngles(); 314 g_win->R()->resetAngles();
295 } 315 }
316
317 for (LDDocumentPtr f : m_files)
318 f->reloadAllSubfiles();
296 319
297 if (cfg::AutoCloseDownloadDialog and not failed) 320 if (cfg::AutoCloseDownloadDialog and not failed)
298 { 321 {
299 // Close automatically if desired. 322 // Close automatically if desired.
300 accept(); 323 accept();
425 if (networkReply()->error() != QNetworkReply::NoError) 448 if (networkReply()->error() != QNetworkReply::NoError)
426 { 449 {
427 if (isPrimary() and not prompt()->isAborted()) 450 if (isPrimary() and not prompt()->isAborted())
428 CriticalError (networkReply()->errorString()); 451 CriticalError (networkReply()->errorString());
429 452
453 print ("Unable to download %1: %2\n", m_destinaton, networkReply()->errorString());
430 setState (State::Failed); 454 setState (State::Failed);
431 } 455 }
432 elif (state() != State::Failed) 456 elif (state() != State::Failed)
457 {
433 setState (State::Finished); 458 setState (State::Finished);
459 }
434 460
435 setNumBytesRead (numBytesTotal()); 461 setNumBytesRead (numBytesTotal());
436 updateToTable(); 462 updateToTable();
437 463
438 if (filePointer()) 464 if (filePointer())
467 493
468 if ((err == null) or (err->fileReferenced().isEmpty())) 494 if ((err == null) or (err->fileReferenced().isEmpty()))
469 continue; 495 continue;
470 496
471 QString dest = err->fileReferenced(); 497 QString dest = err->fileReferenced();
472 prompt()->modifyDestination (dest); 498 prompt()->downloadFromPartsTracker (dest);
473 prompt()->downloadFile (dest, g_unofficialLibraryURL + dest, false); 499 }
474 } 500
501 prompt()->addFile (f);
475 502
476 if (isPrimary()) 503 if (isPrimary())
477 { 504 {
478 AddRecentFile (filePath()); 505 AddRecentFile (filePath());
479 prompt()->setPrimaryFile (f); 506 prompt()->setPrimaryFile (f);
480 } 507 }
481 508
482 prompt()->checkIfFinished(); 509 prompt()->checkIfFinished();
510 }
511
512 // =============================================================================
513 //
514 void PartDownloader::addFile (LDDocumentPtr f)
515 {
516 m_files << f;
483 } 517 }
484 518
485 // ============================================================================= 519 // =============================================================================
486 // 520 //
487 void PartDownloadRequest::downloadProgress (int64 recv, int64 total) 521 void PartDownloadRequest::downloadProgress (int64 recv, int64 total)

mercurial