Optionnally show mime type icons in result list

This commit is contained in:
dockes 2005-11-16 15:07:20 +00:00
parent fb42a135e8
commit 9f52e4ce90
9 changed files with 162 additions and 20 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #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 #endif
#include <iostream> #include <iostream>
@ -167,6 +167,16 @@ string getMimeViewer(const std::string &mtype, ConfTree *mhandlers)
return hs; 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 * Return decompression command line for given mime type
*/ */

View File

@ -1,6 +1,6 @@
#ifndef _MIMEHANDLER_H_INCLUDED_ #ifndef _MIMEHANDLER_H_INCLUDED_
#define _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 <string>
#include <list> #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); 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 * Return command to uncompress the given type. The returned command has
* substitutable places for input file name and temp dir name, and will * substitutable places for input file name and temp dir name, and will

View File

@ -1,5 +1,5 @@
#ifndef lint #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 #endif
#include <unistd.h> #include <unistd.h>
@ -29,6 +29,8 @@ RclConfig *rclconfig;
Rcl::Db *rcldb; Rcl::Db *rcldb;
int recollNeedsExit; int recollNeedsExit;
string tmpdir; string tmpdir;
bool showicons;
string iconsdir;
void getQueryStemming(bool &dostem, std::string &stemlang) void getQueryStemming(bool &dostem, std::string &stemlang)
{ {
@ -158,6 +160,17 @@ int main( int argc, char ** argv )
exit(1); 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)) { if (!maketmpdir(tmpdir)) {
QMessageBox::critical(0, "Recoll", QMessageBox::critical(0, "Recoll",
a.translate("Main", a.translate("Main",

View File

@ -195,6 +195,7 @@
<variable>int matchPara;</variable> <variable>int matchPara;</variable>
<variable>bool dynSearchActive;</variable> <variable>bool dynSearchActive;</variable>
<variable>bool canBeep;</variable> <variable>bool canBeep;</variable>
<variable>void *tabData;</variable>
</variables> </variables>
<signals> <signals>
<signal>previewClosed(Preview *)</signal> <signal>previewClosed(Preview *)</signal>
@ -206,15 +207,17 @@
<slot>prevPressed()</slot> <slot>prevPressed()</slot>
<slot>currentChanged( QWidget * tw )</slot> <slot>currentChanged( QWidget * tw )</slot>
<slot>closeCurrentTab()</slot> <slot>closeCurrentTab()</slot>
<slot>setCurTabProps( const Rcl::Doc &amp; doc )</slot> <slot>setCurTabProps( const string &amp; fn, const Rcl::Doc &amp; doc )</slot>
<slot>loadFileInCurrentTab( string fn, size_t sz, const Rcl::Doc &amp; idoc )</slot> <slot>loadFileInCurrentTab( string fn, size_t sz, const Rcl::Doc &amp; idoc )</slot>
</slots> </slots>
<functions> <functions>
<function access="private" specifier="non virtual">init()</function> <function access="private" specifier="non virtual">init()</function>
<function>closeEvent( QCloseEvent * e )</function> <function>closeEvent( QCloseEvent * e )</function>
<function returnType="bool">eventFilter( QObject * target, QEvent * event )</function> <function returnType="bool">eventFilter( QObject * target, QEvent * event )</function>
<function returnType="bool">makeFileCurrent( const string &amp; fn )</function>
<function returnType="QTextEdit *">getCurrentEditor()</function> <function returnType="QTextEdit *">getCurrentEditor()</function>
<function returnType="QTextEdit *">addEditorTab()</function> <function returnType="QTextEdit *">addEditorTab()</function>
<function access="private">destroy()</function>
</functions> </functions>
<layoutdefaults spacing="6" margin="11"/> <layoutdefaults spacing="6" margin="11"/>
</UI> </UI>

View File

@ -11,6 +11,7 @@
*****************************************************************************/ *****************************************************************************/
#include <unistd.h> #include <unistd.h>
#include <list>
#include <utility> #include <utility>
using std::pair; using std::pair;
@ -24,6 +25,16 @@ using std::pair;
#include "recoll.h" #include "recoll.h"
#include "plaintorich.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() void Preview::init()
{ {
connect(pvTab, SIGNAL(currentChanged(QWidget *)), connect(pvTab, SIGNAL(currentChanged(QWidget *)),
@ -31,6 +42,12 @@ void Preview::init()
searchTextLine->installEventFilter(this); searchTextLine->installEventFilter(this);
dynSearchActive = false; dynSearchActive = false;
canBeep = true; canBeep = true;
tabData = new list<TabData>;
TABDATA->push_back(TabData(string(""), pvTab->currentPage()));
}
void Preview::destroy()
{
delete TABDATA;
} }
void Preview::closeEvent(QCloseEvent *e) void Preview::closeEvent(QCloseEvent *e)
@ -196,8 +213,19 @@ void Preview::closeCurrentTab()
{ {
if (pvTab->count() > 1) { if (pvTab->count() > 1) {
QWidget *tw = pvTab->currentPage(); QWidget *tw = pvTab->currentPage();
if (tw) if (!tw)
return;
pvTab->removePage(tw); 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 { } else {
close(); close();
} }
@ -214,17 +242,20 @@ QTextEdit * Preview::addEditorTab()
anonLayout->addWidget(editor); anonLayout->addWidget(editor);
pvTab->addTab(anon, "Tab"); pvTab->addTab(anon, "Tab");
pvTab->showPage(anon); pvTab->showPage(anon);
if (tabData)
TABDATA->push_back(TabData(string(""), anon));
return editor; 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(), QString title = QString::fromUtf8(doc.title.c_str(),
doc.title.length()); doc.title.length());
if (title.length() > 20) { if (title.length() > 20) {
title = title.left(10) + "..." + title.right(10); title = title.left(10) + "..." + title.right(10);
} }
pvTab->changeTab(pvTab->currentPage(), title); QWidget *w = pvTab->currentPage();
pvTab->changeTab(w, title);
char datebuf[100]; char datebuf[100];
datebuf[0] = 0; datebuf[0] = 0;
@ -238,8 +269,30 @@ void Preview::setCurTabProps(const Rcl::Doc &doc)
tiptxt += doc.mimetype + " " + string(datebuf) + "\n"; tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
if (!doc.title.empty()) if (!doc.title.empty())
tiptxt += doc.title + "\n"; tiptxt += doc.title + "\n";
pvTab->setTabToolTip(pvTab->currentPage(), pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
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()) if (doc.title.empty())
doc.title = path_getsimple(doc.url); doc.title = path_getsimple(doc.url);
setCurTabProps(doc); setCurTabProps(fn, doc);
char csz[20]; char csz[20];
sprintf(csz, "%lu", (unsigned long)sz); 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", LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n",
editor->length(), editor->paragraphs(), para, index)); editor->length(), editor->paragraphs(), para, index));
} }

View File

@ -1,6 +1,6 @@
#ifndef _RECOLL_H_INCLUDED_ #ifndef _RECOLL_H_INCLUDED_
#define _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 <string>
#include <list> #include <list>
#include "rclconfig.h" #include "rclconfig.h"
@ -16,6 +16,8 @@ extern void getQueryStemming(bool &dostem, std::string &stemlang);
extern RclConfig *rclconfig; extern RclConfig *rclconfig;
extern Rcl::Db *rcldb; extern Rcl::Db *rcldb;
extern std::string tmpdir; extern std::string tmpdir;
extern bool showicons;
extern string iconsdir;
extern int recollNeedsExit; extern int recollNeedsExit;

View File

@ -407,6 +407,23 @@ void RecollMain::listNextPB_clicked()
gotone = true; 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 // Result list display: TOBEDONE
// - move abstract/keywords to Detail window ? // - move abstract/keywords to Detail window ?
// - keywords matched // - keywords matched
@ -426,8 +443,11 @@ void RecollMain::listNextPB_clicked()
} }
string abst = stripMarkup(doc.abstract); string abst = stripMarkup(doc.abstract);
LOGDEB1(("Abstract: {%s}\n", abst.c_str())); LOGDEB1(("Abstract: {%s}\n", abst.c_str()));
string result = "<p>" + string result = string("<p>");
string(perbuf) + " <b>" + doc.title + "</b><br>" + if (!img_name.empty()) {
result += "<img source=\"" + img_name + "\" align=\"left\">";
}
result += string(perbuf) + " <b>" + doc.title + "</b><br>" +
doc.mimetype + "&nbsp;" + doc.mimetype + "&nbsp;" +
(datebuf[0] ? string(datebuf) + "<br>" : string("<br>")) + (datebuf[0] ? string(datebuf) + "<br>" : string("<br>")) +
(!abst.empty() ? abst + "<br>" : string("")) + (!abst.empty() ? abst + "<br>" : string("")) +
@ -447,7 +467,10 @@ void RecollMain::listNextPB_clicked()
reslistTE->ensureCursorVisible(); reslistTE->ensureCursorVisible();
} else { } else {
// Restore first in win parameter that we shouln't have incremented // 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; reslist_winfirst -= respagesize;
if (reslist_winfirst < 0) if (reslist_winfirst < 0)
reslist_winfirst = -1; reslist_winfirst = -1;
@ -555,8 +578,7 @@ void RecollMain::startPreview(int docnum)
return; return;
} }
// Go to the file system to retrieve / convert the document text // Check file exists in file system
// for preview:
string fn = urltolocalpath(doc.url); string fn = urltolocalpath(doc.url);
struct stat st; struct stat st;
if (stat(fn.c_str(), &st) < 0) { if (stat(fn.c_str(), &st) < 0) {
@ -581,6 +603,10 @@ void RecollMain::startPreview(int docnum)
this, SLOT(previewClosed(Preview *))); this, SLOT(previewClosed(Preview *)));
curPreview->show(); curPreview->show();
} else { } else {
if (curPreview->makeFileCurrent(fn)) {
// Already there
return;
}
(void)curPreview->addEditorTab(); (void)curPreview->addEditorTab();
} }

View File

@ -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. # Recoll : associations of mime types to processing filters.
# There are different sections for decompression, 'interning' for indexing # 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 = openoffice-1.1.3 %f
application/vnd.sun.xml.writer.global = 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 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

View File

@ -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 default configuration file. This should be copied to
# ~/.recoll/recoll.conf # ~/.recoll/recoll.conf
@ -8,7 +8,7 @@ topdirs = ~
# Wildcard expressions for names of files and directories that we should # Wildcard expressions for names of files and directories that we should
# ignore: # ignore:
skippedNames = *~ #* .deps bin CVS Cache caughtspam skippedNames = *~ #* .* bin CVS Cache caughtspam
# Debug messages # Debug messages
loglevel = 4 loglevel = 4
@ -28,6 +28,13 @@ mimemapfile = mimemap
# Name of mime-type to filter type/name map file. # Name of mime-type to filter type/name map file.
mimeconffile = mimeconf 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. # Where to store the database.
dbdir = ~/.recoll/xapiandb dbdir = ~/.recoll/xapiandb