Tessdata and translators path and constant and point to default app writable location
This commit is contained in:
parent
bff2598285
commit
d7b671a73d
@ -1,6 +1,7 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -21,7 +22,6 @@ const QString qs_lastUpdateCheck = "lastUpdateCheck";
|
|||||||
const QString qs_showMessageOnStart = "showMessageOnStart";
|
const QString qs_showMessageOnStart = "showMessageOnStart";
|
||||||
|
|
||||||
const QString qs_recogntionGroup = "Recognition";
|
const QString qs_recogntionGroup = "Recognition";
|
||||||
const QString qs_tessDataPlace = "tessdata_dir";
|
|
||||||
const QString qs_ocrLanguage = "language";
|
const QString qs_ocrLanguage = "language";
|
||||||
|
|
||||||
const QString qs_correctionGroup = "Correction";
|
const QString qs_correctionGroup = "Correction";
|
||||||
@ -82,6 +82,7 @@ void cleanupOutdated(QSettings& settings)
|
|||||||
|
|
||||||
settings.beginGroup(qs_recogntionGroup);
|
settings.beginGroup(qs_recogntionGroup);
|
||||||
settings.remove("image_scale");
|
settings.remove("image_scale");
|
||||||
|
settings.remove("tessdata_dir");
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup(qs_translationGroup);
|
settings.beginGroup(qs_translationGroup);
|
||||||
@ -92,6 +93,14 @@ void cleanupOutdated(QSettings& settings)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
Settings::Settings()
|
||||||
|
{
|
||||||
|
const auto baseDataPath =
|
||||||
|
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
tessdataPath = baseDataPath + "/tessdata";
|
||||||
|
translatorsDir = baseDataPath + "/translators";
|
||||||
|
}
|
||||||
|
|
||||||
void Settings::save()
|
void Settings::save()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
@ -123,10 +132,7 @@ void Settings::save()
|
|||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup(qs_recogntionGroup);
|
settings.beginGroup(qs_recogntionGroup);
|
||||||
|
|
||||||
settings.setValue(qs_tessDataPlace, tessdataPath);
|
|
||||||
settings.setValue(qs_ocrLanguage, sourceLanguage);
|
settings.setValue(qs_ocrLanguage, sourceLanguage);
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup(qs_correctionGroup);
|
settings.beginGroup(qs_correctionGroup);
|
||||||
@ -185,10 +191,7 @@ void Settings::load()
|
|||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup(qs_recogntionGroup);
|
settings.beginGroup(qs_recogntionGroup);
|
||||||
|
|
||||||
tessdataPath = settings.value(qs_tessDataPlace, tessdataPath).toString();
|
|
||||||
sourceLanguage = settings.value(qs_ocrLanguage, sourceLanguage).toString();
|
sourceLanguage = settings.value(qs_ocrLanguage, sourceLanguage).toString();
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup(qs_correctionGroup);
|
settings.beginGroup(qs_correctionGroup);
|
||||||
|
@ -21,6 +21,8 @@ enum class AutoUpdate { Disabled, Daily, Weekly, Monthly };
|
|||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Settings();
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ public:
|
|||||||
|
|
||||||
bool debugMode{false};
|
bool debugMode{false};
|
||||||
|
|
||||||
QString tessdataPath{"tessdata"};
|
QString tessdataPath;
|
||||||
QString sourceLanguage{"eng"};
|
QString sourceLanguage{"eng"};
|
||||||
LanguageIds availableOcrLanguages_;
|
LanguageIds availableOcrLanguages_;
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ public:
|
|||||||
bool forceRotateTranslators{false};
|
bool forceRotateTranslators{false};
|
||||||
LanguageId targetLanguage{"rus"};
|
LanguageId targetLanguage{"rus"};
|
||||||
std::chrono::seconds translationTimeout{15};
|
std::chrono::seconds translationTimeout{15};
|
||||||
QString translatorsDir{"translators"};
|
QString translatorsDir;
|
||||||
QStringList translators{"google.js"};
|
QStringList translators{"google.js"};
|
||||||
|
|
||||||
ResultMode resultShowType{ResultMode::Widget}; // dialog
|
ResultMode resultShowType{ResultMode::Widget}; // dialog
|
||||||
|
@ -42,12 +42,6 @@ SettingsEditor::SettingsEditor(update::Loader &updater)
|
|||||||
ui->proxyPassEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
ui->proxyPassEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// recognition
|
|
||||||
connect(ui->tessdataButton, &QPushButton::clicked, //
|
|
||||||
this, &SettingsEditor::openTessdataDialog);
|
|
||||||
connect(ui->tessdataEdit, &QLineEdit::textChanged, //
|
|
||||||
this, &SettingsEditor::updateTesseractLanguages);
|
|
||||||
|
|
||||||
// correction
|
// correction
|
||||||
|
|
||||||
ui->userSubstitutionsTable->setEnabled(ui->useUserSubstitutions->isChecked());
|
ui->userSubstitutionsTable->setEnabled(ui->useUserSubstitutions->isChecked());
|
||||||
@ -110,7 +104,6 @@ Settings SettingsEditor::settings() const
|
|||||||
settings.proxySavePassword = ui->proxySaveCheck->isChecked();
|
settings.proxySavePassword = ui->proxySaveCheck->isChecked();
|
||||||
|
|
||||||
LanguageCodes langs;
|
LanguageCodes langs;
|
||||||
settings.tessdataPath = ui->tessdataEdit->text();
|
|
||||||
if (auto lang = langs.findByName(ui->tesseractLangCombo->currentText()))
|
if (auto lang = langs.findByName(ui->tesseractLangCombo->currentText()))
|
||||||
settings.sourceLanguage = lang->id;
|
settings.sourceLanguage = lang->id;
|
||||||
|
|
||||||
@ -154,7 +147,8 @@ void SettingsEditor::setSettings(const Settings &settings)
|
|||||||
ui->proxySaveCheck->setChecked(settings.proxySavePassword);
|
ui->proxySaveCheck->setChecked(settings.proxySavePassword);
|
||||||
|
|
||||||
LanguageCodes langs;
|
LanguageCodes langs;
|
||||||
ui->tessdataEdit->setText(settings.tessdataPath);
|
ui->tessdataPath->setText(settings.tessdataPath);
|
||||||
|
updateTesseractLanguages();
|
||||||
if (auto lang = langs.findById(settings.sourceLanguage))
|
if (auto lang = langs.findById(settings.sourceLanguage))
|
||||||
ui->tesseractLangCombo->setCurrentText(lang->name);
|
ui->tesseractLangCombo->setCurrentText(lang->name);
|
||||||
|
|
||||||
@ -165,7 +159,7 @@ void SettingsEditor::setSettings(const Settings &settings)
|
|||||||
ui->ignoreSslCheck->setChecked(settings.ignoreSslErrors);
|
ui->ignoreSslCheck->setChecked(settings.ignoreSslErrors);
|
||||||
ui->translatorDebugCheck->setChecked(settings.debugMode);
|
ui->translatorDebugCheck->setChecked(settings.debugMode);
|
||||||
ui->translateTimeoutSpin->setValue(settings.translationTimeout.count());
|
ui->translateTimeoutSpin->setValue(settings.translationTimeout.count());
|
||||||
translatorsPath_ = settings.translatorsDir;
|
ui->translatorsPath->setText(settings.translatorsDir);
|
||||||
enabledTranslators_ = settings.translators;
|
enabledTranslators_ = settings.translators;
|
||||||
updateTranslators();
|
updateTranslators();
|
||||||
if (auto lang = langs.findById(settings.targetLanguage))
|
if (auto lang = langs.findById(settings.targetLanguage))
|
||||||
@ -180,22 +174,11 @@ void SettingsEditor::updateCurrentPage()
|
|||||||
ui->pagesView->setCurrentIndex(ui->pagesList->currentIndex().row());
|
ui->pagesView->setCurrentIndex(ui->pagesList->currentIndex().row());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsEditor::openTessdataDialog()
|
|
||||||
{
|
|
||||||
const auto path =
|
|
||||||
QFileDialog::getExistingDirectory(this, tr("Path to tessdata"));
|
|
||||||
|
|
||||||
if (path.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
ui->tessdataEdit->setText(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsEditor::updateTesseractLanguages()
|
void SettingsEditor::updateTesseractLanguages()
|
||||||
{
|
{
|
||||||
ui->tesseractLangCombo->clear();
|
ui->tesseractLangCombo->clear();
|
||||||
|
|
||||||
const auto path = ui->tessdataEdit->text();
|
const auto path = ui->tessdataPath->text();
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -224,7 +207,11 @@ void SettingsEditor::updateTranslators()
|
|||||||
{
|
{
|
||||||
ui->translatorList->clear();
|
ui->translatorList->clear();
|
||||||
|
|
||||||
QDir dir(translatorsPath_);
|
const auto path = ui->translatorsPath->text();
|
||||||
|
if (path.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QDir dir(path);
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCurrentPage();
|
void updateCurrentPage();
|
||||||
void openTessdataDialog();
|
|
||||||
void updateTesseractLanguages();
|
void updateTesseractLanguages();
|
||||||
void updateTranslators();
|
void updateTranslators();
|
||||||
void updateTranslationLanguages();
|
void updateTranslationLanguages();
|
||||||
@ -30,6 +29,5 @@ private:
|
|||||||
|
|
||||||
Ui::SettingsEditor *ui;
|
Ui::SettingsEditor *ui;
|
||||||
update::Loader &updater_;
|
update::Loader &updater_;
|
||||||
QString translatorsPath_;
|
|
||||||
QStringList enabledTranslators_;
|
QStringList enabledTranslators_;
|
||||||
};
|
};
|
||||||
|
@ -210,57 +210,59 @@
|
|||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p>Заполняется на основании содержания tessdata</p></body></html></string>
|
<string><html><head/><body><p>Заполняется на основании содержания tessdata</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Language</string>
|
<string>Default language:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
<property name="buddy">
|
||||||
<cstring>tesseractLangCombo</cstring>
|
<cstring>tesseractLangCombo</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="3">
|
<item row="0" column="0">
|
||||||
<widget class="QToolButton" name="tessdataButton">
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>...</string>
|
<string>Tessdata path:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="2">
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>17</width>
|
||||||
<height>40</height>
|
<height>410</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="1" column="2">
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Path to tessdata</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>tessdataEdit</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" colspan="2">
|
|
||||||
<widget class="QLineEdit" name="tessdataEdit">
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>Enter path</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" colspan="3">
|
|
||||||
<widget class="QComboBox" name="tesseractLangCombo"/>
|
<widget class="QComboBox" name="tesseractLangCombo"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QLineEdit" name="tessdataPath">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="pageCorrect">
|
<widget class="QWidget" name="pageCorrect">
|
||||||
@ -299,16 +301,6 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="pageTranslate">
|
<widget class="QWidget" name="pageTranslate">
|
||||||
<layout class="QGridLayout" name="gridLayout_9">
|
<layout class="QGridLayout" name="gridLayout_9">
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QCheckBox" name="translatorDebugCheck">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string><html><head/><body><p>Отображает окно переводчика. Следует использовать только для разработки переводчиков.</p></body></html></string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Debug mode</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QSpinBox" name="translateTimeoutSpin">
|
<widget class="QSpinBox" name="translateTimeoutSpin">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
@ -316,6 +308,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="doTranslationCheck">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><html><head/><body><p>Необходимо ли переводить (вкл) распознанный текст.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Translate text</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="ignoreSslCheck">
|
<widget class="QCheckBox" name="ignoreSslCheck">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -323,30 +325,27 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0" colspan="3">
|
<item row="3" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="label_10">
|
<widget class="QLabel" name="label_9">
|
||||||
<property name="text">
|
|
||||||
<string>Translators</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QLabel" name="label_6">
|
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html></string>
|
<string><html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Language:</string>
|
<string>Single translator timeout:</string>
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>translateLangCombo</cstring>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0" colspan="3">
|
<item row="0" column="0">
|
||||||
|
<widget class="QCheckBox" name="translatorDebugCheck">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><html><head/><body><p>Отображает окно переводчика. Следует использовать только для разработки переводчиков.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Debug mode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="0" colspan="3">
|
||||||
<widget class="QListWidget" name="translatorList">
|
<widget class="QListWidget" name="translatorList">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html></string>
|
<string><html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html></string>
|
||||||
@ -362,26 +361,43 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="5" column="0">
|
||||||
<widget class="QCheckBox" name="doTranslationCheck">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p>Необходимо ли переводить (вкл) распознанный текст.</p></body></html></string>
|
<string><html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Translate text</string>
|
<string>Language:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>translateLangCombo</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1" colspan="2">
|
||||||
|
<widget class="QComboBox" name="translateLangCombo"/>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0" colspan="3">
|
||||||
|
<widget class="QLabel" name="label_10">
|
||||||
|
<property name="text">
|
||||||
|
<string>Translators</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Translators path:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1" colspan="2">
|
<item row="4" column="1" colspan="2">
|
||||||
<widget class="QComboBox" name="translateLangCombo"/>
|
<widget class="QLineEdit" name="translatorsPath">
|
||||||
</item>
|
<property name="readOnly">
|
||||||
<item row="3" column="0" colspan="2">
|
<bool>true</bool>
|
||||||
<widget class="QLabel" name="label_9">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string><html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html></string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Single translator timeout:</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user