From e2e22f8bf0f7990c104ef7f577114c705995322b Mon Sep 17 00:00:00 2001 From: Ja'Virr-Dar Date: Tue, 12 Oct 2021 23:19:42 +0800 Subject: [PATCH] Make setEngineUrl method required for LibreTranslate and Lingva to work --- src/qonlinetranslator.cpp | 10 ++++++++++ src/qonlinetranslator.h | 11 +++++------ 2 files changed, 15 insertions(+), 6 deletions(-) mode change 100755 => 100644 src/qonlinetranslator.cpp diff --git a/src/qonlinetranslator.cpp b/src/qonlinetranslator.cpp old mode 100755 new mode 100644 index 3c07fa5..760e06d --- a/src/qonlinetranslator.cpp +++ b/src/qonlinetranslator.cpp @@ -1890,6 +1890,11 @@ void QOnlineTranslator::buildLibreStateMachine() void QOnlineTranslator::buildLibreDetectStateMachine() { + Q_ASSERT_X( + !m_libreUrl.isEmpty(), + "buildLibreDetectStateMachine", + "The engine requires a URL, but it was not specified"); + // States auto *detectState = new QState(m_stateMachine); auto *finalState = new QFinalState(m_stateMachine); @@ -1918,6 +1923,11 @@ void QOnlineTranslator::buildLingvaStateMachine() void QOnlineTranslator::buildLingvaDetectStateMachine() { + Q_ASSERT_X( + !m_lingvaUrl.isEmpty(), + "buildLingvaDetectStateMachine", + "The engine requires a URL, but it was not specified"); + // States auto *detectState = new QState(m_stateMachine); auto *finalState = new QFinalState(m_stateMachine); diff --git a/src/qonlinetranslator.h b/src/qonlinetranslator.h index b2719f6..a3b5c52 100755 --- a/src/qonlinetranslator.h +++ b/src/qonlinetranslator.h @@ -430,7 +430,8 @@ class QOnlineTranslator : public QObject /** * @brief Set the URL engine * - * Affects only LibreTranslate and Lingva. + * Only affects LibreTranslate and Lingva because these engines have multiple instances. + * You need to call this function to specify the URL of an instance for them. * * @param engine engine * @param url engine url @@ -622,11 +623,9 @@ private slots: QString m_errorString; // Self-hosted engines settings - // LibreTranslate - QByteArray m_libreApiKey; // Doesn't require key for free instance - QString m_libreUrl = QStringLiteral("https://translate.argosopentech.com"); // One of the free instance - // Lingva - QString m_lingvaUrl = QStringLiteral("https://lingva.ml"); + QByteArray m_libreApiKey; // Can be empty, since free instances ignores api_key param + QString m_libreUrl; + QString m_lingvaUrl; QMap> m_translationOptions; QMap> m_examples;