Compare commits

..

7 Commits
qt6 ... master

Author SHA1 Message Date
dependabot[bot]
6efc473859
Bump actions/download-artifact from 1 to 4.1.7 in /.github/workflows (#191)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 1 to 4.1.7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v1...v4.1.7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-06 10:51:26 +03:00
Gres
e1ec86f298 Update deepl translation 2023-09-02 21:09:27 +03:00
Gres
29ee5dda90 Update deepl translation 2023-05-19 23:30:44 +03:00
Gres
b8cd2dff54 Update project state 2023-05-05 21:50:57 +03:00
Gres
fb3f32f050 Update deepl translation 2023-04-08 22:09:35 +03:00
Gres
41f1f56fe5 Update deepl translation 2023-02-12 14:17:17 +03:00
Gres
5be5def820 Update deepl translation 2023-02-06 23:40:07 +03:00
20 changed files with 79 additions and 85 deletions

View File

@ -78,7 +78,7 @@ jobs:
- name: Download release url
if: contains(github.ref, '/tags/')
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4.1.7
with:
name: release_upload_url
path: ./

View File

@ -1,5 +1,7 @@
# Screen Translator
**The project is almost abandoned. I don't have time for it and I can only fix minor issues**
## Introduction
This software allows you to translate any text on screen.

View File

@ -14,7 +14,7 @@ win32{
LIBS += -lUser32
}
linux{
# QT += x11extras
QT += x11extras
LIBS += -lX11
}

View File

@ -7,7 +7,7 @@
#include <QDir>
#include <QRegularExpression>
#include <QStringConverter>
#include <QTextCodec>
static int levenshteinDistance(const QString &source, const QString &target)
{
@ -106,21 +106,19 @@ QString HunspellCorrector::correct(const QString &original)
{
SOFT_ASSERT(engine_, return original);
const auto encoding =
QStringConverter::encodingForName(engine_->get_dict_encoding().c_str());
SOFT_ASSERT(encoding, return original);
auto codec = QStringEncoder(*encoding);
const auto codec =
QTextCodec::codecForName(engine_->get_dict_encoding().c_str());
SOFT_ASSERT(codec, return original);
QString result;
QString word;
QString separator;
for (auto i = 0ll, end = original.size(); i < end; ++i) {
for (auto i = 0, end = original.size(); i < end; ++i) {
const auto ch = original[i];
if (ch.isPunct() || ch.isSpace()) {
if (!word.isEmpty()) {
correctWord(word, codec);
correctWord(word, *codec);
result += word;
word.clear();
}
@ -141,7 +139,7 @@ QString HunspellCorrector::correct(const QString &original)
}
if (!word.isEmpty()) {
correctWord(word, codec);
correctWord(word, *codec);
result += word;
}
result += separator;
@ -149,12 +147,12 @@ QString HunspellCorrector::correct(const QString &original)
return result;
}
void HunspellCorrector::correctWord(QString &word, QStringEncoder &codec) const
void HunspellCorrector::correctWord(QString &word, QTextCodec &codec) const
{
if (word.isEmpty())
return;
const auto stdWord = codec(word).data.toStdString();
const auto stdWord = codec.fromUnicode(word).toStdString();
if (engine_->spell(stdWord))
return;

View File

@ -5,7 +5,6 @@
#include <QString>
class Hunspell;
class QStringEncoder;
class HunspellCorrector
{
@ -20,7 +19,7 @@ public:
private:
void init(const QString& path);
void correctWord(QString& word, QStringEncoder& codec) const;
void correctWord(QString& word, QTextCodec& codec) const;
std::unique_ptr<Hunspell> engine_;
QString error_;

View File

@ -16,7 +16,6 @@
#include <QFileInfo>
#include <QMessageBox>
#include <QNetworkProxy>
#include <QStandardPaths>
#include <QThread>
namespace
@ -188,8 +187,7 @@ bool Manager::setupTrace(bool isOn)
const auto traceFile =
QStandardPaths::writableLocation(QStandardPaths::TempLocation) +
QLatin1String("/screen-translator-") +
QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss") +
QLatin1String(".txt");
QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if (!debug::setTraceFileName(traceFile)) {
QMessageBox::warning(

View File

@ -4,8 +4,6 @@
#include <QObject>
Q_MOC_INCLUDE("tesseract.h")
class Tesseract;
class RecognizeWorker : public QObject

View File

@ -7,6 +7,7 @@
#include <QApplication>
#include <QBoxLayout>
#include <QDesktopWidget>
#include <QLabel>
#include <QMenu>
#include <QMouseEvent>
@ -69,7 +70,7 @@ ResultWidget::ResultWidget(Manager &manager, Representer &representer,
layout->addWidget(separator_);
layout->addWidget(translated_);
layout->setContentsMargins(0, 0, 0, 0);
layout->setMargin(0);
layout->setSpacing(0);
updateSettings();

View File

@ -77,7 +77,7 @@ void GlobalAction::triggerHotKey(quint32 nativeKey, quint32 nativeMods)
#ifdef Q_OS_LINUX
#include <X11/Xlib.h>
#include <xcb/xcb_event.h>
#include <QWindow>
#include <QX11Info>
namespace service
{
@ -101,22 +101,18 @@ static int customHandler(Display *display, XErrorEvent *event)
bool GlobalAction::registerHotKey(quint32 nativeKey, quint32 nativeMods)
{
auto nativeInterface =
qApp->nativeInterface<QNativeInterface::QX11Application>();
SOFT_ASSERT(nativeInterface, return false);
Display *display = nativeInterface->display();
SOFT_ASSERT(display, return false);
Display *display = QX11Info::display();
Window window = QX11Info::appRootWindow();
Bool owner = True;
int pointer = GrabModeAsync;
int keyboard = GrabModeAsync;
error = false;
int (*handler)(Display * display, XErrorEvent * event) =
XSetErrorHandler(customHandler);
XGrabKey(display, nativeKey, nativeMods, DefaultRootWindow(display), owner,
pointer, keyboard);
XGrabKey(display, nativeKey, nativeMods, window, owner, pointer, keyboard);
// allow numlock
XGrabKey(display, nativeKey, nativeMods | Mod2Mask,
DefaultRootWindow(display), owner, pointer, keyboard);
XGrabKey(display, nativeKey, nativeMods | Mod2Mask, window, owner, pointer,
keyboard);
XSync(display, False);
XSetErrorHandler(handler);
return !error;
@ -124,25 +120,21 @@ bool GlobalAction::registerHotKey(quint32 nativeKey, quint32 nativeMods)
bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
{
auto nativeInterface =
qApp->nativeInterface<QNativeInterface::QX11Application>();
SOFT_ASSERT(nativeInterface, return false);
Display *display = nativeInterface->display();
SOFT_ASSERT(display, return false);
Display *display = QX11Info::display();
Window window = QX11Info::appRootWindow();
error = false;
int (*handler)(Display * display, XErrorEvent * event) =
XSetErrorHandler(customHandler);
XUngrabKey(display, nativeKey, nativeMods, DefaultRootWindow(display));
XUngrabKey(display, nativeKey, nativeMods, window);
// allow numlock
XUngrabKey(display, nativeKey, nativeMods | Mod2Mask,
DefaultRootWindow(display));
XUngrabKey(display, nativeKey, nativeMods | Mod2Mask, window);
XSync(display, False);
XSetErrorHandler(handler);
return !error;
}
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
qintptr *result)
long *result)
{
Q_UNUSED(eventType);
Q_UNUSED(result);
@ -159,9 +151,7 @@ bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
quint32 GlobalAction::nativeKeycode(Qt::Key key)
{
auto nativeInterface =
qApp->nativeInterface<QNativeInterface::QX11Application>();
Display *display = nativeInterface->display();
Display *display = QX11Info::display();
KeySym keySym = XStringToKeysym(qPrintable(QKeySequence(key).toString()));
if (XKeysymToString(keySym) == nullptr) {
keySym = QChar(key).unicode();
@ -201,7 +191,7 @@ bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
}
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
qintptr *result)
long *result)
{
Q_UNUSED(eventType);
Q_UNUSED(result);
@ -417,8 +407,8 @@ bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
}
}
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
qintptr *result)
bool GlobalAction::nativeEventFilter(const QByteArray & /*eventType*/,
void * /*message*/, long * /*result*/)
{
return false;
}

View File

@ -11,7 +11,7 @@ class GlobalAction : public QAbstractNativeEventFilter
{
public:
bool nativeEventFilter(const QByteArray &eventType, void *message,
qintptr *result) override;
long *result);
static void init();
static bool makeGlobal(QAction *action);

View File

@ -63,7 +63,7 @@ void KeySequenceEdit::keyPressEvent(QKeyEvent *event)
return;
}
QKeySequence seq(QKeyCombination(event->modifiers(), Qt::Key(event->key())));
QKeySequence seq = event->modifiers() + event->key();
setKeySequence(seq, false);
event->accept();
}

View File

@ -85,7 +85,7 @@ Substitutions unpackSubstitutions(const QStringList& raw)
return {};
Substitutions result;
for (auto i = 0ll, end = raw.size(); i < end; i += 3) {
for (auto i = 0, end = raw.size(); i < end; i += 3) {
result.emplace(raw[i], Substitution{raw[i + 1], raw[i + 2]});
}
return result;

View File

@ -9,7 +9,6 @@
#include "widgetstate.h"
#include <QColorDialog>
#include <QRegularExpression>
#include <QStandardItemModel>
namespace
@ -113,10 +112,10 @@ SettingsEditor::SettingsEditor(Manager &manager, update::Updater &updater)
proxyTypes.insert(ProxyType::Http, tr("HTTP"));
ui->proxyTypeCombo->addItems(proxyTypes.values());
QRegularExpression urlRegexp(
QRegExp urlRegexp(
R"(^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$)");
ui->proxyHostEdit->setValidator(
new QRegularExpressionValidator(urlRegexp, ui->proxyHostEdit));
new QRegExpValidator(urlRegexp, ui->proxyHostEdit));
ui->proxyPassEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
}

View File

@ -3,9 +3,7 @@
#include <memory>
class QString;
template <class T>
class QList;
using QStringList = QList<QString>;
class QStringList;
class Manager;
class Settings;

View File

@ -55,7 +55,7 @@ public:
{"\\\\", "\\"},
{"\\n", "\n"},
};
for (auto i = 0ll, end = text.size() - 1; i < end; ++i) {
for (auto i = 0, end = text.size() - 1; i < end; ++i) {
const auto pair = text.mid(i, 2);
const auto replaced = replacements.value(pair);
if (replaced.isEmpty())

View File

@ -14,7 +14,6 @@
#include <QLineEdit>
#include <QSplitter>
#include <QTabWidget>
#include <QTcpSocket>
#include <QTextEdit>
#include <QToolBar>

View File

@ -33,9 +33,6 @@ WebPage::WebPage(Translator &translator, const QString &script,
channel->registerObject("proxy", proxy_.get());
setWebChannel(channel, QWebEngineScript::ScriptWorldId::UserWorld);
connect(this, &QWebEnginePage::certificateError, //
this, &WebPage::handleCertificateError);
// to load scripts
setUrl(QUrl::fromUserInput("about:blank"));
}
@ -189,15 +186,11 @@ void WebPage::javaScriptConsoleMessage(
emit log(QString("%1: %2 %3").arg(sourceID).arg(lineNumber).arg(message));
}
void WebPage::handleCertificateError(const QWebEngineCertificateError &error)
bool WebPage::certificateError(const QWebEngineCertificateError &error)
{
qDebug() << "certificateError" << error.url() << error.type()
<< error.description();
if (ignoreSslErrors_) {
const_cast<QWebEngineCertificateError &>(error).acceptCertificate();
return;
}
const_cast<QWebEngineCertificateError &>(error).rejectCertificate();
qDebug() << "certificateError" << error.url() << error.error()
<< error.errorDescription();
return ignoreSslErrors_;
}
void WebPage::authenticateProxy(const QUrl & /*requestUrl*/,

View File

@ -34,7 +34,7 @@ protected:
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
const QString &message, int lineNumber,
const QString &sourceID) override;
void handleCertificateError(const QWebEngineCertificateError &error);
bool certificateError(const QWebEngineCertificateError &error) override;
private:
void authenticateProxy(const QUrl &requestUrl, QAuthenticator *authenticator,

View File

@ -4,8 +4,16 @@ var active = window.location.href !== "about:blank";
function checkFinished() {
if (!active) return;
let area = document.querySelector('textarea[dl-test=translator-target-input]');
let text = area ? area.value : '';
let area = document.querySelector('div#target-dummydiv');
let text = area ? area.innerHTML.trim() : '';
if (area == null) {
area = document.querySelector('d-textarea.lmt__target_textarea p');
text = area ? area.innerText.trim() : '';
}
if (area == null) {
area = document.querySelector('d-textarea[data-testid=translator-target-input] p');
text = area ? area.innerText.trim() : '';
}
if (text === lastText || text === '')
return;
@ -20,16 +28,16 @@ function translate(text, from, to) {
console.log('start translate', text, from, to)
if (text.trim().length == 0) {
proxy.setTranslated('');
return;
proxy.setTranslated('');
return;
}
from = from == 'zh-CN' ? 'zh' : from;
to = to == 'zh-CN' ? 'zh' : to;
let supported = ['ru', 'en', 'de', 'fr', 'es', 'pt', 'it', 'nl', 'pl', 'ja', 'zh',
'uk', 'bg', 'hu', 'el', 'da', 'id', 'lt', 'pt', 'ro', 'sk', 'sk', 'tr', 'fi', 'cs',
'sv', 'et']
'uk', 'bg', 'hu', 'el', 'da', 'id', 'lt', 'pt', 'ro', 'sk', 'sk', 'tr', 'fi', 'cs',
'sv', 'et']
if (supported.indexOf(from) == -1) {
proxy.setFailed('Source language not supported');
return;
@ -41,21 +49,32 @@ function translate(text, from, to) {
active = true;
var singleLineText = text.replace(/(?:\r\n|\r|\n)/g, ' ');
let langs = from + '/' + to + '/';
if (window.location.href.indexOf('www.deepl.com/translator') !== -1
&& window.location.href.indexOf(langs) !== -1) {
var input = document.querySelector('textarea[dl-test=translator-source-input]');
if (input.value == text) {
console.log('using cached result');
lastText = '';
return;
var input = document.querySelector('d-textarea[dl-test=translator-source-input] p');
if (input == null)
input = document.querySelector('d-textarea.lmt__source_textarea p');
if (input == null)
input = document.querySelector('d-textarea[data-testid=translator-source-input] p');
if (input.innerText == singleLineText) {
console.log('using cached result');
lastText = '';
return;
}
input.value = text;
input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
input.innerText = singleLineText;
if (areaCopy = document.querySelector('div#source-dummydiv'))
areaCopy.innerHTML = singleLineText;
setTimeout(function () {
input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
}, 300);
return;
}
let url = 'https://www.deepl.com/translator#' + langs + encodeURIComponent(text);
let url = 'https://www.deepl.com/translator#' + langs + encodeURIComponent(singleLineText);
console.log("setting url", url);
window.location = url;
}

View File

@ -594,7 +594,7 @@
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js", "path":"$translators$/bing.js", "md5":"a982e9aa6cac598f4c9bf4a56386d13e", "size":1481}
]}
,"deepl": {"files":[
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/deepl.js", "path":"$translators$/deepl.js", "md5":"6f1c5cd1ccd18cd663f65e6a9bf8462a", "size":1854}
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/deepl.js", "path":"$translators$/deepl.js", "md5":"76856af9b80c3d0e852ca73f8f1ebbdb", "size":2611}
]}
,"google": {"files":[
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js", "path":"$translators$/google.js", "md5":"793d6628ac9e26a1f3cc00fa9c863495", "size":1508}