2017-09-08 16:59:53 +02:00
|
|
|
import QtQml 2.2
|
2021-11-25 20:27:58 +01:00
|
|
|
import QtQuick 2.8
|
2022-01-24 15:08:12 +01:00
|
|
|
import QtQuick.Layouts 1.3
|
2021-11-25 20:27:58 +01:00
|
|
|
import QtQuick.Controls 2.15 as QQ2
|
2017-08-29 23:58:49 +02:00
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
|
|
import org.kde.plasma.extras 2.0 as PlasmaExtras
|
2020-11-27 19:09:47 +01:00
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents3
|
2017-08-29 23:58:49 +02:00
|
|
|
|
2022-08-25 22:33:30 +02:00
|
|
|
PlasmaExtras.Representation {
|
|
|
|
// disable margins as they don't look good together with the scroll view
|
|
|
|
// note: Would be collapsed automatically if the scroll view was the immediate content item.
|
|
|
|
collapseMarginsHint: true
|
|
|
|
|
2021-12-01 18:53:23 +01:00
|
|
|
// header ("toolbar" with buttons and combo box) and footer ("tabbar")
|
2021-11-25 20:27:58 +01:00
|
|
|
header: PlasmaExtras.PlasmoidHeading {
|
|
|
|
ToolBar {
|
|
|
|
id: toolbar
|
|
|
|
width: parent.width
|
|
|
|
}
|
|
|
|
}
|
2021-12-01 18:53:23 +01:00
|
|
|
footer: PlasmaExtras.PlasmoidHeading {
|
|
|
|
spacing: 0
|
2022-01-02 01:33:29 +01:00
|
|
|
topPadding: 0
|
2021-12-01 18:53:23 +01:00
|
|
|
height: units.iconSizes.medium
|
|
|
|
PlasmaComponents3.TabBar {
|
|
|
|
id: tabBar
|
|
|
|
readonly property double buttonWidth: parent.width / count
|
|
|
|
position: PlasmaComponents3.TabBar.Footer
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
TabButton {
|
|
|
|
id: dirsTabButton
|
|
|
|
text: qsTr("Directories")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "folder"
|
2021-12-01 18:53:23 +01:00
|
|
|
width: tabBar.buttonWidth
|
|
|
|
}
|
|
|
|
TabButton {
|
|
|
|
id: devsTabButton
|
|
|
|
text: qsTr("Devices")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "sitemap"
|
2021-12-01 18:53:23 +01:00
|
|
|
width: tabBar.buttonWidth
|
|
|
|
}
|
|
|
|
TabButton {
|
|
|
|
id: downloadsTabButton
|
|
|
|
text: qsTr("Downloads")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "download"
|
2021-12-01 18:53:23 +01:00
|
|
|
width: tabBar.buttonWidth
|
|
|
|
}
|
|
|
|
TabButton {
|
|
|
|
id: recentChangesTabButton
|
|
|
|
text: qsTr("History")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "history"
|
2021-12-01 18:53:23 +01:00
|
|
|
width: tabBar.buttonWidth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 21:35:56 +02:00
|
|
|
|
2021-11-25 20:27:58 +01:00
|
|
|
// define functions to locate the current page and filter
|
|
|
|
function findCurrentPage() {
|
|
|
|
switch (tabBar.currentIndex) {
|
|
|
|
case 0: return directoriesPage
|
|
|
|
case 1: return devicesPage
|
|
|
|
case 2: return downloadsPage
|
|
|
|
case 3: return recentChangesPage
|
|
|
|
default: return directoriesPage
|
2019-11-30 18:43:24 +01:00
|
|
|
}
|
2017-09-18 20:29:36 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
function findCurrentFilter() {
|
|
|
|
return findCurrentPage().filter
|
|
|
|
}
|
2017-09-18 20:29:36 +02:00
|
|
|
|
2017-10-04 00:31:51 +02:00
|
|
|
// define shortcuts to trigger actions for currently selected item
|
|
|
|
function clickCurrentItemButton(buttonName) {
|
2021-11-25 20:27:58 +01:00
|
|
|
findCurrentPage().view.clickCurrentItemButton(buttonName)
|
2017-10-04 00:31:51 +02:00
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+R"
|
|
|
|
onActivated: clickCurrentItemButton("rescanButton")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+P"
|
|
|
|
onActivated: clickCurrentItemButton("resumePauseButton")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+O"
|
|
|
|
onActivated: clickCurrentItemButton("openButton")
|
|
|
|
}
|
|
|
|
|
2021-12-01 18:53:23 +01:00
|
|
|
// main contents
|
2021-11-25 20:27:58 +01:00
|
|
|
FocusScope {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.topMargin: PlasmaCore.Units.smallSpacing * 2
|
2019-03-19 22:55:40 +01:00
|
|
|
|
2022-01-02 01:26:10 +01:00
|
|
|
TinyButton {
|
|
|
|
id: searchButton
|
|
|
|
anchors.right: mainLayout.right
|
2022-09-06 10:54:04 +02:00
|
|
|
anchors.rightMargin: PlasmaCore.Units.smallSpacing * 2
|
2022-01-02 01:26:10 +01:00
|
|
|
anchors.verticalCenter: infoLayout.verticalCenter
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "search"
|
2022-01-02 01:26:10 +01:00
|
|
|
width: PlasmaCore.Units.iconSizes.smallMedium
|
|
|
|
height: width
|
|
|
|
enabled: tabBar.currentIndex === 0
|
|
|
|
opacity: enabled ? 1.0 : 0.25
|
|
|
|
tooltip: qsTr("Toggle filter")
|
|
|
|
onClicked: {
|
|
|
|
var filter = findCurrentFilter()
|
|
|
|
if (!filter) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (!filter.explicitelyShown) {
|
|
|
|
filter.explicitelyShown = true
|
|
|
|
filter.forceActiveFocus()
|
|
|
|
} else {
|
|
|
|
filter.explicitelyShown = false
|
|
|
|
filter.text = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-25 20:27:58 +01:00
|
|
|
ColumnLayout {
|
2022-01-02 01:26:10 +01:00
|
|
|
id: mainLayout
|
2021-11-25 20:27:58 +01:00
|
|
|
anchors.fill: parent
|
2022-01-02 01:26:10 +01:00
|
|
|
spacing: 0
|
2017-10-01 17:54:11 +02:00
|
|
|
|
2021-11-25 20:27:58 +01:00
|
|
|
// ensure keyboard events can be received after initialization
|
|
|
|
Component.onCompleted: forceActiveFocus()
|
2017-08-29 23:58:49 +02:00
|
|
|
|
2021-11-25 20:27:58 +01:00
|
|
|
// define custom key handling for switching tabs, selecting items and filtering
|
|
|
|
function sendKeyEventToFilter(event) {
|
|
|
|
var filter = findCurrentFilter()
|
|
|
|
if (!filter || event.text === "" || filter.activeFocus) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (event.key === Qt.Key_Backspace && filter.text === "") {
|
|
|
|
filter.explicitelyShown = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (event.matches(StandardKey.Paste)) {
|
|
|
|
filter.paste()
|
|
|
|
} else {
|
|
|
|
filter.text = ""
|
|
|
|
filter.text += event.text
|
|
|
|
}
|
|
|
|
filter.forceActiveFocus()
|
|
|
|
}
|
|
|
|
Keys.onPressed: {
|
|
|
|
// note: event only received after clicking the tab buttons in plasmoidviewer
|
|
|
|
// but works as expected in plasmashell
|
|
|
|
switch (event.key) {
|
|
|
|
case Qt.Key_Up:
|
|
|
|
switch (event.modifiers) {
|
|
|
|
case Qt.NoModifier:
|
|
|
|
// select previous item in current tab
|
|
|
|
findCurrentPage().view.decrementCurrentIndex()
|
|
|
|
break
|
|
|
|
case Qt.ShiftModifier:
|
|
|
|
// select previous connection
|
|
|
|
--plasmoid.nativeInterface.currentConnectionConfigIndex
|
|
|
|
break
|
2020-05-25 18:39:00 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
break
|
|
|
|
case Qt.Key_Down:
|
|
|
|
switch (event.modifiers) {
|
|
|
|
case Qt.NoModifier:
|
|
|
|
// select next item in current tab
|
|
|
|
findCurrentPage().view.incrementCurrentIndex()
|
|
|
|
break
|
|
|
|
case Qt.ShiftModifier:
|
|
|
|
// select previous connection
|
|
|
|
++plasmoid.nativeInterface.currentConnectionConfigIndex
|
|
|
|
break
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
break
|
|
|
|
case Qt.Key_Left:
|
|
|
|
// select previous tab
|
|
|
|
tabBar.currentIndex = tabBar.currentIndex > 0 ? tabBar.currentIndex - 1 : 3
|
|
|
|
break
|
|
|
|
case Qt.Key_Right:
|
|
|
|
// select next tab
|
|
|
|
tabBar.currentIndex = tabBar.currentIndex < 3 ? tabBar.currentIndex + 1 : 0
|
|
|
|
break
|
|
|
|
case Qt.Key_Enter:
|
|
|
|
|
|
|
|
// fallthrough
|
|
|
|
case Qt.Key_Return:
|
|
|
|
// toggle expanded state of current item
|
|
|
|
var currentItem = findCurrentPage().view.currentItem
|
|
|
|
if (currentItem) {
|
|
|
|
currentItem.expanded = !currentItem.expanded
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
break
|
|
|
|
case Qt.Key_Escape:
|
|
|
|
var filter = findCurrentFilter()
|
|
|
|
if (filter && filter.text !== "") {
|
|
|
|
// reset filter
|
|
|
|
filter.explicitelyShown = false
|
|
|
|
filter.text = ""
|
|
|
|
event.accepted = true
|
|
|
|
} else {
|
|
|
|
// hide plasmoid
|
|
|
|
plasmoid.expanded = false
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2017-09-09 21:40:00 +02:00
|
|
|
break
|
2021-11-25 20:27:58 +01:00
|
|
|
case Qt.Key_1:
|
|
|
|
tabBar.currentIndex = 0
|
2020-05-25 18:39:00 +02:00
|
|
|
break
|
2021-11-25 20:27:58 +01:00
|
|
|
case Qt.Key_2:
|
|
|
|
tabBar.currentIndex = 1
|
2017-09-09 21:40:00 +02:00
|
|
|
break
|
2021-11-25 20:27:58 +01:00
|
|
|
case Qt.Key_3:
|
|
|
|
tabBar.currentIndex = 2
|
2017-09-09 21:40:00 +02:00
|
|
|
break
|
2021-11-25 20:27:58 +01:00
|
|
|
case Qt.Key_4:
|
|
|
|
tabBar.currentIndex = 3
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
sendKeyEventToFilter(event)
|
|
|
|
return
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
event.accepted = true
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2020-11-27 19:09:47 +01:00
|
|
|
|
2021-11-25 20:27:58 +01:00
|
|
|
// global statistics and traffic
|
|
|
|
GridLayout {
|
2022-01-02 01:26:10 +01:00
|
|
|
id: infoLayout
|
2022-09-01 22:32:17 +02:00
|
|
|
Layout.leftMargin: PlasmaCore.Units.smallSpacing * 2
|
|
|
|
Layout.rightMargin: PlasmaCore.Units.smallSpacing * 2
|
2021-11-25 20:27:58 +01:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: false
|
2022-01-02 01:26:10 +01:00
|
|
|
Layout.maximumWidth: parent.width
|
|
|
|
columns: 4
|
2021-11-25 20:27:58 +01:00
|
|
|
rowSpacing: 1
|
|
|
|
columnSpacing: 4
|
|
|
|
|
|
|
|
Image {
|
|
|
|
Layout.preferredWidth: 16
|
|
|
|
Layout.preferredHeight: 16
|
|
|
|
height: 16
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2022-02-05 21:31:53 +01:00
|
|
|
source: plasmoid.nativeInterface.faUrl + "globe"
|
|
|
|
cache: false
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
StatisticsView {
|
|
|
|
Layout.leftMargin: 4
|
|
|
|
statistics: plasmoid.nativeInterface.globalStatistics
|
|
|
|
context: qsTr("Global")
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
IconLabel {
|
2022-01-02 01:26:10 +01:00
|
|
|
Layout.leftMargin: 5
|
2022-02-05 21:31:53 +01:00
|
|
|
iconSource: plasmoid.nativeInterface.faUrl + "cloud-download"
|
2021-11-25 20:27:58 +01:00
|
|
|
iconOpacity: plasmoid.nativeInterface.hasIncomingTraffic ? 1.0 : 0.5
|
|
|
|
text: plasmoid.nativeInterface.incomingTraffic
|
|
|
|
tooltip: qsTr("Global incoming traffic")
|
2017-09-08 16:59:53 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.rowSpan: 2
|
2017-10-04 00:31:51 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
Image {
|
|
|
|
Layout.preferredWidth: 16
|
|
|
|
Layout.preferredHeight: 16
|
|
|
|
height: 16
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2022-02-05 21:31:53 +01:00
|
|
|
source: plasmoid.nativeInterface.faUrl + "home"
|
|
|
|
cache: false
|
2019-03-19 22:55:40 +01:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
StatisticsView {
|
|
|
|
Layout.leftMargin: 4
|
|
|
|
statistics: plasmoid.nativeInterface.localStatistics
|
|
|
|
context: qsTr("Local")
|
2019-03-19 22:55:40 +01:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
IconLabel {
|
2022-01-02 01:26:10 +01:00
|
|
|
Layout.leftMargin: 5
|
2022-02-05 21:31:53 +01:00
|
|
|
iconSource: plasmoid.nativeInterface.faUrl + "cloud-upload"
|
2021-11-25 20:27:58 +01:00
|
|
|
iconOpacity: plasmoid.nativeInterface.hasOutgoingTraffic ? 1.0 : 0.5
|
|
|
|
text: plasmoid.nativeInterface.outgoingTraffic
|
|
|
|
tooltip: qsTr("Global outgoing traffic")
|
2020-01-18 16:37:20 +01:00
|
|
|
}
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
2021-11-25 20:27:58 +01:00
|
|
|
|
2021-12-01 18:53:23 +01:00
|
|
|
// tab content
|
|
|
|
StackLayout {
|
|
|
|
id: tabLayout
|
|
|
|
currentIndex: tabBar.currentIndex
|
2021-11-25 20:27:58 +01:00
|
|
|
Layout.fillWidth: true
|
2019-03-19 22:55:40 +01:00
|
|
|
Layout.fillHeight: true
|
2021-12-01 18:53:23 +01:00
|
|
|
DirectoriesPage {
|
|
|
|
id: directoriesPage
|
2019-03-19 22:55:40 +01:00
|
|
|
}
|
2021-12-01 18:53:23 +01:00
|
|
|
DevicesPage {
|
|
|
|
id: devicesPage
|
2021-11-25 20:27:58 +01:00
|
|
|
}
|
2021-12-01 18:53:23 +01:00
|
|
|
DownloadsPage {
|
|
|
|
id: downloadsPage
|
|
|
|
}
|
|
|
|
RecentChangesPage {
|
|
|
|
id: recentChangesPage
|
2021-11-13 22:51:04 +01:00
|
|
|
}
|
2020-01-18 16:37:20 +01:00
|
|
|
}
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|