# HG changeset patch # User Teemu Piippo # Date 1410119744 -10800 # Node ID 7ad8fb667084e454ff465445562c982c6e14142a # Parent 98fe1587dc43239b3d6fd599ca3b673fa833f710 - improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in diff -r 98fe1587dc43 -r 7ad8fb667084 src/ldDocument.cc --- 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()->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(); + } } } diff -r 98fe1587dc43 -r 7ad8fb667084 src/mainWindow.cc --- 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); diff -r 98fe1587dc43 -r 7ad8fb667084 src/partDownloader.cc --- 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 #include #include +#include +#include #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(); diff -r 98fe1587dc43 -r 7ad8fb667084 src/partDownloader.h --- 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); diff -r 98fe1587dc43 -r 7ad8fb667084 ui/config.ui --- 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 @@ 0 0 - 644 + 648 370 @@ -995,6 +995,13 @@ + + + Attempt to download missing parts from the PT + + + + <p>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 <tt>"&lt;dir&gt;/&lt;file&gt;.dat"</tt> - with this set, input can be automatically completed.</p> diff -r 98fe1587dc43 -r 7ad8fb667084 ui/ldforge.ui --- 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 @@ - + Colors