From d748af0299e20fafdab6c9813f7df56b7e795ba9 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 25 Jun 2008 13:32:27 +0000 Subject: [PATCH] Add a preference combo box for the preferred user interface language. The rc variable gui_language now require a language name and not its code. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25387 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyX.cpp | 5 +- src/LyXFunc.cpp | 3 + src/frontends/qt4/GuiPrefs.cpp | 30 ++- src/frontends/qt4/GuiPrefs.h | 3 + src/frontends/qt4/ui/PrefLanguageUi.ui | 320 +++++++++++++------------ 5 files changed, 205 insertions(+), 156 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index 6a6c140e1f..5ff73f64ea 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -347,8 +347,9 @@ void LyX::setRcGuiLanguage() { if (lyxrc.gui_language == "auto") return; - LYXERR(Debug::LOCALE, "Setting LANGUAGE to " << lyxrc.gui_language); - if (!setEnv("LANGUAGE", lyxrc.gui_language)) + Language const * language = languages.getLanguage(lyxrc.gui_language); + LYXERR(Debug::LOCALE, "Setting LANGUAGE to " << language->code()); + if (!setEnv("LANGUAGE", language->code())) LYXERR(Debug::LOCALE, "\t... failed!"); LYXERR(Debug::LOCALE, "Setting LC_ALL to en_US"); if (!setEnv("LC_ALL", "en_US")) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 79d67237de..6a3db5bb85 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1529,6 +1529,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) actOnUpdatedPrefs(lyxrc_orig, lyxrc); + // Set the language defined by the user. + LyX::ref().setRcGuiLanguage(); + theApp()->resetGui(); /// We force the redraw in any case because there might be diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index fc87c8de54..a0b815ed04 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1689,13 +1689,35 @@ PrefLanguage::PrefLanguage(GuiPreferences * form) this, SIGNAL(changed())); connect(defaultLanguageCO, SIGNAL(activated(int)), this, SIGNAL(changed())); + connect(uiLanguageCO, SIGNAL(activated(int)), + this, SIGNAL(changed())); defaultLanguageCO->clear(); + uiLanguageCO->clear(); QAbstractItemModel * language_model = guiApp->languageModel(); // FIXME: it would be nice if sorting was enabled/disabled via a checkbox. language_model->sort(0); defaultLanguageCO->setModel(language_model); + + // FIXME: This is wrong, we need filter this list based on the available + // translation. + uiLanguageCO->blockSignals(true); + uiLanguageCO->addItem(qt_("Default"), toqstr("auto")); + for (int i = 0; i != language_model->rowCount(); ++i) { + QModelIndex index = language_model->index(i, 0); + uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(), + index.data(Qt::UserRole).toString()); + } + uiLanguageCO->blockSignals(false); +} + + +void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int) +{ + QMessageBox::information(this, qt_("LyX needs to be restarted!"), + qt_("The change of user interface language will be fully " + "effective only after a restart.")); } @@ -1714,6 +1736,8 @@ void PrefLanguage::apply(LyXRC & rc) const rc.language_command_end = fromqstr(endCommandED->text()); rc.default_language = fromqstr( defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString()); + rc.gui_language = fromqstr( + uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString()); } @@ -1734,8 +1758,12 @@ void PrefLanguage::update(LyXRC const & rc) startCommandED->setText(toqstr(rc.language_command_begin)); endCommandED->setText(toqstr(rc.language_command_end)); - int const pos = defaultLanguageCO->findData(toqstr(rc.default_language)); + int pos = defaultLanguageCO->findData(toqstr(rc.default_language)); defaultLanguageCO->setCurrentIndex(pos); + pos = uiLanguageCO->findData(toqstr(rc.gui_language)); + uiLanguageCO->blockSignals(true); + uiLanguageCO->setCurrentIndex(pos); + uiLanguageCO->blockSignals(false); } diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index b9064d68dc..6aed28dfef 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -369,6 +369,9 @@ public: void apply(LyXRC & rc) const; void update(LyXRC const & rc); + +private Q_SLOTS: + void on_uiLanguageCO_currentIndexChanged(int); }; diff --git a/src/frontends/qt4/ui/PrefLanguageUi.ui b/src/frontends/qt4/ui/PrefLanguageUi.ui index 813baaa49a..3628bbe23e 100644 --- a/src/frontends/qt4/ui/PrefLanguageUi.ui +++ b/src/frontends/qt4/ui/PrefLanguageUi.ui @@ -12,14 +12,165 @@ - - - 9 - - - 6 - - + + + + + &User Interface language: + + + defaultLanguageCO + + + + + + + Select the default language of your documents + + + 20 + + + + + + + &Default language: + + + defaultLanguageCO + + + + + + + Select the default language of your documents + + + 20 + + + + + + + Language pac&kage: + + + languagePackageED + + + + + + + Enter the command to load the language package (default: babel) + + + + + + + Command s&tart: + + + startCommandED + + + + + + + The LaTeX command that starts a switch to a foreign language + + + + + + + Command e&nd: + + + endCommandED + + + + + + + The LaTeX command that ends a switch to a foreign language + + + + + + + Use the babel package for multilingual support + + + Use b&abel + + + + + + + Check to pass the language globally (to the document class), not locally (to the language package) + + + &Global + + + + + + + If checked, the document language is not explicitely set by a language switch command + + + Auto &begin + + + + + + + If checked, the document language is not explicitely closed by a language switch command + + + Auto &end + + + + + + + Check to highlight foreign languages visually in the work area + + + Mark &foreign languages + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 16 + + + + + @@ -55,7 +206,7 @@ Qt::Horizontal - + 101 20 @@ -65,12 +216,12 @@ - - 0 - 6 + + 0 + @@ -103,17 +254,7 @@ - - - - Check to highlight foreign languages visually in the work area - - - Mark &foreign languages - - - - + Qt::Vertical @@ -121,7 +262,7 @@ QSizePolicy::Expanding - + 20 20 @@ -129,43 +270,12 @@ - - - - Select the default language of your documents - - - 20 - - - - - - - The LaTeX command that starts a switch to a foreign language - - - - - - - Enter the command to load the language package (default: babel) - - - - - - - The LaTeX command that ends a switch to a foreign language - - - - + Qt::Horizontal - + 40 20 @@ -173,102 +283,6 @@ - - - - &Default language: - - - defaultLanguageCO - - - - - - - Language pac&kage: - - - languagePackageED - - - - - - - Command s&tart: - - - startCommandED - - - - - - - Command e&nd: - - - endCommandED - - - - - - - Check to pass the language globally (to the document class), not locally (to the language package) - - - &Global - - - - - - - If checked, the document language is not explicitely set by a language switch command - - - Auto &begin - - - - - - - If checked, the document language is not explicitely closed by a language switch command - - - Auto &end - - - - - - - Use the babel package for multilingual support - - - Use b&abel - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 16 - - - - -- 2.39.2