1.8 KiB · text History 5fae34f
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.kcmutils as KCM

// Which queries to show, picked from what the bus has rather than typed.
KCM.SimpleKCM {
    id: page

    property string cfg_queries
    property bool cfg_showStale

    Crib {
        id: crib
    }

    readonly property var chosen: cfg_queries.split(",").map(k => k.trim()).filter(k => k !== "")

    function toggle(key, on) {
        // Kept in the order they were ticked: the widget shows them that way.
        const keys = chosen.filter(k => k !== key);
        if (on) {
            keys.push(key);
        }
        cfg_queries = keys.join(",");
    }

    Kirigami.FormLayout {
        QQC2.CheckBox {
            Kirigami.FormData.label: i18n("Stale queries:")
            text: i18n("Show, dimmed")
            checked: page.cfg_showStale
            onToggled: page.cfg_showStale = checked
        }

        Kirigami.Separator {
            Kirigami.FormData.isSection: true
            Kirigami.FormData.label: i18n("Queries")
        }

        QQC2.Label {
            visible: !crib.running
            text: i18n("apollos-dbus is not running, so there is nothing to pick from.")
            wrapMode: Text.Wrap
        }

        QQC2.Label {
            visible: crib.running
            text: page.chosen.length === 0 ? i18n("None ticked: every query is shown.") : i18n("Shown in the order ticked.")
            opacity: 0.7
        }

        Repeater {
            model: Object.keys(crib.board).sort()

            QQC2.CheckBox {
                required property string modelData
                text: i18n("%1 (%2)", crib.board[modelData].name, modelData)
                checked: page.chosen.indexOf(modelData) >= 0
                onToggled: page.toggle(modelData, checked)
            }
        }
    }
}