diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-12-06 14:29:38 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-06 09:49:05 -0800 |
commit | 4e263bae987bcc343497496bcdc962c292977b6a (patch) | |
tree | 9cf584fe5c83493356e64a0b17faae4bbb31ad55 /qt-ui | |
parent | bfe5ccda1ca50221828255e8f017a5f0180a020a (diff) | |
download | subsurface-4e263bae987bcc343497496bcdc962c292977b6a.tar.gz |
Added a language preference to the Settings.
When the user first opens the application the default language is
selected; this can be changed to a hardcoded one by going to system
preferences and choosing the one you want.
Restart required.
Fixes #136
[Dirk Hohndel: whitespace fixes, removed qDebug() call, rephrased the
message displayed prompting the user to restart.]
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/models.cpp | 51 | ||||
-rw-r--r-- | qt-ui/models.h | 14 | ||||
-rw-r--r-- | qt-ui/preferences.cpp | 19 | ||||
-rw-r--r-- | qt-ui/preferences.ui | 45 |
4 files changed, 113 insertions, 16 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 9950ed339..985d213f6 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -16,6 +16,8 @@ #include <QCoreApplication> #include <QDebug> +#include <QDir> +#include <QSettings> #include <QColor> #include <QBrush> #include <QFont> @@ -318,7 +320,7 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in int CylindersModel::rowCount(const QModelIndex& parent) const { - return rows; + return rows; } void CylindersModel::add() @@ -1750,3 +1752,50 @@ QVariant GasSelectionModel::data(const QModelIndex& index, int role) const } return QStringListModel::data(index, role); } + +// Language Model, The Model to populate the list of possible Languages. + +LanguageModel* LanguageModel::instance() +{ + static LanguageModel *self = new LanguageModel(); + QLocale l; + return self; +} + +LanguageModel::LanguageModel(QObject* parent): QAbstractListModel(parent) +{ + QSettings s; + QDir d; + d.setCurrent( getSubsurfaceDataPath("translations") ); + QStringList result = d.entryList(); + Q_FOREACH(const QString& s, result){ + if ( !s.endsWith(".qm") ){ + continue; + } + languages.push_back(s); + } +} + +QVariant LanguageModel::data(const QModelIndex& index, int role) const +{ + QLocale loc; + if(!index.isValid()) + return QVariant(); + switch(role){ + case Qt::DisplayRole:{ + QString currentString = languages.at(index.row()); + QLocale l( currentString.remove("subsurface_")); + return l.countryToString(l.country()); + }break; + case Qt::UserRole:{ + QString currentString = languages.at(index.row()); + return currentString.remove("subsurface_"); + }break; + } + return QVariant(); +} + +int LanguageModel::rowCount(const QModelIndex& parent) const +{ + return languages.count(); +} diff --git a/qt-ui/models.h b/qt-ui/models.h index 9dd7b2bf6..baa7b32c4 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -234,7 +234,7 @@ private: class YearlyStatisticsModel : public TreeModel { Q_OBJECT public: - enum { YEAR,DIVES,TOTAL_TIME,AVERAGE_TIME,SHORTEST_TIME,LONGEST_TIME,AVG_DEPTH,MIN_DEPTH, + enum { YEAR,DIVES,TOTAL_TIME,AVERAGE_TIME,SHORTEST_TIME,LONGEST_TIME,AVG_DEPTH,MIN_DEPTH, MAX_DEPTH,AVG_SAC,MIN_SAC,MAX_SAC,AVG_TEMP,MIN_TEMP,MAX_TEMP,COLUMNS}; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; @@ -312,4 +312,16 @@ public slots: void repopulate(); }; + +class LanguageModel : public QAbstractListModel { + Q_OBJECT +public: + static LanguageModel* instance(); + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; +private: + LanguageModel(QObject* parent = 0); + + QStringList languages; +}; #endif diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index f8b24da42..2155a710d 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -3,11 +3,13 @@ #include <QSettings> #include <QDebug> #include <QFileDialog> +#include <QMessageBox> PreferencesDialog* PreferencesDialog::instance() { static PreferencesDialog *dialog = new PreferencesDialog(mainWindow()); dialog->setAttribute(Qt::WA_QuitOnClose, false); + LanguageModel::instance(); return dialog; } @@ -107,6 +109,15 @@ void PreferencesDialog::setUiFromPrefs() ui.show_sac->setChecked(prefs.show_sac); ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); + + ui.languageView->setModel( LanguageModel::instance() ); + + QSettings s; + s.beginGroup("Language"); + QAbstractItemModel *m = ui.languageView->model(); + QModelIndexList languages = m->match( m->index(0,0), Qt::DisplayRole, s.value("UiLanguage").toString()); + if (languages.count()) + ui.languageView->setCurrentIndex(languages.first()); } void PreferencesDialog::restorePrefs() @@ -174,6 +185,14 @@ void PreferencesDialog::syncSettings() s.endGroup(); s.sync(); + QLocale loc; + s.beginGroup("Language"); + if (s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole)){ + QMessageBox::warning(mainWindow(), tr("Restart required"), + tr("To correctly load a new language you must restart Subsurface.")); + } + s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); + emit settingsChanged(); } diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui index 7b6f3e596..73632dc72 100644 --- a/qt-ui/preferences.ui +++ b/qt-ui/preferences.ui @@ -110,6 +110,16 @@ </iconset> </property> </item> + <item> + <property name="text"> + <string>Language</string> + </property> + <property name="icon"> + <iconset> + <normalon>:/advanced</normalon> + </iconset> + </property> + </item> </widget> </item> <item> @@ -121,7 +131,7 @@ </sizepolicy> </property> <property name="currentIndex"> - <number>1</number> + <number>0</number> </property> <widget class="QWidget" name="page_2"> <layout class="QVBoxLayout" name="verticalLayout_3"> @@ -301,7 +311,7 @@ <item row="0" column="1"> <widget class="QRadioButton" name="meter"> <property name="text"> - <string>meter</string> + <string>meter</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup</string> @@ -311,7 +321,7 @@ <item row="0" column="2"> <widget class="QRadioButton" name="feet"> <property name="text"> - <string>feet</string> + <string>feet</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup</string> @@ -328,7 +338,7 @@ <item row="1" column="1"> <widget class="QRadioButton" name="bar"> <property name="text"> - <string>bar</string> + <string>bar</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup_2</string> @@ -338,7 +348,7 @@ <item row="1" column="2"> <widget class="QRadioButton" name="psi"> <property name="text"> - <string>psi</string> + <string>psi</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup_2</string> @@ -355,7 +365,7 @@ <item row="2" column="1"> <widget class="QRadioButton" name="liter"> <property name="text"> - <string>liter</string> + <string>liter</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup_3</string> @@ -365,7 +375,7 @@ <item row="2" column="2"> <widget class="QRadioButton" name="cuft"> <property name="text"> - <string>cu ft</string> + <string>cu ft</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup_3</string> @@ -382,7 +392,7 @@ <item row="3" column="1"> <widget class="QRadioButton" name="celsius"> <property name="text"> - <string>celsius</string> + <string>celsius</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup_4</string> @@ -392,7 +402,7 @@ <item row="3" column="2"> <widget class="QRadioButton" name="fahrenheit"> <property name="text"> - <string>fahrenheit</string> + <string>fahrenheit</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup_4</string> @@ -409,7 +419,7 @@ <item row="4" column="1"> <widget class="QRadioButton" name="kgs"> <property name="text"> - <string>kg</string> + <string>kg</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup_5</string> @@ -497,7 +507,7 @@ <item> <widget class="QCheckBox" name="po2"> <property name="text"> - <string>pO₂</string> + <string>pO₂</string> </property> </widget> </item> @@ -538,7 +548,7 @@ <item> <widget class="QCheckBox" name="pn2"> <property name="text"> - <string>pN₂</string> + <string>pN₂</string> </property> </widget> </item> @@ -643,7 +653,7 @@ <bool>false</bool> </property> <property name="text"> - <string>max ppO₂</string> + <string>max ppO₂</string> </property> </widget> </item> @@ -817,6 +827,13 @@ </item> </layout> </widget> + <widget class="QWidget" name="page_4"> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QListView" name="languageView"/> + </item> + </layout> + </widget> </widget> </item> </layout> @@ -1098,9 +1115,9 @@ <buttongroup name="verticalSpeed"/> <buttongroup name="buttonGroup_2"/> <buttongroup name="buttonGroup_3"/> + <buttongroup name="buttonGroup"/> <buttongroup name="buttonGroup_4"/> <buttongroup name="buttonGroup_5"/> <buttongroup name="buttonGroup_6"/> - <buttongroup name="buttonGroup"/> </buttongroups> </ui> |