/*SPDX-FileCopyrightText: 2022 MΓ©ven Car <meven@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import org.kde.kirigami as Kirigamiimport org.kde.kcmutils as KCMKirigami.OverlaySheet {id: rootproperty QtObject componentChooser// type: list<string>property var unsupportedMimeTypes: componentChooser?.unsupportedMimeTypes ?? []// type: list<{ first, second }>property var mimeTypesNotAssociated: componentChooser?.mimeTypesNotAssociated ?? []function sanitize(input: string): string {// Based on QQuickStyledTextPrivate::parseEntityconst table = {'>': '>','<': '<','&': '&',"'": ''','"': '"','\u00a0': ' ',};return input.replace(/[<>&'"\u00a0]/g, c => table[c]);}function formatListItem(item: string): string {return "<li>" + sanitize(item) + "</li>";}function formatHtmlUnorderedStringList(list: list<string>): string {return "<ul>" + list.map(formatListItem).join("\n") + "</ul>";}onOpened: {focus = true;}onClosed: {componentChooser = null;}title: i18n("Details")modal: trueQQC2.Overlay.modal: KcmPopupModal {}ColumnLayout {enabled: root.componentChooser !== nullspacing: Kirigami.Units.smallSpacingLayout.preferredWidth: Kirigami.Units.gridUnit * 25RowLayout {Layout.fillWidth: truespacing: Kirigami.Units.largeSpacingKirigami.Icon {Layout.preferredWidth: Kirigami.Units.iconSizes.largeLayout.preferredHeight: Kirigami.Units.iconSizes.largesource: root.componentChooser?.applicationIcon()}Kirigami.Heading {text: root.componentChooser?.applicationName() ?? ""textFormat: Text.PlainTextlevel: 1wrapMode: Text.WrapLayout.fillWidth: trueLayout.alignment: Qt.AlignVCenter}}Kirigami.Heading {text: i18n("This application can also open these file types:")textFormat: Text.PlainTextvisible: root.mimeTypesNotAssociated.length > 0level: 3wrapMode: Text.WrapLayout.fillWidth: trueLayout.bottomMargin: Kirigami.Units.largeSpacing}Kirigami.SelectableLabel {visible: root.mimeTypesNotAssociated.length > 0text: root.formatHtmlUnorderedStringList(root.mimeTypesNotAssociated.map(({first, second}) => i18nc("@label %1 is a MIME type and %2 is an application name","%1 (Currently opens in %2)",second,first,)))Layout.fillWidth: true}QQC2.Button {visible: root.mimeTypesNotAssociated.length > 0icon.name: root.componentChooser?.applicationIcon() ?? ""text: i18nc("@action:button %1 is an application name","Open All in %1",root.componentChooser?.applicationName() ?? "")Layout.topMargin: Kirigami.Units.largeSpacingonClicked: {root.close();root.componentChooser.saveMimeTypesNotAssociated();}}Kirigami.Separator {// extra double-spacingLayout.fillWidth: trueLayout.margins: Kirigami.Units.largeSpacingvisible: root.unsupportedMimeTypes.length > 0&& root.mimeTypesNotAssociated.length > 0}Kirigami.Heading {text: i18n("This application does not advertise support for the following file types, but may be able to open them anyway:")textFormat: Text.PlainTextvisible: root.unsupportedMimeTypes.length > 0level: 3wrapMode: Text.WrapLayout.fillWidth: trueLayout.bottomMargin: Kirigami.Units.largeSpacing}Kirigami.SelectableLabel {visible: root.unsupportedMimeTypes.length > 0text: root.formatHtmlUnorderedStringList(root.unsupportedMimeTypes)Layout.fillWidth: true}QQC2.Button {visible: root.unsupportedMimeTypes.length > 0icon.name: root.componentChooser?.applicationIcon() ?? ""text: root.componentChooser? i18nc("@action:button", "Force All to Open in %1", root.componentChooser.applicationName()): ""Layout.topMargin: Kirigami.Units.largeSpacingonClicked: {root.close();root.componentChooser.saveAssociationUnsuportedMimeTypes();}}QQC2.Button {Layout.topMargin: Kirigami.Units.largeSpacingicon.name: "configure-symbolic"text: i18n("Configure Manuallyβ¦")visible: root.componentChooser !== nullonClicked: {root.close();KCM.KCMLauncher.openSystemSettings("kcm_filetypes");}}}}