Warning, /pim/vakzination/src/qml/TestDetailsSheet.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0004 */
0005 
0006 import QtQuick 2.15
0007 import QtQuick.Controls 2.15 as QQC2
0008 import QtQuick.Layouts 1.2
0009 import org.kde.kirigami 2.15 as Kirigami
0010 import org.kde.khealthcertificate 1.0 as KHC
0011 import org.kde.i18n.localeData 1.0
0012 
0013 ColumnLayout {
0014 
0015     required property var certificate
0016 
0017     function daysTo(d1, d2) {
0018         return (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24);
0019     }
0020 
0021     Kirigami.FormLayout {
0022 
0023         Kirigami.Separator {
0024             Kirigami.FormData.isSection: true
0025             Kirigami.FormData.label: i18n("Person")
0026         }
0027 
0028         QQC2.Label {
0029             text: certificate.name
0030             Kirigami.FormData.label: i18n("Name:")
0031         }
0032         QQC2.Label {
0033             text: certificate.dateOfBirth.toLocaleDateString(Qt.locale(), Locale.ShortFormat)
0034             visible: !isNaN(certificate.dateOfBirth.getTime())
0035             Kirigami.FormData.label: i18n("Date of birth:")
0036         }
0037 
0038         Kirigami.Separator {
0039             Kirigami.FormData.isSection: true
0040             Kirigami.FormData.label: i18n("Test")
0041         }
0042 
0043         QQC2.Label {
0044             text: certificate.date.toLocaleDateString(Qt.locale(), Locale.ShortFormat)
0045             Kirigami.FormData.label: i18n("Date:")
0046             color: daysTo(certificate.date, new Date()) >= 2 ? Kirigami.Theme.neutralTextColor : Kirigami.Theme.textColor
0047             visible: !isNaN(certificate.date.getTime())
0048         }
0049         QQC2.Label {
0050             text: certificate.disease
0051             Kirigami.FormData.label: i18n("Disease:")
0052             visible: certificate.disease
0053         }
0054         QQC2.Label {
0055             text: certificate.testType
0056             Kirigami.FormData.label: i18n("Type:")
0057             visible: certificate.testType
0058         }
0059         QQC2.Label {
0060             text: certificate.testUrl != "" ? '<a href="' + certificate.testUrl + '">' + certificate.testName + '</a>' : certificate.testName
0061             visible: certificate.testName.length > 0
0062             Kirigami.FormData.label: i18n("Test:")
0063             onLinkActivated: Qt.openUrlExternally(link)
0064         }
0065         QQC2.Label {
0066             text: {
0067                 if (certificate.resultString !== "") {
0068                     return certificate.resultString;
0069                 }
0070                 switch (certificate.result) {
0071                     case KHC.TestCertificate.Positive:
0072                         return i18nc('test result', 'Positive');
0073                     case KHC.TestCertificate.Negative:
0074                         return i18nc('test result', 'Negative');
0075                 }
0076             }
0077             Kirigami.FormData.label: i18n("Result:")
0078             color: certificate.result == KHC.TestCertificate.Positive ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.textColor
0079         }
0080         QQC2.Label {
0081             text: certificate.testCenter
0082             Kirigami.FormData.label: i18n("Test Center:")
0083             visible: text !== ""
0084         }
0085         QQC2.Label {
0086             text: i18nc("%1 a flag emoji, %2 is a country name", "%1 %2", Country.fromAlpha2(certificate.country).emojiFlag, Country.fromAlpha2(certificate.country).name)
0087             Kirigami.FormData.label: i18n("Country:")
0088             visible: certificate.country
0089         }
0090 
0091         Kirigami.Separator {
0092             Kirigami.FormData.isSection: true
0093             Kirigami.FormData.label: i18n("Certificate")
0094         }
0095 
0096         QQC2.Label {
0097             text: certificate.certificateIssuer
0098             Kirigami.FormData.label: i18n("Issuer:")
0099             visible: text !== ""
0100         }
0101         QQC2.Label {
0102             text: certificate.certificateId
0103             Kirigami.FormData.label: i18n("Identifier:")
0104             wrapMode: Text.Wrap
0105             visible: text !== ""
0106         }
0107         QQC2.Label {
0108             text: certificate.certificateIssueDate.toLocaleString(Qt.locale(), Locale.ShortFormat)
0109             Kirigami.FormData.label: i18n("Issued:")
0110             visible: !isNaN(certificate.certificateIssueDate.getTime())
0111         }
0112         QQC2.Label {
0113             text: certificate.certificateExpiryDate.toLocaleString(Qt.locale(), Locale.ShortFormat)
0114             Kirigami.FormData.label: i18n("Expires:")
0115             visible: !isNaN(certificate.certificateExpiryDate.getTime())
0116             color: certificate.certificateExpiryDate.getTime() < Date.now() ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.textColor
0117         }
0118         Kirigami.Icon {
0119             source: {
0120                 switch(certificate.signatureState) {
0121                     case KHC.HealthCertificate.ValidSignature: return "dialog-ok";
0122                     case KHC.HealthCertificate.UnknownSignature: return "question";
0123                     case KHC.HealthCertificate.InvalidSignature:
0124                     default:
0125                         return "dialog-error-symbolic";
0126                 }
0127             }
0128             height: Kirigami.Units.gridUnit
0129             Kirigami.FormData.label: i18n("Signature:")
0130             color: {
0131                 switch(certificate.signatureState) {
0132                     case KHC.HealthCertificate.ValidSignature: return Kirigami.Theme.positiveTextColor;
0133                     case KHC.HealthCertificate.UnknownSignature: return Kirigami.Theme.neutralTextColor;
0134                     case KHC.HealthCertificate.InvalidSignature:
0135                     default:
0136                         return Kirigami.Theme.negativeTextColor;
0137                 }
0138             }
0139             visible: certificate.signatureState != KHC.HealthCertificate.UncheckedSignature
0140         }
0141     }
0142 }
0143