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;
// 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
// 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
@ -48,9 +54,8 @@ void RclMain::viewUrl()
return;
QUrl qurl(m_urltoview);
LOGDEB("RclMain::viewUrl: Path [" <<
((const char *)qurl.path().toLocal8Bit()) << "] fragment ["
<< ((const char *)qurl.fragment().toLocal8Bit()) << "]\n");
LOGDEB("RclMain::viewUrl: Path [" << qs2path(qurl.path()) <<
"] fragment [" << qs2path(qurl.fragment()) << "]\n");
/* In theory, the url might not be for a file managed by the fs
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
appropriate indexer/identification scheme */
string udi;
make_udi((const char *)qurl.path().toLocal8Bit(),
(const char *)qurl.fragment().toLocal8Bit(), udi);
make_udi(qs2path(qurl.path()), qs2path(qurl.fragment()), udi);
Rcl::Doc doc;
Rcl::Doc idxdoc; // idxdoc.idxi == 0 -> works with base index only
@ -103,15 +107,12 @@ void RclMain::viewUrl()
* (xdg-open etc.) failed */
static bool lookForHtmlBrowser(string &exefile)
{
vector<string> blist{"opera", "google-chrome", "chromium-browser",
"palemoon", "iceweasel", "firefox", "konqueror", "epiphany"};
const char *path = getenv("PATH");
if (path == 0) {
path = "/usr/local/bin:/usr/bin:/bin";
}
// Look for each browser
for (const auto& entry : blist) {
for (const auto& entry : browser_list) {
if (ExecCmd::which(entry, exefile, path))
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 " <<
doc.haspages << " " <<(source ? "Source not null" : "Source is Null")
<< " " << (source ? (source->snippetsCapable() ?
"snippetsCapable" : "not snippetsCapable") : "")
"snippetsCapable":"not snippetsCapable") : "")
<< "\n");
string apptag;
@ -169,12 +169,9 @@ void copyFN(const Rcl::Doc &doc)
void copyURL(const Rcl::Doc &doc)
{
string url = url_encode(doc.url, 7);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Selection);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Clipboard);
QString url = path2qs(doc.url);
QApplication::clipboard()->setText(url, QClipboard::Selection);
QApplication::clipboard()->setText(url, QClipboard::Clipboard);
}
}

View File

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

View File

@ -84,8 +84,7 @@ void RTIToolW::accept()
// Setting up daemon indexing autostart
if (path_exists(autostartfile)) {
QString msg = tr("Replacing: ") +
QString::fromLocal8Bit(autostartfile.c_str());
QString msg = tr("Replacing: ") + path2qs(autostartfile);
QMessageBox::Button rep =
QMessageBox::question(this, tr("Replacing file"), msg,
@ -115,8 +114,7 @@ void RTIToolW::accept()
string reason;
if (!stringtofile(text, autostartfile.c_str(), reason)) {
QString msg = tr("Can't create: ") +
QString::fromLocal8Bit(autostartfile.c_str());
QString msg = tr("Can't create: ") + path2qs(autostartfile);
QMessageBox::warning(0, tr("Warning"), msg, QMessageBox::Ok);
return;
}
@ -142,8 +140,7 @@ void RTIToolW::accept()
} else {
// Turning autostart off
if (path_exists(autostartfile)) {
QString msg = tr("Deleting: ") +
QString::fromLocal8Bit(autostartfile.c_str());
QString msg = tr("Deleting: ") + path2qs(autostartfile);
QMessageBox::Button rep =
QMessageBox::question(this, tr("Deleting file"), msg,
@ -156,8 +153,8 @@ void RTIToolW::accept()
pid_t pid;
if ((pid = pidfile.open()) != 0) {
QMessageBox::Button rep =
QMessageBox::question(this,
tr("Removing autostart"),
QMessageBox::question(
this, tr("Removing autostart"),
tr("Autostart file deleted. Kill current process too ?"),
QMessageBox::Yes | QMessageBox::No);
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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@ -37,6 +37,7 @@
#include "conftree.h"
#include "rclmain_w.h"
#include "smallut.h"
#include "log.h"
using namespace std;
@ -160,15 +161,16 @@ QVariant WebcacheModel::data(const QModelIndex& index, int role) const
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();
for (unsigned int i = 0; i < m->all.size(); i++) {
if (re(m->all[i].url)) {
m->disp.push_back(m->all[i]);
} else {
//qDebug() << "match failed. exp" << _txt << "data" <<
// m->all[i].url.c_str();
LOGDEB1(" WebcacheMOdel::filter: match failed. exp" <<
qs2utf8s(_txt) << "data" << m->all[i].url);
}
}
emit dataChanged(createIndex(0,0), createIndex(1, m->all.size()));
@ -279,13 +281,11 @@ void WebcacheEdit::copyURL()
QModelIndexList selection = tableview->selectionModel()->selectedRows();
if (selection.size() != 1)
return;
string url = m_model->getURL(selection[0].row());
const string& url = m_model->getURL(selection[0].row());
if (!url.empty()) {
url = url_encode(url, 7);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Selection);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Clipboard);
QString qurl = path2qs(url);
QApplication::clipboard()->setText(qurl, QClipboard::Selection);
QApplication::clipboard()->setText(qurl, QClipboard::Clipboard);
}
}