3.3 KiB · text History e43831b
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.components as PlasmaComponents3
import org.kde.kirigami as Kirigami

import "Lambent.js" as L

// A link: machine → device. The switch is the light switch: enabling a
// link pauses any other link driving the same channels of that device.
ColumnLayout {
    id: item

    required property var store
    required property string key

    readonly property var link: (store.rev, store.links[key] || null)
    readonly property var target: link ? (store.devices[link.target] || null) : null
    readonly property var pixels: (store.rev, link ? (store.previews[link.source] || []) : [])

    spacing: Kirigami.Units.smallSpacing / 2

    RowLayout {
        Layout.fillWidth: true
        spacing: Kirigami.Units.smallSpacing

        PlasmaComponents3.Switch {
            checked: !!item.link && !!item.link.enabled
            onToggled: {
                item.store.linkCommand("toggle", item.key)
                // the next push says what actually happened
                checked = Qt.binding(function() { return !!item.link && !!item.link.enabled })
            }
            PlasmaComponents3.ToolTip { text: checked ? i18n("Turn this link off") : i18n("Turn this link on") }
        }

        ColumnLayout {
            Layout.fillWidth: true
            spacing: 0

            PlasmaComponents3.Label {
                Layout.fillWidth: true
                elide: Text.ElideRight
                text: item.key
                opacity: item.link && item.link.enabled ? 1 : 0.6
            }

            PlasmaComponents3.Label {
                Layout.fillWidth: true
                elide: Text.ElideRight
                font: Kirigami.Theme.smallFont
                opacity: 0.7
                text: !item.link ? "" : (item.link.source || "?") + " → "
                      + L.deviceLabel(item.target, item.link.target)
                      + (item.target && item.target.place ? " (" + item.target.place + ")" : "")
                      // only worth showing the channel when the target has more than one
                      + (item.target && item.target.sox > 1 ? " · " + L.chanLabel(item.link.chan) : "")
            }
        }

        PlasmaComponents3.ToolButton {
            icon.name: item.link && item.link.persist ? "window-pin" : "window-unpin"
            checked: !!item.link && !!item.link.persist
            onClicked: item.store.linkCommand("persist", item.key)
            PlasmaComponents3.ToolTip {
                text: item.link && item.link.persist ? i18n("Kept across restarts — click to stop keeping it")
                                                     : i18n("Keep across restarts")
            }
        }
        PlasmaComponents3.ToolButton {
            icon.name: "edit-delete"
            onClicked: item.store.linkCommand("quit", item.key)
            PlasmaComponents3.ToolTip { text: i18n("Remove this link") }
        }
    }

    PreviewStrip {
        visible: item.pixels.length > 0
        Layout.fillWidth: true
        Layout.preferredHeight: cellHeight
        opacity: item.link && item.link.enabled ? 1 : 0.35
        pixels: item.pixels
    }

    Kirigami.Separator {
        Layout.fillWidth: true
        Layout.topMargin: Kirigami.Units.smallSpacing / 2
        opacity: 0.5
    }
}