diff --git a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp index aa4769ab..852a9493 100644 --- a/src/qtgui/preview_w.cpp +++ b/src/qtgui/preview_w.cpp @@ -491,23 +491,21 @@ void Preview::setCurTabProps(const Rcl::Doc &doc, int docnum) int curidx = pvTab->currentIndex(); pvTab->setTabText(curidx, title); - char datebuf[100]; - datebuf[0] = 0; + string datebuf; if (!doc.fmtime.empty() || !doc.dmtime.empty()) { 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", tm); + datebuf = utf8datestring("%Y-%m-%d %H:%M:%S", tm); } LOGDEB("Doc.url: [" << doc.url << "]\n"); string url; printableUrl(theconfig->getDefCharset(), doc.url, url); string tiptxt = url + string("\n"); - tiptxt += doc.mimetype + " " + string(datebuf) + "\n"; + tiptxt += doc.mimetype + " " + datebuf + "\n"; if (!ctitle.empty()) tiptxt += ctitle + "\n"; - pvTab->setTabToolTip(curidx, - QString::fromUtf8(tiptxt.c_str(), tiptxt.length())); + pvTab->setTabToolTip(curidx, u8s2qs(tiptxt)); PreviewTextEdit *e = currentEditor(); if (e) { diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 270a4773..6241e911 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -194,26 +194,22 @@ static string dategetter(const string&, const Rcl::Doc& doc) { 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"); + sdate = utf8datestring("%Y-%m-%d", tm); } return sdate; } static string datetimegetter(const string&, const Rcl::Doc& doc) { - char datebuf[100]; - datebuf[0] = 0; + string datebuf; if (!doc.dmtime.empty() || !doc.fmtime.empty()) { time_t mtime = doc.dmtime.empty() ? atoll(doc.fmtime.c_str()) : atoll(doc.dmtime.c_str()); struct tm *tm = localtime(&mtime); - strftime(datebuf, 99, prefs.creslistdateformat.c_str(), tm); + datebuf = utf8datestring(prefs.creslistdateformat.c_str(), tm); } return datebuf; } diff --git a/src/query/reslistpager.cpp b/src/query/reslistpager.cpp index 438a7465..5a9b4b36 100644 --- a/src/query/reslistpager.cpp +++ b/src/query/reslistpager.cpp @@ -196,13 +196,10 @@ void ResListPager::displayDoc(RclConfig *config, int i, Rcl::Doc& doc, // 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(cdate, 99, dateFormat().c_str(), tm); - transcode(cdate, datebuf, RclConfig::getLocaleCharset(), "UTF-8"); + datebuf = utf8datestring(dateFormat(), tm); } // Size information. We print both doc and file if they differ a lot diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index 94ce2922..15eacd96 100644 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -16,6 +16,7 @@ */ #ifdef BUILDING_RECOLL #include "autoconfig.h" +#include "transcode.h" #else #include "config.h" #endif diff --git a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp index 3e22cdea..af1a7f84 100644 --- a/src/utils/rclutil.cpp +++ b/src/utils/rclutil.cpp @@ -49,6 +49,7 @@ #include "md5ut.h" #include "log.h" #include "smallut.h" +#include "rclconfig.h" using namespace std; @@ -277,6 +278,23 @@ string url_gpathS(const string& url) #endif } +std::string utf8datestring(const std::string& format, struct tm *tm) +{ + string u8date; +#ifdef _WIN32 + wchar_t wformat[200]; + utf8towchar(format, wformat, 199); + wchar_t wdate[250]; + wcsftime(wdate, 250, wformat, tm); + wchartoutf8(wformat, u8date); +#else + char datebuf[200]; + strftime(datebuf, 199, format.c_str(), tm); + transcode(datebuf, u8date, RclConfig::getLocaleCharset(), "UTF-8"); +#endif + return u8date; +} + const string& tmplocation() { static string stmpdir; diff --git a/src/utils/rclutil.h b/src/utils/rclutil.h index 4d2f3910..f1226575 100644 --- a/src/utils/rclutil.h +++ b/src/utils/rclutil.h @@ -47,6 +47,10 @@ extern bool printableUrl(const std::string& fcharset, /// "/c/" This should be used only for splitting the path in rcldb. extern std::string url_gpathS(const std::string& url); +/// Like strftime but guaranteed utf-8 output (esp. useful on Windows) +struct tm; +extern std::string utf8datestring(const std::string& format, struct tm *tm); + /// Retrieve the temp dir location: $RECOLL_TMPDIR else $TMPDIR else /tmp extern const std::string& tmplocation();