Debian Codegraph @

src/imports/Lomiri/AddressBook/ContactView/ContactDetailBirthdayView.qml

raw
1 /*
2 * Copyright (C) 2020 UBports Foundation.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 1.3
19 import Lomiri.Components.ListItems 1.3
20 import QtContacts 5.0 as QtContacts
21
22 import Lomiri.AddressBook.Base 0.1
23
24
25 ContactDetailBase {
26 id: root
27
28 property string date : detail && isDateValid(detail.birthday) ? Qt.formatDate(detail.birthday) : ""
29
30 detailType: QtContacts.ContactDetail.Birthday
31
32 activeFocusOnTab: false
33 visible: implicitHeight > 0
34 implicitHeight:(date.length > 0) ? contents.implicitHeight : 0
35
36 function isDateValid(dt) {
37 return dt instanceof Date && !isNaN(dt.valueOf())
38 }
39
40 Column {
41 id: contents
42 spacing: units.gu(1)
43 width: parent.width
44
45 ContactDetailTitle {
46 title: i18n.dtr("lomiri-addressbook-app", "Birthday")
47 }
48
49 Rectangle {
50
51 anchors {
52 left: parent.left
53 right: parent.right
54 leftMargin: units.gu(2)
55 rightMargin: units.gu(2)
56 }
57 height: childrenRect.height
58 color: theme.palette.normal.background
59
60 Label {
61 id: label
62 anchors.left: parent.left
63 height: units.gu(3)
64 fontSize: "medium"
65 text: root.date
66 }
67
68 Icon {
69 id: icon
70
71 anchors.right: parent.right
72 anchors.rightMargin: units.gu(1)
73 width: units.gu(2.5)
74 height: width
75 name: "calendar"
76 color: root.activeFocus ? theme.palette.normal.focus : theme.palette.normal.baseText
77 asynchronous: true
78 }
79 }
80 }
81
82 onClicked: {
83 var bdayDate = new Date(root.detail.birthday);
84 bdayDate.setFullYear(new Date().getFullYear())
85 Qt.openUrlExternally("calendar:///startdate=%1".arg(bdayDate.toISOString()))
86 }
87 }