GUI: fix some questionable uses of url_encode and use path2qs in places

This commit is contained in:
Jean-Francois Dockes 2020-04-19 09:21:40 +02:00
parent dce3bff5d7
commit 19c8c50fb1
5 changed files with 253 additions and 258 deletions

View File

@ -37,6 +37,12 @@
using namespace std; using namespace std;
// Browser list used if xdg-open fails for opening the help doc
static const vector<string> browser_list{
"opera", "google-chrome", "chromium-browser",
"palemoon", "iceweasel", "firefox", "konqueror", "epiphany"};
// Start native viewer or preview for input Doc. This is used to allow // Start native viewer or preview for input Doc. This is used to allow
// using recoll from another app (e.g. Unity Scope) to view embedded // using recoll from another app (e.g. Unity Scope) to view embedded
// result docs (docs with an ipath). . We act as a proxy to extract // result docs (docs with an ipath). . We act as a proxy to extract
@ -48,9 +54,8 @@ void RclMain::viewUrl()
return; return;
QUrl qurl(m_urltoview); QUrl qurl(m_urltoview);
LOGDEB("RclMain::viewUrl: Path [" << LOGDEB("RclMain::viewUrl: Path [" << qs2path(qurl.path()) <<
((const char *)qurl.path().toLocal8Bit()) << "] fragment [" "] fragment [" << qs2path(qurl.fragment()) << "]\n");
<< ((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
@ -58,8 +63,7 @@ void RclMain::viewUrl()
inside internfile and have some url magic to indicate the inside internfile and have some url magic to indicate the
appropriate indexer/identification scheme */ appropriate indexer/identification scheme */
string udi; string udi;
make_udi((const char *)qurl.path().toLocal8Bit(), make_udi(qs2path(qurl.path()), qs2path(qurl.fragment()), udi);
(const char *)qurl.fragment().toLocal8Bit(), udi);
Rcl::Doc doc; Rcl::Doc doc;
Rcl::Doc idxdoc; // idxdoc.idxi == 0 -> works with base index only Rcl::Doc idxdoc; // idxdoc.idxi == 0 -> works with base index only
@ -103,15 +107,12 @@ void RclMain::viewUrl()
* (xdg-open etc.) failed */ * (xdg-open etc.) failed */
static bool lookForHtmlBrowser(string &exefile) static bool lookForHtmlBrowser(string &exefile)
{ {
vector<string> blist{"opera", "google-chrome", "chromium-browser",
"palemoon", "iceweasel", "firefox", "konqueror", "epiphany"};
const char *path = getenv("PATH"); const char *path = getenv("PATH");
if (path == 0) { if (path == 0) {
path = "/usr/local/bin:/usr/bin:/bin"; path = "/usr/local/bin:/usr/bin:/bin";
} }
// Look for each browser // Look for each browser
for (const auto& entry : blist) { for (const auto& entry : browser_list) {
if (ExecCmd::which(entry, exefile, path)) if (ExecCmd::which(entry, exefile, path))
return true; return true;
} }

View File

@ -37,7 +37,7 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
LOGDEB("ResultPopup::create: opts " << opts << " haspages " << LOGDEB("ResultPopup::create: opts " << opts << " haspages " <<
doc.haspages << " " <<(source ? "Source not null" : "Source is Null") doc.haspages << " " <<(source ? "Source not null" : "Source is Null")
<< " " << (source ? (source->snippetsCapable() ? << " " << (source ? (source->snippetsCapable() ?
"snippetsCapable" : "not snippetsCapable") : "") "snippetsCapable":"not snippetsCapable") : "")
<< "\n"); << "\n");
string apptag; string apptag;
@ -169,12 +169,9 @@ void copyFN(const Rcl::Doc &doc)
void copyURL(const Rcl::Doc &doc) void copyURL(const Rcl::Doc &doc)
{ {
string url = url_encode(doc.url, 7); QString url = path2qs(doc.url);
QApplication::clipboard()->setText(url.c_str(), QApplication::clipboard()->setText(url, QClipboard::Selection);
QClipboard::Selection); QApplication::clipboard()->setText(url, QClipboard::Clipboard);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Clipboard);
} }
} }

View File

@ -405,14 +405,14 @@ QVariant RecollModel::data(const QModelIndex& index, int role) const
int ecnt; int ecnt;
string data1; string data1;
if (!transcode(data, data1, "UTF-8", "UTF-8", &ecnt) || ecnt > 0) { if (!transcode(data, data1, "UTF-8", "UTF-8", &ecnt) || ecnt > 0) {
data = url_encode(data); data = url_encode(data, 7);
} }
} }
#endif #endif
list<string> lr; list<string> lr;
g_hiliter.plaintorich(data, lr, m_hdata); g_hiliter.plaintorich(data, lr, m_hdata);
return QString::fromUtf8(lr.front().c_str()); return u8s2qs(lr.front());
} }
void RecollModel::saveAsCSV(std::fstream& fp) void RecollModel::saveAsCSV(std::fstream& fp)

View File

@ -84,8 +84,7 @@ void RTIToolW::accept()
// Setting up daemon indexing autostart // Setting up daemon indexing autostart
if (path_exists(autostartfile)) { if (path_exists(autostartfile)) {
QString msg = tr("Replacing: ") + QString msg = tr("Replacing: ") + path2qs(autostartfile);
QString::fromLocal8Bit(autostartfile.c_str());
QMessageBox::Button rep = QMessageBox::Button rep =
QMessageBox::question(this, tr("Replacing file"), msg, QMessageBox::question(this, tr("Replacing file"), msg,
@ -115,8 +114,7 @@ void RTIToolW::accept()
string reason; string reason;
if (!stringtofile(text, autostartfile.c_str(), reason)) { if (!stringtofile(text, autostartfile.c_str(), reason)) {
QString msg = tr("Can't create: ") + QString msg = tr("Can't create: ") + path2qs(autostartfile);
QString::fromLocal8Bit(autostartfile.c_str());
QMessageBox::warning(0, tr("Warning"), msg, QMessageBox::Ok); QMessageBox::warning(0, tr("Warning"), msg, QMessageBox::Ok);
return; return;
} }
@ -142,8 +140,7 @@ void RTIToolW::accept()
} else { } else {
// Turning autostart off // Turning autostart off
if (path_exists(autostartfile)) { if (path_exists(autostartfile)) {
QString msg = tr("Deleting: ") + QString msg = tr("Deleting: ") + path2qs(autostartfile);
QString::fromLocal8Bit(autostartfile.c_str());
QMessageBox::Button rep = QMessageBox::Button rep =
QMessageBox::question(this, tr("Deleting file"), msg, QMessageBox::question(this, tr("Deleting file"), msg,
@ -156,8 +153,8 @@ void RTIToolW::accept()
pid_t pid; pid_t pid;
if ((pid = pidfile.open()) != 0) { if ((pid = pidfile.open()) != 0) {
QMessageBox::Button rep = QMessageBox::Button rep =
QMessageBox::question(this, QMessageBox::question(
tr("Removing autostart"), this, tr("Removing autostart"),
tr("Autostart file deleted. Kill current process too ?"), tr("Autostart file deleted. Kill current process too ?"),
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if (rep == QMessageBox::Yes) { if (rep == QMessageBox::Yes) {

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 J.F.Dockes /* Copyright (C) 2016-2020 J.F.Dockes
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -37,6 +37,7 @@
#include "conftree.h" #include "conftree.h"
#include "rclmain_w.h" #include "rclmain_w.h"
#include "smallut.h" #include "smallut.h"
#include "log.h"
using namespace std; using namespace std;
@ -160,15 +161,16 @@ QVariant WebcacheModel::data(const QModelIndex& index, int role) const
void WebcacheModel::setSearchFilter(const QString& _txt) void WebcacheModel::setSearchFilter(const QString& _txt)
{ {
SimpleRegexp re(qs2utf8s(_txt), SimpleRegexp::SRE_NOSUB); SimpleRegexp re(
qs2utf8s(_txt), SimpleRegexp::SRE_NOSUB|SimpleRegexp::SRE_ICASE);
m->disp.clear(); m->disp.clear();
for (unsigned int i = 0; i < m->all.size(); i++) { for (unsigned int i = 0; i < m->all.size(); i++) {
if (re(m->all[i].url)) { if (re(m->all[i].url)) {
m->disp.push_back(m->all[i]); m->disp.push_back(m->all[i]);
} else { } else {
//qDebug() << "match failed. exp" << _txt << "data" << LOGDEB1(" WebcacheMOdel::filter: match failed. exp" <<
// m->all[i].url.c_str(); qs2utf8s(_txt) << "data" << m->all[i].url);
} }
} }
emit dataChanged(createIndex(0,0), createIndex(1, m->all.size())); emit dataChanged(createIndex(0,0), createIndex(1, m->all.size()));
@ -279,13 +281,11 @@ void WebcacheEdit::copyURL()
QModelIndexList selection = tableview->selectionModel()->selectedRows(); QModelIndexList selection = tableview->selectionModel()->selectedRows();
if (selection.size() != 1) if (selection.size() != 1)
return; return;
string url = m_model->getURL(selection[0].row()); const string& url = m_model->getURL(selection[0].row());
if (!url.empty()) { if (!url.empty()) {
url = url_encode(url, 7); QString qurl = path2qs(url);
QApplication::clipboard()->setText(url.c_str(), QApplication::clipboard()->setText(qurl, QClipboard::Selection);
QClipboard::Selection); QApplication::clipboard()->setText(qurl, QClipboard::Clipboard);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Clipboard);
} }
} }