mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:03:23 +00:00
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>
This commit is contained in:
parent
bfe5ccda1c
commit
4e263bae98
5 changed files with 118 additions and 18 deletions
|
@ -87,8 +87,12 @@ void init_ui(int *argcp, char ***argvp)
|
|||
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());
|
||||
xslt_path = strdup(getSubsurfaceDataPath("xslt").toAscii().data());
|
||||
|
||||
QLocale loc;
|
||||
QSettings s;
|
||||
s.beginGroup("Language");
|
||||
QLocale loc(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
|
||||
QString uiLang = loc.uiLanguages().first();
|
||||
s.endGroup();
|
||||
|
||||
// there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info
|
||||
if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) {
|
||||
QLocale loc2(loc.bcp47Name());
|
||||
|
@ -117,7 +121,6 @@ void init_ui(int *argcp, char ***argvp)
|
|||
}
|
||||
}
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup("DiveComputer");
|
||||
default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
|
||||
default_dive_computer_product = getSetting(s,"dive_computer_product");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Reference in a new issue