RSSFinder/rssfinder/main.qml
Juraj Oravec 86747dbadc
Move site js code to separate file "finder.js"
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2022-03-12 02:15:24 +01:00

111 lines
3.0 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'
location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
onClicked: findFeeds()
popup: ScrollView {
id: popupWindow
width: 500
height: 200
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
ListView {
Component {
id: contactsDelegate
Button {
hoverEnabled: true
width: popupWindow.width
onClicked: Falkon.Clipboard.copy(url)
ToolTip.delay: 1000
ToolTip.timeout: 5000
ToolTip.visible: hovered
ToolTip.text: i18n("Click to copy URL")
ColumnLayout {
id: wrapper
spacing: 0
Text {
font.bold: true
text: title
}
Text {
text: url
}
}
}
}
model: rssFinderObject.feeds
delegate: contactsDelegate
focus: true
}
}
}
}