|
a/src/qtgui/snippets_w.cpp |
|
b/src/qtgui/snippets_w.cpp |
|
... |
|
... |
19 |
#include <unistd.h>
|
19 |
#include <unistd.h>
|
20 |
#include <stdio.h>
|
20 |
#include <stdio.h>
|
21 |
|
21 |
|
22 |
#include <string>
|
22 |
#include <string>
|
23 |
#include <vector>
|
23 |
#include <vector>
|
|
|
24 |
#include <sstream>
|
24 |
using namespace std;
|
25 |
using namespace std;
|
|
|
26 |
|
|
|
27 |
#include <QWebSettings>
|
|
|
28 |
#include <QWebFrame>
|
|
|
29 |
#include <QShortcut>
|
25 |
|
30 |
|
26 |
#include "debuglog.h"
|
31 |
#include "debuglog.h"
|
27 |
#include "recoll.h"
|
32 |
#include "recoll.h"
|
28 |
#include "snippets_w.h"
|
33 |
#include "snippets_w.h"
|
29 |
#include "guiutils.h"
|
34 |
#include "guiutils.h"
|
|
... |
|
... |
48 |
void SnippetsW::init()
|
53 |
void SnippetsW::init()
|
49 |
{
|
54 |
{
|
50 |
if (m_source.isNull())
|
55 |
if (m_source.isNull())
|
51 |
return;
|
56 |
return;
|
52 |
|
57 |
|
|
|
58 |
searchFM->hide();
|
|
|
59 |
webView->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal,
|
|
|
60 |
Qt::ScrollBarAlwaysOff);
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
new QShortcut(QKeySequence::Find, this, SLOT(slotEditFind()));
|
|
|
64 |
new QShortcut(QKeySequence(Qt::Key_Slash), this, SLOT(slotEditFind()));
|
|
|
65 |
new QShortcut(QKeySequence::FindNext, this, SLOT(slotEditFindNext()));
|
|
|
66 |
new QShortcut(QKeySequence::FindPrevious, this,
|
|
|
67 |
SLOT(slotEditFindPrevious()));
|
|
|
68 |
connect(searchLE, SIGNAL(textChanged(const QString&)),
|
|
|
69 |
this, SLOT(slotSearchTextChanged(const QString&)));
|
|
|
70 |
connect(nextPB, SIGNAL(clicked()), this, SLOT(slotEditFindNext()));
|
|
|
71 |
new QShortcut(QKeySequence(Qt::Key_F3), this, SLOT(slotEditFindNext()));
|
|
|
72 |
connect(prevPB, SIGNAL(clicked()), this, SLOT(slotEditFindPrevious()));
|
|
|
73 |
connect(webView, SIGNAL(linkClicked(const QUrl &)),
|
|
|
74 |
this, SLOT(linkWasClicked(const QUrl &)));
|
|
|
75 |
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
|
|
76 |
|
53 |
// Make title out of file name if none yet
|
77 |
// Make title out of file name if none yet
|
54 |
string titleOrFilename;
|
78 |
string titleOrFilename;
|
55 |
string utf8fn;
|
79 |
string utf8fn;
|
56 |
m_doc.getmeta(Rcl::Doc::keytt, &titleOrFilename);
|
80 |
m_doc.getmeta(Rcl::Doc::keytt, &titleOrFilename);
|
57 |
m_doc.getmeta(Rcl::Doc::keyfn, &utf8fn);
|
81 |
m_doc.getmeta(Rcl::Doc::keyfn, &utf8fn);
|
58 |
if (titleOrFilename.empty()) {
|
82 |
if (titleOrFilename.empty()) {
|
59 |
titleOrFilename = utf8fn;
|
83 |
titleOrFilename = utf8fn;
|
60 |
}
|
84 |
}
|
61 |
|
|
|
62 |
setWindowTitle(QString::fromUtf8(titleOrFilename.c_str()));
|
85 |
setWindowTitle(QString::fromUtf8(titleOrFilename.c_str()));
|
63 |
|
86 |
|
64 |
vector<Rcl::Snippet> vpabs;
|
87 |
vector<Rcl::Snippet> vpabs;
|
65 |
m_source->getAbstract(m_doc, vpabs);
|
88 |
m_source->getAbstract(m_doc, vpabs);
|
66 |
|
89 |
|
67 |
HighlightData hdata;
|
90 |
HighlightData hdata;
|
68 |
m_source->getTerms(hdata);
|
91 |
m_source->getTerms(hdata);
|
69 |
|
92 |
|
70 |
QString html = QString::fromAscii(
|
93 |
ostringstream oss;
|
|
|
94 |
oss <<
|
71 |
"<html><head>"
|
95 |
"<html><head>"
|
72 |
"<meta http-equiv=\"content-type\" "
|
96 |
"<meta http-equiv=\"content-type\" "
|
73 |
"content=\"text/html; charset=utf-8\"></head>"
|
97 |
"content=\"text/html; charset=utf-8\"></head>"
|
74 |
"<body style='overflow-x: scroll; white-space: nowrap'>"
|
98 |
"<body style='overflow-x: scroll; white-space: nowrap'>"
|
75 |
"<table>"
|
99 |
"<table>"
|
76 |
);
|
100 |
;
|
77 |
|
101 |
|
78 |
g_hiliter.set_inputhtml(false);
|
102 |
g_hiliter.set_inputhtml(false);
|
79 |
|
103 |
|
80 |
for (vector<Rcl::Snippet>::const_iterator it = vpabs.begin();
|
104 |
for (vector<Rcl::Snippet>::const_iterator it = vpabs.begin();
|
81 |
it != vpabs.end(); it++) {
|
105 |
it != vpabs.end(); it++) {
|
82 |
html += "<tr><td>";
|
106 |
list<string> lr;
|
|
|
107 |
if (!g_hiliter.plaintorich(it->snippet, lr, hdata)) {
|
|
|
108 |
LOGDEB1(("No match for [%s]\n", it->snippet.c_str()));
|
|
|
109 |
continue;
|
|
|
110 |
}
|
|
|
111 |
oss << "<tr><td>";
|
83 |
if (it->page > 0) {
|
112 |
if (it->page > 0) {
|
84 |
char txt[100];
|
113 |
oss << "<a href=\"P" << it->page << "T" << it->term << "\">"
|
85 |
sprintf(txt, "P. %d", it->page);
|
114 |
<< "P. " << it->page << "</a>";
|
86 |
char url[100];
|
|
|
87 |
sprintf(url, "P%dT%s", it->page, it->term.c_str());
|
|
|
88 |
html += "<a href=\"";
|
|
|
89 |
html += url;
|
|
|
90 |
html += "\">";
|
|
|
91 |
html += txt;
|
|
|
92 |
html += "</a>";
|
|
|
93 |
}
|
115 |
}
|
94 |
html += "</td><td>";
|
116 |
oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << endl;
|
95 |
list<string> lr;
|
|
|
96 |
g_hiliter.plaintorich(it->snippet, lr, hdata);
|
|
|
97 |
html.append(QString::fromUtf8(lr.front().c_str()));
|
|
|
98 |
html.append("</td></tr>\n");
|
|
|
99 |
}
|
117 |
}
|
100 |
html.append("</body></html>");
|
118 |
oss << "</body></html>";
|
101 |
webView->setHtml(html);
|
119 |
|
102 |
connect(webView, SIGNAL(linkClicked(const QUrl &)),
|
120 |
QWebSettings *ws = webView->page()->settings();
|
103 |
this, SLOT(linkWasClicked(const QUrl &)));
|
121 |
if (prefs.reslistfontfamily != "") {
|
104 |
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
122 |
ws->setFontFamily(QWebSettings::StandardFont, prefs.reslistfontfamily);
|
|
|
123 |
ws->setFontSize(QWebSettings::DefaultFontSize, prefs.reslistfontsize);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
webView->setHtml(QString::fromUtf8(oss.str().c_str()));
|
105 |
}
|
127 |
}
|
106 |
|
128 |
|
|
|
129 |
void SnippetsW::slotEditFind()
|
|
|
130 |
{
|
|
|
131 |
searchFM->show();
|
|
|
132 |
searchLE->selectAll();
|
|
|
133 |
searchLE->setFocus();
|
|
|
134 |
}
|
|
|
135 |
void SnippetsW::slotEditFindNext()
|
|
|
136 |
{
|
|
|
137 |
webView->findText(searchLE->text());
|
|
|
138 |
}
|
|
|
139 |
void SnippetsW::slotEditFindPrevious()
|
|
|
140 |
{
|
|
|
141 |
webView->findText(searchLE->text(), QWebPage::FindBackward);
|
|
|
142 |
}
|
|
|
143 |
void SnippetsW::slotSearchTextChanged(const QString& txt)
|
|
|
144 |
{
|
|
|
145 |
webView->findText(txt);
|
|
|
146 |
}
|
107 |
|
147 |
|
108 |
void SnippetsW::linkWasClicked(const QUrl &url)
|
148 |
void SnippetsW::linkWasClicked(const QUrl &url)
|
109 |
{
|
149 |
{
|
110 |
string ascurl = (const char *)url.toString().toAscii();
|
150 |
string ascurl = (const char *)url.toString().toAscii();
|
111 |
LOGDEB(("Snippets::linkWasClicked: [%s]\n", ascurl.c_str()));
|
151 |
LOGDEB(("Snippets::linkWasClicked: [%s]\n", ascurl.c_str()));
|