1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Added HelloQml Extension

Reviewers: drosca

Reviewed By: drosca

Subscribers: falkon

Tags: #falkon

Differential Revision: https://phabricator.kde.org/D14519
This commit is contained in:
Anmol Gautam 2018-10-02 03:06:10 +05:30
parent 011df43851
commit 0abde8b755
6 changed files with 293 additions and 0 deletions

View File

@ -9,6 +9,16 @@ function(install_python_script 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)

View File

@ -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

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="32" version="1.1" xmlns="http://www.w3.org/2000/svg" height="32" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">
<defs id="defs5455">
<linearGradient inkscape:collect="always" id="linearGradient4303">
<stop style="stop-color:#c6cdd1" id="stop4305"/>
<stop offset="1" style="stop-color:#e0e5e7" id="stop4307"/>
</linearGradient>
<linearGradient inkscape:collect="always" id="linearGradient4227">
<stop style="stop-color:#292c2f" id="stop4229"/>
<stop offset="1" style="stop-opacity:0" id="stop4231"/>
</linearGradient>
<linearGradient id="linearGradient3819">
<stop style="stop-color:#eff0f1" id="stop3821"/>
<stop offset="1" style="stop-color:#bdc3c7" id="stop3823"/>
</linearGradient>
<linearGradient inkscape:collect="always" id="linearGradient4303-3">
<stop style="stop-color:#197cf1" id="stop4305-6"/>
<stop offset="1" style="stop-color:#21c9fb" id="stop4307-4"/>
</linearGradient>
<linearGradient inkscape:collect="always" id="linearGradient5193" xlink:href="#linearGradient4303-3" y1="540.79797" y2="521.79797" x1="384.57144" gradientUnits="userSpaceOnUse" x2="409.57147" gradientTransform="matrix(1 0 0 1 -6.00005 4)"/>
<linearGradient inkscape:collect="always" id="linearGradient4903">
<stop style="stop-color:#eef1f2" id="stop4905"/>
<stop offset="1" style="stop-color:#f9fafb" id="stop4907"/>
</linearGradient>
<linearGradient inkscape:collect="always" id="linearGradient5324" xlink:href="#linearGradient4903" y1="537.24286" y2="507.798" x1="401.57144" gradientUnits="userSpaceOnUse" x2="384.57144" gradientTransform="matrix(1 0 0 1 -4.00005 5)"/>
<linearGradient inkscape:collect="always" xlink:href="#linearGradient4256-6" id="linearGradient6638" y1="534.79797" y2="510.798" gradientUnits="userSpaceOnUse" x2="0" gradientTransform="matrix(1 0 0 1 -182.85714 -77.1501)"/>
<linearGradient id="linearGradient4256-6">
<stop style="stop-color:#8cbdf8" id="stop4258-2"/>
<stop offset="1" style="stop-color:#d5e8ff" id="stop4260-8"/>
</linearGradient>
<linearGradient inkscape:collect="always" xlink:href="#linearGradient4227" id="linearGradient6640" y1="513.38367" x1="396.57144" y2="531.38367" gradientUnits="userSpaceOnUse" x2="412.57144" gradientTransform="matrix(1 0 0 1 -182.85714 -76.73579)"/>
<linearGradient inkscape:collect="always" xlink:href="#linearGradient4232" id="linearGradient4849" y1="43" y2="5" gradientUnits="userSpaceOnUse" x2="0" gradientTransform="matrix(1.0810811 0 0 1.0810811 199.76834 420.70195)"/>
<linearGradient id="linearGradient4232">
<stop style="stop-color:#3889e9" id="stop4234-0"/>
<stop offset="1" style="stop-color:#5ea5fb" id="stop4236"/>
</linearGradient>
<linearGradient inkscape:collect="always" id="linearGradient5464" xlink:href="#linearGradient4303" y1="539.79797" y2="503.798" x1="432.57144" gradientUnits="userSpaceOnUse" x2="412.57144" gradientTransform="matrix(1 0 0 1 -10.00005 4)"/>
<linearGradient inkscape:collect="always" id="linearGradient5324-8" xlink:href="#linearGradient4903" y1="536.79797" y2="509.3006" x1="384.57144" gradientUnits="userSpaceOnUse" x2="396.32709" gradientTransform="matrix(-1 0 0 1 805.14281 5)"/>
<linearGradient inkscape:collect="always" id="linearGradient4290-2">
<stop style="stop-color:#7cbaf8" id="stop4292"/>
<stop offset="1" style="stop-color:#f4fcff" id="stop4294"/>
</linearGradient>
<linearGradient inkscape:collect="always" id="linearGradient5785" xlink:href="#linearGradient4290-2" y1="34" y2="22.724428" x1="9" gradientUnits="userSpaceOnUse" x2="3.746097" gradientTransform="matrix(1 0 0 1 379.57138 505.798)"/>
</defs>
<metadata id="metadata5458"/>
<g inkscape:label="Capa 1" inkscape:groupmode="layer" id="layer1" transform="matrix(1 0 0 1 -384.57143 -515.798)">
<path inkscape:connector-curvature="0" style="fill:#2980b9;fill-rule:evenodd" id="path5195" d="m 397.57138,530.798 6,0 0,2 -6,6 z"/>
<path inkscape:connector-curvature="0" style="fill:#289769;fill-rule:evenodd" id="path5195-7-4-3-1" d="m 397.57138,537.798 6,-6 0,1 -6,6 z"/>
<path inkscape:connector-curvature="0" style="fill:url(#linearGradient5193);fill-rule:evenodd" id="path5167-5" d="m 384.57141,544.798 14,0 0,-9 2.5,-2.5 2.5,-2.5 -2.5,-2.5 -2.5,-2.5 0,-8 -14,0 z"/>
<path inkscape:connector-curvature="0" style="fill:#99a1a7;fill-rule:evenodd" id="path5195-7" d="m 408.57138,523.798 -6,0 0,4 6,6 z"/>
<path inkscape:connector-curvature="0" style="fill:#289769;fill-rule:evenodd" id="path5195-7-4-3" d="m 408.57138,532.798 -6,-6 0,1 6,6 z"/>
<path inkscape:connector-curvature="0" style="fill:url(#linearGradient5464);fill-rule:evenodd" id="path5167" d="m 416.57138,544.798 -14,0 0,-9 5,-5 -5,-5 0,-8 14,0 z"/>
<path inkscape:connector-curvature="0" style="fill:#2980b9;stroke-linejoin:round;stroke-width:0.5" id="rect5150-0" d="m 398.5714,543.798 -13.99997,0 0,1.99995 13.99997,0 z"/>
<path inkscape:connector-curvature="0" style="fill:#99a1a7;stroke-linejoin:round;stroke-width:0.5" id="rect5150" d="m 402.57139,543.798 14.00004,0 0,1.99995 -14.00004,0 z"/>
<path inkscape:connector-curvature="0" style="fill:#289769;stroke-linejoin:round;stroke-width:0.5" id="rect5150-30" d="m 402.57139,544.798 14.00004,0 0,0.99992 -14.00004,0 z"/>
<path inkscape:connector-curvature="0" style="fill:url(#linearGradient5324);opacity:0.2;fill-rule:evenodd" id="path5316" d="m 384.57143,519.798 0,1 4.5,0 2.5,2.71484 0,14.57032 -2.5,2.71484 -4.5,0 0,1 5,0 3,-3 0,-16 -3,-3 z"/>
<path inkscape:connector-curvature="0" style="fill:url(#linearGradient5324-8);fill-rule:evenodd" id="path5316-6" d="m 416.57138,519.798 0,22 -5,0 -3,-3 0,-16 3,-3 z"/>
<rect width="2" x="402.57138" y="539.79797" height="2" style="fill:#4c5154;stroke-linejoin:round;stroke-width:0.5" id="rect5589"/>
<rect width="2" x="402.57138" y="519.79797" height="2" style="fill:#4c5154;stroke-linejoin:round;stroke-width:0.5" id="rect5591"/>
<path inkscape:connector-curvature="0" style="fill:#289769;stroke-linejoin:round;stroke-width:0.5" id="rect5150-30-2" d="m 384.57145,544.798 13.99998,0 0,0.99992 -13.99998,0 z"/>
<rect width="4" x="411.57138" y="520.79797" height="1" style="fill:#4d4d4d;stroke-linejoin:round;stroke-width:0.5" id="rect5658"/>
<rect width="2" x="413.57138" y="522.79797" height="1" style="fill:#4d4d4d;stroke-linejoin:round;stroke-width:0.5" id="rect5660"/>
<rect width="1" x="411.57138" y="522.79797" height="1" style="fill:#4d4d4d;stroke-linejoin:round;stroke-width:0.5" id="rect5662"/>
<rect width="3" x="412.57138" y="524.79797" height="1" style="fill:#4d4d4d;stroke-linejoin:round;stroke-width:0.5" id="rect5664"/>
<path inkscape:connector-curvature="0" style="fill:url(#linearGradient5785);stroke-linejoin:round;stroke-width:0.5" id="rect5666" d="m 385.57138,534.798 0,5 1,0 0,-5 -1,0 z m 2,0 0,1 1,0 0,-1 -1,0 z m 0,2 0,1 1,0 0,-1 -1,0 z m 0,2 0,1 1,0 0,-1 -1,0 z"/>
<rect width="2" x="396.57138" y="519.79797" height="2" style="fill:#2980b9;stroke-linejoin:round;stroke-width:0.5" id="rect5591-8"/>
<rect width="2" x="396.57138" y="539.79797" height="2" style="fill:#2980b9;stroke-linejoin:round;stroke-width:0.5" id="rect5589-6"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@ -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: '<h1>Hello World</h1>'
})
}
}
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!')
}
}
}
}
}

View File

@ -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

View File

@ -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);
}