diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-10-29 16:57:43 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-11-02 12:51:31 -0800 |
commit | f85883c707e9d6c021025dfe406c9acfb6441e57 (patch) | |
tree | 06312dea8132dd0595b360c923ddde9d5de3e736 | |
parent | 222ce62bceac4c7f95e7a0564f11b5789dc18d29 (diff) | |
download | subsurface-f85883c707e9d6c021025dfe406c9acfb6441e57.tar.gz |
Create date and time formats preferences
Now we can actually change them in preferences instead of just deriving
them from the language set.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | desktop-widgets/diveplanner.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/maintab.cpp | 2 | ||||
-rw-r--r-- | subsurface-core/helpers.h | 1 | ||||
-rw-r--r-- | subsurface-core/pref.h | 5 | ||||
-rw-r--r-- | subsurface-core/qthelper.cpp | 24 | ||||
-rw-r--r-- | subsurface-core/subsurfacestartup.c | 3 |
6 files changed, 23 insertions, 14 deletions
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 86f03b1d2..fd14944f0 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -104,7 +104,7 @@ void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { ui.setupUi(this); - ui.dateEdit->setDisplayFormat(getDateFormat()); + ui.dateEdit->setDisplayFormat(prefs.date_format); ui.tableWidget->setTitle(tr("Dive planner points")); ui.tableWidget->setModel(plannerModel); plannerModel->setRecalc(true); diff --git a/desktop-widgets/maintab.cpp b/desktop-widgets/maintab.cpp index 4d4cd3a5e..c7961735a 100644 --- a/desktop-widgets/maintab.cpp +++ b/desktop-widgets/maintab.cpp @@ -43,7 +43,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), currentTrip(0) { ui.setupUi(this); - ui.dateEdit->setDisplayFormat(getDateFormat()); + ui.dateEdit->setDisplayFormat(prefs.date_format); memset(&displayed_dive, 0, sizeof(displayed_dive)); memset(&displayedTrip, 0, sizeof(displayedTrip)); diff --git a/subsurface-core/helpers.h b/subsurface-core/helpers.h index 5f2f2f2c5..b5c119870 100644 --- a/subsurface-core/helpers.h +++ b/subsurface-core/helpers.h @@ -40,7 +40,6 @@ bool is_same_day (timestamp_t trip_when, timestamp_t dive_when); QString get_trip_date_string(timestamp_t when, int nr, bool getday); QString uiLanguage(QLocale *callerLoc); QLocale getLocale(); -QString getDateFormat(); void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsed); QString getUserAgent(); diff --git a/subsurface-core/pref.h b/subsurface-core/pref.h index 84975aaaa..9f5f587e2 100644 --- a/subsurface-core/pref.h +++ b/subsurface-core/pref.h @@ -44,6 +44,11 @@ struct preferences { const char *default_cylinder; const char *cloud_base_url; const char *cloud_git_url; + const char *time_format; + const char *date_format; + const char *date_format_short; + bool time_format_override; + bool date_format_override; double font_size; partial_pressure_graphs_t pp_graphs; short mod; diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index a12d25333..a91e1aae2 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -33,9 +33,6 @@ #include <libxslt/documents.h> const char *existing_filename; -static QString shortDateFormat; -static QString dateFormat; -static QString timeFormat; static QLocale loc; #define translate(_context, arg) trGettext(arg) @@ -168,8 +165,8 @@ void Dive::put_date_time() { QDateTime localTime = QDateTime::fromTime_t(dive->when - gettimezoneoffset(displayed_dive.when)); localTime.setTimeSpec(Qt::UTC); - m_date = localTime.date().toString(dateFormat); - m_time = localTime.time().toString(timeFormat); + m_date = localTime.date().toString(prefs.date_format); + m_time = localTime.time().toString(prefs.time_format); } void Dive::put_timestamp() @@ -721,6 +718,9 @@ QString getUserAgent() QString uiLanguage(QLocale *callerLoc) { + QString shortDateFormat; + QString dateFormat; + QString timeFormat; QSettings s; s.beginGroup("Language"); @@ -754,6 +754,12 @@ QString uiLanguage(QLocale *callerLoc) 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)); return uiLang; } @@ -762,10 +768,6 @@ QLocale getLocale() return loc; } -QString getDateFormat() -{ - return dateFormat; -} void set_filename(const char *filename, bool force) { if (!force && existing_filename) @@ -1034,14 +1036,14 @@ QString get_dive_date_string(timestamp_t when) { QDateTime ts; ts.setMSecsSinceEpoch(when * 1000L); - return loc.toString(ts.toUTC(), dateFormat + " " + timeFormat); + return loc.toString(ts.toUTC(), QString(prefs.date_format) + " " + prefs.time_format); } QString get_short_dive_date_string(timestamp_t when) { QDateTime ts; ts.setMSecsSinceEpoch(when * 1000L); - return loc.toString(ts.toUTC(), shortDateFormat + " " + timeFormat); + return loc.toString(ts.toUTC(), QString(prefs.date_format_short) + " " + prefs.time_format); } const char *get_dive_date_c_string(timestamp_t when) diff --git a/subsurface-core/subsurfacestartup.c b/subsurface-core/subsurfacestartup.c index 1286885ee..0bde2a070 100644 --- a/subsurface-core/subsurfacestartup.c +++ b/subsurface-core/subsurfacestartup.c @@ -291,6 +291,9 @@ void copy_prefs(struct preferences *src, struct preferences *dest) dest->proxy_host = copy_string(src->proxy_host); dest->proxy_user = copy_string(src->proxy_user); dest->proxy_pass = copy_string(src->proxy_pass); + dest->time_format = copy_string(src->time_format); + dest->date_format = copy_string(src->date_format); + dest->date_format_short = copy_string(src->date_format_short); dest->cloud_storage_password = copy_string(src->cloud_storage_password); dest->cloud_storage_newpassword = copy_string(src->cloud_storage_newpassword); dest->cloud_storage_email = copy_string(src->cloud_storage_email); |