1st beagle version with index/preview working

This commit is contained in:
dockes
2009-11-13 13:29:34 +00:00
parent efa501f06d
commit bbba826c06
12 changed files with 341 additions and 152 deletions
+3 -3
View File
@@ -156,10 +156,10 @@ ConfBeaglePanelW::ConfBeaglePanelW(QWidget *parent, ConfNull *config)
ConfLink lnk1(new ConfLinkRclRep(config, "processbeaglequeue"));
ConfParamBoolW* cp1 =
new ConfParamBoolW(gb1, lnk1, tr("Process Beagle queue"),
new ConfParamBoolW(gb1, lnk1, tr("Steal Beagle indexing queue"),
tr("Beagle MUST NOT be running. Enables processing "
"the beagle queue to index Firefox web history.<br>"
"(you must also install the Firefox Beagle Plugin)"
"the beagle queue to index Firefox web history.<br>"
"(you should also install the Firefox Beagle plugin)"
));
ConfLink lnk2(new ConfLinkRclRep(config, "webcachedir"));
+35 -48
View File
@@ -538,14 +538,16 @@ PreviewTextEdit *Preview::addEditorTab()
return editor;
}
void Preview::setCurTabProps(const string &fn, const Rcl::Doc &doc,
int docnum)
void Preview::setCurTabProps(const Rcl::Doc &doc, int docnum)
{
QString title;
map<string,string>::const_iterator meta_it;
if ((meta_it = doc.meta.find("title")) != doc.meta.end()) {
if ((meta_it = doc.meta.find(Rcl::Doc::keytt)) != doc.meta.end()
&& !meta_it->second.empty()) {
title = QString::fromUtf8(meta_it->second.c_str(),
meta_it->second.length());
} else {
title = QString::fromLocal8Bit(path_getsimple(doc.url).c_str());
}
if (title.length() > 20) {
title = title.left(10) + "..." + title.right(10);
@@ -572,16 +574,15 @@ void Preview::setCurTabProps(const string &fn, const Rcl::Doc &doc,
PreviewTextEdit *e = currentEditor();
if (e) {
e->m_data.fn = fn;
e->m_data.url = doc.url;
e->m_data.ipath = doc.ipath;
e->m_data.docnum = docnum;
}
}
bool Preview::makeDocCurrent(const string &fn, size_t sz,
const Rcl::Doc& doc, int docnum, bool sametab)
bool Preview::makeDocCurrent(const Rcl::Doc& doc, int docnum, bool sametab)
{
LOGDEB(("Preview::makeDocCurrent: %s\n", fn.c_str()));
LOGDEB(("Preview::makeDocCurrent: %s\n", doc.url.c_str()));
/* Check if we already have this page */
for (int i = 0; i < pvTab->count(); i++) {
@@ -593,7 +594,7 @@ bool Preview::makeDocCurrent(const string &fn, size_t sz,
if (tw) {
PreviewTextEdit *edit =
dynamic_cast<PreviewTextEdit*>(tw->child("pvEdit"));
if (edit && !edit->m_data.fn.compare(fn) &&
if (edit && !edit->m_data.url.compare(doc.url) &&
!edit->m_data.ipath.compare(doc.ipath)) {
pvTab->showPage(tw);
return true;
@@ -606,7 +607,7 @@ bool Preview::makeDocCurrent(const string &fn, size_t sz,
return false;
}
m_justCreated = false;
if (!loadFileInCurrentTab(fn, sz, doc, docnum)) {
if (!loadDocInCurrentTab(doc, docnum)) {
closeCurrentTab();
return false;
}
@@ -637,16 +638,15 @@ bool Preview::makeDocCurrent(const string &fn, size_t sz,
/* A thread to to the file reading / format conversion */
class LoadThread : public QThread {
int *statusp;
Rcl::Doc *out;
Rcl::Doc& out;
const Rcl::Doc& idoc;
string filename;
string ipath;
string *mtype;
string tmpdir;
int loglevel;
public:
string missing;
LoadThread(int *stp, Rcl::Doc *odoc, string fn, string ip, string *mt)
: statusp(stp), out(odoc), filename(fn), ipath(ip), mtype(mt)
LoadThread(int *stp, Rcl::Doc& odoc, const Rcl::Doc& idc)
: statusp(stp), out(odoc), idoc(idc)
{
loglevel = DebugLog::getdbl()->getlevel();
}
@@ -666,40 +666,35 @@ class LoadThread : public QThread {
*statusp = -1;
return;
}
struct stat st;
if (stat(filename.c_str(), &st) < 0) {
LOGERR(("Preview: can't stat [%s]\n", filename.c_str()));
QMessageBox::critical(0, "Recoll",
Preview::tr("File does not exist"));
*statusp = -1;
return;
}
// QMessageBox::critical(0, "Recoll", Preview::tr("File does not exist"));
FileInterner interner(filename, &st, rclconfig, tmpdir,
FileInterner::FIF_forPreview,
mtype);
FileInterner interner(idoc, rclconfig, tmpdir,
FileInterner::FIF_forPreview);
// We don't set the interner's target mtype to html because we
// do want the html filter to do its work: we won't use the
// text, but we need the conversion to utf-8
// interner.setTargetMType("text/html");
try {
FileInterner::Status ret = interner.internfile(*out, ipath);
string ipath = idoc.ipath;
FileInterner::Status ret = interner.internfile(out, ipath);
if (ret == FileInterner::FIDone || ret == FileInterner::FIAgain) {
// FIAgain is actually not nice here. It means that the record
// for the *file* of a multidoc was selected. Actually this
// shouldn't have had a preview link at all, but we don't know
// how to handle it now. Better to show the first doc than
// a mysterious error. Happens when the file name matches a
// a search term of course.
// a search term.
*statusp = 0;
// If we prefer html and it is available, replace the
// text/plain document text
if (prefs.previewHtml && !interner.get_html().empty()) {
out->text = interner.get_html();
out->mimetype = "text/html";
out.text = interner.get_html();
out.mimetype = "text/html";
}
} else {
out->mimetype = interner.getMimetype();
out.mimetype = interner.getMimetype();
interner.getMissingExternal(missing);
*statusp = -1;
}
@@ -754,8 +749,7 @@ public:
~LoadGuard() {*m_bp = false; CancelCheck::instance().setCancel(false);}
};
bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
int docnum)
bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
{
if (m_loading) {
LOGERR(("ALready loading\n"));
@@ -767,18 +761,11 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
m_haveAnchors = false;
Rcl::Doc doc = idoc;
setCurTabProps(idoc, docnum);
if (doc.meta[Rcl::Doc::keytt].empty())
doc.meta[Rcl::Doc::keytt] = path_getsimple(doc.url);
setCurTabProps(fn, doc, docnum);
char csz[20];
sprintf(csz, "%lu", (unsigned long)sz);
QString msg = QString("Loading: %1 (size %2 bytes)")
.arg(QString::fromLocal8Bit(fn.c_str()))
.arg(csz);
.arg(QString::fromLocal8Bit(idoc.url.c_str()))
.arg(QString::fromAscii(idoc.fbytes.c_str()));
// Create progress dialog and aux objects
const int nsteps = 20;
@@ -786,12 +773,12 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
progress.setMinimumDuration(2000);
WaiterThread waiter(100);
// Load and convert file
// Load and convert document
// idoc came out of the index data (main text and other fields missing).
// foc is the complete one what we are going to extract from storage.
Rcl::Doc fdoc;
// Need to setup config to retrieve possibly local parameters
rclconfig->setKeyDir(path_getfather(fn));
int status = 1;
LoadThread lthr(&status, &fdoc, fn, doc.ipath, &doc.mimetype);
LoadThread lthr(&status, fdoc, idoc);
lthr.start();
int prog;
for (prog = 1;;prog++) {
@@ -963,7 +950,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
}
// Enter document in document history
g_dynconf->enterDoc(fn, doc.ipath);
g_dynconf->enterDoc(idoc.url, idoc.ipath);
editor->setFocus();
emit(previewExposed(this, m_searchId, docnum));
@@ -998,7 +985,7 @@ void PreviewTextEdit::toggleFields()
// Else display fields
m_dspflds = true;
QString txt = "<html><head></head><body>\n";
txt += "<b>" + QString::fromLocal8Bit(m_data.fn.c_str());
txt += "<b>" + QString::fromLocal8Bit(m_data.url.c_str());
if (!m_data.ipath.empty())
txt += "|" + QString::fromUtf8(m_data.ipath.c_str());
txt += "</b><br><br>";
+10 -7
View File
@@ -51,7 +51,7 @@ class Q3PopupMenu;
// We keep a list of data associated to each tab
class TabData {
public:
string fn; // filename for this tab
string url; // filename for this tab
string ipath; // Internal doc path inside file
int docnum; // Index of doc in db search results.
// doc out of internfile (previous fields come from the index) with
@@ -133,8 +133,13 @@ public:
virtual void closeEvent(QCloseEvent *e );
virtual bool eventFilter(QObject *target, QEvent *event );
virtual bool makeDocCurrent(const string &fn, size_t sz,
const Rcl::Doc& idoc, int docnum,
/**
* Arrange for the document to be displayed either by exposing the tab
* if already loaded, or by creating a new tab and loading it.
* @para docnum is used to link back to the result list (to highlight
* paragraph when tab exposed etc.
*/
virtual bool makeDocCurrent(const Rcl::Doc& idoc, int docnum,
bool sametab = false);
friend class PreviewTextEdit;
public slots:
@@ -182,12 +187,10 @@ private:
QCheckBox* matchCheck;
void init();
virtual void setCurTabProps(const string& fn, const Rcl::Doc& doc,
int docnum);
virtual void setCurTabProps(const Rcl::Doc& doc, int docnum);
virtual PreviewTextEdit *currentEditor();
virtual PreviewTextEdit *addEditorTab();
virtual bool loadFileInCurrentTab(string fn, size_t sz,
const Rcl::Doc& idoc, int dnm);
virtual bool loadDocInCurrentTab(const Rcl::Doc& idoc, int dnm);
};
#endif /* _PREVIEW_W_H_INCLUDED_ */
+22 -48
View File
@@ -498,12 +498,6 @@ void RclMain::toggleIndexing()
fileToggleIndexingAction->setEnabled(FALSE);
}
// Note that all our 'urls' are like : file://...
static string urltolocalpath(string url)
{
return url.substr(7, string::npos);
}
// Start a db query and set the reslist docsource
void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata)
{
@@ -688,14 +682,6 @@ void RclMain::startPreview(int docnum, int mod)
return;
}
// Check file exists in file system
string fn = urltolocalpath(doc.url);
struct stat st;
if (stat(fn.c_str(), &st) < 0) {
QMessageBox::warning(0, "Recoll", tr("Cannot access document file: ") +
fn.c_str());
return;
}
if (mod & Qt::ShiftButton) {
// User wants new preview window
curPreview = 0;
@@ -724,7 +710,7 @@ void RclMain::startPreview(int docnum, int mod)
curPreview->setCaption(resList->getDescription());
curPreview->show();
}
curPreview->makeDocCurrent(fn, st.st_size, doc, docnum);
curPreview->makeDocCurrent(doc, docnum);
}
/**
@@ -736,14 +722,6 @@ void RclMain::startPreview(int docnum, int mod)
*/
void RclMain::startPreview(Rcl::Doc doc)
{
// Check file exists in file system
string fn = urltolocalpath(doc.url);
struct stat st;
if (stat(fn.c_str(), &st) < 0) {
QMessageBox::warning(0, "Recoll", tr("Cannot access document file: ") +
fn.c_str());
return;
}
Preview *preview = new Preview(0, HiliteData());
if (preview == 0) {
QMessageBox::warning(0, tr("Warning"),
@@ -755,7 +733,7 @@ void RclMain::startPreview(Rcl::Doc doc)
connect(preview, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString)));
preview->show();
preview->makeDocCurrent(fn, st.st_size, doc, 0);
preview->makeDocCurrent(doc, 0);
}
// Show next document from result list in current preview tab
@@ -802,15 +780,7 @@ void RclMain::previewPrevOrNextInTab(Preview * w, int sid, int docnum, bool nxt)
}
// Check that file exists in file system
string fn = urltolocalpath(doc.url);
struct stat st;
if (stat(fn.c_str(), &st) < 0) {
QMessageBox::warning(0, "Recoll", tr("Cannot access document file: ") +
fn.c_str());
return;
}
w->makeDocCurrent(fn, st.st_size, doc, docnum, true);
w->makeDocCurrent(doc, docnum, true);
}
// Preview tab exposed: if the preview comes from the currently
@@ -862,7 +832,6 @@ void RclMain::saveDocToFile(int docnum)
" from database"));
return;
}
string fn = urltolocalpath(doc.url);
QString s =
QFileDialog::getSaveFileName(path_home().c_str(),
"", this,
@@ -870,8 +839,7 @@ void RclMain::saveDocToFile(int docnum)
tr("Choose a file name to save under"));
string tofile((const char *)s.local8Bit());
TempFile temp; // not used
if (!FileInterner::idocToFile(temp, tofile, rclconfig, fn,
doc.ipath, doc.mimetype)) {
if (!FileInterner::idocToFile(temp, tofile, rclconfig, doc)) {
QMessageBox::warning(0, "Recoll",
tr("Cannot extract document or create "
"temporary file"));
@@ -913,6 +881,14 @@ void RclMain::startNativeViewer(int docnum)
startNativeViewer(doc);
}
// Convert to file path if url is like file://
static string fileurltolocalpath(string url)
{
if (url.find("file://") == 0)
return url.substr(7, string::npos);
return string();
}
void RclMain::startNativeViewer(Rcl::Doc doc)
{
// Look for appropriate viewer
@@ -993,22 +969,20 @@ void RclMain::startNativeViewer(Rcl::Doc doc)
return;
}
// For files with an ipath, we do things differently depending if
// the configured command seems to be able to grok it or not: if
// not, create a temporary file
// We may need a temp file, or not depending on the command arguments
// and the fact that this is a subdoc or not.
bool wantsipath = cmd.find("%i") != string::npos;
bool wantsfile = cmd.find("%f") != string::npos;
bool istempfile = false;
string fn = urltolocalpath(doc.url);
string url;
string fn = fileurltolocalpath(doc.url);
string url = doc.url;
// If the command wants a file but this is not a file url, or
// there is an ipath that it won't understand, we need a temp file:
rclconfig->setKeyDir(path_getfather(fn));
if (doc.ipath.empty() || wantsipath) {
url = doc.url;
} else {
// There is an ipath and the command does not know about
// them. We need a temp file.
if ((wantsfile && fn.empty()) || (!wantsipath && !doc.ipath.empty())) {
TempFile temp;
if (!FileInterner::idocToFile(temp, string(), rclconfig, fn,
doc.ipath, doc.mimetype)) {
if (!FileInterner::idocToFile(temp, string(), rclconfig, doc)) {
QMessageBox::warning(0, "Recoll",
tr("Cannot extract document or create "
"temporary file"));