Manager now sets ocrLanguage instead of recognizer. Last one checks input item for validity.

This commit is contained in:
Gres 2015-10-10 21:04:28 +03:00
parent c1dab33e7c
commit a57e0b1af8
5 changed files with 22 additions and 6 deletions

View File

@ -170,6 +170,10 @@ void Manager::applySettings () {
QNetworkProxy::setApplicationProxy (proxy);
settings.endGroup ();
settings.beginGroup (settings_names::recogntionGroup);
defaultOrcLanguage_ = GET (ocrLanguage).toString ();
settings.endGroup ();
settings.beginGroup (settings_names::translationGroup);
defaultTranslationLanguage_ = GET (translationLanguage).toString ();
doTranslation_ = GET (doTranslation).toBool ();
@ -215,6 +219,12 @@ void Manager::handleSelection (ProcessingItem item) {
if ((doTranslation_ && !altMod) || (!doTranslation_ && altMod)) {
item.translateLanguage = defaultTranslationLanguage_;
}
if (item.ocrLanguage.isEmpty ()) {
item.ocrLanguage = defaultOrcLanguage_;
}
if (item.sourceLanguage.isEmpty ()) {
item.sourceLanguage = dictionary_->ocrToTranslateCodes (item.ocrLanguage);
}
emit requestRecognize (item);
++itemProcessingCount_;
updateNormalIcon ();

View File

@ -71,6 +71,7 @@ class Manager : public QObject {
//! Used threads. For proper termination.
QList<QThread *> threads_;
QString defaultTranslationLanguage_;
QString defaultOrcLanguage_;
bool doTranslation_;
int itemProcessingCount_;
};

View File

@ -1,9 +1,12 @@
#include "ProcessingItem.h"
bool ProcessingItem::isValid () const {
bool ProcessingItem::isValid (bool checkOnlyInput) const {
bool valid = true;
valid &= (!screenPos.isNull ());
valid &= (!source.isNull ());
valid &= (!recognized.isEmpty ());
valid &= (!ocrLanguage.isEmpty ());
if (!checkOnlyInput) {
valid &= (!recognized.isEmpty ());
}
return valid;
}

View File

@ -15,7 +15,7 @@ struct ProcessingItem {
Qt::KeyboardModifiers modifiers;
bool isValid () const;
bool isValid (bool checkOnlyInput = false) const;
};
Q_DECLARE_METATYPE (ProcessingItem)

View File

@ -56,9 +56,11 @@ bool Recognizer::initEngine (tesseract::TessBaseAPI * &engine, const QString &la
}
void Recognizer::recognize (ProcessingItem item) {
ST_ASSERT (!item.source.isNull ());
bool isCustomLanguage = (!item.ocrLanguage.isEmpty () &&
item.ocrLanguage != ocrLanguage_);
if (!item.isValid (true)) {
emit recognized (item);
return;
}
bool isCustomLanguage = (item.ocrLanguage != ocrLanguage_);
tesseract::TessBaseAPI *engine = (isCustomLanguage) ? NULL : engine_;
QString language = (isCustomLanguage) ? item.ocrLanguage : ocrLanguage_;
if (engine == NULL) {