Fix plural word issues in status message

This commit is contained in:
Jean-Francois Dockes 2019-07-22 11:26:39 +02:00
parent c18f069c58
commit 99ee4d456c

View File

@ -55,20 +55,22 @@ void RclMain::updateIdxStatus()
} }
msg += phs + " "; msg += phs + " ";
if (status.phase == DbIxStatus::DBIXS_FILES) { if (status.phase == DbIxStatus::DBIXS_FILES) {
char cnts[100]; QString sdocs = status.docsdone > 1 ?tr("documents") : tr("document");
if (status.dbtotdocs > 0) { QString sfiles = status.filesdone > 1 ? tr("files") : tr("file");
string format = QString serrors = status.fileerrors > 1 ? tr("errors") : tr("error");
qs2utf8s(tr("(%d documents/%d files/%d errors/%d total files) ")); QString stats;
sprintf(cnts, format.c_str(), if (status.dbtotdocs > 0) {
status.docsdone, status.filesdone, status.fileerrors, stats = QString("(%1 ") + sdocs + "/%2 " + sfiles +
status.totfiles); "/%3 " + serrors + "/%4 " + tr("total files)");
stats = stats.arg(status.docsdone).arg(status.filesdone).
arg(status.fileerrors).arg(status.totfiles);
} else { } else {
string format = stats = QString("(%1 ") + sdocs + "/%2 " + sfiles +
qs2utf8s(tr("(%d documents/%d files/%d errors) ")); "/%3 " + serrors + ") ";
sprintf(cnts, format.c_str(), stats = stats.arg(status.docsdone).arg(status.filesdone).
status.docsdone, status.filesdone, status.fileerrors); arg(status.fileerrors);
} }
msg += QString::fromUtf8(cnts) + " "; msg += stats + " ";
} }
string mf;int ecnt = 0; string mf;int ecnt = 0;
string fcharset = theconfig->getDefCharset(true); string fcharset = theconfig->getDefCharset(true);
@ -95,10 +97,10 @@ void RclMain::periodic100()
} }
if (m_idxproc) { if (m_idxproc) {
// An indexing process was launched. If its' done, see status. // An indexing process was launched. If its' done, see status.
int status; int status;
bool exited = m_idxproc->maybereap(&status); bool exited = m_idxproc->maybereap(&status);
if (exited) { if (exited) {
QString reasonmsg; QString reasonmsg;
if (m_idxreasontmp && m_idxreasontmp->ok()) { if (m_idxreasontmp && m_idxreasontmp->ok()) {
string reasons; string reasons;
@ -115,8 +117,8 @@ void RclMain::periodic100()
} }
} }
} }
deleteZ(m_idxproc); deleteZ(m_idxproc);
if (status) { if (status) {
if (m_idxkilled) { if (m_idxkilled) {
QMessageBox::warning(0, "Recoll", QMessageBox::warning(0, "Recoll",
tr("Indexing interrupted")); tr("Indexing interrupted"));
@ -129,58 +131,58 @@ void RclMain::periodic100()
} }
QMessageBox::warning(0, "Recoll", msg); QMessageBox::warning(0, "Recoll", msg);
} }
} else { } else {
// On the first run, show missing helpers. We only do this once // On the first run, show missing helpers. We only do this once
if (m_firstIndexing) if (m_firstIndexing)
showMissingHelpers(); showMissingHelpers();
if (!reasonmsg.isEmpty()) { if (!reasonmsg.isEmpty()) {
QString msg = tr("Non-fatal indexing message: "); QString msg = tr("Non-fatal indexing message: ");
msg.append(reasonmsg); msg.append(reasonmsg);
QMessageBox::warning(0, "Recoll", msg); QMessageBox::warning(0, "Recoll", msg);
} }
} }
string reason; string reason;
maybeOpenDb(reason, 1); maybeOpenDb(reason, 1);
} else { } else {
// update/show status even if the status file did not // update/show status even if the status file did not
// change (else the status line goes blank during // change (else the status line goes blank during
// lengthy operations). // lengthy operations).
updateIdxStatus(); updateIdxStatus();
} }
} }
// Update the "start/stop indexing" menu entry, can't be done from // Update the "start/stop indexing" menu entry, can't be done from
// the "start/stop indexing" slot itself // the "start/stop indexing" slot itself
IndexerState prevstate = m_indexerState; IndexerState prevstate = m_indexerState;
if (m_idxproc) { if (m_idxproc) {
m_indexerState = IXST_RUNNINGMINE; m_indexerState = IXST_RUNNINGMINE;
fileToggleIndexingAction->setText(tr("Stop &Indexing")); fileToggleIndexingAction->setText(tr("Stop &Indexing"));
fileToggleIndexingAction->setEnabled(true); fileToggleIndexingAction->setEnabled(true);
fileRebuildIndexAction->setEnabled(false); fileRebuildIndexAction->setEnabled(false);
actionSpecial_Indexing->setEnabled(false); actionSpecial_Indexing->setEnabled(false);
periodictimer->setInterval(200); periodictimer->setInterval(200);
} else { } else {
Pidfile pidfile(theconfig->getPidfile()); Pidfile pidfile(theconfig->getPidfile());
pid_t pid = pidfile.open(); pid_t pid = pidfile.open();
fileBumpIndexingAction->setEnabled(false); fileBumpIndexingAction->setEnabled(false);
if (pid == getpid()) { if (pid == getpid()) {
// Locked by me // Locked by me
m_indexerState = IXST_NOTRUNNING; m_indexerState = IXST_NOTRUNNING;
fileToggleIndexingAction->setText(tr("Index locked")); fileToggleIndexingAction->setText(tr("Index locked"));
fileToggleIndexingAction->setEnabled(false); fileToggleIndexingAction->setEnabled(false);
fileRebuildIndexAction->setEnabled(false); fileRebuildIndexAction->setEnabled(false);
actionSpecial_Indexing->setEnabled(false); actionSpecial_Indexing->setEnabled(false);
periodictimer->setInterval(1000); periodictimer->setInterval(1000);
} else if (pid == 0) { } else if (pid == 0) {
m_indexerState = IXST_NOTRUNNING; m_indexerState = IXST_NOTRUNNING;
fileToggleIndexingAction->setText(tr("Update &Index")); fileToggleIndexingAction->setText(tr("Update &Index"));
fileToggleIndexingAction->setEnabled(true); fileToggleIndexingAction->setEnabled(true);
fileRebuildIndexAction->setEnabled(true); fileRebuildIndexAction->setEnabled(true);
actionSpecial_Indexing->setEnabled(true); actionSpecial_Indexing->setEnabled(true);
periodictimer->setInterval(1000); periodictimer->setInterval(1000);
} else { } else {
// Real time or externally started batch indexer running // Real time or externally started batch indexer running
m_indexerState = IXST_RUNNINGNOTMINE; m_indexerState = IXST_RUNNINGNOTMINE;
fileToggleIndexingAction->setText(tr("Stop &Indexing")); fileToggleIndexingAction->setText(tr("Stop &Indexing"));
DbIxStatus status; DbIxStatus status;
readIdxStatus(theconfig, status); readIdxStatus(theconfig, status);
if (status.hasmonitor) { if (status.hasmonitor) {
@ -188,11 +190,11 @@ void RclMain::periodic100()
// incremental pass // incremental pass
fileBumpIndexingAction->setEnabled(true); fileBumpIndexingAction->setEnabled(true);
} }
fileToggleIndexingAction->setEnabled(true); fileToggleIndexingAction->setEnabled(true);
fileRebuildIndexAction->setEnabled(false); fileRebuildIndexAction->setEnabled(false);
actionSpecial_Indexing->setEnabled(false); actionSpecial_Indexing->setEnabled(false);
periodictimer->setInterval(200); periodictimer->setInterval(200);
} }
} }
if ((prevstate == IXST_RUNNINGMINE || prevstate == IXST_RUNNINGNOTMINE) if ((prevstate == IXST_RUNNINGMINE || prevstate == IXST_RUNNINGNOTMINE)
@ -202,22 +204,22 @@ void RclMain::periodic100()
// Possibly cleanup the dead viewers // Possibly cleanup the dead viewers
for (vector<ExecCmd*>::iterator it = m_viewers.begin(); for (vector<ExecCmd*>::iterator it = m_viewers.begin();
it != m_viewers.end(); it++) { it != m_viewers.end(); it++) {
int status; int status;
if ((*it)->maybereap(&status)) { if ((*it)->maybereap(&status)) {
deleteZ(*it); deleteZ(*it);
} }
} }
vector<ExecCmd*> v; vector<ExecCmd*> v;
for (vector<ExecCmd*>::iterator it = m_viewers.begin(); for (vector<ExecCmd*>::iterator it = m_viewers.begin();
it != m_viewers.end(); it++) { it != m_viewers.end(); it++) {
if (*it) if (*it)
v.push_back(*it); v.push_back(*it);
} }
m_viewers = v; m_viewers = v;
if (recollNeedsExit) if (recollNeedsExit)
fileExit(); fileExit();
} }
bool RclMain::checkIdxPaths() bool RclMain::checkIdxPaths()
@ -246,43 +248,43 @@ void RclMain::toggleIndexing()
{ {
switch (m_indexerState) { switch (m_indexerState) {
case IXST_RUNNINGMINE: case IXST_RUNNINGMINE:
if (m_idxproc) { if (m_idxproc) {
// Indexing was in progress, request stop. Let the periodic // Indexing was in progress, request stop. Let the periodic
// routine check for the results. // routine check for the results.
if (m_idxproc->requestChildExit()) { if (m_idxproc->requestChildExit()) {
m_idxkilled = true; m_idxkilled = true;
} }
} }
break; break;
case IXST_RUNNINGNOTMINE: case IXST_RUNNINGNOTMINE:
{ {
int rep = int rep =
QMessageBox::information( QMessageBox::information(
0, tr("Warning"), 0, tr("Warning"),
tr("The current indexing process was not started from this " tr("The current indexing process was not started from this "
"interface. Click Ok to kill it " "interface. Click Ok to kill it "
"anyway, or Cancel to leave it alone"), "anyway, or Cancel to leave it alone"),
QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton); QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton);
if (rep == QMessageBox::Ok) { if (rep == QMessageBox::Ok) {
#ifdef _WIN32 #ifdef _WIN32
// No simple way to signal the process. Use the stop file // No simple way to signal the process. Use the stop file
::close(::creat(theconfig->getIdxStopFile().c_str(), 0666)); ::close(::creat(theconfig->getIdxStopFile().c_str(), 0666));
#else #else
Pidfile pidfile(theconfig->getPidfile()); Pidfile pidfile(theconfig->getPidfile());
pid_t pid = pidfile.open(); pid_t pid = pidfile.open();
if (pid > 0) if (pid > 0)
kill(pid, SIGTERM); kill(pid, SIGTERM);
#endif // !_WIN32 #endif // !_WIN32
} }
} }
break; break;
case IXST_NOTRUNNING: case IXST_NOTRUNNING:
{ {
// Could also mean that no helpers are missing, but then we // Could also mean that no helpers are missing, but then we
// won't try to show a message anyway (which is what // won't try to show a message anyway (which is what
// firstIndexing is used for) // firstIndexing is used for)
string mhd; string mhd;
m_firstIndexing = !theconfig->getMissingHelperDesc(mhd); m_firstIndexing = !theconfig->getMissingHelperDesc(mhd);
if (!checkIdxPaths()) { if (!checkIdxPaths()) {
return; return;
@ -292,8 +294,8 @@ void RclMain::toggleIndexing()
args.push_back("-R"); args.push_back("-R");
args.push_back(m_idxreasontmp->filename()); args.push_back(m_idxreasontmp->filename());
} }
m_idxproc = new ExecCmd; m_idxproc = new ExecCmd;
m_idxproc->startExec("recollindex", args, false, false); m_idxproc->startExec("recollindex", args, false, false);
} }
break; break;
case IXST_UNKNOWN: case IXST_UNKNOWN:
@ -347,21 +349,21 @@ void RclMain::rebuildIndex()
case IXST_UNKNOWN: case IXST_UNKNOWN:
case IXST_RUNNINGMINE: case IXST_RUNNINGMINE:
case IXST_RUNNINGNOTMINE: case IXST_RUNNINGNOTMINE:
return; //?? Should not have been called return; //?? Should not have been called
case IXST_NOTRUNNING: case IXST_NOTRUNNING:
{ {
if (m_idxproc) { if (m_idxproc) {
LOGERR("RclMain::rebuildIndex: current indexer exec not null\n" ); LOGERR("RclMain::rebuildIndex: current indexer exec not null\n" );
return; return;
} }
int rep = int rep =
QMessageBox::warning(0, tr("Erasing index"), QMessageBox::warning(0, tr("Erasing index"),
tr("Reset the index and start " tr("Reset the index and start "
"from scratch ?"), "from scratch ?"),
QMessageBox::Ok, QMessageBox::Ok,
QMessageBox::Cancel, QMessageBox::Cancel,
QMessageBox::NoButton); QMessageBox::NoButton);
if (rep == QMessageBox::Ok) { if (rep == QMessageBox::Ok) {
#ifdef _WIN32 #ifdef _WIN32
// Under windows, it is necessary to close the db here, // Under windows, it is necessary to close the db here,
// else Xapian won't be able to do what it wants with the // else Xapian won't be able to do what it wants with the
@ -382,24 +384,24 @@ void RclMain::rebuildIndex()
rcldb->close(); rcldb->close();
} }
#endif // _WIN32 #endif // _WIN32
// Could also mean that no helpers are missing, but then we // Could also mean that no helpers are missing, but then we
// won't try to show a message anyway (which is what // won't try to show a message anyway (which is what
// firstIndexing is used for) // firstIndexing is used for)
string mhd; string mhd;
m_firstIndexing = !theconfig->getMissingHelperDesc(mhd); m_firstIndexing = !theconfig->getMissingHelperDesc(mhd);
if (!checkIdxPaths()) { if (!checkIdxPaths()) {
return; return;
} }
vector<string> args{"-c", theconfig->getConfDir(), "-z"}; vector<string> args{"-c", theconfig->getConfDir(), "-z"};
if (m_idxreasontmp && m_idxreasontmp->ok()) { if (m_idxreasontmp && m_idxreasontmp->ok()) {
args.push_back("-R"); args.push_back("-R");
args.push_back(m_idxreasontmp->filename()); args.push_back(m_idxreasontmp->filename());
} }
m_idxproc = new ExecCmd; m_idxproc = new ExecCmd;
m_idxproc->startExec("recollindex", args, false, false); m_idxproc->startExec("recollindex", args, false, false);
} }
} }
break; break;
} }
@ -467,7 +469,7 @@ void RclMain::specialIndex()
case IXST_UNKNOWN: case IXST_UNKNOWN:
case IXST_RUNNINGMINE: case IXST_RUNNINGMINE:
case IXST_RUNNINGNOTMINE: case IXST_RUNNINGNOTMINE:
return; //?? Should not have been called return; //?? Should not have been called
case IXST_NOTRUNNING: case IXST_NOTRUNNING:
default: default:
break; break;
@ -529,28 +531,28 @@ void RclMain::specialIndex()
void RclMain::updateIdxForDocs(vector<Rcl::Doc>& docs) void RclMain::updateIdxForDocs(vector<Rcl::Doc>& docs)
{ {
if (m_idxproc) { if (m_idxproc) {
QMessageBox::warning(0, tr("Warning"), QMessageBox::warning(0, tr("Warning"),
tr("Can't update index: indexer running"), tr("Can't update index: indexer running"),
QMessageBox::Ok, QMessageBox::NoButton); QMessageBox::Ok, QMessageBox::NoButton);
return; return;
} }
vector<string> paths; vector<string> paths;
if (Rcl::docsToPaths(docs, paths)) { if (Rcl::docsToPaths(docs, paths)) {
vector<string> args{"-c", theconfig->getConfDir(), "-i",}; vector<string> args{"-c", theconfig->getConfDir(), "-i",};
if (m_idxreasontmp && m_idxreasontmp->ok()) { if (m_idxreasontmp && m_idxreasontmp->ok()) {
args.push_back("-R"); args.push_back("-R");
args.push_back(m_idxreasontmp->filename()); args.push_back(m_idxreasontmp->filename());
} }
args.insert(args.end(), paths.begin(), paths.end()); args.insert(args.end(), paths.begin(), paths.end());
m_idxproc = new ExecCmd; m_idxproc = new ExecCmd;
m_idxproc->startExec("recollindex", args, false, false); m_idxproc->startExec("recollindex", args, false, false);
// Call periodic100 to update the menu entries states // Call periodic100 to update the menu entries states
periodic100(); periodic100();
} else { } else {
QMessageBox::warning(0, tr("Warning"), QMessageBox::warning(0, tr("Warning"),
tr("Can't update index: internal error"), tr("Can't update index: internal error"),
QMessageBox::Ok, QMessageBox::NoButton); QMessageBox::Ok, QMessageBox::NoButton);
return; return;
} }
} }