From 9f52e4ce90965864027ea1732c4bf1290159ad45 Mon Sep 17 00:00:00 2001 From: dockes Date: Wed, 16 Nov 2005 15:07:20 +0000 Subject: [PATCH] Optionnally show mime type icons in result list --- src/internfile/mimehandler.cpp | 12 +++++- src/internfile/mimehandler.h | 8 +++- src/qtgui/main.cpp | 15 +++++++- src/qtgui/preview/preview.ui | 5 ++- src/qtgui/preview/preview.ui.h | 69 ++++++++++++++++++++++++++++++---- src/qtgui/recoll.h | 4 +- src/qtgui/recollmain.ui.h | 36 +++++++++++++++--- src/sampleconf/mimeconf | 22 ++++++++++- src/sampleconf/recoll.conf | 11 +++++- 9 files changed, 162 insertions(+), 20 deletions(-) diff --git a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp index 831b5943..023c22cc 100644 --- a/src/internfile/mimehandler.cpp +++ b/src/internfile/mimehandler.cpp @@ -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 @@ -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 */ diff --git a/src/internfile/mimehandler.h b/src/internfile/mimehandler.h index 4d28e18f..ed08af4e 100644 --- a/src/internfile/mimehandler.h +++ b/src/internfile/mimehandler.h @@ -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 #include @@ -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 diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index b4ef8156..60482f63 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -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 @@ -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", diff --git a/src/qtgui/preview/preview.ui b/src/qtgui/preview/preview.ui index 66a070a6..f07a5589 100644 --- a/src/qtgui/preview/preview.ui +++ b/src/qtgui/preview/preview.ui @@ -195,6 +195,7 @@ int matchPara; bool dynSearchActive; bool canBeep; + void *tabData; previewClosed(Preview *) @@ -206,15 +207,17 @@ prevPressed() currentChanged( QWidget * tw ) closeCurrentTab() - setCurTabProps( const Rcl::Doc & doc ) + setCurTabProps( const string & fn, const Rcl::Doc & doc ) loadFileInCurrentTab( string fn, size_t sz, const Rcl::Doc & idoc ) init() closeEvent( QCloseEvent * e ) eventFilter( QObject * target, QEvent * event ) + makeFileCurrent( const string & fn ) getCurrentEditor() addEditorTab() + destroy() diff --git a/src/qtgui/preview/preview.ui.h b/src/qtgui/preview/preview.ui.h index b6671fd8..da807bb9 100644 --- a/src/qtgui/preview/preview.ui.h +++ b/src/qtgui/preview/preview.ui.h @@ -11,6 +11,7 @@ *****************************************************************************/ #include +#include #include 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) + 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->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::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::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::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)); } + + diff --git a/src/qtgui/recoll.h b/src/qtgui/recoll.h index 584d3165..2768f1a7 100644 --- a/src/qtgui/recoll.h +++ b/src/qtgui/recoll.h @@ -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 #include #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; diff --git a/src/qtgui/recollmain.ui.h b/src/qtgui/recollmain.ui.h index 23b8b350..ef0fa7b9 100644 --- a/src/qtgui/recollmain.ui.h +++ b/src/qtgui/recollmain.ui.h @@ -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 = "

" + - string(perbuf) + " " + doc.title + "
" + + string result = string("

"); + if (!img_name.empty()) { + result += ""; + } + result += string(perbuf) + " " + doc.title + "
" + doc.mimetype + " " + (datebuf[0] ? string(datebuf) + "
" : string("
")) + (!abst.empty() ? abst + "
" : 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("

No results found
")); + reslistTE->append(tr("

" + /*""*/ + "No results found" + "
")); 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(); } diff --git a/src/sampleconf/mimeconf b/src/sampleconf/mimeconf index 6040a2b8..b5ce056e 100644 --- a/src/sampleconf/mimeconf +++ b/src/sampleconf/mimeconf @@ -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 + diff --git a/src/sampleconf/recoll.conf b/src/sampleconf/recoll.conf index 773f36f5..bb7a1c02 100644 --- a/src/sampleconf/recoll.conf +++ b/src/sampleconf/recoll.conf @@ -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