Warning, /network/falkon/src/scripts/helloqml/main.qml is written in an unsupported language. File is not indexed.

0001 import org.kde.falkon 1.0 as Falkon
0002 import QtQuick.Controls 2.3
0003 import QtQuick 2.3
0004 
0005 Falkon.PluginInterface {
0006 
0007     QtObject {
0008         id: helloQmlObject
0009         property int clickCount: 0
0010         signal clicked(int count)
0011     }
0012 
0013     Falkon.UserScript {
0014         id: testingHelloQmlUserScript
0015         name: 'testing-hello-qml'
0016         runsOnSubFrames: false
0017         sourceCode: Falkon.FileUtils.readAllFileContents('script.js')
0018         injectionPoint: Falkon.UserScript.DocumentReady
0019         worldId: Falkon.UserScript.ApplicationWorld
0020     }
0021 
0022     init: function(state, settingsPath){
0023         console.log(i18n('"Hello QML" plugin loaded'))
0024         Falkon.ExternalJsObject.registerExtraObject({
0025             id: 'helloQmlObject',
0026             object: helloQmlObject
0027         })
0028     }
0029 
0030     testPlugin: function() {
0031         return true
0032     }
0033 
0034     unload: function() {
0035         console.log(i18n('Bye!'))
0036     }
0037 
0038     // Point falkon to extension://helloqml to see Hello World
0039     Falkon.ExtensionScheme {
0040         name: 'helloqml'
0041         onRequestStarted: {
0042             request.reply({
0043                 contentType: 'text/html',
0044                 content: '<h1>Hello World</h1>'
0045             })
0046         }
0047     }
0048 
0049     Falkon.BrowserAction {
0050         name: 'helloqml-button'
0051         identity: 'helloqml-id'
0052         title: i18n('Testing QML Title')
0053         toolTip: i18n('Testing QML Tooltip')
0054         icon: 'extensions.svg'
0055         location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
0056         popup: Rectangle {
0057             property var borderMargin: 1
0058             property var imageWidth: 256
0059             property var imageHeight: 200
0060             property var buttonHeight: 40
0061 
0062             width: imageWidth + 2 * borderMargin
0063             height: imageHeight + buttonHeight + 2 * borderMargin
0064             color: 'black'
0065             Rectangle {
0066                 anchors.fill: parent
0067                 anchors.leftMargin: borderMargin
0068                 anchors.rightMargin: borderMargin
0069                 anchors.topMargin: borderMargin
0070                 anchors.bottomMargin: borderMargin
0071                 color: 'white'
0072                 Image {
0073                     id: image
0074                     source: 'qrc:/icons/other/startpage.svg'
0075                     anchors.left: parent.left
0076                     anchors.right: parent.right
0077                     anchors.top: parent.top
0078                 }
0079 
0080                 Button {
0081                     text: i18n('Click Me!')
0082                     height: buttonHeight
0083                     anchors.top: image.bottom
0084                     anchors.left: parent.left
0085                     anchors.right: parent.right
0086                     onClicked: {
0087                         helloQmlObject.clickCount += 1
0088                         helloQmlObject.clicked(helloQmlObject.clickCount)
0089                     }
0090                 }
0091             }
0092         }
0093     }
0094 
0095     Falkon.SideBar {
0096         name: 'helloqml-sidebar'
0097         title: i18n('Testing QML SideBar')
0098         icon: 'extensions.svg'
0099         checkable: true
0100         Rectangle {
0101             Image {
0102                 source: 'qrc:/icons/other/startpage.svg'
0103                 anchors.verticalCenter: parent.verticalCenter
0104                 anchors.left: parent.left
0105                 anchors.right: parent.right
0106             }
0107 
0108             Button {
0109                 text: i18n('Hello Qml Plugin')
0110                 anchors.left: parent.left
0111                 anchors.right: parent.right
0112                 anchors.bottom: parent.bottom
0113             }
0114         }
0115     }
0116 
0117     populateWebViewMenu: function(menu, webHitTestResult) {
0118         var text = 'My first qml plugin action'
0119         var action = menu.addAction({
0120             text: text,
0121             icon: 'extensions.svg'
0122         })
0123 
0124         action.triggered.connect(function() {
0125             Falkon.Notifications.create({
0126                 heading: i18n('Hello QML'),
0127                 message: i18n('First qml plugin action works :-)'),
0128                 icon: 'extensions.svg'
0129             })
0130         })
0131     }
0132 
0133     Falkon.Settings {
0134         id: settings
0135         name: 'HelloQML'
0136     }
0137 
0138     settingsWindow: Rectangle {
0139         id: window
0140         width: 256
0141         height: 200
0142         Image {
0143             id: image
0144             source: 'qrc:/icons/other/about.svg'
0145             anchors.top: parent.top
0146             anchors.left: parent.left
0147             anchors.right: parent.right
0148         }
0149         TextField {
0150             id: textField
0151             text: settings.value({key: 'text'})
0152             placeholderText: i18n('Enter text to save')
0153             width: 256
0154             height: 50
0155             anchors.top: image.bottom
0156             onTextChanged: function() {
0157                 button.text = i18n('Save')
0158             }
0159         }
0160         Button {
0161             id: button
0162             text: i18n('Save')
0163             width: 256
0164             height: 50
0165             anchors.top: textField.bottom
0166             onClicked: function() {
0167                 var res = settings.setValue({
0168                     key: 'text',
0169                     value: textField.text
0170                 })
0171                 if (res) {
0172                     button.text = i18n('Saved!')
0173                 } else {
0174                     button.text = i18n('Error occurred, try again!')
0175                 }
0176             }
0177         }
0178     }
0179 }