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