Warning, /pim/vakzination/src/qml/VaccinationDetailsSheet.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("Vaccination")
0041         }
0042 
0043         QQC2.Label {
0044             readonly property int days: daysTo(certificate.date, new Date())
0045             text: {
0046                 const formattedDate = certificate.date.toLocaleDateString(Qt.locale(), Locale.ShortFormat);
0047                 if (days > 0) {
0048                     return i18np("%2 (%1 day ago)", "%2 (%1 days ago)", days, formattedDate);
0049                 }
0050                 return formattedDate;
0051             }
0052             Kirigami.FormData.label: i18n("Date:")
0053             color: certificate.vaccinationState != KHC.VaccinationCertificate.VaccinationTooRecent ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.neutralTextColor
0054             font.bold: true
0055             visible: !isNaN(certificate.date.getTime())
0056         }
0057         QQC2.Label {
0058             text: certificate.disease
0059             Kirigami.FormData.label: i18n("Disease:")
0060             visible: certificate.disease
0061         }
0062         QQC2.Label {
0063             text: certificate.vaccineType
0064             Kirigami.FormData.label: i18n("Type:")
0065             visible: certificate.vaccineType
0066         }
0067         QQC2.Label {
0068             text: certificate.vaccineUrl != "" ? '<a href="' + certificate.vaccineUrl + '">' + certificate.vaccine + '</a>' : certificate.vaccine
0069             Kirigami.FormData.label: i18n("Vaccine:")
0070             onLinkActivated: Qt.openUrlExternally(link)
0071             visible: text !== ""
0072         }
0073         QQC2.Label {
0074             text: certificate.manufacturer
0075             Kirigami.FormData.label: i18n("Manufacturer:")
0076             visible: text !== ""
0077         }
0078         QQC2.Label {
0079             text: certificate.totalDoses > 0 ? i18n("%1/%2", certificate.dose, certificate.totalDoses) : certificate.dose
0080             Kirigami.FormData.label: i18n("Dose:")
0081             color: certificate.dose < certificate.totalDoses ? Kirigami.Theme.neutralTextColor : Kirigami.Theme.positiveTextColor
0082             font.bold: true
0083             visible: certificate.dose > 0
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: certificate.certificateId
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