foxygit / TV-Launcher Log in
commits tags

/qml/AppsPage.qml · 2.34 KB

raw
import QtQuick
import TvLauncher

// Lista över alla appar och webbappar med möjlighet att lägga till och redigera.
Item {
    id: page

    signal editApp(var app)
    signal addApp(string type)
    signal pickInstalled()

    readonly property var all: {
        apps.revision
        let out = []
        for (const c of apps.categories) out = out.concat(apps.appsIn(c))
        return out
    }

    // Kortet som hade fokus, så att vi hittar tillbaka när listan byggs om.
    property int lastIndex: -1
    function focusFirst() {
        const cs = list.cards()
        if (lastIndex >= 0 && cs.length > 0) {
            const c = cs[Math.min(lastIndex, cs.length - 1)]
            c.forceActiveFocus()
            list.ensureVisible(c)
        } else {
            list.focusFirst()
        }
    }

    CardList {
        id: list
        anchors.fill: parent

        SettingsCard {
            icon: "add"
            title: "Lägg till program"
            subtitle: "Ett eget kommando, t.ex. ett spel, en emulator eller ett skript"
            onActivated: page.addApp("app")
        }
        SettingsCard {
            icon: "globe"
            title: "Lägg till webbapp"
            subtitle: "Gör en webbplats till en app, t.ex. Jellyfin, SVT Play eller Spotify"
            onActivated: page.addApp("web")
        }
        SettingsCard {
            icon: "apps"
            title: "Från installerade program"
            subtitle: "Välj bland programmen som finns på datorn"
            onActivated: page.pickInstalled()
        }

        SectionTitle { text: "Dina appar (" + page.all.length + ")" }
        Repeater {
            model: page.all
            delegate: SettingsCard {
                required property var modelData
                required property int index
                onActiveFocusChanged: if (activeFocus) page.lastIndex = index + 3
                appIcon: modelData.icon || " "
                title: modelData.name
                subtitle: modelData.category + "  ·  " + (modelData.type === "web"
                          ? "Webbapp: " + modelData.url + (modelData.engine === "chromium" ? " (Chromium)" : "")
                          : modelData.command)
                valueText: "Redigera"
                onActivated: page.editApp(modelData)
                onMenuRequested: page.editApp(modelData)
            }
        }
    }
}