RSSFinder/rssfinder/main.qml
Juraj Oravec f710368b3b
Try to fix the polish loop
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2023-02-22 11:49:32 +01:00

149 lines
4.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
RowLayout {
spacing: 2
width: rssList.width
Button {
hoverEnabled: true
onClicked: Falkon.Tabs.addTab({
url: url,
windowId: Falkon.Windows.getCurrent()
})
clip: true
ToolTip.visible: hovered
ToolTip.text: i18n("Open in new tab")
Layout.fillWidth: true
Layout.fillHeight: true
contentItem: ColumnLayout {
Label {
font.bold: true
topPadding: 5
leftPadding: 5
text: title
}
Label {
leftPadding: 5
bottomPadding: 5
text: url
}
}
}
Button {
hoverEnabled: true
onClicked: Falkon.Clipboard.copy(url)
ToolTip.visible: hovered
ToolTip.text: i18n("Copy URL")
contentItem: Image {
source: 'clipboard.svg'
sourceSize.width: 50
sourceSize.height: 50
fillMode: Image.PreserveAspectFit
}
}
}
}
id: rssList
model: rssFinderObject.feeds
delegate: contactsDelegate
focus: true
spacing: 5
}
}
}
}
}