misc small mods to help with building kio_recoll

This commit is contained in:
dockes
2006-01-19 12:01:43 +00:00
parent 4bcdb17480
commit 6e0ec42dad
25 changed files with 504 additions and 238 deletions
+20 -3
View File
@@ -1,6 +1,14 @@
depth=../..
include $(depth)/mk/sysconf
all: kio_recoll.so
DEPS_CXXFLAGS = -MT pop3.lo -MD -MP -MF .deps/pop3.Tpo
INC_CXXFLAGS = -I. -I/usr/local/include -I/usr/X11R6/include
INC_CXXFLAGS = -I. -I/usr/local/include -I/usr/X11R6/include \
-I$(depth)/common -I$(depth)/query -I$(depth)/utils \
-I$(depth)/qtgui
PIC_CXXFLAGS = -fPIC -DPIC
DEBUG_CXXFLAGS = -DNDEBUG -DNO_DEBUG -O2 -O
LANG_CXXFLAGS = -fno-exceptions -fno-check-new -fno-common
@@ -15,14 +23,18 @@ LDFLAGS = -rpath=/usr/lib:/usr/local/lib \
-Wl,-export-dynamic -Wl,-soname -Wl,kio_recoll.so
THREAD_LDFLAGS = -pthread
kio_recoll.so : kio_recoll.o
c++ -shared $(LDFLAGS) $(THREAD_LDFLAGS) kio_recoll.o \
kio_recoll.so : kio_recoll.o piclib/librcl.a
c++ -shared $(LDFLAGS) $(THREAD_LDFLAGS) \
-Wl,--no-undefined \
kio_recoll.o piclib/librcl.a \
$(LIBXAPIAN) $(LIBICONV) \
-L/usr/local/lib -L/usr/X11R6/lib -lkio -lkdeui -lkdesu \
-lkdecore \
-lDCOP \
-lqt-mt \
-lpng -lXext -lX11 -lSM -lICE -lXrender \
-lz -lfam -lsasl2 -ljpeg -L/usr/lib -lstdc++ -lm \
-lstdc++ -lc \
-o kio_recoll.so
kio_recoll.o : kio_recoll.cpp kio_recoll.h
@@ -30,3 +42,8 @@ kio_recoll.o : kio_recoll.cpp kio_recoll.h
$(DEBUG_CXXFLAGS) $(LANG_CXXFLAGS) $(QT_CXXFLAGS) $(SYS_CXXFLAGS) \
$(THREAD_CXXFLAGS) \
-o kio_recoll.o
piclib/librcl.a:
cd piclib;make
.PHONY: all
+162 -9
View File
@@ -1,10 +1,15 @@
#ifndef lint
static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.1 2006-01-18 13:41:11 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.2 2006-01-19 12:01:42 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string>
using namespace std;
#include <qfile.h>
@@ -13,33 +18,164 @@ static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.1 2006-01-18 13:41:11 dockes E
#include <kinstance.h>
#include <kio/global.h>
#include <errno.h>
#include "rclconfig.h"
#include "rcldb.h"
#include "rclinit.h"
#include "docseq.h"
#include "pathut.h"
#include "plaintorich.h"
#include "kio_recoll.h"
using namespace KIO;
RecollProtocol::RecollProtocol(const QCString &pool, const QCString &app)
: SlaveBase("recoll", pool, app)
: SlaveBase("recoll", pool, app), m_initok(false),
m_rclconfig(0), m_rcldb(0), m_docsource(0)
{
string reason;
m_rclconfig = recollinit(0, 0, m_reason);
if (!m_rclconfig || !m_rclconfig->ok()) {
m_reason = string("Configuration problem: ") + reason;
return;
}
if (m_rclconfig->getConfParam(string("dbdir"), m_dbdir) == 0) {
// Note: this will have to be replaced by a call to a
// configuration buildin dialog for initial configuration
m_reason = "No db directory in configuration ??";
return;
}
m_dbdir = path_tildexpand(m_dbdir);
m_rcldb = new Rcl::Db;
if (!m_rcldb) {
m_reason = "Could not build database object. (out of memory ?)";
return;
}
m_initok = true;
return;
}
RecollProtocol::~RecollProtocol()
{
delete m_docsource;
delete m_rcldb;
delete m_rclconfig;
}
bool RecollProtocol::maybeOpenDb(string &reason)
{
if (!m_rcldb) {
reason = "Internal error: initialization error";
return false;
}
if (!m_rcldb->isopen() && !m_rcldb->open(m_dbdir, Rcl::Db::DbRO)) {
reason = "Could not open database in " + m_dbdir;
return false;
}
return true;
}
void RecollProtocol::get(const KURL & url)
{
fprintf(stderr, "RecollProtocol::get %s\n", url.url().ascii());
mimeType("text/html");
QByteArray output;
if (!m_initok || !maybeOpenDb(m_reason)) {
outputError(m_reason.c_str());
finished();
return;
}
string iconsdir;
m_rclconfig->getConfParam("iconsdir", iconsdir);
if (iconsdir.empty()) {
iconsdir = path_cat("/usr/local/share/recoll", "images");
} else {
iconsdir = path_tildexpand(iconsdir);
}
QString path = url.path();
fprintf(stderr, "RecollProtocol::get:path [%s]\n", path.latin1());
Rcl::AdvSearchData sdata;
QCString u8 = path.utf8();
sdata.orwords = u8;
if (!m_rcldb->setQuery(sdata, Rcl::Db::QO_STEM, "english")) {
m_reason = "Internal Error: setQuery failed";
outputError(m_reason.c_str());
finished();
return;
}
if (m_docsource)
delete m_docsource;
m_docsource = new DocSequenceDb(m_rcldb, "Query results");
QByteArray output;
QTextStream os(output, IO_WriteOnly );
os.setEncoding(QTextStream::Latin1);
os <<
"<html><head><title>Recoll:get</title></head>"
"<body><h1>Un titre!</h1><p>This is RECOLL</p></body></html>";
os.setEncoding(QTextStream::UnicodeUTF8);
os << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" << endl;
os << "<html><head>" << endl;
os << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" << endl;
os << "<meta http-equiv=\"Pragma\" content=\"no-cache\">" << endl;
os << "<title>Recoll: query results</title>" << endl;
os << "</head><body>" << endl;
Rcl::Doc doc;
for (int i = 0; i < 100; i++) {
string sh;
doc.erase();
int percent;
if (!m_docsource->getDoc(i, doc, &percent, &sh)) {
// This may very well happen for history if the doc has
// been removed since. So don't treat it as fatal.
doc.abstract = string("Unavailable document");
}
string iconname = m_rclconfig->getMimeIconName(doc.mimetype);
if (iconname.empty())
iconname = "document";
string imgfile = iconsdir + "/" + iconname + ".png";
string result;
if (!sh.empty())
result += string("<p><b>") + sh + "</p>\n<p>";
else
result = "<p>";
char perbuf[10];
sprintf(perbuf, "%3d%%", percent);
if (doc.title.empty())
doc.title = path_getsimple(doc.url);
char datebuf[100];
datebuf[0] = 0;
if (!doc.dmtime.empty() || !doc.fmtime.empty()) {
time_t mtime = doc.dmtime.empty() ?
atol(doc.fmtime.c_str()) : atol(doc.dmtime.c_str());
struct tm *tm = localtime(&mtime);
strftime(datebuf, 99,
"<i>Modified:</i>&nbsp;%Y-%m-%d&nbsp;%H:%M:%S", tm);
}
result += "<img src=\"file://" + imgfile + "\" align=\"left\">";
string abst = escapeHtml(doc.abstract);
result += string(perbuf) + " <b>" + doc.title + "</b><br>" +
doc.mimetype + "&nbsp;" +
(datebuf[0] ? string(datebuf) + "<br>" : string("<br>")) +
(!abst.empty() ? abst + "<br>" : string("")) +
(!doc.keywords.empty() ? doc.keywords + "<br>" : string("")) +
"<a href=\"" + doc.url + "\">" + doc.url + "</a><br></p>\n";
QString str = QString::fromUtf8(result.c_str(), result.length());
os << str;
}
os << "</body></html>";
data(output);
data(QByteArray());
@@ -55,6 +191,23 @@ void RecollProtocol::mimetype(const KURL & /*url*/)
finished();
}
void RecollProtocol::outputError(const QString& errmsg)
{
QByteArray array;
QTextStream os(array, IO_WriteOnly);
os.setEncoding(QTextStream::UnicodeUTF8);
os << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Strict//EN\">" << endl;
os << "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" << endl;
os << "<title>" << "Recoll output" << "</title>\n" << endl;
os << "</head>" << endl;
os << "<body><h1>Recoll Error</h1>" << errmsg << "</body>" << endl;
os << "</html>" << endl;
data(array);
}
extern "C" { int KDE_EXPORT kdemain(int argc, char **argv); }
int kdemain(int argc, char **argv)
+11
View File
@@ -1,6 +1,8 @@
#ifndef _RECOLL_H
#define _RECOLL_H
#include <string>
#include <kio/global.h>
#include <kio/slavebase.h>
@@ -14,5 +16,14 @@ public:
// virtual void listDir( const KURL & url );
// virtual void stat( const KURL & url );
private:
bool m_initok;
RclConfig *m_rclconfig;
Rcl::Db *m_rcldb;
DocSequence *m_docsource;
std::string m_dbdir;
std::string m_reason;
bool maybeOpenDb(string &reason);
void outputError(const QString& errmsg);
};
#endif