1
FalkonTutorials/qml/extensions/qml_tutorial_9/main.qml

128 lines
3.7 KiB
QML
Raw Normal View History

import org.kde.falkon 1.0 as Falkon
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.0
import QtQuick 2.3
Falkon.PluginInterface {
QtObject {
id: objectTutorial9
property ListModel windows: ListModel {}
}
init: function(state, settingsPath) {
console.log(i18n('"Tutorial9" plugin loaded'))
Falkon.Windows.created.connect(function(window) {
objectTutorial9.windows.append({
"id": window.id.toString(),
"window": window,
"check": false
})
})
if (state == 1 /* LateInitState */) {
var windowsAll = Falkon.Windows.getAll()
console.log("Creating windows")
for (var i = 0; i < windowsAll.length; ++i) {
objectTutorial9.windows.append({
"id": windowsAll[i].id.toString(),
"window": window,
"check": false
})
}
}
Falkon.Windows.removed.connect(function(window) {
for (var i = 0; i < objectTutorial9.windows.count; ++i) {
if (objectTutorial9.windows.get(i)["window"] == window) {
objectTutorial9.windows.remove(i, 1)
}
}
})
}
testPlugin: function() {
return true
}
unload: function() {
console.log(i18n('"Tutorial9" plugin unloaded'))
}
Falkon.SideBar {
name: 'qml-tutorial9-sidebar'
title: i18n('Tutorial 9 - QML SideBar')
icon: 'falkon'
checkable: true
shortcut: 'Ctrl+Shift+Alt+W'
Rectangle {
ScrollView {
id: scroll_windows
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: button_add.top
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
ListView {
id: listWindows
Component {
id: contactsDelegate
CheckBox {
id: checkSelected
checked: check
text: "Id: " + id + " Tabs: " + Falkon.Windows.get(id).tabs.length
onCheckStateChanged: {
objectTutorial9.windows.setProperty(id, "check", checked)
}
}
}
model: objectTutorial9.windows
delegate: contactsDelegate
focus: true
}
}
Button {
id: button_add
text: i18n('Add Window')
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: button_remove.top
onClicked: function() {
Falkon.Windows.create({
url: "falkon:start"
})
}
}
Button {
id: button_remove
text: i18n('Remove Selected Windows')
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
onClicked: function() {
for (var i = 0; i < objectTutorial9.windows.count; ++i) {
if (objectTutorial9.windows.get(i)["check"]) {
Falkon.Windows.remove(objectTutorial9.windows.get(i)["id"])
}
}
}
}
}
}
}