aboutsummaryrefslogtreecommitdiffstats
path: root/subsurface-core
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 /subsurface-core
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>
Diffstat (limited to 'subsurface-core')
-rw-r--r--subsurface-core/qthelper.cpp53
1 files changed, 34 insertions, 19 deletions
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;
}