From 8dbc32a07f36996bef698b0c7f8bbc4c44a64f73 Mon Sep 17 00:00:00 2001 From: Gres Date: Sat, 27 May 2017 13:03:17 +0300 Subject: [PATCH] Added option to ignore ssl errors. --- Settings.h | 2 ++ SettingsEditor.cpp | 2 ++ SettingsEditor.ui | 29 +++++++++++-------- WebTranslator.cpp | 14 +++++++++- WebTranslator.h | 3 ++ translations/translation_en.ts | 51 +++++++++++++++++++--------------- translations/translation_ru.ts | 51 +++++++++++++++++++--------------- 7 files changed, 94 insertions(+), 58 deletions(-) diff --git a/Settings.h b/Settings.h index 013cd70..3468989 100644 --- a/Settings.h +++ b/Settings.h @@ -30,6 +30,7 @@ namespace settings_names { //! Translation const QString translationGroup = "Translation"; const QString doTranslation = "doTranslation"; + const QString ignoreSslErrors = "ignoreSslErrors"; const QString sourceLanguage = "source_language"; const QString translationLanguage = "translation_language"; const QString translationTimeout = "translation_timeout"; @@ -67,6 +68,7 @@ namespace settings_values { //! Translation const bool doTranslation = true; + const bool ignoreSslErrors = false; const QString sourceLanguage = "auto"; const QString translationLanguage = "ru"; const int translationTimeout = 15; // secs diff --git a/SettingsEditor.cpp b/SettingsEditor.cpp index 72b75c7..fe6cb11 100644 --- a/SettingsEditor.cpp +++ b/SettingsEditor.cpp @@ -128,6 +128,7 @@ void SettingsEditor::saveSettings () const { settings.beginGroup (translationGroup); settings.setValue (doTranslation, ui->doTranslationCheck->isChecked ()); + settings.setValue (ignoreSslErrors, ui->ignoreSslCheck->isChecked ()); settings.setValue (translationDebugMode, ui->translatorDebugCheck->isChecked ()); QString trLanguage = dictionary_.translateUiToCode (ui->translateLangCombo->currentText ()); settings.setValue (translationLanguage, trLanguage); @@ -216,6 +217,7 @@ void SettingsEditor::loadSettings () { settings.beginGroup (settings_names::translationGroup); ui->doTranslationCheck->setChecked (GET (doTranslation).toBool ()); + ui->ignoreSslCheck->setChecked (GET (ignoreSslErrors).toBool ()); ui->translatorDebugCheck->setChecked (GET (translationDebugMode).toBool ()); QString trLanguage = dictionary_.translateCodeToUi (GET (translationLanguage).toString ()); ui->translateLangCombo->setCurrentText (trLanguage); diff --git a/SettingsEditor.ui b/SettingsEditor.ui index d7a1fab..064b900 100644 --- a/SettingsEditor.ui +++ b/SettingsEditor.ui @@ -378,7 +378,7 @@ - + <html><head/><body><p>Отображает окно переводчика. Следует использовать только для разработки переводчиков.</p></body></html> @@ -388,6 +388,13 @@ + + + + Игнорировать ошибки SSL + + + @@ -398,6 +405,13 @@ + + + + сек. + + + @@ -411,6 +425,9 @@ + + + @@ -421,16 +438,6 @@ - - - - - - - сек. - - - diff --git a/WebTranslator.cpp b/WebTranslator.cpp index 1a9b166..6293816 100644 --- a/WebTranslator.cpp +++ b/WebTranslator.cpp @@ -14,7 +14,8 @@ WebTranslator::WebTranslator () : QObject (), proxy_ (new WebTranslatorProxy (this)), view_ (new QWebView), - translatorHelper_ (new TranslatorHelper), isReady_ (true) { + translatorHelper_ (new TranslatorHelper), isReady_ (true), + ignoreSslErrors_ (settings_values::ignoreSslErrors){ view_->settings ()->setAttribute (QWebSettings::AutoLoadImages, false); view_->settings ()->setAttribute (QWebSettings::DeveloperExtrasEnabled, true); @@ -25,6 +26,9 @@ WebTranslator::WebTranslator () this, SLOT (addProxyToView ())); connect (view_->page ()->networkAccessManager (), SIGNAL (finished (QNetworkReply *)), this, SLOT (replyFinished (QNetworkReply *))); + connect (view_->page ()->networkAccessManager (), + SIGNAL (sslErrors (QNetworkReply *, QList)), + this, SLOT (handleSslErrors (QNetworkReply *, QList))); translationTimeout_.setSingleShot (true); connect (&translationTimeout_, SIGNAL (timeout ()), SLOT (abortTranslation ())); @@ -76,6 +80,12 @@ void WebTranslator::proxyTranslated (const QString &text) { finishTranslation (false); } +void WebTranslator::handleSslErrors (QNetworkReply *reply, const QList &) { + if (ignoreSslErrors_) { + reply->ignoreSslErrors (); + } +} + void WebTranslator::abortTranslation () { if (!tryNextTranslator ()) { emit error (tr ("Перевод отменен по таймауту.")); @@ -134,6 +144,8 @@ void WebTranslator::applySettings () { } bool debugMode = GET (translationDebugMode).toBool (); setDebugMode (debugMode); + + ignoreSslErrors_ = GET(ignoreSslErrors).toBool (); #undef GET } diff --git a/WebTranslator.h b/WebTranslator.h index 8cb60ba..bcc31a3 100644 --- a/WebTranslator.h +++ b/WebTranslator.h @@ -9,6 +9,7 @@ class QWebView; class QNetworkReply; +class QSslError; class WebTranslatorProxy; class TranslatorHelper; @@ -35,6 +36,7 @@ class WebTranslator : public QObject { void addProxyToView (); void abortTranslation (); void proxyTranslated (const QString &text); + void handleSslErrors (QNetworkReply *reply, const QList &errors); private: void translateQueued (); @@ -47,6 +49,7 @@ class WebTranslator : public QObject { TranslatorHelper *translatorHelper_; QVector queue_; bool isReady_; + bool ignoreSslErrors_; QTimer translationTimeout_; }; diff --git a/translations/translation_en.ts b/translations/translation_en.ts index f8bc7fb..cfbd843 100644 --- a/translations/translation_en.ts +++ b/translations/translation_en.ts @@ -34,7 +34,7 @@ - + Результат Result @@ -56,7 +56,7 @@ - + О программе About @@ -73,12 +73,12 @@ %1 - + Не найден подходящий язык распознавания. Failed to find selected recognition language. - + Программа для распознавания текста на экране. Создана с использованием Qt, tesseract-ocr, Google Translate. Автор: Gres (translator@gres.biz) @@ -86,7 +86,7 @@ Screen text recognition and translation program. \n Uses Qt, tesseract-ocr, Google Translate. \n Author: Gres (translator@gres.biz) \n Version: %1 from %2 %3 - + Подсказки. @@ -113,17 +113,17 @@ Key modifiers what capturing : - + Последний результат был скопирован в буфер обмена. Last result has been copied to clipboard. - + Правка Correction - + Исправьте распознанный текст Correct recognized text @@ -736,27 +736,27 @@ Key modifiers what capturing : Result - + Распознать другой язык Recognize another language - + Перевести на другой язык Translate to another language - + Скопировать в буфер Copy to clipboard - + Скопировать рисунок в буфер Copy image to clibpoard - + Исправить распознанный текст Correct recognized text @@ -846,7 +846,7 @@ Key modifiers what capturing : - + Путь к tessdata Tessdata path @@ -1001,36 +1001,41 @@ Key modifiers what capturing : + Игнорировать ошибки SSL + Ignore SSL errors + + + <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> <html><head/><body><p>Max time of translation process.</p></body></html> - + Максимальное время перевода: Max translation time: - + <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> <html><head/><body><p>Translated text language.</p></body></html> - + Язык результата: Translation language: - + Переводчики: Translators: - + сек. secs. - + <html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html> <html><head/><body><p>Sorted by priority descending.</p></body></html> @@ -1446,17 +1451,17 @@ Change dirs permissions and try again or perform manual update. WebTranslator - + Перевод отменен по таймауту. Translation timed out. - + Ошибка загрузки страницы (%1) для перевода. Page (%1) load failed. - + Нет сценариев для перевода. Измените настройки. Not found any translators. Change settings. diff --git a/translations/translation_ru.ts b/translations/translation_ru.ts index 690dc61..05cbd2c 100644 --- a/translations/translation_ru.ts +++ b/translations/translation_ru.ts @@ -34,7 +34,7 @@ - + Результат Результат @@ -56,7 +56,7 @@ - + О программе О программе @@ -73,12 +73,12 @@ %1 - + Не найден подходящий язык распознавания. Не найден подходящий язык распознавания. - + Программа для распознавания текста на экране. Создана с использованием Qt, tesseract-ocr, Google Translate. Автор: Gres (translator@gres.biz) @@ -89,7 +89,7 @@ Версия: %1 от %2 %3 - + Подсказки. @@ -116,17 +116,17 @@ - + Последний результат был скопирован в буфер обмена. Последний результат был скопирован в буфер обмена. - + Правка Правка - + Исправьте распознанный текст Исправьте распознанный текст @@ -741,27 +741,27 @@ Результат - + Распознать другой язык Распознать другой язык - + Перевести на другой язык Перевести на другой язык - + Скопировать в буфер Скопировать в буфер - + Скопировать рисунок в буфер Скопировать рисунок в буфер - + Исправить распознанный текст Исправить распознанный текст @@ -851,7 +851,7 @@ - + Путь к tessdata Путь к tessdata @@ -1006,36 +1006,41 @@ + Игнорировать ошибки SSL + Игнорировать ошибки SSL + + + <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> - + Максимальное время перевода: Максимальное время перевода: - + <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> - + Язык результата: Язык результата: - + Переводчики: Переводчики: - + сек. сек. - + <html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html> <html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html> @@ -1455,17 +1460,17 @@ WebTranslator - + Перевод отменен по таймауту. Перевод отменен по таймауту. - + Ошибка загрузки страницы (%1) для перевода. Ошибка загрузки страницы (%1) для перевода. - + Нет сценариев для перевода. Измените настройки. Нет сценариев для перевода. Измените настройки.