fix queryBuildAbstract option functionality. Allow substituting %(fieldname) in reslist paragraph format
This commit is contained in:
parent
0cf33ede6b
commit
fb2994ea74
@ -529,6 +529,9 @@ void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata)
|
||||
DocSequenceDb *src =
|
||||
new DocSequenceDb(RefCntr<Rcl::Query>(query),
|
||||
string(tr("Query results").utf8()), sdata);
|
||||
src->setAbstractParams(prefs.queryBuildAbstract,
|
||||
prefs.queryReplaceAbstract);
|
||||
|
||||
resList->setDocSource(RefCntr<DocSequence>(src));
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
@ -27,7 +27,9 @@ static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.9 2008-11-13 10:57:46 dockes Exp
|
||||
DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
|
||||
RefCntr<Rcl::SearchData> sdata)
|
||||
: DocSequence(t), m_q(q), m_sdata(sdata), m_fsdata(sdata),
|
||||
m_rescnt(-1), m_filt(false)
|
||||
m_rescnt(-1), m_filt(false),
|
||||
m_queryBuildAbstract(true),
|
||||
m_queryReplaceAbstract(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -66,7 +68,13 @@ string DocSequenceDb::getAbstract(Rcl::Doc &doc)
|
||||
if (!m_q->whatDb())
|
||||
return doc.meta[Rcl::Doc::keyabs];
|
||||
string abstract;
|
||||
m_q->whatDb()->makeDocAbstract(doc, m_q.getptr(), abstract);
|
||||
|
||||
if (m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
|
||||
m_q->whatDb()->makeDocAbstract(doc, m_q.getptr(), abstract);
|
||||
} else {
|
||||
abstract = doc.meta[Rcl::Doc::keyabs];
|
||||
}
|
||||
|
||||
return abstract.empty() ? doc.meta[Rcl::Doc::keyabs] : abstract;
|
||||
}
|
||||
|
||||
|
||||
@ -43,12 +43,20 @@ class DocSequenceDb : public DocSequence {
|
||||
virtual bool canSort() {return false;}
|
||||
virtual bool setSortSpec(DocSeqSortSpec &sortspec);
|
||||
virtual string title();
|
||||
virtual void setAbstractParams(bool qba, bool qra)
|
||||
{
|
||||
m_queryBuildAbstract = qba;
|
||||
m_queryReplaceAbstract = qra;
|
||||
}
|
||||
|
||||
private:
|
||||
RefCntr<Rcl::Query> m_q;
|
||||
RefCntr<Rcl::SearchData> m_sdata;
|
||||
RefCntr<Rcl::SearchData> m_fsdata; // Filtered
|
||||
int m_rescnt;
|
||||
bool m_filt;
|
||||
bool m_queryBuildAbstract;
|
||||
bool m_queryReplaceAbstract;
|
||||
};
|
||||
|
||||
#endif /* _DOCSEQDB_H_INCLUDED_ */
|
||||
|
||||
@ -201,12 +201,8 @@ void ResListPager::displayPage()
|
||||
sizebuf = displayableBytes(fsize);
|
||||
}
|
||||
|
||||
string abstract;
|
||||
if (m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
|
||||
abstract = m_docSource->getAbstract(doc);
|
||||
} else {
|
||||
abstract = doc.meta[Rcl::Doc::keyabs];
|
||||
}
|
||||
string abstract = m_docSource->getAbstract(doc);
|
||||
|
||||
// No need to call escapeHtml(), plaintorich handles it
|
||||
list<string> lr;
|
||||
m_hiliter->set_inputhtml(false);
|
||||
@ -237,20 +233,23 @@ void ResListPager::displayPage()
|
||||
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() ?
|
||||
map<string,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;
|
||||
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;
|
||||
|
||||
// Let %(xx) access all metadata.
|
||||
subs.insert(doc.meta.begin(), doc.meta.end());
|
||||
|
||||
string formatted;
|
||||
pcSubst(parFormat(), formatted, subs);
|
||||
@ -281,10 +280,13 @@ void ResListPager::displayPage()
|
||||
append(chunk);
|
||||
}
|
||||
|
||||
// Default implementations for things that should be implemented by
|
||||
// specializations
|
||||
string ResListPager::nextUrl()
|
||||
{
|
||||
return "n-1";
|
||||
}
|
||||
|
||||
string ResListPager::prevUrl()
|
||||
{
|
||||
return "p-1";
|
||||
@ -298,7 +300,6 @@ string ResListPager::iconPath(const string& mtype)
|
||||
return iconpath;
|
||||
}
|
||||
|
||||
// Default implementations for things that should be re-implemented by our user.
|
||||
bool ResListPager::append(const string& data)
|
||||
{
|
||||
fprintf(stderr, "%s", data.c_str());
|
||||
|
||||
@ -16,12 +16,6 @@ class PlainToRich;
|
||||
class ResListPager {
|
||||
public:
|
||||
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;}
|
||||
@ -79,8 +73,6 @@ private:
|
||||
m_winfirst = -1;
|
||||
m_hasNext = false;
|
||||
m_respage.clear();
|
||||
m_queryBuildAbstract = true;
|
||||
m_queryReplaceAbstract = false;
|
||||
m_hiliter = 0;
|
||||
}
|
||||
|
||||
@ -91,8 +83,6 @@ private:
|
||||
|
||||
bool m_hasNext;
|
||||
vector<ResListEntry> m_respage;
|
||||
bool m_queryBuildAbstract;
|
||||
bool m_queryReplaceAbstract;
|
||||
PlainToRich *m_hiliter;
|
||||
};
|
||||
|
||||
|
||||
@ -72,12 +72,14 @@ trmimeparse.o : mimeparse.cpp
|
||||
$(CXX) $(ALL_CXXFLAGS) -DTEST_MIMEPARSE -c -o trmimeparse.o \
|
||||
mimeparse.cpp
|
||||
|
||||
SMALLUT_OBJS= trsmallut.o $(BIGLIB)
|
||||
smallut : $(SMALLUT_OBJS)
|
||||
SMALLUT_OBJS= trsmallut.o ../lib/smallut.o
|
||||
smallut : $(SMALLUT_OBJS) smallut.h
|
||||
$(CXX) $(ALL_CXXFLAGS) -o smallut $(SMALLUT_OBJS) $(LIBICONV)
|
||||
trsmallut.o : smallut.cpp
|
||||
trsmallut.o : smallut.cpp smallut.h
|
||||
$(CXX) $(ALL_CXXFLAGS) -DTEST_SMALLUT -c -o trsmallut.o \
|
||||
smallut.cpp
|
||||
../lib/smallut.o: smallut.cpp smallut.h
|
||||
cd ../lib;make smallut.o
|
||||
|
||||
WIPEDIR_OBJS= trwipedir.o $(BIGLIB)
|
||||
wipedir : $(WIPEDIR_OBJS)
|
||||
|
||||
@ -492,7 +492,8 @@ bool pcSubst(const string& in, string& out, map<char, string>& subs)
|
||||
if ((tr = subs.find(*it)) != subs.end()) {
|
||||
out += tr->second;
|
||||
} else {
|
||||
out += *it;
|
||||
// We used to do "out += *it;" here but this does not make
|
||||
// sense
|
||||
}
|
||||
} else {
|
||||
out += *it;
|
||||
@ -501,6 +502,52 @@ bool pcSubst(const string& in, string& out, map<char, string>& subs)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pcSubst(const string& in, string& out, map<string, string>& subs)
|
||||
{
|
||||
out.erase();
|
||||
string::size_type i;
|
||||
for (i = 0; i < in.size(); i++) {
|
||||
if (in[i] == '%') {
|
||||
if (++i == in.size()) {
|
||||
out += '%';
|
||||
break;
|
||||
}
|
||||
if (in[i] == '%') {
|
||||
out += '%';
|
||||
continue;
|
||||
}
|
||||
string key = "";
|
||||
if (in[i] == '(') {
|
||||
if (++i == in.size()) {
|
||||
out += string("%(");
|
||||
break;
|
||||
}
|
||||
string::size_type j = in.find_first_of(")", i);
|
||||
if (j == string::npos) {
|
||||
// ??concatenate remaining part and stop
|
||||
out += in.substr(i-2);
|
||||
break;
|
||||
}
|
||||
key = in.substr(i, j-i);
|
||||
i = j;
|
||||
} else {
|
||||
key = in[i];
|
||||
}
|
||||
map<string,string>::iterator tr;
|
||||
if ((tr = subs.find(key)) != subs.end()) {
|
||||
out += tr->second;
|
||||
} else {
|
||||
// Substitute to nothing, that's the reasonable thing to do
|
||||
// instead of keeping the %(key)
|
||||
// out += key.size()==1? key : string("(") + key + string(")");
|
||||
}
|
||||
} else {
|
||||
out += in[i];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Convert byte count into unit (KB/MB...) appropriate for display
|
||||
string displayableBytes(long size)
|
||||
{
|
||||
@ -712,11 +759,34 @@ int main(int argc, char **argv)
|
||||
utf8truncate(testit, sz);
|
||||
cout << testit << endl;
|
||||
}
|
||||
#elif 1
|
||||
#elif 0
|
||||
std::string testit("ligne\ndeuxieme ligne\r3eme ligne\r\n");
|
||||
cout << "[" << neutchars(testit, "\r\n") << "]" << endl;
|
||||
string i, o;
|
||||
cout << "neutchars(null) is [" << neutchars(i, "\r\n") << "]" << endl;
|
||||
#elif 1
|
||||
map<string, string> substs;
|
||||
substs["a"] = "A_SUBST";
|
||||
substs["title"] = "TITLE_SUBST";
|
||||
string in = "a: %a title: %(title) pcpc: %% %";
|
||||
string out;
|
||||
pcSubst(in, out, substs);
|
||||
cout << in << " => " << out << endl;
|
||||
|
||||
in = "unfinished: %(unfinished";
|
||||
pcSubst(in, out, substs);
|
||||
cout << in << " => " << out << endl;
|
||||
in = "unfinished: %(";
|
||||
pcSubst(in, out, substs);
|
||||
cout << in << " => " << out << endl;
|
||||
in = "empty: %()";
|
||||
pcSubst(in, out, substs);
|
||||
cout << in << " => " << out << endl;
|
||||
substs.clear();
|
||||
in = "a: %a title: %(title) pcpc: %% %";
|
||||
pcSubst(in, out, substs);
|
||||
cout << "After map clear: " << in << " => " << out << endl;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -102,6 +102,8 @@ string breakIntoLines(const string& in, unsigned int ll = 100,
|
||||
unsigned int maxlines= 50);
|
||||
/** Small utility to substitute printf-like percents cmds in a string */
|
||||
bool pcSubst(const string& in, string& out, map<char, string>& subs);
|
||||
/** Substitute printf-like percents and also %(key) */
|
||||
bool pcSubst(const string& in, string& out, map<string, string>& subs);
|
||||
|
||||
class Chrono {
|
||||
public:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user