listdir doesnt work on kde 4.0 because on parent/child assumptions in kdirmodel have to check on kde 4.1
This commit is contained in:
parent
abafb31235
commit
b4333737e4
@ -46,7 +46,7 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES}
|
|||||||
${rcltop}/utils
|
${rcltop}/utils
|
||||||
)
|
)
|
||||||
|
|
||||||
set(kio_recoll_SRCS kio_recoll.cpp
|
set(kio_recoll_SRCS kio_recoll.cpp htmlif.cpp dirif.cpp
|
||||||
${depth}/aspell/rclaspell.cpp
|
${depth}/aspell/rclaspell.cpp
|
||||||
${depth}/bincimapmime/mime-getpart.cc
|
${depth}/bincimapmime/mime-getpart.cc
|
||||||
${depth}/bincimapmime/mime-parsefull.cc
|
${depth}/bincimapmime/mime-parsefull.cc
|
||||||
|
|||||||
2
src/kde/kioslave/recoll/cleancmakestuff.sh
Normal file
2
src/kde/kioslave/recoll/cleancmakestuff.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm -rf CMakeCache.txt CMakeFiles cmake_install.cmake CMakeTmp cmake_uninstall.cmake CPackConfig.cmake CPackSourceConfig.cmake DartTestfile.txt install_manifest.txt kio_recoll_automoc.cpp kio_recoll_automoc.cpp.files kio_recoll.la kio_recoll.so lib Makefile
|
||||||
118
src/kde/kioslave/recoll/dirif.cpp
Normal file
118
src/kde/kioslave/recoll/dirif.cpp
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "@(#$Id: dirif.cpp,v 1.1 2008-11-26 15:03:41 dockes Exp $ (C) 2008 J.F.Dockes";
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A lot of code in this file was copied from kio_beagle 0.4.0,
|
||||||
|
* which is a GPL program. The authors listed are:
|
||||||
|
* Debajyoti Bera <dbera.web@gmail.com>
|
||||||
|
*
|
||||||
|
* KDE4 port:
|
||||||
|
* Stephan Binner <binner@kde.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <kurl.h>
|
||||||
|
#include <kio/global.h>
|
||||||
|
|
||||||
|
#include <kdebug.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "kio_recoll.h"
|
||||||
|
|
||||||
|
using namespace KIO;
|
||||||
|
|
||||||
|
const UDSEntry resultToUDSEntry(Rcl::Doc doc)
|
||||||
|
{
|
||||||
|
|
||||||
|
UDSEntry entry;
|
||||||
|
|
||||||
|
KUrl url(doc.url.c_str());
|
||||||
|
kDebug() << doc.url.c_str();
|
||||||
|
|
||||||
|
entry.insert(KIO::UDSEntry::UDS_NAME, url.fileName());
|
||||||
|
if (!doc.mimetype.compare("application/x-fsdirectory")) {
|
||||||
|
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory");
|
||||||
|
entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
|
||||||
|
} else {
|
||||||
|
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, doc.mimetype.c_str());
|
||||||
|
entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
|
||||||
|
}
|
||||||
|
entry.insert(KIO::UDSEntry::UDS_LOCAL_PATH, url.path());
|
||||||
|
// For local files, supply the usual file stat information
|
||||||
|
struct stat info;
|
||||||
|
if (lstat(url.path().toAscii(), &info) >= 0) {
|
||||||
|
entry.insert( KIO::UDSEntry::UDS_SIZE, info.st_size);
|
||||||
|
entry.insert( KIO::UDSEntry::UDS_ACCESS, info.st_mode);
|
||||||
|
entry.insert( KIO::UDSEntry::UDS_MODIFICATION_TIME, info.st_mtime);
|
||||||
|
entry.insert( KIO::UDSEntry::UDS_ACCESS_TIME, info.st_atime);
|
||||||
|
entry.insert( KIO::UDSEntry::UDS_CREATION_TIME, info.st_ctime);
|
||||||
|
}
|
||||||
|
|
||||||
|
// entry.insert(KIO::UDSEntry::UDS_URL, doc.url.c_str());
|
||||||
|
// entry.insert(KIO::UDSEntry::UDS_URL, "recoll://search/query/1");
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Don't know that we really need this. It's used by beagle to return
|
||||||
|
// info on the virtual entries used to execute commands, and on the
|
||||||
|
// saved searches (appearing as directories)
|
||||||
|
void RecollProtocol::stat(const KUrl & url)
|
||||||
|
{
|
||||||
|
kDebug() << url << endl ;
|
||||||
|
|
||||||
|
QString path = url.path();
|
||||||
|
KIO::UDSEntry entry;
|
||||||
|
entry.insert(KIO::UDSEntry::UDS_NAME, url.path());
|
||||||
|
entry.insert(KIO::UDSEntry::UDS_URL, url.url());
|
||||||
|
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
|
||||||
|
statEntry(entry);
|
||||||
|
finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecollProtocol::listDir(const KUrl& url)
|
||||||
|
{
|
||||||
|
kDebug() << url << endl;
|
||||||
|
if (!m_initok || !maybeOpenDb(m_reason)) {
|
||||||
|
error(KIO::ERR_SLAVE_DEFINED, "Init error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString query, opt;
|
||||||
|
URLToQuery(url, query, opt);
|
||||||
|
kDebug() << "Query: " << query;
|
||||||
|
if (!query.isEmpty()) {
|
||||||
|
doSearch(query, opt.toUtf8().at(0));
|
||||||
|
} else {
|
||||||
|
finished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<ResListEntry> page;
|
||||||
|
int pagelen = m_source->getSeqSlice(0, 20, page);
|
||||||
|
kDebug() << "Got " << pagelen << " results.";
|
||||||
|
UDSEntryList entries;
|
||||||
|
for (int i = 0; i < pagelen; i++) {
|
||||||
|
entries.append(resultToUDSEntry(page[i].doc));
|
||||||
|
}
|
||||||
|
listEntries(entries);
|
||||||
|
// finished();
|
||||||
|
}
|
||||||
176
src/kde/kioslave/recoll/htmlif.cpp
Normal file
176
src/kde/kioslave/recoll/htmlif.cpp
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "@(#$Id: htmlif.cpp,v 1.1 2008-11-26 15:03:41 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <kdebug.h>
|
||||||
|
#include <kstandarddirs.h>
|
||||||
|
|
||||||
|
#include "rclconfig.h"
|
||||||
|
#include "rcldb.h"
|
||||||
|
#include "rclinit.h"
|
||||||
|
#include "pathut.h"
|
||||||
|
#include "searchdata.h"
|
||||||
|
#include "rclquery.h"
|
||||||
|
#include "wasastringtoquery.h"
|
||||||
|
#include "wasatorcl.h"
|
||||||
|
#include "kio_recoll.h"
|
||||||
|
#include "docseqdb.h"
|
||||||
|
#include "readfile.h"
|
||||||
|
#include "smallut.h"
|
||||||
|
|
||||||
|
using namespace KIO;
|
||||||
|
|
||||||
|
bool RecollKioPager::append(const string& data)
|
||||||
|
{
|
||||||
|
if (!m_parent) return false;
|
||||||
|
m_parent->data(QByteArray(data.c_str()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string RecollKioPager::detailsLink()
|
||||||
|
{
|
||||||
|
string chunk = "<a href=\"recoll://command/QueryDetails\">";
|
||||||
|
chunk += tr("(show query)") + "</a>";
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
const static string parformat =
|
||||||
|
"<a href=\"%U\"><img src=\"%I\" align=\"left\"></a>"
|
||||||
|
"%R %S "
|
||||||
|
"<a href=\"%U\">Open</a> <b>%T</b><br>"
|
||||||
|
"%M %D <i>%U</i><br>"
|
||||||
|
"%A %K";
|
||||||
|
const string &RecollKioPager::parFormat()
|
||||||
|
{
|
||||||
|
return parformat;
|
||||||
|
}
|
||||||
|
|
||||||
|
string RecollKioPager::pageTop()
|
||||||
|
{
|
||||||
|
return "<p align=\"center\"><a href=\"recoll:///\">New Search</a></p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
string RecollKioPager::nextUrl()
|
||||||
|
{
|
||||||
|
int pagenum = pageNumber();
|
||||||
|
if (pagenum < 0)
|
||||||
|
pagenum = 0;
|
||||||
|
else
|
||||||
|
pagenum++;
|
||||||
|
char buf[100];
|
||||||
|
sprintf(buf, "recoll://command/Page%d", pagenum);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
string RecollKioPager::prevUrl()
|
||||||
|
{
|
||||||
|
int pagenum = pageNumber();
|
||||||
|
if (pagenum <= 0)
|
||||||
|
pagenum = 0;
|
||||||
|
else
|
||||||
|
pagenum--;
|
||||||
|
char buf[100];
|
||||||
|
sprintf(buf, "recoll://command/Page%d", pagenum);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string welcomedata;
|
||||||
|
|
||||||
|
void RecollProtocol::welcomePage()
|
||||||
|
{
|
||||||
|
kDebug() << endl;
|
||||||
|
mimeType("text/html");
|
||||||
|
if (welcomedata.empty()) {
|
||||||
|
QString location =
|
||||||
|
KStandardDirs::locate("data", "kio_recoll/welcome.html");
|
||||||
|
string reason;
|
||||||
|
if (location.isEmpty() ||
|
||||||
|
!file_to_string((const char *)location.toUtf8(),
|
||||||
|
welcomedata, &reason)) {
|
||||||
|
welcomedata = "<html><head><title>Recoll Error</title></head>"
|
||||||
|
"<body><p>Could not locate Recoll welcome.html file: ";
|
||||||
|
welcomedata += reason;
|
||||||
|
welcomedata += "</p></body></html>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string tmp;
|
||||||
|
map<char, string> subs;
|
||||||
|
subs['Q'] = "";
|
||||||
|
pcSubst(welcomedata, tmp, subs);
|
||||||
|
data(tmp.c_str());
|
||||||
|
kDebug() << "done" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecollProtocol::queryDetails()
|
||||||
|
{
|
||||||
|
kDebug() << endl;
|
||||||
|
mimeType("text/html");
|
||||||
|
QByteArray array;
|
||||||
|
QTextStream os(&array, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
os << "<html><head>" << endl;
|
||||||
|
os << "<meta http-equiv=\"Content-Type\" content=\"text/html;"
|
||||||
|
"charset=utf-8\">" << endl;
|
||||||
|
os << "<title>" << "Recoll query details" << "</title>\n" << endl;
|
||||||
|
os << "</head>" << endl;
|
||||||
|
os << "<body><h3>Query details:</h3>" << endl;
|
||||||
|
os << "<p>" << m_pager.queryDescription().c_str() <<"</p>"<< endl;
|
||||||
|
os << "<p><a href=\"recoll://command/Page" <<
|
||||||
|
m_pager.pageNumber() << "\">Return to results</a>" << endl;
|
||||||
|
os << "</body></html>" << endl;
|
||||||
|
data(array);
|
||||||
|
kDebug() << "done" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecollProtocol::htmlDoSearch(const QString& q, char opt)
|
||||||
|
{
|
||||||
|
kDebug() << endl;
|
||||||
|
mimeType("text/html");
|
||||||
|
doSearch(q, opt);
|
||||||
|
m_pager.setDocSource(m_source);
|
||||||
|
m_pager.resultPageNext();
|
||||||
|
m_pager.displayPage();
|
||||||
|
kDebug() << "done" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecollProtocol::outputError(const QString& errmsg)
|
||||||
|
{
|
||||||
|
mimeType("text/html");
|
||||||
|
QByteArray array;
|
||||||
|
QTextStream os(&array, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
os << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Strict//EN\">" << endl;
|
||||||
|
os << "<html><head>" << endl;
|
||||||
|
os << "<meta http-equiv=\"Content-Type\" content=\"text/html;"
|
||||||
|
"charset=utf-8\">" << endl;
|
||||||
|
os << "<title>" << "Recoll error" << "</title>\n" << endl;
|
||||||
|
os << "</head>" << endl;
|
||||||
|
os << "<body><p><b>Recoll error: </b>" << errmsg << "</p>" << endl;
|
||||||
|
os << "<p><a href=\"recoll:///\">New query</a></p>"<< endl;
|
||||||
|
os << "</body></html>" << endl;
|
||||||
|
data(array);
|
||||||
|
}
|
||||||
@ -1,6 +1,22 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.15 2008-11-20 13:10:23 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.16 2008-11-26 15:03:41 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
|
/*
|
||||||
|
* 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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -43,78 +59,24 @@ using namespace std;
|
|||||||
|
|
||||||
using namespace KIO;
|
using namespace KIO;
|
||||||
|
|
||||||
bool RecollKioPager::append(const string& data)
|
RclConfig *RecollProtocol::o_rclconfig;
|
||||||
{
|
|
||||||
if (!m_parent) return false;
|
|
||||||
m_parent->data(QByteArray(data.c_str()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
string RecollKioPager::detailsLink()
|
|
||||||
{
|
|
||||||
string chunk = "<a href=\"recoll://command/QueryDetails\">";
|
|
||||||
chunk += tr("(show query)") + "</a>";
|
|
||||||
return chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
const static string parformat =
|
|
||||||
"<a href=\"%U\"><img src=\"%I\" align=\"left\"></a>"
|
|
||||||
"%R %S "
|
|
||||||
"<a href=\"%U\">Open</a> <b>%T</b><br>"
|
|
||||||
"%M %D <i>%U</i><br>"
|
|
||||||
"%A %K";
|
|
||||||
const string &RecollKioPager::parFormat()
|
|
||||||
{
|
|
||||||
return parformat;
|
|
||||||
}
|
|
||||||
|
|
||||||
string RecollKioPager::pageTop()
|
|
||||||
{
|
|
||||||
return "<p align=\"center\"><a href=\"recoll://welcome\">New Search</a></p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
string RecollKioPager::nextUrl()
|
|
||||||
{
|
|
||||||
int pagenum = pageNumber();
|
|
||||||
if (pagenum < 0)
|
|
||||||
pagenum = 0;
|
|
||||||
else
|
|
||||||
pagenum++;
|
|
||||||
char buf[100];
|
|
||||||
sprintf(buf, "recoll://command/Page%d", pagenum);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
string RecollKioPager::prevUrl()
|
|
||||||
{
|
|
||||||
int pagenum = pageNumber();
|
|
||||||
if (pagenum <= 0)
|
|
||||||
pagenum = 0;
|
|
||||||
else
|
|
||||||
pagenum--;
|
|
||||||
char buf[100];
|
|
||||||
sprintf(buf, "recoll://command/Page%d", pagenum);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static RclConfig *rclconfig;
|
|
||||||
RclConfig *RclConfig::getMainConfig()
|
RclConfig *RclConfig::getMainConfig()
|
||||||
{
|
{
|
||||||
return rclconfig;
|
return RecollProtocol::o_rclconfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
RecollProtocol::RecollProtocol(const QByteArray &pool, const QByteArray &app)
|
RecollProtocol::RecollProtocol(const QByteArray &pool, const QByteArray &app)
|
||||||
: SlaveBase("recoll", pool, app), m_initok(false),
|
: SlaveBase("recoll", pool, app), m_initok(false), m_rcldb(0)
|
||||||
m_rclconfig(0), m_rcldb(0)
|
|
||||||
{
|
{
|
||||||
m_pager.setParent(this);
|
kDebug() << endl;
|
||||||
string reason;
|
if (o_rclconfig == 0) {
|
||||||
rclconfig = m_rclconfig = recollinit(0, 0, m_reason);
|
o_rclconfig = recollinit(0, 0, m_reason);
|
||||||
if (!m_rclconfig || !m_rclconfig->ok()) {
|
if (!o_rclconfig || !o_rclconfig->ok()) {
|
||||||
m_reason = string("Configuration problem: ") + reason;
|
m_reason = string("Configuration problem: ") + m_reason;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_dbdir = m_rclconfig->getDbDir();
|
if (o_rclconfig->getDbDir().empty()) {
|
||||||
if (m_dbdir.empty()) {
|
|
||||||
// Note: this will have to be replaced by a call to a
|
// Note: this will have to be replaced by a call to a
|
||||||
// configuration buildin dialog for initial configuration
|
// configuration buildin dialog for initial configuration
|
||||||
m_reason = "No db directory in configuration ??";
|
m_reason = "No db directory in configuration ??";
|
||||||
@ -126,20 +88,17 @@ RecollProtocol::RecollProtocol(const QByteArray &pool, const QByteArray &app)
|
|||||||
m_reason = "Could not build database object. (out of memory ?)";
|
m_reason = "Could not build database object. (out of memory ?)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
m_pager.setParent(this);
|
||||||
m_initok = true;
|
m_initok = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There should be an object counter somewhere to delete the config when done.
|
||||||
|
// Doesn't seem needed in the kio context.
|
||||||
RecollProtocol::~RecollProtocol()
|
RecollProtocol::~RecollProtocol()
|
||||||
{
|
{
|
||||||
|
kDebug() << endl;
|
||||||
delete m_rcldb;
|
delete m_rcldb;
|
||||||
delete m_rclconfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RecollProtocol::mimetype(const KUrl & /*url*/)
|
|
||||||
{
|
|
||||||
mimeType("text/html");
|
|
||||||
finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecollProtocol::maybeOpenDb(string &reason)
|
bool RecollProtocol::maybeOpenDb(string &reason)
|
||||||
@ -148,43 +107,104 @@ bool RecollProtocol::maybeOpenDb(string &reason)
|
|||||||
reason = "Internal error: initialization error";
|
reason = "Internal error: initialization error";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!m_rcldb->isopen() && !m_rcldb->open(m_dbdir,
|
if (!m_rcldb->isopen() && !m_rcldb->open(o_rclconfig->getDbDir(),
|
||||||
m_rclconfig->getStopfile(),
|
o_rclconfig->getStopfile(),
|
||||||
Rcl::Db::DbRO)) {
|
Rcl::Db::DbRO)) {
|
||||||
reason = "Could not open database in " + m_dbdir;
|
reason = "Could not open database in " + o_rclconfig->getDbDir();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string welcomedata;
|
void RecollProtocol::mimetype(const KUrl &url)
|
||||||
|
|
||||||
void RecollProtocol::welcomePage()
|
|
||||||
{
|
{
|
||||||
kDebug() << endl;
|
kDebug() << url << endl;
|
||||||
if (welcomedata.empty()) {
|
if (0)
|
||||||
QString location =
|
mimeType("text/html");
|
||||||
KStandardDirs::locate("data", "kio_recoll/welcome.html");
|
else
|
||||||
string reason;
|
mimeType("inode/directory");
|
||||||
if (location.isEmpty() ||
|
finished();
|
||||||
!file_to_string((const char *)location.toUtf8(),
|
}
|
||||||
welcomedata, &reason)) {
|
|
||||||
welcomedata = "<html><head><title>Recoll Error</title></head>"
|
bool RecollProtocol::URLToQuery(const KUrl &url, QString& q, QString& opt)
|
||||||
"<body><p>Could not locate Recoll welcome.html file: ";
|
{
|
||||||
welcomedata += reason;
|
if (url.host().isEmpty()) {
|
||||||
welcomedata += "</p></body></html>";
|
q = url.path();
|
||||||
|
opt = "l";
|
||||||
|
} else {
|
||||||
|
// Decode the forms' arguments
|
||||||
|
q = url.queryItem("q");
|
||||||
|
opt = url.queryItem("qtp");
|
||||||
|
if (opt.isEmpty()) {
|
||||||
|
opt = "l";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string tmp;
|
return true;
|
||||||
map<char, string> subs;
|
}
|
||||||
subs['Q'] = "";
|
|
||||||
pcSubst(welcomedata, tmp, subs);
|
void RecollProtocol::get(const KUrl & url)
|
||||||
data(tmp.c_str());
|
{
|
||||||
kDebug() << "WelcomePage done" << endl;
|
kDebug() << url << endl;
|
||||||
|
|
||||||
|
if (!m_initok || !maybeOpenDb(m_reason)) {
|
||||||
|
error(KIO::ERR_SLAVE_DEFINED, "Init error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
error(KIO::ERR_IS_DIRECTORY, QString::null);
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString host = url.host();
|
||||||
|
QString path = url.path();
|
||||||
|
|
||||||
|
kDebug() << "host:" << host << " path:" << path;
|
||||||
|
|
||||||
|
if (host.isEmpty() && !path.compare("/")) {
|
||||||
|
// recoll:/
|
||||||
|
welcomePage();
|
||||||
|
goto out;
|
||||||
|
} else if ((!host.compare("search") && !path.compare("/query"))
|
||||||
|
|| host.isEmpty()) {
|
||||||
|
// Either "recoll://search/query?query args"
|
||||||
|
// Or "recoll: some search string"
|
||||||
|
QString query, opt;
|
||||||
|
URLToQuery(url, query, opt);
|
||||||
|
if (!query.isEmpty()) {
|
||||||
|
htmlDoSearch(query, opt.toUtf8().at(0));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
} else if (!host.compare("command")) {
|
||||||
|
if (!path.isEmpty()) {
|
||||||
|
if (path.indexOf("/Page") == 0) {
|
||||||
|
int newpage = 0;
|
||||||
|
sscanf(path.toUtf8(), "/Page%d", &newpage);
|
||||||
|
if (newpage > m_pager.pageNumber()) {
|
||||||
|
int npages = newpage - m_pager.pageNumber();
|
||||||
|
for (int i = 0; i < npages; i++)
|
||||||
|
m_pager.resultPageNext();
|
||||||
|
} else if (newpage < m_pager.pageNumber()) {
|
||||||
|
int npages = m_pager.pageNumber() - newpage;
|
||||||
|
for (int i = 0; i < npages; i++)
|
||||||
|
m_pager.resultPageBack();
|
||||||
|
}
|
||||||
|
mimeType("text/html");
|
||||||
|
m_pager.displayPage();
|
||||||
|
goto out;
|
||||||
|
} else if (path.indexOf("/QueryDetails") == 0) {
|
||||||
|
queryDetails();
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kDebug() << "Unrecognized URL" << endl;
|
||||||
|
outputError("unrecognized URL");
|
||||||
|
out:
|
||||||
|
finished();
|
||||||
|
kDebug() << "done" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecollProtocol::doSearch(const QString& q, char opt)
|
void RecollProtocol::doSearch(const QString& q, char opt)
|
||||||
{
|
{
|
||||||
|
kDebug() << q << endl;
|
||||||
string qs = (const char *)q.toUtf8();
|
string qs = (const char *)q.toUtf8();
|
||||||
Rcl::SearchData *sd = 0;
|
Rcl::SearchData *sd = 0;
|
||||||
if (opt != 'l') {
|
if (opt != 'l') {
|
||||||
@ -207,7 +227,7 @@ void RecollProtocol::doSearch(const QString& q, char opt)
|
|||||||
if (sd && clp)
|
if (sd && clp)
|
||||||
sd->addClause(clp);
|
sd->addClause(clp);
|
||||||
} else {
|
} else {
|
||||||
kDebug() << "Parsing query";
|
kDebug() << "Parsing query: " << qs.c_str();
|
||||||
sd = wasaStringToRcl(qs, m_reason);
|
sd = wasaStringToRcl(qs, m_reason);
|
||||||
}
|
}
|
||||||
if (!sd) {
|
if (!sd) {
|
||||||
@ -219,6 +239,7 @@ void RecollProtocol::doSearch(const QString& q, char opt)
|
|||||||
|
|
||||||
RefCntr<Rcl::SearchData> sdata(sd);
|
RefCntr<Rcl::SearchData> sdata(sd);
|
||||||
sdata->setStemlang("english");
|
sdata->setStemlang("english");
|
||||||
|
kDebug() << "Building query";
|
||||||
RefCntr<Rcl::Query>query(new Rcl::Query(m_rcldb));
|
RefCntr<Rcl::Query>query(new Rcl::Query(m_rcldb));
|
||||||
if (!query->setQuery(sdata)) {
|
if (!query->setQuery(sdata)) {
|
||||||
m_reason = "Internal Error: setQuery failed";
|
m_reason = "Internal Error: setQuery failed";
|
||||||
@ -226,115 +247,19 @@ void RecollProtocol::doSearch(const QString& q, char opt)
|
|||||||
finished();
|
finished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
kDebug() << "Building docsequence";
|
||||||
DocSequenceDb *src =
|
DocSequenceDb *src =
|
||||||
new DocSequenceDb(RefCntr<Rcl::Query>(query), "Query results",
|
new DocSequenceDb(RefCntr<Rcl::Query>(query), "Query results", sdata);
|
||||||
sdata);
|
if (src == 0) {
|
||||||
|
kDebug() << "Cant' build result sequence";
|
||||||
m_pager.setDocSource(RefCntr<DocSequence>(src));
|
error(-1, QString::null);
|
||||||
m_pager.resultPageNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RecollProtocol::get(const KUrl & url)
|
|
||||||
{
|
|
||||||
kDebug() << url << endl;
|
|
||||||
|
|
||||||
mimeType("text/html");
|
|
||||||
|
|
||||||
if (!m_initok || !maybeOpenDb(m_reason)) {
|
|
||||||
outputError(m_reason.c_str());
|
|
||||||
finished();
|
finished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
kDebug() << "Setting source";
|
||||||
QString host = url.host();
|
m_source = RefCntr<DocSequence>(src);
|
||||||
QString path = url.path();
|
|
||||||
kDebug() << "host:" << host << " path:" << path;
|
|
||||||
if (host.isEmpty() || !host.compare("welcome")) {
|
|
||||||
kDebug() << "Host is empty";
|
|
||||||
if (path.isEmpty() || !path.compare("/")) {
|
|
||||||
kDebug() << "Path is empty or strange";
|
|
||||||
// Display welcome page
|
|
||||||
welcomePage();
|
|
||||||
finished();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Ie: "recoll: some search string"
|
|
||||||
doSearch(path);
|
|
||||||
} else if (!host.compare("search")) {
|
|
||||||
if (path.compare("/query")) {
|
|
||||||
finished(); return;
|
|
||||||
}
|
|
||||||
// Decode the forms' arguments
|
|
||||||
QString query = url.queryItem("q");
|
|
||||||
if (query.isEmpty()) {
|
|
||||||
finished(); return;
|
|
||||||
}
|
|
||||||
QString opt = url.queryItem("qtp");
|
|
||||||
if (opt.isEmpty()) {
|
|
||||||
opt = "l";
|
|
||||||
}
|
|
||||||
doSearch(query, opt.toUtf8().at(0));
|
|
||||||
} else if (!host.compare("command")) {
|
|
||||||
if (path.isEmpty()) {
|
|
||||||
finished();return;
|
|
||||||
} else if (path.indexOf("/Page") == 0) {
|
|
||||||
int newpage = 0;
|
|
||||||
sscanf(path.toUtf8(), "/Page%d", &newpage);
|
|
||||||
if (newpage > m_pager.pageNumber()) {
|
|
||||||
int npages = newpage - m_pager.pageNumber();
|
|
||||||
for (int i = 0; i < npages; i++)
|
|
||||||
m_pager.resultPageNext();
|
|
||||||
} else if (newpage < m_pager.pageNumber()) {
|
|
||||||
int npages = m_pager.pageNumber() - newpage;
|
|
||||||
for (int i = 0; i < npages; i++)
|
|
||||||
m_pager.resultPageBack();
|
|
||||||
}
|
|
||||||
} else if (path.indexOf("/QueryDetails") == 0) {
|
|
||||||
QByteArray array;
|
|
||||||
QTextStream os(&array, QIODevice::WriteOnly);
|
|
||||||
|
|
||||||
os << "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" << endl;
|
|
||||||
os << "<title>" << "Recoll query details" << "</title>\n" << endl;
|
|
||||||
os << "</head>" << endl;
|
|
||||||
os << "<body><h3>Query details:</h3>" << endl;
|
|
||||||
os << "<p>" << m_pager.queryDescription().c_str() <<"</p>"<< endl;
|
|
||||||
os << "<p><a href=\"recoll://command/Page" <<
|
|
||||||
m_pager.pageNumber() << "\">Return to results</a>" << endl;
|
|
||||||
os << "</body></html>" << endl;
|
|
||||||
data(array);
|
|
||||||
finished();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
// Unknown //command/???
|
|
||||||
finished(); return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Unknown 'host' //??? value
|
|
||||||
finished(); return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pager.displayPage();
|
|
||||||
|
|
||||||
kDebug() << "call finished" << endl;
|
|
||||||
finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecollProtocol::outputError(const QString& errmsg)
|
|
||||||
{
|
|
||||||
QByteArray array;
|
|
||||||
QTextStream os(&array, QIODevice::WriteOnly);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Note: KDE_EXPORT is actually needed on Unix when building with
|
// Note: KDE_EXPORT is actually needed on Unix when building with
|
||||||
// cmake. Says something like __attribute__(visibility(defautl))
|
// cmake. Says something like __attribute__(visibility(defautl))
|
||||||
// (cmake apparently sets all symbols to not exported)
|
// (cmake apparently sets all symbols to not exported)
|
||||||
@ -360,4 +285,3 @@ int kdemain(int argc, char **argv)
|
|||||||
kDebug() << "kio_recoll Done" << endl;
|
kDebug() << "kio_recoll Done" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,22 @@
|
|||||||
#ifndef _RECOLL_H
|
#ifndef _RECOLL_H
|
||||||
/* @(#$Id: kio_recoll.h,v 1.6 2008-11-20 13:10:23 dockes Exp $ (C) 2005 J.F.Dockes */
|
/* @(#$Id: kio_recoll.h,v 1.7 2008-11-26 15:03:41 dockes Exp $ (C) 2005 J.F.Dockes */
|
||||||
#define _RECOLL_H
|
#define _RECOLL_H
|
||||||
|
/*
|
||||||
|
* 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 <string>
|
#include <string>
|
||||||
using std::string;
|
using std::string;
|
||||||
@ -17,7 +33,11 @@ using std::string;
|
|||||||
#include <kio/global.h>
|
#include <kio/global.h>
|
||||||
#include <kio/slavebase.h>
|
#include <kio/slavebase.h>
|
||||||
|
|
||||||
|
#include "rclconfig.h"
|
||||||
|
#include "rcldb.h"
|
||||||
#include "reslistpager.h"
|
#include "reslistpager.h"
|
||||||
|
#include "docseq.h"
|
||||||
|
#include "refcntr.h"
|
||||||
|
|
||||||
class RecollProtocol;
|
class RecollProtocol;
|
||||||
|
|
||||||
@ -42,20 +62,25 @@ class RecollProtocol : public KIO::SlaveBase {
|
|||||||
virtual ~RecollProtocol();
|
virtual ~RecollProtocol();
|
||||||
virtual void mimetype(const KUrl & url );
|
virtual void mimetype(const KUrl & url );
|
||||||
virtual void get(const KUrl & url );
|
virtual void get(const KUrl & url );
|
||||||
|
virtual void stat(const KUrl & url);
|
||||||
|
virtual void listDir(const KUrl& url);
|
||||||
|
|
||||||
|
static RclConfig *o_rclconfig;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool maybeOpenDb(string &reason);
|
bool maybeOpenDb(string &reason);
|
||||||
void outputError(const QString& errmsg);
|
void outputError(const QString& errmsg);
|
||||||
void doSearch(const QString& q, char opt = 'l');
|
void doSearch(const QString& q, char opt = 'l');
|
||||||
void welcomePage();
|
void welcomePage();
|
||||||
|
void queryDetails();
|
||||||
|
void htmlDoSearch(const QString& q, char opt);
|
||||||
|
bool URLToQuery(const KUrl &url, QString& q, QString& opt);
|
||||||
|
|
||||||
bool m_initok;
|
bool m_initok;
|
||||||
RclConfig *m_rclconfig;
|
|
||||||
Rcl::Db *m_rcldb;
|
Rcl::Db *m_rcldb;
|
||||||
std::string m_dbdir;
|
|
||||||
std::string m_reason;
|
std::string m_reason;
|
||||||
RecollKioPager m_pager;
|
RecollKioPager m_pager;
|
||||||
|
RefCntr<DocSequence> m_source;
|
||||||
};
|
};
|
||||||
extern "C" {int kdemain(int, char**);}
|
extern "C" {int kdemain(int, char**);}
|
||||||
|
|
||||||
|
|||||||
12
src/kde/kioslave/recoll/notes.txt
Normal file
12
src/kde/kioslave/recoll/notes.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
- Sur ubuntu et freebsd cmake installe
|
||||||
|
-- Installing /usr/lib/kde4/kio_recoll.so
|
||||||
|
Au lieu de /usr/lib/kde4/lib/kde4/kio_recoll.so
|
||||||
|
-- Installing /usr/share/kde4/services/recoll.protocol
|
||||||
|
Au lieu de /usr/lib/kde4/share/kde4/services/recoll.protocol
|
||||||
|
-- Installing /usr/share/apps/kio_recoll/welcome.html
|
||||||
|
Au lieu de /usr/lib/kde4/share/kde4/apps/
|
||||||
|
|
||||||
|
- Il faut configurer cmake avec target /usr, donc attention a configurer
|
||||||
|
recoll avec --target=/usr pour que les fichiers de config soient au bon
|
||||||
|
endroit
|
||||||
|
|
||||||
@ -3,7 +3,9 @@ exec=kio_recoll
|
|||||||
protocol=recoll
|
protocol=recoll
|
||||||
input=none
|
input=none
|
||||||
output=filesystem
|
output=filesystem
|
||||||
|
listing=Name,Type, URL
|
||||||
reading=true
|
reading=true
|
||||||
defaultMimeType=text/html
|
defaultMimeType=inode/directory
|
||||||
Icon=help_index
|
Icon=help_index
|
||||||
Class=:local
|
Class=:local
|
||||||
|
URIMode=rawuri
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user