Author: jrioux
Date: Tue Oct 11 19:57:33 2011
New Revision: 39828
URL: http://www.lyx.org/trac/changeset/39828
Log:
Don't allow newline characters in document settings and preferences (#5840).
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.
Modified:
lyx-devel/branches/BRANCH_2_0_X/ (props changed)
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.cpp
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.h
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiPrefs.cpp
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.cpp
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.h
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BiblioUi.ui
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/IndicesUi.ui
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/LanguageUi.ui
lyx-devel/branches/BRANCH_2_0_X/status.20x
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp Tue Oct
11 19:57:33 2011 (r39828)
@@ -70,6 +70,8 @@
undef_, SLOT(accept()));
connect(undef_->cancelPB, SIGNAL(clicked()),
undef_, SLOT(reject()));
+
+ newBranchLE->setValidator(new NoNewLineValidator(newBranchLE));
}
void GuiBranches::update(BufferParams const & params)
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp Tue Oct
11 19:57:33 2011 (r39828)
@@ -744,6 +744,9 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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::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 @@
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 @@
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 @@
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 @@
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
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.cpp Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.cpp Tue Oct
11 19:57:33 2011 (r39828)
@@ -60,6 +60,9 @@
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 @@
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 @@
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::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();
}
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.h
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.h Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiIndices.h Tue Oct
11 19:57:33 2011 (r39828)
@@ -45,7 +45,7 @@
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();
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiPrefs.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiPrefs.cpp Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiPrefs.cpp Tue Oct
11 19:57:33 2011 (r39828)
@@ -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 @@
: 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 @@
: 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 @@
connect(texinputsPrefixED, SIGNAL(textChanged(QString)),
this, SIGNAL(changed()));
+
+ pathPrefixED->setValidator(new NoNewLineValidator(pathPrefixED));
+ texinputsPrefixED->setValidator(new
NoNewLineValidator(texinputsPrefixED));
}
@@ -1487,6 +1505,9 @@
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 @@
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 @@
: 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 @@
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 @@
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 @@
this, SIGNAL(changed()));
connect(emailED, SIGNAL(textChanged(QString)),
this, SIGNAL(changed()));
+
+ nameED->setValidator(new NoNewLineValidator(nameED));
+ emailED->setValidator(new NoNewLineValidator(emailED));
}
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.cpp Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.cpp Tue Oct
11 19:57:33 2011 (r39828)
@@ -138,6 +138,18 @@
}
+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),
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.h
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.h Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/Validator.h Tue Oct
11 19:57:33 2011 (r39828)
@@ -124,6 +124,18 @@
};
+// 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
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BiblioUi.ui
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BiblioUi.ui Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BiblioUi.ui Tue Oct
11 19:57:33 2011 (r39828)
@@ -168,12 +168,12 @@
<string>&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>
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/IndicesUi.ui
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/IndicesUi.ui Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/IndicesUi.ui Tue Oct
11 19:57:33 2011 (r39828)
@@ -54,12 +54,12 @@
<string>&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>
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/LanguageUi.ui
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/LanguageUi.ui Tue Oct
11 00:47:52 2011 (r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/LanguageUi.ui Tue Oct
11 19:57:33 2011 (r39828)
@@ -137,7 +137,7 @@
</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>
Modified: lyx-devel/branches/BRANCH_2_0_X/status.20x
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/status.20x Tue Oct 11 00:47:52 2011
(r39827)
+++ lyx-devel/branches/BRANCH_2_0_X/status.20x Tue Oct 11 19:57:33 2011
(r39828)
@@ -142,6 +142,9 @@
- 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