]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrefs.cpp
Improve wording (#10670)
[lyx.git] / src / frontends / qt4 / GuiPrefs.cpp
index 996be4916be1d52e8a4832314141937ead92f3c7..bacf17ac57de7ce9e0b97c2d2689614673588c5d 100644 (file)
@@ -72,6 +72,7 @@
 #include <iomanip>
 #include <sstream>
 #include <algorithm>
+#include <math.h>
 
 using namespace Ui;
 
@@ -743,6 +744,8 @@ PrefLatex::PrefLatex(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(latexBibtexED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+       connect(latexJBibtexCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
        connect(latexJBibtexED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
        connect(latexIndexCO, SIGNAL(activated(int)),
@@ -779,7 +782,7 @@ void PrefLatex::on_latexBibtexCO_activated(int n)
        QString const bibtex = latexBibtexCO->itemData(n).toString();
        if (bibtex.isEmpty()) {
                latexBibtexED->clear();
-               latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
+               latexBibtexOptionsLA->setText(qt_("C&ommand:"));
                return;
        }
        for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
@@ -799,6 +802,31 @@ void PrefLatex::on_latexBibtexCO_activated(int n)
 }
 
 
+void PrefLatex::on_latexJBibtexCO_activated(int n)
+{
+       QString const jbibtex = latexJBibtexCO->itemData(n).toString();
+       if (jbibtex.isEmpty()) {
+               latexJBibtexED->clear();
+               latexJBibtexOptionsLA->setText(qt_("Co&mmand:"));
+               return;
+       }
+       for (LyXRC::CommandSet::const_iterator it = jbibtex_alternatives.begin();
+            it != jbibtex_alternatives.end(); ++it) {
+               QString const bib = toqstr(*it);
+               int ind = bib.indexOf(" ");
+               QString sel_command = bib.left(ind);
+               QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
+               if (jbibtex == sel_command) {
+                       if (ind < 0)
+                               latexJBibtexED->clear();
+                       else
+                               latexJBibtexED->setText(sel_options.trimmed());
+               }
+       }
+       latexJBibtexOptionsLA->setText(qt_("Opt&ions:"));
+}
+
+
 void PrefLatex::on_latexIndexCO_activated(int n)
 {
        QString const index = latexIndexCO->itemData(n).toString();
@@ -838,6 +866,18 @@ void PrefLatex::applyRC(LyXRC & rc) const
        else
                rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
 
+       // If jbibtex is not empty, jbibopt contains the options, otherwise
+       // it is a customized bibtex command with options.
+       QString const jbibtex = latexJBibtexCO->itemData(
+               latexJBibtexCO->currentIndex()).toString();
+       QString const jbibopt = latexJBibtexED->text();
+       if (jbibtex.isEmpty())
+               rc.jbibtex_command = fromqstr(jbibopt);
+       else if (jbibopt.isEmpty())
+               rc.jbibtex_command = fromqstr(jbibtex);
+       else
+               rc.jbibtex_command = fromqstr(jbibtex) + " " + fromqstr(jbibopt);
+
        // If index is not empty, idxopt contains the options, otherwise
        // it is a customized index command with options.
        QString const index = latexIndexCO->itemData(
@@ -855,7 +895,6 @@ void PrefLatex::applyRC(LyXRC & rc) const
        else
                rc.fontenc = "default";
        rc.chktex_command = fromqstr(latexChecktexED->text());
-       rc.jbibtex_command = fromqstr(latexJBibtexED->text());
        rc.jindex_command = fromqstr(latexJIndexED->text());
        rc.nomencl_command = fromqstr(latexNomenclED->text());
        rc.auto_reset_options = latexAutoresetCB->isChecked();
@@ -870,6 +909,7 @@ void PrefLatex::updateRC(LyXRC const & rc)
 {
        latexBibtexCO->clear();
 
+       latexBibtexCO->addItem(qt_("Automatic"), "automatic");
        latexBibtexCO->addItem(qt_("Custom"), QString());
        for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
                             it != rc.bibtex_alternatives.end(); ++it) {
@@ -892,7 +932,35 @@ void PrefLatex::updateRC(LyXRC const & rc)
        } else {
                latexBibtexED->setText(toqstr(rc.bibtex_command));
                latexBibtexCO->setCurrentIndex(0);
-               latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
+               latexBibtexOptionsLA->setText(qt_("C&ommand:"));
+       }
+
+       latexJBibtexCO->clear();
+
+       latexJBibtexCO->addItem(qt_("Automatic"), "automatic");
+       latexJBibtexCO->addItem(qt_("Custom"), QString());
+       for (LyXRC::CommandSet::const_iterator it = rc.jbibtex_alternatives.begin();
+                            it != rc.jbibtex_alternatives.end(); ++it) {
+               QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
+               latexJBibtexCO->addItem(command, command);
+       }
+
+       jbibtex_alternatives = rc.jbibtex_alternatives;
+
+       QString const jbib = toqstr(rc.jbibtex_command);
+       ind = jbib.indexOf(" ");
+       sel_command = jbib.left(ind);
+       sel_options = ind < 0 ? QString() : jbib.mid(ind + 1);
+
+       pos = latexJBibtexCO->findData(sel_command);
+       if (pos != -1) {
+               latexJBibtexCO->setCurrentIndex(pos);
+               latexJBibtexED->setText(sel_options.trimmed());
+               latexJBibtexOptionsLA->setText(qt_("Opt&ions:"));
+       } else {
+               latexJBibtexED->setText(toqstr(rc.bibtex_command));
+               latexJBibtexCO->setCurrentIndex(0);
+               latexJBibtexOptionsLA->setText(qt_("Co&mmand:"));
        }
 
        latexIndexCO->clear();
@@ -931,7 +999,6 @@ void PrefLatex::updateRC(LyXRC const & rc)
                latexEncodingED->setText(toqstr(rc.fontenc));
        }
        latexChecktexED->setText(toqstr(rc.chktex_command));
-       latexJBibtexED->setText(toqstr(rc.jbibtex_command));
        latexJIndexED->setText(toqstr(rc.jindex_command));
        latexNomenclED->setText(toqstr(rc.nomencl_command));
        latexAutoresetCB->setChecked(rc.auto_reset_options);
@@ -1227,12 +1294,17 @@ void PrefColors::changeSysColor()
 {
        for (int row = 0 ; row < lyxObjectsLW->count() ; ++row) {
                // skip colors that are taken from system palette
-               bool const hide = syscolorsCB->isChecked()
+               bool const disable = syscolorsCB->isChecked()
                        && guiApp->colorCache().isSystem(lcolors_[row]);
 
-               lyxObjectsLW->item(row)->setHidden(hide);
-       }
+               QListWidgetItem * const item = lyxObjectsLW->item(row);
+               Qt::ItemFlags const flags = item->flags();
 
+               if (disable)
+                       item->setFlags(flags & ~Qt::ItemIsEnabled);
+               else
+                       item->setFlags(flags | Qt::ItemIsEnabled);
+       }
 }
 
 void PrefColors::changeLyxObjectsSelection()
@@ -1610,10 +1682,14 @@ PrefConverters::PrefConverters(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(maxAgeLE, SIGNAL(textEdited(QString)),
                this, SIGNAL(changed()));
+       connect(needauthForbiddenCB, SIGNAL(toggled(bool)),
+               this, SIGNAL(changed()));
+       connect(needauthCB, SIGNAL(toggled(bool)),
+               this, SIGNAL(changed()));
 
        converterED->setValidator(new NoNewLineValidator(converterED));
        converterFlagED->setValidator(new NoNewLineValidator(converterFlagED));
-       maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
+       maxAgeLE->setValidator(new QDoubleValidator(0, HUGE_VAL, 6, maxAgeLE));
        //converterDefGB->setFocusProxy(convertersLW);
 }
 
@@ -1621,6 +1697,8 @@ PrefConverters::PrefConverters(GuiPreferences * form)
 void PrefConverters::applyRC(LyXRC & rc) const
 {
        rc.use_converter_cache = cacheCB->isChecked();
+       rc.use_converter_needauth_forbidden = needauthForbiddenCB->isChecked();
+       rc.use_converter_needauth = needauthCB->isChecked();
        rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
 }
 
@@ -1628,6 +1706,8 @@ void PrefConverters::applyRC(LyXRC & rc) const
 void PrefConverters::updateRC(LyXRC const & rc)
 {
        cacheCB->setChecked(rc.use_converter_cache);
+       needauthForbiddenCB->setChecked(rc.use_converter_needauth_forbidden);
+       needauthCB->setChecked(rc.use_converter_needauth);
        QString max_age;
        doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
        updateGui();
@@ -1636,20 +1716,22 @@ void PrefConverters::updateRC(LyXRC const & rc)
 
 void PrefConverters::updateGui()
 {
+       QString const pattern("%1 -> %2");
        form_->formats().sort();
        form_->converters().update(form_->formats());
        // save current selection
-       QString current = converterFromCO->currentText()
-               + " -> " + converterToCO->currentText();
+       QString current =
+               pattern
+               .arg(converterFromCO->currentText())
+               .arg(converterToCO->currentText());
 
        converterFromCO->clear();
        converterToCO->clear();
 
-       Formats::const_iterator cit = form_->formats().begin();
-       Formats::const_iterator end = form_->formats().end();
-       for (; cit != end; ++cit) {
-               converterFromCO->addItem(qt_(cit->prettyname()));
-               converterToCO->addItem(qt_(cit->prettyname()));
+       for (Format const & f : form_->formats()) {
+               QString const name = toqstr(translateIfPossible(f.prettyname()));
+               converterFromCO->addItem(name);
+               converterToCO->addItem(name);
        }
 
        // currentRowChanged(int) is also triggered when updating the listwidget
@@ -1657,19 +1739,20 @@ void PrefConverters::updateGui()
        convertersLW->blockSignals(true);
        convertersLW->clear();
 
-       Converters::const_iterator ccit = form_->converters().begin();
-       Converters::const_iterator cend = form_->converters().end();
-       for (; ccit != cend; ++ccit) {
+       for (Converter const & c : form_->converters()) {
                QString const name =
-                       qt_(ccit->From()->prettyname()) + " -> " + qt_(ccit->To()->prettyname());
-               int type = form_->converters().getNumber(ccit->From()->name(), ccit->To()->name());
+                       pattern
+                       .arg(toqstr(translateIfPossible(c.From()->prettyname())))
+                       .arg(toqstr(translateIfPossible(c.To()->prettyname())));
+               int type = form_->converters().getNumber(c.From()->name(),
+                                                        c.To()->name());
                new QListWidgetItem(name, convertersLW, type);
        }
        convertersLW->sortItems(Qt::AscendingOrder);
        convertersLW->blockSignals(false);
 
        // restore selection
-       if (!current.isEmpty()) {
+       if (current != pattern.arg(QString()).arg(QString())) {
                QList<QListWidgetItem *> const item =
                        convertersLW->findItems(current, Qt::MatchExactly);
                if (!item.isEmpty())
@@ -1785,6 +1868,12 @@ void PrefConverters::on_cacheCB_stateChanged(int state)
 }
 
 
+void PrefConverters::on_needauthForbiddenCB_toggled(bool checked)
+{
+       needauthCB->setEnabled(!checked);
+}
+
+
 /////////////////////////////////////////////////////////////////////
 //
 // FormatValidator
@@ -1884,7 +1973,7 @@ public:
 private:
        QString toString(Format const & format) const
        {
-               return qt_(format.prettyname());
+               return toqstr(translateIfPossible(format.prettyname()));
        }
 };
 
@@ -1931,13 +2020,13 @@ PrefFileformats::PrefFileformats(GuiPreferences * form)
 
 namespace {
 
-string const l10n_shortcut(string const & prettyname, string const & shortcut)
+string const l10n_shortcut(docstring const & prettyname, string const & shortcut)
 {
        if (shortcut.empty())
                return string();
 
        string l10n_format =
-               to_utf8(_(prettyname + '|' + shortcut));
+               to_utf8(_(to_utf8(prettyname) + '|' + shortcut));
        return split(l10n_format, '|');
 }
 
@@ -1986,25 +2075,24 @@ void PrefFileformats::updateView()
        defaultFormatCB->clear();
        defaultOTFFormatCB->clear();
        form_->formats().sort();
-       Formats::const_iterator cit = form_->formats().begin();
-       Formats::const_iterator end = form_->formats().end();
-       for (; cit != end; ++cit) {
-               formatsCB->addItem(qt_(cit->prettyname()),
-                               QVariant(form_->formats().getNumber(cit->name())));
-               if (cit->viewer().empty())
+       for (Format const & f : form_->formats()) {
+               QString const prettyname = toqstr(translateIfPossible(f.prettyname()));
+               formatsCB->addItem(prettyname,
+                                  QVariant(form_->formats().getNumber(f.name())));
+               if (f.viewer().empty())
                        continue;
-               if (form_->converters().isReachable("xhtml", cit->name())
-                   || form_->converters().isReachable("dviluatex", cit->name())
-                   || form_->converters().isReachable("luatex", cit->name())
-                   || form_->converters().isReachable("xetex", cit->name())) {
-                       defaultFormatCB->addItem(qt_(cit->prettyname()),
-                                       QVariant(toqstr(cit->name())));
-                       defaultOTFFormatCB->addItem(qt_(cit->prettyname()),
-                                       QVariant(toqstr(cit->name())));
-               } else if (form_->converters().isReachable("latex", cit->name())
-                          || form_->converters().isReachable("pdflatex", cit->name()))
-                       defaultFormatCB->addItem(qt_(cit->prettyname()),
-                                       QVariant(toqstr(cit->name())));
+               if (form_->converters().isReachable("xhtml", f.name())
+                   || form_->converters().isReachable("dviluatex", f.name())
+                   || form_->converters().isReachable("luatex", f.name())
+                   || form_->converters().isReachable("xetex", f.name())) {
+                       defaultFormatCB->addItem(prettyname,
+                                       QVariant(toqstr(f.name())));
+                       defaultOTFFormatCB->addItem(prettyname,
+                                       QVariant(toqstr(f.name())));
+               } else if (form_->converters().isReachable("latex", f.name())
+                          || form_->converters().isReachable("pdflatex", f.name()))
+                       defaultFormatCB->addItem(prettyname,
+                                       QVariant(toqstr(f.name())));
        }
 
        // restore selections
@@ -2146,10 +2234,10 @@ void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
 void PrefFileformats::updatePrettyname()
 {
        QString const newname = formatsCB->currentText();
-       if (newname == qt_(currentFormat().prettyname()))
+       if (newname == toqstr(translateIfPossible(currentFormat().prettyname())))
                return;
 
-       currentFormat().setPrettyname(fromqstr(newname));
+       currentFormat().setPrettyname(qstring_to_ucs4(newname));
        formatsChanged();
        updateView();
        changed();
@@ -2251,7 +2339,7 @@ Format & PrefFileformats::currentFormat()
 
 void PrefFileformats::on_formatNewPB_clicked()
 {
-       form_->formats().add("", "", "", "", "", "", "", Format::none);
+       form_->formats().add("", "", docstring(), "", "", "", "", Format::none);
        updateView();
        formatsCB->setCurrentIndex(0);
        formatsCB->setFocus(Qt::OtherFocusReason);
@@ -3409,7 +3497,7 @@ void GuiPreferences::applyView()
 bool GuiPreferences::initialiseParams(string const &)
 {
        rc_ = lyxrc;
-       formats_ = lyx::formats;
+       formats_ = theFormats();
        converters_ = theConverters();
        converters_.update(formats_);
        movers_ = theMovers();
@@ -3440,12 +3528,13 @@ void GuiPreferences::dispatchParams()
                Author(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
        theBufferList().recordCurrentAuthor(author);
 
-       lyx::formats = formats_;
+       theFormats() = formats_;
 
        theConverters() = converters_;
-       theConverters().update(lyx::formats);
+       theConverters().update(formats_);
        theConverters().buildGraph();
-
+       theBufferList().invalidateConverterCache();
+       
        theMovers() = movers_;
 
        vector<string>::const_iterator it = colors_.begin();