Show translator script errors
This commit is contained in:
parent
835714d76d
commit
9da8c516b6
@ -22,6 +22,7 @@ public:
|
|||||||
QStringList translators;
|
QStringList translators;
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
|
QStringList translatorErrors;
|
||||||
};
|
};
|
||||||
|
|
||||||
using TaskPtr = std::shared_ptr<Task>;
|
using TaskPtr = std::shared_ptr<Task>;
|
||||||
|
@ -210,7 +210,7 @@ void Translator::processQueue()
|
|||||||
std::unordered_set<Task *> busyTasks;
|
std::unordered_set<Task *> busyTasks;
|
||||||
|
|
||||||
for (auto &i : pages_) {
|
for (auto &i : pages_) {
|
||||||
if (i.second->isBusy())
|
if (i.second->checkBusy())
|
||||||
busyTasks.insert(i.second->task().get());
|
busyTasks.insert(i.second->task().get());
|
||||||
else
|
else
|
||||||
idlePages.insert(i.first);
|
idlePages.insert(i.first);
|
||||||
@ -228,7 +228,8 @@ void Translator::processQueue()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (task->translators.isEmpty()) {
|
if (task->translators.isEmpty()) {
|
||||||
task->error = tr("All translators failed");
|
task->error = tr("All translators failed (%1)")
|
||||||
|
.arg(task->translatorErrors.join(", "));
|
||||||
finishedTasks.push_back(task);
|
finishedTasks.push_back(task);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ WebPage::WebPage(Translator &translator, const QString &script,
|
|||||||
const QString &scriptName)
|
const QString &scriptName)
|
||||||
: QWebEnginePage(new QWebEngineProfile)
|
: QWebEnginePage(new QWebEngineProfile)
|
||||||
, translator_(translator)
|
, translator_(translator)
|
||||||
|
, scriptName_(scriptName)
|
||||||
, proxy_(new WebPageProxy(*this))
|
, proxy_(new WebPageProxy(*this))
|
||||||
{
|
{
|
||||||
profile()->setParent(this);
|
profile()->setParent(this);
|
||||||
@ -22,7 +23,7 @@ WebPage::WebPage(Translator &translator, const QString &script,
|
|||||||
&WebPage::authenticateProxy);
|
&WebPage::authenticateProxy);
|
||||||
|
|
||||||
scheduleWebchannelInitScript();
|
scheduleWebchannelInitScript();
|
||||||
scheduleTranslatorScript(script, scriptName);
|
scheduleTranslatorScript(script);
|
||||||
|
|
||||||
setLoadImages(false);
|
setLoadImages(false);
|
||||||
|
|
||||||
@ -62,13 +63,12 @@ if (typeof init === "function") init ();
|
|||||||
profile()->scripts()->insert(js);
|
profile()->scripts()->insert(js);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::scheduleTranslatorScript(const QString &script,
|
void WebPage::scheduleTranslatorScript(const QString &script)
|
||||||
const QString &scriptName)
|
|
||||||
{
|
{
|
||||||
QWebEngineScript js;
|
QWebEngineScript js;
|
||||||
|
|
||||||
js.setSourceCode(script);
|
js.setSourceCode(script);
|
||||||
js.setName(scriptName);
|
js.setName(scriptName_);
|
||||||
js.setWorldId(QWebEngineScript::UserWorld);
|
js.setWorldId(QWebEngineScript::UserWorld);
|
||||||
js.setInjectionPoint(QWebEngineScript::Deferred);
|
js.setInjectionPoint(QWebEngineScript::Deferred);
|
||||||
js.setRunsOnSubFrames(false);
|
js.setRunsOnSubFrames(false);
|
||||||
@ -77,6 +77,13 @@ void WebPage::scheduleTranslatorScript(const QString &script,
|
|||||||
profile()->scripts()->insert(js);
|
profile()->scripts()->insert(js);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebPage::addErrorToTask(const QString &text) const
|
||||||
|
{
|
||||||
|
if (!task_)
|
||||||
|
return;
|
||||||
|
task_->translatorErrors.append(QString("%1: %2").arg(scriptName_, text));
|
||||||
|
}
|
||||||
|
|
||||||
void WebPage::setIgnoreSslErrors(bool ignoreSslErrors)
|
void WebPage::setIgnoreSslErrors(bool ignoreSslErrors)
|
||||||
{
|
{
|
||||||
ignoreSslErrors_ = ignoreSslErrors;
|
ignoreSslErrors_ = ignoreSslErrors;
|
||||||
@ -105,14 +112,23 @@ void WebPage::start(const TaskPtr &task)
|
|||||||
proxy_->translate(task->corrected, task->sourceLanguage, langCodes->iso639_1);
|
proxy_->translate(task->corrected, task->sourceLanguage, langCodes->iso639_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebPage::isBusy() const
|
bool WebPage::checkBusy()
|
||||||
{
|
{
|
||||||
return task_ && isBusy_ && QDateTime::currentDateTime() < nextIdleTime_;
|
if (!task_ || !isBusy_)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (QDateTime::currentDateTime() < nextIdleTime_)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
addErrorToTask(tr("timed out"));
|
||||||
|
isBusy_ = false;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::setTranslated(const QString &text)
|
void WebPage::setTranslated(const QString &text)
|
||||||
{
|
{
|
||||||
if (!isBusy())
|
if (!checkBusy())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
isBusy_ = false;
|
isBusy_ = false;
|
||||||
@ -124,14 +140,12 @@ void WebPage::setTranslated(const QString &text)
|
|||||||
|
|
||||||
void WebPage::setFailed(const QString &error)
|
void WebPage::setFailed(const QString &error)
|
||||||
{
|
{
|
||||||
if (!isBusy())
|
if (!checkBusy())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
isBusy_ = false;
|
isBusy_ = false;
|
||||||
|
|
||||||
SOFT_ASSERT(task_, return )
|
addErrorToTask(error);
|
||||||
// task_->error = error;
|
|
||||||
translator_.finish(task_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskPtr WebPage::task() const
|
TaskPtr WebPage::task() const
|
||||||
|
@ -21,7 +21,7 @@ public:
|
|||||||
void start(const TaskPtr &task);
|
void start(const TaskPtr &task);
|
||||||
void setTranslated(const QString &text);
|
void setTranslated(const QString &text);
|
||||||
void setFailed(const QString &error);
|
void setFailed(const QString &error);
|
||||||
bool isBusy() const;
|
bool checkBusy();
|
||||||
TaskPtr task() const;
|
TaskPtr task() const;
|
||||||
|
|
||||||
bool isLoadImages() const;
|
bool isLoadImages() const;
|
||||||
@ -40,10 +40,11 @@ private:
|
|||||||
void authenticateProxy(const QUrl &requestUrl, QAuthenticator *authenticator,
|
void authenticateProxy(const QUrl &requestUrl, QAuthenticator *authenticator,
|
||||||
const QString &proxyHost);
|
const QString &proxyHost);
|
||||||
void scheduleWebchannelInitScript();
|
void scheduleWebchannelInitScript();
|
||||||
void scheduleTranslatorScript(const QString &script,
|
void scheduleTranslatorScript(const QString &script);
|
||||||
const QString &scriptName);
|
void addErrorToTask(const QString &text) const;
|
||||||
|
|
||||||
Translator &translator_;
|
Translator &translator_;
|
||||||
|
QString scriptName_;
|
||||||
std::unique_ptr<WebPageProxy> proxy_;
|
std::unique_ptr<WebPageProxy> proxy_;
|
||||||
TaskPtr task_;
|
TaskPtr task_;
|
||||||
bool ignoreSslErrors_{false};
|
bool ignoreSslErrors_{false};
|
||||||
|
Loading…
Reference in New Issue
Block a user