Use the browser and http URL to "Open" web search results, instead of the local cached file

This commit is contained in:
Jean-Francois Dockes 2017-11-30 15:50:39 +01:00
parent 5f1555a6eb
commit 6cd99138b0

View File

@ -48,7 +48,9 @@ void RclMain::viewUrl()
return; return;
QUrl qurl(m_urltoview); QUrl qurl(m_urltoview);
LOGDEB("RclMain::viewUrl: Path [" << ((const char *)qurl.path().toLocal8Bit()) << "] fragment [" << ((const char *)qurl.fragment().toLocal8Bit()) << "]\n" ); LOGDEB("RclMain::viewUrl: Path [" <<
((const char *)qurl.path().toLocal8Bit()) << "] fragment ["
<< ((const char *)qurl.fragment().toLocal8Bit()) << "]\n");
/* In theory, the url might not be for a file managed by the fs /* In theory, the url might not be for a file managed by the fs
indexer so that the make_udi() call here would be indexer so that the make_udi() call here would be
@ -101,20 +103,16 @@ void RclMain::viewUrl()
* (xdg-open etc.) failed */ * (xdg-open etc.) failed */
static bool lookForHtmlBrowser(string &exefile) static bool lookForHtmlBrowser(string &exefile)
{ {
static const char *htmlbrowserlist = vector<string> blist{"opera", "google-chrome", "chromium-browser",
"opera google-chrome chromium-browser konqueror iceweasel firefox " "palemoon", "iceweasel", "firefox", "konqueror", "epiphany"};
"mozilla netscape epiphany";
vector<string> blist;
stringToTokens(htmlbrowserlist, blist, " ");
const char *path = getenv("PATH"); const char *path = getenv("PATH");
if (path == 0) if (path == 0) {
path = "/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin"; path = "/usr/local/bin:/usr/bin:/bin";
}
// Look for each browser // Look for each browser
for (vector<string>::const_iterator bit = blist.begin(); for (const auto& entry : blist) {
bit != blist.end(); bit++) { if (ExecCmd::which(entry, exefile, path))
if (ExecCmd::which(*bit, exefile, path))
return true; return true;
} }
exefile.clear(); exefile.clear();
@ -123,7 +121,7 @@ static bool lookForHtmlBrowser(string &exefile)
void RclMain::openWith(Rcl::Doc doc, string cmdspec) void RclMain::openWith(Rcl::Doc doc, string cmdspec)
{ {
LOGDEB("RclMain::openWith: " << (cmdspec) << "\n" ); LOGDEB("RclMain::openWith: " << cmdspec << "\n");
// Split the command line // Split the command line
vector<string> lcmd; vector<string> lcmd;
@ -175,6 +173,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
+ doc.mimetype.c_str() + "]"); + doc.mimetype.c_str() + "]");
return; return;
} }
LOGDEB("StartNativeViewer: viewerdef from config: " << cmdplusattr << endl);
// Separate command string and viewer attributes (if any) // Separate command string and viewer attributes (if any)
ConfSimple viewerattrs; ConfSimple viewerattrs;
@ -259,12 +258,25 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
// This can be overridden with the "ignoreipath" attribute // This can be overridden with the "ignoreipath" attribute
bool groksipath = (cmd.find("%i") != string::npos) || ignoreipath; bool groksipath = (cmd.find("%i") != string::npos) || ignoreipath;
// wantsfile: do we actually need a local file ? The only other // We used to try being clever here, but actually, the only case
// case here is an url %u (ie: for web history). // where we don't need a local file copy of the document (or
bool wantsfile = cmd.find("%f") != string::npos && urlisfileurl(doc.url); // parent document) is the case of an HTML page with a non-file
bool wantsparentfile = cmd.find("%F") != string::npos && // URL (http or https). Trying to guess based on %u or %f is
urlisfileurl(doc.url); // doomed because we pass %u to xdg-open.
bool wantsfile = false;
if (cmd.find("%f") != string::npos || urlisfileurl(doc.url) ||
doc.mimetype.compare("text/html")) {
wantsfile = true;
}
bool wantsparentfile = cmd.find("%F") != string::npos;
if (wantsparentfile && !urlisfileurl(doc.url)) {
QMessageBox::warning(0, "Recoll",
tr("Viewer command line for %1 specifies both "
"parent file but URL is http[s]: unsupported")
.arg(QString::fromUtf8(doc.mimetype.c_str())));
return;
}
if (wantsfile && wantsparentfile) { if (wantsfile && wantsparentfile) {
QMessageBox::warning(0, "Recoll", QMessageBox::warning(0, "Recoll",
tr("Viewer command line for %1 specifies both " tr("Viewer command line for %1 specifies both "
@ -306,8 +318,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
// If the command wants a file but this is not a file url, or // If the command wants a file but this is not a file url, or
// there is an ipath that it won't understand, we need a temp file: // there is an ipath that it won't understand, we need a temp file:
theconfig->setKeyDir(fn.empty() ? "" : path_getfather(fn)); theconfig->setKeyDir(fn.empty() ? "" : path_getfather(fn));
if (!doc.isFsFile() || if (((wantsfile || wantsparentfile) && fn.empty()) ||
((wantsfile || wantsparentfile) && fn.empty()) ||
(!groksipath && !doc.ipath.empty()) ) { (!groksipath && !doc.ipath.empty()) ) {
TempFile temp; TempFile temp;
Rcl::Doc& thedoc = wantsparentfile ? pdoc : doc; Rcl::Doc& thedoc = wantsparentfile ? pdoc : doc;
@ -356,7 +367,8 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
"Recoll", "Recoll",
tr("Opening a temporary copy. Edits will be lost if you don't save" tr("Opening a temporary copy. Edits will be lost if you don't save"
"<br/>them to a permanent location."), "<br/>them to a permanent location."),
tr("Do not show this warning next time (use GUI preferences to restore).")); tr("Do not show this warning next time (use GUI preferences "
"to restore)."));
confirm.setSettingsPath("Recoll/prefs"); confirm.setSettingsPath("Recoll/prefs");
confirm.setOverrideSettingsKey("showTempFileWarning"); confirm.setOverrideSettingsKey("showTempFileWarning");
confirm.exec(); confirm.exec();