1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00
This commit is contained in:
Anmol Gautam 2018-08-06 19:58:31 +05:30
parent 45ce83641c
commit d39a16fb43
16 changed files with 258 additions and 27 deletions

3
cmake/config.h.in Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#define HAVE_LIBINTL 1

View File

@ -9,3 +9,5 @@
/* Disable DBus support */
#cmakedefine DISABLE_DBUS
#define HAVE_LIBINTL LibIntl_FOUND

View File

@ -157,6 +157,7 @@ set(SRCS ${SRCS}
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
@ -334,11 +335,6 @@ qt5_add_resources(SRCS
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})

View File

@ -22,46 +22,74 @@ 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;
}

View File

@ -69,6 +69,8 @@ public:
quint32 nativeVirtualKey() const;
QString text() const;
void makeNull();
private:
QKeyEvent *m_keyEvent;
};

View File

@ -27,60 +27,101 @@ QmlMouseEvent::QmlMouseEvent(QMouseEvent *mouseEvent, QObject *parent)
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;
}

View File

@ -88,6 +88,8 @@ public:
int x() const;
int y() const;
void makeNull();
private:
QMouseEvent *m_mouseEvent;
};

View File

@ -27,70 +27,117 @@ QmlWheelEvent::QmlWheelEvent(QWheelEvent *wheelEvent, QObject *parent)
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;
}

View File

@ -98,6 +98,8 @@ public:
int source() const;
int x() const;
int y() const;
void makeNull();
private:
QWheelEvent *m_wheelEvent;
};

View File

@ -22,9 +22,7 @@
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();
}

View File

@ -0,0 +1,43 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "qmlengine.h"
QmlEngine::QmlEngine(QObject *parent)
: QQmlEngine(parent)
{
}
QString QmlEngine::extensionName()
{
return m_extensionName;
}
void QmlEngine::setExtensionName(const QString &name)
{
m_extensionName = name;
}
QString QmlEngine::extensionPath()
{
return m_extensionPath;
}
void QmlEngine::setExtensionPath(const QString &path)
{
m_extensionPath = path;
}

View File

@ -0,0 +1,33 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#pragma once
#include <QQmlEngine>
class QmlEngine : public QQmlEngine
{
public:
explicit QmlEngine(QObject *parent = nullptr);
QString extensionName();
void setExtensionName(const QString &name);
QString extensionPath();
void setExtensionPath(const QString &path);
private:
QString m_extensionName;
QString m_extensionPath;
};

View File

@ -132,10 +132,12 @@ bool QmlPluginInterface::mouseDoubleClick(Qz::ObjectName type, QObject *obj, QMo
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;
}
@ -145,10 +147,12 @@ bool QmlPluginInterface::mousePress(Qz::ObjectName type, QObject *obj, QMouseEve
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;
}
@ -158,10 +162,12 @@ bool QmlPluginInterface::mouseRelease(Qz::ObjectName type, QObject *obj, QMouseE
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;
}
@ -171,10 +177,12 @@ bool QmlPluginInterface::mouseMove(Qz::ObjectName type, QObject *obj, QMouseEven
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;
}
@ -184,10 +192,12 @@ bool QmlPluginInterface::wheelEvent(Qz::ObjectName type, QObject *obj, QWheelEve
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;
}
@ -197,10 +207,12 @@ bool QmlPluginInterface::keyPress(Qz::ObjectName type, QObject *obj, QKeyEvent *
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;
}
@ -210,10 +222,12 @@ bool QmlPluginInterface::keyRelease(Qz::ObjectName type, QObject *obj, QKeyEvent
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;
}

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "qmlpluginloader.h"
#include "qmlengine.h"
#include <QQmlContext>
QmlPluginLoader::QmlPluginLoader(const QString &path)
@ -53,12 +54,12 @@ QmlPluginInterface *QmlPluginLoader::instance() const
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);
}

View File

@ -22,6 +22,8 @@
#include "qmlplugininterface.h"
class QmlEngine;
class QmlPluginLoader : public QObject
{
Q_OBJECT
@ -33,7 +35,7 @@ public:
void setName(const QString &name);
private:
QString m_path;
QQmlEngine *m_engine;
QmlEngine *m_engine;
QQmlComponent *m_component;
QmlPluginInterface *m_interface;

View File

@ -17,6 +17,7 @@
* ============================================================ */
#include "qmlplugins.h"
#include "qmlplugininterface.h"
#include "qmlengine.h"
#include "api/bookmarks/qmlbookmarktreenode.h"
#include "api/bookmarks/qmlbookmarks.h"
#include "api/topsites/qmlmostvisitedurl.h"
@ -49,7 +50,9 @@
#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
@ -114,10 +117,14 @@ void QmlPlugins::registerQmlTypes()
// Notifications
qmlRegisterSingletonType<QmlNotifications>("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<QmlEngine *>(engine);
if (!qmlEngine) {
qWarning() << "Unable to cast QQmlEngine * to QmlEngine *";
return nullptr;
}
QString filePath = qmlEngine->extensionPath();
auto *object = new QmlNotifications();
object->setPluginPath(filePath);
@ -173,11 +180,17 @@ void QmlPlugins::registerQmlTypes()
// WheelEvents
qmlRegisterUncreatableType<QmlWheelEvent>("org.kde.falkon", 1, 0, "WheelEvent", "Unable to register type: WheelEvent");
#ifdef LibIntl_FOUND
#ifdef HAVE_LIBINTL
// i18n
qmlRegisterSingletonType<QmlI18n>("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<QmlEngine *>(engine);
if (!qmlEngine) {
qWarning() << "Unable to cast QQmlEngine * to QmlEngine *";
return nullptr;
}
QString pluginName = qmlEngine->extensionName();
return new QmlI18n(pluginName);
});
#endif
@ -206,10 +219,14 @@ void QmlPlugins::registerQmlTypes()
// FileUtils
qmlRegisterSingletonType<QmlFileUtils>("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<QmlEngine *>(engine);
if (!qmlEngine) {
qWarning() << "Unable to cast QQmlEngine * to QmlEngine *";
return nullptr;
}
QString filePath = qmlEngine->extensionPath();
return new QmlFileUtils(filePath);
});