converted qt reslist to reslistpager

This commit is contained in:
dockes 2008-12-16 14:20:10 +00:00
parent 34c8fed8e5
commit 42a745f384
8 changed files with 265 additions and 358 deletions

View File

@ -1,6 +1,6 @@
#ifndef _PREVIEW_W_H_INCLUDED_ #ifndef _PREVIEW_W_H_INCLUDED_
#define _PREVIEW_W_H_INCLUDED_ #define _PREVIEW_W_H_INCLUDED_
/* @(#$Id: preview_w.h,v 1.19 2008-10-03 08:09:35 dockes Exp $ (C) 2006 J.F.Dockes */ /* @(#$Id: preview_w.h,v 1.20 2008-12-16 14:20:10 dockes Exp $ (C) 2006 J.F.Dockes */
/* /*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -69,7 +69,8 @@ class TabData {
class PlainToRichQtPreview : public PlainToRich { class PlainToRichQtPreview : public PlainToRich {
public: public:
int lastanchor; int lastanchor;
PlainToRichQtPreview(bool inputhtml = false) : PlainToRich(inputhtml) { PlainToRichQtPreview()
{
lastanchor = 0; lastanchor = 0;
} }
virtual ~PlainToRichQtPreview() {} virtual ~PlainToRichQtPreview() {}

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: reslist.cpp,v 1.50 2008-12-12 11:01:01 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: reslist.cpp,v 1.51 2008-12-16 14:20:10 dockes Exp $ (C) 2005 J.F.Dockes";
#endif #endif
#include <time.h> #include <time.h>
@ -50,7 +50,6 @@ static char rcsid[] = "@(#$Id: reslist.cpp,v 1.50 2008-12-12 11:01:01 dockes Exp
#define MIN(A,B) ((A) < (B) ? (A) : (B)) #define MIN(A,B) ((A) < (B) ? (A) : (B))
#endif #endif
class PlainToRichQtReslist : public PlainToRich { class PlainToRichQtReslist : public PlainToRich {
public: public:
virtual ~PlainToRichQtReslist() {} virtual ~PlainToRichQtReslist() {}
@ -78,10 +77,10 @@ ResList::ResList(QWidget* parent, const char* name)
#if (QT_VERSION >= 0x040000) #if (QT_VERSION >= 0x040000)
connect(this, SIGNAL(selectionChanged()), this, SLOT(selecChanged())); connect(this, SIGNAL(selectionChanged()), this, SLOT(selecChanged()));
#endif #endif
m_winfirst = -1;
m_curPvDoc = -1; m_curPvDoc = -1;
m_lstClckMod = 0; m_lstClckMod = 0;
m_listId = 0; m_listId = 0;
m_pager = new QtGuiResListPager(this, prefs.respagesize);
} }
ResList::~ResList() ResList::~ResList()
@ -132,6 +131,7 @@ void ResList::setDocSource()
m_sortspecs, m_sortspecs,
title)); title));
} }
m_pager->setDocSource(m_docSource);
resultPageNext(); resultPageNext();
} }
@ -149,7 +149,6 @@ void ResList::setFilterParams(const DocSeqFiltSpec& spec)
void ResList::resetList() void ResList::resetList()
{ {
m_winfirst = -1;
m_curPvDoc = -1; m_curPvDoc = -1;
// There should be a progress bar for long searches but there isn't // There should be a progress bar for long searches but there isn't
// We really want the old result list to go away, otherwise, for a // We really want the old result list to go away, otherwise, for a
@ -184,7 +183,6 @@ void ResList::languageChange()
bool ResList::getTerms(vector<string>& terms, bool ResList::getTerms(vector<string>& terms,
vector<vector<string> >& groups, vector<int>& gslks) vector<vector<string> >& groups, vector<int>& gslks)
{ {
// We could just
return m_baseDocSource->getTerms(terms, groups, gslks); return m_baseDocSource->getTerms(terms, groups, gslks);
} }
@ -198,12 +196,12 @@ list<string> ResList::expand(Rcl::Doc& doc)
// Get document number from paragraph number // Get document number from paragraph number
int ResList::docnumfromparnum(int par) int ResList::docnumfromparnum(int par)
{ {
if (m_winfirst == -1) if (m_pager->pageNumber() < 0)
return -1; return -1;
std::map<int,int>::iterator it = m_pageParaToReldocnums.find(par); std::map<int,int>::iterator it = m_pageParaToReldocnums.find(par);
int dn; int dn;
if (it != m_pageParaToReldocnums.end()) { if (it != m_pageParaToReldocnums.end()) {
dn = m_winfirst + it->second; dn = m_pager->pageNumber() * prefs.respagesize + it->second;
} else { } else {
dn = -1; dn = -1;
} }
@ -213,9 +211,12 @@ int ResList::docnumfromparnum(int par)
// Get paragraph number from document number // Get paragraph number from document number
int ResList::parnumfromdocnum(int docnum) int ResList::parnumfromdocnum(int docnum)
{ {
if (m_winfirst == -1 || docnum - m_winfirst < 0) if (m_pager->pageNumber() < 0)
return -1; return -1;
docnum -= m_winfirst; int winfirst = m_pager->pageNumber() * prefs.respagesize;
if (docnum - winfirst < 0)
return -1;
docnum -= winfirst;
for (std::map<int,int>::iterator it = m_pageParaToReldocnums.begin(); for (std::map<int,int>::iterator it = m_pageParaToReldocnums.begin();
it != m_pageParaToReldocnums.end(); it++) { it != m_pageParaToReldocnums.end(); it++) {
if (docnum == it->second) if (docnum == it->second)
@ -230,27 +231,28 @@ int ResList::parnumfromdocnum(int docnum)
// result in a one-page change. // result in a one-page change.
bool ResList::getDoc(int docnum, Rcl::Doc &doc) bool ResList::getDoc(int docnum, Rcl::Doc &doc)
{ {
LOGDEB(("ResList::getDoc: docnum %d m_winfirst %d\n", docnum, m_winfirst)); LOGDEB(("ResList::getDoc: docnum %d winfirst %d\n", docnum,
m_pager->pageNumber() * prefs.respagesize));
if (docnum < 0) if (docnum < 0)
return false; return false;
if (m_pager->pageNumber() < 0)
return false;
int winfirst = m_pager->pageNumber() * prefs.respagesize;
// Is docnum in current page ? Then all Ok // Is docnum in current page ? Then all Ok
if (docnum >= int(m_winfirst) && if (docnum >= winfirst && docnum < winfirst + int(m_curDocs.size())) {
docnum < int(m_winfirst + m_curDocs.size())) { doc = m_curDocs[docnum - winfirst];
doc = m_curDocs[docnum - m_winfirst];
return true; return true;
} }
// Else we accept to page down or up but not further // Else we accept to page down or up but not further
if (docnum < int(m_winfirst) && if (docnum < winfirst && docnum >= winfirst - prefs.respagesize) {
docnum >= int(m_winfirst) - prefs.respagesize) {
resultPageBack(); resultPageBack();
} else if (docnum < } else if (docnum < winfirst + int(m_curDocs.size()) + prefs.respagesize) {
int(m_winfirst + m_curDocs.size()) + prefs.respagesize) {
resultPageNext(); resultPageNext();
} }
if (docnum >= int(m_winfirst) && winfirst = m_pager->pageNumber() * prefs.respagesize;
docnum < int(m_winfirst + m_curDocs.size())) { if (docnum >= winfirst && docnum < winfirst + int(m_curDocs.size())) {
doc = m_curDocs[docnum - m_winfirst]; doc = m_curDocs[docnum - winfirst];
return true; return true;
} }
return false; return false;
@ -323,23 +325,21 @@ void ResList::resPageDownOrNext()
// 2 pages and show next page. // 2 pages and show next page.
void ResList::resultPageBack() void ResList::resultPageBack()
{ {
if (m_winfirst <= 0) m_pager->resultPageBack();
return; displayPage();
m_winfirst -= 2 * prefs.respagesize;
resultPageNext();
} }
// Go to the first page // Go to the first page
void ResList::resultPageFirst() void ResList::resultPageFirst()
{ {
m_winfirst = -1; m_pager->resultPageFirst();
resultPageNext(); displayPage();
} }
void ResList::append(const QString &text) void ResList::append(const QString &text)
{ {
QTEXTBROWSER::append(text); QTEXTBROWSER::append(text);
#if 0 #if 1
{ {
FILE *fp = fopen("/tmp/debugreslist", "a"); FILE *fp = fopen("/tmp/debugreslist", "a");
fprintf(fp, "%s\n", (const char *)text.utf8()); fprintf(fp, "%s\n", (const char *)text.utf8());
@ -348,268 +348,88 @@ void ResList::append(const QString &text)
#endif #endif
} }
bool QtGuiResListPager::append(const string& data)
{
LOGDEB1(("QtGuiReslistPager::append: %s\n", data.c_str()));
m_parent->append(QString::fromUtf8(data.c_str()));
return true;
}
bool QtGuiResListPager::append(const string& data, int i, const Rcl::Doc& doc)
{
LOGDEB1(("QtGuiReslistPager::append: %d %s %s\n",
i, doc.url.c_str(), doc.ipath.c_str()));
m_parent->setCursorPosition(0,0);
m_parent->ensureCursorVisible();
m_parent->m_pageParaToReldocnums[m_parent->paragraphs()] = i;
m_parent->m_curDocs.push_back(doc);
return append(data);
}
string QtGuiResListPager::trans(const string& in)
{
return string((const char*)ResList::tr(in.c_str()).utf8());
}
string QtGuiResListPager::detailsLink()
{
string chunk = "<a href=\"H-1\">";
chunk += (const char*)ResList::tr("(show query)");
chunk += "</a>";
return chunk;
}
const string& QtGuiResListPager::parFormat()
{
static string parformat;
if (parformat.empty())
parformat = (const char*)prefs.reslistformat.utf8();
return parformat;
}
string QtGuiResListPager::nextUrl()
{
return "n-1";
}
string QtGuiResListPager::prevUrl()
{
return "p-1";
}
string QtGuiResListPager::pageTop()
{
m_parent->clear();
return string();
}
string QtGuiResListPager::iconPath(const string& mtype)
{
string iconpath;
RclConfig::getMainConfig()->getMimeIconName(mtype, &iconpath);
return iconpath;
}
// Fill up result list window with next screen of hits // Fill up result list window with next screen of hits
void ResList::resultPageNext() void ResList::resultPageNext()
{ {
if (m_docSource.isNull()) m_pager->resultPageNext();
return; displayPage();
}
int resCnt = m_docSource->getResCnt(); void ResList::displayPage()
{
// Query term colorization
static QStyleSheetItem *item;
if (!item) {
item = new QStyleSheetItem(styleSheet(), "termtag" );
if (item)
item->setColor(prefs.qtermcolor);
}
m_curDocs.clear();
m_pageParaToReldocnums.clear(); m_pageParaToReldocnums.clear();
LOGDEB(("resultPageNext: rescnt %d, winfirst %d\n", resCnt, m_pager->displayPage();
m_winfirst));
bool hasPrev = false;
if (m_winfirst < 0) {
m_winfirst = 0;
} else {
m_winfirst += prefs.respagesize;
}
if (m_winfirst)
hasPrev = true;
emit prevPageAvailable(hasPrev);
// Get the next page of results.
vector<ResListEntry> respage;
int pagelen = m_docSource->getSeqSlice(m_winfirst,
prefs.respagesize, respage);
// If page was truncated, there is no next
bool hasNext = pagelen == prefs.respagesize;
emit nextPageAvailable(hasNext);
if (pagelen <= 0) {
// No results ? This can only happen on the first page or if the
// actual result list size is a multiple of the page pref (else
// there would have been no Next on the last page)
if (m_winfirst) {
// Have already results. Let them show, just disable the
// Next button. We'd need to remove the Next link from the page
// too.
// Restore the m_winfirst value
m_winfirst -= prefs.respagesize;
return;
}
clear();
QString chunk = "<qt><head></head><body><p>";
chunk += "<p><font size=+1><b>";
chunk += QString::fromUtf8(m_docSource->title().c_str());
chunk += "</b></font><br>";
chunk += "<a href=\"H-1\">";
chunk += tr("Show query details");
chunk += "</a><br>";
append(chunk);
append(tr("<p><b>No results found</b><br>"));
if (m_winfirst < 0)
m_winfirst = -1;
return;
}
clear();
m_curDocs.clear();
// Query term colorization
QStyleSheetItem *item = new QStyleSheetItem(styleSheet(), "termtag" );
item->setColor(prefs.qtermcolor);
// Result paragraph format
string sformat = string(prefs.reslistformat.utf8());
LOGDEB(("resultPageNext: format: [%s]\n", sformat.c_str()));
// Display list header
// We could use a <title> but the textedit doesnt display
// it prominently
// Note: have to append text in chunks that make sense
// html-wise. If we break things up too much, the editor
// gets confused. Hence the use of the 'chunk' text
// accumulator
// Also note that there can be results beyond the estimated resCnt.
QString chunk = "<qt><head></head><body><p>";
chunk += "<font size=+1><b>";
chunk += QString::fromUtf8(m_docSource->title().c_str());
chunk += ".</b></font>";
chunk += "&nbsp;&nbsp;&nbsp;";
if (m_winfirst + pagelen < resCnt) {
chunk +=
tr("Documents <b>%1-%2</b> out of at least <b>%3</b> for ")
.arg(m_winfirst+1)
.arg(m_winfirst+pagelen)
.arg(resCnt);
} else {
chunk += tr("Documents <b>%1-%2</b> for ")
.arg(m_winfirst+1)
.arg(m_winfirst+pagelen);
}
chunk += "<a href=\"H-1\">";
chunk += tr("(show query)");
chunk += "</a>";
append(chunk);
HiliteData hdata;
m_docSource->getTerms(hdata.terms, hdata.groups, hdata.gslks);
// Insert results in result list window. We have to actually send
// the text to the widget (instead of setting the whole at the
// end), because we need the paragraph number each time we add a
// result paragraph (its diffult and error-prone to compute the
// paragraph numbers in parallel). We would like to disable
// updates while we're doing this, but couldn't find a way to make
// it work, the widget seems to become confused if appended while
// updates are disabled
// setUpdatesEnabled(false);
for (int i = 0; i < pagelen; i++) {
Rcl::Doc &doc(respage[i].doc);
string& sh(respage[i].subHeader);
int percent;
if (doc.pc == -1) {
percent = 0;
// Document not available, maybe other further, will go on.
doc.meta[Rcl::Doc::keyabs] = string(tr("Unavailable document").utf8());
} else {
percent = doc.pc;
}
// Percentage of 'relevance'
char perbuf[10];
sprintf(perbuf, "%3d%% ", percent);
// Determine icon to display if any
string iconpath;
(void)rclconfig->getMimeIconName(doc.mimetype, &iconpath);
// Printable url: either utf-8 if transcoding succeeds, or url-encoded
string url;
printableUrl(rclconfig->getDefCharset(), doc.url, url);
// Make title out of file name if none yet
if (doc.meta[Rcl::Doc::keytt].empty()) {
doc.meta[Rcl::Doc::keytt] = path_getsimple(url);
}
// Result number
char numbuf[20];
int docnumforlinks = m_winfirst + 1 + i;
sprintf(numbuf, "%d", docnumforlinks);
// Document date: either doc or file modification time
char datebuf[100];
datebuf[0] = 0;
if (!doc.dmtime.empty() || !doc.fmtime.empty()) {
time_t mtime = doc.dmtime.empty() ?
atol(doc.fmtime.c_str()) : atol(doc.dmtime.c_str());
struct tm *tm = localtime(&mtime);
#ifndef sun
strftime(datebuf, 99, "&nbsp;%Y-%m-%d&nbsp;%H:%M:%S&nbsp;%z", tm);
#else
strftime(datebuf, 99, "&nbsp;%Y-%m-%d&nbsp;%H:%M:%S&nbsp;%Z", tm);
#endif
}
// Size information. We print both doc and file if they differ a lot
long fsize = -1, dsize = -1;
if (!doc.dbytes.empty())
dsize = atol(doc.dbytes.c_str());
if (!doc.fbytes.empty())
fsize = atol(doc.fbytes.c_str());
string sizebuf;
if (dsize > 0) {
sizebuf = displayableBytes(dsize);
if (fsize > 10 * dsize && fsize - dsize > 1000)
sizebuf += string(" / ") + displayableBytes(fsize);
} else if (fsize >= 0) {
sizebuf = displayableBytes(fsize);
}
string abstract;
if (prefs.queryBuildAbstract &&
(doc.syntabs || prefs.queryReplaceAbstract)) {
abstract = m_docSource->getAbstract(doc);
} else {
abstract = doc.meta[Rcl::Doc::keyabs];
}
// No need to call escapeHtml(), plaintorich handles it
list<string> lr;
PlainToRichQtReslist ptr;
ptr.plaintorich(abstract, lr, hdata);
string richabst = lr.front();
// Links;
string linksbuf;
char vlbuf[100];
if (canIntern(doc.mimetype, rclconfig)) {
sprintf(vlbuf, "\"P%d\"", docnumforlinks);
linksbuf += string("<a href=") + vlbuf + ">" + "Preview" + "</a>"
+ "&nbsp;&nbsp;";
}
if (!rclconfig->getMimeViewerDef(doc.mimetype).empty()) {
sprintf(vlbuf, "E%d", docnumforlinks);
linksbuf += string("<a href=") + vlbuf + ">" + "Open" + "</a>";
}
// Build the result list paragraph:
chunk = "";
// Subheader: this is used by history
if (!sh.empty())
chunk += "<p><b>" + QString::fromUtf8(sh.c_str()) + "</p>\n<p>";
else
chunk += "<p>";
// Configurable stuff
map<char,string> subs;
subs['A'] = !richabst.empty() ? richabst + "<br>" : "";
subs['D'] = datebuf;
subs['I'] = iconpath;
subs['i'] = doc.ipath;
subs['K'] = !doc.meta[Rcl::Doc::keykw].empty() ?
escapeHtml(doc.meta[Rcl::Doc::keykw]) + "<br>" : "";
subs['L'] = linksbuf;
subs['N'] = numbuf;
subs['M'] = doc.mimetype;
subs['R'] = perbuf;
subs['S'] = sizebuf;
subs['T'] = escapeHtml(doc.meta[Rcl::Doc::keytt]);
subs['U'] = url;
string formatted;
pcSubst(sformat, formatted, subs);
chunk += QString::fromUtf8(formatted.c_str());
chunk += "</p>\n";
LOGDEB2(("Chunk: [%s]\n", (const char *)chunk.utf8()));
append(chunk);
setCursorPosition(0,0);
ensureCursorVisible();
m_pageParaToReldocnums[paragraphs()-1] = i;
m_curDocs.push_back(doc);
}
// Footer
chunk = "<p align=\"center\">";
if (hasPrev || hasNext) {
if (hasPrev) {
chunk += "<a href=\"p-1\"><b>";
chunk += tr("Previous");
chunk += "</b></a>&nbsp;&nbsp;&nbsp;";
}
if (hasNext) {
chunk += "<a href=\"n-1\"><b>";
chunk += tr("Next");
chunk += "</b></a>";
}
}
chunk += "</p>\n";
chunk += "</body></qt>\n";
append(chunk);
LOGDEB0(("ResList::resultPageNext: hasNext %d hasPrev %d\n",
m_pager->hasPrev(), m_pager->hasNext()));
emit prevPageAvailable(m_pager->hasPrev());
emit nextPageAvailable(m_pager->hasNext());
// Possibly color paragraph of current preview if any // Possibly color paragraph of current preview if any
previewExposed(m_curPvDoc); previewExposed(m_curPvDoc);
ensureCursorVisible(); ensureCursorVisible();
@ -725,18 +545,17 @@ void ResList::menuPreview()
void ResList::menuSeeParent() void ResList::menuSeeParent()
{ {
Rcl::Doc doc; Rcl::Doc doc;
if (getDoc(m_popDoc, doc)) { if (!getDoc(m_popDoc, doc))
Rcl::Doc doc1; return;
if (FileInterner::getEnclosing(doc.url, doc.ipath, Rcl::Doc doc1;
doc1.url, doc1.ipath)) { if (FileInterner::getEnclosing(doc.url, doc.ipath, doc1.url, doc1.ipath)) {
emit previewRequested(doc1); emit previewRequested(doc1);
} else { } else {
// No parent doc: show enclosing folder with app configured for // No parent doc: show enclosing folder with app configured for
// directories // directories
doc1.url = path_getfather(doc.url); doc1.url = path_getfather(doc.url);
doc1.mimetype = "application/x-fsdirectory"; doc1.mimetype = "application/x-fsdirectory";
emit editRequested(doc1); emit editRequested(doc1);
}
} }
} }

View File

@ -1,6 +1,6 @@
#ifndef _RESLIST_H_INCLUDED_ #ifndef _RESLIST_H_INCLUDED_
#define _RESLIST_H_INCLUDED_ #define _RESLIST_H_INCLUDED_
/* @(#$Id: reslist.h,v 1.16 2008-09-29 07:13:47 dockes Exp $ (C) 2005 J.F.Dockes */ /* @(#$Id: reslist.h,v 1.17 2008-12-16 14:20:10 dockes Exp $ (C) 2005 J.F.Dockes */
#include <list> #include <list>
@ -25,6 +25,27 @@ class Q3PopupMenu;
#include "filtseq.h" #include "filtseq.h"
#include "refcntr.h" #include "refcntr.h"
#include "rcldoc.h" #include "rcldoc.h"
#include "reslistpager.h"
class ResList;
class QtGuiResListPager : public ResListPager {
public:
QtGuiResListPager(ResList *p, int ps)
: ResListPager(ps), m_parent(p)
{}
virtual bool append(const string& data);
virtual bool append(const string& data, int idx, const Rcl::Doc& doc);
virtual string trans(const string& in);
virtual string detailsLink();
virtual const string &parFormat();
virtual string nextUrl();
virtual string prevUrl();
virtual string pageTop();
virtual string iconPath(const string& mt);
private:
ResList *m_parent;
};
/** /**
* Display a list of document records. The data can be out of the history * Display a list of document records. The data can be out of the history
@ -39,6 +60,7 @@ class ResList : public QTEXTBROWSER
{ {
Q_OBJECT; Q_OBJECT;
friend class QtGuiResListPager;
public: public:
ResList(QWidget* parent = 0, const char* name = 0); ResList(QWidget* parent = 0, const char* name = 0);
virtual ~ResList(); virtual ~ResList();
@ -63,9 +85,10 @@ class ResList : public QTEXTBROWSER
virtual void doubleClicked(int, int); virtual void doubleClicked(int, int);
virtual void resPageUpOrBack(); // Page up pressed virtual void resPageUpOrBack(); // Page up pressed
virtual void resPageDownOrNext(); // Page down pressed virtual void resPageDownOrNext(); // Page down pressed
virtual void resultPageBack(); // Display previous page of results virtual void resultPageBack(); // Previous page of results
virtual void resultPageFirst(); // Display first page of results virtual void resultPageFirst(); // First page of results
virtual void resultPageNext(); // Display next (or first) page of results virtual void resultPageNext(); // Next (or first) page of results
virtual void displayPage(); // Display current page
virtual void menuPreview(); virtual void menuPreview();
virtual void menuEdit(); virtual void menuEdit();
virtual void menuCopyFN(); virtual void menuCopyFN();
@ -102,6 +125,7 @@ class ResList : public QTEXTBROWSER
virtual void showQueryDetails(); virtual void showQueryDetails();
private: private:
QtGuiResListPager *m_pager;
// Raw doc source // Raw doc source
RefCntr<DocSequence> m_baseDocSource; RefCntr<DocSequence> m_baseDocSource;
// Possibly filtered/sorted docsource (the one displayed) // Possibly filtered/sorted docsource (the one displayed)
@ -111,8 +135,7 @@ class ResList : public QTEXTBROWSER
DocSeqFiltSpec m_filtspecs; DocSeqFiltSpec m_filtspecs;
// Docs for current page // Docs for current page
std::vector<Rcl::Doc> m_curDocs; std::vector<Rcl::Doc> m_curDocs;
// First docnum (in m_docSource sequence) for current page
int m_winfirst;
// Translate from textedit paragraph number to relative // Translate from textedit paragraph number to relative
// docnum. Built while we insert text into the qtextedit // docnum. Built while we insert text into the qtextedit
std::map<int,int> m_pageParaToReldocnums; std::map<int,int> m_pageParaToReldocnums;
@ -122,6 +145,7 @@ class ResList : public QTEXTBROWSER
list<int> m_selDocs; list<int> m_selDocs;
int m_listId; int m_listId;
virtual int docnumfromparnum(int); virtual int docnumfromparnum(int);
virtual int parnumfromdocnum(int); virtual int parnumfromdocnum(int);

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _PLAINTORICH_H_INCLUDED_ #ifndef _PLAINTORICH_H_INCLUDED_
#define _PLAINTORICH_H_INCLUDED_ #define _PLAINTORICH_H_INCLUDED_
/* @(#$Id: plaintorich.h,v 1.1 2008-11-19 12:19:40 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: plaintorich.h,v 1.2 2008-12-16 14:20:10 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string> #include <string>
#include <list> #include <list>
@ -42,7 +42,7 @@ struct HiliteData {
*/ */
class PlainToRich { class PlainToRich {
public: public:
PlainToRich(bool inputhtml = false) : m_inputhtml(inputhtml) {} PlainToRich() : m_inputhtml(false) {}
virtual ~PlainToRich() {} virtual ~PlainToRich() {}
void set_inputhtml(bool v) {m_inputhtml = v;} void set_inputhtml(bool v) {m_inputhtml = v;}

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: reslistpager.cpp,v 1.6 2008-12-15 15:04:53 dockes Exp $ (C) 2007 J.F.Dockes"; static char rcsid[] = "@(#$Id: reslistpager.cpp,v 1.7 2008-12-16 14:20:10 dockes Exp $ (C) 2007 J.F.Dockes";
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -13,19 +13,14 @@ static char rcsid[] = "@(#$Id: reslistpager.cpp,v 1.6 2008-12-15 15:04:53 dockes
#include "plaintorich.h" #include "plaintorich.h"
#include "mimehandler.h" #include "mimehandler.h"
// This should be passed as an input object to the pager instead // Default highlighter
class PlainToRichHtReslist : public PlainToRich { class PlainToRichHtReslist : public PlainToRich {
public: public:
virtual ~PlainToRichHtReslist() {} virtual ~PlainToRichHtReslist() {}
virtual string startMatch() {return string("<font color=\"blue\">");} virtual string startMatch() {return string("<font color=\"blue\">");}
virtual string endMatch() {return string("</font>");} virtual string endMatch() {return string("</font>");}
}; };
// IDEM static PlainToRichHtReslist g_hiliter;
struct Prefs {
bool queryBuildAbstract;
bool queryReplaceAbstract;
};
Prefs prefs = {true, true};
void ResListPager::resultPageNext() void ResListPager::resultPageNext()
{ {
@ -41,7 +36,7 @@ void ResListPager::resultPageNext()
if (m_winfirst < 0) { if (m_winfirst < 0) {
m_winfirst = 0; m_winfirst = 0;
} else { } else {
m_winfirst += m_pagesize; m_winfirst += m_respage.size();
} }
// Get the next page of results. // Get the next page of results.
vector<ResListEntry> npage; vector<ResListEntry> npage;
@ -59,7 +54,7 @@ void ResListPager::resultPageNext()
// Next button. We'd need to remove the Next link from the page // Next button. We'd need to remove the Next link from the page
// too. // too.
// Restore the m_winfirst value, let the current result vector alone // Restore the m_winfirst value, let the current result vector alone
m_winfirst -= m_pagesize; m_winfirst -= m_respage.size();
} else { } else {
// No results at all (on first page) // No results at all (on first page)
m_winfirst = -1; m_winfirst = -1;
@ -71,14 +66,18 @@ void ResListPager::resultPageNext()
void ResListPager::displayPage() void ResListPager::displayPage()
{ {
LOGDEB(("ResListPager::displayPage\n"));
if (m_docSource.isNull()) { if (m_docSource.isNull()) {
LOGDEB(("ResListPager::displayPage: null source\n")); LOGDEB(("ResListPager::displayPage: null source\n"));
return; return;
} }
if (m_winfirst < 0) { if (m_winfirst < 0 && !pageEmpty()) {
LOGDEB(("ResListPager::displayPage: sequence error: winfirst < 0\n")); LOGDEB(("ResListPager::displayPage: sequence error: winfirst < 0\n"));
return; return;
} }
if (m_hiliter == 0)
m_hiliter = &g_hiliter;
string chunk; string chunk;
// Display list header // Display list header
@ -89,10 +88,8 @@ void ResListPager::displayPage()
// gets confused. Hence the use of the 'chunk' text // gets confused. Hence the use of the 'chunk' text
// accumulator // accumulator
// Also note that there can be results beyond the estimated resCnt. // Also note that there can be results beyond the estimated resCnt.
chunk = "<html><head>" chunk = "<html><head><meta http-equiv=\"content-type\""
"<meta http-equiv=\"content-type\"" "content=\"text/html; charset=utf-8\"></head><body>";
"content=\"text/html; charset=utf-8\">"
"</head><body>";
chunk += pageTop(); chunk += pageTop();
chunk += "<p><font size=+1><b>"; chunk += "<p><font size=+1><b>";
chunk += m_docSource->title(); chunk += m_docSource->title();
@ -100,17 +97,17 @@ void ResListPager::displayPage()
"&nbsp;&nbsp;&nbsp;"; "&nbsp;&nbsp;&nbsp;";
if (pageEmpty()) { if (pageEmpty()) {
chunk += tr("<p><b>No results found</b> for "); chunk += trans("<p><b>No results found</b><br>");
} else { } else {
unsigned int resCnt = m_docSource->getResCnt(); unsigned int resCnt = m_docSource->getResCnt();
if (m_winfirst + m_respage.size() < resCnt) { if (m_winfirst + m_respage.size() < resCnt) {
string f1 = tr("Documents <b>%d-%d</b> out of at least <b>%d</b> for "); string f1 = trans("Documents <b>%d-%d</b> out of at least <b>%d</b> for ");
char buf[1024]; char buf[1024];
snprintf(buf, 1023, f1.c_str(), m_winfirst+1, snprintf(buf, 1023, f1.c_str(), m_winfirst+1,
m_winfirst + m_respage.size(), resCnt); m_winfirst + m_respage.size(), resCnt);
chunk += buf; chunk += buf;
} else { } else {
string f1 = tr("Documents <b>%d-%d</b> for "); string f1 = trans("Documents <b>%d-%d</b> for ");
char buf[1024]; char buf[1024];
snprintf(buf, 1023, f1.c_str(), m_winfirst + 1, snprintf(buf, 1023, f1.c_str(), m_winfirst + 1,
m_winfirst + m_respage.size()); m_winfirst + m_respage.size());
@ -122,12 +119,12 @@ void ResListPager::displayPage()
chunk += "&nbsp;&nbsp;"; chunk += "&nbsp;&nbsp;";
if (hasPrev()) { if (hasPrev()) {
chunk += "<a href=\"" + prevUrl() + "\"><b>"; chunk += "<a href=\"" + prevUrl() + "\"><b>";
chunk += tr("Previous"); chunk += trans("Previous");
chunk += "</b></a>&nbsp;&nbsp;&nbsp;"; chunk += "</b></a>&nbsp;&nbsp;&nbsp;";
} }
if (hasNext()) { if (hasNext()) {
chunk += "<a href=\""+ nextUrl() + "\"><b>"; chunk += "<a href=\""+ nextUrl() + "\"><b>";
chunk += tr("Next"); chunk += trans("Next");
chunk += "</b></a>"; chunk += "</b></a>";
} }
} }
@ -137,7 +134,6 @@ void ResListPager::displayPage()
if (pageEmpty()) if (pageEmpty())
return; return;
HiliteData hdata; HiliteData hdata;
m_docSource->getTerms(hdata.terms, hdata.groups, hdata.gslks); m_docSource->getTerms(hdata.terms, hdata.groups, hdata.gslks);
@ -151,7 +147,7 @@ void ResListPager::displayPage()
if (doc.pc == -1) { if (doc.pc == -1) {
percent = 0; percent = 0;
// Document not available, maybe other further, will go on. // Document not available, maybe other further, will go on.
doc.meta[Rcl::Doc::keyabs] = string(tr("Unavailable document")); doc.meta[Rcl::Doc::keyabs] = string(trans("Unavailable document"));
} else { } else {
percent = doc.pc; percent = doc.pc;
} }
@ -160,9 +156,7 @@ void ResListPager::displayPage()
sprintf(perbuf, "%3d%% ", percent); sprintf(perbuf, "%3d%% ", percent);
// Determine icon to display if any // Determine icon to display if any
string iconpath; string iconpath = iconPath(doc.mimetype);
RclConfig::getMainConfig()->getMimeIconName(doc.mimetype, &iconpath);
iconpath = string("file://") + iconpath;
// Printable url: either utf-8 if transcoding succeeds, or url-encoded // Printable url: either utf-8 if transcoding succeeds, or url-encoded
string url; string url;
@ -208,16 +202,15 @@ void ResListPager::displayPage()
} }
string abstract; string abstract;
if (prefs.queryBuildAbstract && if (m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
(doc.syntabs || prefs.queryReplaceAbstract)) {
abstract = m_docSource->getAbstract(doc); abstract = m_docSource->getAbstract(doc);
} else { } else {
abstract = doc.meta[Rcl::Doc::keyabs]; abstract = doc.meta[Rcl::Doc::keyabs];
} }
// No need to call escapeHtml(), plaintorich handles it // No need to call escapeHtml(), plaintorich handles it
list<string> lr; list<string> lr;
PlainToRichHtReslist ptr; m_hiliter->set_inputhtml(false);
ptr.plaintorich(abstract, lr, hdata); m_hiliter->plaintorich(abstract, lr, hdata);
string richabst = lr.front(); string richabst = lr.front();
// Links; // Links;
@ -225,12 +218,13 @@ void ResListPager::displayPage()
char vlbuf[100]; char vlbuf[100];
if (canIntern(doc.mimetype, RclConfig::getMainConfig())) { if (canIntern(doc.mimetype, RclConfig::getMainConfig())) {
sprintf(vlbuf, "\"P%d\"", docnumforlinks); sprintf(vlbuf, "\"P%d\"", docnumforlinks);
linksbuf += string("<a href=") + vlbuf + ">" + "Preview" + "</a>" linksbuf += string("<a href=") + vlbuf + ">" + trans("Preview")
+ "&nbsp;&nbsp;"; + "</a>&nbsp;&nbsp;";
} }
if (!RclConfig::getMainConfig()->getMimeViewerDef(doc.mimetype).empty()) { if (!RclConfig::getMainConfig()->getMimeViewerDef(doc.mimetype).empty()) {
sprintf(vlbuf, "E%d", docnumforlinks); sprintf(vlbuf, "E%d", docnumforlinks);
linksbuf += string("<a href=") + vlbuf + ">" + "Open" + "</a>"; linksbuf += string("<a href=") + vlbuf + ">" + trans("Open")
+ "</a>";
} }
// Build the result list paragraph: // Build the result list paragraph:
@ -265,7 +259,7 @@ void ResListPager::displayPage()
chunk += "</p>\n"; chunk += "</p>\n";
LOGDEB2(("Chunk: [%s]\n", (const char *)chunk.c_str())); LOGDEB2(("Chunk: [%s]\n", (const char *)chunk.c_str()));
append(chunk); append(chunk, i, doc);
} }
// Footer // Footer
@ -273,12 +267,12 @@ void ResListPager::displayPage()
if (hasPrev() || hasNext()) { if (hasPrev() || hasNext()) {
if (hasPrev()) { if (hasPrev()) {
chunk += "<a href=\"" + prevUrl() + "\"><b>"; chunk += "<a href=\"" + prevUrl() + "\"><b>";
chunk += tr("Previous"); chunk += trans("Previous");
chunk += "</b></a>&nbsp;&nbsp;&nbsp;"; chunk += "</b></a>&nbsp;&nbsp;&nbsp;";
} }
if (hasNext()) { if (hasNext()) {
chunk += "<a href=\""+ nextUrl() + "\"><b>"; chunk += "<a href=\""+ nextUrl() + "\"><b>";
chunk += tr("Next"); chunk += trans("Next");
chunk += "</b></a>"; chunk += "</b></a>";
} }
} }
@ -296,6 +290,14 @@ string ResListPager::prevUrl()
return "p-1"; return "p-1";
} }
string ResListPager::iconPath(const string& mtype)
{
string iconpath;
RclConfig::getMainConfig()->getMimeIconName(mtype, &iconpath);
iconpath = string("file://") + iconpath;
return iconpath;
}
// Default implementations for things that should be re-implemented by our user. // Default implementations for things that should be re-implemented by our user.
bool ResListPager::append(const string& data) bool ResListPager::append(const string& data)
{ {
@ -303,7 +305,7 @@ bool ResListPager::append(const string& data)
return true; return true;
} }
string ResListPager::tr(const string& in) string ResListPager::trans(const string& in)
{ {
return in; return in;
} }
@ -311,7 +313,7 @@ string ResListPager::tr(const string& in)
string ResListPager::detailsLink() string ResListPager::detailsLink()
{ {
string chunk = "<a href=\"H-1\">"; string chunk = "<a href=\"H-1\">";
chunk += tr("(show query)") + "</a>"; chunk += trans("(show query)") + "</a>";
return chunk; return chunk;
} }

View File

@ -1,6 +1,6 @@
#ifndef _reslistpager_h_included_ #ifndef _reslistpager_h_included_
#define _reslistpager_h_included_ #define _reslistpager_h_included_
/* @(#$Id: reslistpager.h,v 1.3 2008-12-04 11:49:59 dockes Exp $ (C) 2007 J.F.Dockes */ /* @(#$Id: reslistpager.h,v 1.4 2008-12-16 14:20:10 dockes Exp $ (C) 2007 J.F.Dockes */
#include <vector> #include <vector>
using std::vector; using std::vector;
@ -8,24 +8,31 @@ using std::vector;
#include "refcntr.h" #include "refcntr.h"
#include "docseq.h" #include "docseq.h"
class PlainToRich;
/** /**
* Produces html text for a paged result list. * Manage a paged HTML result list.
*/ */
class ResListPager { class ResListPager {
public: public:
ResListPager() : m_pagesize(10), m_hasNext(false) {} ResListPager(int pagesize=10) : m_pagesize(pagesize) {initall();}
ResListPager(RefCntr<DocSequence> src, int pagesize)
: m_pagesize(pagesize)
{
initall();
m_docSource = src;
}
virtual ~ResListPager() {}
void setHighLighter(PlainToRich *ptr) {m_hiliter = ptr;}
void setDocSource(RefCntr<DocSequence> src) void setDocSource(RefCntr<DocSequence> src)
{ {
m_winfirst = -1; m_winfirst = -1;
m_docSource = src;
m_hasNext = false; m_hasNext = false;
m_respage.clear(); m_respage.clear();
m_docSource = src;
} }
ResListPager(RefCntr<DocSequence> src, int pagesize)
: m_winfirst(-1), m_docSource(src), m_pagesize(pagesize),
m_hasNext(false)
{}
virtual ~ResListPager() {}
int pageNumber() int pageNumber()
{ {
if (m_winfirst < 0 || m_pagesize <= 0) if (m_winfirst < 0 || m_pagesize <= 0)
@ -55,13 +62,28 @@ public:
// Things that need to be reimplemented in the subclass: // Things that need to be reimplemented in the subclass:
virtual bool append(const string& data); virtual bool append(const string& data);
virtual string tr(const string& in); virtual bool append(const string& data, int, const Rcl::Doc&)
{
return append(data);
}
virtual string trans(const string& in);
virtual string detailsLink(); virtual string detailsLink();
virtual const string &parFormat(); virtual const string &parFormat();
virtual string nextUrl(); virtual string nextUrl();
virtual string prevUrl(); virtual string prevUrl();
virtual string pageTop() {return string();} virtual string pageTop() {return string();}
virtual string iconPath(const string& mtype);
private: private:
void initall()
{
m_winfirst = -1;
m_hasNext = false;
m_respage.clear();
m_queryBuildAbstract = true;
m_queryReplaceAbstract = false;
m_hiliter = 0;
}
// First docnum (from docseq) in current page // First docnum (from docseq) in current page
int m_winfirst; int m_winfirst;
RefCntr<DocSequence> m_docSource; RefCntr<DocSequence> m_docSource;
@ -69,6 +91,9 @@ private:
bool m_hasNext; bool m_hasNext;
vector<ResListEntry> m_respage; vector<ResListEntry> m_respage;
bool m_queryBuildAbstract;
bool m_queryReplaceAbstract;
PlainToRich *m_hiliter;
}; };
#endif /* _reslistpager_h_included_ */ #endif /* _reslistpager_h_included_ */

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: debuglog.cpp,v 1.5 2007-01-16 10:58:09 dockes Exp $ (C) 2006 J.F.Dockes"; static char rcsid[] = "@(#$Id: debuglog.cpp,v 1.6 2008-12-16 14:20:10 dockes Exp $ (C) 2006 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
@ -29,9 +29,16 @@ static char rcsid[] = "@(#$Id: debuglog.cpp,v 1.5 2007-01-16 10:58:09 dockes Exp
#include <new.h> #include <new.h>
#endif #endif
#include <stack> #include <string>
#include <set>
#include <list>
using std::set;
using std::string;
using std::list;
#include "debuglog.h" #include "debuglog.h"
#include "pathut.h"
#include "smallut.h"
#ifndef freeZ #ifndef freeZ
#define freeZ(X) {if (X) {free(X);X=0;}} #define freeZ(X) {if (X) {free(X);X=0;}}
@ -152,7 +159,26 @@ int DebugLogFileWriter::put(const char *s)
return impl ? impl->put(s) : -1; return impl ? impl->put(s) : -1;
}; };
static set<string> yesfiles;
static void initfiles()
{
const char *cp = getenv("DEBUGLOG_FILES");
if (!cp)
return;
list<string> files;
stringToTokens(cp, files, ",");
yesfiles.insert(files.begin(), files.end());
}
static bool fileInFiles(const string& file)
{
string sf = path_getsimple(file);
if (yesfiles.find(sf) != yesfiles.end()) {
//fprintf(stderr, "Debug ON: %s \n", file.c_str());
return true;
}
//fprintf(stderr, "Debug OFF: %s \n", file.c_str());
return false;
}
#ifdef _WINDOWS #ifdef _WINDOWS
#include <windows.h> #include <windows.h>
@ -186,6 +212,12 @@ DebugLog::prolog(int lev, const char *f, int line)
{ {
if (!writer) if (!writer)
return; return;
if (!yesfiles.empty() && !fileInFiles(f)) {
fileyes = false;
return;
} else {
fileyes = true;
}
if (dodate) { if (dodate) {
char dts[100]; char dts[100];
datestring(dts); datestring(dts);
@ -210,7 +242,7 @@ DebugLog::prolog(int lev, const char *f, int line)
void void
DebugLog::log(const char *s ...) DebugLog::log(const char *s ...)
{ {
if (!writer) if (!writer || !fileyes)
return; return;
va_list ap; va_list ap;
va_start(ap,s); va_start(ap,s);
@ -308,6 +340,7 @@ DebugLog *getdbl()
if (!(dbl = (DebugLog *)pthread_getspecific(dbl_key))) { if (!(dbl = (DebugLog *)pthread_getspecific(dbl_key))) {
dbl = new DebugLog; dbl = new DebugLog;
dbl->setwriter(theWriter); dbl->setwriter(theWriter);
initfiles();
status = pthread_setspecific(dbl_key, dbl); status = pthread_setspecific(dbl_key, dbl);
if (status) { if (status) {
fprintf(stderr, "debuglog: cant initialize pthread " fprintf(stderr, "debuglog: cant initialize pthread "
@ -326,6 +359,7 @@ DebugLog *getdbl()
if (!dbl) { if (!dbl) {
dbl = new DebugLog; dbl = new DebugLog;
dbl->setwriter(theWriter); dbl->setwriter(theWriter);
initfiles();
} }
return dbl; return dbl;
} }

View File

@ -44,13 +44,15 @@ namespace DebugLog {
class DebugLogWriter; class DebugLogWriter;
class DebugLog { class DebugLog {
std::stack<int> levels; stack<int> levels;
int debuglevel; int debuglevel;
int dodate; int dodate;
DebugLogWriter *writer; DebugLogWriter *writer;
bool fileyes;
public: public:
DebugLog() : debuglevel(10), dodate(0), writer(0) {} DebugLog() : debuglevel(10), dodate(0), writer(0), fileyes(true) {}
DebugLog(DebugLogWriter *w) : debuglevel(-1), dodate(0), writer(w) {} DebugLog(DebugLogWriter *w) : debuglevel(-1), dodate(0), writer(w),
fileyes(true) {}
virtual ~DebugLog() {} virtual ~DebugLog() {}
virtual void setwriter(DebugLogWriter *w) {writer = w;} virtual void setwriter(DebugLogWriter *w) {writer = w;}
virtual DebugLogWriter *getwriter() {return writer;} virtual DebugLogWriter *getwriter() {return writer;}