2021-11-25 20:27:58 +01:00
|
|
|
import QtQml 2.3
|
|
|
|
import QtQuick 2.7
|
|
|
|
import QtQuick.Layouts 1.2
|
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents3
|
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
|
|
import org.kde.kquickcontrolsaddons 2.0
|
|
|
|
import martchus.syncthingplasmoid 0.6 as SyncthingPlasmoid
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
id: toolBar
|
|
|
|
Layout.fillWidth: true
|
|
|
|
spacing: PlasmaCore.Units.smallSpacing
|
|
|
|
Layout.minimumHeight: units.iconSizes.medium
|
|
|
|
Layout.maximumHeight: units.iconSizes.medium
|
|
|
|
|
|
|
|
readonly property bool showExtraButtons: !(plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentDrawsPlasmoidHeading)
|
|
|
|
|
|
|
|
ToolButton {
|
|
|
|
id: connectButton
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "disconnected"
|
|
|
|
PropertyChanges {
|
|
|
|
target: connectButton
|
|
|
|
text: qsTr("Connect")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "refresh"
|
2023-06-20 23:21:21 +02:00
|
|
|
enabled: true
|
2021-11-25 20:27:58 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "connecting"
|
|
|
|
PropertyChanges {
|
|
|
|
target: connectButton
|
2023-06-20 23:21:21 +02:00
|
|
|
text: qsTr("Connecting …")
|
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "refresh"
|
|
|
|
enabled: false
|
2021-11-25 20:27:58 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "paused"
|
|
|
|
PropertyChanges {
|
|
|
|
target: connectButton
|
|
|
|
text: qsTr("Resume")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "play"
|
2023-06-20 23:21:21 +02:00
|
|
|
enabled: true
|
2021-11-25 20:27:58 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "idle"
|
|
|
|
PropertyChanges {
|
|
|
|
target: connectButton
|
|
|
|
text: qsTr("Pause")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "pause"
|
2023-06-20 23:21:21 +02:00
|
|
|
enabled: true
|
2021-11-25 20:27:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
state: {
|
|
|
|
switch (plasmoid.nativeInterface.connection.status) {
|
|
|
|
case SyncthingPlasmoid.Data.Disconnected:
|
2023-06-20 23:21:21 +02:00
|
|
|
return plasmoid.nativeInterface.connection.connecting ? "connecting" : "disconnected"
|
2021-11-25 20:27:58 +01:00
|
|
|
case SyncthingPlasmoid.Data.Reconnecting:
|
|
|
|
return "connecting";
|
|
|
|
case SyncthingPlasmoid.Data.Paused:
|
|
|
|
return "paused"
|
|
|
|
default:
|
|
|
|
return "idle"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
switch (plasmoid.nativeInterface.connection.status) {
|
|
|
|
case SyncthingPlasmoid.Data.Disconnected:
|
|
|
|
plasmoid.nativeInterface.connection.connect()
|
|
|
|
break
|
|
|
|
case SyncthingPlasmoid.Data.Reconnecting:
|
|
|
|
break
|
|
|
|
case SyncthingPlasmoid.Data.Paused:
|
|
|
|
plasmoid.nativeInterface.connection.resumeAllDevs()
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
plasmoid.nativeInterface.connection.pauseAllDevs()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: connectButton.text
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+Shift+P"
|
|
|
|
onActivated: connectButton.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: startStopButton
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "running"
|
|
|
|
PropertyChanges {
|
|
|
|
target: startStopButton
|
|
|
|
visible: true
|
|
|
|
text: qsTr("Stop")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "stop"
|
2021-11-25 20:27:58 +01:00
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: startStopToolTip
|
|
|
|
text: (plasmoid.nativeInterface.service.userScope ? "systemctl --user stop " : "systemctl stop ")
|
|
|
|
+ plasmoid.nativeInterface.service.unitName
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "stopped"
|
|
|
|
PropertyChanges {
|
|
|
|
target: startStopButton
|
|
|
|
visible: true
|
|
|
|
text: qsTr("Start")
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "play"
|
2021-11-25 20:27:58 +01:00
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: startStopToolTip
|
|
|
|
text: (plasmoid.nativeInterface.service.userScope ? "systemctl --user start " : "systemctl start ")
|
|
|
|
+ plasmoid.nativeInterface.service.unitName
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "irrelevant"
|
|
|
|
PropertyChanges {
|
|
|
|
target: startStopButton
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
state: {
|
|
|
|
var nativeInterface = plasmoid.nativeInterface
|
|
|
|
// the systemd unit status is only relevant when connected to the local instance
|
|
|
|
if (!nativeInterface.local
|
|
|
|
|| !nativeInterface.startStopEnabled) {
|
|
|
|
return "irrelevant"
|
|
|
|
}
|
|
|
|
// show start/stop button only when the configured unit is available
|
|
|
|
var service = nativeInterface.service
|
|
|
|
if (!service || !service.systemdAvailable) {
|
|
|
|
return "irrelevant"
|
|
|
|
}
|
|
|
|
return service.running ? "running" : "stopped"
|
|
|
|
}
|
|
|
|
onClicked: plasmoid.nativeInterface.service.toggleRunning()
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
id: startStopToolTip
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+Shift+S"
|
|
|
|
onActivated: {
|
|
|
|
if (startStopButton.visible) {
|
|
|
|
startStopButton.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolButton {
|
|
|
|
id: showNewNotifications
|
|
|
|
icon.name: "emblem-warning"
|
|
|
|
visible: plasmoid.nativeInterface.notificationsAvailable
|
|
|
|
onClicked: {
|
|
|
|
plasmoid.nativeInterface.showNotificationsDialog()
|
|
|
|
plasmoid.expanded = false
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: qsTr("Show new notifications")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+N"
|
|
|
|
onActivated: {
|
|
|
|
if (showNewNotifications.visible) {
|
|
|
|
showNewNotifications.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolButton {
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "info"
|
2021-11-25 20:27:58 +01:00
|
|
|
visible: showExtraButtons
|
|
|
|
onClicked: {
|
|
|
|
plasmoid.nativeInterface.showAboutDialog()
|
|
|
|
plasmoid.expanded = false
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: qsTr("About Syncthing Tray")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: showOwnIdButton
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "qrcode"
|
2021-11-25 20:27:58 +01:00
|
|
|
visible: showExtraButtons
|
|
|
|
onClicked: {
|
|
|
|
plasmoid.nativeInterface.showOwnDeviceId()
|
|
|
|
plasmoid.expanded = false
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: qsTr("Show own device ID")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+I"
|
|
|
|
onActivated: showOwnIdButton.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: showLogButton
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "file-text"
|
2021-11-25 20:27:58 +01:00
|
|
|
visible: showExtraButtons
|
|
|
|
onClicked: {
|
|
|
|
plasmoid.nativeInterface.showLog()
|
|
|
|
plasmoid.expanded = false
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: qsTr("Show Syncthing log")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+L"
|
|
|
|
onActivated: showLogButton.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: rescanAllDirsButton
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "refresh"
|
2021-11-25 20:27:58 +01:00
|
|
|
onClicked: plasmoid.nativeInterface.connection.rescanAllDirs()
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: qsTr("Rescan all directories")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+Shift+R"
|
|
|
|
onActivated: rescanAllDirsButton.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: settingsButton
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "cog"
|
2021-11-25 20:27:58 +01:00
|
|
|
visible: showExtraButtons
|
|
|
|
onClicked: {
|
|
|
|
plasmoid.nativeInterface.showSettingsDlg()
|
|
|
|
plasmoid.expanded = false
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: qsTr("Settings")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+S"
|
|
|
|
onActivated: settingsButton.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: webUIButton
|
2022-02-05 21:31:53 +01:00
|
|
|
icon.source: plasmoid.nativeInterface.faUrl + "syncthing"
|
2021-11-25 20:27:58 +01:00
|
|
|
onClicked: {
|
|
|
|
plasmoid.nativeInterface.showWebUI()
|
|
|
|
plasmoid.expanded = false
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ToolTip {
|
|
|
|
text: qsTr("Open Syncthing")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+W"
|
|
|
|
onActivated: webUIButton.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlasmaComponents3.ComboBox {
|
|
|
|
id: connectionConfigsMenu
|
|
|
|
model: plasmoid.nativeInterface.connectionConfigNames
|
|
|
|
visible: plasmoid.nativeInterface.connectionConfigNames.length > 1
|
|
|
|
currentIndex: plasmoid.nativeInterface.currentConnectionConfigIndex
|
|
|
|
onCurrentIndexChanged: plasmoid.nativeInterface.currentConnectionConfigIndex = currentIndex
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.maximumWidth: implicitWidth
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+Shift+C"
|
|
|
|
onActivated: connectionConfigsMenu.popup()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|