Commit 2a091e87 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

Result list: if a thumbnail exists for the result, display it instead of the file type icon

parent 4cd65b98
......@@ -84,8 +84,10 @@ src/sampleconf/rclmon.sh
src/sampleconf/recoll.conf
tests/config/aspdict.en.rws
tests/config/history
tests/config/idxstatus.txt
tests/config/index.pid
tests/config/missing
tests/config/xapiandb
tests/indexedmimetypes/idxstatus.txt
tests/indexedmimetypes/index.pid
website/usermanual/*
......@@ -37,7 +37,7 @@ RclDynConf *g_dynconf;
// introducing blank space.
const char *PrefsPack::dfltResListFormat =
#if 1
"<table><tr><td><img src='%I'></td>"
"<table><tr><td><img src='%I' width='64'></td>"
"<td>%R %S %L &nbsp;&nbsp;<b>%T</b><br>"
"%M&nbsp;%D&nbsp;&nbsp;&nbsp;<i>%U</i><br>"
"%A %K</td></tr></table>"
......@@ -49,10 +49,10 @@ const char *PrefsPack::dfltResListFormat =
#endif
;
const char *v114reslistformat = "<img src=\"%I\" align=\"left\">"
"%R %S %L &nbsp;&nbsp;<b>%T</b><br>"
"%M&nbsp;%D&nbsp;&nbsp;&nbsp;<i>%U</i>&nbsp;%i<br>"
"%A %K";
const char* v162reslistformat="<table><tr><td><img src='%I'></td>"
"<td>%R %S %L &nbsp;&nbsp;<b>%T</b><br>"
"%M&nbsp;%D&nbsp;&nbsp;&nbsp;<i>%U</i><br>"
"%A %K</td></tr></table>";
// The global preferences structure
......@@ -151,7 +151,7 @@ void rwSettings(bool writing)
// If the current value of the format is the default for the
// previous version, replace it with the new default. We
// should have a flag to say if it was changed instead
if (!prefs.creslistformat.compare(v114reslistformat)) {
if (!prefs.creslistformat.compare(v162reslistformat)) {
LOGDEB(("Replacing old default format\n"));
prefs.reslistformat = rlfDflt;
prefs.creslistformat = (const char*)prefs.reslistformat.toUtf8();
......
......@@ -49,6 +49,7 @@
#include "plaintorich.h"
#include "refcntr.h"
#include "internfile.h"
#include "indexer.h"
#include "reslist.h"
#include "moc_reslist.cpp"
......@@ -75,9 +76,9 @@ public:
virtual string nextUrl();
virtual string prevUrl();
virtual string pageTop();
virtual string iconPath(const string& mt);
virtual void suggest(const vector<string>uterms, vector<string>&sugg);
virtual string absSep() {return (const char *)(prefs.abssep.toUtf8());}
virtual string iconUrl(RclConfig *, Rcl::Doc& doc);
private:
ResList *m_parent;
};
......@@ -161,12 +162,6 @@ string QtGuiResListPager::pageTop()
return string();
}
string QtGuiResListPager::iconPath(const string& mtype)
{
string iconpath;
theconfig->getMimeIconName(mtype, &iconpath);
return iconpath;
}
void QtGuiResListPager::suggest(const vector<string>uterms, vector<string>&sugg)
{
......@@ -200,6 +195,24 @@ void QtGuiResListPager::suggest(const vector<string>uterms, vector<string>&sugg)
#endif
}
string QtGuiResListPager::iconUrl(RclConfig *config, Rcl::Doc& doc)
{
if (doc.ipath.empty()) {
vector<Rcl::Doc> docs;
docs.push_back(doc);
vector<string> paths;
ConfIndexer::docsToPaths(docs, paths);
if (!paths.empty()) {
string path;
if (thumbPathForUrl(cstr_fileu + paths[0], 128, path)) {
return cstr_fileu + path;
}
}
}
return ResListPager::iconUrl(config, doc);
}
/////// /////// End reslistpager methods
class PlainToRichQtReslist : public PlainToRich {
......
......@@ -45,6 +45,7 @@
#include "reslist.h"
#include "rclconfig.h"
#include "plaintorich.h"
#include "indexer.h"
// Compensate for the default and somewhat bizarre vertical placement
// of text in cells
......@@ -77,8 +78,8 @@ public:
virtual bool append(const string& data, int idx, const Rcl::Doc& doc);
virtual string trans(const string& in);
virtual const string &parFormat();
virtual string iconPath(const string& mt);
virtual string absSep() {return (const char *)(prefs.abssep.toUtf8());}
virtual string iconUrl(RclConfig *, Rcl::Doc& doc);
private:
ResTable *m_parent;
};
......@@ -102,11 +103,21 @@ const string& ResTablePager::parFormat()
return prefs.creslistformat;
}
string ResTablePager::iconPath(const string& mtype)
string ResTablePager::iconUrl(RclConfig *config, Rcl::Doc& doc)
{
string iconpath;
theconfig->getMimeIconName(mtype, &iconpath);
return iconpath;
if (doc.ipath.empty()) {
vector<Rcl::Doc> docs;
docs.push_back(doc);
vector<string> paths;
ConfIndexer::docsToPaths(docs, paths);
if (!paths.empty()) {
string path;
if (thumbPathForUrl(cstr_fileu + paths[0], 128, path)) {
return cstr_fileu + path;
}
}
}
return ResListPager::iconUrl(config, doc);
}
/////////////////////////////////////////////////////////////////////////////
......
......@@ -138,7 +138,7 @@ void ResListPager::displayDoc(RclConfig *config,
}
// Determine icon to display if any
string iconpath = iconPath(config, doc.mimetype);
string iconurl = iconUrl(config, doc);
// Printable url: either utf-8 if transcoding succeeds, or url-encoded
string url;
......@@ -225,7 +225,7 @@ void ResListPager::displayDoc(RclConfig *config,
map<string,string> subs;
subs["A"] = !richabst.empty() ? richabst : "";
subs["D"] = datebuf;
subs["I"] = iconpath;
subs["I"] = iconurl;
subs["i"] = doc.ipath;
subs["K"] = !doc.meta[Rcl::Doc::keykw].empty() ?
string("[") + escapeHtml(doc.meta[Rcl::Doc::keykw]) + "]" : "";
......@@ -379,12 +379,12 @@ string ResListPager::prevUrl()
return "p-1";
}
string ResListPager::iconPath(RclConfig *config, const string& mtype)
string ResListPager::iconUrl(RclConfig *config, Rcl::Doc& doc)
{
string iconpath;
config->getMimeIconName(mtype, &iconpath);
iconpath = cstr_fileu + iconpath;
return iconpath;
string iconurl;
config->getMimeIconName(doc.mimetype, &iconurl);
iconurl = cstr_fileu + iconurl;
return iconurl;
}
bool ResListPager::append(const string& data)
......
......@@ -110,7 +110,7 @@ public:
virtual string nextUrl();
virtual string prevUrl();
virtual string pageTop() {return string();}
virtual string iconPath(RclConfig *, const string& mtype);
virtual string iconUrl(RclConfig *, Rcl::Doc& doc);
virtual void suggest(const vector<string>, vector<string>&sugg) {
sugg.clear();
}
......
......@@ -58,6 +58,7 @@ using std::stack;
#include "pathut.h"
#include "transcode.h"
#include "wipedir.h"
#include "md5.h"
bool fsocc(const string &path, int *pc, long *blocks)
{
......@@ -559,6 +560,47 @@ int Pidfile::remove()
return unlink(m_path.c_str());
}
// Freedesktop standard paths for thumbnails
// Place for 256x256 files
static const string thmbdirlarge = ".thumbnails/large";
// 128x128
static const string thmbdirnormal = ".thumbnails/normal";
static void thumbname(const string& url, string& name)
{
string digest;
MD5String(url, digest);
MD5HexPrint(digest, name);
name += ".png";
}
bool thumbPathForUrl(const string& url, int size, string& path)
{
string name;
thumbname(url, name);
if (size <= 128) {
path = path_cat(path_home(), thmbdirnormal);
path = path_cat(path, name);
if (access(path.c_str(), R_OK) == 0) {
return true;
}
}
path = path_cat(path_home(), thmbdirlarge);
path = path_cat(path, name);
if (access(path.c_str(), R_OK) == 0) {
return true;
}
// File does not exist. Path corresponds to the large version at this point,
// fix it if needed.
if (size <= 128) {
path = path_cat(path_home(), thmbdirnormal);
path = path_cat(path, name);
}
return false;
}
#else // TEST_PATHUT
#include <stdlib.h>
#include <iostream>
......@@ -645,7 +687,7 @@ int main(int argc, const char **argv)
printf("pc %d, megabytes %ld\n", pc, blocks);
#endif
#if 1
#if 0
Pidfile pidfile("/tmp/pathutpidfile");
pid_t pid;
if ((pid = pidfile.open()) != 0) {
......@@ -659,6 +701,35 @@ int main(int argc, const char **argv)
pidfile.remove();
#endif
#if 1
if (argc != 2) {
fprintf(stderr, "Usage: thumbpath <filepath> <size>\n");
exit(1);
}
string input = *argv++;
int size = atoi(*argv++);
if (input.empty()) {
fprintf(stderr, "Usage: thumbpath <filepath> <size>\n");
exit(1);
}
// Make absolute path if needed
if (input[0] != '/') {
input = path_absolute(input);
}
input = string("file://") + path_canon(input);
string path;
if (thumbPathForUrl(input, size, path)) {
cout << "Thumbnail for [" << input << "] [" << path << "]" << endl;
} else {
cout << "No thumbnail for [" << input << "] path [" << path << "]" <<endl;
}
exit(0);
#endif
return 0;
}
......
......@@ -129,4 +129,11 @@ private:
int flopen();
};
// Freedesktop thumbnail standard path routine
// On return, path will have the appropriate value in all cases,
// returns true if the file already exists
extern bool thumbPathForUrl(const string& url, int size, string& path);
#endif /* _PATHUT_H_INCLUDED_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment