Optionnally show mime type icons in result list
This commit is contained in:
parent
fb42a135e8
commit
9f52e4ce90
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.10 2005-11-08 21:02:55 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.11 2005-11-16 15:07:20 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
@ -167,6 +167,16 @@ string getMimeViewer(const std::string &mtype, ConfTree *mhandlers)
|
||||
return hs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return icon name
|
||||
*/
|
||||
string getMimeIconName(const std::string &mtype, ConfTree *mhandlers)
|
||||
{
|
||||
string hs;
|
||||
mhandlers->get(mtype, hs, "icons");
|
||||
return hs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return decompression command line for given mime type
|
||||
*/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _MIMEHANDLER_H_INCLUDED_
|
||||
#define _MIMEHANDLER_H_INCLUDED_
|
||||
/* @(#$Id: mimehandler.h,v 1.7 2005-11-08 21:02:55 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: mimehandler.h,v 1.8 2005-11-16 15:07:20 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@ -54,6 +54,12 @@ extern MimeHandler *getMimeHandler(const std::string &mtyp, ConfTree *mhdlers);
|
||||
*/
|
||||
extern std::string getMimeViewer(const std::string &mtyp, ConfTree *mhandlers);
|
||||
|
||||
/**
|
||||
* Return icon name
|
||||
*/
|
||||
extern std::string getMimeIconName(const std::string &mtyp, ConfTree *mhandlers);
|
||||
|
||||
|
||||
/**
|
||||
* Return command to uncompress the given type. The returned command has
|
||||
* substitutable places for input file name and temp dir name, and will
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: main.cpp,v 1.14 2005-11-16 08:17:10 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: main.cpp,v 1.15 2005-11-16 15:07:20 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
@ -29,6 +29,8 @@ RclConfig *rclconfig;
|
||||
Rcl::Db *rcldb;
|
||||
int recollNeedsExit;
|
||||
string tmpdir;
|
||||
bool showicons;
|
||||
string iconsdir;
|
||||
|
||||
void getQueryStemming(bool &dostem, std::string &stemlang)
|
||||
{
|
||||
@ -158,6 +160,17 @@ int main( int argc, char ** argv )
|
||||
exit(1);
|
||||
}
|
||||
|
||||
string tmp;
|
||||
rclconfig->getConfParam("showicons", tmp);
|
||||
if (tmp.empty())
|
||||
tmp = "0";
|
||||
showicons = atoi(tmp.c_str()) ? true : false;
|
||||
rclconfig->getConfParam("iconsdir", iconsdir);
|
||||
if (iconsdir.empty())
|
||||
iconsdir = "/usr/local/share/recoll/images";
|
||||
else
|
||||
iconsdir = path_tildexpand(iconsdir);
|
||||
|
||||
if (!maketmpdir(tmpdir)) {
|
||||
QMessageBox::critical(0, "Recoll",
|
||||
a.translate("Main",
|
||||
|
||||
@ -195,6 +195,7 @@
|
||||
<variable>int matchPara;</variable>
|
||||
<variable>bool dynSearchActive;</variable>
|
||||
<variable>bool canBeep;</variable>
|
||||
<variable>void *tabData;</variable>
|
||||
</variables>
|
||||
<signals>
|
||||
<signal>previewClosed(Preview *)</signal>
|
||||
@ -206,15 +207,17 @@
|
||||
<slot>prevPressed()</slot>
|
||||
<slot>currentChanged( QWidget * tw )</slot>
|
||||
<slot>closeCurrentTab()</slot>
|
||||
<slot>setCurTabProps( const Rcl::Doc & doc )</slot>
|
||||
<slot>setCurTabProps( const string & fn, const Rcl::Doc & doc )</slot>
|
||||
<slot>loadFileInCurrentTab( string fn, size_t sz, const Rcl::Doc & idoc )</slot>
|
||||
</slots>
|
||||
<functions>
|
||||
<function access="private" specifier="non virtual">init()</function>
|
||||
<function>closeEvent( QCloseEvent * e )</function>
|
||||
<function returnType="bool">eventFilter( QObject * target, QEvent * event )</function>
|
||||
<function returnType="bool">makeFileCurrent( const string & fn )</function>
|
||||
<function returnType="QTextEdit *">getCurrentEditor()</function>
|
||||
<function returnType="QTextEdit *">addEditorTab()</function>
|
||||
<function access="private">destroy()</function>
|
||||
</functions>
|
||||
<layoutdefaults spacing="6" margin="11"/>
|
||||
</UI>
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
*****************************************************************************/
|
||||
#include <unistd.h>
|
||||
|
||||
#include <list>
|
||||
#include <utility>
|
||||
using std::pair;
|
||||
|
||||
@ -24,6 +25,16 @@ using std::pair;
|
||||
#include "recoll.h"
|
||||
#include "plaintorich.h"
|
||||
|
||||
// We keep a list of data associated to each tab
|
||||
class TabData {
|
||||
public:
|
||||
string fn; // filename for this tab
|
||||
QWidget *w; // widget for setCurrent
|
||||
TabData(const string &str, QWidget *wi) : fn(str), w(wi) {}
|
||||
};
|
||||
|
||||
#define TABDATA ((list<TabData> *)tabData)
|
||||
|
||||
void Preview::init()
|
||||
{
|
||||
connect(pvTab, SIGNAL(currentChanged(QWidget *)),
|
||||
@ -31,6 +42,12 @@ void Preview::init()
|
||||
searchTextLine->installEventFilter(this);
|
||||
dynSearchActive = false;
|
||||
canBeep = true;
|
||||
tabData = new list<TabData>;
|
||||
TABDATA->push_back(TabData(string(""), pvTab->currentPage()));
|
||||
}
|
||||
void Preview::destroy()
|
||||
{
|
||||
delete TABDATA;
|
||||
}
|
||||
|
||||
void Preview::closeEvent(QCloseEvent *e)
|
||||
@ -196,8 +213,19 @@ void Preview::closeCurrentTab()
|
||||
{
|
||||
if (pvTab->count() > 1) {
|
||||
QWidget *tw = pvTab->currentPage();
|
||||
if (tw)
|
||||
pvTab->removePage(tw);
|
||||
if (!tw)
|
||||
return;
|
||||
pvTab->removePage(tw);
|
||||
// Have to remove from tab data list
|
||||
if (tabData == 0)
|
||||
return;
|
||||
for (list<TabData>::iterator it = TABDATA->begin();
|
||||
it != TABDATA->end(); it++) {
|
||||
if (it->w == tw) {
|
||||
TABDATA->erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
@ -214,17 +242,20 @@ QTextEdit * Preview::addEditorTab()
|
||||
anonLayout->addWidget(editor);
|
||||
pvTab->addTab(anon, "Tab");
|
||||
pvTab->showPage(anon);
|
||||
if (tabData)
|
||||
TABDATA->push_back(TabData(string(""), anon));
|
||||
return editor;
|
||||
}
|
||||
|
||||
void Preview::setCurTabProps(const Rcl::Doc &doc)
|
||||
void Preview::setCurTabProps(const string &fn, const Rcl::Doc &doc)
|
||||
{
|
||||
QString title = QString::fromUtf8(doc.title.c_str(),
|
||||
doc.title.length());
|
||||
if (title.length() > 20) {
|
||||
title = title.left(10) + "..." + title.right(10);
|
||||
}
|
||||
pvTab->changeTab(pvTab->currentPage(), title);
|
||||
QWidget *w = pvTab->currentPage();
|
||||
pvTab->changeTab(w, title);
|
||||
|
||||
char datebuf[100];
|
||||
datebuf[0] = 0;
|
||||
@ -238,8 +269,30 @@ void Preview::setCurTabProps(const Rcl::Doc &doc)
|
||||
tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
|
||||
if (!doc.title.empty())
|
||||
tiptxt += doc.title + "\n";
|
||||
pvTab->setTabToolTip(pvTab->currentPage(),
|
||||
QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
|
||||
pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
|
||||
|
||||
for (list<TabData>::iterator it = TABDATA->begin();
|
||||
it != TABDATA->end(); it++) {
|
||||
if (it->w == w) {
|
||||
it->fn = fn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Preview::makeFileCurrent(const string &fn)
|
||||
{
|
||||
LOGDEB(("Preview::makeFileCurrent: %s\n", fn.c_str()));
|
||||
for (list<TabData>::iterator it = TABDATA->begin();
|
||||
it != TABDATA->end(); it++) {
|
||||
LOGDEB2(("Preview::makeFileCurrent: compare to w %p, file %s\n",
|
||||
it->w, it->fn.c_str()));
|
||||
if (!it->fn.compare(fn)) {
|
||||
pvTab->showPage(it->w);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -319,7 +372,7 @@ void Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
|
||||
if (doc.title.empty())
|
||||
doc.title = path_getsimple(doc.url);
|
||||
|
||||
setCurTabProps(doc);
|
||||
setCurTabProps(fn, doc);
|
||||
|
||||
char csz[20];
|
||||
sprintf(csz, "%lu", (unsigned long)sz);
|
||||
@ -404,3 +457,5 @@ void Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
|
||||
LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n",
|
||||
editor->length(), editor->paragraphs(), para, index));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _RECOLL_H_INCLUDED_
|
||||
#define _RECOLL_H_INCLUDED_
|
||||
/* @(#$Id: recoll.h,v 1.4 2005-10-19 10:21:48 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: recoll.h,v 1.5 2005-11-16 15:07:20 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "rclconfig.h"
|
||||
@ -16,6 +16,8 @@ extern void getQueryStemming(bool &dostem, std::string &stemlang);
|
||||
extern RclConfig *rclconfig;
|
||||
extern Rcl::Db *rcldb;
|
||||
extern std::string tmpdir;
|
||||
extern bool showicons;
|
||||
extern string iconsdir;
|
||||
|
||||
extern int recollNeedsExit;
|
||||
|
||||
|
||||
@ -407,6 +407,23 @@ void RecollMain::listNextPB_clicked()
|
||||
|
||||
gotone = true;
|
||||
|
||||
string img_name;
|
||||
if (showicons) {
|
||||
string iconname = getMimeIconName(doc.mimetype,
|
||||
rclconfig->getMimeConf());
|
||||
if (iconname.empty())
|
||||
iconname = "document";
|
||||
string imgfile = iconsdir + "/" + iconname + ".png";
|
||||
|
||||
LOGDEB(("Img file; %s\n", imgfile.c_str()));
|
||||
QImage image(imgfile.c_str());
|
||||
if (!image.isNull()) {
|
||||
img_name = string("img_") + iconname;
|
||||
QMimeSourceFactory::defaultFactory()->
|
||||
setImage(img_name.c_str(),image);
|
||||
}
|
||||
}
|
||||
|
||||
// Result list display: TOBEDONE
|
||||
// - move abstract/keywords to Detail window ?
|
||||
// - keywords matched
|
||||
@ -426,8 +443,11 @@ void RecollMain::listNextPB_clicked()
|
||||
}
|
||||
string abst = stripMarkup(doc.abstract);
|
||||
LOGDEB1(("Abstract: {%s}\n", abst.c_str()));
|
||||
string result = "<p>" +
|
||||
string(perbuf) + " <b>" + doc.title + "</b><br>" +
|
||||
string result = string("<p>");
|
||||
if (!img_name.empty()) {
|
||||
result += "<img source=\"" + img_name + "\" align=\"left\">";
|
||||
}
|
||||
result += string(perbuf) + " <b>" + doc.title + "</b><br>" +
|
||||
doc.mimetype + " " +
|
||||
(datebuf[0] ? string(datebuf) + "<br>" : string("<br>")) +
|
||||
(!abst.empty() ? abst + "<br>" : string("")) +
|
||||
@ -447,7 +467,10 @@ void RecollMain::listNextPB_clicked()
|
||||
reslistTE->ensureCursorVisible();
|
||||
} else {
|
||||
// Restore first in win parameter that we shouln't have incremented
|
||||
reslistTE->append(tr("<p><b>No results found</b><br>"));
|
||||
reslistTE->append(tr("<p>"
|
||||
/*"<img align=\"left\" source=\"myimage\">"*/
|
||||
"<b>No results found</b>"
|
||||
"<br>"));
|
||||
reslist_winfirst -= respagesize;
|
||||
if (reslist_winfirst < 0)
|
||||
reslist_winfirst = -1;
|
||||
@ -555,8 +578,7 @@ void RecollMain::startPreview(int docnum)
|
||||
return;
|
||||
}
|
||||
|
||||
// Go to the file system to retrieve / convert the document text
|
||||
// for preview:
|
||||
// Check file exists in file system
|
||||
string fn = urltolocalpath(doc.url);
|
||||
struct stat st;
|
||||
if (stat(fn.c_str(), &st) < 0) {
|
||||
@ -581,6 +603,10 @@ void RecollMain::startPreview(int docnum)
|
||||
this, SLOT(previewClosed(Preview *)));
|
||||
curPreview->show();
|
||||
} else {
|
||||
if (curPreview->makeFileCurrent(fn)) {
|
||||
// Already there
|
||||
return;
|
||||
}
|
||||
(void)curPreview->addEditorTab();
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# @(#$Id: mimeconf,v 1.7 2005-11-10 08:46:15 dockes Exp $ (C) 2004 J.F.Dockes
|
||||
# @(#$Id: mimeconf,v 1.8 2005-11-16 15:07:20 dockes Exp $ (C) 2004 J.F.Dockes
|
||||
|
||||
# Recoll : associations of mime types to processing filters.
|
||||
# There are different sections for decompression, 'interning' for indexing
|
||||
@ -64,3 +64,23 @@ application/vnd.sun.xml.math = openoffice-1.1.3 %f
|
||||
application/vnd.sun.xml.writer = openoffice-1.1.3 %f
|
||||
application/vnd.sun.xml.writer.global = openoffice-1.1.3 %f
|
||||
application/vnd.sun.xml.writer.template = openoffice-1.1.3 %f
|
||||
|
||||
# Icons to be used in the result list.
|
||||
[icons]
|
||||
application/msword = wordprocessing
|
||||
application/pdf = pdf
|
||||
application/postscript = postscript
|
||||
application/vnd.sun.xml.calc = spreadsheet
|
||||
application/vnd.sun.xml.calc.template = spreadsheet
|
||||
application/vnd.sun.xml.draw = drawing
|
||||
application/vnd.sun.xml.draw.template = drawing
|
||||
application/vnd.sun.xml.impress = presentation
|
||||
application/vnd.sun.xml.impress.template = presentation
|
||||
application/vnd.sun.xml.writer = wordprocessing
|
||||
application/vnd.sun.xml.writer.global = wordprocessing
|
||||
application/vnd.sun.xml.writer.template = wordprocessing
|
||||
text/html = html
|
||||
text/plain = txt
|
||||
text/x-mail = message
|
||||
message/rfc822 = message
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# @(#$Id: recoll.conf,v 1.6 2005-11-10 08:47:49 dockes Exp $ (C) 2004 J.F.Dockes
|
||||
# @(#$Id: recoll.conf,v 1.7 2005-11-16 15:07:20 dockes Exp $ (C) 2004 J.F.Dockes
|
||||
|
||||
# Recoll default configuration file. This should be copied to
|
||||
# ~/.recoll/recoll.conf
|
||||
@ -8,7 +8,7 @@ topdirs = ~
|
||||
|
||||
# Wildcard expressions for names of files and directories that we should
|
||||
# ignore:
|
||||
skippedNames = *~ #* .deps bin CVS Cache caughtspam
|
||||
skippedNames = *~ #* .* bin CVS Cache caughtspam
|
||||
|
||||
# Debug messages
|
||||
loglevel = 4
|
||||
@ -28,6 +28,13 @@ mimemapfile = mimemap
|
||||
# Name of mime-type to filter type/name map file.
|
||||
mimeconffile = mimeconf
|
||||
|
||||
# Decide if we do show icons in the result list. This looks a bit more
|
||||
# beaglish, but I'm not quite sure it's useful. If you wish to have them,
|
||||
# you will have to copy the pngs from the distribution to wherever you want
|
||||
# to store them (the associations are decided in mimeconf)
|
||||
showicons = 1
|
||||
iconsdir = ~/.recoll
|
||||
|
||||
# Where to store the database.
|
||||
dbdir = ~/.recoll/xapiandb
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user