http://bugzilla.lyx.org/show_bug.cgi?id=2753

The patch does what Georg proposed on bugzilla: remove the patch validators in 
the dialog (since those filenames are mangled and copied to the temp dir 
anyway) and add a validator/warning to LaTeX export instead.

Tested by Uwe. OK to go in?

Jürgen
Index: src/insets/InsetGraphics.cpp
===================================================================
--- src/insets/InsetGraphics.cpp	(Revision 18885)
+++ src/insets/InsetGraphics.cpp	(Arbeitskopie)
@@ -99,6 +99,7 @@
 using support::float_equal;
 using support::getExtension;
 using support::isFileReadable;
+using support::isValidLaTeXFilename;
 using support::latex_path;
 using support::onlyFilename;
 using support::removeExtension;
@@ -607,6 +608,14 @@
 	string output_file = support::os::external_path(runparams.nice ?
 		params().filename.outputFilename(m_buffer->filePath()) :
 		onlyFilename(temp_file.absFilename()));
+
+	if (runparams.nice && !isValidLaTeXFilename(output_file)) {
+		frontend::Alert::warning(_("Invalid filename"),
+				         _("The following filename is likely to cause trouble "
+					   "when running the exported file through LaTeX: ") +
+					    from_utf8(output_file));
+	}
+
 	FileName source_file = runparams.nice ? FileName(params().filename) : temp_file;
 	string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
 			"latex" : "pdflatex";
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(Revision 18885)
+++ src/insets/InsetInclude.cpp	(Arbeitskopie)
@@ -68,6 +68,7 @@
 using support::getVectorFromString;
 using support::isFileReadable;
 using support::isLyXFilename;
+using support::isValidLaTeXFilename;
 using support::latex_path;
 using support::makeAbsPath;
 using support::makeDisplayPath;
@@ -459,6 +460,12 @@
 
 	if (!runparams.nice)
 		incfile = mangled;
+	else if (!isValidLaTeXFilename(incfile)) {
+		frontend::Alert::warning(_("Invalid filename"),
+				         _("The following filename is likely to cause trouble "
+					   "when running the exported file through LaTeX: ") +
+					    from_utf8(incfile));
+	}
 	LYXERR(Debug::LATEX) << "incfile:" << incfile << endl;
 	LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
 	LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
Index: src/insets/InsetBibtex.cpp
===================================================================
--- src/insets/InsetBibtex.cpp	(Revision 18885)
+++ src/insets/InsetBibtex.cpp	(Arbeitskopie)
@@ -46,6 +46,7 @@
 using support::FileName;
 using support::findtexfile;
 using support::isFileReadable;
+using support::isValidLaTeXFilename;
 using support::latex_path;
 using support::ltrim;
 using support::makeAbsPath;
@@ -188,6 +189,12 @@
 				       << "' to '" << out_file << "'"
 				       << endl;
 			}
+		} else if (!runparams.inComment && runparams.nice && not_from_texmf &&
+			   !isValidLaTeXFilename(database)) {
+				frontend::Alert::warning(_("Invalid filename"),
+						         _("The following filename is likely to cause trouble "
+							   "when running the exported file through LaTeX: ") +
+							    from_utf8(database));
 		}
 
 		if (it != begin)
Index: src/insets/ExternalSupport.cpp
===================================================================
--- src/insets/ExternalSupport.cpp	(Revision 18885)
+++ src/insets/ExternalSupport.cpp	(Arbeitskopie)
@@ -19,11 +19,14 @@
 #include "Buffer.h"
 #include "Converter.h"
 #include "debug.h"
+#include "gettext.h"
 #include "ErrorList.h"
 #include "Exporter.h"
 #include "Format.h"
 #include "Mover.h"
 
+#include "frontends/alert.h"
+
 #include "support/filetools.h"
 #include "support/Forkedcall.h"
 #include "support/lstrings.h"
@@ -44,6 +47,7 @@
 namespace lyx {
 
 using support::FileName;
+using support::isValidLaTeXFilename;
 
 namespace external {
 
@@ -368,6 +372,17 @@
 	bool const use_latex_path = format == "LaTeX";
 	string str = doSubstitution(params, buffer, cit->second.product,
 				    use_latex_path, external_in_tmpdir);
+
+	string const absname = support::makeAbsPath(
+		params.filename.outputFilename(buffer.filePath()), buffer.filePath()).absFilename();
+
+	if (!external_in_tmpdir && !isValidLaTeXFilename(absname)) {
+		lyx::frontend::Alert::warning(_("Invalid filename"),
+					      _("The following filename is likely to cause trouble "
+						"when running the exported file through LaTeX: ") +
+					      from_utf8(absname));
+	}
+
 	str = substituteCommands(params, str, format);
 	str = substituteOptions(params, str, format);
 	// FIXME UNICODE
Index: src/support/filetools.cpp
===================================================================
--- src/support/filetools.cpp	(Revision 18885)
+++ src/support/filetools.cpp	(Arbeitskopie)
@@ -79,6 +79,16 @@
 }
 
 
+bool isValidLaTeXFilename(string const & filename)
+{
+	string const invalid_chars("#$%{}()[]\"^");
+	if (filename.find_first_of(invalid_chars) != string::npos)
+		return false;
+	else
+		return true;
+}
+
+
 string const latex_path(string const & original_path,
 		latex_path_extension extension,
 		latex_path_dots dots)
Index: src/support/filetools.h
===================================================================
--- src/support/filetools.h	(Revision 18885)
+++ src/support/filetools.h	(Arbeitskopie)
@@ -94,6 +94,9 @@
 ///
 bool isSGMLFilename(std::string const & filename);
 
+///
+bool isValidLaTeXFilename(std::string const & filename);
+
 /** Returns the path of a library data file.
     Search the file name.ext in the subdirectory dir of
       -# user_lyxdir
Index: src/frontends/qt4/QInclude.cpp
===================================================================
--- src/frontends/qt4/QInclude.cpp	(Revision 18885)
+++ src/frontends/qt4/QInclude.cpp	(Arbeitskopie)
@@ -18,7 +18,6 @@
 #include "CheckedLineEdit.h"
 #include "Qt2BC.h"
 #include "qt_helpers.h"
-#include "Validator.h"
 
 #include "LyXRC.h"
 
@@ -68,7 +67,6 @@
 	connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
 	connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
 
-	filenameED->setValidator(new PathValidator(true, filenameED));
 	setFocusProxy(filenameED);
 }
 
@@ -200,10 +198,6 @@
 
 void QInclude::update_contents()
 {
-	PathValidator * path_validator = getPathValidator(dialog_->filenameED);
-	if (path_validator)
-		path_validator->setChecker(kernel().docType(), lyxrc);
-
 	InsetCommandParams const & params = controller().params();
 
 	dialog_->filenameED->setText(toqstr(params["filename"]));
Index: src/frontends/qt4/QBibtex.cpp
===================================================================
--- src/frontends/qt4/QBibtex.cpp	(Revision 18885)
+++ src/frontends/qt4/QBibtex.cpp	(Arbeitskopie)
@@ -91,7 +91,6 @@
 	bcview->setOK(add_->addPB);
 	bcview->setCancel(add_->closePB);
 
-	add_->bibED->setValidator(new PathValidator(true, add_->bibED));
 	addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
 
 	connect(add_->bibED, SIGNAL(textChanged(const QString &)),
@@ -279,11 +278,6 @@
 
 void QBibtex::update_contents()
 {
-	PathValidator * path_validator =
-		getPathValidator(dialog_->add_->bibED);
-	if (path_validator)
-		path_validator->setChecker(kernel().docType(), lyxrc);
-
 	bool bibtopic = controller().usingBibtopic();
 
 	dialog_->databaseLW->clear();
Index: src/frontends/qt4/QExternal.cpp
===================================================================
--- src/frontends/qt4/QExternal.cpp	(Revision 18885)
+++ src/frontends/qt4/QExternal.cpp	(Arbeitskopie)
@@ -132,7 +132,6 @@
 	widthED->setValidator(unsignedLengthValidator(widthED));
 	heightED->setValidator(unsignedLengthValidator(heightED));
 
-	fileED->setValidator(new PathValidator(true, fileED));
 	setFocusProxy(fileED);
 }
 
@@ -562,10 +561,6 @@
 
 void QExternal::update_contents()
 {
-	PathValidator * path_validator = getPathValidator(dialog_->fileED);
-	if (path_validator)
-		path_validator->setChecker(kernel().docType(), lyxrc);
-
 	dialog_->tab->setCurrentIndex(0);
 	InsetExternalParams const & params = controller().params();
 
Index: src/frontends/qt4/QGraphics.cpp
===================================================================
--- src/frontends/qt4/QGraphics.cpp	(Revision 18885)
+++ src/frontends/qt4/QGraphics.cpp	(Arbeitskopie)
@@ -20,7 +20,6 @@
 #include "QGraphicsDialog.h"
 #include "Qt2BC.h"
 #include "qt_helpers.h"
-#include "Validator.h"
 
 #include "lengthcommon.h"
 #include "LyXRC.h"
@@ -119,10 +118,6 @@
 
 void QGraphics::update_contents()
 {
-	PathValidator * path_validator = getPathValidator(dialog_->filename);
-	if (path_validator)
-		path_validator->setChecker(kernel().docType(), lyxrc);
-
 	// clear and fill in the comboboxes
 	vector<string> const bb_units = frontend::getBBUnits();
 	dialog_->lbXunit->clear();

Reply via email to