ask the user for ext prog paths instead of telling to go to configuration if no path is defined

Sat, 17 Aug 2013 11:35:51 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 17 Aug 2013 11:35:51 +0300
changeset 452
47cc663e4ff4
parent 451
7ef26b45ed55
child 453
8f43577495ba

ask the user for ext prog paths instead of telling to go to configuration if no path is defined

changelog.txt file | annotate | diff | comparison | revisions
src/configDialog.cpp file | annotate | diff | comparison | revisions
src/dialogs.cpp file | annotate | diff | comparison | revisions
src/dialogs.h file | annotate | diff | comparison | revisions
src/download.cpp file | annotate | diff | comparison | revisions
src/extprogs.cpp file | annotate | diff | comparison | revisions
--- a/changelog.txt	Sat Aug 17 02:24:08 2013 +0300
+++ b/changelog.txt	Sat Aug 17 11:35:51 2013 +0300
@@ -15,6 +15,8 @@
 - Added new action "Add History Line" for quickly inserting 0 !HISTORY lines to headers
 - Added support for '0 BFC CLIP' and '0 BFC NOCLIP' and added auto-correction from errorneous MLCAD
 	syntax ('0 BFC CERTIFY CLIP').
+- When an external program is attempted to be used without a binary path defined, one will be asked
+	with an input dialog instead of being told to go to configuration to set the path.
 - If the vertex snapper finds a vertex closer than 4 pixels, it likely is the vertex being looked for
 	and the algorithm can terminate early, hopefully this will save a few cycles on large parts.
 - The camera icons now draw real tooltips instead of emulated ones.
--- a/src/configDialog.cpp	Sat Aug 17 02:24:08 2013 +0300
+++ b/src/configDialog.cpp	Sat Aug 17 11:35:51 2013 +0300
@@ -63,6 +63,13 @@
 extern_cfg (bool, prog_isecalc_wine);
 extern_cfg (bool, prog_edger2_wine);
 
+const char* g_extProgPathFilter =
+#ifdef _WIN32
+	"Applications (*.exe)(*.exe);;All files (*.*)(*.*)";
+#else
+	"";
+#endif
+
 #define act(N) extern_cfg (keyseq, key_##N);
 #include "actions.h"
 
@@ -477,6 +484,7 @@
 }
 
 // =============================================================================
+// -----------------------------------------------------------------------------
 void ConfigDialog::slot_resetShortcut()
 {
 	QList<ShortcutListItem*> sel = getShortcutSelection();
@@ -488,6 +496,7 @@
 }
 
 // =============================================================================
+// -----------------------------------------------------------------------------
 void ConfigDialog::slot_clearShortcut() {
 	QList<ShortcutListItem*> sel = getShortcutSelection();
 	
@@ -498,6 +507,7 @@
 }
 
 // =============================================================================
+// -----------------------------------------------------------------------------
 void ConfigDialog::slot_setExtProgPath() {
 	const extProgInfo* info = null;
 	
@@ -509,17 +519,11 @@
 	}
 	
 	assert (info != null);
-	
-	str filter;
-#ifdef _WIN32
-	filter = "Applications (*.exe)(*.exe);;All files (*.*)(*.*)";
-#endif // WIN32
+	str fpath = QFileDialog::getOpenFileName (this, fmt ("Path to %1", info->name), *info->path, g_extProgPathFilter);
 	
-	str fpath = QFileDialog::getOpenFileName (this, fmt ("Path to %1", info->name), *info->path, filter);
-
-	if (fpath.length() == 0)
+	if (fpath.isEmpty())
 		return;
-
+	
 	info->input->setText (fpath);
 }
 
@@ -531,8 +535,7 @@
 }
 
 // =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
+// -----------------------------------------------------------------------------
 void ConfigDialog::setShortcutText (ShortcutListItem* item) {
 	QAction* act = item->action();
 	str label = act->iconText();
--- a/src/dialogs.cpp	Sat Aug 17 02:24:08 2013 +0300
+++ b/src/dialogs.cpp	Sat Aug 17 11:35:51 2013 +0300
@@ -38,7 +38,10 @@
 #include "ui_overlay.h"
 #include "ui_ldrawpath.h"
 #include "ui_openprogress.h"
+#include "ui_extprogpath.h"
+#include "build/moc_dialogs.cpp"
 
+extern const char* g_extProgPathFilter;
 extern_cfg (str, io_ldpath);
 
 // =============================================================================
@@ -243,5 +246,30 @@
 	updateValues();
 }
 
-#include "build/moc_dialogs.cpp"
-// kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4; 
+ExtProgPathPrompt::ExtProgPathPrompt (str progName, QWidget* parent, Qt::WindowFlags f) :
+	QDialog (parent, f),
+	ui (new Ui_ExtProgPath)
+{
+	ui->setupUi (this);
+	
+	str labelText = ui->m_label->text();
+	labelText.replace ("<PROGRAM>", progName);
+	ui->m_label->setText (labelText);
+	
+	connect (ui->m_findPath, SIGNAL (clicked (bool)), this, SLOT (findPath()));
+}
+
+ExtProgPathPrompt::~ExtProgPathPrompt() {
+	delete ui;
+}
+
+void ExtProgPathPrompt::findPath() {
+	str path = QFileDialog::getOpenFileName (null, "", "", g_extProgPathFilter);
+	
+	if (!path.isEmpty())
+		ui->m_path->setText (path);
+}
+
+str ExtProgPathPrompt::getPath() const {
+	return ui->m_path->text();
+}
\ No newline at end of file
--- a/src/dialogs.h	Sat Aug 17 02:24:08 2013 +0300
+++ b/src/dialogs.h	Sat Aug 17 11:35:51 2013 +0300
@@ -23,6 +23,7 @@
 #include "common.h"
 #include "types.h"
 
+class Ui_ExtProgPath;
 class QRadioButton;
 class QCheckBox;
 class QProgressBar;
@@ -107,5 +108,20 @@
 	void updateValues();
 };
 
-#endif // DIALOGS_H
-// kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4; 
+// =============================================================================
+class ExtProgPathPrompt : public QDialog {
+	Q_OBJECT
+	
+public:
+	explicit ExtProgPathPrompt (str progName, QWidget* parent = 0, Qt::WindowFlags f = 0);
+	virtual ~ExtProgPathPrompt();
+	str getPath() const;
+	
+public slots:
+	void findPath();
+	
+private:
+	Ui_ExtProgPath* ui;
+};
+
+#endif // DIALOGS_H
\ No newline at end of file
--- a/src/download.cpp	Sat Aug 17 02:24:08 2013 +0300
+++ b/src/download.cpp	Sat Aug 17 11:35:51 2013 +0300
@@ -73,7 +73,7 @@
 	
 	m_downloadButton = new QPushButton (tr ("Download"));
 	ui->buttonBox->addButton (m_downloadButton, QDialogButtonBox::ActionRole);
-	ui->buttonBox->button (QDialogButtonBox::Abort)->setEnabled (false);
+	getButton (Abort)->setEnabled (false);
 	
 	connect (ui->source, SIGNAL (currentIndexChanged (int)), this, SLOT (sourceChanged (int)));
 	connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), this, SLOT (buttonClicked (QAbstractButton*)));
@@ -116,8 +116,8 @@
 	
 	// Ensure .dat extension
 	if (dest.right (4) != ".dat") {
-		// Remove the existing extension, if any. It may be we're here over a
-		// typo in the .dat extension.
+		/* Remove the existing extension, if any. It may be we're here over a
+		   typo in the .dat extension. */
 		const int dotpos = dest.lastIndexOf (".");
 		if (dotpos != -1 && dotpos >= dest.length() - 4)
 			dest.chop (dest.length() - dotpos);
@@ -125,8 +125,8 @@
 		dest += ".dat";
 	}
 	
-	// If the part starts with s\ or s/, then use parts/s/. Same goes with
-	// 48\ and p/48/.
+	/* If the part starts with s\ or s/, then use parts/s/. Same goes with
+	   48\ and p/48/. */
 	if (dest.left (2) == "s\\" || dest.left (2) == "s/") {
 		dest.remove (0, 2);
 		dest.prepend ("parts/s/");
@@ -136,31 +136,30 @@
 	}
 	
 	/* Try determine where to put this part. We have four directories:
-	 * parts/, parts/s/, p/, and p/48/. If we haven't already specified
-	 * either parts/ or p/, we need to add it automatically. Part files
-	 * are numbers which can be followed by:
-	 * - c** (composites)
-	 * - d** (formed stickers)
-	 * - a lowercase alphabetic letter for variants
-	 *
-	 * Subfiles have an s** prefix, in which case we use parts/s/. Note that
-	 * the regex starts with a '^' so it won't catch already fully given part
-	 * file names.
-	 */
-	{
-		str partRegex = "^u?[0-9]+(c[0-9][0-9]+)*(d[0-9][0-9]+)*[a-z]?(p[0-9a-z][0-9a-z]+)*";
-		str subpartRegex = partRegex + "s[0-9][0-9]+";
-		
-		partRegex += "\\.dat$";
-		subpartRegex += "\\.dat$";
-		
-		if (QRegExp (subpartRegex).exactMatch (dest))
-			dest.prepend ("parts/s/");
-		elif (QRegExp (partRegex).exactMatch (dest))
-			dest.prepend ("parts/");
-		elif (dest.left (6) != "parts/" && dest.left (2) != "p/")
-			dest.prepend ("p/");
-	}
+	   parts/, parts/s/, p/, and p/48/. If we haven't already specified
+	   either parts/ or p/, we need to add it automatically. Part files
+	   are numbers wit a possible u prefix for parts with unknown number
+	   which can be followed by any of:
+	   - c** (composites)
+	   - d** (formed stickers)
+	   - p** (patterns)
+	   - a lowercase alphabetic letter for variants
+	
+	   Subfiles (usually) have an s** prefix, in which case we use parts/s/.
+	   Note that the regex starts with a '^' so it won't catch already fully
+	   given part file names. */
+	str partRegex = "^u?[0-9]+(c[0-9][0-9]+)*(d[0-9][0-9]+)*[a-z]?(p[0-9a-z][0-9a-z]+)*";
+	str subpartRegex = partRegex + "s[0-9][0-9]+";
+	
+	partRegex += "\\.dat$";
+	subpartRegex += "\\.dat$";
+	
+	if (QRegExp (subpartRegex).exactMatch (dest))
+		dest.prepend ("parts/s/");
+	elif (QRegExp (partRegex).exactMatch (dest))
+		dest.prepend ("parts/");
+	elif (dest.left (6) != "parts/" && dest.left (2) != "p/")
+		dest.prepend ("p/");
 }
 
 // =============================================================================
@@ -178,6 +177,8 @@
 		ui->fileNameLabel->setText (tr ("File name:"));
 }
 
+// =============================================================================
+// -----------------------------------------------------------------------------
 void PartDownloader::buttonClicked (QAbstractButton* btn) {
 	if (btn == getButton (Close)) {
 		reject();
@@ -260,7 +261,7 @@
 		g_win->fullRefresh();
 		g_win->R()->resetAngles();
 	}
-		
+	
 	if (net_autoclose && !failed) {
 		// Close automatically if desired.
 		accept();
--- a/src/extprogs.cpp	Sat Aug 17 02:24:08 2013 +0300
+++ b/src/extprogs.cpp	Sat Aug 17 11:35:51 2013 +0300
@@ -38,6 +38,7 @@
 #include "ui_coverer.h"
 #include "ui_isecalc.h"
 #include "ui_edger2.h"
+#include "dialogs.h"
 
 enum extprog {
 	Isecalc,
@@ -56,6 +57,15 @@
 cfg (str, prog_rectifier, "");
 cfg (str, prog_edger2, "");
 
+strconfig* const g_extProgPaths[] = {
+	&prog_isecalc,
+	&prog_intersector,
+	&prog_coverer,
+	&prog_ytruder,
+	&prog_rectifier,
+	&prog_edger2,
+};
+
 #ifndef _WIN32
 cfg (bool, prog_isecalc_wine, false);
 cfg (bool, prog_intersector_wine, false);
@@ -88,11 +98,12 @@
 	if (path.length() > 0)
 		return true;
 	
-	const char* name = g_extProgNames[prog];
+	ExtProgPathPrompt* dlg = new ExtProgPathPrompt (g_extProgNames[prog]);
+	if (dlg->exec() && !dlg->getPath().isEmpty()) {
+		*g_extProgPaths[prog] = dlg->getPath();
+		return true;
+	}
 	
-	critical (fmt (QObject::tr ("Couldn't run %1 as no path has "
-		"been defined for it. Use the configuration dialog's External Programs "
-		"tab to define a path for %1."), name));
 	return false;
 }
 

mercurial