@@ -112,6 +112,64 @@ Configuration::Configuration(QString file, QWidget *parent) :
112112 ui->fullscreenWidth ->setValue (display.width ());
113113 ui->fullscreenHeight ->setValue (display.height ());
114114 }
115+
116+ // Locale Stuff
117+ {
118+ QLocale locale;
119+ if (!config.value (" language" ).isValid ()) {
120+ QString name = locale.name ();
121+ name = name.replace (' _' , ' -' );
122+ int ind = ui->languages ->findData (langEquiv.value (name, name), Qt::UserRole, Qt::MatchExactly);
123+
124+ if (ind < 0 ) {
125+ QStringList languages = locale.uiLanguages ();
126+ for (QString lang : languages) {
127+ lang = lang.replace (' _' , ' -' );
128+ ind = ui->languages ->findData (langEquiv.value (lang, lang), Qt::UserRole, Qt::MatchExactly);
129+ if (ind >= 0 ) break ;
130+ }
131+ }
132+
133+ if (ind < 0 ) {
134+ QStringList languages = locale.uiLanguages ();
135+ for (QString lang : languages) {
136+ lang = lang.replace (' _' , ' -' );
137+ if (lang.contains (' -' )) lang.truncate (lang.indexOf (' -' ));
138+ ind = ui->languages ->findData (lang, Qt::UserRole, Qt::MatchStartsWith);
139+ if (ind >= 0 ) break ;
140+ }
141+ }
142+
143+ ui->languages ->setCurrentIndex (ind);
144+ }
145+ if (!config.value (" currency_format" ).isValid ()) {
146+ int ind = ui->currencies ->findData (locale.currencySymbol (QLocale::CurrencyIsoCode));
147+ if (ind >= 0 ) ui->currencies ->setCurrentIndex (ind);
148+ }
149+ if (!config.value (" measurement_format" ).isValid ()) {
150+ ui->measurements ->setCurrentIndex ((locale.measurementSystem () == QLocale::MetricSystem) ? 1 : 0 );
151+ }
152+ if (!config.value (" temperature_format" ).isValid ()) {
153+ ui->temperatures ->setCurrentIndex ((locale.measurementSystem () == QLocale::ImperialUSSystem) ? 1 : 0 );
154+ }
155+ if (!config.value (" date_format" ).isValid ()) {
156+ QString df = locale.dateFormat ();
157+ // dateFormat is not quite what we need, so I'll translate it
158+ int day = df.indexOf (' d' , 0 , Qt::CaseInsensitive);
159+ int month = df.indexOf (' M' , 0 , Qt::CaseInsensitive);
160+ int year = df.indexOf (' y' , 0 , Qt::CaseInsensitive);
161+ // Assume that if year is not first, it's last
162+ if (day >= 0 && month >= 0 && year >= 0 ) {
163+ if (month < day) {
164+ if (year < month) ui->dates ->setCurrentIndex (2 );
165+ else ui->dates ->setCurrentIndex (1 );
166+ } else {
167+ if (year < day) ui->dates ->setCurrentIndex (3 );
168+ else ui->dates ->setCurrentIndex (0 );
169+ }
170+ }
171+ }
172+ }
115173}
116174
117175Configuration::~Configuration ()
0 commit comments