diff --git a/src/qtgui/rclm_wins.cpp b/src/qtgui/rclm_wins.cpp index 1b3da16f..bba12b0a 100644 --- a/src/qtgui/rclm_wins.cpp +++ b/src/qtgui/rclm_wins.cpp @@ -466,6 +466,8 @@ void RclMain::newDupsW(const Rcl::Doc, const vector dups) void RclMain::showSnippets(Rcl::Doc doc) { + if (!m_source) + return; if (!m_snippets) { m_snippets = new SnippetsW(doc, m_source); connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)), diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index 95685289..f17f7f4d 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -66,9 +66,10 @@ static const QKeySequence closeKeySeq("Ctrl+w"); # include # define QWEBSETTINGS QWebSettings #elif defined(USING_WEBENGINE) -// Notes for WebEngine -// - All links must begin with http:// for acceptNavigationRequest to be -// called. +// Notes for WebEngine: +// - All links must begin with http:// for acceptNavigationRequest to +// be called. Actually not any more since we set baseURL see +// comments in linkClicked(). // - The links passed to acceptNav.. have the host part // lowercased -> we change S0 to http://localhost/S0, not http://S0 # include @@ -942,25 +943,43 @@ void ResList::onLinkClicked(const QUrl &qurl) // want. e.g. Suggestions links are like Sterm|spelling which we // receive as Sterm%7CSpelling string strurl = url_decode(qs2utf8s(qurl.toString())); - + + // Link prefix remark: it used to be that webengine refused to + // acknowledge link clicks on links like "%P1", it needed an + // absolute URL like http://localhost/P1. This does not seem to be + // the case any more, probably because we now set baseUrl (to fix + // icons display which had stopped working). So the linkprefix + // thing could probably go away. OTOH, we'd have to substract the + // baseUrl because we receive links like baseUrl+P1 instead. LOGDEB1("ResList::onLinkClicked: [" << strurl << "] prefix " << m_pager->linkPrefix() << "\n"); + if (m_pager->linkPrefix().size() > 0 && + (strurl.size() <= m_pager->linkPrefix().size() || + !beginswith(strurl, m_pager->linkPrefix()))) { + return; + } strurl = strurl.substr(m_pager->linkPrefix().size()); + int docnum{-1}; + bool havedoc{false}; + Rcl::Doc doc; + if (strurl.size() > 1 && (docnum = atoi(strurl.c_str()+1) - 1) >= 0) { + if (getDoc(docnum, doc)) { + havedoc = true; + } else { + LOGERR("ResList::onLinkClicked: can't get doc for "<< + docnum << "\n"); + } + } + int what = strurl[0]; switch (what) { // Open abstract/snippets window case 'A': { - if (!m_source) + if (!havedoc) return; - int i = atoi(strurl.c_str()+1) - 1; - Rcl::Doc doc; - if (!getDoc(i, doc)) { - LOGERR("ResList::onLinkClicked: can't get doc for " << i << "\n"); - return; - } emit(showSnippets(doc)); } break; @@ -968,14 +987,8 @@ void ResList::onLinkClicked(const QUrl &qurl) // Show duplicates case 'D': { - if (!m_source) + if (!m_source || !havedoc) return; - int i = atoi(strurl.c_str()+1) - 1; - Rcl::Doc doc; - if (!getDoc(i, doc)) { - LOGERR("ResList::onLinkClicked: can't get doc for " << i << "\n"); - return; - } vector dups; if (m_source->docDups(doc, dups) && m_rclmain) { m_rclmain->newDupsW(doc, dups); @@ -986,14 +999,9 @@ void ResList::onLinkClicked(const QUrl &qurl) // Open parent folder case 'F': { - int i = atoi(strurl.c_str()+1) - 1; - Rcl::Doc doc; - if (!getDoc(i, doc)) { - LOGERR("ResList::onLinkClicked: can't get doc for " << i << "\n"); + if (!havedoc) return; - } - emit editRequested(ResultPopup::getParent(std::shared_ptr(), - doc)); + emit editRequested(ResultPopup::getFolder(doc)); } break; @@ -1009,15 +1017,11 @@ void ResList::onLinkClicked(const QUrl &qurl) case 'P': case 'E': { - int i = atoi(strurl.c_str()+1) - 1; - Rcl::Doc doc; - if (!getDoc(i, doc)) { - LOGERR("ResList::onLinkClicked: can't get doc for " << i << "\n"); + if (!havedoc) return; - } if (what == 'P') { if (m_ismainres) { - emit docPreviewClicked(i, doc, m_lstClckMod); + emit docPreviewClicked(docnum, doc, m_lstClckMod); } else { emit previewRequested(doc); } @@ -1038,7 +1042,8 @@ void ResList::onLinkClicked(const QUrl &qurl) // Run script. Link format Rnn|Script Name case 'R': { - int i = atoi(strurl.c_str() + 1) - 1; + if (!havedoc) + return; QString s = qurl.toString(); int bar = s.indexOf("|"); if (bar == -1 || bar >= s.size()-1) @@ -1050,7 +1055,7 @@ void ResList::onLinkClicked(const QUrl &qurl) QAction act(QString::fromUtf8(app.name.c_str()), this); QVariant v(QString::fromUtf8(app.command.c_str())); act.setData(v); - m_popDoc = i; + m_popDoc = docnum; menuOpenWith(&act); } } @@ -1073,8 +1078,9 @@ void ResList::onLinkClicked(const QUrl &qurl) break; default: - LOGERR("ResList::onLinkClicked: bad link [" << strurl.substr(0,20) << "]\n"); - break;// ?? + LOGERR("ResList::onLinkClicked: bad link [" << strurl.substr(0,20) << + "]\n"); + break; } } @@ -1194,7 +1200,7 @@ void ResList::menuOpenFolder() { Rcl::Doc doc; if (getDoc(m_popDoc, doc) && m_source) { - Rcl::Doc pdoc = ResultPopup::getFolder(m_source, doc); + Rcl::Doc pdoc = ResultPopup::getFolder(doc); if (!pdoc.url.empty()) { emit editRequested(pdoc); } diff --git a/src/qtgui/respopup.cpp b/src/qtgui/respopup.cpp index 817edf34..0a280179 100644 --- a/src/qtgui/respopup.cpp +++ b/src/qtgui/respopup.cpp @@ -144,7 +144,7 @@ Rcl::Doc getParent(std::shared_ptr source, Rcl::Doc& doc) return pdoc; } -Rcl::Doc getFolder(std::shared_ptr, Rcl::Doc& doc) +Rcl::Doc getFolder(Rcl::Doc& doc) { Rcl::Doc pdoc; pdoc.url = url_parentfolder(doc.url); diff --git a/src/qtgui/respopup.h b/src/qtgui/respopup.h index 6757cd93..72cf00ef 100644 --- a/src/qtgui/respopup.h +++ b/src/qtgui/respopup.h @@ -26,8 +26,7 @@ extern QMenu *create(QWidget *me, int opts, Rcl::Doc& doc); extern Rcl::Doc getParent(std::shared_ptr source, Rcl::Doc& doc); -extern Rcl::Doc getFolder(std::shared_ptr source, - Rcl::Doc& doc); +extern Rcl::Doc getFolder(Rcl::Doc& doc); extern void copyFN(const Rcl::Doc &doc); extern void copyURL(const Rcl::Doc &doc); }; diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 00840b09..44a58f36 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -718,7 +718,7 @@ void ResTable::onTableView_currentChanged(const QModelIndex& index) m_detail->clear(); m_detaildocnum = index.row(); m_detaildoc = doc; - m_pager->displayDoc(theconfig, index.row(), m_detaildoc, + m_pager->displayDoc(theconfig, m_detaildocnum, m_detaildoc, m_model->m_hdata); emit(detailDocChanged(doc, m_model->getDocSource())); } else { @@ -841,19 +841,23 @@ void ResTable::linkWasClicked(const QUrl &url) const char *ascurl = s.toUtf8(); LOGDEB("ResTable::linkWasClicked: [" << ascurl << "]\n"); - int i = atoi(ascurl+1) -1; + int docseqnum = atoi(ascurl+1) -1; + if (m_detaildocnum != docseqnum) { + //? Really we should abort... + LOGERR("ResTable::linkWasClicked: m_detaildocnum != docseqnum !\n"); + return; + } + int what = ascurl[0]; switch (what) { // Open abstract/snippets window case 'A': - if (m_detaildocnum >= 0) - emit(showSnippets(m_detaildoc)); + emit(showSnippets(m_detaildoc)); break; case 'D': { vector dups; - if (m_detaildocnum >= 0 && m_rclmain && - m_model->getDocSource()->docDups(m_detaildoc, dups)) { + if (m_rclmain && m_model->getDocSource()->docDups(m_detaildoc, dups)) { m_rclmain->newDupsW(m_detaildoc, dups); } } @@ -862,8 +866,7 @@ void ResTable::linkWasClicked(const QUrl &url) // Open parent folder case 'F': { - emit editRequested(ResultPopup::getParent( - std::shared_ptr(), m_detaildoc)); + emit editRequested(ResultPopup::getFolder(m_detaildoc)); } break; @@ -872,7 +875,7 @@ void ResTable::linkWasClicked(const QUrl &url) { if (what == 'P') { if (m_ismainres) { - emit docPreviewClicked(i, m_detaildoc, 0); + emit docPreviewClicked(docseqnum, m_detaildoc, 0); } else { emit previewRequested(m_detaildoc); } @@ -1013,9 +1016,8 @@ void ResTable::menuOpenParent() void ResTable::menuOpenFolder() { - if (m_detaildocnum >= 0 && m_model && m_model->getDocSource()) { - Rcl::Doc pdoc = - ResultPopup::getFolder(m_model->getDocSource(), m_detaildoc); + if (m_detaildocnum >= 0) { + Rcl::Doc pdoc = ResultPopup::getFolder(m_detaildoc); if (!pdoc.url.empty()) { emit editRequested(pdoc); }