RSSFinder/rssfinder/main.qml
Juraj Oravec 314b3d56f2
Redo the popup window to use styleable components
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2022-06-19 23:50:43 +02:00

125 lines
3.6 KiB
QML

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: rssFinderObject
property ListModel feeds: ListModel {}
property string jsFinder
}
init: function(state, settingsPath) {
console.log(i18n('"RSSFinder" plugin is loading'))
rssFinderObject.jsFinder = Falkon.FileUtils.readAllFileContents('finder.js')
if (rssFinderObject.jsFinder.length == 0) {
console.log(i18n('"RSSFinder" Unable to load "finder.js""'))
}
console.log(i18n('"RSSFinder" plugin loaded'))
}
testPlugin: function() {
return true
}
unload: function() {
console.log(i18n('"RSSFinder" plugin unloaded'))
}
function findCurrentTab(window) {
for (var i = 0; i < window.tabs.length; ++i) {
if (window.tabs[i].current) {
return window.tabs[i]
}
}
}
function findFeeds() {
if (rssFinderObject.jsFinder.length == 0) {
return
}
var window = Falkon.Windows.getCurrent()
var currentTab = findCurrentTab(window)
var result = currentTab.execJavaScript(rssFinderObject.jsFinder)
rssFinderObject.feeds.clear()
for (var link of result.links) {
rssFinderObject.feeds.append({
"title": link.title,
"url": link.url
})
}
}
Falkon.BrowserAction {
name: 'RSS Finder'
identity: 'rssfinder-id'
title: i18n('RSS Finder')
toolTip: i18n('RSS Finder')
icon: 'rss.svg'
location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
onClicked: findFeeds()
popup: Pane {
id: mainPane
width: 500
height: 200
ScrollView {
width: mainPane.width
height: mainPane.height
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
ListView {
Component {
id: contactsDelegate
Button {
hoverEnabled: true
onClicked: Falkon.Clipboard.copy(url)
width: rssList.width
height: wrapper.height
ToolTip.delay: 1000
ToolTip.timeout: 5000
ToolTip.visible: hovered
ToolTip.text: i18n("Click to copy URL")
ColumnLayout {
id: wrapper
spacing: 2
Label {
font.bold: true
text: title
}
Label {
text: url
}
}
}
}
id: rssList
model: rssFinderObject.feeds
delegate: contactsDelegate
focus: true
spacing: 5
}
}
}
}
}