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,9 +45,9 @@ 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
// 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;
@ -63,26 +63,29 @@ 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;
@ -100,10 +103,37 @@ static const UDSEntry resultToUDSEntry(const Rcl::Doc& doc, int num)
QUrl url(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");
@ -112,7 +142,7 @@ static const UDSEntry resultToUDSEntry(const Rcl::Doc& doc, int num)
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().toUtf8(), &info) >= 0) {
@ -122,7 +152,6 @@ static const UDSEntry resultToUDSEntry(const Rcl::Doc& doc, int num)
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;
}
@ -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,8 +205,8 @@ 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;
@ -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 ??";
@ -256,8 +281,7 @@ void RecollProtocol::listDir(const QUrl& url)
if (ingest.isRootEntry(&rettp)) {
switch (rettp) {
case UrlIngester::UIRET_ROOT:
{
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();
}
@ -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);
}
@ -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,13 +222,11 @@ 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>");
}
@ -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

@ -52,9 +52,6 @@ RecollProtocol::RecollProtocol(const QByteArray &pool, const QByteArray &app)
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()) {
@ -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);
}
if (m_query.query.endsWith("/")) {
qDebug() << "UrlIngester::UrlIngester: query Ends with /";
m_slashend = true;
@ -246,8 +244,7 @@ void RecollProtocol::get(const QUrl& url)
int resnum;
if (ingest.isRootEntry(&rettp)) {
switch (rettp) {
case UrlIngester::UIRET_HELP:
{
case UrlIngester::UIRET_HELP: {
QString location =
QStandardPaths::locate(QStandardPaths::GenericDataLocation,
"kio_recoll/help.html");
@ -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));
@ -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,11 +36,14 @@ 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 std::string nextUrl();
@ -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;
};
@ -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)
{