- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in

Sun, 07 Sep 2014 22:55:44 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 07 Sep 2014 22:55:44 +0300
changeset 888
7ad8fb667084
parent 887
98fe1587dc43
child 889
ba9e4bcc2fcc
child 894
120cf01d8831

- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in

src/ldDocument.cc file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
src/partDownloader.cc file | annotate | diff | comparison | revisions
src/partDownloader.h file | annotate | diff | comparison | revisions
ui/config.ui file | annotate | diff | comparison | revisions
ui/ldforge.ui file | annotate | diff | comparison | revisions
--- a/src/ldDocument.cc	Sun Sep 07 21:08:53 2014 +0300
+++ b/src/ldDocument.cc	Sun Sep 07 22:55:44 2014 +0300
@@ -35,6 +35,7 @@
 
 CFGENTRY (String, LDrawPath, "")
 CFGENTRY (List, RecentFiles, {})
+CFGENTRY (Bool, TryDownloadMissingFiles, false)
 EXTERN_CFGENTRY (String, DownloadFilePath)
 EXTERN_CFGENTRY (Bool, UseLogoStuds)
 
@@ -756,18 +757,22 @@
 		unknowns << obj.staticCast<LDError>()->fileReferenced();
 	}
 
-	if (not unknowns.isEmpty())
+	if (cfg::TryDownloadMissingFiles and not unknowns.isEmpty())
 	{
 		PartDownloader dl;
-		dl.setSource (PartDownloader::PartsTracker);
-		dl.setPrimaryFile (file);
+
+		if (dl.checkValidPath())
+		{
+			dl.setSource (PartDownloader::PartsTracker);
+			dl.setPrimaryFile (file);
 
-		for (QString const& unknown : unknowns)
-			dl.downloadFromPartsTracker (unknown);
+			for (QString const& unknown : unknowns)
+				dl.downloadFromPartsTracker (unknown);
 
-		dl.exec();
-		dl.checkIfFinished();
-		file->reloadAllSubfiles();
+			dl.exec();
+			dl.checkIfFinished();
+			file->reloadAllSubfiles();
+		}
 	}
 }
 
--- a/src/mainWindow.cc	Sun Sep 07 21:08:53 2014 +0300
+++ b/src/mainWindow.cc	Sun Sep 07 22:55:44 2014 +0300
@@ -215,14 +215,16 @@
 void MainWindow::updateColorToolbar()
 {
 	m_colorButtons.clear();
-	ui->colorToolbar->clear();
-	ui->colorToolbar->addAction (ui->actionUncolor);
-	ui->colorToolbar->addSeparator();
+	ui->toolBarColors->clear();
+	ui->toolBarColors->addAction (ui->actionUncolor);
+	ui->toolBarColors->addSeparator();
 
 	for (LDQuickColor& entry : m_quickColors)
 	{
 		if (entry.isSeparator())
-			ui->colorToolbar->addSeparator();
+		{
+			ui->toolBarColors->addSeparator();
+		}
 		else
 		{
 			QToolButton* colorButton = new QToolButton;
@@ -231,7 +233,7 @@
 			colorButton->setToolTip (entry.color().name());
 
 			connect (colorButton, SIGNAL (clicked()), this, SLOT (slot_quickColor()));
-			ui->colorToolbar->addWidget (colorButton);
+			ui->toolBarColors->addWidget (colorButton);
 			m_colorButtons << colorButton;
 
 			entry.setToolButton (colorButton);
--- a/src/partDownloader.cc	Sun Sep 07 21:08:53 2014 +0300
+++ b/src/partDownloader.cc	Sun Sep 07 22:55:44 2014 +0300
@@ -22,13 +22,14 @@
 #include <QDir>
 #include <QProgressBar>
 #include <QPushButton>
+#include <QFileDialog>
+#include <QMessageBox>
 #include "partDownloader.h"
 #include "ui_downloadfrom.h"
 #include "basics.h"
 #include "mainWindow.h"
 #include "ldDocument.h"
 #include "glRenderer.h"
-#include "configDialog.h"
 
 CFGENTRY (String, DownloadFilePath, "")
 CFGENTRY (Bool, GuessDownloadPaths, true)
@@ -40,19 +41,12 @@
 //
 void PartDownloader::staticBegin()
 {
-	QString path = getDownloadPath();
-
-	if (path.isEmpty() or not QDir (path).exists())
-	{
-		Critical (PartDownloader::tr ("You need to specify a valid path for "
-			"downloaded files in the configuration to download paths."));
+	PartDownloader dlg;
 
-		(new ConfigDialog (ConfigDialog::DownloadTab, null))->exec();
+	if (not dlg.checkValidPath())
 		return;
-	}
 
-	PartDownloader* dlg = new PartDownloader;
-	dlg->exec();
+	dlg.exec();
 }
 
 // =============================================================================
@@ -102,6 +96,26 @@
 
 // =============================================================================
 //
+bool PartDownloader::checkValidPath()
+{
+	QString path = getDownloadPath();
+
+	if (path.isEmpty() or not QDir (path).exists())
+	{
+		QMessageBox::information(this, "Notice", "Please input a path for files to download.");
+		path = QFileDialog::getExistingDirectory (this, "Path for downloaded files:");
+
+		if (path.isEmpty())
+			return false;
+
+		cfg::DownloadFilePath = path;
+	}
+
+	return true;
+}
+
+// =============================================================================
+//
 QString PartDownloader::getURL()
 {
 	const Source src = getSource();
--- a/src/partDownloader.h	Sun Sep 07 21:08:53 2014 +0300
+++ b/src/partDownloader.h	Sun Sep 07 22:55:44 2014 +0300
@@ -70,6 +70,7 @@
 	virtual			~PartDownloader();
 
 	void			addFile (LDDocumentPtr f);
+	bool			checkValidPath();
 	void			downloadFile (QString dest, QString url, bool primary);
 	void			downloadFromPartsTracker (QString file);
 	QPushButton*	getButton (Button i);
--- a/ui/config.ui	Sun Sep 07 21:08:53 2014 +0300
+++ b/ui/config.ui	Sun Sep 07 22:55:44 2014 +0300
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>644</width>
+    <width>648</width>
     <height>370</height>
    </rect>
   </property>
@@ -995,6 +995,13 @@
              </layout>
             </item>
             <item>
+             <widget class="QCheckBox" name="configTryDownloadMissingFiles">
+              <property name="text">
+               <string>Attempt to download missing parts from the PT</string>
+              </property>
+             </widget>
+            </item>
+            <item>
              <widget class="QCheckBox" name="configGuessDownloadPaths">
               <property name="whatsThis">
                <string>&lt;p&gt;When this is set, LDForge tries to adjust and correct part paths based on the input. A full path given to the download prompt should be of form &lt;tt&gt;&quot;&amp;lt;dir&amp;gt;/&amp;lt;file&amp;gt;.dat&quot;&lt;/tt&gt; - with this set, input can be automatically completed.&lt;/p&gt;
--- a/ui/ldforge.ui	Sun Sep 07 21:08:53 2014 +0300
+++ b/ui/ldforge.ui	Sun Sep 07 22:55:44 2014 +0300
@@ -541,7 +541,7 @@
    <addaction name="actionModeCircle"/>
    <addaction name="actionModeLinePath"/>
   </widget>
-  <widget class="QToolBar" name="toolBarColor">
+  <widget class="QToolBar" name="toolBarColors">
    <property name="windowTitle">
     <string>Colors</string>
    </property>

mercurial