diff --git a/Manager.cpp b/Manager.cpp index 4ee2372..9171a69 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -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 (); diff --git a/Manager.h b/Manager.h index adcf665..c1e0f6b 100644 --- a/Manager.h +++ b/Manager.h @@ -71,6 +71,7 @@ class Manager : public QObject { //! Used threads. For proper termination. QList threads_; QString defaultTranslationLanguage_; + QString defaultOrcLanguage_; bool doTranslation_; int itemProcessingCount_; }; diff --git a/ProcessingItem.cpp b/ProcessingItem.cpp index c24de1d..396357e 100644 --- a/ProcessingItem.cpp +++ b/ProcessingItem.cpp @@ -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; } diff --git a/ProcessingItem.h b/ProcessingItem.h index d2dc272..2f603b0 100644 --- a/ProcessingItem.h +++ b/ProcessingItem.h @@ -15,7 +15,7 @@ struct ProcessingItem { Qt::KeyboardModifiers modifiers; - bool isValid () const; + bool isValid (bool checkOnlyInput = false) const; }; Q_DECLARE_METATYPE (ProcessingItem) diff --git a/Recognizer.cpp b/Recognizer.cpp index f1c0f07..ce94ace 100644 --- a/Recognizer.cpp +++ b/Recognizer.cpp @@ -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) {