This commit is contained in:
Jean-Francois Dockes 2020-04-16 15:01:20 +02:00
commit ecd7fe4065
6 changed files with 31 additions and 17 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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

View File

@ -16,6 +16,7 @@
*/
#ifdef BUILDING_RECOLL
#include "autoconfig.h"
#include "transcode.h"
#else
#include "config.h"
#endif

View File

@ -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;

View File

@ -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();