From b90a31ad70fa60946ae5c0d89504a37d62e49a68 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 31 Oct 2010 10:03:04 +0100 Subject: [PATCH] permit starting an info viewer (info) on an internal gnu info node. This needed a small shell script and a slight modification in how we search from the viewer command in rclmain_w.cpp. The path is now always searched before the filters directory even if useDesktopOpen is set --- src/doc/user/usermanual.sgml | 45 ++++++++++++++++++++++++++++------ src/filters/rclshowinfo | 32 ++++++++++++++++++++++++ src/qtgui/rclmain_w.cpp | 47 +++++++++++++++++++++--------------- src/sampleconf/mimeview | 1 + 4 files changed, 98 insertions(+), 27 deletions(-) create mode 100755 src/filters/rclshowinfo diff --git a/src/doc/user/usermanual.sgml b/src/doc/user/usermanual.sgml index 47c0156c..a055e5a7 100644 --- a/src/doc/user/usermanual.sgml +++ b/src/doc/user/usermanual.sgml @@ -806,7 +806,7 @@ fvwm Preview - Edit + Open Copy File Name Copy Url Save to File @@ -818,7 +818,7 @@ fvwm The Preview and - Edit entries do the same thing as the + Open entries do the same thing as the corresponding links. The Copy File Name and @@ -1638,7 +1638,7 @@ fvwm Use desktop preferences to choose document editor: if this is checked, the xdg-open utility will be used to open files - when you click the Edit link in the result + when you click the Open link in the result list, instead of the application defined in mimeview. xdg-open will in term use your desktop preferences to choose an appropriate @@ -1647,7 +1647,7 @@ fvwm Choose editor applications this will let you choose the command started by the - Edit links inside the result list, for + Open links inside the result list, for specific document types. @@ -3580,7 +3580,7 @@ x-my-tag = mailmytag The mimeview file mimeview specifies which programs - are started when you click on an Edit + are started when you click on an Open link in a result list. Ie: HTML is normally displayed using firefox, but you may prefer Konqueror, your @@ -3612,13 +3612,44 @@ x-my-tag = mailmytag except the one labelled application/x-all (which is set to use xdg-open by default). - The nouncompforviewmts entry, (placed at the top level, outside of the [view] section), holds a list of mime types that should not be uncompressed before starting the viewer (if they are found compressed, ie: mydoc.doc.gz). + The right side of each assignment holds a command to be + executed for opening the file. The following substitutions are + performed: + + + + %DDocument date + + %fFile name. This the + name of a temporary file if it was necessary to create one (ie: + to extract a subdocument from a container). + + %FOriginal file name. + Same as %f except if a temporary file is used. + + %iInternal path, for + subdocuments of containers. The format depends on the container + type. + + %MMime + type + + %U, %uUrl. + + + + + In addition to the predefined values above, all strings like + %(fieldname) will be replaced by the value of + the field named fieldname for the + document. + @@ -3629,7 +3660,7 @@ x-my-tag = mailmytag Imagine that you have some kind of file which does not have indexable content, but for which you would like to have a - functional Edit link in the result list + functional Open link in the result list (when found by file name). The file names end in .blob and can be displayed by application blobviewer. diff --git a/src/filters/rclshowinfo b/src/filters/rclshowinfo new file mode 100755 index 00000000..388d843e --- /dev/null +++ b/src/filters/rclshowinfo @@ -0,0 +1,32 @@ +#!/bin/sh +# A small script to help recoll start info on the node corresponding to +# the result document. The title is the node path, but it needs to be +# somewhat processed + +fatal() +{ + echo $* + exit 1 +} +Usage() +{ + fatal "Usage: rclshowinfo filename top node / sub node [/ ...]" +} + +test $# -ge 2 || Usage +filename=`echo $1 | sed -e 's!^file://!!'` +shift + +# The title set by recoll while indexing is like: +# infofilename / first node path element / second node path element ... +IFS=/ +set $* +while test $# -gt 1;do + shift +# node=`echo $1 | sed -e 's/^ *//' -e 's/ *$//'` + node=`eval "echo $1"` + nodepath="$nodepath '$node'" +done + +set -x +exec xterm -e "info -f $filename $nodepath" diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 1def4459..60d9ca64 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -946,7 +946,7 @@ void RclMain::saveDocToFile(int docnum) static bool lookForHtmlBrowser(string &exefile) { static const char *htmlbrowserlist = - "opera konqueror firefox mozilla netscape epiphany"; + "opera google-chrome konqueror firefox mozilla netscape epiphany"; vector blist; stringToTokens(htmlbrowserlist, blist, " "); @@ -1003,7 +1003,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc) cmdplusattr = rclconfig->getMimeViewerDef(doc.mimetype, apptag); } - if (cmdplusattr.length() == 0) { + if (cmdplusattr.empty()) { QMessageBox::warning(0, "Recoll", tr("No external viewer configured for mime type [") + doc.mimetype.c_str() + "]"); @@ -1029,27 +1029,31 @@ void RclMain::startNativeViewer(Rcl::Doc doc) return; } - // Look for the command to execute in the exec path and a few - // other places + // Look for the command to execute in the exec path and the filters + // directory string cmdpath; - if (prefs.useDesktopOpen) { - // Findfilter searches the recoll filters directory in - // addition to the path. We store a copy of xdg-open there, to be - // used as last resort + if (!ExecCmd::which(lcmd.front(), cmdpath)) { cmdpath = rclconfig->findFilter(lcmd.front()); - } else { - ExecCmd::which(lcmd.front(), cmdpath); - } + // findFilter returns its input param if the filter is not in + // the normal places. As we already looked in the path, we + // have no use for a simple command name here (as opposed to + // mimehandler which will just let execvp do its thing). Erase + // cmdpath so that the user dialog will be started further + // down. + if (!cmdpath.compare(lcmd.front())) + cmdpath.erase(); - // Specialcase text/html because of the help browser need - if (cmdpath.empty() && !doc.mimetype.compare("text/html")) { - if (lookForHtmlBrowser(cmdpath)) { - lcmd.clear(); - lcmd.push_back(cmdpath); - lcmd.push_back("%u"); + // Specialcase text/html because of the help browser need + if (cmdpath.empty() && !doc.mimetype.compare("text/html")) { + if (lookForHtmlBrowser(cmdpath)) { + lcmd.clear(); + lcmd.push_back(cmdpath); + lcmd.push_back("%u"); + } } } + // Command not found: start the user dialog to help find another one: if (cmdpath.empty()) { QString mt = QString::fromAscii(doc.mimetype.c_str()); @@ -1073,12 +1077,13 @@ void RclMain::startNativeViewer(Rcl::Doc doc) return; } - // We may need a temp file, or not depending on the command arguments - // and the fact that this is a subdoc or not. + // We may need a temp file, or not, depending on the command + // arguments and the fact that this is a subdoc or not. bool wantsipath = (cmd.find("%i") != string::npos) || ignoreipath; bool wantsfile = cmd.find("%f") != string::npos; bool istempfile = false; string fn = fileurltolocalpath(doc.url); + string orgfn = fn; string url = doc.url; // If the command wants a file but this is not a file url, or @@ -1139,6 +1144,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc) map subs; subs["D"] = efftime; subs["f"] = fn; + subs["F"] = orgfn; subs["i"] = doc.ipath; subs["M"] = doc.mimetype; subs["U"] = url; @@ -1156,7 +1162,8 @@ void RclMain::startNativeViewer(Rcl::Doc doc) *it = ncmd; } - // Also substitute inside the unsplitted command line for displaying + // Also substitute inside the unsplitted command line and display + // in status bar pcSubst(cmd, ncmd, subs); ncmd += " &"; QStatusBar *stb = statusBar(); diff --git a/src/sampleconf/mimeview b/src/sampleconf/mimeview index 968c62cd..8bdf0cd2 100644 --- a/src/sampleconf/mimeview +++ b/src/sampleconf/mimeview @@ -62,6 +62,7 @@ image/svg+xml = inkview %f image/vnd.djvu = djview %f # Or firefox -remote "openFile(%u)" text/html = firefox %u +text/html|gnuinfo = rclshowinfo %F %(title) text/plain = gnuclient -q %f text/x-c = gnuclient -q %f text/x-html-sidux-man = konqueror %f