summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-02 11:32:46 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-02 12:51:31 -0800
commit8a3fb854c2b835271cc03ea02e1046f2ec0fd5d5 (patch)
tree34f27142fce33c91a406b4c13b1349faba1fdec1
parentf85883c707e9d6c021025dfe406c9acfb6441e57 (diff)
downloadsubsurface-8a3fb854c2b835271cc03ea02e1046f2ec0fd5d5.tar.gz
Preferences: hook up the UI page with the preferences structure
With this the new date and time formats mostly work Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--desktop-widgets/preferences/preferences_language.cpp15
-rw-r--r--subsurface-core/qthelper.cpp53
2 files changed, 48 insertions, 20 deletions
diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp
index ec4eed471..1b5ee19a8 100644
--- a/desktop-widgets/preferences/preferences_language.cpp
+++ b/desktop-widgets/preferences/preferences_language.cpp
@@ -32,6 +32,11 @@ void PreferencesLanguage::refreshSettings()
QSettings s;
s.beginGroup("Language");
ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool());
+ ui->timeFormatSystemDefault->setChecked(!s.value("time_format_override", false).toBool());
+ ui->dateFormatSystemDefault->setChecked(!s.value("date_format_override", false).toBool());
+ ui->timeFormatEntry->setText(s.value("time_format").toString());
+ ui->dateFormatEntry->setText(s.value("date_format").toString());
+ ui->shortDateFormatEntry->setText(s.value("date_format_short").toString());
QAbstractItemModel *m = ui->languageDropdown->model();
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString());
if (languages.count())
@@ -51,7 +56,15 @@ void PreferencesLanguage::syncSettings()
QMessageBox::warning(this, tr("Restart required"),
tr("To correctly load a new language you must restart Subsurface."));
}
- s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked());
s.setValue("UiLanguage", currentText);
+ s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked());
+ s.setValue("time_format_override", !ui->timeFormatSystemDefault->isChecked());
+ s.setValue("date_format_override", !ui->dateFormatSystemDefault->isChecked());
+ if (!ui->timeFormatSystemDefault->isChecked())
+ s.setValue("time_format", ui->timeFormatEntry->text());
+ if (!ui->dateFormatSystemDefault->isChecked()) {
+ s.setValue("date_format", ui->dateFormatEntry->text());
+ s.setValue("date_format_short", ui->shortDateFormatEntry->text());
+ }
s.endGroup();
}
diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp
index a91e1aae2..40c507a7e 100644
--- a/subsurface-core/qthelper.cpp
+++ b/subsurface-core/qthelper.cpp
@@ -722,6 +722,7 @@ QString uiLanguage(QLocale *callerLoc)
QString dateFormat;
QString timeFormat;
QSettings s;
+ QVariant v;
s.beginGroup("Language");
if (!s.value("UseSystemLanguage", true).toBool()) {
@@ -731,6 +732,11 @@ QString uiLanguage(QLocale *callerLoc)
}
QString uiLang = loc.uiLanguages().first();
+ GET_BOOL("time_format_override", time_format_override);
+ GET_BOOL("date_format_override", date_format_override);
+ GET_TXT("time_format", time_format);
+ GET_TXT("date_format", date_format);
+ GET_TXT("date_format_short", date_format_short);
s.endGroup();
// there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info
@@ -742,24 +748,33 @@ QString uiLanguage(QLocale *callerLoc)
if (callerLoc)
*callerLoc = loc;
- // the short format is fine
- // the long format uses long weekday and month names, so replace those with the short ones
- // for time we don't want the time zone designator and don't want leading zeroes on the hours
- shortDateFormat = loc.dateFormat(QLocale::ShortFormat);
- dateFormat = loc.dateFormat(QLocale::LongFormat);
- dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM");
- // special hack for Swedish as our switching from long weekday names to short weekday names
- // messes things up there
- dateFormat.replace("'en' 'den' d:'e'", " d");
- timeFormat = loc.timeFormat();
- timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", "");
- timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", "");
- free((void*)prefs.time_format);
- prefs.time_format = strdup(qPrintable(timeFormat));
- free((void*)prefs.date_format);
- prefs.date_format = strdup(qPrintable(dateFormat));
- free((void*)prefs.date_format_short);
- prefs.date_format_short = strdup(qPrintable(shortDateFormat));
+ if (!prefs.date_format_override || same_string(prefs.date_format_short, "") || same_string(prefs.date_format, "")) {
+ // derive our standard date format from what the locale gives us
+ // the short format is fine
+ // the long format uses long weekday and month names, so replace those with the short ones
+ // for time we don't want the time zone designator and don't want leading zeroes on the hours
+ shortDateFormat = loc.dateFormat(QLocale::ShortFormat);
+ dateFormat = loc.dateFormat(QLocale::LongFormat);
+ dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM");
+ // special hack for Swedish as our switching from long weekday names to short weekday names
+ // messes things up there
+ dateFormat.replace("'en' 'den' d:'e'", " d");
+ if (!prefs.date_format_override || same_string(prefs.date_format, "")) {
+ free((void*)prefs.date_format);
+ prefs.date_format = strdup(qPrintable(dateFormat));
+ }
+ if (!prefs.date_format_override || same_string(prefs.date_format_short, "")) {
+ free((void*)prefs.date_format_short);
+ prefs.date_format_short = strdup(qPrintable(shortDateFormat));
+ }
+ }
+ if (!prefs.time_format_override || same_string(prefs.time_format, "")) {
+ timeFormat = loc.timeFormat();
+ timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", "");
+ timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", "");
+ free((void*)prefs.time_format);
+ prefs.time_format = strdup(qPrintable(timeFormat));
+ }
return uiLang;
}
@@ -1078,7 +1093,7 @@ QString get_trip_date_string(timestamp_t when, int nr, bool getday)
QString suffix = " " + QObject::tr("(%n dive(s))", "", nr);
if (getday) {
- ret = localTime.date().toString(dateFormat) + suffix;
+ ret = localTime.date().toString(prefs.date_format) + suffix;
} else {
ret = localTime.date().toString("MMM yy") + suffix;
}