allow stopping indexing through menu action
This commit is contained in:
parent
b94128c067
commit
ad93c2b301
@ -27,6 +27,12 @@
|
||||
#include "smallut.h"
|
||||
#include "rclinit.h"
|
||||
|
||||
int stopindexing;
|
||||
int startindexing;
|
||||
IdxThreadStatus indexingstatus = IDXTS_OK;
|
||||
string indexingReason;
|
||||
static int stopidxthread;
|
||||
|
||||
static QMutex curfile_mutex;
|
||||
|
||||
class IdxThread : public QThread , public DbIxStatusUpdater {
|
||||
@ -38,22 +44,17 @@ class IdxThread : public QThread , public DbIxStatusUpdater {
|
||||
LOGDEB1(("IdxThread::update: indexing %s\n", m_statusSnap.fn.c_str()));
|
||||
if (stopindexing) {
|
||||
stopindexing = 0;
|
||||
m_interrupted = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Maintain a copy/snapshot of idx status
|
||||
DbIxStatus m_statusSnap;
|
||||
bool m_interrupted;
|
||||
const RclConfig *cnf;
|
||||
};
|
||||
|
||||
int stopindexing;
|
||||
int startindexing;
|
||||
int indexingdone = 1;
|
||||
IdxThreadStatus indexingstatus = IDXTS_NULL;
|
||||
string indexingReason;
|
||||
static int stopidxthread;
|
||||
|
||||
void IdxThread::run()
|
||||
{
|
||||
recoll_threadinit();
|
||||
@ -63,7 +64,7 @@ void IdxThread::run()
|
||||
}
|
||||
if (startindexing) {
|
||||
startindexing = 0;
|
||||
indexingdone = 0;
|
||||
m_interrupted = false;
|
||||
indexingstatus = IDXTS_NULL;
|
||||
// We have to make a copy of the config (setKeydir changes
|
||||
// it during indexation)
|
||||
@ -80,7 +81,6 @@ void IdxThread::run()
|
||||
indexingstatus = IDXTS_ERROR;
|
||||
indexingReason = "Indexing failed: " + indexer->getReason();
|
||||
}
|
||||
indexingdone = 1;
|
||||
delete indexer;
|
||||
}
|
||||
msleep(100);
|
||||
@ -105,5 +105,9 @@ void stop_idxthread()
|
||||
DbIxStatus idxthread_idxStatus()
|
||||
{
|
||||
QMutexLocker locker(&curfile_mutex);
|
||||
return(idxthread.m_statusSnap);
|
||||
return idxthread.m_statusSnap;
|
||||
}
|
||||
bool idxthread_idxInterrupted()
|
||||
{
|
||||
return idxthread.m_interrupted;
|
||||
}
|
||||
|
||||
@ -16,23 +16,28 @@
|
||||
*/
|
||||
#ifndef _IDXTHREAD_H_INCLUDED_
|
||||
#define _IDXTHREAD_H_INCLUDED_
|
||||
/* @(#$Id: idxthread.h,v 1.6 2006-04-12 10:41:39 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: idxthread.h,v 1.7 2008-01-17 11:15:43 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include "indexer.h"
|
||||
|
||||
class RclConfig;
|
||||
|
||||
// These two deal with starting / stopping the thread itself, not indexing
|
||||
// sessions.
|
||||
// These two deal with starting / stopping the thread itself, not
|
||||
// indexing sessions.
|
||||
extern void start_idxthread(const RclConfig& cnf);
|
||||
extern void stop_idxthread();
|
||||
extern DbIxStatus idxthread_idxStatus();
|
||||
|
||||
// Set these to to request action
|
||||
extern int stopindexing;
|
||||
extern int startindexing;
|
||||
extern int indexingdone;
|
||||
|
||||
// indexingstatus is NULL iff indexing is currently in progress.
|
||||
enum IdxThreadStatus {IDXTS_NULL = 0, IDXTS_OK = 1, IDXTS_ERROR = 2};
|
||||
extern IdxThreadStatus indexingstatus;
|
||||
// Final indexing status message
|
||||
extern string indexingReason;
|
||||
|
||||
// Current status of running indexing (phase, file name etc.)
|
||||
extern DbIxStatus idxthread_idxStatus();
|
||||
// Did last op fail because of stop request ?
|
||||
extern bool idxthread_idxInterrupted();
|
||||
#endif /* _IDXTHREAD_H_INCLUDED_ */
|
||||
|
||||
@ -76,7 +76,7 @@
|
||||
<cstring>MenuBar</cstring>
|
||||
</property>
|
||||
<item text="&File" name="fileMenu">
|
||||
<action name="fileStart_IndexingAction"/>
|
||||
<action name="fileToggleIndexingAction"/>
|
||||
<separator/>
|
||||
<action name="fileEraseDocHistoryAction"/>
|
||||
<separator/>
|
||||
@ -174,7 +174,7 @@
|
||||
</action>
|
||||
<action>
|
||||
<property name="name">
|
||||
<cstring>fileStart_IndexingAction</cstring>
|
||||
<cstring>fileToggleIndexingAction</cstring>
|
||||
</property>
|
||||
<property name="menuText">
|
||||
<string>Update &index</string>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.46 2007-12-04 10:17:14 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.47 2008-01-17 11:15:43 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -103,6 +103,8 @@ void RclMain::init()
|
||||
indexConfig = 0;
|
||||
spellform = 0;
|
||||
m_searchId = 0;
|
||||
m_idxStatusAck = false;
|
||||
|
||||
// Set the focus to the search terms entry:
|
||||
sSearch->queryText->setFocus();
|
||||
|
||||
@ -180,8 +182,8 @@ void RclMain::init()
|
||||
this, SLOT(startPreview(Rcl::Doc)));
|
||||
|
||||
connect(fileExitAction, SIGNAL(activated() ), this, SLOT(fileExit() ) );
|
||||
connect(fileStart_IndexingAction, SIGNAL(activated()),
|
||||
this, SLOT(startIndexing()));
|
||||
connect(fileToggleIndexingAction, SIGNAL(activated()),
|
||||
this, SLOT(toggleIndexing()));
|
||||
connect(fileEraseDocHistoryAction, SIGNAL(activated()),
|
||||
this, SLOT(eraseDocHistory()));
|
||||
connect(helpAbout_RecollAction, SIGNAL(activated()),
|
||||
@ -336,18 +338,29 @@ void RclMain::periodic100()
|
||||
static int toggle = 0;
|
||||
// Check if indexing thread done
|
||||
if (indexingstatus != IDXTS_NULL) {
|
||||
// Indexing is stopped
|
||||
statusBar()->message("");
|
||||
if (indexingstatus != IDXTS_OK) {
|
||||
indexingstatus = IDXTS_NULL;
|
||||
QMessageBox::warning(0, "Recoll",
|
||||
QString::fromAscii(indexingReason.c_str()));
|
||||
fileToggleIndexingAction->setText(tr("Update &Index"));
|
||||
fileToggleIndexingAction->setEnabled(TRUE);
|
||||
if (m_idxStatusAck == false) {
|
||||
m_idxStatusAck = true;
|
||||
if (indexingstatus != IDXTS_OK) {
|
||||
if (idxthread_idxInterrupted()) {
|
||||
QMessageBox::warning(0, "Recoll",
|
||||
tr("Indexing interrupted"));
|
||||
} else {
|
||||
QMessageBox::warning(0, "Recoll",
|
||||
QString::fromAscii(indexingReason.c_str()));
|
||||
}
|
||||
}
|
||||
// Make sure we reopen the db to get the results.
|
||||
rcldb->close();
|
||||
}
|
||||
indexingstatus = IDXTS_NULL;
|
||||
fileStart_IndexingAction->setEnabled(TRUE);
|
||||
// Make sure we reopen the db to get the results.
|
||||
LOGINFO(("Indexing done: closing query database\n"));
|
||||
rcldb->close();
|
||||
} else if (indexingdone == 0) {
|
||||
} else {
|
||||
// Indexing is running
|
||||
m_idxStatusAck = false;
|
||||
fileToggleIndexingAction->setText(tr("Stop &Indexing"));
|
||||
// The toggle thing is for the status to flash
|
||||
if (toggle == 0) {
|
||||
QString msg = tr("Indexing in progress: ");
|
||||
DbIxStatus status = idxthread_idxStatus();
|
||||
@ -385,11 +398,17 @@ void RclMain::periodic100()
|
||||
fileExit();
|
||||
}
|
||||
|
||||
void RclMain::startIndexing()
|
||||
void RclMain::toggleIndexing()
|
||||
{
|
||||
if (indexingdone)
|
||||
if (indexingstatus == IDXTS_NULL) {
|
||||
// Indexing in progress
|
||||
stopindexing = 1;
|
||||
fileToggleIndexingAction->setText(tr("Update &Index"));
|
||||
} else {
|
||||
startindexing = 1;
|
||||
fileStart_IndexingAction->setEnabled(FALSE);
|
||||
fileToggleIndexingAction->setText(tr("Stop &Indexing"));
|
||||
}
|
||||
fileToggleIndexingAction->setEnabled(FALSE);
|
||||
}
|
||||
|
||||
// Note that all our 'urls' are like : file://...
|
||||
@ -405,7 +424,7 @@ void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata)
|
||||
// The db may have been closed at the end of indexing
|
||||
string reason;
|
||||
// If indexing is being performed, we reopen the db at each query.
|
||||
if (!maybeOpenDb(reason, indexingdone == 0)) {
|
||||
if (!maybeOpenDb(reason, indexingstatus == IDXTS_NULL)) {
|
||||
QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ public slots:
|
||||
virtual bool close();
|
||||
virtual void fileExit();
|
||||
virtual void periodic100();
|
||||
virtual void startIndexing();
|
||||
virtual void toggleIndexing();
|
||||
virtual void startSearch(RefCntr<Rcl::SearchData> sdata);
|
||||
virtual void setDocSequence();
|
||||
virtual void previewClosed(Preview *w);
|
||||
@ -133,6 +133,7 @@ private:
|
||||
map<QString, int> m_stemLangToId;
|
||||
int m_idNoStem;
|
||||
int m_idAllStem;
|
||||
bool m_idxStatusAck; // Did we act on last status?
|
||||
|
||||
virtual void init();
|
||||
virtual void previewPrevOrNextInTab(Preview *, int sid, int docnum,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user