astyled + removed some debug/diag statements inserted during kde5 port

This commit is contained in:
Jean-Francois Dockes 2016-04-05 08:45:51 +02:00
parent 2de064796d
commit 5435681d4e
5 changed files with 441 additions and 391 deletions

View File

@ -87,7 +87,8 @@ z
pthread pthread
) )
install(FILES recoll.protocol DESTINATION ${SERVICES_INSTALL_DIR}) install(FILES recoll.protocol recollf.protocol
DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES data/welcome.html data/help.html install(FILES data/welcome.html data/help.html
DESTINATION ${DATA_INSTALL_DIR}/kio_recoll) DESTINATION ${DATA_INSTALL_DIR}/kio_recoll)

View File

@ -45,10 +45,10 @@ static const QString resultBaseName("recollResult");
// Check if the input URL is of the form that konqueror builds by // Check if the input URL is of the form that konqueror builds by
// appending one of our result file names to the directory name (which // appending one of our result file names to the directory name (which
// is the search string). If it is, extract return the result document // is the search string). If it is, extract and return the result
// number. Possibly restart the search if the search string does not // document number. Possibly restart the search if the search string
// match the current one // does not match the current one
bool RecollProtocol::isRecollResult(const QUrl &url, int *num, QString *q) bool RecollProtocol::isRecollResult(const QUrl& url, int *num, QString *q)
{ {
*num = -1; *num = -1;
qDebug() << "RecollProtocol::isRecollResult: url: " << url; qDebug() << "RecollProtocol::isRecollResult: url: " << url;
@ -63,32 +63,35 @@ bool RecollProtocol::isRecollResult(const QUrl &url, int *num, QString *q)
QString path = url.path(); QString path = url.path();
qDebug() << "RecollProtocol::isRecollResult: path: " << path; qDebug() << "RecollProtocol::isRecollResult: path: " << path;
// if (!path.startsWith("/")) { if (!path.startsWith("/")) {
// return false; return false;
// } }
// Look for the last '/' and check if it is followed by // Look for the last '/' and check if it is followed by
// resultBaseName (riiiight...) // resultBaseName (riiiight...)
int slashpos = path.lastIndexOf("/"); int slashpos = path.lastIndexOf("/");
if (slashpos == -1 || slashpos == 0 || slashpos == path.length() -1) if (slashpos == -1 || slashpos == 0 || slashpos == path.length() - 1) {
return false; return false;
}
slashpos++; slashpos++;
//qDebug() << "Comparing " << path.mid(slashpos, resultBaseName.length()) << //qDebug() << "Comparing " << path.mid(slashpos, resultBaseName.length()) <<
// "and " << resultBaseName; // "and " << resultBaseName;
if (path.mid(slashpos, resultBaseName.length()).compare(resultBaseName)) if (path.mid(slashpos, resultBaseName.length()).compare(resultBaseName)) {
return false; return false;
}
// Extract the result number // Extract the result number
QString snum = path.mid(slashpos + resultBaseName.length()); QString snum = path.mid(slashpos + resultBaseName.length());
sscanf(snum.toUtf8(), "%d", num); sscanf(snum.toUtf8(), "%d", num);
if (*num == -1) if (*num == -1) {
return false; return false;
}
//qDebug() << "URL analysis ok, num:" << *num; //qDebug() << "URL analysis ok, num:" << *num;
// We do have something that ressembles a recoll result locator. Check if // We do have something that ressembles a recoll result locator. Check if
// this matches the current search, else have to run the requested one // this matches the current search, else have to run the requested one
*q = path.mid(1, slashpos-2); *q = path.mid(1, slashpos - 2);
return true; return true;
} }
@ -98,31 +101,57 @@ static const UDSEntry resultToUDSEntry(const Rcl::Doc& doc, int num)
UDSEntry entry; UDSEntry entry;
QUrl url(doc.url.c_str()); QUrl url(doc.url.c_str());
// qDebug() << doc.url.c_str(); //qDebug() << doc.url.c_str();
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, url.fileName()); /// Filename - as displayed in directory listings etc.
char cnum[30];sprintf(cnum, "%04d", num); /// "." has the usual special meaning of "current directory"
/// UDS_NAME must always be set and never be empty, neither contain '/'.
///
/// Note that KIO will append the UDS_NAME to the url of their
/// parent directory, so all kioslaves must use that naming scheme
/// ("url_of_parent/filename" will be the full url of that file).
/// To customize the appearance of files without changing the url
/// of the items, use UDS_DISPLAY_NAME.
//
// Use the result number to designate the file in case we are
// asked to access it
char cnum[30];
sprintf(cnum, "%04d", num);
entry.insert(KIO::UDSEntry::UDS_NAME, resultBaseName + cnum); entry.insert(KIO::UDSEntry::UDS_NAME, resultBaseName + cnum);
// Display the real file name
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, url.fileName());
/// A local file path if the ioslave display files sitting on the
/// local filesystem (but in another hierarchy, e.g. settings:/ or
/// remote:/)
entry.insert(KIO::UDSEntry::UDS_LOCAL_PATH, url.path());
/// This file is a shortcut or mount, pointing to an
/// URL in a different hierarchy
/// @since 4.1
// We should probably set this only if the scheme is not 'file' (e.g.
// from the web cache).
entry.insert(KIO::UDSEntry::UDS_TARGET_URL, doc.url.c_str());
if (!doc.mimetype.compare("application/x-fsdirectory") || if (!doc.mimetype.compare("application/x-fsdirectory") ||
!doc.mimetype.compare("inode/directory")) { !doc.mimetype.compare("inode/directory")) {
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory"); entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory");
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
} else { } else {
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, doc.mimetype.c_str()); 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_FILE_TYPE, S_IFREG);
} }
entry.insert(KIO::UDSEntry::UDS_LOCAL_PATH, url.path());
// For local files, supply the usual file stat information // For local files, supply the usual file stat information
struct stat info; struct stat info;
if (lstat(url.path().toUtf8(), &info) >= 0) { if (lstat(url.path().toUtf8(), &info) >= 0) {
entry.insert( KIO::UDSEntry::UDS_SIZE, info.st_size); entry.insert(KIO::UDSEntry::UDS_SIZE, info.st_size);
entry.insert( KIO::UDSEntry::UDS_ACCESS, info.st_mode); entry.insert(KIO::UDSEntry::UDS_ACCESS, info.st_mode);
entry.insert( KIO::UDSEntry::UDS_MODIFICATION_TIME, info.st_mtime); 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_ACCESS_TIME, info.st_atime);
entry.insert( KIO::UDSEntry::UDS_CREATION_TIME, info.st_ctime); entry.insert(KIO::UDSEntry::UDS_CREATION_TIME, info.st_ctime);
} }
entry.insert(KIO::UDSEntry::UDS_TARGET_URL, doc.url.c_str());
return entry; return entry;
} }
@ -132,10 +161,10 @@ static const UDSEntry resultToUDSEntry(const Rcl::Doc& doc, int num)
static void createRootEntry(KIO::UDSEntry& entry) static void createRootEntry(KIO::UDSEntry& entry)
{ {
entry.clear(); entry.clear();
entry.insert( KIO::UDSEntry::UDS_NAME, "."); entry.insert(KIO::UDSEntry::UDS_NAME, ".");
entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
entry.insert( KIO::UDSEntry::UDS_ACCESS, 0700); entry.insert(KIO::UDSEntry::UDS_ACCESS, 0700);
entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory"); entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory");
} }
// Points to html query screen // Points to html query screen
@ -168,6 +197,7 @@ static void createGoHelpEntry(KIO::UDSEntry& entry)
entry.insert(KIO::UDSEntry::UDS_ICON_NAME, "help"); entry.insert(KIO::UDSEntry::UDS_ICON_NAME, "help");
} }
// As far as I can see we only ever get this on '/' so why all the code?
void RecollProtocol::stat(const QUrl& url) void RecollProtocol::stat(const QUrl& url)
{ {
qDebug() << "RecollProtocol::stat:" << url; qDebug() << "RecollProtocol::stat:" << url;
@ -175,14 +205,14 @@ void RecollProtocol::stat(const QUrl& url)
UrlIngester ingest(this, url); UrlIngester ingest(this, url);
KIO::UDSEntry entry; KIO::UDSEntry entry;
entry.insert(KIO::UDSEntry::UDS_TARGET_URL, url.url()); // entry.insert(KIO::UDSEntry::UDS_TARGET_URL, url.url());
entry.insert(KIO::UDSEntry::UDS_URL, url.url()); // entry.insert(KIO::UDSEntry::UDS_URL, url.url());
UrlIngester::RootEntryType rettp; UrlIngester::RootEntryType rettp;
QueryDesc qd; QueryDesc qd;
int num; int num;
if (ingest.isRootEntry(&rettp)) { if (ingest.isRootEntry(&rettp)) {
qDebug() << "RecollProtocol::stat: root entry"; qDebug() << "RecollProtocol::stat: root entry";
switch(rettp) { switch (rettp) {
case UrlIngester::UIRET_ROOT: case UrlIngester::UIRET_ROOT:
qDebug() << "RecollProtocol::stat: root"; qDebug() << "RecollProtocol::stat: root";
createRootEntry(entry); createRootEntry(entry);
@ -224,20 +254,15 @@ void RecollProtocol::stat(const QUrl& url)
// //
// Another approach would be to use different protocol names // Another approach would be to use different protocol names
// to avoid any possibility of mixups // to avoid any possibility of mixups
if (true || m_alwaysdir || ingest.alwaysDir() || ingest.endSlashQuery()) { if (m_alwaysdir || ingest.alwaysDir() || ingest.endSlashQuery()) {
qDebug() << "RecollProtocol::stat: Directory type:"; qDebug() << "RecollProtocol::stat: Directory type:";
// Need to check no / in there // Need to check no / in there
#if 0 entry.insert(KIO::UDSEntry::UDS_NAME, qd.query);
entry.insert(KIO::UDSEntry::UDS_NAME, "dockes bla"/*qd.query*/); entry.insert(KIO::UDSEntry::UDS_ACCESS, 0700);
entry.insert(KIO::UDSEntry::UDS_URL, "recoll:other query");
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, qd.query);
entry.insert(KIO::UDSEntry::UDS_ACCESS, 0777);
entry.insert(KIO::UDSEntry::UDS_SIZE, 20480);
entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, time(0)); entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, time(0));
entry.insert(KIO::UDSEntry::UDS_CREATION_TIME, time(0)); entry.insert(KIO::UDSEntry::UDS_CREATION_TIME, time(0));
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory"); entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory");
#endif
} }
} else { } else {
qDebug() << "RecollProtocol::stat: none of the above ??"; qDebug() << "RecollProtocol::stat: none of the above ??";
@ -255,9 +280,8 @@ void RecollProtocol::listDir(const QUrl& url)
QueryDesc qd; QueryDesc qd;
if (ingest.isRootEntry(&rettp)) { if (ingest.isRootEntry(&rettp)) {
switch(rettp) { switch (rettp) {
case UrlIngester::UIRET_ROOT: case UrlIngester::UIRET_ROOT: {
{
qDebug() << "RecollProtocol::listDir:list /"; qDebug() << "RecollProtocol::listDir:list /";
UDSEntryList entries; UDSEntryList entries;
KIO::UDSEntry entry; KIO::UDSEntry entry;
@ -297,11 +321,13 @@ void RecollProtocol::listDir(const QUrl& url)
static int maxentries = -1; static int maxentries = -1;
if (maxentries == -1) { if (maxentries == -1) {
if (o_rclconfig) if (o_rclconfig) {
o_rclconfig->getConfParam("kio_max_direntries", &maxentries); o_rclconfig->getConfParam("kio_max_direntries", &maxentries);
if (maxentries == -1) }
if (maxentries == -1) {
maxentries = 10000; maxentries = 10000;
} }
}
static const int pagesize = 200; static const int pagesize = 200;
int pagebase = 0; int pagebase = 0;
while (pagebase < maxentries) { while (pagebase < maxentries) {

View File

@ -45,8 +45,9 @@ using namespace KIO;
bool RecollKioPager::append(const string& data) bool RecollKioPager::append(const string& data)
{ {
if (!m_parent) if (!m_parent) {
return false; return false;
}
m_parent->data(QByteArray(data.c_str())); m_parent->data(QByteArray(data.c_str()));
return true; return true;
} }
@ -57,10 +58,12 @@ string RecollProtocol::makeQueryUrl(int page, bool isdet)
str << "recoll://search/query?q=" << str << "recoll://search/query?q=" <<
url_encode((const char*)m_query.query.toUtf8()) << url_encode((const char*)m_query.query.toUtf8()) <<
"&qtp=" << (const char*)m_query.opt.toUtf8(); "&qtp=" << (const char*)m_query.opt.toUtf8();
if (page >= 0) if (page >= 0) {
str << "&p=" << page; str << "&p=" << page;
if (isdet) }
if (isdet) {
str << "&det=1"; str << "&det=1";
}
return str.str(); return str.str();
} }
@ -78,7 +81,7 @@ const string& RecollKioPager::parFormat()
// Need to escape the % inside the query url // Need to escape the % inside the query url
string qurl = m_parent->makeQueryUrl(-1, false), escurl; string qurl = m_parent->makeQueryUrl(-1, false), escurl;
for (string::size_type pos = 0; pos < qurl.length(); pos++) { for (string::size_type pos = 0; pos < qurl.length(); pos++) {
switch(qurl.at(pos)) { switch (qurl.at(pos)) {
case '%': case '%':
escurl += "%%"; escurl += "%%";
break; break;
@ -117,20 +120,22 @@ string RecollKioPager::pageTop()
string RecollKioPager::nextUrl() string RecollKioPager::nextUrl()
{ {
int pagenum = pageNumber(); int pagenum = pageNumber();
if (pagenum < 0) if (pagenum < 0) {
pagenum = 0; pagenum = 0;
else } else {
pagenum++; pagenum++;
}
return m_parent->makeQueryUrl(pagenum); return m_parent->makeQueryUrl(pagenum);
} }
string RecollKioPager::prevUrl() string RecollKioPager::prevUrl()
{ {
int pagenum = pageNumber(); int pagenum = pageNumber();
if (pagenum <= 0) if (pagenum <= 0) {
pagenum = 0; pagenum = 0;
else } else {
pagenum--; pagenum--;
}
return m_parent->makeQueryUrl(pagenum); return m_parent->makeQueryUrl(pagenum);
} }
@ -164,7 +169,7 @@ void RecollProtocol::searchPage()
if (o_rclconfig->getMimeCategories(cats) && !cats.empty()) { if (o_rclconfig->getMimeCategories(cats) && !cats.empty()) {
catgq = "<p>Filter on types: " catgq = "<p>Filter on types: "
"<input type=\"radio\" name=\"ct\" value=\"All\" checked>All"; "<input type=\"radio\" name=\"ct\" value=\"All\" checked>All";
for (list<string>::iterator it = cats.begin(); it != cats.end();it++) { for (list<string>::iterator it = cats.begin(); it != cats.end(); it++) {
catgq += "\n<input type=\"radio\" name=\"ct\" value=\"" + catgq += "\n<input type=\"radio\" name=\"ct\" value=\"" +
*it + "\">" + *it ; *it + "\">" + *it ;
} }
@ -192,7 +197,7 @@ void RecollProtocol::queryDetails()
os << "<title>" << "Recoll query details" << "</title>\n" << endl; os << "<title>" << "Recoll query details" << "</title>\n" << endl;
os << "</head>" << endl; os << "</head>" << endl;
os << "<body><h3>Query details:</h3>" << endl; os << "<body><h3>Query details:</h3>" << endl;
os << "<p>" << m_pager.queryDescription().c_str() <<"</p>"<< endl; os << "<p>" << m_pager.queryDescription().c_str() << "</p>" << endl;
os << "<p><a href=\"" << makeQueryUrl(m_pager.pageNumber()).c_str() << os << "<p><a href=\"" << makeQueryUrl(m_pager.pageNumber()).c_str() <<
"\">Return to results</a>" << endl; "\">Return to results</a>" << endl;
os << "</body></html>" << endl; os << "</body></html>" << endl;
@ -202,8 +207,7 @@ void RecollProtocol::queryDetails()
class PlainToRichKio : public PlainToRich { class PlainToRichKio : public PlainToRich {
public: public:
PlainToRichKio(const string& nm) PlainToRichKio(const string& nm)
: m_name(nm) : m_name(nm) {
{
} }
virtual string header() { virtual string header() {
@ -218,17 +222,15 @@ public:
} }
} }
virtual string startMatch(unsigned int) virtual string startMatch(unsigned int) {
{
return string("<font color=\"blue\">"); return string("<font color=\"blue\">");
} }
virtual string endMatch() virtual string endMatch() {
{
return string("</font>"); return string("</font>");
} }
const string &m_name; const string& m_name;
}; };
void RecollProtocol::showPreview(const Rcl::Doc& idoc) void RecollProtocol::showPreview(const Rcl::Doc& idoc)
@ -253,8 +255,9 @@ void RecollProtocol::showPreview(const Rcl::Doc& idoc)
ptr.set_inputhtml(!fdoc.mimetype.compare("text/html")); ptr.set_inputhtml(!fdoc.mimetype.compare("text/html"));
list<string> otextlist; list<string> otextlist;
HighlightData hdata; HighlightData hdata;
if (m_source) if (m_source) {
m_source->getTerms(hdata); m_source->getTerms(hdata);
}
ptr.plaintorich(fdoc.text, otextlist, hdata); ptr.plaintorich(fdoc.text, otextlist, hdata);
QByteArray array; QByteArray array;
@ -274,8 +277,9 @@ void RecollProtocol::htmlDoSearch(const QueryDesc& qd)
mimeType("text/html"); mimeType("text/html");
if (!syncSearch(qd)) if (!syncSearch(qd)) {
return; return;
}
// syncSearch/doSearch do the setDocSource when needed // syncSearch/doSearch do the setDocSource when needed
if (m_pager.pageNumber() < 0) { if (m_pager.pageNumber() < 0) {
m_pager.resultPageNext(); m_pager.resultPageNext();
@ -288,13 +292,15 @@ void RecollProtocol::htmlDoSearch(const QueryDesc& qd)
// Check / adjust page number // Check / adjust page number
if (qd.page > m_pager.pageNumber()) { if (qd.page > m_pager.pageNumber()) {
int npages = qd.page - m_pager.pageNumber(); int npages = qd.page - m_pager.pageNumber();
for (int i = 0; i < npages; i++) for (int i = 0; i < npages; i++) {
m_pager.resultPageNext(); m_pager.resultPageNext();
}
} else if (qd.page < m_pager.pageNumber()) { } else if (qd.page < m_pager.pageNumber()) {
int npages = m_pager.pageNumber() - qd.page; int npages = m_pager.pageNumber() - qd.page;
for (int i = 0; i < npages; i++) for (int i = 0; i < npages; i++) {
m_pager.resultPageBack(); m_pager.resultPageBack();
} }
}
// Display // Display
m_pager.displayPage(o_rclconfig); m_pager.displayPage(o_rclconfig);
} }

View File

@ -47,14 +47,11 @@ using namespace std;
RclConfig *RecollProtocol::o_rclconfig; RclConfig *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), m_rcldb(0), : SlaveBase("recoll", pool, app), m_initok(false), m_rcldb(0),
m_alwaysdir(false) m_alwaysdir(false)
{ {
qDebug() << "RecollProtocol::RecollProtocol()"; qDebug() << "RecollProtocol::RecollProtocol()";
int fd = ::creat("/tmp/recolldebug", 0666);
::write(fd, "Hello\n", strlen("Hello\n"));
::close(fd);
if (o_rclconfig == 0) { if (o_rclconfig == 0) {
o_rclconfig = recollinit(0, 0, m_reason); o_rclconfig = recollinit(0, 0, m_reason);
if (!o_rclconfig || !o_rclconfig->ok()) { if (!o_rclconfig || !o_rclconfig->ok()) {
@ -106,7 +103,7 @@ RecollProtocol::~RecollProtocol()
delete m_rcldb; delete m_rcldb;
} }
bool RecollProtocol::maybeOpenDb(string &reason) bool RecollProtocol::maybeOpenDb(string& reason)
{ {
if (!m_rcldb) { if (!m_rcldb) {
reason = "Internal error: initialization error"; reason = "Internal error: initialization error";
@ -120,7 +117,7 @@ bool RecollProtocol::maybeOpenDb(string &reason)
} }
// This is never called afaik // This is never called afaik
void RecollProtocol::mimetype(const QUrl &url) void RecollProtocol::mimetype(const QUrl& url)
{ {
qDebug() << "RecollProtocol::mimetype: url: " << url; qDebug() << "RecollProtocol::mimetype: url: " << url;
mimeType("text/html"); mimeType("text/html");
@ -200,8 +197,9 @@ UrlIngester::UrlIngester(RecollProtocol *p, const QUrl& url)
} }
} }
} }
if (m_query.query.startsWith("/")) if (m_query.query.startsWith("/")) {
m_query.query.remove(0,1); m_query.query.remove(0, 1);
}
if (m_query.query.endsWith("/")) { if (m_query.query.endsWith("/")) {
qDebug() << "UrlIngester::UrlIngester: query Ends with /"; qDebug() << "UrlIngester::UrlIngester: query Ends with /";
m_slashend = true; m_slashend = true;
@ -212,7 +210,7 @@ UrlIngester::UrlIngester(RecollProtocol *p, const QUrl& url)
return; return;
} }
bool RecollProtocol::syncSearch(const QueryDesc &qd) bool RecollProtocol::syncSearch(const QueryDesc& qd)
{ {
qDebug() << "RecollProtocol::syncSearch"; qDebug() << "RecollProtocol::syncSearch";
if (!m_initok || !maybeOpenDb(m_reason)) { if (!m_initok || !maybeOpenDb(m_reason)) {
@ -245,9 +243,8 @@ void RecollProtocol::get(const QUrl& url)
QueryDesc qd; QueryDesc qd;
int resnum; int resnum;
if (ingest.isRootEntry(&rettp)) { if (ingest.isRootEntry(&rettp)) {
switch(rettp) { switch (rettp) {
case UrlIngester::UIRET_HELP: case UrlIngester::UIRET_HELP: {
{
QString location = QString location =
QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"kio_recoll/help.html"); "kio_recoll/help.html");
@ -275,7 +272,7 @@ void RecollProtocol::get(const QUrl& url)
Rcl::Doc doc; Rcl::Doc doc;
if (resnum >= 0 && m_source && m_source->getDoc(resnum, doc)) { if (resnum >= 0 && m_source && m_source->getDoc(resnum, doc)) {
mimeType(doc.mimetype.c_str()); mimeType(doc.mimetype.c_str());
redirection(QUrl::fromLocalFile((const char *)(doc.url.c_str()+7))); redirection(QUrl::fromLocalFile((const char *)(doc.url.c_str() + 7)));
goto out; goto out;
} }
} else if (ingest.isPreview(&qd, &resnum)) { } else if (ingest.isPreview(&qd, &resnum)) {
@ -291,7 +288,8 @@ void RecollProtocol::get(const QUrl& url)
#if 0 #if 0
// Do we need this ? // Do we need this ?
if (host.isEmpty()) { if (host.isEmpty()) {
char cpage[20];sprintf(cpage, "%d", page); char cpage[20];
sprintf(cpage, "%d", page);
QString nurl = QString::fromAscii("recoll://search/query?q=") + QString nurl = QString::fromAscii("recoll://search/query?q=") +
query + "&qtp=" + opt + "&p=" + cpage; query + "&qtp=" + opt + "&p=" + cpage;
redirection(QUrl(nurl)); redirection(QUrl(nurl));
@ -304,7 +302,7 @@ void RecollProtocol::get(const QUrl& url)
} }
error(KIO::ERR_SLAVE_DEFINED, u8s2qs("Unrecognized URL or internal error")); error(KIO::ERR_SLAVE_DEFINED, u8s2qs("Unrecognized URL or internal error"));
out: out:
finished(); finished();
} }
@ -326,8 +324,9 @@ bool RecollProtocol::doSearch(const QueryDesc& qd)
Rcl::SCLT_AND, qs); Rcl::SCLT_AND, qs);
} }
sd = new Rcl::SearchData(Rcl::SCLT_OR, m_stemlang); sd = new Rcl::SearchData(Rcl::SCLT_OR, m_stemlang);
if (sd && clp) if (sd && clp) {
sd->addClause(clp); sd->addClause(clp);
}
} else { } else {
sd = wasaStringToRcl(o_rclconfig, m_stemlang, qs, m_reason); sd = wasaStringToRcl(o_rclconfig, m_stemlang, qs, m_reason);
} }

View File

@ -36,13 +36,16 @@ class RecollProtocol;
class RecollKioPager : public ResListPager { class RecollKioPager : public ResListPager {
public: public:
RecollKioPager() : m_parent(0) {} RecollKioPager() : m_parent(0) {}
void setParent(RecollProtocol *proto) {m_parent = proto;} void setParent(RecollProtocol *proto) {
m_parent = proto;
}
virtual bool append(const std::string& data); virtual bool append(const std::string& data);
virtual bool append(const std::string& data, int, const Rcl::Doc&) virtual bool append(const std::string& data, int, const Rcl::Doc&) {
{return append(data);} return append(data);
}
virtual std::string detailsLink(); virtual std::string detailsLink();
virtual const std::string &parFormat(); virtual const std::string& parFormat();
virtual std::string nextUrl(); virtual std::string nextUrl();
virtual std::string prevUrl(); virtual std::string prevUrl();
virtual std::string pageTop(); virtual std::string pageTop();
@ -70,29 +73,41 @@ public:
UrlIngester(RecollProtocol *p, const QUrl& url); UrlIngester(RecollProtocol *p, const QUrl& url);
enum RootEntryType {UIRET_NONE, UIRET_ROOT, UIRET_HELP, UIRET_SEARCH}; enum RootEntryType {UIRET_NONE, UIRET_ROOT, UIRET_HELP, UIRET_SEARCH};
bool isRootEntry(RootEntryType *tp) { bool isRootEntry(RootEntryType *tp) {
if (m_type != UIMT_ROOTENTRY) return false; if (m_type != UIMT_ROOTENTRY) {
return false;
}
*tp = m_retType; *tp = m_retType;
return true; return true;
} }
bool isQuery(QueryDesc *q) { bool isQuery(QueryDesc *q) {
if (m_type != UIMT_QUERY) return false; if (m_type != UIMT_QUERY) {
return false;
}
*q = m_query; *q = m_query;
return true; return true;
} }
bool isResult(QueryDesc *q, int *num) { bool isResult(QueryDesc *q, int *num) {
if (m_type != UIMT_QUERYRESULT) return false; if (m_type != UIMT_QUERYRESULT) {
return false;
}
*q = m_query; *q = m_query;
*num = m_resnum; *num = m_resnum;
return true; return true;
} }
bool isPreview(QueryDesc *q, int *num) { bool isPreview(QueryDesc *q, int *num) {
if (m_type != UIMT_PREVIEW) return false; if (m_type != UIMT_PREVIEW) {
return false;
}
*q = m_query; *q = m_query;
*num = m_resnum; *num = m_resnum;
return true; return true;
} }
bool endSlashQuery() {return m_slashend;} bool endSlashQuery() {
bool alwaysDir() {return m_alwaysdir;} return m_slashend;
}
bool alwaysDir() {
return m_alwaysdir;
}
private: private:
RecollProtocol *m_parent; RecollProtocol *m_parent;
@ -102,7 +117,8 @@ private:
RootEntryType m_retType; RootEntryType m_retType;
int m_resnum; int m_resnum;
enum MyType {UIMT_NONE, UIMT_ROOTENTRY, UIMT_QUERY, UIMT_QUERYRESULT, enum MyType {UIMT_NONE, UIMT_ROOTENTRY, UIMT_QUERY, UIMT_QUERYRESULT,
UIMT_PREVIEW}; UIMT_PREVIEW
};
MyType m_type; MyType m_type;
}; };
@ -132,14 +148,14 @@ private:
* the form of the URL. * the form of the URL.
*/ */
class RecollProtocol : public KIO::SlaveBase { class RecollProtocol : public KIO::SlaveBase {
public: public:
RecollProtocol(const QByteArray &pool, const QByteArray &app ); RecollProtocol(const QByteArray& pool, const QByteArray& app);
virtual ~RecollProtocol(); virtual ~RecollProtocol();
virtual void mimetype(const QUrl& url); virtual void mimetype(const QUrl& url);
virtual void get(const QUrl& url); virtual void get(const QUrl& url);
// The directory mode is not available with KDE 4.0, I could find // The directory mode is not available with KDE 4.0, I could find
// no way to avoid crashing kdirmodel // no way to avoid crashing kdirmodel
virtual void stat(const QUrl & url); virtual void stat(const QUrl& url);
virtual void listDir(const QUrl& url); virtual void listDir(const QUrl& url);
static RclConfig *o_rclconfig; static RclConfig *o_rclconfig;
@ -147,9 +163,9 @@ class RecollProtocol : public KIO::SlaveBase {
friend class RecollKioPager; friend class RecollKioPager;
friend class UrlIngester; friend class UrlIngester;
private: private:
bool maybeOpenDb(std::string& reason); bool maybeOpenDb(std::string& reason);
bool URLToQuery(const QUrl &url, QString& q, QString& opt, int *page=0); bool URLToQuery(const QUrl& url, QString& q, QString& opt, int *page = 0);
bool doSearch(const QueryDesc& qd); bool doSearch(const QueryDesc& qd);
void searchPage(); void searchPage();
@ -158,7 +174,7 @@ class RecollProtocol : public KIO::SlaveBase {
bool syncSearch(const QueryDesc& qd); bool syncSearch(const QueryDesc& qd);
void htmlDoSearch(const QueryDesc& qd); void htmlDoSearch(const QueryDesc& qd);
void showPreview(const Rcl::Doc& doc); void showPreview(const Rcl::Doc& doc);
bool isRecollResult(const QUrl &url, int *num, QString* q); bool isRecollResult(const QUrl& url, int *num, QString* q);
bool m_initok; bool m_initok;
Rcl::Db *m_rcldb; Rcl::Db *m_rcldb;
@ -180,8 +196,10 @@ class RecollProtocol : public KIO::SlaveBase {
QueryDesc m_query; QueryDesc m_query;
}; };
extern "C" { __attribute__ ((visibility("default"))) int extern "C" {
kdemain(int argc, char **argv);} __attribute__((visibility("default"))) int
kdemain(int argc, char **argv);
}
inline QString u8s2qs(const string& s) inline QString u8s2qs(const string& s)
{ {