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