<commit_before>import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.2
import "utils.js" as Utils

StackView {
    anchors.fill: parent
    initialItem: noDeviceView

    property int selectedSlot
    property bool slot1Configured
    property bool slot2Configured

    property bool locked

    property bool isConfiguringInterfaces: currentItem !== null
                                           && currentItem.objectName === "interfaces"

    property bool isShowingHomeView: currentItem !== null
                                     && currentItem.objectName === "homeView"

    function lock() {
        locked = true
    }

    function unlock() {
        locked = false
    }

    function selectSlot1() {
        selectedSlot = 1
    }

    function selectSlot2() {
        selectedSlot = 2
    }

    function selectedSlotConfigured() {
        if (selectedSlot === 1) {
            return slot1Configured
        }
        if (selectedSlot === 2) {
            return slot2Configured
        }
        return false
    }

    function popToDepth(height) {
        pop(find(function (item, searchIndex) {
            return searchIndex === height
        }))
    }

    function replaceAtDepth(depth, item, newObjectName) {
        var itemToReplace = find(function (item, index) {
            return index === depth
        })
        if (itemToReplace) {
            if (newObjectName) {
                if (itemToReplace.objectName === newObjectName) {
                    pop(itemToReplace)
                } else {
                    replace(itemToReplace, item)
                }
            } else {
                replace(itemToReplace, item)
            }
        } else {
            push(item)
        }
    }

    function home() {
        if (yubiKey.hasDevice) {
            var homeViewOnStack = find(function (item) {
                return item.objectName === 'homeView'
            })
            if (homeViewOnStack) {
                pop(homeViewOnStack)
            } else {
                replaceAtDepth(0, homeView, 'homeView')
            }
        } else if (yubiKey.nDevices > 1) {
            replaceAtDepth(0, multipleDevicesView, 'multipleDevicesView')
        } else {
            replaceAtDepth(0, noDeviceView, 'noDeviceView')
        }
    }

    function configureInterfaces() {
        var interfaceComponent = yubiKey.supportsNewInterfaces(
                    ) ? interfaces : legacyInterfaces
        replaceAtDepth(1, interfaceComponent, 'interfaces')
    }

    function piv() {
        replaceAtDepth(1, pivView, 'pivView')
    }

    function pivCertificates() {
        replaceAtDepth(2, pivCertificatesView, 'pivCertificatesView')
    }

    function pivReset() {
        replaceAtDepth(2, pivResetView, 'pivResetView')
    }

    function pivPinManagement() {
        replaceAtDepth(2, pivPinManagementView, 'pivPinManagementView')
    }

    function pivChangePin() {
        replaceAtDepth(3, pivChangePinView, 'pivChangePinView')
    }

    function pivUnblockPin() {
        replaceAtDepth(3, pivUnblockPinView, 'pivUnblockPinView')
    }

    function pivChangePuk() {
        replaceAtDepth(3, pivChangePukView, 'pivChangePukView')
    }

    function pivChangeManagementKey() {
        replaceAtDepth(3, pivChangeManagementKeyView, 'pivChangeManagementKeyView')
    }

    function pivGetManagementKeyAndThen(pinCallback, keyCallback) {
        if ((yubiKey.piv || {}).has_protected_key) {
            pivPinPopup.getPinAndThen(pinCallback)
        } else {
            pivManagementKeyPopup.getKeyAndThen(keyCallback)
        }
    }

    function fido2() {
        replaceAtDepth(1, fido2View, 'fido2View')
    }

    function fido2SetPin() {
        replaceAtDepth(2, fido2SetPinView, 'fido2SetPinView')
    }

    function fido2ChangePin() {
        replaceAtDepth(2, fido2ChangePinView, 'fido2ChangePinView')
    }

    function fido2Reset() {
        replaceAtDepth(2, fido2ResetView, 'fido2ResetView')
    }<commit_msg>Rename pivGet{ManagementKeyAndThen => PinOrManagementKey}<commit_after>import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.2
import "utils.js" as Utils

StackView {
    anchors.fill: parent
    initialItem: noDeviceView

    property int selectedSlot
    property bool slot1Configured
    property bool slot2Configured

    property bool locked

    property bool isConfiguringInterfaces: currentItem !== null
                                           && currentItem.objectName === "interfaces"

    property bool isShowingHomeView: currentItem !== null
                                     && currentItem.objectName === "homeView"

    function lock() {
        locked = true
    }

    function unlock() {
        locked = false
    }

    function selectSlot1() {
        selectedSlot = 1
    }

    function selectSlot2() {
        selectedSlot = 2
    }

    function selectedSlotConfigured() {
        if (selectedSlot === 1) {
            return slot1Configured
        }
        if (selectedSlot === 2) {
            return slot2Configured
        }
        return false
    }

    function popToDepth(height) {
        pop(find(function (item, searchIndex) {
            return searchIndex === height
        }))
    }

    function replaceAtDepth(depth, item, newObjectName) {
        var itemToReplace = find(function (item, index) {
            return index === depth
        })
        if (itemToReplace) {
            if (newObjectName) {
                if (itemToReplace.objectName === newObjectName) {
                    pop(itemToReplace)
                } else {
                    replace(itemToReplace, item)
                }
            } else {
                replace(itemToReplace, item)
            }
        } else {
            push(item)
        }
    }

    function home() {
        if (yubiKey.hasDevice) {
            var homeViewOnStack = find(function (item) {
                return item.objectName === 'homeView'
            })
            if (homeViewOnStack) {
                pop(homeViewOnStack)
            } else {
                replaceAtDepth(0, homeView, 'homeView')
            }
        } else if (yubiKey.nDevices > 1) {
            replaceAtDepth(0, multipleDevicesView, 'multipleDevicesView')
        } else {
            replaceAtDepth(0, noDeviceView, 'noDeviceView')
        }
    }

    function configureInterfaces() {
        var interfaceComponent = yubiKey.supportsNewInterfaces(
                    ) ? interfaces : legacyInterfaces
        replaceAtDepth(1, interfaceComponent, 'interfaces')
    }

    function piv() {
        replaceAtDepth(1, pivView, 'pivView')
    }

    function pivCertificates() {
        replaceAtDepth(2, pivCertificatesView, 'pivCertificatesView')
    }

    function pivReset() {
        replaceAtDepth(2, pivResetView, 'pivResetView')
    }

    function pivPinManagement() {
        replaceAtDepth(2, pivPinManagementView, 'pivPinManagementView')
    }

    function pivChangePin() {
        replaceAtDepth(3, pivChangePinView, 'pivChangePinView')
    }

    function pivUnblockPin() {
        replaceAtDepth(3, pivUnblockPinView, 'pivUnblockPinView')
    }

    function pivChangePuk() {
        replaceAtDepth(3, pivChangePukView, 'pivChangePukView')
    }

    function pivChangeManagementKey() {
        replaceAtDepth(3, pivChangeManagementKeyView, 'pivChangeManagementKeyView')
    }

    function pivGetPinOrManagementKey(pinCallback, keyCallback) {
        if ((yubiKey.piv || {}).has_protected_key) {
            pivPinPopup.getPinAndThen(pinCallback)
        } else {
            pivManagementKeyPopup.getKeyAndThen(keyCallback)
        }
    }

    function fido2() {
        replaceAtDepth(1, fido2View, 'fido2View')
    }

    function fido2SetPin() {
        replaceAtDepth(2, fido2SetPinView, 'fido2SetPinView')
    }

    function fido2ChangePin() {
        replaceAtDepth(2, fido2ChangePinView, 'fido2ChangePinView')
    }

    function fido2Reset() {
        replaceAtDepth(2, fido2ResetView, 'fido2ResetView')
    }
{'fraction_non_alphanumeric': 0.08957816377171215, 'fraction_numerical': 0.011166253101736972, 'mean_word_length': 2.0327313769751694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6515836', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2230, 'n_words': 438}