diff --git a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp index f379628d..ad3ae7c8 100644 --- a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp +++ b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp @@ -1,85 +1,88 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2018 Anmol Gautam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "qmlwebengineurlrequestjob.h" #include #include #include QmlWebEngineUrlRequestJob::QmlWebEngineUrlRequestJob(QWebEngineUrlRequestJob *job, QObject *parent) : QObject(parent) , m_job(job) { } void QmlWebEngineUrlRequestJob::fail(QmlWebEngineUrlRequestJob::Error error) { if (!m_job) { return; } m_job->fail(QWebEngineUrlRequestJob::Error(error)); } void QmlWebEngineUrlRequestJob::redirect(const QString &urlString) { if (!m_job) { return; } return m_job->redirect(QUrl::fromEncoded(urlString.toUtf8())); } void QmlWebEngineUrlRequestJob::reply(const QVariantMap &map) { if (!m_job) { return; } if (!map.contains(QSL("content")) || !map.contains(QSL("contentType"))) { qWarning() << "Unable to call" << __FUNCTION__ << ": invalid parameters"; return; } QByteArray content = map.value(QSL("content")).toString().toUtf8(); QByteArray contentType = map.value(QSL("contentType")).toString().toUtf8(); QBuffer *buffer = new QBuffer(); buffer->open(QIODevice::ReadWrite); buffer->write(content); buffer->seek(0); m_job->reply(contentType, buffer); } - QString QmlWebEngineUrlRequestJob::initiator() const { if (!m_job) { return QString(); } - return QString::fromUtf8(m_job->initiator().toEncoded()); + QString initiatorString; +#if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5, 11, 0) + initiatorString = QString::fromUtf8(m_job->initiator().toEncoded()); +#endif + return initiatorString; } QString QmlWebEngineUrlRequestJob::requestUrl() const { if (!m_job) { return QString(); } return QString::fromUtf8(m_job->requestUrl().toEncoded()); } QString QmlWebEngineUrlRequestJob::requestMethod() const { if (!m_job) { return QString(); } return QString::fromUtf8(m_job->requestMethod()); } diff --git a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h index 1da0331b..5f1bdef2 100644 --- a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h +++ b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h @@ -1,77 +1,76 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2018 Anmol Gautam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #pragma once #include /** * @brief The QmlWebEngineUrlRequestJob class */ class QmlWebEngineUrlRequestJob : public QObject { Q_OBJECT /** * @brief initiator of the QWebEngineUrlRequestJob */ Q_PROPERTY(QString initiator READ initiator CONSTANT) /** * @brief request url of the QWebEngineUrlRequestJob */ Q_PROPERTY(QString requestUrl READ requestUrl CONSTANT) /** * @brief request method of the QWebEngineUrlRequestJob */ Q_PROPERTY(QString requestMethod READ requestMethod CONSTANT) public: /** * @brief The Error enum, exposes QWebEngineUrlRequestJob::Error to QML */ enum Error { NoError = QWebEngineUrlRequestJob::NoError, //! No error UrlNotFound = QWebEngineUrlRequestJob::UrlNotFound, //! Url not found error UrlInvaild = QWebEngineUrlRequestJob::UrlInvalid, //! Url invalid error RequestAborted = QWebEngineUrlRequestJob::RequestAborted, //! Request aborted RequestDenied = QWebEngineUrlRequestJob::RequestDenied, //! Request denied RequestFailed = QWebEngineUrlRequestJob::RequestFailed //! Request failed }; Q_ENUM(Error) explicit QmlWebEngineUrlRequestJob(QWebEngineUrlRequestJob *job = nullptr, QObject *parent = nullptr); /** * @brief Fails the request with the error * @param error */ Q_INVOKABLE void fail(Error error); /** * @brief Redirects the request to the url * @param urlString, represents the url to which the request is to be redirected */ Q_INVOKABLE void redirect(const QString &urlString); /** * @brief Replies to the request * @param A JavaScript object containing * - content: String representing the reply data * - contentType: String representing the contentType of reply data */ Q_INVOKABLE void reply(const QVariantMap &map); private: QWebEngineUrlRequestJob *m_job = nullptr; - QString initiator() const; QString requestUrl() const; QString requestMethod() const; }; diff --git a/src/lib/plugins/qml/qmlplugininterface.h b/src/lib/plugins/qml/qmlplugininterface.h index 7fa43f81..09c85747 100644 --- a/src/lib/plugins/qml/qmlplugininterface.h +++ b/src/lib/plugins/qml/qmlplugininterface.h @@ -1,122 +1,122 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2018 Anmol Gautam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #pragma once #include #include #include #include "desktopfile.h" #include "plugininterface.h" class QmlTab; class QmlPluginInterface : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) Q_ENUM(InitState) Q_PROPERTY(QJSValue init READ readInit WRITE setInit) Q_PROPERTY(QJSValue unload READ readUnload WRITE setUnload) Q_PROPERTY(QJSValue testPlugin READ readTestPlugin WRITE setTestPlugin) Q_PROPERTY(QJSValue populateWebViewMenu READ readPopulateWebViewMenu WRITE setPopulateWebViewMenu) Q_PROPERTY(QQmlComponent* settingsWindow READ settingsWindow WRITE setSettingsWindow) Q_PROPERTY(QJSValue mouseDoubleClick READ readMouseDoubleClick WRITE setMouseDoubleClick) Q_PROPERTY(QJSValue mousePress READ readMousePress WRITE setMousePress) Q_PROPERTY(QJSValue mouseRelease READ readMouseRelease WRITE setMouseRelease) Q_PROPERTY(QJSValue mouseMove READ readMouseMove WRITE setMouseMove) Q_PROPERTY(QJSValue wheelEvent READ readWheelEvent WRITE setWheelEvent) Q_PROPERTY(QJSValue keyPress READ readKeyPress WRITE setKeyPress) Q_PROPERTY(QJSValue keyRelease READ readKeyRelease WRITE setKeyRelease) Q_PROPERTY(QJSValue acceptNavigationRequest READ readAcceptNavigationRequest WRITE setAcceptNavigationRequest) Q_PROPERTY(QQmlListProperty childItems READ childItems) Q_CLASSINFO("DefaultProperty", "childItems") public: explicit QmlPluginInterface(); - ~QmlPluginInterface(); - DesktopFile metaData() const; - void init(InitState state, const QString &settingsPath); - void unload(); - bool testPlugin(); + ~QmlPluginInterface() override; + DesktopFile metaData() const override; + void init(InitState state, const QString &settingsPath) override; + void unload() override; + bool testPlugin() override; void setEngine(QQmlEngine *engine); void setName(const QString &name); void populateWebViewMenu(QMenu *menu, WebView *webview, const WebHitTestResult &webHitTestResult) override; - void showSettings(QWidget *parent = nullptr); + void showSettings(QWidget *parent = nullptr) override; bool mouseDoubleClick(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override; bool mousePress(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override; bool mouseRelease(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override; bool mouseMove(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override; bool wheelEvent(Qz::ObjectName type, QObject *obj, QWheelEvent *event) override; bool keyPress(Qz::ObjectName type, QObject *obj, QKeyEvent *event) override; bool keyRelease(Qz::ObjectName type, QObject *obj, QKeyEvent *event) override; bool acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override; Q_SIGNALS: void qmlPluginUnloaded(); private: QQmlEngine *m_engine = nullptr; QString m_name; QJSValue m_init; QJSValue m_unload; QJSValue m_testPlugin; QJSValue m_populateWebViewMenu; QQmlComponent *m_settingsWindow = nullptr; QJSValue m_mouseDoubleClick; QJSValue m_mousePress; QJSValue m_mouseRelease; QJSValue m_mouseMove; QJSValue m_wheelEvent; QJSValue m_keyPress; QJSValue m_keyRelease; QJSValue m_acceptNavigationRequest; QList m_childItems; QmlTab *m_qmlReusableTab = nullptr; QJSValue readInit() const; void setInit(const QJSValue &init); QJSValue readUnload() const; void setUnload(const QJSValue &unload); QJSValue readTestPlugin() const; void setTestPlugin(const QJSValue &testPlugin); QJSValue readPopulateWebViewMenu() const; void setPopulateWebViewMenu(const QJSValue &value); QQmlComponent *settingsWindow() const; void setSettingsWindow(QQmlComponent *settingsWindow); QJSValue readMouseDoubleClick() const; void setMouseDoubleClick(const QJSValue &mouseDoubleClick); QJSValue readMousePress() const; void setMousePress(const QJSValue &mousePress); QJSValue readMouseRelease() const; void setMouseRelease(const QJSValue &mouseRelease); QJSValue readMouseMove() const; void setMouseMove(const QJSValue &mouseMove); QJSValue readWheelEvent() const; void setWheelEvent(const QJSValue &wheelEvent); QJSValue readKeyPress() const; void setKeyPress(const QJSValue &keyPress); QJSValue readKeyRelease() const; void setKeyRelease(const QJSValue &keyRelease); QJSValue readAcceptNavigationRequest() const; void setAcceptNavigationRequest(const QJSValue &acceptNavigationRequest); QQmlListProperty childItems(); }; diff --git a/src/lib/plugins/qml/qmlpluginloader.cpp b/src/lib/plugins/qml/qmlpluginloader.cpp index a7ef1ad5..507d925b 100644 --- a/src/lib/plugins/qml/qmlpluginloader.cpp +++ b/src/lib/plugins/qml/qmlpluginloader.cpp @@ -1,75 +1,75 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2018 Anmol Gautam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "qmlpluginloader.h" #include "qmlengine.h" #include #include #include "../config.h" #if HAVE_LIBINTL #include "qml/api/i18n/qmli18n.h" #endif QmlPluginLoader::QmlPluginLoader(const QString &name, const QString &path, const QString &entryPoint) { m_name = name; m_path = path; m_entryPoint = entryPoint; initEngineAndComponent(); } void QmlPluginLoader::createComponent() { m_interface = qobject_cast(m_component->create(m_component->creationContext())); if (!m_interface) { return; } m_interface->setEngine(m_engine); m_interface->setName(m_name); connect(m_interface, &QmlPluginInterface::qmlPluginUnloaded, this, [this] { delete m_component; delete m_engine; initEngineAndComponent(); }); } QQmlComponent *QmlPluginLoader::component() const { return m_component; } QmlPluginInterface *QmlPluginLoader::instance() const { return m_interface; } void QmlPluginLoader::initEngineAndComponent() { m_engine = new QmlEngine(); m_component = new QQmlComponent(m_engine, QDir(m_path).filePath(m_entryPoint)); m_engine->setExtensionPath(m_path); m_engine->setExtensionName(m_name); -#ifdef HAVE_LIBINTL +#if HAVE_LIBINTL auto i18n = new QmlI18n(m_name); m_engine->globalObject().setProperty(QSL("__falkon_i18n"), m_engine->newQObject(i18n)); m_engine->globalObject().setProperty(QSL("i18n"), m_engine->evaluate(QSL("function (s) { return __falkon_i18n.i18n(s) }"))); m_engine->globalObject().setProperty(QSL("i18np"), m_engine->evaluate(QSL("function (s1, s2) { return __falkon_i18n.i18np(s1, s2) }"))); #endif }