From ad93c2b30133d5465e97c7a61e2dd204f95a7f1d Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 17 Jan 2008 11:15:43 +0000 Subject: [PATCH] allow stopping indexing through menu action --- src/qtgui/idxthread.cpp | 24 +++++++++++-------- src/qtgui/idxthread.h | 17 ++++++++----- src/qtgui/rclmain.ui | 4 ++-- src/qtgui/rclmain_w.cpp | 53 ++++++++++++++++++++++++++++------------- src/qtgui/rclmain_w.h | 3 ++- 5 files changed, 65 insertions(+), 36 deletions(-) diff --git a/src/qtgui/idxthread.cpp b/src/qtgui/idxthread.cpp index 10e9fc33..5b8afe49 100644 --- a/src/qtgui/idxthread.cpp +++ b/src/qtgui/idxthread.cpp @@ -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; } diff --git a/src/qtgui/idxthread.h b/src/qtgui/idxthread.h index 8b0bc418..ec290d0f 100644 --- a/src/qtgui/idxthread.h +++ b/src/qtgui/idxthread.h @@ -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 #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_ */ diff --git a/src/qtgui/rclmain.ui b/src/qtgui/rclmain.ui index 8f6b83c2..92e47b6d 100644 --- a/src/qtgui/rclmain.ui +++ b/src/qtgui/rclmain.ui @@ -76,7 +76,7 @@ MenuBar - + @@ -174,7 +174,7 @@ - fileStart_IndexingAction + fileToggleIndexingAction Update &index diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 1447ae87..dfadb384 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.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 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; } diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index 2e1ba069..52cf7ec3 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -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 sdata); virtual void setDocSequence(); virtual void previewClosed(Preview *w); @@ -133,6 +133,7 @@ private: map 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,