]> git.lyx.org Git - features.git/commitdiff
Don't allow newline characters in document settings and preferences (#5840).
authorJulien Rioux <jrioux@lyx.org>
Tue, 11 Oct 2011 17:57:33 +0000 (17:57 +0000)
committerJulien Rioux <jrioux@lyx.org>
Tue, 11 Oct 2011 17:57:33 +0000 (17:57 +0000)
Set a validator on QLineEdit widgets. The validator removes any
\n and \r characters, thus preventing users from copy-pasting
newline characters into these fields, and subsequently saving
them, inadvertantly, to their lyx file or preferences file.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39828 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiBranches.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiIndices.cpp
src/frontends/qt4/GuiIndices.h
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/Validator.cpp
src/frontends/qt4/Validator.h
src/frontends/qt4/ui/BiblioUi.ui
src/frontends/qt4/ui/IndicesUi.ui
src/frontends/qt4/ui/LanguageUi.ui
status.20x

index ebc1f01eb6f91a5e741d5580138b2c920c398a92..c79a42def221ba4cc45b4d27325ff88ee1b8dad6 100644 (file)
@@ -70,6 +70,8 @@ GuiBranches::GuiBranches(QWidget * parent)
                undef_, SLOT(accept()));
        connect(undef_->cancelPB, SIGNAL(clicked()),
                undef_, SLOT(reject()));
+
+       newBranchLE->setValidator(new NoNewLineValidator(newBranchLE));
 }
 
 void GuiBranches::update(BufferParams const & params)
index a836d65a9502a94469293d5d1bd5a0c128ae77d8..efa00689427cb189f508211b31cb2201503686f5 100644 (file)
@@ -744,6 +744,9 @@ GuiDocument::GuiDocument(GuiView & lv)
        outputModule->synccustomCB->addItem("\\synctex=-1");
        outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
 
+       outputModule->synccustomCB->setValidator(new NoNewLineValidator(
+               outputModule->synccustomCB));
+
        // fonts
        fontModule = new UiWidget<Ui::FontUi>;
        connect(fontModule->osFontsCB, SIGNAL(clicked()),
@@ -783,6 +786,11 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(fontModule->fontOsfCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+       fontModule->fontencLE->setValidator(new NoNewLineValidator(
+               fontModule->fontencLE));
+       fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
+               fontModule->cjkFontLE));
+
        updateFontlist();
 
        fontModule->fontsizeCO->addItem(qt_("Default"));
@@ -971,11 +979,14 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(langModule->languagePackageCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageED, SIGNAL(textChanged(QString)),
+       connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
        connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
                this, SLOT(languagePackageChanged(int)));
 
+       langModule->languagePackageLE->setValidator(new NoNewLineValidator(
+               langModule->languagePackageLE));
+
        QAbstractItemModel * language_model = guiApp->languageModel();
        // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
        language_model->sort(0);
@@ -1066,9 +1077,12 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
                this, SLOT(bibtexChanged(int)));
-       connect(biblioModule->bibtexOptionsED, SIGNAL(textChanged(QString)),
+       connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
 
+       biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
+               biblioModule->bibtexOptionsLE));
+
        biblioModule->citeStyleCO->addItem(qt_("Author-year"));
        biblioModule->citeStyleCO->addItem(qt_("Numerical"));
        biblioModule->citeStyleCO->setCurrentIndex(0);
@@ -1145,6 +1159,11 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(latexModule->refstyleCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+       latexModule->optionsLE->setValidator(new NoNewLineValidator(
+               latexModule->optionsLE));
+       latexModule->childDocLE->setValidator(new NoNewLineValidator(
+               latexModule->childDocLE));
+
        // postscript drivers
        for (int n = 0; tex_graphics[n][0]; ++n) {
                QString enc = qt_(tex_graphics_gui[n]);
@@ -1246,6 +1265,17 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
 
+       pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->titleLE));
+       pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->authorLE));
+       pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->subjectLE));
+       pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->keywordsLE));
+       pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->optionsLE));
+
        for (int i = 0; backref_opts[i][0]; ++i)
                pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
 
@@ -1903,14 +1933,14 @@ void GuiDocument::classChanged()
 
 void GuiDocument::languagePackageChanged(int i)
 {
-        langModule->languagePackageED->setEnabled(
+        langModule->languagePackageLE->setEnabled(
                langModule->languagePackageCO->itemData(i).toString() == "custom");
 }
 
 
 void GuiDocument::bibtexChanged(int n)
 {
-       biblioModule->bibtexOptionsED->setEnabled(
+       biblioModule->bibtexOptionsLE->setEnabled(
                biblioModule->bibtexCO->itemData(n).toString() != "default");
        changed();
 }
@@ -2168,7 +2198,7 @@ void GuiDocument::applyView()
                fromqstr(biblioModule->bibtexCO->itemData(
                        biblioModule->bibtexCO->currentIndex()).toString());
        string const bibtex_options =
-               fromqstr(biblioModule->bibtexOptionsED->text());
+               fromqstr(biblioModule->bibtexOptionsLE->text());
        if (bibtex_command == "default" || bibtex_options.empty())
                bp_.bibtex_command = bibtex_command;
        else
@@ -2236,7 +2266,7 @@ void GuiDocument::applyView()
                langModule->languagePackageCO->currentIndex()).toString();
        if (pack == "custom")
                bp_.lang_package =
-                       fromqstr(langModule->languagePackageED->text());
+                       fromqstr(langModule->languagePackageLE->text());
        else
                bp_.lang_package = fromqstr(pack);
 
@@ -2588,15 +2618,15 @@ void GuiDocument::paramsToDialog()
        int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
        if (bpos != -1) {
                biblioModule->bibtexCO->setCurrentIndex(bpos);
-               biblioModule->bibtexOptionsED->setText(toqstr(options).trimmed());
+               biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
        } else {
                // We reset to default if we do not know the specified compiler
                // This is for security reasons
                biblioModule->bibtexCO->setCurrentIndex(
                        biblioModule->bibtexCO->findData(toqstr("default")));
-               biblioModule->bibtexOptionsED->clear();
+               biblioModule->bibtexOptionsLE->clear();
        }
-       biblioModule->bibtexOptionsED->setEnabled(
+       biblioModule->bibtexOptionsLE->setEnabled(
                biblioModule->bibtexCO->currentIndex() != 0);
 
        // indices
@@ -2641,10 +2671,10 @@ void GuiDocument::paramsToDialog()
        if (p == -1) {
                langModule->languagePackageCO->setCurrentIndex(
                          langModule->languagePackageCO->findData("custom"));
-               langModule->languagePackageED->setText(toqstr(bp_.lang_package));
+               langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
        } else {
                langModule->languagePackageCO->setCurrentIndex(p);
-               langModule->languagePackageED->clear();
+               langModule->languagePackageLE->clear();
        }
 
        //color
index 7c21e70acb49ae97fabb1b2b120cb5f4f3ffe7c6..8694b98cd74184171128ceb621e881138e5a1176 100644 (file)
@@ -60,6 +60,9 @@ GuiIndices::GuiIndices(QWidget * parent)
                QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
                indexCO->addItem(command, command);
        }
+
+       indexOptionsLE->setValidator(new NoNewLineValidator(indexOptionsLE));
+       newIndexLE->setValidator(new NoNewLineValidator(newIndexLE));
 }
 
 void GuiIndices::update(BufferParams const & params)
@@ -82,14 +85,14 @@ void GuiIndices::update(BufferParams const & params)
        int const pos = indexCO->findData(toqstr(command));
        if (pos != -1) {
                indexCO->setCurrentIndex(pos);
-               indexOptionsED->setText(toqstr(options).trimmed());
+               indexOptionsLE->setText(toqstr(options).trimmed());
        } else {
                // We reset to default if we do not know the specified compiler
                // This is for security reasons
                indexCO->setCurrentIndex(indexCO->findData(toqstr("default")));
-               indexOptionsED->clear();
+               indexOptionsLE->clear();
        }
-       indexOptionsED->setEnabled(
+       indexOptionsLE->setEnabled(
                indexCO->currentIndex() != 0);
 
        updateView();
@@ -145,7 +148,7 @@ void GuiIndices::apply(BufferParams & params) const
        string const index_command =
                fromqstr(indexCO->itemData(
                        indexCO->currentIndex()).toString());
-       string const index_options = fromqstr(indexOptionsED->text());
+       string const index_options = fromqstr(indexOptionsLE->text());
        if (index_command == "default" || index_options.empty())
                params.index_command = index_command;
        else
@@ -155,13 +158,13 @@ void GuiIndices::apply(BufferParams & params) const
 
 void GuiIndices::on_indexCO_activated(int n)
 {
-       indexOptionsED->setEnabled(
+       indexOptionsLE->setEnabled(
                indexCO->itemData(n).toString() != "default");
        changed();
 }
 
 
-void GuiIndices::on_indexOptionsED_textChanged(QString)
+void GuiIndices::on_indexOptionsLE_textChanged(QString)
 {
        changed();
 }
index 7e833edb422406ca779f1bb02e30d84e1e387d75..a78d07e513053a732aac78b47c998656cab55cb8 100644 (file)
@@ -45,7 +45,7 @@ protected:
 
 protected Q_SLOTS:
        void on_indexCO_activated(int n);
-       void on_indexOptionsED_textChanged(QString);
+       void on_indexOptionsLE_textChanged(QString);
        void on_addIndexPB_pressed();
        void on_renamePB_clicked();
        void on_removePB_pressed();
index 99808976957b2fc3caf0fc99a6fa1fd34b7f3270..391f0c0023f9007ae8f21517108e7a8a02b2cc8c 100644 (file)
@@ -20,6 +20,7 @@
 #include "GuiFontLoader.h"
 #include "GuiKeySymbol.h"
 #include "qt_helpers.h"
+#include "Validator.h"
 
 #include "Author.h"
 #include "BufferList.h"
@@ -387,7 +388,11 @@ PrefOutput::PrefOutput(GuiPreferences * form)
        : PrefModule(qt_(catOutput), qt_("General"), form)
 {
        setupUi(this);
+
        DateED->setValidator(new StrftimeValidator(DateED));
+       dviCB->setValidator(new NoNewLineValidator(dviCB));
+       pdfCB->setValidator(new NoNewLineValidator(pdfCB));
+
        connect(DateED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
        connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
@@ -690,6 +695,16 @@ PrefLatex::PrefLatex(GuiPreferences * form)
        : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
 {
        setupUi(this);
+
+       latexEncodingED->setValidator(new NoNewLineValidator(latexEncodingED));
+       latexDviPaperED->setValidator(new NoNewLineValidator(latexDviPaperED));
+       latexBibtexED->setValidator(new NoNewLineValidator(latexBibtexED));
+       latexJBibtexED->setValidator(new NoNewLineValidator(latexJBibtexED));
+       latexIndexED->setValidator(new NoNewLineValidator(latexIndexED));
+       latexJIndexED->setValidator(new NoNewLineValidator(latexJIndexED));
+       latexNomenclED->setValidator(new NoNewLineValidator(latexNomenclED));
+       latexChecktexED->setValidator(new NoNewLineValidator(latexChecktexED));
+
        connect(latexEncodingCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
        connect(latexEncodingED, SIGNAL(textChanged(QString)),
@@ -1339,6 +1354,9 @@ PrefPaths::PrefPaths(GuiPreferences * form)
 
        connect(texinputsPrefixED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       pathPrefixED->setValidator(new NoNewLineValidator(pathPrefixED));
+       texinputsPrefixED->setValidator(new NoNewLineValidator(texinputsPrefixED));
 }
 
 
@@ -1487,6 +1505,9 @@ PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
                        this, SIGNAL(changed()));
                connect(spellcheckNotesCB, SIGNAL(clicked()),
                        this, SIGNAL(changed()));
+
+               altLanguageED->setValidator(new NoNewLineValidator(altLanguageED));
+               escapeCharactersED->setValidator(new NoNewLineValidator(escapeCharactersED));
        #else
                spellcheckerCB->setEnabled(false);
                altLanguageED->setEnabled(false);
@@ -1570,6 +1591,8 @@ PrefConverters::PrefConverters(GuiPreferences * form)
        connect(maxAgeLE, SIGNAL(textEdited(QString)),
                this, SIGNAL(changed()));
 
+       converterED->setValidator(new NoNewLineValidator(converterED));
+       converterFlagED->setValidator(new NoNewLineValidator(converterFlagED));
        maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
        //converterDefGB->setFocusProxy(convertersLW);
 }
@@ -1850,8 +1873,14 @@ PrefFileformats::PrefFileformats(GuiPreferences * form)
        : PrefModule(qt_(catFiles), qt_("File Formats"), form)
 {
        setupUi(this);
+
        formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
        formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
+       extensionED->setValidator(new NoNewLineValidator(extensionED));
+       shortcutED->setValidator(new NoNewLineValidator(shortcutED));
+       editorED->setValidator(new NoNewLineValidator(editorED));
+       viewerED->setValidator(new NoNewLineValidator(viewerED));
+       copierED->setValidator(new NoNewLineValidator(copierED));
 
        connect(documentCB, SIGNAL(clicked()),
                this, SLOT(setFlags()));
@@ -2231,6 +2260,10 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
        connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
 
+       languagePackageED->setValidator(new NoNewLineValidator(languagePackageED));
+       startCommandED->setValidator(new NoNewLineValidator(startCommandED));
+       endCommandED->setValidator(new NoNewLineValidator(endCommandED));
+
        uiLanguageCO->clear();
 
        QAbstractItemModel * language_model = guiApp->languageModel();
@@ -2374,6 +2407,24 @@ PrefPrinter::PrefPrinter(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       printerNameED->setValidator(new NoNewLineValidator(printerNameED));
+       printerCommandED->setValidator(new NoNewLineValidator(printerCommandED));
+       printerEvenED->setValidator(new NoNewLineValidator(printerEvenED));
+       printerPageRangeED->setValidator(new NoNewLineValidator(printerPageRangeED));
+       printerCopiesED->setValidator(new NoNewLineValidator(printerCopiesED));
+       printerReverseED->setValidator(new NoNewLineValidator(printerReverseED));
+       printerToFileED->setValidator(new NoNewLineValidator(printerToFileED));
+       printerPaperTypeED->setValidator(new NoNewLineValidator(printerPaperTypeED));
+       printerExtraED->setValidator(new NoNewLineValidator(printerExtraED));
+       printerOddED->setValidator(new NoNewLineValidator(printerOddED));
+       printerCollatedED->setValidator(new NoNewLineValidator(printerCollatedED));
+       printerLandscapeED->setValidator(new NoNewLineValidator(printerLandscapeED));
+       printerToPrinterED->setValidator(new NoNewLineValidator(printerToPrinterED));
+       printerExtensionED->setValidator(new NoNewLineValidator(printerExtensionED));
+       printerPaperSizeED->setValidator(new NoNewLineValidator(printerPaperSizeED));
+       printerSpoolCommandED->setValidator(new NoNewLineValidator(printerSpoolCommandED));
+       printerSpoolPrefixED->setValidator(new NoNewLineValidator(printerSpoolPrefixED));
 }
 
 
@@ -3114,6 +3165,9 @@ PrefIdentity::PrefIdentity(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(emailED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       nameED->setValidator(new NoNewLineValidator(nameED));
+       emailED->setValidator(new NoNewLineValidator(emailED));
 }
 
 
index e156dcb099dedbe83a86326438d197cae0c494b3..7f5d5d45e283634838252b710757d72918d08223 100644 (file)
@@ -138,6 +138,18 @@ QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) cons
 }
 
 
+NoNewLineValidator::NoNewLineValidator(QWidget * parent)
+       : QValidator(parent)
+{}
+
+
+QValidator::State NoNewLineValidator::validate(QString & qtext, int &) const
+{
+       qtext.remove(QRegExp("[\\n\\r]"));
+       return QValidator::Acceptable;
+}
+
+
 PathValidator::PathValidator(bool acceptable_if_empty,
                             QWidget * parent)
        : QValidator(parent),
index 36250bbdca924721211af2eb446d1e4a39937803..e824659323652368a1ac8b87343fe97049529a16 100644 (file)
@@ -124,6 +124,18 @@ private:
 };
 
 
+// A class to ascertain that no newline characters are passed.
+class NoNewLineValidator : public QValidator
+{
+       Q_OBJECT
+public:
+       // Define a validator.
+       NoNewLineValidator(QWidget *);
+       // Remove newline characters from input.
+       QValidator::State validate(QString &, int &) const;
+};
+
+
 /** A class to ascertain whether the data passed to the @c validate()
  *  member function is a valid file path.
  *  The test is active only when the path is to be stored in a LaTeX
index cc1122949140e389d333883de411512f81aa6182..6c6d5b8cb0641667a3e3beb2a279b38fd2d8f66e 100644 (file)
            <string>&amp;Options:</string>
           </property>
           <property name="buddy" >
-           <cstring>bibtexOptionsED</cstring>
+           <cstring>bibtexOptionsLE</cstring>
           </property>
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="bibtexOptionsED" >
+         <widget class="QLineEdit" name="bibtexOptionsLE" >
           <property name="toolTip" >
            <string>Define options such as --min-crossrefs (see the documentation of BibTeX)</string>
           </property>
index ce398b17db2e5c800c35db77420bcd10af3e5ec4..81d014538defc93fbed5431f0d6314c0ff062c49 100644 (file)
            <string>&amp;Options:</string>
           </property>
           <property name="buddy" >
-           <cstring>indexOptionsED</cstring>
+           <cstring>indexOptionsLE</cstring>
           </property>
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="indexOptionsED" >
+         <widget class="QLineEdit" name="indexOptionsLE" >
           <property name="toolTip" >
            <string>Define program options of the selected processor.</string>
           </property>
index 5741aada029dee8460bb7964ec346abb5a74872d..3dea1c27d6712eab34f8620c4dc9f808602984c9 100644 (file)
       </widget>
      </item>
      <item>
-      <widget class="QLineEdit" name="languagePackageED">
+      <widget class="QLineEdit" name="languagePackageLE">
        <property name="toolTip">
         <string>Enter the command to load the language package (default: \usepackage{babel})</string>
        </property>
index 3e8809361af3ca489ea987c329a3dc6b8af7c378..dd9290a3b878e1d301a57219faad4b269ac306a4 100644 (file)
@@ -142,6 +142,9 @@ What's new
 
 - Fix instant preview when using Python version 2.4 or lower.
 
+- Don't allow copy-pasting newline characters in Document->Settings
+  and Tools->Preferences (bug 5840).
+
 
 * ADVANCED FIND AND REPLACE