Mercurial > hg > octave-lyh
changeset 15972:22ab4fe661d7
gui: selectable language in settings dialog
* octave-gui.cc(octave_start_gu): install translators for gui and qt strings
* resource-manager.cc(get_gui_translation_dir): new function returning the
directory of the translator files
* resource-manager.cc(config_translators): new function replacing
find_trnaslator_file and configuring the translators for gui and qt strings
* resource-manager.h: declaration of new function in resource-manager.cc
* settings-dialog.ui: new combo box for selecting the desired language
* settings-dialog.cc(settings_dialog): look for available translator files and
the actual language setting and fill the language combo box
* settings-dialog.cc(write_changed_settings): get the selected element from
the language combo box and write the selection into the settings file
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 19 Jan 2013 16:21:55 +0100 |
parents | e27d9b9b71f4 |
children | a0b313c17a6b |
files | libgui/src/octave-gui.cc libgui/src/resource-manager.cc libgui/src/resource-manager.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.ui |
diffstat | 5 files changed, 170 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/octave-gui.cc +++ b/libgui/src/octave-gui.cc @@ -26,7 +26,6 @@ #include <QtGui/QApplication> #include <QTranslator> -#include <QSettings> #include <iostream> @@ -95,21 +94,19 @@ } else { - QSettings *settings = resource_manager::get_settings (); - - // FIXME -- what should happen if settings is 0? - - QString language = settings->value ("language").toString (); + // install translators for the gui and qt text + QTranslator gui_translator, qt_translator; + resource_manager::config_translators (&gui_translator,&qt_translator); + application.installTranslator (&qt_translator); + application.installTranslator (&gui_translator); - QString translatorFile = resource_manager::find_translator_file (language); - QTranslator translator; - translator.load (translatorFile); - application.installTranslator (&translator); - + // update network-settings resource_manager::update_network_settings (); + // create main window, read settings, and show window main_window w; - w.read_settings (); // Get the widget settings after construction and before showing + w.read_settings (); // get widget settings after construction + // but before showing w.show (); w.focus_command_window ();
--- a/libgui/src/resource-manager.cc +++ b/libgui/src/resource-manager.cc @@ -29,6 +29,7 @@ #include <QFile> #include <QDir> #include <QNetworkProxy> + #include <QLibraryInfo> #include "error.h" #include "file-ops.h" @@ -52,11 +53,31 @@ delete settings; } + QString -resource_manager::find_translator_file (const QString& language) +resource_manager::get_gui_translation_dir (void) { - // TODO: Quick hack to be able to test language files. - return QString ("libgui/languages/%1.qm").arg (language); + // get environment variable for the locale dir (e.g. from run-octave) + std::string dldir = octave_env::getenv ("OCTAVE_LOCALE_DIR"); + if (dldir.empty ()) + dldir = Voct_locale_dir; // env-var empty, load the default location + return QString::fromStdString (dldir); +} + +void +resource_manager::config_translators (QTranslator *qt_tr,QTranslator *gui_tr) +{ + QSettings *settings = resource_manager::get_settings (); + // FIXME -- what should happen if settings is 0? + // get the locale from the settings + QString language = settings->value ("language","SYSTEM").toString (); + if (language == "SYSTEM") + language = QLocale::system().name(); // get system wide locale + // load the translator file for qt strings + qt_tr->load("qt_" + language, + QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + // load the translator file for gui strings + gui_tr->load (language, get_gui_translation_dir ()); } bool
--- a/libgui/src/resource-manager.h +++ b/libgui/src/resource-manager.h @@ -27,7 +27,7 @@ #include <QIcon> #include <QMap> #include <QSettings> - +#include <QTranslator> class resource_manager { @@ -61,7 +61,9 @@ instance->do_set_settings (file); } - static QString find_translator_file (const QString& language); + static QString get_gui_translation_dir (void); + + static void config_translators (QTranslator*, QTranslator*); static void update_network_settings (void) {
--- a/libgui/src/settings-dialog.cc +++ b/libgui/src/settings-dialog.cc @@ -28,6 +28,8 @@ #include "settings-dialog.h" #include "ui-settings-dialog.h" #include <QSettings> +#include <QDir> +#include <QFileInfo> settings_dialog::settings_dialog (QWidget *p): QDialog (p), ui (new Ui::settings_dialog) @@ -35,9 +37,28 @@ ui->setupUi (this); QSettings *settings = resource_manager::get_settings (); - // FIXME -- what should happen if settings is 0? + // look for available language files and the actual settings + QString qm_dir_name = resource_manager::get_gui_translation_dir (); + QDir qm_dir (qm_dir_name); + QFileInfoList qm_files = qm_dir.entryInfoList (QStringList ("*.qm"), + QDir::Files | QDir::Readable, + QDir::Name); + for (int i = 0; i < qm_files.length (); i++) // insert available languages + ui->comboBox_language->addItem (qm_files.at (i).baseName ()); + ui->comboBox_language->insertItem (0,tr("System setting")); // System at beginning + ui->comboBox_language->insertSeparator (1); // separator after System + QString language = settings->value ("language","SYSTEM").toString (); + if (language == "SYSTEM") + language = tr("System setting"); + int selected = ui->comboBox_language->findText (language); + if (selected >= 0) + ui->comboBox_language->setCurrentIndex (selected); + else + ui->comboBox_language->setCurrentIndex (0); // System is default + + // which icon has to be selected QString widget_icon_set = settings->value ("DockWidgets/widget_icon_set","NONE").toString (); ui->general_icon_octave-> setChecked (true); // the default (if invalid set) @@ -104,15 +125,23 @@ settings_dialog::write_changed_settings () { QSettings *settings = resource_manager::get_settings (); - // FIXME -- what should happen if settings is 0? + // the icon set QString widget_icon_set = "NONE"; if (ui->general_icon_letter->isChecked ()) widget_icon_set = "LETTER"; else if (ui->general_icon_graphic->isChecked ()) widget_icon_set = "GRAPHIC"; settings->setValue ("DockWidgets/widget_icon_set",widget_icon_set); + + // language + QString language = ui->comboBox_language->currentText (); + if (language == tr("System setting")) + language = "SYSTEM"; + settings->setValue ("language", language); + + // other settings settings->setValue ("useCustomFileEditor", ui->useCustomFileEditor->isChecked ()); settings->setValue ("customFileEditor", ui->customFileEditor->text ()); settings->setValue ("editor/showLineNumbers", ui->editor_showLineNumbers->isChecked ()); @@ -138,6 +167,7 @@ settings->setValue ("proxyPassword", ui->proxyPassword->text ()); settings->setValue ("terminal/cursorBlinking", ui->terminal_cursorBlinking->isChecked ()); + // the cursor QString cursorType; switch (ui->terminal_cursorType->currentIndex ()) {
--- a/libgui/src/settings-dialog.ui +++ b/libgui/src/settings-dialog.ui @@ -41,75 +41,112 @@ <attribute name="title"> <string>General</string> </attribute> - <widget class="QGroupBox" name="groupBox"> + <widget class="QWidget" name="verticalLayoutWidget"> <property name="geometry"> <rect> - <x>10</x> + <x>9</x> <y>10</y> - <width>551</width> - <height>81</height> + <width>561</width> + <height>131</height> </rect> </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="title"> - <string>Icon set for dock widget</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> - </property> - <property name="flat"> - <bool>false</bool> - </property> - <property name="checkable"> - <bool>false</bool> - </property> - <widget class="QRadioButton" name="general_icon_octave"> - <property name="geometry"> - <rect> - <x>0</x> - <y>20</y> - <width>151</width> - <height>21</height> - </rect> - </property> - <property name="text"> - <string>Octave logo only</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - <widget class="QRadioButton" name="general_icon_letter"> - <property name="geometry"> - <rect> - <x>0</x> - <y>40</y> - <width>151</width> - <height>21</height> - </rect> - </property> - <property name="text"> - <string>Letter icons</string> - </property> - </widget> - <widget class="QRadioButton" name="general_icon_graphic"> - <property name="geometry"> - <rect> - <x>0</x> - <y>60</y> - <width>151</width> - <height>21</height> - </rect> - </property> - <property name="text"> - <string>Graphic icons</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout_7"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Language (requires restart)</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="comboBox_language"> + <property name="insertPolicy"> + <enum>QComboBox::InsertAtBottom</enum> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Icon set for dock widgets</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="flat"> + <bool>false</bool> + </property> + <property name="checkable"> + <bool>false</bool> + </property> + <widget class="QRadioButton" name="general_icon_octave"> + <property name="geometry"> + <rect> + <x>0</x> + <y>20</y> + <width>151</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>Octave logo only</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QRadioButton" name="general_icon_letter"> + <property name="geometry"> + <rect> + <x>0</x> + <y>40</y> + <width>151</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>Letter icons</string> + </property> + </widget> + <widget class="QRadioButton" name="general_icon_graphic"> + <property name="geometry"> + <rect> + <x>0</x> + <y>60</y> + <width>151</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>Graphic icons</string> + </property> + </widget> + </widget> + </item> + </layout> </widget> </widget> <widget class="QWidget" name="tab">