From bfb0f4c03bdeaba5d3a2b02d0d85e4763d418d23 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 6 Aug 2016 15:01:34 +0200 Subject: [PATCH] Encode strftime output into utf-8 before displaying in GUI --- src/common/rclconfig.cpp | 5 +++++ src/common/rclconfig.h | 3 +++ src/qtgui/restable.cpp | 11 +++++++---- src/query/reslistpager.cpp | 11 +++++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 519bc387..fd767a79 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -520,6 +520,11 @@ vector RclConfig::getTopdirs() const return tdl; } +const string& RclConfig::getLocaleCharset() +{ + return o_localecharset; +} + // Get charset to be used for transcoding to utf-8 if unspecified by doc // For document contents: // If defcharset was set (from the config or a previous call, this diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 986dfebe..95a49c29 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -239,6 +239,9 @@ class RclConfig { static bool valueSplitAttributes(const string& whole, string& value, ConfSimple& attrs) ; + /** Return the locale's character set */ + static const std::string& getLocaleCharset(); + /** Return icon path for mime type and tag */ string getMimeIconPath(const string &mt, const string& apptag) const; diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 0e042323..2f477d85 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -49,6 +49,7 @@ #include "rclmain_w.h" #include "multisave.h" #include "appformime.h" +#include "transcode.h" static const QKeySequence quitKeySeq("Ctrl+q"); static const QKeySequence closeKeySeq("Ctrl+w"); @@ -177,15 +178,17 @@ static string sizegetter(const string& fld, const Rcl::Doc& doc) static string dategetter(const string&, const Rcl::Doc& doc) { - char datebuf[100]; - datebuf[0] = 0; + string sdate; if (!doc.dmtime.empty() || !doc.fmtime.empty()) { + char datebuf[100]; + datebuf[0] = 0; time_t mtime = doc.dmtime.empty() ? atoll(doc.fmtime.c_str()) : atoll(doc.dmtime.c_str()); struct tm *tm = localtime(&mtime); strftime(datebuf, 99, "%Y-%m-%d", tm); + transcode(datebuf, sdate, RclConfig::getLocaleCharset(), "UTF-8"); } - return datebuf; + return sdate; } static string datetimegetter(const string&, const Rcl::Doc& doc) @@ -196,7 +199,7 @@ static string datetimegetter(const string&, const Rcl::Doc& doc) time_t mtime = doc.dmtime.empty() ? atoll(doc.fmtime.c_str()) : atoll(doc.dmtime.c_str()); struct tm *tm = localtime(&mtime); - strftime(datebuf, 99, "%Y-%m-%d %H:%M:%S %z", tm); + strftime(datebuf, 99, prefs.creslistdateformat.c_str(), tm); } return datebuf; } diff --git a/src/query/reslistpager.cpp b/src/query/reslistpager.cpp index 44be35ef..e4379926 100644 --- a/src/query/reslistpager.cpp +++ b/src/query/reslistpager.cpp @@ -37,6 +37,7 @@ using std::list; #include "rclutil.h" #include "plaintorich.h" #include "mimehandler.h" +#include "transcode.h" // Default highlighter. No need for locking, this is query-only. static const string cstr_hlfontcolor(""); @@ -191,14 +192,16 @@ void ResListPager::displayDoc(RclConfig *config, int i, Rcl::Doc& doc, int docnumforlinks = m_winfirst + 1 + i; sprintf(numbuf, "%d", docnumforlinks); - // Document date: either doc or file modification time - char datebuf[100]; - datebuf[0] = 0; + // Document date: either doc or file modification times + string datebuf; if (!doc.dmtime.empty() || !doc.fmtime.empty()) { + char cdate[100]; + cdate[0] = 0; time_t mtime = doc.dmtime.empty() ? atoll(doc.fmtime.c_str()) : atoll(doc.dmtime.c_str()); struct tm *tm = localtime(&mtime); - strftime(datebuf, 99, dateFormat().c_str(), tm); + strftime(cdate, 99, dateFormat().c_str(), tm); + transcode(cdate, datebuf, RclConfig::getLocaleCharset(), "UTF-8"); } // Size information. We print both doc and file if they differ a lot