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/models.cpp | |
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/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 51 |
1 files changed, 50 insertions, 1 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(); +} |