Parent: [b2a0e6] (diff)

Child: [4a0a4f] (diff)

Download this file

snippets_w.cpp    125 lines (108 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* Copyright (C) 2012 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include <unistd.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#include "debuglog.h"
#include "recoll.h"
#include "snippets_w.h"
#include "guiutils.h"
#include "rcldb.h"
#include "rclhelp.h"
#include "plaintorich.h"
class PlainToRichQtSnippets : public PlainToRich {
public:
virtual string startMatch(unsigned int)
{
return string("<span class='rclmatch' style='color: ")
+ string((const char *)prefs.qtermcolor.toAscii()) + string("'>");
}
virtual string endMatch()
{
return string("</span>");
}
};
static PlainToRichQtSnippets g_hiliter;
void SnippetsW::init()
{
if (m_source.isNull())
return;
// Make title out of file name if none yet
string titleOrFilename;
string utf8fn;
m_doc.getmeta(Rcl::Doc::keytt, &titleOrFilename);
m_doc.getmeta(Rcl::Doc::keyfn, &utf8fn);
if (titleOrFilename.empty()) {
titleOrFilename = utf8fn;
}
setWindowTitle(QString::fromUtf8(titleOrFilename.c_str()));
vector<pair<int, string> > vpabs;
m_source->getAbstract(m_doc, vpabs);
HighlightData hdata;
m_source->getTerms(hdata);
QString html = QString::fromAscii(
"<html><head>"
"<meta http-equiv=\"content-type\" "
"content=\"text/html; charset=utf-8\"></head>"
"<body style='overflow-x: scroll; white-space: nowrap'>"
"<table>"
);
g_hiliter.set_inputhtml(false);
for (vector<pair<int, string> >::const_iterator it = vpabs.begin();
it != vpabs.end(); it++) {
html += "<tr><td>";
if (it->first > 0) {
char buf[100];
sprintf(buf, "P.&nbsp;%d", it->first);
html += "<a href=\"";
html += buf;
html += "\">";
html += buf;
html += "</a>";
}
html += "</td><td>";
list<string> lr;
g_hiliter.plaintorich(it->second, lr, hdata);
html.append(QString::fromUtf8(lr.front().c_str()));
html.append("</td></tr>\n");
}
html.append("</body></html>");
webView->setHtml(html);
connect(webView, SIGNAL(linkClicked(const QUrl &)),
this, SLOT(linkWasClicked(const QUrl &)));
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
}
void SnippetsW::linkWasClicked(const QUrl &url)
{
string ascurl = (const char *)url.toString().toAscii();;
LOGDEB(("Snippets::linkWasClicked: [%s]\n", ascurl.c_str()));
if (ascurl.size() > 3) {
int what = ascurl[0];
switch (what) {
case 'P':
{
int page = atoi(ascurl.c_str()+2);
emit startNativeViewer(m_doc, page);
return;
}
}
}
LOGERR(("Snippets::linkWasClicked: bad link [%s]\n", ascurl.c_str()));
}