bits of dual mode working

This commit is contained in:
dockes 2008-11-27 17:48:43 +00:00
parent 36ba132a1e
commit a494eddb92
7 changed files with 125 additions and 35 deletions

View File

@ -105,6 +105,10 @@ CHECK_LIBRARY_EXISTS(dl dlopen "" DLOPEN_IN_LIBDL)
IF(DLOPEN_IN_LIBDL) IF(DLOPEN_IN_LIBDL)
LIST(APPEND EXTRA_LIBS dl) LIST(APPEND EXTRA_LIBS dl)
ENDIF(DLOPEN_IN_LIBDL) ENDIF(DLOPEN_IN_LIBDL)
CHECK_LIBRARY_EXISTS(pthread pthread_sigmask "" PTHREAD_IN_LIBPTHREAD)
IF(PTHREAD_IN_LIBPTHREAD)
LIST(APPEND EXTRA_LIBS pthread)
ENDIF(PTHREAD_IN_LIBPTHREAD)
kde4_add_plugin(kio_recoll ${kio_recoll_SRCS}) kde4_add_plugin(kio_recoll ${kio_recoll_SRCS})

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: dirif.cpp,v 1.1 2008-11-26 15:03:41 dockes Exp $ (C) 2008 J.F.Dockes"; static char rcsid[] = "@(#$Id: dirif.cpp,v 1.2 2008-11-27 17:48:43 dockes Exp $ (C) 2008 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -66,33 +66,88 @@ const UDSEntry resultToUDSEntry(Rcl::Doc doc)
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_URL, doc.url.c_str()); entry.insert(KIO::UDSEntry::UDS_TARGET_URL, doc.url.c_str());
// entry.insert(KIO::UDSEntry::UDS_URL, "recoll://search/query/1"); // entry.insert(KIO::UDSEntry::UDS_URL, "recoll://search/query/1");
return entry; 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) void RecollProtocol::stat(const KUrl & url)
{ {
kDebug() << url << endl ; kDebug() << url << endl ;
QString path = url.path(); QString path = url.path();
KIO::UDSEntry entry; KIO::UDSEntry entry;
entry.insert(KIO::UDSEntry::UDS_NAME, url.path()); if (!path.compare("/"))
entry.insert(KIO::UDSEntry::UDS_URL, url.url()); entry.insert(KIO::UDSEntry::UDS_NAME, "/welcome");
else
entry.insert(KIO::UDSEntry::UDS_NAME, url.path());
entry.insert(KIO::UDSEntry::UDS_TARGET_URL, url.url());
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
statEntry(entry); statEntry(entry);
finished(); finished();
} }
// From kio_beagle
void RecollProtocol::createRootEntry(KIO::UDSEntry& entry)
{
// home directory
entry.clear();
entry.insert( KIO::UDSEntry::UDS_NAME, ".");
entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
entry.insert( KIO::UDSEntry::UDS_ACCESS, 0700);
entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, "inode/directory");
}
void RecollProtocol::createGoHomeEntry(KIO::UDSEntry& entry)
{
// status file
entry.clear();
entry.insert(KIO::UDSEntry::UDS_NAME, "Recoll home (click me)");
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
entry.insert(KIO::UDSEntry::UDS_TARGET_URL, "recoll:///welcome");
entry.insert(KIO::UDSEntry::UDS_ACCESS, 0500);
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "text/html");
entry.insert(KIO::UDSEntry::UDS_ICON_NAME, "recoll");
}
void RecollProtocol::listDir(const KUrl& url) void RecollProtocol::listDir(const KUrl& url)
{ {
kDebug() << url << endl; kDebug() << url << endl;
// It seems that when the request is from konqueror
// autocompletion it comes with a / at the end, which offers
// an opportunity to not perform it.
if (url.path() != "/" && url.path().endsWith("/")) {
kDebug() << "Endswith/" << endl;
error(-1, "");
return;
}
if (!m_initok || !maybeOpenDb(m_reason)) { if (!m_initok || !maybeOpenDb(m_reason)) {
error(KIO::ERR_SLAVE_DEFINED, "Init error"); string reason = "RecollProtocol::listDir: Init error:" + m_reason;
error(KIO::ERR_SLAVE_DEFINED, reason.c_str());
return;
}
if (url.path().isEmpty() || url.path() == "/") {
kDebug() << "list /" << endl;
UDSEntryList entries;
KIO::UDSEntry entry;
// entry for '/'
createRootEntry(entry);
// listEntry(entry, false);
entries.append(entry);
// entry for 'Information'
createGoHomeEntry(entry);
// listEntry(entry, false);
entries.append(entry);
listEntries(entries);
finished();
return; return;
} }
@ -100,19 +155,20 @@ void RecollProtocol::listDir(const KUrl& url)
URLToQuery(url, query, opt); URLToQuery(url, query, opt);
kDebug() << "Query: " << query; kDebug() << "Query: " << query;
if (!query.isEmpty()) { if (!query.isEmpty()) {
doSearch(query, opt.toUtf8().at(0)); if (!doSearch(query, opt.toUtf8().at(0)))
return;
} else { } else {
finished(); finished();
return; return;
} }
vector<ResListEntry> page; vector<ResListEntry> page;
int pagelen = m_source->getSeqSlice(0, 20, page); int pagelen = m_source->getSeqSlice(0, 100, page);
kDebug() << "Got " << pagelen << " results."; kDebug() << "Got " << pagelen << " results.";
UDSEntryList entries; UDSEntryList entries;
for (int i = 0; i < pagelen; i++) { for (int i = 0; i < pagelen; i++) {
entries.append(resultToUDSEntry(page[i].doc)); entries.append(resultToUDSEntry(page[i].doc));
} }
listEntries(entries); listEntries(entries);
// finished(); finished();
} }

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: htmlif.cpp,v 1.1 2008-11-26 15:03:41 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: htmlif.cpp,v 1.2 2008-11-27 17:48:43 dockes Exp $ (C) 2005 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -72,7 +72,7 @@ const string &RecollKioPager::parFormat()
string RecollKioPager::pageTop() string RecollKioPager::pageTop()
{ {
return "<p align=\"center\"><a href=\"recoll:///\">New Search</a></p>"; return "<p align=\"center\"><a href=\"recoll:///welcome\">New Search</a></p>";
} }
string RecollKioPager::nextUrl() string RecollKioPager::nextUrl()
@ -148,9 +148,10 @@ void RecollProtocol::queryDetails()
void RecollProtocol::htmlDoSearch(const QString& q, char opt) void RecollProtocol::htmlDoSearch(const QString& q, char opt)
{ {
kDebug() << endl; kDebug() << "htmlDoSearch" << endl;
if (!doSearch(q, opt))
return;
mimeType("text/html"); mimeType("text/html");
doSearch(q, opt);
m_pager.setDocSource(m_source); m_pager.setDocSource(m_source);
m_pager.resultPageNext(); m_pager.resultPageNext();
m_pager.displayPage(); m_pager.displayPage();

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.16 2008-11-26 15:03:41 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.17 2008-11-27 17:48:43 dockes Exp $ (C) 2005 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -119,10 +119,11 @@ bool RecollProtocol::maybeOpenDb(string &reason)
void RecollProtocol::mimetype(const KUrl &url) void RecollProtocol::mimetype(const KUrl &url)
{ {
kDebug() << url << endl; kDebug() << url << endl;
if (0) #ifdef USEDIRMODEL
mimeType("text/html");
else
mimeType("inode/directory"); mimeType("inode/directory");
#else
mimeType("text/html");
#endif
finished(); finished();
} }
@ -139,6 +140,8 @@ bool RecollProtocol::URLToQuery(const KUrl &url, QString& q, QString& opt)
opt = "l"; opt = "l";
} }
} }
if (q.startsWith("/"))
q.remove(0,1);
return true; return true;
} }
@ -147,18 +150,21 @@ void RecollProtocol::get(const KUrl & url)
kDebug() << url << endl; kDebug() << url << endl;
if (!m_initok || !maybeOpenDb(m_reason)) { if (!m_initok || !maybeOpenDb(m_reason)) {
error(KIO::ERR_SLAVE_DEFINED, "Init error"); string reason = "RecollProtocol::get:Init error: " + m_reason;
error(KIO::ERR_SLAVE_DEFINED, reason.c_str());
return; return;
} }
#ifdef USEDIRMODEL
error(KIO::ERR_IS_DIRECTORY, QString::null); error(KIO::ERR_IS_DIRECTORY, QString::null);
return; return;
#endif
QString host = url.host(); QString host = url.host();
QString path = url.path(); QString path = url.path();
kDebug() << "host:" << host << " path:" << path; kDebug() << "host:" << host << " path:" << path;
if (host.isEmpty() && !path.compare("/")) { if (host.isEmpty() && (!path.compare("/")||!path.compare("/welcome"))) {
// recoll:/ // recoll:/
welcomePage(); welcomePage();
goto out; goto out;
@ -202,7 +208,7 @@ void RecollProtocol::get(const KUrl & url)
kDebug() << "done" << endl; kDebug() << "done" << endl;
} }
void RecollProtocol::doSearch(const QString& q, char opt) bool RecollProtocol::doSearch(const QString& q, char opt)
{ {
kDebug() << q << endl; kDebug() << q << endl;
string qs = (const char *)q.toUtf8(); string qs = (const char *)q.toUtf8();
@ -231,33 +237,37 @@ void RecollProtocol::doSearch(const QString& q, char opt)
sd = wasaStringToRcl(qs, m_reason); sd = wasaStringToRcl(qs, m_reason);
} }
if (!sd) { if (!sd) {
m_reason = "Internal Error: cant allocate new query"; kDebug() << "Could not build search data from user string";
outputError(m_reason.c_str()); m_reason = "Internal Error: cant build search";
error(-1, m_reason.c_str());
finished(); finished();
return; return false;
} }
RefCntr<Rcl::SearchData> sdata(sd); RefCntr<Rcl::SearchData> sdata(sd);
sdata->setStemlang("english"); sdata->setStemlang("english");
kDebug() << "Building query"; kDebug() << "Executing 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: query execute failed";
outputError(m_reason.c_str()); error(-1, m_reason.c_str());
finished(); finished();
return; kDebug() << "setQuery failed, returning";
return false;
} }
kDebug() << "Building docsequence"; kDebug() << "Building docsequence";
DocSequenceDb *src = DocSequenceDb *src =
new DocSequenceDb(RefCntr<Rcl::Query>(query), "Query results", sdata); new DocSequenceDb(RefCntr<Rcl::Query>(query), "Query results", sdata);
if (src == 0) { if (src == 0) {
kDebug() << "Cant' build result sequence"; kDebug() << "Cant' build result sequence";
error(-1, QString::null); error(-1, "Can't build result sequence");
finished(); finished();
return; return false;
} }
kDebug() << "Setting source"; kDebug() << "Setting source";
m_source = RefCntr<DocSequence>(src); m_source = RefCntr<DocSequence>(src);
return true;
} }
// Note: KDE_EXPORT is actually needed on Unix when building with // Note: KDE_EXPORT is actually needed on Unix when building with

View File

@ -1,5 +1,5 @@
#ifndef _RECOLL_H #ifndef _RECOLL_H
/* @(#$Id: kio_recoll.h,v 1.7 2008-11-26 15:03:41 dockes Exp $ (C) 2005 J.F.Dockes */ /* @(#$Id: kio_recoll.h,v 1.8 2008-11-27 17:48:43 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 * This program is free software; you can redistribute it and/or modify
@ -70,11 +70,13 @@ class RecollProtocol : public KIO::SlaveBase {
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'); bool doSearch(const QString& q, char opt = 'l');
void welcomePage(); void welcomePage();
void queryDetails(); void queryDetails();
void htmlDoSearch(const QString& q, char opt); void htmlDoSearch(const QString& q, char opt);
bool URLToQuery(const KUrl &url, QString& q, QString& opt); bool URLToQuery(const KUrl &url, QString& q, QString& opt);
void createRootEntry(KIO::UDSEntry& entry);
void createGoHomeEntry(KIO::UDSEntry& entry);
bool m_initok; bool m_initok;
Rcl::Db *m_rcldb; Rcl::Db *m_rcldb;

View File

@ -10,3 +10,19 @@ Au lieu de /usr/lib/kde4/share/kde4/apps/
recoll avec --target=/usr pour que les fichiers de config soient au bon recoll avec --target=/usr pour que les fichiers de config soient au bon
endroit endroit
Sur kubuntu 8.10 (a jour au 2008-27-11), cmake genere une dependance sur
/build/buildd/kde4libs-4.1.2/obj-i486-linux-gnu/lib/libkdecore.so dans
CMakeFiles/kio_recoll.dir/build.make
Pas trouve le moyen de corriger, il faut editer la ligne et remplacer
par /usr/lib/..
Debug areas: /usr/share/kde4/config/kdebug.areas
kdebugdialog [--fullmode] pour configurer
./.kde/share/config/kdebugrc
Output to ~/.xession-errors par defaut controle ?
Probleme quand l'url se termine par un / et qu'on edite le mot,
konqueror lance une recherche a chaque lettre.

View File

@ -5,7 +5,8 @@ input=none
output=filesystem output=filesystem
listing=Name,Type, URL listing=Name,Type, URL
reading=true reading=true
defaultMimeType=inode/directory #defaultMimeType=inode/directory
defaultMimeType=text/html
Icon=help_index Icon=help_index
Class=:local Class=:local
URIMode=rawuri URIMode=rawuri