diff --git a/src/scripts/CMakeLists.txt b/src/scripts/CMakeLists.txt index 8c143f0a..6e18917f 100644 --- a/src/scripts/CMakeLists.txt +++ b/src/scripts/CMakeLists.txt @@ -1,14 +1,24 @@ function(install_python_script name) if (ENABLE_PYTHON_PLUGINS) install( DIRECTORY ${name} DESTINATION "${FALKON_INSTALL_PLUGINDIR}/python" FILES_MATCHING PATTERN "*" PATTERN "Messages.sh" EXCLUDE ) install(FILES i18n.py DESTINATION "${FALKON_INSTALL_PLUGINDIR}/python/${name}") endif() endfunction() +function(install_qml_script name) + install( + DIRECTORY ${name} + DESTINATION "${FALKON_INSTALL_PLUGINDIR}/qml" + FILES_MATCHING PATTERN "*" PATTERN "Messages.sh" EXCLUDE + ) +endfunction() + install_python_script(hellopython) install_python_script(runaction) install_python_script(middleclickloader) + +install_qml_script(helloqml) diff --git a/src/scripts/helloqml/Messages.sh b/src/scripts/helloqml/Messages.sh new file mode 100755 index 00000000..bcb9da94 --- /dev/null +++ b/src/scripts/helloqml/Messages.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +XGETTEXT_FLAGS_QML="\ +--copyright-holder=This_file_is_part_of_KDE \ +--msgid-bugs-address=http://bugs.kde.org \ +--from-code=UTF-8 \ +-L javascript \ +-ki18n:1 -ki18np:1,2 \ +" + +$XGETTEXT_PROGRAM $XGETTEXT_FLAGS_QML `find . -name '*.qml' -o -name '*.js'` -o $podir/falkon_helloqml.pot diff --git a/src/scripts/helloqml/extensions.svg b/src/scripts/helloqml/extensions.svg new file mode 100644 index 00000000..702d712f --- /dev/null +++ b/src/scripts/helloqml/extensions.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/scripts/helloqml/helloqml.qml b/src/scripts/helloqml/helloqml.qml new file mode 100644 index 00000000..054faf37 --- /dev/null +++ b/src/scripts/helloqml/helloqml.qml @@ -0,0 +1,180 @@ +import org.kde.falkon 1.0 as Falkon +import QtQuick.Controls 2.3 +import QtQuick 2.3 + +Falkon.PluginInterface { + + QtObject { + id: helloQmlObject + property int clickCount: 0 + signal clicked(int count) + } + + Falkon.UserScript { + id: testingHelloQmlUserScript + name: 'testing-hello-qml' + runsOnSubFrames: false + sourceCode: Falkon.FileUtils.readAllFileContents('script.js') + injectionPoint: Falkon.UserScript.DocumentReady + worldId: Falkon.UserScript.ApplicationWorld + } + + init: function(state, settingsPath){ + console.log(i18n('"Hello QML" plugin loaded')) + Falkon.ExternalJsObject.registerExtraObject({ + id: 'helloQmlObject', + object: helloQmlObject + }) + Falkon.UserScripts.insert(testingHelloQmlUserScript) + } + + testPlugin: function() { + return true + } + + unload: function() { + console.log(i18n('Bye!')) + } + + // Point falkon to extension://helloqml to see Hello World + Falkon.ExtensionScheme { + name: 'helloqml' + onRequestStarted: { + request.reply({ + contentType: 'text/html', + content: '

Hello World

' + }) + } + } + + Falkon.BrowserAction { + name: 'helloqml-button' + identity: 'helloqml-id' + title: i18n('Testing QML Title') + toolTip: i18n('Testing QML Tooltip') + icon: 'extensions.svg' + location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar + popup: Rectangle { + property var borderMargin: 1 + property var imageWidth: 256 + property var imageHeight: 200 + property var buttonHeight: 40 + + width: imageWidth + 2 * borderMargin + height: imageHeight + buttonHeight + 2 * borderMargin + color: 'black' + Rectangle { + anchors.fill: parent + anchors.leftMargin: borderMargin + anchors.rightMargin: borderMargin + anchors.topMargin: borderMargin + anchors.bottomMargin: borderMargin + color: 'white' + Image { + id: image + source: 'qrc:/icons/other/startpage.svg' + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + } + + Button { + text: i18n('Click Me!') + height: buttonHeight + anchors.top: image.bottom + anchors.left: parent.left + anchors.right: parent.right + onClicked: { + helloQmlObject.clickCount += 1 + helloQmlObject.clicked(helloQmlObject.clickCount) + } + } + } + } + } + + Falkon.SideBar { + name: 'helloqml-sidebar' + title: i18n('Testing QML SideBar') + icon: 'extensions.svg' + checkable: true + Rectangle { + Image { + source: 'qrc:/icons/other/startpage.svg' + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.right: parent.right + } + + Button { + text: i18n('Hello Qml Plugin') + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + } + } + } + + populateWebViewMenu: function(menu, webHitTestResult) { + var text = 'My first qml plugin action' + var action = menu.addAction({ + text: text, + icon: 'extensions.svg' + }) + + action.triggered.connect(function() { + Falkon.Notifications.create({ + heading: i18n('Hello QML'), + message: i18n('First qml plugin action works :-)'), + icon: 'extensions.svg' + }) + }) + } + + Falkon.Settings { + id: settings + name: 'HelloQML' + } + + settingsWindow: Rectangle { + id: window + width: 256 + height: 200 + Image { + id: image + source: 'qrc:/icons/other/about.svg' + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + } + TextField { + id: textField + text: settings.value({key: 'text'}) + placeholderText: i18n('Enter text to save') + width: 256 + height: 50 + anchors.top: image.bottom + onTextChanged: function() { + button.text = i18n('Save') + } + } + Button { + id: button + text: i18n('Save') + width: 256 + height: 50 + anchors.top: textField.bottom + onClicked: function() { + var res = settings.setValue({ + key: 'text', + value: textField.text + }) + if (res) { + button.text = i18n('Saved!') + } else { + button.text = i18n('Error occurred, try again!') + } + } + } + } +} diff --git a/src/scripts/helloqml/metadata.desktop b/src/scripts/helloqml/metadata.desktop new file mode 100644 index 00000000..19d00045 --- /dev/null +++ b/src/scripts/helloqml/metadata.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Hello Qml +Comment=Sample Qml Plugin +Icon= +Type=Service +X-Falkon-Author=Anmol Gautam +X-Falkon-Email=tarptaeya@gmail.com +X-Falkon-Version=0.1.0 +X-Falkon-Settings=true +X-Falkon-EntryPoint=helloqml.qml diff --git a/src/scripts/helloqml/script.js b/src/scripts/helloqml/script.js new file mode 100644 index 00000000..c3280f8f --- /dev/null +++ b/src/scripts/helloqml/script.js @@ -0,0 +1,11 @@ +function init() { + external.extra.helloQmlObject.clicked.connect(function(count){ + alert('You clicked ' + count + ' times') + }) +} + +if (window._falkon_external) { + init(); +} else { + document.addEventListener("_falkon_external_created", init); +}