]> git.lyx.org Git - features.git/commitdiff
Fix bug 2753: LyX doesn't support paths and filenames with parentheses
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 26 Jun 2007 16:55:42 +0000 (16:55 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 26 Jun 2007 16:55:42 +0000 (16:55 +0000)
* src/frontends/qt4/QBibtex.cpp:
* src/frontends/qt4/QExternal.cpp:
* src/frontends/qt4/QGraphics.cpp:
* src/frontends/qt4/QInclude.cpp:
- remove path validator

* src/support/filetools.{cpp,h}:
- new validator for exporting LaTeX files

* src/insets/ExternalSupport.cpp:
* src/insets/InsetBibtex.cpp:
* src/insets/InsetGraphics.cpp:
* src/insets/InsetInclude.cpp:
- use validator when exporting a LaTeX file

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18897 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/QBibtex.cpp
src/frontends/qt4/QExternal.cpp
src/frontends/qt4/QGraphics.cpp
src/frontends/qt4/QInclude.cpp
src/insets/ExternalSupport.cpp
src/insets/InsetBibtex.cpp
src/insets/InsetGraphics.cpp
src/insets/InsetInclude.cpp
src/support/filetools.cpp
src/support/filetools.h

index bb85f9c45aec3cc808867613a3f28a1dcb147e84..9bc8bb13fce8bfe614fc16e72db8c2b532dae852 100644 (file)
@@ -91,7 +91,6 @@ QBibtexDialog::QBibtexDialog(QBibtex * form)
        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::build_dialog()
 
 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 ec6f9705c95ae0a58a1c688d2a36eeab9a1ce78e..0757d9fca8ef2ed768b2c691bff054117029ab97 100644 (file)
@@ -132,7 +132,6 @@ QExternalDialog::QExternalDialog(QExternal * form)
        widthED->setValidator(unsignedLengthValidator(widthED));
        heightED->setValidator(unsignedLengthValidator(heightED));
 
-       fileED->setValidator(new PathValidator(true, fileED));
        setFocusProxy(fileED);
 }
 
@@ -562,10 +561,6 @@ void QExternal::build_dialog()
 
 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 f88bd150801acf1ec050812d64dd586254d29429..3e6e6bf4059cec9d9df99158c9d73a9d23b323a7 100644 (file)
@@ -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 @@ int getItemNo(vector<string> v, string const & s) {
 
 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();
index 46e66b081506fb83d4272eecc93829ccecced186..c4f650f4b6fbc1aca3e732fd475b86ed024ed22d 100644 (file)
@@ -18,7 +18,6 @@
 #include "CheckedLineEdit.h"
 #include "Qt2BC.h"
 #include "qt_helpers.h"
-#include "Validator.h"
 
 #include "LyXRC.h"
 
@@ -69,7 +68,6 @@ QIncludeDialog::QIncludeDialog(QInclude * form)
        connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
        connect(bypassCB, SIGNAL(clicked()), this, SLOT(validate_listings_params()));
 
-       filenameED->setValidator(new PathValidator(true, filenameED));
        setFocusProxy(filenameED);
 }
 
@@ -201,10 +199,6 @@ void QInclude::build_dialog()
 
 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 ecfd61797c6ce4e45af0e386e6c728f388940078..e214c3e4f253b128acffb7e14a3c8ca1cf157829 100644 (file)
 #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 @@ using boost::filesystem::is_directory;
 namespace lyx {
 
 using support::FileName;
+using support::isValidLaTeXFilename;
 
 namespace external {
 
@@ -368,6 +372,17 @@ int writeExternal(InsetExternalParams const & params,
        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 8029855233a1b98fb5461700efb4791ad44df817..6870b58134efb612a94c461e41000ef26b62837c 100644 (file)
@@ -46,6 +46,7 @@ using support::DocFileName;
 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 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
                                       << "' 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 f48f784e7f99dccf5a2261797bcb39bec0602148..61daef31aff975d5fc5795eb50a4e9eae4ff9d9a 100644 (file)
@@ -99,6 +99,7 @@ using support::FileName;
 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 const InsetGraphics::prepareFile(Buffer const & buf,
        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 a755de41090c6b722bbfad428fff8e826a106e92..169c8baff8a9561881d61429534e1838457503b2 100644 (file)
@@ -68,6 +68,7 @@ using support::getFileContents;
 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 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 
        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 8fc53ae1a40313caf37114b7f84c34f8c50d9bed..0622e351c240486fb06fa2b426fdc4861c8953be 100644 (file)
@@ -79,6 +79,16 @@ bool isSGMLFilename(string const & filename)
 }
 
 
+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 c8872ebce1e00cce9cc98f1fdf7a74b6cad3aa9f..6d717a58c66783794d9fe45b66f36377c4713fdc 100644 (file)
@@ -94,6 +94,9 @@ bool isLyXFilename(std::string const & filename);
 ///
 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