make indexation more easily cancellable

This commit is contained in:
dockes
2006-04-04 13:49:55 +00:00
parent e9d722e25c
commit 962f6f1012
6 changed files with 75 additions and 27 deletions
+20 -7
View File
@@ -30,20 +30,26 @@ static QMutex curfile_mutex;
class IdxThread : public QThread , public DbIxStatusUpdater {
virtual void run();
public:
virtual void update(const string &fn) {
virtual bool update(const string &fn) {
QMutexLocker locker(&curfile_mutex);
m_curfile = fn;
LOGDEB(("IdxThread::update: indexing %s\n", m_curfile.c_str()));
LOGDEB1(("IdxThread::update: indexing %s\n", m_curfile.c_str()));
if (stopindexing) {
stopindexing = 0;
return false;
}
return true;
}
ConfIndexer *indexer;
string m_curfile;
int loglevel;
};
int stopindexing;
int startindexing;
int indexingdone = 1;
bool indexingstatus = false;
IdxThreadStatus indexingstatus = IDXTS_NULL;
string indexingReason;
static int stopidxthread;
void IdxThread::run()
@@ -55,10 +61,16 @@ void IdxThread::run()
return;
}
if (startindexing) {
indexingdone = indexingstatus = 0;
fprintf(stderr, "Index thread :start index\n");
indexingstatus = indexer->index();
startindexing = 0;
indexingdone = 0;
indexingstatus = IDXTS_NULL;
if (indexer->index()) {
indexingstatus = IDXTS_OK;
indexingReason = "";
} else {
indexingstatus = IDXTS_ERROR;
indexingReason = "Indexation failed: " + indexer->getReason();
}
indexingdone = 1;
}
msleep(100);
@@ -80,6 +92,7 @@ void start_idxthread(const RclConfig& cnf)
void stop_idxthread()
{
stopindexing = 1;
stopidxthread = 1;
idxthread.wait();
}
+5 -2
View File
@@ -16,7 +16,7 @@
*/
#ifndef _IDXTHREAD_H_INCLUDED_
#define _IDXTHREAD_H_INCLUDED_
/* @(#$Id: idxthread.h,v 1.4 2006-03-22 16:24:41 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: idxthread.h,v 1.5 2006-04-04 13:49:55 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
class RclConfig;
@@ -27,8 +27,11 @@ extern void start_idxthread(const RclConfig& cnf);
extern void stop_idxthread();
extern std::string idxthread_currentfile();
extern int stopindexing;
extern int startindexing;
extern int indexingdone;
extern bool indexingstatus;
enum IdxThreadStatus {IDXTS_NULL = 0, IDXTS_OK = 1, IDXTS_ERROR = 2};
extern IdxThreadStatus indexingstatus;
extern string indexingReason;
#endif /* _IDXTHREAD_H_INCLUDED_ */
+9 -4
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.18 2006-04-04 07:55:29 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.19 2006-04-04 13:49:55 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -211,9 +211,14 @@ void RclMain::periodic100()
{
static int toggle = 0;
// Check if indexing thread done
if (indexingstatus) {
if (indexingstatus != IDXTS_NULL) {
statusBar()->message("");
indexingstatus = false;
if (indexingstatus != IDXTS_OK) {
indexingstatus = IDXTS_NULL;
QMessageBox::warning(0, "Recoll",
QString::fromAscii(indexingReason.c_str()));
}
indexingstatus = IDXTS_NULL;
// Make sure we reopen the db to get the results.
LOGINFO(("Indexing done: closing query database\n"));
rcldb->close();
@@ -240,7 +245,7 @@ void RclMain::periodic100()
void RclMain::fileStart_IndexingAction_activated()
{
if (indexingdone == 1)
if (indexingdone)
startindexing = 1;
}