diff --git a/src/qtgui/plaintorich.cpp b/src/qtgui/plaintorich.cpp index 8baf7452..9c82a730 100644 --- a/src/qtgui/plaintorich.cpp +++ b/src/qtgui/plaintorich.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.19 2006-12-11 14:56:38 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.20 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -68,8 +68,9 @@ class myTextSplitCB : public TextSplitCB { // Out: begin and end byte positions of query terms/groups in text vector > tboffs; - myTextSplitCB(const vector& its, vector >&groups, - vector& slacks) + myTextSplitCB(const vector& its, + const vector >&groups, + const vector& slacks) : firstTermOcc(1), m_wcount(0), m_groups(groups), m_slacks(slacks) { for (vector::const_iterator it = its.begin(); @@ -316,16 +317,14 @@ const char *firstTermBeacon = "\xe2\xa0\x91\xe2\x96\x9f\x20\x01\x9a"; // we return the first term encountered, and the caller will use the // editor's find() function to position on it bool plaintorich(const string& in, string& out, - RefCntr sdata, + const HiliteData& hdata, bool noHeader, bool fft) { Chrono chron; out.erase(); - vector terms; - vector > groups; - vector slacks; - - sdata->getTerms(terms, groups, slacks); + const vector& terms(hdata.terms); + const vector >& groups(hdata.groups); + const vector& slacks(hdata.gslks); if (DebugLog::getdbl()->getlevel() >= DEBDEB0) { LOGDEB0(("plaintorich: terms: \n")); @@ -333,7 +332,7 @@ bool plaintorich(const string& in, string& out, LOGDEB0((" %s\n", sterms.c_str())); sterms = "\n"; LOGDEB0(("plaintorich: groups: \n")); - for (vector >::iterator vit = groups.begin(); + for (vector >::const_iterator vit = groups.begin(); vit != groups.end(); vit++) { sterms += vecStringToString(*vit); sterms += "\n"; diff --git a/src/qtgui/plaintorich.h b/src/qtgui/plaintorich.h index 3f7fbdd9..a6b895d7 100644 --- a/src/qtgui/plaintorich.h +++ b/src/qtgui/plaintorich.h @@ -16,11 +16,16 @@ */ #ifndef _PLAINTORICH_H_INCLUDED_ #define _PLAINTORICH_H_INCLUDED_ -/* @(#$Id: plaintorich.h,v 1.11 2006-11-30 13:38:44 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: plaintorich.h,v 1.12 2007-01-19 15:22:50 dockes Exp $ (C) 2004 J.F.Dockes */ #include -#include "searchdata.h" +// A data struct to hold words and groups of words to be highlighted +struct HiliteData { + vector terms; + vector > groups; + vector gslks; // group slacks (number of permitted non-matched words) +}; /** * Transform plain text into qt rich text for the preview window. @@ -31,13 +36,13 @@ * * @param in raw text out of internfile. * @param out rich text output - * @param terms list of query terms. These are out of Rcl::Db and dumb - * @param firstTerm out: value of the first search term in text. - * @param frsttocc out: occurrence of 1st term to look for + * @param hdata terms and groups to be highlighted. These are + * lowercase and unaccented. * @param noHeader if true don't output header (...) + * @param fft If true mark the first term position in the text */ extern bool plaintorich(const string &in, string &out, - RefCntr<Rcl::SearchData> sdata, + const HiliteData& hdata, bool noHeader = false, bool fft = false); diff --git a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp index e137ade0..17bbe055 100644 --- a/src/qtgui/preview_w.cpp +++ b/src/qtgui/preview_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.13 2006-12-20 14:09:21 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.14 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -497,12 +497,12 @@ class LoadThread : public QThread { /* A thread to convert to rich text (mark search terms) */ class ToRichThread : public QThread { string ∈ - RefCntr<Rcl::SearchData> m_searchData; + const HiliteData &hdata; QString &out; int loglevel; public: - ToRichThread(string &i, RefCntr<Rcl::SearchData> searchData, QString &o) - : in(i), m_searchData(searchData), out(o) + ToRichThread(string &i, const HiliteData& hd, QString &o) + : in(i), hdata(hd), out(o) { loglevel = DebugLog::getdbl()->getlevel(); } @@ -511,7 +511,7 @@ class ToRichThread : public QThread { DebugLog::getdbl()->setloglevel(loglevel); string rich; try { - plaintorich(in, rich, m_searchData, false, true); + plaintorich(in, rich, hdata, false, true); } catch (CancelExcept) { } out = QString::fromUtf8(rich.c_str(), rich.length()); @@ -599,7 +599,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc, bool highlightTerms = fdoc.text.length() < 1000 *1024; if (highlightTerms) { progress.setLabelText(tr("Creating preview text")); - ToRichThread rthr(fdoc.text, m_searchData, richTxt); + ToRichThread rthr(fdoc.text, m_hData, richTxt); rthr.start(); for (;;prog++) { diff --git a/src/qtgui/preview_w.h b/src/qtgui/preview_w.h index 93872584..5e211a1b 100644 --- a/src/qtgui/preview_w.h +++ b/src/qtgui/preview_w.h @@ -1,6 +1,6 @@ #ifndef _PREVIEW_W_H_INCLUDED_ #define _PREVIEW_W_H_INCLUDED_ -/* @(#$Id: preview_w.h,v 1.7 2006-12-04 09:56:26 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: preview_w.h,v 1.8 2007-01-19 15:22:50 dockes Exp $ (C) 2006 J.F.Dockes */ /* * 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 @@ -29,7 +29,7 @@ #define QTextEdit Q3TextEdit #endif #include "refcntr.h" -#include "searchdata.h" +#include "plaintorich.h" // We keep a list of data associated to each tab class TabData { @@ -69,10 +69,10 @@ public: ~Preview(){} - virtual void setSId(int sid, RefCntr<Rcl::SearchData> sdata) + virtual void setSId(int sid, const HiliteData& hdata) { m_searchId = sid; - m_searchData = sdata; + m_hData = hdata; } virtual void closeEvent( QCloseEvent *e ); virtual bool eventFilter( QObject *target, QEvent *event ); @@ -111,7 +111,7 @@ private: bool canBeep; list<TabData> tabData; QWidget *currentW; - RefCntr<Rcl::SearchData> m_searchData; + HiliteData m_hData; void init(); virtual void destroy(); TabData *tabDataForCurrent(); // Return auxiliary data pointer for cur tab diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 48de7704..cddbf5ef 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.23 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.24 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -380,8 +380,10 @@ void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata) return; } curPreview = 0; + DocSequenceDb *src = + new DocSequenceDb(rcldb, string(tr("Query results").utf8()), sdata); + m_docSource = RefCntr<DocSequence>(src); m_searchData = sdata; - m_docSource = RefCntr<DocSequence>(new DocSequenceDb(rcldb, string(tr("Query results").utf8()))); setDocSequence(); } @@ -404,7 +406,7 @@ void RclMain::setDocSequence() docsource = m_docSource; } m_searchId++; - resList->setDocSource(docsource, m_searchData); + resList->setDocSource(docsource); } // Open advanced search dialog. @@ -531,7 +533,9 @@ void RclMain::startPreview(int docnum, int mod) QMessageBox::NoButton); return; } - curPreview->setSId(m_searchId, resList->getSearchData()); + HiliteData hdata; + m_searchData->getTerms(hdata.terms, hdata.groups, hdata.gslks); + curPreview->setSId(m_searchId, hdata); curPreview->setCaption(resList->getDescription()); connect(curPreview, SIGNAL(previewClosed(QWidget *)), this, SLOT(previewClosed(QWidget *))); @@ -582,8 +586,7 @@ void RclMain::startPreview(Rcl::Doc doc) QMessageBox::NoButton); return; } - RefCntr<Rcl::SearchData> searchdata(new Rcl::SearchData(Rcl::SCLT_AND)); - preview->setSId(0, searchdata); + preview->setSId(0, HiliteData()); connect(preview, SIGNAL(wordSelect(QString)), this, SLOT(ssearchAddTerm(QString))); g_dynconf->enterDoc(fn, doc.ipath); @@ -868,9 +871,11 @@ void RclMain::showDocHistory() m_searchId++; - m_docSource = RefCntr<DocSequence>(new DocSequenceHistory(rcldb, - g_dynconf, - string(tr("Document history").utf8()))); + DocSequenceHistory *src = + new DocSequenceHistory(rcldb, g_dynconf, + string(tr("Document history").utf8())); + src->setDescription((const char *)tr("History data").utf8()); + m_docSource = RefCntr<DocSequence>(src); setDocSequence(); } diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index 7ab355d3..51867ab5 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: reslist.cpp,v 1.20 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: reslist.cpp,v 1.21 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include <time.h> @@ -85,12 +85,10 @@ void ResList::languageChange() } // Acquire new docsource -void ResList::setDocSource(RefCntr<DocSequence> docsource, - RefCntr<Rcl::SearchData> sdt) +void ResList::setDocSource(RefCntr<DocSequence> docsource) { m_winfirst = -1; m_docSource = docsource; - m_searchData = sdt; m_curPvDoc = -1; resultPageNext(); @@ -351,6 +349,9 @@ void ResList::resultPageNext() 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 @@ -443,7 +444,7 @@ void ResList::resultPageNext() } string richabst; - plaintorich(abstract, richabst, m_searchData, true); + plaintorich(abstract, richabst, hdata, true); // Links; string linksbuf; @@ -682,7 +683,7 @@ void ResList::menuExpand() QString ResList::getDescription() { - return QString::fromUtf8(m_searchData->getDescription().c_str()); + return QString::fromUtf8(m_docSource->getDescription().c_str()); } /** Show detailed expansion of a query */ @@ -692,7 +693,7 @@ void ResList::showQueryDetails() // Also limit the total number of lines. const unsigned int ll = 100; const unsigned int maxlines = 50; - string query = m_searchData->getDescription(); + string query = m_docSource->getDescription(); string oq; unsigned int nlines = 0; while (query.length() > 0) { diff --git a/src/qtgui/reslist.h b/src/qtgui/reslist.h index 59aafaec..806a73ed 100644 --- a/src/qtgui/reslist.h +++ b/src/qtgui/reslist.h @@ -1,6 +1,6 @@ #ifndef _RESLIST_H_INCLUDED_ #define _RESLIST_H_INCLUDED_ -/* @(#$Id: reslist.h,v 1.8 2007-01-08 10:01:55 dockes Exp $ (C) 2005 J.F.Dockes */ +/* @(#$Id: reslist.h,v 1.9 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes */ #include <list> @@ -20,12 +20,9 @@ class Q3PopupMenu; #define QTEXTBROWSER Q3TextBrowser #endif -#include "rcldb.h" #include "docseq.h" -#include "searchdata.h" #include "refcntr.h" - class ResList : public QTEXTBROWSER { Q_OBJECT; @@ -40,12 +37,10 @@ class ResList : public QTEXTBROWSER // num is inside the current page or its immediate neighbours. virtual bool getDoc(int docnum, Rcl::Doc &); - virtual void setDocSource(RefCntr<DocSequence> source, - RefCntr<Rcl::SearchData> qdata); + virtual void setDocSource(RefCntr<DocSequence> source); virtual RCLPOPUP *createPopupMenu(const QPoint& pos); virtual QString getDescription(); // Printable actual query performed on db virtual int getResCnt(); // Return total result list size - virtual RefCntr<Rcl::SearchData> getSearchData() {return m_searchData;} public slots: virtual void resetSearch(); @@ -86,7 +81,6 @@ class ResList : public QTEXTBROWSER private: std::map<int,int> m_pageParaToReldocnums; - RefCntr<Rcl::SearchData> m_searchData; RefCntr<DocSequence> m_docSource; std::vector<Rcl::Doc> m_curDocs; int m_winfirst; diff --git a/src/query/docseq.h b/src/query/docseq.h index fb1468d9..dda1be88 100644 --- a/src/query/docseq.h +++ b/src/query/docseq.h @@ -16,7 +16,7 @@ */ #ifndef _DOCSEQ_H_INCLUDED_ #define _DOCSEQ_H_INCLUDED_ -/* @(#$Id: docseq.h,v 1.10 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: docseq.h,v 1.11 2007-01-19 15:22:50 dockes Exp $ (C) 2004 J.F.Dockes */ #include <string> #include <list> #include <vector> @@ -79,9 +79,16 @@ class DocSequence { /** Get title for result list */ virtual string title() {return m_title;} + /** Get description for underlying query */ + virtual string getDescription() = 0; + /** Get search terms (for highlighting abstracts). Some sequences * may have no associated search terms. Implement this for them. */ - virtual void getTerms(list<string>& t) {t.clear();} + virtual bool getTerms(vector<string>& terms, + vector<vector<string> >& groups, + vector<int>& gslks) const { + terms.clear(); groups.clear(); gslks.clear(); return true; + } private: string m_title; diff --git a/src/query/docseqdb.cpp b/src/query/docseqdb.cpp index 4741f294..6754adce 100644 --- a/src/query/docseqdb.cpp +++ b/src/query/docseqdb.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.1 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.2 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -39,13 +39,6 @@ int DocSequenceDb::getResCnt() return m_rescnt; } -void DocSequenceDb::getTerms(list<string> &terms) -{ - if (!m_db) - return; - m_db->getQueryTerms(terms); -} - string DocSequenceDb::getAbstract(Rcl::Doc &doc) { if (!m_db) diff --git a/src/query/docseqdb.h b/src/query/docseqdb.h index 8b9f9dc3..203713eb 100644 --- a/src/query/docseqdb.h +++ b/src/query/docseqdb.h @@ -16,35 +16,35 @@ */ #ifndef _DOCSEQDB_H_INCLUDED_ #define _DOCSEQDB_H_INCLUDED_ -/* @(#$Id: docseqdb.h,v 1.1 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */ -#include <string> -#include <list> -#ifndef NO_NAMESPACES -using std::string; -using std::list; -#endif - +/* @(#$Id: docseqdb.h,v 1.2 2007-01-19 15:22:50 dockes Exp $ (C) 2004 J.F.Dockes */ #include "docseq.h" -namespace Rcl { -class Db; -} +#include "refcntr.h" + +#include "searchdata.h" /** A DocSequence from a Db query (there should be one active for this - to make sense */ + to make sense) */ class DocSequenceDb : public DocSequence { public: - DocSequenceDb(Rcl::Db *d, const string &t) : - DocSequence(t), m_db(d), m_rescnt(-1) + DocSequenceDb(Rcl::Db *d, const string &t, RefCntr<Rcl::SearchData> sdata) + : DocSequence(t), m_db(d), m_sdata(sdata), m_rescnt(-1) {} virtual ~DocSequenceDb() {} virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0); virtual int getResCnt(); - virtual void getTerms(list<string>&); + virtual bool getTerms(vector<string>& terms, + vector<vector<string> >& groups, + vector<int>& gslks) const { + return m_sdata.getptr()->getTerms(terms, groups, gslks); + } + virtual string getAbstract(Rcl::Doc &doc); + virtual string getDescription() {return m_sdata->getDescription();} private: - Rcl::Db *m_db; - int m_rescnt; + Rcl::Db *m_db; + RefCntr<Rcl::SearchData> m_sdata; + int m_rescnt; }; #endif /* _DOCSEQDB_H_INCLUDED_ */ diff --git a/src/query/docseqhist.h b/src/query/docseqhist.h index b179f5bc..0f5633ce 100644 --- a/src/query/docseqhist.h +++ b/src/query/docseqhist.h @@ -16,20 +16,14 @@ */ #ifndef _DOCSEQHIST_H_INCLUDED_ #define _DOCSEQHIST_H_INCLUDED_ -/* @(#$Id: docseqhist.h,v 1.1 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */ -#include <string> -#include <list> -#ifndef NO_NAMESPACES -using std::string; -using std::list; -#endif +/* @(#$Id: docseqhist.h,v 1.2 2007-01-19 15:22:50 dockes Exp $ (C) 2004 J.F.Dockes */ #include "docseq.h" #include "history.h" + namespace Rcl { -class Db; + class Db; } -class RclHistory; /** A DocSequence coming from the history file. * History is kept as a list of urls. This queries the db to fetch @@ -42,12 +36,14 @@ class DocSequenceHistory : public DocSequence { virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0); virtual int getResCnt(); + virtual string getDescription() {return m_description;} + void setDescription(const string& desc) {m_description = desc;} private: Rcl::Db *m_db; RclHistory *m_hist; int m_prevnum; long m_prevtime; - + string m_description; // This is just an nls translated 'doc history' list<RclDHistoryEntry> m_hlist; list<RclDHistoryEntry>::const_iterator m_it; }; diff --git a/src/query/sortseq.cpp b/src/query/sortseq.cpp index 195ad9bd..e2c87a70 100644 --- a/src/query/sortseq.cpp +++ b/src/query/sortseq.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.10 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.11 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -120,8 +120,3 @@ bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *) doc = *m_docsp[num]; return true; } - -string DocSeqSorted::getAbstract(Rcl::Doc& doc) -{ - return m_seq->getAbstract(doc); -} diff --git a/src/query/sortseq.h b/src/query/sortseq.h index 7f055bca..7f53dd60 100644 --- a/src/query/sortseq.h +++ b/src/query/sortseq.h @@ -16,7 +16,7 @@ */ #ifndef _SORTSEQ_H_INCLUDED_ #define _SORTSEQ_H_INCLUDED_ -/* @(#$Id: sortseq.h,v 1.9 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: sortseq.h,v 1.10 2007-01-19 15:22:50 dockes Exp $ (C) 2004 J.F.Dockes */ #include <vector> #include <string> @@ -48,7 +48,10 @@ class DocSeqSorted : public DocSequence { virtual ~DocSeqSorted() {} virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0); virtual int getResCnt() {return m_spec.sortwidth;} - virtual string getAbstract(Rcl::Doc& doc); + virtual string getAbstract(Rcl::Doc& doc) { + return m_seq->getAbstract(doc); + } + virtual string getDescription() {return m_seq->getDescription();} private: RefCntr<DocSequence> m_seq;