Warning, /pim/merkuro/src/contacts/applet/package/contents/ui/ContactPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <car@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 import QtQuick 2.15
0005 import QtQml 2.15
0006 import QtQuick.Layouts 1.15
0007 import org.kde.kirigami 2.19 as Kirigami
0008 import org.kde.plasma.core 2.0 as PlasmaCore
0009 import org.kde.plasma.extras 2.0 as PlasmaExtras
0010 import org.kde.plasma.components 3.0 as PlasmaComponents3
0011 import org.kde.merkuro.contact 1.0
0012 
0013 PlasmaComponents3.ScrollView {
0014     id: root
0015 
0016     property int itemId
0017     topPadding: 0
0018 
0019     property string title: addressee.formattedName
0020 
0021     property AddresseeWrapper addressee: AddresseeWrapper {
0022         addresseeItem: ContactManager.getItem(root.itemId)
0023     }
0024     PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
0025 
0026     function callNumber(number) {
0027         Qt.openUrlExternally("tel:" + number)
0028     }
0029 
0030     function sendSms(number) {
0031         Qt.openUrlExternally("sms:" + number)
0032     }
0033 
0034     Keys.onPressed: if (event.key === Qt.Key_Escape) {
0035         stack.pop()
0036         event.accepted = true;
0037     }
0038 
0039     property var header: PlasmaExtras.PlasmoidHeading {
0040         Component {
0041             id: menuItemComponent
0042             PlasmaComponents3.MenuItem { }
0043         }
0044         RowLayout {
0045             width: parent.width
0046 
0047             PlasmaComponents3.Button {
0048                 icon.name: "go-previous-view"
0049                 text: i18n("Return to Contact List")
0050                 onClicked: stack.pop()
0051                 Layout.fillWidth: true
0052             }
0053 
0054             PlasmaComponents3.ToolButton {
0055                 id: configureButtonCall
0056                 Accessible.name: i18n("Call")
0057                 PlasmaComponents3.ToolTip { text: i18n("Call") }
0058                 icon.name: "call-start"
0059                 visible: addressee.phoneNumbers.length > 0
0060                 onClicked: {
0061                     const model = addressee.phoneNumbers;
0062 
0063                     if (model.length === 1) {
0064                         page.callNumber(model[0].normalizedNumber);
0065                     } else {
0066                         if (menuCall.count == 0) {
0067                             model.forEach((item) => {
0068                                 let menuItem = menuItemComponent.createObject(menuCall, {
0069                                     text: i18n("%1 (%2)", item.typeLabel, item.number)
0070                                 });
0071                                 menuItem.clicked.connect(() => {
0072                                     callNumber(item.number);
0073                                 });
0074                                 menuCall.addItem(menuItem);
0075                             });
0076                         }
0077                         menuCall.open();
0078                     }
0079                 }
0080                 PlasmaComponents3.Menu {
0081                     id: menuCall
0082                     y: configureButtonCall.height
0083                 }
0084             }
0085 
0086             PlasmaComponents3.ToolButton {
0087                 id: configureButtonSms
0088                 Accessible.name: i18n("Send SMS")
0089                 PlasmaComponents3.ToolTip { text: i18n("Send SMS") }
0090                 icon.name: "mail-message"
0091                 visible: addressee.phoneNumbers.length > 0
0092                 onClicked: {
0093                     const model = addressee.phoneNumbers;
0094 
0095                     if (addressee.phoneNumbers.length === 1) {
0096                         sendSms(model[0].normalizedNumber);
0097                     } else {
0098                         if (menuSms.count == 0) {
0099                             model.forEach((item) => {
0100                                 let menuItem = menuItemComponent.createObject(menuSms, {
0101                                     text: i18n("%1 (%2)", item.typeLabel, item.number)
0102                                 });
0103                                 menuItem.clicked.connect(() => {
0104                                     sendSms(item.number);
0105                                 });
0106                                 menuSms.addItem(menuItem);
0107                             });
0108                         }
0109                         menuSms.open();
0110                     }
0111                 }
0112                 PlasmaComponents3.Menu {
0113                     id: menuSms
0114                     y: configureButtonSms.height
0115                 }
0116             }
0117 
0118             PlasmaComponents3.ToolButton {
0119                 Accessible.name: i18n("Send Email")
0120                 PlasmaComponents3.ToolTip { text: i18n("Send Email") }
0121                 icon.name: "mail-message"
0122                 visible: addressee.preferredEmail.length > 0
0123                 onClicked: Qt.openUrlExternally(`mailto:${addressee.preferredEmail}`)
0124             }
0125 
0126             PlasmaComponents3.ToolButton {
0127                 icon.name: 'view-barcode-qr'
0128                 Accessible.name: i18n("Show QR Code")
0129                 PlasmaComponents3.ToolTip { text: i18n("Show QR Code") }
0130                 onClicked: stack.push(Qt.resolvedUrl('./QrCodePage.qml'), {
0131                     qrCodeData: addressee.qrCodeData(),
0132                 })
0133             }
0134         }
0135     }
0136 
0137     contentItem: Flickable {
0138         contentHeight: layout.implicitHeight
0139         ColumnLayout {
0140             id: layout
0141             width: parent.width
0142             spacing: 0
0143             Header {
0144                 Layout.fillWidth: true
0145                 Layout.preferredHeight: Kirigami.Units.gridUnit * 8
0146 
0147                 source: addressee.photo.isIntern ? addressee.photo.data : addressee.photo.url
0148                 backgroundSource: Qt.resolvedUrl("../resources/fallbackBackground.png")
0149 
0150                 contentItems: PlasmaExtras.Heading {
0151                     text: addressee.formattedName
0152                     color: "#fcfcfc"
0153                     level: 2
0154                 }
0155             }
0156 
0157             PlasmaComponents3.Label {
0158                 visible: addressee.nickName !== ""
0159                 text: i18n("Nickname: %1", addressee.nickName)
0160                 Layout.leftMargin: PlasmaCore.Units.smallSpacing
0161                 Layout.rightMargin: PlasmaCore.Units.smallSpacing
0162                 Layout.topMargin: PlasmaCore.Units.smallSpacing
0163             }
0164 
0165             PlasmaComponents3.Label {
0166                 Layout.leftMargin: PlasmaCore.Units.smallSpacing
0167                 Layout.rightMargin: PlasmaCore.Units.smallSpacing
0168                 Layout.topMargin: PlasmaCore.Units.smallSpacing
0169                 visible: text !== i18n("Birthday:") + ' '
0170                 text: if (addressee.birthday.getFullYear() === 0) {
0171                     return Qt.formatDate(addressee.birthday, i18nc("Day month format", "dd.MM."))
0172                 } else {
0173                     return i18n("Birthday:") + ' ' + addressee.birthday.toLocaleDateString()
0174                 }
0175             }
0176 
0177             PlasmaExtras.Heading {
0178                 Layout.leftMargin: PlasmaCore.Units.smallSpacing
0179                 Layout.rightMargin: PlasmaCore.Units.smallSpacing
0180                 Layout.topMargin: PlasmaCore.Units.smallSpacing
0181                 visible: addressesRepeater.count > 0
0182                 text: i18np("Address", "Addresses", addressesRepeater.count)
0183                 level: 4
0184             }
0185 
0186             Repeater {
0187                 id: addressesRepeater
0188                 model: addressee.addressesModel
0189                 PlasmaComponents3.Label {
0190                     Layout.leftMargin: PlasmaCore.Units.smallSpacing
0191                     Layout.rightMargin: PlasmaCore.Units.smallSpacing
0192                     visible: text.lenght !== 0
0193                     text: (model.typeLabel ? i18nc("%1 is the type of the address, e.g. home, work, ...", "%1:", model.typeLabel) : '') + ' ' + model.formattedAddress
0194                 }
0195             }
0196 
0197             PlasmaExtras.Heading {
0198                 Layout.topMargin: PlasmaCore.Units.smallSpacing
0199                 Layout.leftMargin: PlasmaCore.Units.smallSpacing
0200                 Layout.rightMargin: PlasmaCore.Units.smallSpacing
0201                 visible: emailRepeater.count > 0
0202                 text: i18np("Email Address", "Email Addresses", emailRepeater.count)
0203                 level: 4
0204             }
0205 
0206             Repeater {
0207                 id: emailRepeater
0208                 model: addressee.emailModel
0209                 PlasmaComponents3.Label {
0210                     visible: text !== ""
0211                     text: `${model.type} <a href="mailto:${model.display}">${model.display}</a>`
0212                     Layout.leftMargin: PlasmaCore.Units.smallSpacing
0213                     Layout.rightMargin: PlasmaCore.Units.smallSpacing
0214                     PlasmaComponents3.ToolTip { text: i18n("Send Email") }
0215                     onLinkActivated: Qt.openUrlExternally(link)
0216                     MouseArea {
0217                         id: area
0218                         anchors.fill: parent
0219                         hoverEnabled: true
0220                         cursorShape: Qt.PointingHandCursor
0221                         onClicked: Qt.openUrlExternally(`mailto:${model.display}`)
0222                     }
0223                 }
0224             }
0225 
0226             PlasmaExtras.Heading {
0227                 Layout.topMargin: PlasmaCore.Units.smallSpacing
0228                 Layout.leftMargin: PlasmaCore.Units.smallSpacing
0229                 Layout.rightMargin: PlasmaCore.Units.smallSpacing
0230                 visible: phoneRepeater.count > 0
0231                 text: i18np("Phone number", "Phone numbers", phoneRepeater.count)
0232                 level: 4
0233             }
0234 
0235             Repeater {
0236                 id: phoneRepeater
0237                 model: addressee.phoneModel
0238                 PlasmaComponents3.Label {
0239                     visible: text !== ""
0240                     text: i18n("%1:", model.type) + ` <a href="tel:${model.display}">${model.display}</a>`
0241                     Layout.leftMargin: PlasmaCore.Units.smallSpacing
0242                     Layout.rightMargin: PlasmaCore.Units.smallSpacing
0243                     PlasmaComponents3.ToolTip { text: i18n("Call") }
0244                     onLinkActivated: Qt.openUrlExternally(link)
0245                     MouseArea {
0246                         id: area
0247                         anchors.fill: parent
0248                         hoverEnabled: true
0249                         cursorShape: Qt.PointingHandCursor
0250                         onClicked: Qt.openUrlExternally(`tel:${model.display}`)
0251                     }
0252                 }
0253             }
0254         }
0255     }
0256 }