Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6eb5a6d9f1 |
@ -14,7 +14,7 @@ win32{
|
||||
LIBS += -lUser32
|
||||
}
|
||||
linux{
|
||||
QT += x11extras
|
||||
# QT += x11extras
|
||||
LIBS += -lX11
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
#include <QTextCodec>
|
||||
#include <QStringConverter>
|
||||
|
||||
static int levenshteinDistance(const QString &source, const QString &target)
|
||||
{
|
||||
@ -106,19 +106,21 @@ QString HunspellCorrector::correct(const QString &original)
|
||||
{
|
||||
SOFT_ASSERT(engine_, return original);
|
||||
|
||||
const auto codec =
|
||||
QTextCodec::codecForName(engine_->get_dict_encoding().c_str());
|
||||
SOFT_ASSERT(codec, return original);
|
||||
const auto encoding =
|
||||
QStringConverter::encodingForName(engine_->get_dict_encoding().c_str());
|
||||
SOFT_ASSERT(encoding, return original);
|
||||
auto codec = QStringEncoder(*encoding);
|
||||
|
||||
QString result;
|
||||
|
||||
QString word;
|
||||
QString separator;
|
||||
for (auto i = 0, end = original.size(); i < end; ++i) {
|
||||
|
||||
for (auto i = 0ll, 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();
|
||||
}
|
||||
@ -139,7 +141,7 @@ QString HunspellCorrector::correct(const QString &original)
|
||||
}
|
||||
|
||||
if (!word.isEmpty()) {
|
||||
correctWord(word, *codec);
|
||||
correctWord(word, codec);
|
||||
result += word;
|
||||
}
|
||||
result += separator;
|
||||
@ -147,12 +149,12 @@ QString HunspellCorrector::correct(const QString &original)
|
||||
return result;
|
||||
}
|
||||
|
||||
void HunspellCorrector::correctWord(QString &word, QTextCodec &codec) const
|
||||
void HunspellCorrector::correctWord(QString &word, QStringEncoder &codec) const
|
||||
{
|
||||
if (word.isEmpty())
|
||||
return;
|
||||
|
||||
const auto stdWord = codec.fromUnicode(word).toStdString();
|
||||
const auto stdWord = codec(word).data.toStdString();
|
||||
if (engine_->spell(stdWord))
|
||||
return;
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QString>
|
||||
|
||||
class Hunspell;
|
||||
class QStringEncoder;
|
||||
|
||||
class HunspellCorrector
|
||||
{
|
||||
@ -19,7 +20,7 @@ public:
|
||||
|
||||
private:
|
||||
void init(const QString& path);
|
||||
void correctWord(QString& word, QTextCodec& codec) const;
|
||||
void correctWord(QString& word, QStringEncoder& codec) const;
|
||||
|
||||
std::unique_ptr<Hunspell> engine_;
|
||||
QString error_;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkProxy>
|
||||
#include <QStandardPaths>
|
||||
#include <QThread>
|
||||
|
||||
namespace
|
||||
@ -187,7 +188,8 @@ bool Manager::setupTrace(bool isOn)
|
||||
const auto traceFile =
|
||||
QStandardPaths::writableLocation(QStandardPaths::TempLocation) +
|
||||
QLatin1String("/screen-translator-") +
|
||||
QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
|
||||
QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss") +
|
||||
QLatin1String(".txt");
|
||||
|
||||
if (!debug::setTraceFileName(traceFile)) {
|
||||
QMessageBox::warning(
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
Q_MOC_INCLUDE("tesseract.h")
|
||||
|
||||
class Tesseract;
|
||||
|
||||
class RecognizeWorker : public QObject
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBoxLayout>
|
||||
#include <QDesktopWidget>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
@ -70,7 +69,7 @@ ResultWidget::ResultWidget(Manager &manager, Representer &representer,
|
||||
layout->addWidget(separator_);
|
||||
layout->addWidget(translated_);
|
||||
|
||||
layout->setMargin(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
updateSettings();
|
||||
|
@ -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 <QX11Info>
|
||||
#include <QWindow>
|
||||
|
||||
namespace service
|
||||
{
|
||||
@ -101,18 +101,22 @@ static int customHandler(Display *display, XErrorEvent *event)
|
||||
|
||||
bool GlobalAction::registerHotKey(quint32 nativeKey, quint32 nativeMods)
|
||||
{
|
||||
Display *display = QX11Info::display();
|
||||
Window window = QX11Info::appRootWindow();
|
||||
auto nativeInterface =
|
||||
qApp->nativeInterface<QNativeInterface::QX11Application>();
|
||||
SOFT_ASSERT(nativeInterface, return false);
|
||||
Display *display = nativeInterface->display();
|
||||
SOFT_ASSERT(display, return false);
|
||||
Bool owner = True;
|
||||
int pointer = GrabModeAsync;
|
||||
int keyboard = GrabModeAsync;
|
||||
error = false;
|
||||
int (*handler)(Display * display, XErrorEvent * event) =
|
||||
XSetErrorHandler(customHandler);
|
||||
XGrabKey(display, nativeKey, nativeMods, window, owner, pointer, keyboard);
|
||||
XGrabKey(display, nativeKey, nativeMods, DefaultRootWindow(display), owner,
|
||||
pointer, keyboard);
|
||||
// allow numlock
|
||||
XGrabKey(display, nativeKey, nativeMods | Mod2Mask, window, owner, pointer,
|
||||
keyboard);
|
||||
XGrabKey(display, nativeKey, nativeMods | Mod2Mask,
|
||||
DefaultRootWindow(display), owner, pointer, keyboard);
|
||||
XSync(display, False);
|
||||
XSetErrorHandler(handler);
|
||||
return !error;
|
||||
@ -120,21 +124,25 @@ bool GlobalAction::registerHotKey(quint32 nativeKey, quint32 nativeMods)
|
||||
|
||||
bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
|
||||
{
|
||||
Display *display = QX11Info::display();
|
||||
Window window = QX11Info::appRootWindow();
|
||||
auto nativeInterface =
|
||||
qApp->nativeInterface<QNativeInterface::QX11Application>();
|
||||
SOFT_ASSERT(nativeInterface, return false);
|
||||
Display *display = nativeInterface->display();
|
||||
SOFT_ASSERT(display, return false);
|
||||
error = false;
|
||||
int (*handler)(Display * display, XErrorEvent * event) =
|
||||
XSetErrorHandler(customHandler);
|
||||
XUngrabKey(display, nativeKey, nativeMods, window);
|
||||
XUngrabKey(display, nativeKey, nativeMods, DefaultRootWindow(display));
|
||||
// allow numlock
|
||||
XUngrabKey(display, nativeKey, nativeMods | Mod2Mask, window);
|
||||
XUngrabKey(display, nativeKey, nativeMods | Mod2Mask,
|
||||
DefaultRootWindow(display));
|
||||
XSync(display, False);
|
||||
XSetErrorHandler(handler);
|
||||
return !error;
|
||||
}
|
||||
|
||||
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
long *result)
|
||||
qintptr *result)
|
||||
{
|
||||
Q_UNUSED(eventType);
|
||||
Q_UNUSED(result);
|
||||
@ -151,7 +159,9 @@ bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
|
||||
quint32 GlobalAction::nativeKeycode(Qt::Key key)
|
||||
{
|
||||
Display *display = QX11Info::display();
|
||||
auto nativeInterface =
|
||||
qApp->nativeInterface<QNativeInterface::QX11Application>();
|
||||
Display *display = nativeInterface->display();
|
||||
KeySym keySym = XStringToKeysym(qPrintable(QKeySequence(key).toString()));
|
||||
if (XKeysymToString(keySym) == nullptr) {
|
||||
keySym = QChar(key).unicode();
|
||||
@ -191,7 +201,7 @@ bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
|
||||
}
|
||||
|
||||
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
long *result)
|
||||
qintptr *result)
|
||||
{
|
||||
Q_UNUSED(eventType);
|
||||
Q_UNUSED(result);
|
||||
@ -407,8 +417,8 @@ bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalAction::nativeEventFilter(const QByteArray & /*eventType*/,
|
||||
void * /*message*/, long * /*result*/)
|
||||
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
qintptr *result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class GlobalAction : public QAbstractNativeEventFilter
|
||||
{
|
||||
public:
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
long *result);
|
||||
qintptr *result) override;
|
||||
|
||||
static void init();
|
||||
static bool makeGlobal(QAction *action);
|
||||
|
@ -63,7 +63,7 @@ void KeySequenceEdit::keyPressEvent(QKeyEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
QKeySequence seq = event->modifiers() + event->key();
|
||||
QKeySequence seq(QKeyCombination(event->modifiers(), Qt::Key(event->key())));
|
||||
setKeySequence(seq, false);
|
||||
event->accept();
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ Substitutions unpackSubstitutions(const QStringList& raw)
|
||||
return {};
|
||||
|
||||
Substitutions result;
|
||||
for (auto i = 0, end = raw.size(); i < end; i += 3) {
|
||||
for (auto i = 0ll, end = raw.size(); i < end; i += 3) {
|
||||
result.emplace(raw[i], Substitution{raw[i + 1], raw[i + 2]});
|
||||
}
|
||||
return result;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "widgetstate.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QRegularExpression>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
namespace
|
||||
@ -112,10 +113,10 @@ SettingsEditor::SettingsEditor(Manager &manager, update::Updater &updater)
|
||||
proxyTypes.insert(ProxyType::Http, tr("HTTP"));
|
||||
ui->proxyTypeCombo->addItems(proxyTypes.values());
|
||||
|
||||
QRegExp urlRegexp(
|
||||
QRegularExpression urlRegexp(
|
||||
R"(^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$)");
|
||||
ui->proxyHostEdit->setValidator(
|
||||
new QRegExpValidator(urlRegexp, ui->proxyHostEdit));
|
||||
new QRegularExpressionValidator(urlRegexp, ui->proxyHostEdit));
|
||||
|
||||
ui->proxyPassEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
#include <memory>
|
||||
|
||||
class QString;
|
||||
class QStringList;
|
||||
template <class T>
|
||||
class QList;
|
||||
using QStringList = QList<QString>;
|
||||
|
||||
class Manager;
|
||||
class Settings;
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
{"\\\\", "\\"},
|
||||
{"\\n", "\n"},
|
||||
};
|
||||
for (auto i = 0, end = text.size() - 1; i < end; ++i) {
|
||||
for (auto i = 0ll, end = text.size() - 1; i < end; ++i) {
|
||||
const auto pair = text.mid(i, 2);
|
||||
const auto replaced = replacements.value(pair);
|
||||
if (replaced.isEmpty())
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <QSplitter>
|
||||
#include <QTabWidget>
|
||||
#include <QTcpSocket>
|
||||
#include <QTextEdit>
|
||||
#include <QToolBar>
|
||||
|
||||
|
@ -33,6 +33,9 @@ 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"));
|
||||
}
|
||||
@ -186,11 +189,15 @@ void WebPage::javaScriptConsoleMessage(
|
||||
emit log(QString("%1: %2 %3").arg(sourceID).arg(lineNumber).arg(message));
|
||||
}
|
||||
|
||||
bool WebPage::certificateError(const QWebEngineCertificateError &error)
|
||||
void WebPage::handleCertificateError(const QWebEngineCertificateError &error)
|
||||
{
|
||||
qDebug() << "certificateError" << error.url() << error.error()
|
||||
<< error.errorDescription();
|
||||
return ignoreSslErrors_;
|
||||
qDebug() << "certificateError" << error.url() << error.type()
|
||||
<< error.description();
|
||||
if (ignoreSslErrors_) {
|
||||
const_cast<QWebEngineCertificateError &>(error).acceptCertificate();
|
||||
return;
|
||||
}
|
||||
const_cast<QWebEngineCertificateError &>(error).rejectCertificate();
|
||||
}
|
||||
|
||||
void WebPage::authenticateProxy(const QUrl & /*requestUrl*/,
|
||||
|
@ -34,7 +34,7 @@ protected:
|
||||
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
|
||||
const QString &message, int lineNumber,
|
||||
const QString &sourceID) override;
|
||||
bool certificateError(const QWebEngineCertificateError &error) override;
|
||||
void handleCertificateError(const QWebEngineCertificateError &error);
|
||||
|
||||
private:
|
||||
void authenticateProxy(const QUrl &requestUrl, QAuthenticator *authenticator,
|
||||
|
Loading…
Reference in New Issue
Block a user