src/partDownloader.cc

changeset 861
83426c5fa732
parent 855
e16f1587ef44
child 865
6d68840fcb26
equal deleted inserted replaced
860:a496e72af069 861:83426c5fa732
42 { 42 {
43 QString path = getDownloadPath(); 43 QString path = getDownloadPath();
44 44
45 if (path.isEmpty() or not QDir (path).exists()) 45 if (path.isEmpty() or not QDir (path).exists())
46 { 46 {
47 critical (PartDownloader::tr ("You need to specify a valid path for " 47 CriticalError (PartDownloader::tr ("You need to specify a valid path for "
48 "downloaded files in the configuration to download paths.")); 48 "downloaded files in the configuration to download paths."));
49 49
50 (new ConfigDialog (ConfigDialog::DownloadTab, null))->exec(); 50 (new ConfigDialog (ConfigDialog::DownloadTab, null))->exec();
51 return; 51 return;
52 } 52 }
144 dest += ".dat"; 144 dest += ".dat";
145 } 145 }
146 146
147 // If the part starts with s\ or s/, then use parts/s/. Same goes with 147 // If the part starts with s\ or s/, then use parts/s/. Same goes with
148 // 48\ and p/48/. 148 // 48\ and p/48/.
149 if (eq (dest.left (2), "s\\", "s/")) 149 if (Eq (dest.left (2), "s\\", "s/"))
150 { 150 {
151 dest.remove (0, 2); 151 dest.remove (0, 2);
152 dest.prepend ("parts/s/"); 152 dest.prepend ("parts/s/");
153 } 153 }
154 elif (eq (dest.left (3), "48\\", "48/")) 154 elif (Eq (dest.left (3), "48\\", "48/"))
155 { 155 {
156 dest.remove (0, 3); 156 dest.remove (0, 3);
157 dest.prepend ("p/48/"); 157 dest.prepend ("p/48/");
158 } 158 }
159 159
221 QString dest = form()->fname->text(); 221 QString dest = form()->fname->text();
222 setPrimaryFile (LDDocumentPtr()); 222 setPrimaryFile (LDDocumentPtr());
223 setAborted (false); 223 setAborted (false);
224 224
225 if (getSource() == CustomURL) 225 if (getSource() == CustomURL)
226 dest = basename (getURL()); 226 dest = Basename (getURL());
227 227
228 modifyDestination (dest); 228 modifyDestination (dest);
229 229
230 if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest)) 230 if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest))
231 { 231 {
232 const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest); 232 const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest);
233 if (not confirm (tr ("Overwrite?"), overwritemsg)) 233 if (not Confirm (tr ("Overwrite?"), overwritemsg))
234 return; 234 return;
235 } 235 }
236 236
237 downloadButton()->setEnabled (false); 237 downloadButton()->setEnabled (false);
238 form()->progress->setEnabled (true); 238 form()->progress->setEnabled (true);
287 287
288 // Update everything now 288 // Update everything now
289 if (primaryFile() != null) 289 if (primaryFile() != null)
290 { 290 {
291 LDDocument::setCurrent (primaryFile()); 291 LDDocument::setCurrent (primaryFile());
292 reloadAllSubfiles(); 292 ReloadAllSubfiles();
293 g_win->doFullRefresh(); 293 g_win->doFullRefresh();
294 g_win->R()->resetAngles(); 294 g_win->R()->resetAngles();
295 } 295 }
296 296
297 if (cfg::AutoCloseDownloadDialog and not failed) 297 if (cfg::AutoCloseDownloadDialog and not failed)
339 m_isFirstUpdate (true), 339 m_isFirstUpdate (true),
340 m_isPrimary (primary), 340 m_isPrimary (primary),
341 m_filePointer (null) 341 m_filePointer (null)
342 { 342 {
343 // Make sure that we have a valid destination. 343 // Make sure that we have a valid destination.
344 QString dirpath = dirname (filePath()); 344 QString dirpath = Dirname (filePath());
345 345
346 QDir dir (dirpath); 346 QDir dir (dirpath);
347 347
348 if (not dir.exists()) 348 if (not dir.exists())
349 { 349 {
350 print ("Creating %1...\n", dirpath); 350 print ("Creating %1...\n", dirpath);
351 351
352 if (not dir.mkpath (dirpath)) 352 if (not dir.mkpath (dirpath))
353 critical (format (tr ("Couldn't create the directory %1!"), dirpath)); 353 CriticalError (format (tr ("Couldn't create the directory %1!"), dirpath));
354 } 354 }
355 355
356 setNetworkReply (networkManager()->get (QNetworkRequest (QUrl (url)))); 356 setNetworkReply (networkManager()->get (QNetworkRequest (QUrl (url))));
357 connect (networkReply(), SIGNAL (finished()), this, SLOT (downloadFinished())); 357 connect (networkReply(), SIGNAL (finished()), this, SLOT (downloadFinished()));
358 connect (networkReply(), SIGNAL (readyRead()), this, SLOT (readyRead())); 358 connect (networkReply(), SIGNAL (readyRead()), this, SLOT (readyRead()));
423 void PartDownloadRequest::downloadFinished() 423 void PartDownloadRequest::downloadFinished()
424 { 424 {
425 if (networkReply()->error() != QNetworkReply::NoError) 425 if (networkReply()->error() != QNetworkReply::NoError)
426 { 426 {
427 if (isPrimary() and not prompt()->isAborted()) 427 if (isPrimary() and not prompt()->isAborted())
428 critical (networkReply()->errorString()); 428 CriticalError (networkReply()->errorString());
429 429
430 setState (DLRQ_Failed); 430 setState (DLRQ_Failed);
431 } 431 }
432 elif (state() != DLRQ_Failed) 432 elif (state() != DLRQ_Failed)
433 setState (DLRQ_Finished); 433 setState (DLRQ_Finished);
450 prompt()->checkIfFinished(); 450 prompt()->checkIfFinished();
451 return; 451 return;
452 } 452 }
453 453
454 // Try to load this file now. 454 // Try to load this file now.
455 LDDocumentPtr f = openDocument (filePath(), false, not isPrimary()); 455 LDDocumentPtr f = OpenDocument (filePath(), false, not isPrimary());
456 456
457 if (f == null) 457 if (f == null)
458 return; 458 return;
459 459
460 // Iterate through this file and check for errors. If there's any that stems 460 // Iterate through this file and check for errors. If there's any that stems
473 prompt()->downloadFile (dest, g_unofficialLibraryURL + dest, false); 473 prompt()->downloadFile (dest, g_unofficialLibraryURL + dest, false);
474 } 474 }
475 475
476 if (isPrimary()) 476 if (isPrimary())
477 { 477 {
478 addRecentFile (filePath()); 478 AddRecentFile (filePath());
479 prompt()->setPrimaryFile (f); 479 prompt()->setPrimaryFile (f);
480 } 480 }
481 481
482 prompt()->checkIfFinished(); 482 prompt()->checkIfFinished();
483 } 483 }
507 // to go here. 507 // to go here.
508 setFilePointer (new QFile (filePath().toLocal8Bit())); 508 setFilePointer (new QFile (filePath().toLocal8Bit()));
509 509
510 if (not filePointer()->open (QIODevice::WriteOnly)) 510 if (not filePointer()->open (QIODevice::WriteOnly))
511 { 511 {
512 critical (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno))); 512 CriticalError (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno)));
513 setState (DLRQ_Failed); 513 setState (DLRQ_Failed);
514 networkReply()->abort(); 514 networkReply()->abort();
515 updateToTable(); 515 updateToTable();
516 prompt()->checkIfFinished(); 516 prompt()->checkIfFinished();
517 return; 517 return;
523 523
524 // ============================================================================= 524 // =============================================================================
525 // 525 //
526 bool PartDownloadRequest::isFinished() const 526 bool PartDownloadRequest::isFinished() const
527 { 527 {
528 return eq (state(), DLRQ_Finished, DLRQ_Failed); 528 return Eq (state(), DLRQ_Finished, DLRQ_Failed);
529 } 529 }
530 530
531 // ============================================================================= 531 // =============================================================================
532 // 532 //
533 void PartDownloadRequest::abort() 533 void PartDownloadRequest::abort()

mercurial