src/partDownloader.cc

changeset 867
557cb07dbe57
parent 865
6d68840fcb26
child 882
2f3cc8e045d5
--- a/src/partDownloader.cc	Sat Aug 30 20:09:30 2014 +0300
+++ b/src/partDownloader.cc	Sun Aug 31 03:10:51 2014 +0300
@@ -69,7 +69,9 @@
 
 // =============================================================================
 //
-PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent)
+PartDownloader::PartDownloader (QWidget* parent) :
+	QDialog (parent),
+	m_source (Source (0))
 {
 	setForm (new Ui_DownloadFrom);
 	form()->setupUi (this);
@@ -188,7 +190,15 @@
 //
 PartDownloader::Source PartDownloader::getSource() const
 {
-	return (Source) form()->source->currentIndex();
+	return m_source;
+}
+
+// =============================================================================
+//
+void PartDownloader::setSource (Source src)
+{
+	m_source = src;
+	form()->source->setCurrentIndex (int (src));
 }
 
 // =============================================================================
@@ -199,6 +209,8 @@
 		form()->fileNameLabel->setText (tr ("URL:"));
 	else
 		form()->fileNameLabel->setText (tr ("File name:"));
+
+	m_source = Source (i);
 }
 
 // =============================================================================
@@ -234,14 +246,7 @@
 				return;
 		}
 
-		downloadButton()->setEnabled (false);
-		form()->progress->setEnabled (true);
-		form()->fname->setEnabled (false);
-		form()->source->setEnabled (false);
 		downloadFile (dest, getURL(), true);
-		getButton (Close)->setEnabled (false);
-		getButton (Abort)->setEnabled (true);
-		getButton (Download)->setEnabled (false);
 	}
 }
 
@@ -255,6 +260,7 @@
 	if (filesToDownload().indexOf (dest) != -1)
 		return;
 
+	print ("Downloading %1 from %2\n", dest, url);
 	modifyDestination (dest);
 	PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this);
 	m_filesToDownload << dest;
@@ -262,6 +268,21 @@
 	form()->progress->insertRow (row);
 	req->setTableRow (row);
 	req->updateToTable();
+	downloadButton()->setEnabled (false);
+	form()->progress->setEnabled (true);
+	form()->fname->setEnabled (false);
+	form()->source->setEnabled (false);
+	getButton (Close)->setEnabled (false);
+	getButton (Abort)->setEnabled (true);
+	getButton (Download)->setEnabled (false);
+}
+
+// =============================================================================
+//
+void PartDownloader::downloadFromPartsTracker (QString file)
+{
+	modifyDestination (file);
+	downloadFile (file, g_unofficialLibraryURL + file, false);
 }
 
 // =============================================================================
@@ -289,11 +310,13 @@
 	if (primaryFile() != null)
 	{
 		LDDocument::setCurrent (primaryFile());
-		ReloadAllSubfiles();
 		g_win->doFullRefresh();
 		g_win->R()->resetAngles();
 	}
 
+		for (LDDocumentPtr f : m_files)
+		f->reloadAllSubfiles();
+
 	if (cfg::AutoCloseDownloadDialog and not failed)
 	{
 		// Close automatically if desired.
@@ -427,10 +450,13 @@
 		if (isPrimary() and not prompt()->isAborted())
 			CriticalError (networkReply()->errorString());
 
+		print ("Unable to download %1: %2\n", m_destinaton, networkReply()->errorString());
         setState (State::Failed);
 	}
     elif (state() != State::Failed)
+	{
         setState (State::Finished);
+	}
 
 	setNumBytesRead (numBytesTotal());
 	updateToTable();
@@ -469,10 +495,11 @@
 			continue;
 
 		QString dest = err->fileReferenced();
-		prompt()->modifyDestination (dest);
-		prompt()->downloadFile (dest, g_unofficialLibraryURL + dest, false);
+		prompt()->downloadFromPartsTracker (dest);
 	}
 
+	prompt()->addFile (f);
+
 	if (isPrimary())
 	{
 		AddRecentFile (filePath());
@@ -484,6 +511,13 @@
 
 // =============================================================================
 //
+void PartDownloader::addFile (LDDocumentPtr f)
+{
+	m_files << f;
+}
+
+// =============================================================================
+//
 void PartDownloadRequest::downloadProgress (int64 recv, int64 total)
 {
 	setNumBytesRead (recv);

mercurial