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
)
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
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
// appending one of our result file names to the directory name (which
// is the search string). If it is, extract return the result document
// number. Possibly restart the search if the search string does not
// match the current one
bool RecollProtocol::isRecollResult(const QUrl &url, int *num, QString *q)
// is the search string). If it is, extract and return the result
// document number. Possibly restart the search if the search string
// does not match the current one
bool RecollProtocol::isRecollResult(const QUrl& url, int *num, QString *q)
{
*num = -1;
qDebug() << "RecollProtocol::isRecollResult: url: " << url;
@ -63,32 +63,35 @@ bool RecollProtocol::isRecollResult(const QUrl &url, int *num, QString *q)
QString path = url.path();
qDebug() << "RecollProtocol::isRecollResult: path: " << path;
// if (!path.startsWith("/")) {
// return false;
// }
if (!path.startsWith("/")) {
return false;
}
// Look for the last '/' and check if it is followed by
// resultBaseName (riiiight...)
int slashpos = path.lastIndexOf("/");
if (slashpos == -1 || slashpos == 0 || slashpos == path.length() -1)
if (slashpos == -1 || slashpos == 0 || slashpos == path.length() - 1) {
return false;
}
slashpos++;
//qDebug() << "Comparing " << path.mid(slashpos, resultBaseName.length()) <<
// "and " << resultBaseName;
if (path.mid(slashpos, resultBaseName.length()).compare(resultBaseName))
if (path.mid(slashpos, resultBaseName.length()).compare(resultBaseName)) {
return false;
}
// Extract the result number
QString snum = path.mid(slashpos + resultBaseName.length());
sscanf(snum.toUtf8(), "%d", num);
if (*num == -1)
if (*num == -1) {
return false;
}
//qDebug() << "URL analysis ok, num:" << *num;
// We do have something that ressembles a recoll result locator. Check if
// 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;
}
@ -98,31 +101,57 @@ static const UDSEntry resultToUDSEntry(const Rcl::Doc& doc, int num)
UDSEntry entry;
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());
char cnum[30];sprintf(cnum, "%04d", num);
/// Filename - as displayed in directory listings etc.
/// "." 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);
// 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") ||
!doc.mimetype.compare("inode/directory")) {
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_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().toUtf8(), &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_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_TARGET_URL, doc.url.c_str());
return entry;
}
@ -132,10 +161,10 @@ static const UDSEntry resultToUDSEntry(const Rcl::Doc& doc, int num)
static void createRootEntry(KIO::UDSEntry& entry)
{
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");
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");
}
// Points to html query screen
@ -168,6 +197,7 @@ static void createGoHelpEntry(KIO::UDSEntry& entry)
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)
{
qDebug() << "RecollProtocol::stat:" << url;
@ -175,14 +205,14 @@ void RecollProtocol::stat(const QUrl& url)
UrlIngester ingest(this, url);
KIO::UDSEntry entry;
entry.insert(KIO::UDSEntry::UDS_TARGET_URL, url.url());
entry.insert(KIO::UDSEntry::UDS_URL, url.url());
// entry.insert(KIO::UDSEntry::UDS_TARGET_URL, url.url());
// entry.insert(KIO::UDSEntry::UDS_URL, url.url());
UrlIngester::RootEntryType rettp;
QueryDesc qd;
int num;
if (ingest.isRootEntry(&rettp)) {
qDebug() << "RecollProtocol::stat: root entry";
switch(rettp) {
switch (rettp) {
case UrlIngester::UIRET_ROOT:
qDebug() << "RecollProtocol::stat: root";
createRootEntry(entry);
@ -224,20 +254,15 @@ void RecollProtocol::stat(const QUrl& url)
//
// Another approach would be to use different protocol names
// 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:";
// Need to check no / in there
#if 0
entry.insert(KIO::UDSEntry::UDS_NAME, "dockes bla"/*qd.query*/);
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_NAME, qd.query);
entry.insert(KIO::UDSEntry::UDS_ACCESS, 0700);
entry.insert(KIO::UDSEntry::UDS_MODIFICATION_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_MIME_TYPE, "inode/directory");
#endif
}
} else {
qDebug() << "RecollProtocol::stat: none of the above ??";
@ -255,9 +280,8 @@ void RecollProtocol::listDir(const QUrl& url)
QueryDesc qd;
if (ingest.isRootEntry(&rettp)) {
switch(rettp) {
case UrlIngester::UIRET_ROOT:
{
switch (rettp) {
case UrlIngester::UIRET_ROOT: {
qDebug() << "RecollProtocol::listDir:list /";
UDSEntryList entries;
KIO::UDSEntry entry;
@ -297,11 +321,13 @@ void RecollProtocol::listDir(const QUrl& url)
static int maxentries = -1;
if (maxentries == -1) {
if (o_rclconfig)
if (o_rclconfig) {
o_rclconfig->getConfParam("kio_max_direntries", &maxentries);
if (maxentries == -1)
}
if (maxentries == -1) {
maxentries = 10000;
}
}
static const int pagesize = 200;
int pagebase = 0;
while (pagebase < maxentries) {

View File

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

View File

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

View File

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