GUI: fix some questionable uses of url_encode and use path2qs in places
This commit is contained in:
parent
dce3bff5d7
commit
19c8c50fb1
@ -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
|
||||||
@ -45,12 +51,11 @@ using namespace std;
|
|||||||
void RclMain::viewUrl()
|
void RclMain::viewUrl()
|
||||||
{
|
{
|
||||||
if (m_urltoview.isEmpty() || !rcldb)
|
if (m_urltoview.isEmpty() || !rcldb)
|
||||||
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,13 +63,12 @@ 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
|
||||||
if (!rcldb->getDoc(udi, idxdoc, doc) || doc.pc == -1)
|
if (!rcldb->getDoc(udi, idxdoc, doc) || doc.pc == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// StartNativeViewer needs a db source to call getEnclosing() on.
|
// StartNativeViewer needs a db source to call getEnclosing() on.
|
||||||
Rcl::Query *query = new Rcl::Query(rcldb.get());
|
Rcl::Query *query = new Rcl::Query(rcldb.get());
|
||||||
@ -79,22 +83,22 @@ void RclMain::viewUrl()
|
|||||||
string apptag;
|
string apptag;
|
||||||
doc.getmeta(Rcl::Doc::keyapptg, &apptag);
|
doc.getmeta(Rcl::Doc::keyapptg, &apptag);
|
||||||
string viewer = theconfig->getMimeViewerDef(doc.mimetype, apptag,
|
string viewer = theconfig->getMimeViewerDef(doc.mimetype, apptag,
|
||||||
prefs.useDesktopOpen);
|
prefs.useDesktopOpen);
|
||||||
if (viewer.empty()) {
|
if (viewer.empty()) {
|
||||||
startPreview(doc);
|
startPreview(doc);
|
||||||
} else {
|
} else {
|
||||||
hide();
|
hide();
|
||||||
startNativeViewer(doc);
|
startNativeViewer(doc);
|
||||||
// We have a problem here because xdg-open will exit
|
// We have a problem here because xdg-open will exit
|
||||||
// immediately after starting the command instead of waiting
|
// immediately after starting the command instead of waiting
|
||||||
// for it, so we can't wait either and we don't know when we
|
// for it, so we can't wait either and we don't know when we
|
||||||
// can exit (deleting the temp file). As a bad workaround we
|
// can exit (deleting the temp file). As a bad workaround we
|
||||||
// sleep some time then exit. The alternative would be to just
|
// sleep some time then exit. The alternative would be to just
|
||||||
// prevent the temp file deletion completely, leaving it
|
// prevent the temp file deletion completely, leaving it
|
||||||
// around forever. Better to let the user save a copy if he
|
// around forever. Better to let the user save a copy if he
|
||||||
// wants I think.
|
// wants I think.
|
||||||
sleep(30);
|
sleep(30);
|
||||||
fileExit();
|
fileExit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,17 +107,14 @@ 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;
|
||||||
}
|
}
|
||||||
exefile.clear();
|
exefile.clear();
|
||||||
return false;
|
return false;
|
||||||
@ -126,11 +127,11 @@ void RclMain::openWith(Rcl::Doc doc, string cmdspec)
|
|||||||
// Split the command line
|
// Split the command line
|
||||||
vector<string> lcmd;
|
vector<string> lcmd;
|
||||||
if (!stringToStrings(cmdspec, lcmd)) {
|
if (!stringToStrings(cmdspec, lcmd)) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
0, "Recoll", tr("Bad desktop app spec for %1: [%2]\n"
|
0, "Recoll", tr("Bad desktop app spec for %1: [%2]\n"
|
||||||
"Please check the desktop file")
|
"Please check the desktop file")
|
||||||
.arg(u8s2qs(doc.mimetype)).arg(path2qs(cmdspec)));
|
.arg(u8s2qs(doc.mimetype)).arg(path2qs(cmdspec)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for the command to execute in the exec path and the filters
|
// Look for the command to execute in the exec path and the filters
|
||||||
@ -165,12 +166,12 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
|||||||
|
|
||||||
// Look for appropriate viewer
|
// Look for appropriate viewer
|
||||||
string cmdplusattr = theconfig->getMimeViewerDef(doc.mimetype, apptag,
|
string cmdplusattr = theconfig->getMimeViewerDef(doc.mimetype, apptag,
|
||||||
prefs.useDesktopOpen);
|
prefs.useDesktopOpen);
|
||||||
if (cmdplusattr.empty()) {
|
if (cmdplusattr.empty()) {
|
||||||
QMessageBox::warning(0, "Recoll",
|
QMessageBox::warning(0, "Recoll",
|
||||||
tr("No external viewer configured for mime type [")
|
tr("No external viewer configured for mime type [")
|
||||||
+ doc.mimetype.c_str() + "]");
|
+ doc.mimetype.c_str() + "]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOGDEB("StartNativeViewer: viewerdef from config: " << cmdplusattr << endl);
|
LOGDEB("StartNativeViewer: viewerdef from config: " << cmdplusattr << endl);
|
||||||
|
|
||||||
@ -191,59 +192,59 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
|||||||
// Split the command line
|
// Split the command line
|
||||||
vector<string> lcmd;
|
vector<string> lcmd;
|
||||||
if (!stringToStrings(cmd, lcmd)) {
|
if (!stringToStrings(cmd, lcmd)) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
0, "Recoll", tr("Bad viewer command line for %1: [%2]\n"
|
0, "Recoll", tr("Bad viewer command line for %1: [%2]\n"
|
||||||
"Please check the mimeview file")
|
"Please check the mimeview file")
|
||||||
.arg(u8s2qs(doc.mimetype)).arg(path2qs(cmd)));
|
.arg(u8s2qs(doc.mimetype)).arg(path2qs(cmd)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for the command to execute in the exec path and the filters
|
// Look for the command to execute in the exec path and the filters
|
||||||
// directory
|
// directory
|
||||||
string execpath;
|
string execpath;
|
||||||
if (!ExecCmd::which(lcmd.front(), execpath)) {
|
if (!ExecCmd::which(lcmd.front(), execpath)) {
|
||||||
execpath = theconfig->findFilter(lcmd.front());
|
execpath = theconfig->findFilter(lcmd.front());
|
||||||
// findFilter returns its input param if the filter is not in
|
// findFilter returns its input param if the filter is not in
|
||||||
// the normal places. As we already looked in the path, we
|
// the normal places. As we already looked in the path, we
|
||||||
// have no use for a simple command name here (as opposed to
|
// have no use for a simple command name here (as opposed to
|
||||||
// mimehandler which will just let execvp do its thing). Erase
|
// mimehandler which will just let execvp do its thing). Erase
|
||||||
// execpath so that the user dialog will be started further
|
// execpath so that the user dialog will be started further
|
||||||
// down.
|
// down.
|
||||||
if (!execpath.compare(lcmd.front()))
|
if (!execpath.compare(lcmd.front()))
|
||||||
execpath.erase();
|
execpath.erase();
|
||||||
|
|
||||||
// Specialcase text/html because of the help browser need
|
// Specialcase text/html because of the help browser need
|
||||||
if (execpath.empty() && !doc.mimetype.compare("text/html") &&
|
if (execpath.empty() && !doc.mimetype.compare("text/html") &&
|
||||||
apptag.empty()) {
|
apptag.empty()) {
|
||||||
if (lookForHtmlBrowser(execpath)) {
|
if (lookForHtmlBrowser(execpath)) {
|
||||||
lcmd.clear();
|
lcmd.clear();
|
||||||
lcmd.push_back(execpath);
|
lcmd.push_back(execpath);
|
||||||
lcmd.push_back("%u");
|
lcmd.push_back("%u");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command not found: start the user dialog to help find another one:
|
// Command not found: start the user dialog to help find another one:
|
||||||
if (execpath.empty()) {
|
if (execpath.empty()) {
|
||||||
QString mt = QString::fromUtf8(doc.mimetype.c_str());
|
QString mt = QString::fromUtf8(doc.mimetype.c_str());
|
||||||
QString message = tr("The viewer specified in mimeview for %1: %2"
|
QString message = tr("The viewer specified in mimeview for %1: %2"
|
||||||
" is not found.\nDo you want to start the "
|
" is not found.\nDo you want to start the "
|
||||||
" preferences dialog ?")
|
" preferences dialog ?")
|
||||||
.arg(mt).arg(path2qs(lcmd.front()));
|
.arg(mt).arg(path2qs(lcmd.front()));
|
||||||
|
|
||||||
switch(QMessageBox::warning(0, "Recoll", message,
|
switch(QMessageBox::warning(0, "Recoll", message,
|
||||||
"Yes", "No", 0, 0, 1)) {
|
"Yes", "No", 0, 0, 1)) {
|
||||||
case 0:
|
case 0:
|
||||||
showUIPrefs();
|
showUIPrefs();
|
||||||
if (uiprefs)
|
if (uiprefs)
|
||||||
uiprefs->showViewAction(mt);
|
uiprefs->showViewAction(mt);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// The user will have to click on the link again to try the
|
// The user will have to click on the link again to try the
|
||||||
// new command.
|
// new command.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Get rid of the command name. lcmd is now argv[1...n]
|
// Get rid of the command name. lcmd is now argv[1...n]
|
||||||
lcmd.erase(lcmd.begin());
|
lcmd.erase(lcmd.begin());
|
||||||
@ -270,42 +271,42 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wantsparentfile && !urlisfileurl(doc.url)) {
|
if (wantsparentfile && !urlisfileurl(doc.url)) {
|
||||||
QMessageBox::warning(0, "Recoll",
|
QMessageBox::warning(0, "Recoll",
|
||||||
tr("Viewer command line for %1 specifies "
|
tr("Viewer command line for %1 specifies "
|
||||||
"parent file but URL is http[s]: unsupported")
|
"parent file but URL is http[s]: unsupported")
|
||||||
.arg(QString::fromUtf8(doc.mimetype.c_str())));
|
.arg(QString::fromUtf8(doc.mimetype.c_str())));
|
||||||
return;
|
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 "
|
||||||
"file and parent file value: unsupported")
|
"file and parent file value: unsupported")
|
||||||
.arg(QString::fromUtf8(doc.mimetype.c_str())));
|
.arg(QString::fromUtf8(doc.mimetype.c_str())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string url = doc.url;
|
string url = doc.url;
|
||||||
string fn = fileurltolocalpath(doc.url);
|
string fn = fileurltolocalpath(doc.url);
|
||||||
Rcl::Doc pdoc;
|
Rcl::Doc pdoc;
|
||||||
if (wantsparentfile) {
|
if (wantsparentfile) {
|
||||||
// We want the path for the parent document. For example to
|
// We want the path for the parent document. For example to
|
||||||
// open the chm file, not the internal page. Note that we just
|
// open the chm file, not the internal page. Note that we just
|
||||||
// override the other file name in this case.
|
// override the other file name in this case.
|
||||||
if (!m_source || !m_source->getEnclosing(doc, pdoc)) {
|
if (!m_source || !m_source->getEnclosing(doc, pdoc)) {
|
||||||
QMessageBox::warning(0, "Recoll",
|
QMessageBox::warning(0, "Recoll",
|
||||||
tr("Cannot find parent document"));
|
tr("Cannot find parent document"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Override fn with the parent's :
|
// Override fn with the parent's :
|
||||||
fn = fileurltolocalpath(pdoc.url);
|
fn = fileurltolocalpath(pdoc.url);
|
||||||
|
|
||||||
// If the parent document has an ipath too, we need to create
|
// If the parent document has an ipath too, we need to create
|
||||||
// a temp file even if the command takes an ipath
|
// a temp file even if the command takes an ipath
|
||||||
// parameter. We have no viewer which could handle a double
|
// parameter. We have no viewer which could handle a double
|
||||||
// embedding. Will have to change if such a one appears.
|
// embedding. Will have to change if such a one appears.
|
||||||
if (!pdoc.ipath.empty()) {
|
if (!pdoc.ipath.empty()) {
|
||||||
groksipath = false;
|
groksipath = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't remember what enterHistory was actually for. Set it to
|
// Can't remember what enterHistory was actually for. Set it to
|
||||||
@ -320,20 +321,20 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
|||||||
// 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 (((wantsfile || wantsparentfile) && fn.empty()) ||
|
if (((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;
|
||||||
if (!FileInterner::idocToFile(temp, string(), theconfig, thedoc)) {
|
if (!FileInterner::idocToFile(temp, string(), theconfig, thedoc)) {
|
||||||
QMessageBox::warning(0, "Recoll",
|
QMessageBox::warning(0, "Recoll",
|
||||||
tr("Cannot extract document or create "
|
tr("Cannot extract document or create "
|
||||||
"temporary file"));
|
"temporary file"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
enterHistory = true;
|
enterHistory = true;
|
||||||
istempfile = true;
|
istempfile = true;
|
||||||
rememberTempFile(temp);
|
rememberTempFile(temp);
|
||||||
fn = temp.filename();
|
fn = temp.filename();
|
||||||
url = path_pathtofileurl(fn);
|
url = path_pathtofileurl(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If using an actual file, check that it exists, and if it is
|
// If using an actual file, check that it exists, and if it is
|
||||||
@ -354,7 +355,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
|||||||
}
|
}
|
||||||
if (temp.ok()) {
|
if (temp.ok()) {
|
||||||
istempfile = true;
|
istempfile = true;
|
||||||
rememberTempFile(temp);
|
rememberTempFile(temp);
|
||||||
fn = temp.filename();
|
fn = temp.filename();
|
||||||
url = path_pathtofileurl(fn);
|
url = path_pathtofileurl(fn);
|
||||||
}
|
}
|
||||||
@ -381,14 +382,14 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
|
|||||||
// If we are not called with a page number (which would happen for a call
|
// If we are not called with a page number (which would happen for a call
|
||||||
// from the snippets window), see if we can compute a page number anyway.
|
// from the snippets window), see if we can compute a page number anyway.
|
||||||
if (pagenum == -1) {
|
if (pagenum == -1) {
|
||||||
pagenum = 1;
|
pagenum = 1;
|
||||||
string lterm;
|
string lterm;
|
||||||
if (m_source)
|
if (m_source)
|
||||||
pagenum = m_source->getFirstMatchPage(doc, lterm);
|
pagenum = m_source->getFirstMatchPage(doc, lterm);
|
||||||
if (pagenum == -1)
|
if (pagenum == -1)
|
||||||
pagenum = 1;
|
pagenum = 1;
|
||||||
else // We get the match term used to compute the page
|
else // We get the match term used to compute the page
|
||||||
term = QString::fromUtf8(lterm.c_str());
|
term = QString::fromUtf8(lterm.c_str());
|
||||||
}
|
}
|
||||||
char cpagenum[20];
|
char cpagenum[20];
|
||||||
sprintf(cpagenum, "%d", pagenum);
|
sprintf(cpagenum, "%d", pagenum);
|
||||||
@ -445,20 +446,20 @@ void RclMain::execViewer(const map<string, string>& subs, bool enterHistory,
|
|||||||
#endif
|
#endif
|
||||||
QStatusBar *stb = statusBar();
|
QStatusBar *stb = statusBar();
|
||||||
if (stb) {
|
if (stb) {
|
||||||
string prcmd;
|
string prcmd;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
prcmd = ncmd;
|
prcmd = ncmd;
|
||||||
#else
|
#else
|
||||||
string fcharset = theconfig->getDefCharset(true);
|
string fcharset = theconfig->getDefCharset(true);
|
||||||
transcode(ncmd, prcmd, fcharset, "UTF-8");
|
transcode(ncmd, prcmd, fcharset, "UTF-8");
|
||||||
#endif
|
#endif
|
||||||
QString msg = tr("Executing: [") +
|
QString msg = tr("Executing: [") +
|
||||||
QString::fromUtf8(prcmd.c_str()) + "]";
|
QString::fromUtf8(prcmd.c_str()) + "]";
|
||||||
stb->showMessage(msg, 10000);
|
stb->showMessage(msg, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enterHistory)
|
if (enterHistory)
|
||||||
historyEnterDoc(rcldb.get(), g_dynconf, doc);
|
historyEnterDoc(rcldb.get(), g_dynconf, doc);
|
||||||
|
|
||||||
// Do the zeitgeist thing
|
// Do the zeitgeist thing
|
||||||
zg_send_event(ZGSEND_OPEN, doc);
|
zg_send_event(ZGSEND_OPEN, doc);
|
||||||
@ -497,8 +498,8 @@ void RclMain::startManual(const string& index)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!indexempty) {
|
if (!indexempty) {
|
||||||
usermanual += "#";
|
usermanual += "#";
|
||||||
usermanual += index;
|
usermanual += index;
|
||||||
}
|
}
|
||||||
Rcl::Doc doc;
|
Rcl::Doc doc;
|
||||||
if (has_wh && indexempty) {
|
if (has_wh && indexempty) {
|
||||||
|
|||||||
@ -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;
|
||||||
@ -46,7 +46,7 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
|
|||||||
popup->addAction(QWidget::tr("&Preview"), me, SLOT(menuPreview()));
|
popup->addAction(QWidget::tr("&Preview"), me, SLOT(menuPreview()));
|
||||||
|
|
||||||
if (!theconfig->getMimeViewerDef(doc.mimetype, apptag, 0).empty()) {
|
if (!theconfig->getMimeViewerDef(doc.mimetype, apptag, 0).empty()) {
|
||||||
popup->addAction(QWidget::tr("&Open"), me, SLOT(menuEdit()));
|
popup->addAction(QWidget::tr("&Open"), me, SLOT(menuEdit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needopenwith = true;
|
bool needopenwith = true;
|
||||||
@ -105,17 +105,17 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
|
|||||||
popup->addAction(QWidget::tr("Copy &URL"), me, SLOT(menuCopyURL()));
|
popup->addAction(QWidget::tr("Copy &URL"), me, SLOT(menuCopyURL()));
|
||||||
|
|
||||||
if ((opts&showSaveOne) && (!doc.isFsFile() || !doc.ipath.empty()))
|
if ((opts&showSaveOne) && (!doc.isFsFile() || !doc.ipath.empty()))
|
||||||
popup->addAction(QWidget::tr("&Write to File"), me,
|
popup->addAction(QWidget::tr("&Write to File"), me,
|
||||||
SLOT(menuSaveToFile()));
|
SLOT(menuSaveToFile()));
|
||||||
|
|
||||||
if ((opts&showSaveSel))
|
if ((opts&showSaveSel))
|
||||||
popup->addAction(QWidget::tr("Save selection to files"),
|
popup->addAction(QWidget::tr("Save selection to files"),
|
||||||
me, SLOT(menuSaveSelection()));
|
me, SLOT(menuSaveSelection()));
|
||||||
|
|
||||||
Rcl::Doc pdoc;
|
Rcl::Doc pdoc;
|
||||||
if (source && source->getEnclosing(doc, pdoc)) {
|
if (source && source->getEnclosing(doc, pdoc)) {
|
||||||
popup->addAction(QWidget::tr("Preview P&arent document/folder"),
|
popup->addAction(QWidget::tr("Preview P&arent document/folder"),
|
||||||
me, SLOT(menuPreviewParent()));
|
me, SLOT(menuPreviewParent()));
|
||||||
}
|
}
|
||||||
// Open parent is useful even if there is no parent because we open
|
// Open parent is useful even if there is no parent because we open
|
||||||
// the enclosing folder.
|
// the enclosing folder.
|
||||||
@ -124,16 +124,16 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
|
|||||||
me, SLOT(menuOpenParent()));
|
me, SLOT(menuOpenParent()));
|
||||||
|
|
||||||
if (opts & showExpand)
|
if (opts & showExpand)
|
||||||
popup->addAction(QWidget::tr("Find &similar documents"),
|
popup->addAction(QWidget::tr("Find &similar documents"),
|
||||||
me, SLOT(menuExpand()));
|
me, SLOT(menuExpand()));
|
||||||
|
|
||||||
if (doc.haspages && source && source->snippetsCapable())
|
if (doc.haspages && source && source->snippetsCapable())
|
||||||
popup->addAction(QWidget::tr("Open &Snippets window"),
|
popup->addAction(QWidget::tr("Open &Snippets window"),
|
||||||
me, SLOT(menuShowSnippets()));
|
me, SLOT(menuShowSnippets()));
|
||||||
|
|
||||||
if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc))
|
if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc))
|
||||||
popup->addAction(QWidget::tr("Show subdocuments / attachments"),
|
popup->addAction(QWidget::tr("Show subdocuments / attachments"),
|
||||||
me, SLOT(menuShowSubDocs()));
|
me, SLOT(menuShowSubDocs()));
|
||||||
|
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
@ -142,12 +142,12 @@ Rcl::Doc getParent(std::shared_ptr<DocSequence> source, Rcl::Doc& doc)
|
|||||||
{
|
{
|
||||||
Rcl::Doc pdoc;
|
Rcl::Doc pdoc;
|
||||||
if (!source || !source->getEnclosing(doc, pdoc)) {
|
if (!source || !source->getEnclosing(doc, pdoc)) {
|
||||||
// No parent doc: show enclosing folder with app configured for
|
// No parent doc: show enclosing folder with app configured for
|
||||||
// directories
|
// directories
|
||||||
pdoc.url = url_parentfolder(doc.url);
|
pdoc.url = url_parentfolder(doc.url);
|
||||||
pdoc.meta[Rcl::Doc::keychildurl] = doc.url;
|
pdoc.meta[Rcl::Doc::keychildurl] = doc.url;
|
||||||
pdoc.meta[Rcl::Doc::keyapptg] = "parentopen";
|
pdoc.meta[Rcl::Doc::keyapptg] = "parentopen";
|
||||||
pdoc.mimetype = "inode/directory";
|
pdoc.mimetype = "inode/directory";
|
||||||
}
|
}
|
||||||
return pdoc;
|
return pdoc;
|
||||||
}
|
}
|
||||||
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -45,7 +45,7 @@ static const char *desktopfiletext =
|
|||||||
"[Desktop Entry]\n"
|
"[Desktop Entry]\n"
|
||||||
"Name=Recoll real time indexer\n"
|
"Name=Recoll real time indexer\n"
|
||||||
"Comment=Runs in background to extract and index text from modified "
|
"Comment=Runs in background to extract and index text from modified "
|
||||||
"documents\n"
|
"documents\n"
|
||||||
"Icon=system-run\n"
|
"Icon=system-run\n"
|
||||||
"Exec=recollindex -w 60 -m\n"
|
"Exec=recollindex -w 60 -m\n"
|
||||||
"Terminal=false\n"
|
"Terminal=false\n"
|
||||||
@ -61,10 +61,10 @@ static const char *desktopfiletext =
|
|||||||
void RTIToolW::init()
|
void RTIToolW::init()
|
||||||
{
|
{
|
||||||
connect(this->sesCB, SIGNAL(clicked(bool)),
|
connect(this->sesCB, SIGNAL(clicked(bool)),
|
||||||
this, SLOT(sesclicked(bool)));
|
this, SLOT(sesclicked(bool)));
|
||||||
string autostartfile = path_cat(path_home(), rautostartfile);
|
string autostartfile = path_cat(path_home(), rautostartfile);
|
||||||
if (path_exists(autostartfile)) {
|
if (path_exists(autostartfile)) {
|
||||||
sesCB->setChecked(true);
|
sesCB->setChecked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ void RTIToolW::sesclicked(bool on)
|
|||||||
{
|
{
|
||||||
nowCB->setEnabled(on);
|
nowCB->setEnabled(on);
|
||||||
if (!on)
|
if (!on)
|
||||||
nowCB->setChecked(false);
|
nowCB->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTIToolW::accept()
|
void RTIToolW::accept()
|
||||||
@ -81,98 +81,95 @@ void RTIToolW::accept()
|
|||||||
string autostartfile = path_cat(path_home(), rautostartfile);
|
string autostartfile = path_cat(path_home(), rautostartfile);
|
||||||
|
|
||||||
if (sesCB->isChecked()) {
|
if (sesCB->isChecked()) {
|
||||||
// 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,
|
QMessageBox::Ok | QMessageBox::Cancel);
|
||||||
QMessageBox::Ok | QMessageBox::Cancel);
|
if (rep != QMessageBox::Ok) {
|
||||||
if (rep != QMessageBox::Ok) {
|
goto out;
|
||||||
goto out;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
string text;
|
string text;
|
||||||
if (theconfig) {
|
if (theconfig) {
|
||||||
string sourcefile = path_cat(theconfig->getDatadir(), "examples");
|
string sourcefile = path_cat(theconfig->getDatadir(), "examples");
|
||||||
sourcefile = path_cat(sourcefile, "recollindex.desktop");
|
sourcefile = path_cat(sourcefile, "recollindex.desktop");
|
||||||
if (path_exists(sourcefile)) {
|
if (path_exists(sourcefile)) {
|
||||||
file_to_string(sourcefile, text);
|
file_to_string(sourcefile, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (text.empty())
|
if (text.empty())
|
||||||
text = desktopfiletext;
|
text = desktopfiletext;
|
||||||
|
|
||||||
// Try to create .config and autostart anyway. If they exists this will
|
// Try to create .config and autostart anyway. If they exists this will
|
||||||
// do nothing. An error will be detected when we try to create the file
|
// do nothing. An error will be detected when we try to create the file
|
||||||
string dir = path_cat(path_home(), ".config");
|
string dir = path_cat(path_home(), ".config");
|
||||||
mkdir(dir.c_str(), 0700);
|
mkdir(dir.c_str(), 0700);
|
||||||
dir = path_cat(dir, "autostart");
|
dir = path_cat(dir, "autostart");
|
||||||
mkdir(dir.c_str(), 0700);
|
mkdir(dir.c_str(), 0700);
|
||||||
|
|
||||||
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;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (nowCB->isChecked()) {
|
if (nowCB->isChecked()) {
|
||||||
ExecCmd cmd;
|
ExecCmd cmd;
|
||||||
vector<string> args;
|
vector<string> args;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
args.push_back("-m");
|
args.push_back("-m");
|
||||||
args.push_back("-w");
|
args.push_back("-w");
|
||||||
args.push_back("0");
|
args.push_back("0");
|
||||||
status = cmd.doexec("recollindex", args, 0, 0);
|
status = cmd.doexec("recollindex", args, 0, 0);
|
||||||
if (status) {
|
if (status) {
|
||||||
QMessageBox::warning(0, tr("Warning"),
|
QMessageBox::warning(0, tr("Warning"),
|
||||||
tr("Could not execute recollindex"),
|
tr("Could not execute recollindex"),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exitdial = true;
|
exitdial = true;
|
||||||
} 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,
|
QMessageBox::Ok | QMessageBox::Cancel);
|
||||||
QMessageBox::Ok | QMessageBox::Cancel);
|
if (rep == QMessageBox::Ok) {
|
||||||
if (rep == QMessageBox::Ok) {
|
exitdial = true;
|
||||||
exitdial = true;
|
unlink(autostartfile.c_str());
|
||||||
unlink(autostartfile.c_str());
|
if (theconfig) {
|
||||||
if (theconfig) {
|
Pidfile pidfile(theconfig->getPidfile());
|
||||||
Pidfile pidfile(theconfig->getPidfile());
|
pid_t pid;
|
||||||
pid_t pid;
|
if ((pid = pidfile.open()) != 0) {
|
||||||
if ((pid = pidfile.open()) != 0) {
|
QMessageBox::Button rep =
|
||||||
QMessageBox::Button rep =
|
QMessageBox::question(
|
||||||
QMessageBox::question(this,
|
this, tr("Removing autostart"),
|
||||||
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) {
|
kill(pid, SIGTERM);
|
||||||
kill(pid, SIGTERM);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
exitdial = true;
|
||||||
exitdial = true;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (exitdial)
|
if (exitdial)
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -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()));
|
||||||
@ -197,19 +199,19 @@ WebcacheEdit::WebcacheEdit(RclMain *parent)
|
|||||||
wl = settings.value(cwnm).toStringList();
|
wl = settings.value(cwnm).toStringList();
|
||||||
QHeaderView *header = tableview->horizontalHeader();
|
QHeaderView *header = tableview->horizontalHeader();
|
||||||
if (header) {
|
if (header) {
|
||||||
if (int(wl.size()) == header->count()) {
|
if (int(wl.size()) == header->count()) {
|
||||||
for (int i = 0; i < header->count(); i++) {
|
for (int i = 0; i < header->count(); i++) {
|
||||||
header->resizeSection(i, wl[i].toInt());
|
header->resizeSection(i, wl[i].toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connect(header, SIGNAL(sectionResized(int,int,int)),
|
connect(header, SIGNAL(sectionResized(int,int,int)),
|
||||||
this, SLOT(saveColState()));
|
this, SLOT(saveColState()));
|
||||||
|
|
||||||
header = tableview->verticalHeader();
|
header = tableview->verticalHeader();
|
||||||
if (header) {
|
if (header) {
|
||||||
header->setDefaultSectionSize(QApplication::fontMetrics().height() +
|
header->setDefaultSectionSize(QApplication::fontMetrics().height() +
|
||||||
ROWHEIGHTPAD);
|
ROWHEIGHTPAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = settings.value(wwnm, 0).toInt();
|
int width = settings.value(wwnm, 0).toInt();
|
||||||
@ -223,7 +225,7 @@ WebcacheEdit::WebcacheEdit(RclMain *parent)
|
|||||||
connect(new QShortcut(closeKS, this), SIGNAL (activated()),
|
connect(new QShortcut(closeKS, this), SIGNAL (activated()),
|
||||||
this, SLOT (close()));
|
this, SLOT (close()));
|
||||||
connect(tableview, SIGNAL(customContextMenuRequested(const QPoint&)),
|
connect(tableview, SIGNAL(customContextMenuRequested(const QPoint&)),
|
||||||
this, SLOT(createPopupMenu(const QPoint&)));
|
this, SLOT(createPopupMenu(const QPoint&)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,8 +295,8 @@ void WebcacheEdit::saveColState()
|
|||||||
QHeaderView *header = tableview->horizontalHeader();
|
QHeaderView *header = tableview->horizontalHeader();
|
||||||
QStringList newwidths;
|
QStringList newwidths;
|
||||||
for (int vi = 0; vi < header->count(); vi++) {
|
for (int vi = 0; vi < header->count(); vi++) {
|
||||||
int li = header->logicalIndex(vi);
|
int li = header->logicalIndex(vi);
|
||||||
newwidths.push_back(lltodecstr(header->sectionSize(li)).c_str());
|
newwidths.push_back(lltodecstr(header->sectionSize(li)).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user