diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..590d4616 --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define HAVE_LIBINTL 1 diff --git a/config.h.cmake b/config.h.cmake index d35648e5..93c290a1 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,11 +1,13 @@ /* config.h. Generated by cmake from config.h.cmake */ #define FALKON_VERSION "${PROJECT_VERSION}" #cmakedefine FALKON_PLUGIN_PATH "${FALKON_PLUGIN_PATH}" #cmakedefine FALKON_GIT_REVISION "${FALKON_GIT_REVISION}" /* Enable portable build */ #cmakedefine PORTABLE_BUILD /* Disable DBus support */ #cmakedefine DISABLE_DBUS + +#define HAVE_LIBINTL LibIntl_FOUND diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index ad9cce7c..689685d9 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,375 +1,371 @@ add_definitions(-DFALKON_SHAREDLIBRARY) set(CMAKE_CXX_STANDARD 14) # Enable C++14, with cmake >= 3.1 set(CMAKE_CXX_EXTENSIONS OFF) # Don't enable gcc-specific extensions set(SRCS 3rdparty/qtsingleapplication/qtsingleapplication.cpp 3rdparty/qtsingleapplication/qtlocalpeer.cpp ) if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/tests/modeltest/modeltest.cpp) include_directories(${CMAKE_SOURCE_DIR}/tests/modeltest) endif() include_directories( 3rdparty adblock app autofill bookmarks cookies downloads history navigation network notifications opensearch other plugins popupwindow preferences session sidebar tabwidget tools webengine webtab ) include_directories(${OPENSSL_INCLUDE_DIR}) set(SRCS ${SRCS} 3rdparty/fancytabwidget.cpp 3rdparty/lineedit.cpp 3rdparty/processinfo.cpp 3rdparty/squeezelabelv1.cpp 3rdparty/squeezelabelv2.cpp 3rdparty/stylehelper.cpp adblock/adblockaddsubscriptiondialog.cpp adblock/adblockurlinterceptor.cpp adblock/adblockdialog.cpp adblock/adblockicon.cpp adblock/adblockmanager.cpp adblock/adblockmatcher.cpp adblock/adblockrule.cpp adblock/adblocksearchtree.cpp adblock/adblocksubscription.cpp adblock/adblocktreewidget.cpp adblock/adblockplugin.cpp app/autosaver.cpp app/browserwindow.cpp app/commandlineoptions.cpp app/datapaths.cpp app/mainapplication.cpp app/mainmenu.cpp app/profilemanager.cpp app/proxystyle.cpp app/qzcommon.cpp app/settings.cpp autofill/autofill.cpp autofill/autofillicon.cpp autofill/autofillnotification.cpp autofill/autofillwidget.cpp autofill/passwordbackends/databaseencryptedpasswordbackend.cpp autofill/passwordbackends/databasepasswordbackend.cpp autofill/passwordbackends/passwordbackend.cpp autofill/passwordmanager.cpp bookmarks/bookmarkitem.cpp bookmarks/bookmarks.cpp bookmarks/bookmarksexport/bookmarksexportdialog.cpp bookmarks/bookmarksexport/bookmarksexporter.cpp bookmarks/bookmarksexport/htmlexporter.cpp bookmarks/bookmarksicon.cpp bookmarks/bookmarksimport/bookmarksimportdialog.cpp bookmarks/bookmarksimport/bookmarksimporter.cpp bookmarks/bookmarksimport/firefoximporter.cpp bookmarks/bookmarksimport/htmlimporter.cpp bookmarks/bookmarksimport/chromeimporter.cpp bookmarks/bookmarksimport/ieimporter.cpp bookmarks/bookmarksimport/operaimporter.cpp bookmarks/bookmarksitemdelegate.cpp bookmarks/bookmarksmanager.cpp bookmarks/bookmarksmenu.cpp bookmarks/bookmarksmodel.cpp bookmarks/bookmarkstoolbarbutton.cpp bookmarks/bookmarkstoolbar.cpp bookmarks/bookmarkstools.cpp bookmarks/bookmarkstreeview.cpp bookmarks/bookmarkswidget.cpp cookies/cookiejar.cpp cookies/cookiemanager.cpp downloads/downloaditem.cpp downloads/downloadmanager.cpp downloads/downloadoptionsdialog.cpp downloads/downloadsbutton.cpp history/history.cpp history/historyitem.cpp history/historymanager.cpp history/historymenu.cpp history/historymodel.cpp history/historytreeview.cpp navigation/completer/locationcompleter.cpp navigation/completer/locationcompleterdelegate.cpp navigation/completer/locationcompletermodel.cpp navigation/completer/locationcompleterrefreshjob.cpp navigation/completer/locationcompleterview.cpp navigation/downicon.cpp navigation/goicon.cpp navigation/locationbar.cpp navigation/locationbarpopup.cpp navigation/navigationbar.cpp navigation/navigationbartoolbutton.cpp navigation/navigationbarconfigdialog.cpp navigation/navigationcontainer.cpp navigation/reloadstopbutton.cpp navigation/siteicon.cpp navigation/websearchbar.cpp network/networkmanager.cpp network/networkurlinterceptor.cpp network/schemehandlers/extensionschemehandler.cpp network/schemehandlers/falkonschemehandler.cpp network/sslerrordialog.cpp notifications/desktopnotification.cpp notifications/desktopnotificationsfactory.cpp opensearch/editsearchengine.cpp opensearch/opensearchengine.cpp opensearch/opensearchenginedelegate.cpp opensearch/opensearchreader.cpp opensearch/searchenginesdialog.cpp opensearch/searchenginesmanager.cpp other/aboutdialog.cpp other/browsinglibrary.cpp other/clearprivatedata.cpp other/checkboxdialog.cpp other/iconchooser.cpp other/licenseviewer.cpp other/qzsettings.cpp other/siteinfo.cpp other/siteinfowidget.cpp other/statusbar.cpp other/updater.cpp other/useragentmanager.cpp plugins/pluginproxy.cpp plugins/plugins.cpp plugins/speeddial.cpp plugins/qml/qmlpluginloader.cpp plugins/qml/qmlplugins.cpp plugins/qml/qmlplugininterface.cpp + plugins/qml/qmlengine.cpp plugins/qml/api/bookmarks/qmlbookmarktreenode.cpp plugins/qml/api/bookmarks/qmlbookmarks.cpp plugins/qml/api/topsites/qmlmostvisitedurl.cpp plugins/qml/api/topsites/qmltopsites.cpp plugins/qml/api/history/qmlhistoryitem.cpp plugins/qml/api/history/qmlhistory.cpp plugins/qml/api/cookies/qmlcookie.cpp plugins/qml/api/cookies/qmlcookies.cpp plugins/qml/api/tabs/qmltab.cpp plugins/qml/api/tabs/qmltabs.cpp plugins/qml/api/notifications/qmlnotifications.cpp plugins/qml/api/clipboard/qmlclipboard.cpp plugins/qml/api/windows/qmlwindow.cpp plugins/qml/api/windows/qmlwindows.cpp plugins/qml/api/windows/qmlwindowstate.cpp plugins/qml/api/windows/qmlwindowtype.cpp plugins/qml/api/browseraction/qmlbrowseraction.cpp plugins/qml/api/sidebar/qmlsidebar.cpp plugins/qml/api/menus/qmlmenu.cpp plugins/qml/api/menus/qmlaction.cpp plugins/qml/api/menus/qmlwebhittestresult.cpp plugins/qml/api/settings/qmlsettings.cpp plugins/qml/api/events/qmlqzobjects.cpp plugins/qml/api/events/qmlmouseevent.cpp plugins/qml/api/events/qmlwheelevent.cpp plugins/qml/api/events/qmlkeyevent.cpp plugins/qml/api/userscript/qmluserscript.cpp plugins/qml/api/userscript/qmluserscripts.cpp plugins/qml/api/userscript/qmlexternaljsobject.cpp plugins/qml/api/extensionscheme/qmlextensionscheme.cpp plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp plugins/qml/api/fileutils/qmlfileutils.cpp plugins/extensions.cpp plugins/themes.cpp popupwindow/popuplocationbar.cpp popupwindow/popupstatusbarmessage.cpp popupwindow/popupwebview.cpp popupwindow/popupwindow.cpp preferences/acceptlanguage.cpp preferences/autofillmanager.cpp preferences/jsoptions.cpp preferences/pluginlistdelegate.cpp preferences/pluginsmanager.cpp preferences/preferences.cpp preferences/thememanager.cpp preferences/useragentdialog.cpp session/recoveryjsobject.cpp session/restoremanager.cpp session/sessionmanager.cpp session/sessionmanagerdialog.cpp sidebar/bookmarkssidebar.cpp sidebar/historysidebar.cpp sidebar/sidebar.cpp tabwidget/combotabbar.cpp tabwidget/tabbar.cpp tabwidget/tabicon.cpp tabwidget/tabmodel.cpp tabwidget/tabmrumodel.cpp tabwidget/tabtreemodel.cpp tabwidget/tabstackedwidget.cpp tabwidget/tabwidget.cpp tabwidget/tabcontextmenu.cpp tools/abstractbuttoninterface.cpp tools/aesinterface.cpp tools/animatedwidget.cpp tools/buttonwithmenu.cpp tools/certificateinfowidget.cpp tools/clickablelabel.cpp tools/closedtabsmanager.cpp tools/closedwindowsmanager.cpp tools/colors.cpp tools/delayedfilewatcher.cpp tools/desktopfile.cpp tools/docktitlebarwidget.cpp tools/enhancedmenu.cpp tools/focusselectlineedit.cpp tools/headerview.cpp tools/horizontallistwidget.cpp tools/html5permissions/html5permissionsdialog.cpp tools/html5permissions/html5permissionsmanager.cpp tools/html5permissions/html5permissionsnotification.cpp tools/iconprovider.cpp tools/listitemdelegate.cpp tools/mactoolbutton.cpp tools/menubar.cpp tools/pagethumbnailer.cpp tools/progressbar.cpp tools/qztools.cpp tools/removeitemfocusdelegate.cpp tools/scripts.cpp tools/sqldatabase.cpp tools/toolbutton.cpp tools/treewidget.cpp tools/wheelhelper.cpp webengine/javascript/autofilljsobject.cpp webengine/javascript/externaljsobject.cpp webengine/loadrequest.cpp webengine/webhittestresult.cpp webengine/webinspector.cpp webengine/webpage.cpp webengine/webview.cpp webengine/webscrollbar.cpp webengine/webscrollbarmanager.cpp webtab/searchtoolbar.cpp webtab/tabbedwebview.cpp webtab/webtab.cpp ) if (LibIntl_FOUND) set(SRCS ${SRCS} plugins/qml/api/i18n/qmli18n.cpp) endif() if (WIN32) set(SRCS ${SRCS} other/registerqappassociation.cpp) endif() if (APPLE) set(SRCS ${SRCS} tools/disablewindowtabbbing.mm) endif() # TODO: use ki18n_wrap_ui? qt5_wrap_ui(SRCS adblock/adblockaddsubscriptiondialog.ui adblock/adblockdialog.ui autofill/autofillnotification.ui autofill/autofillwidget.ui autofill/passwordbackends/masterpassworddialog.ui bookmarks/bookmarksexport/bookmarksexportdialog.ui bookmarks/bookmarksimport/bookmarksimportdialog.ui bookmarks/bookmarksmanager.ui bookmarks/bookmarkswidget.ui cookies/cookiemanager.ui downloads/downloaditem.ui downloads/downloadmanager.ui downloads/downloadoptionsdialog.ui history/historymanager.ui navigation/navigationbarconfigdialog.ui network/sslerrordialog.ui notifications/desktopnotification.ui opensearch/editsearchengine.ui opensearch/searchenginesdialog.ui other/aboutdialog.ui other/browsinglibrary.ui other/clearprivatedata.ui other/iconchooser.ui other/siteinfo.ui other/siteinfowidget.ui preferences/acceptlanguage.ui preferences/addacceptlanguage.ui preferences/autofillmanager.ui preferences/jsoptions.ui preferences/pluginslist.ui preferences/preferences.ui preferences/thememanager.ui preferences/useragentdialog.ui session/sessionmanagerdialog.ui sidebar/bookmarkssidebar.ui sidebar/historysidebar.ui tools/certificateinfowidget.ui tools/docktitlebarwidget.ui tools/html5permissions/html5permissionsdialog.ui tools/html5permissions/html5permissionsnotification.ui webengine/jsalert.ui webengine/jsconfirm.ui webengine/jsprompt.ui webtab/searchtoolbar.ui ) qt5_add_resources(SRCS data/data.qrc data/html.qrc data/icons.qrc data/breeze-fallback.qrc adblock/adblock.qrc ) add_library(FalkonPrivate SHARED ${SRCS}) -# define macro to for LibIntl_FOUND -if (LibIntl_FOUND) - target_compile_definitions(FalkonPrivate PRIVATE LibIntl_FOUND=1) -endif() - get_property(QT_WEBENGINE_INCLUDE_DIRS TARGET Qt5::WebEngine PROPERTY INTERFACE_INCLUDE_DIRECTORIES) target_include_directories(FalkonPrivate SYSTEM PUBLIC ${QT_WEBENGINE_INCLUDE_DIRS}) target_link_libraries(FalkonPrivate Qt5::Widgets Qt5::WebEngineWidgets Qt5::Network Qt5::Sql Qt5::PrintSupport Qt5::QuickWidgets Qt5::WebChannel ${OPENSSL_CRYPTO_LIBRARY} ) if (UNIX AND NOT APPLE) if (NOT NO_X11) target_link_libraries(FalkonPrivate XCB::XCB Qt5::X11Extras) endif() set_target_properties(FalkonPrivate PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "3") install(TARGETS FalkonPrivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP) endif() if (WIN32) target_link_libraries(FalkonPrivate Qt5::WinExtras) endif() if (APPLE) target_link_libraries(FalkonPrivate "-framework CoreServices -framework AppKit") endif() if (NOT DISABLE_DBUS) target_link_libraries(FalkonPrivate Qt5::DBus) endif() diff --git a/src/lib/plugins/qml/api/events/qmlkeyevent.cpp b/src/lib/plugins/qml/api/events/qmlkeyevent.cpp index cd7170ef..08cfaab3 100644 --- a/src/lib/plugins/qml/api/events/qmlkeyevent.cpp +++ b/src/lib/plugins/qml/api/events/qmlkeyevent.cpp @@ -1,67 +1,95 @@ /* ============================================================ * 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 "qmlkeyevent.h" #include QmlKeyEvent::QmlKeyEvent(QKeyEvent *keyEvent, QObject *parent) : QObject(parent) , m_keyEvent(keyEvent) { - delete keyEvent; QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } int QmlKeyEvent::count() const { + if (!m_keyEvent) { + return -1; + } return m_keyEvent->count(); } bool QmlKeyEvent::isAutoRepeat() const { + if (!m_keyEvent) { + return false; + } return m_keyEvent->isAutoRepeat(); } int QmlKeyEvent::key() const { + if (!m_keyEvent) { + return -1; + } return m_keyEvent->key(); } int QmlKeyEvent::modifiers() const { + if (!m_keyEvent) { + return -1; + } return (int)m_keyEvent->modifiers(); } quint32 QmlKeyEvent::nativeModifiers() const { + if (!m_keyEvent) { + return -1; + } return m_keyEvent->nativeModifiers(); } quint32 QmlKeyEvent::nativeScanCode() const { + if (!m_keyEvent) { + return -1; + } return m_keyEvent->nativeScanCode(); } quint32 QmlKeyEvent::nativeVirtualKey() const { + if (!m_keyEvent) { + return -1; + } return m_keyEvent->nativeVirtualKey(); } QString QmlKeyEvent::text() const { + if (!m_keyEvent) { + return QString(); + } return m_keyEvent->text(); } + +void QmlKeyEvent::makeNull() +{ + m_keyEvent = nullptr; +} diff --git a/src/lib/plugins/qml/api/events/qmlkeyevent.h b/src/lib/plugins/qml/api/events/qmlkeyevent.h index b1fd0b75..c3ff28de 100644 --- a/src/lib/plugins/qml/api/events/qmlkeyevent.h +++ b/src/lib/plugins/qml/api/events/qmlkeyevent.h @@ -1,74 +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 #include /** * @brief The class exposing KeyEvent to QML */ class QmlKeyEvent : public QObject { Q_OBJECT /** * @brief number of keys involved in this event */ Q_PROPERTY(int count READ count CONSTANT) /** * @brief checks if the event comes from an auto-repeating key */ Q_PROPERTY(bool autoRepeat READ isAutoRepeat CONSTANT) /** * @brief key code which is pressed/released */ Q_PROPERTY(int key READ key CONSTANT) /** * @brief modifiers associated with the event */ Q_PROPERTY(int modifiers READ modifiers CONSTANT) /** * @brief native modifiers of the event */ Q_PROPERTY(quint32 nativeModifiers READ nativeModifiers CONSTANT) /** * @brief native scan code of the event */ Q_PROPERTY(quint32 nativeScanCode READ nativeScanCode CONSTANT) /** * @brief native virtual key, or key sum of the event */ Q_PROPERTY(quint32 nativeVirtualKey READ nativeVirtualKey CONSTANT) /** * @brief Returns the Unicode text that this key generated */ Q_PROPERTY(QString text READ text CONSTANT) public: explicit QmlKeyEvent(QKeyEvent *keyEvent = nullptr, QObject *parent = nullptr); int count() const; bool isAutoRepeat() const; int key() const; int modifiers() const; quint32 nativeModifiers() const; quint32 nativeScanCode() const; quint32 nativeVirtualKey() const; QString text() const; + void makeNull(); + private: QKeyEvent *m_keyEvent; }; diff --git a/src/lib/plugins/qml/api/events/qmlmouseevent.cpp b/src/lib/plugins/qml/api/events/qmlmouseevent.cpp index e1d05051..abafc8c5 100644 --- a/src/lib/plugins/qml/api/events/qmlmouseevent.cpp +++ b/src/lib/plugins/qml/api/events/qmlmouseevent.cpp @@ -1,86 +1,127 @@ /* ============================================================ * 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 "qmlmouseevent.h" #include QmlMouseEvent::QmlMouseEvent(QMouseEvent *mouseEvent, QObject *parent) : QObject(parent) , m_mouseEvent(mouseEvent) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } int QmlMouseEvent::button() const { + if (!m_mouseEvent) { + return -1; + } return (int)m_mouseEvent->button(); } int QmlMouseEvent::buttons() const { + if (!m_mouseEvent) { + return -1; + } return (int)m_mouseEvent->buttons(); } QPoint QmlMouseEvent::globalPos() const { + if (!m_mouseEvent) { + return QPoint(-1, -1); + } return m_mouseEvent->globalPos(); } int QmlMouseEvent::globalX() const { + if (!m_mouseEvent) { + return -1; + } return m_mouseEvent->globalX(); } int QmlMouseEvent::globalY() const { + if (!m_mouseEvent) { + return -1; + } return m_mouseEvent->globalY(); } QPointF QmlMouseEvent::localPos() const { + if (!m_mouseEvent) { + return QPointF(-1, -1); + } return m_mouseEvent->localPos(); } QPoint QmlMouseEvent::pos() const { + if (!m_mouseEvent) { + return QPoint(-1, -1); + } return m_mouseEvent->pos(); } QPointF QmlMouseEvent::screenPos() const { + if (!m_mouseEvent) { + return QPointF(-1, -1); + } return m_mouseEvent->screenPos(); } int QmlMouseEvent::source() const { + if (!m_mouseEvent) { + return -1; + } return (int)m_mouseEvent->source(); } QPointF QmlMouseEvent::windowPos() const { + if (!m_mouseEvent) { + return QPointF(-1, -1); + } return m_mouseEvent->windowPos(); } int QmlMouseEvent::x() const { + if (!m_mouseEvent) { + return -1; + } return m_mouseEvent->x(); } int QmlMouseEvent::y() const { + if (!m_mouseEvent) { + return -1; + } return m_mouseEvent->y(); } + +void QmlMouseEvent::makeNull() +{ + m_mouseEvent = nullptr; +} diff --git a/src/lib/plugins/qml/api/events/qmlmouseevent.h b/src/lib/plugins/qml/api/events/qmlmouseevent.h index dc9bf6ce..d14032d7 100644 --- a/src/lib/plugins/qml/api/events/qmlmouseevent.h +++ b/src/lib/plugins/qml/api/events/qmlmouseevent.h @@ -1,93 +1,95 @@ /* ============================================================ * 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 class exposing MouseEvent to QML */ class QmlMouseEvent : public QObject { Q_OBJECT /** * @brief button associated with the event */ Q_PROPERTY(int button READ button CONSTANT) /** * @brief button state associated with the event */ Q_PROPERTY(int buttons READ buttons CONSTANT) /** * @brief global position of mouse cursor at the time of event */ Q_PROPERTY(QPoint globalPos READ globalPos CONSTANT) /** * @brief global x position of mouse cursor at the time of event */ Q_PROPERTY(int globalX READ globalX CONSTANT) /** * @brief global y position of mouse cursor at the time of event */ Q_PROPERTY(int globalY READ globalY CONSTANT) /** * @brief local position of mouse cursor at the time of event */ Q_PROPERTY(QPointF localPos READ localPos CONSTANT) /** * @brief position of mouse cursor at the time of event */ Q_PROPERTY(QPoint pos READ pos CONSTANT) /** * @brief screen position of mouse cursor at the time of event */ Q_PROPERTY(QPointF screenPos READ screenPos CONSTANT) /** * @brief source of the event */ Q_PROPERTY(int source READ source CONSTANT) /** * @brief window position of mouse cursor at the time of event */ Q_PROPERTY(QPointF windowPos READ windowPos CONSTANT) /** * @brief x position of mouse cursor at the time of event */ Q_PROPERTY(int x READ x CONSTANT) /** * @brief y position of mouse cursor at the time of event */ Q_PROPERTY(int y READ y CONSTANT) public: explicit QmlMouseEvent(QMouseEvent *mouseEvent = nullptr, QObject *parent = nullptr); int button() const; int buttons() const; QPoint globalPos() const; int globalX() const; int globalY() const; QPointF localPos() const; QPoint pos() const; QPointF screenPos() const; int source() const; QPointF windowPos() const; int x() const; int y() const; + void makeNull(); + private: QMouseEvent *m_mouseEvent; }; diff --git a/src/lib/plugins/qml/api/events/qmlwheelevent.cpp b/src/lib/plugins/qml/api/events/qmlwheelevent.cpp index 192ec487..5c7c61b8 100644 --- a/src/lib/plugins/qml/api/events/qmlwheelevent.cpp +++ b/src/lib/plugins/qml/api/events/qmlwheelevent.cpp @@ -1,96 +1,143 @@ /* ============================================================ * 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 "qmlwheelevent.h" #include QmlWheelEvent::QmlWheelEvent(QWheelEvent *wheelEvent, QObject *parent) : QObject(parent) , m_wheelEvent(wheelEvent) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } QPoint QmlWheelEvent::angleDelta() const { + if (!m_wheelEvent) { + return QPoint(-1, -1); + } return m_wheelEvent->angleDelta(); } int QmlWheelEvent::buttons() const { + if (!m_wheelEvent) { + return -1; + } return (int)m_wheelEvent->buttons(); } QPoint QmlWheelEvent::globalPos() const { + if (!m_wheelEvent) { + return QPoint(-1, -1); + } return m_wheelEvent->globalPos(); } QPointF QmlWheelEvent::globalPosF() const { + if (!m_wheelEvent) { + return QPointF(-1, -1); + } return m_wheelEvent->globalPosF(); } int QmlWheelEvent::globalX() const { + if (!m_wheelEvent) { + return -1; + } return m_wheelEvent->globalX(); } int QmlWheelEvent::globalY() const { + if (!m_wheelEvent) { + return -1; + } return m_wheelEvent->globalY(); } bool QmlWheelEvent::inverted() const { + if (!m_wheelEvent) { + return false; + } return m_wheelEvent->inverted(); } int QmlWheelEvent::phase() const { + if (!m_wheelEvent) { + return -1; + } return (int)m_wheelEvent->phase(); } QPoint QmlWheelEvent::pixelDelta() const { + if (!m_wheelEvent) { + return QPoint(-1, -1); + } return m_wheelEvent->pixelDelta(); } QPoint QmlWheelEvent::pos() const { + if (!m_wheelEvent) { + return QPoint(-1, -1); + } return m_wheelEvent->pos(); } QPointF QmlWheelEvent::posF() const { + if (!m_wheelEvent) { + return QPointF(-1, -1); + } return m_wheelEvent->posF(); } int QmlWheelEvent::source() const { + if (!m_wheelEvent) { + return -1; + } return (int)m_wheelEvent->source(); } int QmlWheelEvent::x() const { + if (!m_wheelEvent) { + return -1; + } return m_wheelEvent->x(); } int QmlWheelEvent::y() const { + if (!m_wheelEvent) { + return -1; + } return m_wheelEvent->y(); } + +void QmlWheelEvent::makeNull() +{ + m_wheelEvent = nullptr; +} diff --git a/src/lib/plugins/qml/api/events/qmlwheelevent.h b/src/lib/plugins/qml/api/events/qmlwheelevent.h index 17807503..fc89b048 100644 --- a/src/lib/plugins/qml/api/events/qmlwheelevent.h +++ b/src/lib/plugins/qml/api/events/qmlwheelevent.h @@ -1,103 +1,105 @@ /* ============================================================ * 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 /** * @brief The class exposing WheelEvent to QML */ class QmlWheelEvent : public QObject { Q_OBJECT /** * @brief the distance that the wheel is rotated, in eighths of a degree */ Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT) /** * @brief mouse state at the time of event */ Q_PROPERTY(int buttons READ buttons CONSTANT) /** * @brief global position of mouse cursor at the time of event */ Q_PROPERTY(QPoint globalPos READ globalPos CONSTANT) /** * @brief global position of mouse cursor at the time of event */ Q_PROPERTY(QPointF globalPosF READ globalPosF CONSTANT) /** * @brief global x position of mouse cursor at the time of event */ Q_PROPERTY(int globalX READ globalX CONSTANT) /** * @brief global y position of mouse cursor at the time of event */ Q_PROPERTY(int globalY READ globalY CONSTANT) /** * @brief checks if the delta values delivered with the event are inverted */ Q_PROPERTY(bool inverted READ inverted CONSTANT) /** * @brief scrolling phase of this wheel event */ Q_PROPERTY(int phase READ phase CONSTANT) /** * @brief scrolling distance in pixels on screen */ Q_PROPERTY(QPoint pixelDelta READ pixelDelta CONSTANT) /** * @brief position of mouse cursor at the time of event */ Q_PROPERTY(QPoint pos READ pos CONSTANT) /** * @brief position of mouse cursor at the time of event */ Q_PROPERTY(QPointF posF READ posF CONSTANT) /** * @brief source of the event */ Q_PROPERTY(int source READ source CONSTANT) /** * @brief x position of mouse cursor at the time of event */ Q_PROPERTY(int x READ x CONSTANT) /** * @brief y position of mouse cursor at the time of event */ Q_PROPERTY(int y READ y CONSTANT) public: explicit QmlWheelEvent(QWheelEvent *wheelEvent = nullptr, QObject *parent = nullptr); QPoint angleDelta() const; int buttons() const; QPoint globalPos() const; QPointF globalPosF() const; int globalX() const; int globalY() const; bool inverted() const; int phase() const; QPoint pixelDelta() const; QPoint pos() const; QPointF posF() const; int source() const; int x() const; int y() const; + + void makeNull(); private: QWheelEvent *m_wheelEvent; }; diff --git a/src/lib/plugins/qml/api/i18n/qmli18n.cpp b/src/lib/plugins/qml/api/i18n/qmli18n.cpp index 5e6e6a2a..6f6ffd6b 100644 --- a/src/lib/plugins/qml/api/i18n/qmli18n.cpp +++ b/src/lib/plugins/qml/api/i18n/qmli18n.cpp @@ -1,48 +1,46 @@ /* ============================================================ * 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 "qmli18n.h" #include "qztools.h" #include QmlI18n::QmlI18n(const QString &pluginName, QObject *parent) : QObject(parent) { - m_pluginName = QzTools::filterCharsFromFilename(pluginName); - // QzTools::filterCharsFromFilename doesn't replaces spaces - m_pluginName.replace(QLatin1Char(' '), QLatin1Char('_')); + m_pluginName = pluginName; setlocale(LC_MESSAGES, ""); initTranslations(); } void QmlI18n::initTranslations() { QString domain = QString("falkon_%1").arg(m_pluginName); QString localeDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "locale", QStandardPaths::LocateDirectory); bindtextdomain(domain.toUtf8(), localeDir.toUtf8()); textdomain(domain.toUtf8()); } QString QmlI18n::i18n(const QString &string) { return QString::fromUtf8(gettext(string.toUtf8())); } QString QmlI18n::i18np(const QString &string1, const QString &string2, int count) { return QString::fromUtf8(ngettext(string1.toUtf8(), string2.toUtf8(), count)); } diff --git a/src/lib/plugins/qml/qmlpluginloader.h b/src/lib/plugins/qml/qmlengine.cpp similarity index 60% copy from src/lib/plugins/qml/qmlpluginloader.h copy to src/lib/plugins/qml/qmlengine.cpp index 55db2bf1..131d5b2a 100644 --- a/src/lib/plugins/qml/qmlpluginloader.h +++ b/src/lib/plugins/qml/qmlengine.cpp @@ -1,43 +1,43 @@ /* ============================================================ * 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 "qmlengine.h" -#include -#include +QmlEngine::QmlEngine(QObject *parent) + : QQmlEngine(parent) +{ +} -#include "qmlplugininterface.h" +QString QmlEngine::extensionName() +{ + return m_extensionName; +} -class QmlPluginLoader : public QObject +void QmlEngine::setExtensionName(const QString &name) { - Q_OBJECT -public: - explicit QmlPluginLoader(const QString &path); - void createComponent(); - QQmlComponent *component() const; - QmlPluginInterface *instance() const; - void setName(const QString &name); -private: - QString m_path; - QQmlEngine *m_engine; - QQmlComponent *m_component; - QmlPluginInterface *m_interface; + m_extensionName = name; +} - void initEngineAndComponent(); -}; +QString QmlEngine::extensionPath() +{ + return m_extensionPath; +} -Q_DECLARE_METATYPE(QmlPluginLoader *) +void QmlEngine::setExtensionPath(const QString &path) +{ + m_extensionPath = path; +} diff --git a/src/lib/plugins/qml/qmlpluginloader.h b/src/lib/plugins/qml/qmlengine.h similarity index 64% copy from src/lib/plugins/qml/qmlpluginloader.h copy to src/lib/plugins/qml/qmlengine.h index 55db2bf1..3d7c59af 100644 --- a/src/lib/plugins/qml/qmlpluginloader.h +++ b/src/lib/plugins/qml/qmlengine.h @@ -1,43 +1,33 @@ /* ============================================================ * 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 "qmlplugininterface.h" - -class QmlPluginLoader : public QObject +class QmlEngine : public QQmlEngine { - Q_OBJECT public: - explicit QmlPluginLoader(const QString &path); - void createComponent(); - QQmlComponent *component() const; - QmlPluginInterface *instance() const; - void setName(const QString &name); + explicit QmlEngine(QObject *parent = nullptr); + QString extensionName(); + void setExtensionName(const QString &name); + QString extensionPath(); + void setExtensionPath(const QString &path); private: - QString m_path; - QQmlEngine *m_engine; - QQmlComponent *m_component; - QmlPluginInterface *m_interface; - - void initEngineAndComponent(); + QString m_extensionName; + QString m_extensionPath; }; - -Q_DECLARE_METATYPE(QmlPluginLoader *) diff --git a/src/lib/plugins/qml/qmlplugininterface.cpp b/src/lib/plugins/qml/qmlplugininterface.cpp index b37f3b9d..01ccd4c8 100644 --- a/src/lib/plugins/qml/qmlplugininterface.cpp +++ b/src/lib/plugins/qml/qmlplugininterface.cpp @@ -1,384 +1,398 @@ /* ============================================================ * 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 "qmlplugininterface.h" #include "mainapplication.h" #include "pluginproxy.h" #include "statusbar.h" #include "browserwindow.h" #include "navigationbar.h" #include "sidebar.h" #include "api/menus/qmlmenu.h" #include "api/menus/qmlwebhittestresult.h" #include "api/events/qmlqzobjects.h" #include "api/events/qmlmouseevent.h" #include "api/events/qmlwheelevent.h" #include "api/events/qmlkeyevent.h" #include "api/tabs/qmltab.h" #include "webpage.h" #include "qztools.h" #include #include #include #include #include QmlPluginInterface::QmlPluginInterface() : m_settingsWindow(nullptr) , m_qmlReusableTab(new QmlTab()) { } void QmlPluginInterface::init(InitState state, const QString &settingsPath) { if (!m_init.isCallable()) { qWarning() << "Unable to call" << __FUNCTION__ << "on" << m_name << "plugin"; return; } QJSValueList args; args.append(state); args.append(settingsPath); m_init.call(args); } DesktopFile QmlPluginInterface::metaData() const { return DesktopFile(); } void QmlPluginInterface::unload() { if (!m_unload.isCallable()) { qWarning() << "Unable to call" << __FUNCTION__ << "on" << m_name << "plugin"; return; } m_unload.call(); for (QObject *childItem : m_childItems) { childItem->deleteLater(); } emit qmlPluginUnloaded(); } bool QmlPluginInterface::testPlugin() { if (!m_testPlugin.isCallable()) { qWarning() << "Unable to call" << __FUNCTION__ << "on" << m_name << "plugin"; return false; } QJSValue ret = m_testPlugin.call(); return ret.toBool(); } void QmlPluginInterface::populateWebViewMenu(QMenu *menu, WebView *webview, const WebHitTestResult &webHitTestResult) { Q_UNUSED(webview) if (!m_populateWebViewMenu.isCallable()) { return; } QmlMenu *qmlMenu = new QmlMenu(menu); qmlMenu->setPluginPath(m_engine->rootContext()->contextProperty("__path__").toString()); QmlWebHitTestResult *qmlWebHitTestResult = new QmlWebHitTestResult(webHitTestResult); QJSValueList args; args.append(m_engine->newQObject(qmlMenu)); args.append(m_engine->newQObject(qmlWebHitTestResult)); m_populateWebViewMenu.call(args); menu->addSeparator(); } void QmlPluginInterface::showSettings(QWidget *parent) { if (!m_settingsWindow) { qWarning() << "No dialog to show"; return; } QQuickWindow *window = qobject_cast(m_settingsWindow->create(m_settingsWindow->creationContext())); if (!window) { qWarning() << "Unable to created window"; return; } QWidget *widget = QWidget::createWindowContainer(window); widget->setFixedSize(window->size()); widget->show(); QzTools::centerWidgetToParent(widget, parent); connect(widget, &QWidget::destroyed, window, &QQuickWindow::destroy); } bool QmlPluginInterface::mouseDoubleClick(Qz::ObjectName type, QObject *obj, QMouseEvent *event) { Q_UNUSED(obj) if (!m_mouseDoubleClick.isCallable()) { return false; } + auto qmlMouseEvent = new QmlMouseEvent(event); QJSValueList args; args.append(QmlQzObjects::ObjectName(type)); - args.append(m_engine->newQObject(new QmlMouseEvent(event))); + args.append(m_engine->newQObject(qmlMouseEvent)); m_mouseDoubleClick.call(args); + qmlMouseEvent->makeNull(); return false; } bool QmlPluginInterface::mousePress(Qz::ObjectName type, QObject *obj, QMouseEvent *event) { Q_UNUSED(obj) if (!m_mousePress.isCallable()) { return false; } + auto qmlMouseEvent = new QmlMouseEvent(event); QJSValueList args; args.append(QmlQzObjects::ObjectName(type)); - args.append(m_engine->newQObject(new QmlMouseEvent(event))); + args.append(m_engine->newQObject(qmlMouseEvent)); m_mousePress.call(args); + qmlMouseEvent->makeNull(); return false; } bool QmlPluginInterface::mouseRelease(Qz::ObjectName type, QObject *obj, QMouseEvent *event) { Q_UNUSED(obj) if (!m_mouseRelease.isCallable()) { return false; } + auto qmlMouseEvent = new QmlMouseEvent(event); QJSValueList args; args.append(QmlQzObjects::ObjectName(type)); - args.append(m_engine->newQObject(new QmlMouseEvent(event))); + args.append(m_engine->newQObject(qmlMouseEvent)); m_mouseRelease.call(args); + qmlMouseEvent->makeNull(); return false; } bool QmlPluginInterface::mouseMove(Qz::ObjectName type, QObject *obj, QMouseEvent *event) { Q_UNUSED(obj) if (!m_mouseMove.isCallable()) { return false; } + auto qmlMouseEvent = new QmlMouseEvent(event); QJSValueList args; args.append(QmlQzObjects::ObjectName(type)); - args.append(m_engine->newQObject(new QmlMouseEvent(event))); + args.append(m_engine->newQObject(qmlMouseEvent)); m_mouseMove.call(args); + qmlMouseEvent->makeNull(); return false; } bool QmlPluginInterface::wheelEvent(Qz::ObjectName type, QObject *obj, QWheelEvent *event) { Q_UNUSED(obj) if (!m_wheelEvent.isCallable()) { return false; } + auto qmlWheelEvent = new QmlWheelEvent(event); QJSValueList args; args.append(QmlQzObjects::ObjectName(type)); - args.append(m_engine->newQObject(new QmlWheelEvent(event))); + args.append(m_engine->newQObject(qmlWheelEvent)); m_wheelEvent.call(args); + qmlWheelEvent->makeNull(); return false; } bool QmlPluginInterface::keyPress(Qz::ObjectName type, QObject *obj, QKeyEvent *event) { Q_UNUSED(obj) if (!m_keyPress.isCallable()) { return false; } + auto qmlKeyEvent = new QmlKeyEvent(event); QJSValueList args; args.append(QmlQzObjects::ObjectName(type)); - args.append(m_engine->newQObject(new QmlKeyEvent(event))); + args.append(m_engine->newQObject(qmlKeyEvent)); m_keyPress.call(args); + qmlKeyEvent->makeNull(); return false; } bool QmlPluginInterface::keyRelease(Qz::ObjectName type, QObject *obj, QKeyEvent *event) { Q_UNUSED(obj) if (!m_keyRelease.isCallable()) { return false; } + auto qmlKeyEvent = new QmlKeyEvent(event); QJSValueList args; args.append(QmlQzObjects::ObjectName(type)); - args.append(m_engine->newQObject(new QmlKeyEvent(event))); + args.append(m_engine->newQObject(qmlKeyEvent)); m_keyRelease.call(args); + qmlKeyEvent->makeNull(); return false; } bool QmlPluginInterface::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) { if (!m_acceptNavigationRequest.isCallable()) { return true; } m_qmlReusableTab->setWebPage(page); QJSValueList args; args.append(m_engine->newQObject(m_qmlReusableTab)); args.append(QString::fromUtf8(url.toEncoded())); args.append(type); args.append(isMainFrame); return m_acceptNavigationRequest.call(args).toBool(); } QJSValue QmlPluginInterface::readInit() const { return m_init; } void QmlPluginInterface::setInit(const QJSValue &init) { m_init = init; } QJSValue QmlPluginInterface::readUnload() const { return m_unload; } void QmlPluginInterface::setUnload(const QJSValue &unload) { m_unload = unload; } QJSValue QmlPluginInterface::readTestPlugin() const { return m_testPlugin; } void QmlPluginInterface::setTestPlugin(const QJSValue &testPlugin) { m_testPlugin = testPlugin; } void QmlPluginInterface::setEngine(QQmlEngine *engine) { m_engine = engine; } void QmlPluginInterface::setName(const QString &name) { m_name = name; } QJSValue QmlPluginInterface::readPopulateWebViewMenu() const { return m_populateWebViewMenu; } void QmlPluginInterface::setPopulateWebViewMenu(const QJSValue &value) { m_populateWebViewMenu = value; } QQmlComponent *QmlPluginInterface::settingsWindow() const { return m_settingsWindow; } void QmlPluginInterface::setSettingsWindow(QQmlComponent *settingsWindow) { m_settingsWindow = settingsWindow; } QJSValue QmlPluginInterface::readMouseDoubleClick() const { return m_mouseDoubleClick; } void QmlPluginInterface::setMouseDoubleClick(const QJSValue &mouseDoubleClick) { m_mouseDoubleClick = mouseDoubleClick; mApp->plugins()->registerAppEventHandler(PluginProxy::MouseDoubleClickHandler, this); } QJSValue QmlPluginInterface::readMousePress() const { return m_mousePress; } void QmlPluginInterface::setMousePress(const QJSValue &mousePress) { m_mousePress = mousePress; mApp->plugins()->registerAppEventHandler(PluginProxy::MousePressHandler, this); } QJSValue QmlPluginInterface::readMouseRelease() const { return m_mouseRelease; } void QmlPluginInterface::setMouseRelease(const QJSValue &mouseRelease) { m_mouseRelease = mouseRelease; mApp->plugins()->registerAppEventHandler(PluginProxy::MouseReleaseHandler, this); } QJSValue QmlPluginInterface::readMouseMove() const { return m_mouseMove; } void QmlPluginInterface::setMouseMove(const QJSValue &mouseMove) { m_mouseMove = mouseMove; mApp->plugins()->registerAppEventHandler(PluginProxy::MouseMoveHandler, this); } QJSValue QmlPluginInterface::readWheelEvent() const { return m_wheelEvent; } void QmlPluginInterface::setWheelEvent(const QJSValue &wheelEvent) { m_wheelEvent = wheelEvent; mApp->plugins()->registerAppEventHandler(PluginProxy::WheelEventHandler, this); } QJSValue QmlPluginInterface::readKeyPress() const { return m_keyPress; } void QmlPluginInterface::setKeyPress(const QJSValue &keyPress) { m_keyPress = keyPress; mApp->plugins()->registerAppEventHandler(PluginProxy::KeyPressHandler, this); } QJSValue QmlPluginInterface::readKeyRelease() const { return m_keyRelease; } void QmlPluginInterface::setKeyRelease(const QJSValue &keyRelease) { m_keyRelease = keyRelease; mApp->plugins()->registerAppEventHandler(PluginProxy::KeyReleaseHandler, this); } QJSValue QmlPluginInterface::readAcceptNavigationRequest() const { return m_acceptNavigationRequest; } void QmlPluginInterface::setAcceptNavigationRequest(const QJSValue &acceptNavigationRequest) { m_acceptNavigationRequest = acceptNavigationRequest; } QQmlListProperty QmlPluginInterface::childItems() { return QQmlListProperty(this, m_childItems); } diff --git a/src/lib/plugins/qml/qmlpluginloader.cpp b/src/lib/plugins/qml/qmlpluginloader.cpp index 4d3b7797..d031db27 100644 --- a/src/lib/plugins/qml/qmlpluginloader.cpp +++ b/src/lib/plugins/qml/qmlpluginloader.cpp @@ -1,64 +1,65 @@ /* ============================================================ * 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 QmlPluginLoader::QmlPluginLoader(const QString &path) { m_path = path; initEngineAndComponent(); } void QmlPluginLoader::createComponent() { m_interface = qobject_cast(m_component->create(m_component->creationContext())); if (!m_interface) { return; } m_interface->setEngine(m_engine); 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::setName(const QString &name) { m_interface->setName(name); - m_engine->rootContext()->setContextProperty("__name__", name); + m_engine->setExtensionName(name); } void QmlPluginLoader::initEngineAndComponent() { - m_engine = new QQmlEngine(); + m_engine = new QmlEngine(); m_component = new QQmlComponent(m_engine, m_path); - m_engine->rootContext()->setContextProperty("__path__", m_path); + m_engine->setExtensionPath(m_path); } diff --git a/src/lib/plugins/qml/qmlpluginloader.h b/src/lib/plugins/qml/qmlpluginloader.h index 55db2bf1..921175e2 100644 --- a/src/lib/plugins/qml/qmlpluginloader.h +++ b/src/lib/plugins/qml/qmlpluginloader.h @@ -1,43 +1,45 @@ /* ============================================================ * 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 "qmlplugininterface.h" +class QmlEngine; + class QmlPluginLoader : public QObject { Q_OBJECT public: explicit QmlPluginLoader(const QString &path); void createComponent(); QQmlComponent *component() const; QmlPluginInterface *instance() const; void setName(const QString &name); private: QString m_path; - QQmlEngine *m_engine; + QmlEngine *m_engine; QQmlComponent *m_component; QmlPluginInterface *m_interface; void initEngineAndComponent(); }; Q_DECLARE_METATYPE(QmlPluginLoader *) diff --git a/src/lib/plugins/qml/qmlplugins.cpp b/src/lib/plugins/qml/qmlplugins.cpp index c2343609..0237a10e 100644 --- a/src/lib/plugins/qml/qmlplugins.cpp +++ b/src/lib/plugins/qml/qmlplugins.cpp @@ -1,216 +1,233 @@ /* ============================================================ * 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 "qmlplugins.h" #include "qmlplugininterface.h" +#include "qmlengine.h" #include "api/bookmarks/qmlbookmarktreenode.h" #include "api/bookmarks/qmlbookmarks.h" #include "api/topsites/qmlmostvisitedurl.h" #include "api/topsites/qmltopsites.h" #include "api/history/qmlhistoryitem.h" #include "api/history/qmlhistory.h" #include "api/cookies/qmlcookie.h" #include "api/cookies/qmlcookies.h" #include "api/tabs/qmltab.h" #include "api/tabs/qmltabs.h" #include "api/notifications/qmlnotifications.h" #include "api/clipboard/qmlclipboard.h" #include "api/windows/qmlwindow.h" #include "api/windows/qmlwindows.h" #include "api/windows/qmlwindowstate.h" #include "api/windows/qmlwindowtype.h" #include "api/browseraction/qmlbrowseraction.h" #include "api/sidebar/qmlsidebar.h" #include "api/menus/qmlmenu.h" #include "api/menus/qmlaction.h" #include "api/menus/qmlwebhittestresult.h" #include "api/settings/qmlsettings.h" #include "api/events/qmlqzobjects.h" #include "api/events/qmlmouseevent.h" #include "api/events/qmlwheelevent.h" #include "api/userscript/qmluserscript.h" #include "api/userscript/qmluserscripts.h" #include "api/userscript/qmlexternaljsobject.h" #include "api/extensionscheme/qmlextensionscheme.h" #include "api/extensionscheme/qmlwebengineurlrequestjob.h" #include "api/fileutils/qmlfileutils.h" -#ifdef LibIntl_FOUND +#include "../config.h" + +#ifdef HAVE_LIBINTL #include "qml/api/i18n/qmli18n.h" #endif #include #include // static void QmlPlugins::registerQmlTypes() { // PluginInterface qmlRegisterType("org.kde.falkon", 1, 0, "PluginInterface"); // Bookmarks qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "BookmarkTreeNode", "Unable to register type: BookmarkTreeNode"); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "Bookmarks", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlBookmarks(); }); // TopSites qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "MostVisitedURL", "Unable to register type: MostVisitedURL"); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "TopSites", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlTopSites(); }); // History qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "HistoryItem", "Unable to register type: HistoryItem"); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "History", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlHistory(); }); // Cookies qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "Cookie", "Unable to register type: Cookie"); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "Cookies", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlCookies(); }); // Tabs qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "Tab", "Unable to register type: Tab"); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "Tabs", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlTabs(); }); // Notifications qmlRegisterSingletonType("org.kde.falkon", 1, 0, "Notifications", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { - Q_UNUSED(engine) Q_UNUSED(scriptEngine) - QString filePath = engine->rootContext()->contextProperty("__path__").toString(); + QmlEngine *qmlEngine = dynamic_cast(engine); + if (!qmlEngine) { + qWarning() << "Unable to cast QQmlEngine * to QmlEngine *"; + return nullptr; + } + QString filePath = qmlEngine->extensionPath(); auto *object = new QmlNotifications(); object->setPluginPath(filePath); return object; }); // Clipboard qmlRegisterSingletonType("org.kde.falkon", 1, 0, "Clipboard", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlClipboard(); }); // Windows qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "Window", "Unable to register type: Window"); qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "WindowState", "Unable to register type: WindowState"); qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "WindowType", "Unable to register type: WindowType"); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "Windows", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlWindows(); }); // BrowserAction qmlRegisterType("org.kde.falkon", 1, 0, "BrowserAction"); // SideBar qmlRegisterType("org.kde.falkon", 1, 0, "SideBar"); // Menu qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "Menu", "Unable to register type: Menu"); // Action qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "Action", "Unable to register type: Action"); // WebHitTestResult qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "WebHitTestResult", "Unable to register type: WebHitTestResult"); // Settings qmlRegisterType("org.kde.falkon", 1, 0, "Settings"); // Qz::Objects qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "QzObjects", "Unable to register type: QzObjects"); // MouseEvents qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "MouseEvent", "Unable to register type: MouseEvent"); // WheelEvents qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "WheelEvent", "Unable to register type: WheelEvent"); -#ifdef LibIntl_FOUND +#ifdef HAVE_LIBINTL // i18n qmlRegisterSingletonType("org.kde.falkon", 1, 0, "I18n", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(scriptEngine) - QString pluginName = engine->rootContext()->contextProperty("__name__").toString(); + + QmlEngine *qmlEngine = dynamic_cast(engine); + if (!qmlEngine) { + qWarning() << "Unable to cast QQmlEngine * to QmlEngine *"; + return nullptr; + } + QString pluginName = qmlEngine->extensionName(); return new QmlI18n(pluginName); }); #endif // UserScripts qmlRegisterType("org.kde.falkon", 1, 0, "UserScript"); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "UserScripts", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlUserScripts(); }); qmlRegisterSingletonType("org.kde.falkon", 1, 0, "ExternalJsObject", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new QmlExternalJsObject(); }); // ExtensionScheme qmlRegisterType("org.kde.falkon", 1, 0, "ExtensionScheme"); qmlRegisterUncreatableType("org.kde.falkon", 1, 0, "WebEngineUrlRequestJob", "Unable to register type: WebEngineUrlRequestJob"); // FileUtils qmlRegisterSingletonType("org.kde.falkon", 1, 0, "FileUtils", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { - Q_UNUSED(engine) Q_UNUSED(scriptEngine) - QString filePath = engine->rootContext()->contextProperty("__path__").toString(); + QmlEngine *qmlEngine = dynamic_cast(engine); + if (!qmlEngine) { + qWarning() << "Unable to cast QQmlEngine * to QmlEngine *"; + return nullptr; + } + QString filePath = qmlEngine->extensionPath(); return new QmlFileUtils(filePath); }); }