<commit_before>import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2

DefaultDialog {
    property var device

    title: qsTr("Configure connections")

    onAccepted: {
        var enabled = get_enabled()
        device.set_mode(enabled, function (e) {
            if (e) {
                console.log('Error setting mode: ' + e)
            } else {
                ejectNow.open()
            }
        })
    }

    ColumnLayout {
        anchors.fill: parent

        Text {
            textFormat: Text.StyledText
            text: qsTr("<h2>Configure enabled connection protocols</h2>
<p>Set the enabled connection protocols for your YubiKey.</p>
<p>Once changed, you will need to unplug and re-insert your YubiKey for the settings to take effect.</p>")
        }

        RowLayout {
            Layout.fillWidth: true
            Repeater {
                id: connections
                model: device.connections

                CheckBox {
                    Layout.fillWidth: true
                    text: modelData
                    checked: device.enabled.indexOf(modelData) >= 0
                    enabled: modelData !== 'NFC'
                    onCheckedChanged: button_ok.enabled = check_acceptable()
                }
            }
        }

        RowLayout {
            Layout.alignment: Qt.AlignRight
            Button {
                id: button_ok
                text: qsTr("OK")
                onClicked: {
                    close()
                    accepted()
                }
            }
            Button {
                text: qsTr("Cancel")
                onClicked: {
                    close()
                    rejected()
                }
            }
        }
    }

    MessageDialog {
        id: ejectNow
        title: qsTr('Connections configured')
        icon: StandardIcon.Information
        text: qsTr('Connections are now configured. Remove and re-insert your YubiKey.')
        standardButtons: StandardButton.NoButton

        readonly property bool hasDevice: device.hasDevice
        onHasDeviceChanged: if (!hasDevice) ejectNow.close()
    }

    function get_enabled() {
        var enabled = []
        for (var i = 0; i < device.connections.length; i++) {
            var connection_checkbox = connections.itemAt(i)
            if (connection_checkbox.checked) {
                enabled.push(connection_checkbox.text)
            }
        }
        return enabled
    }

    function check_acceptable() {
        for (var i = 0; i < connections.count; i++) {
            var item = connections.itemAt(i)
            if(item) {
                if (item.text === 'NFC') {
                    continue
                }
                if (item.checked) {
                    return true
                }
            }
        }<commit_msg>Restyle connections dialog<commit_after>import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2

DefaultDialog {
    property var device

    title: qsTr("Configure connections")
    minimumWidth: 500
    onAccepted: {
        var enabled = get_enabled()
        device.set_mode(enabled, function (e) {
            if (e) {
                console.log('Error setting mode: ' + e)
            } else {
                ejectNow.open()
            }
        })
    }

    ColumnLayout {
        anchors.fill: parent

        Text {
            textFormat: Text.StyledText
            text: "<h2>Configure enabled connection protocols</h2>"
        }

        Item {
            width: minimumWidth - margins * 2
            implicitHeight: infoText.implicitHeight

            Text {
                id: infoText
                text: qsTr("Set the enabled connection protocols for your YubiKey. Once changed, you will need to unplug and re-insert your YubiKey for the settings to take effect.")
                wrapMode: Text.Wrap
                width: parent.width
            }
        }

        RowLayout {
            Layout.fillWidth: true
            Layout.alignment: Qt.AlignHCenter
            Repeater {
                id: connections
                model: device.connections

                CheckBox {
                    Layout.fillWidth: true
                    text: modelData
                    checked: device.enabled.indexOf(modelData) >= 0
                    enabled: modelData !== 'NFC'
                    onCheckedChanged: button_ok.enabled = check_acceptable()
                }
            }
        }

        RowLayout {
            Layout.alignment: Qt.AlignRight
            Button {
                id: button_ok
                text: qsTr("OK")
                onClicked: {
                    close()
                    accepted()
                }
            }
            Button {
                text: qsTr("Cancel")
                onClicked: {
                    close()
                    rejected()
                }
            }
        }
    }

    MessageDialog {
        id: ejectNow
        title: qsTr('Connections configured')
        icon: StandardIcon.Information
        text: qsTr('Connections are now configured. Remove and re-insert your YubiKey.')
        standardButtons: StandardButton.NoButton

        readonly property bool hasDevice: device.hasDevice
        onHasDeviceChanged: if (!hasDevice)
                                ejectNow.close()
    }

    function get_enabled() {
        var enabled = []
        for (var i = 0; i < device.connections.length; i++) {
            var connection_checkbox = connections.itemAt(i)
            if (connection_checkbox.checked) {
                enabled.push(connection_checkbox.text)
            }
        }
        return enabled
    }

    function check_acceptable() {
        for (var i = 0; i < connections.count; i++) {
            var item = connections.itemAt(i)
            if (item) {
                if (item.text === 'NFC') {
                    continue
                }
                if (item.checked) {
                    return true
                }
            }
        }
{'fraction_non_alphanumeric': 0.08085592943482522, 'fraction_numerical': 0.004900359359686377, 'mean_word_length': 1.247797356828194, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7208850', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1492, 'n_words': 378}