Debian Codegraph @

src/imports/Lomiri/AddressBook/Base/ContactDetailBase.qml

raw
1 /*
2 * Copyright (C) 2012-2015 Canonical, Ltd.
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.12
18 import QtContacts 5.0 as QtContacts
19
20 FocusScope {
21 id: root
22 objectName: detail ? "base_" + detailToString(detail.type, -1) + "_" + index : ""
23
24 property variant action: null
25 property QtObject contact: null
26 property QtObject detail: null
27 property variant fields: null
28 property int detailType: 0
29 // help to test used to retrieve the correct element
30 property int index: -1
31 property alias highlightOnFocus: highlight.visible
32 property bool editing: false
33
34 signal clicked()
35
36 function detailToString(detail, field)
37 {
38 // name
39 var nameMap = {}
40 nameMap[QtContacts.Name.FirstName] = "firstName"
41 nameMap[QtContacts.Name.LastName] = "lastName"
42
43 // phone
44 var phoneMap = {}
45 phoneMap[QtContacts.PhoneNumber.Number] = "phoneNumber"
46
47 // email
48 var emailMap = {}
49 emailMap[QtContacts.EmailAddress.EmailAddress] = "emailAddress"
50
51 // address
52 var addressMap = {}
53 addressMap[QtContacts.Address.Street] = "streetAddress"
54 addressMap[QtContacts.Address.Locality] = "localityAddress"
55 addressMap[QtContacts.Address.Region] = "regionAddress"
56 addressMap[QtContacts.Address.Postcode] = "postcodeAddress"
57 addressMap[QtContacts.Address.Country] = "countryAddress"
58 addressMap[QtContacts.Address.PostOfficeBox] = "postOfficeBoxAddress"
59
60 // im
61 var imMap = {}
62 imMap[QtContacts.OnlineAccount.AccountUri] = "imUri"
63 imMap[QtContacts.OnlineAccount.ServiceProvider] = "imProvider"
64 imMap[QtContacts.OnlineAccount.Protocol] = "imProtocol"
65 imMap[QtContacts.OnlineAccount.Capabilities] = "imCaps"
66
67 // organization
68 var organizationMap = {}
69 organizationMap[QtContacts.Organization.Name] = 'orgName'
70 organizationMap[QtContacts.Organization.Role] = 'orgRole'
71 organizationMap[QtContacts.Organization.Title] = 'orgTitle'
72
73 // SyncTarget
74 var syncTargetMap = {}
75 syncTargetMap[QtContacts.SyncTarget.SyncTarget] = "syncTarget"
76
77 // all
78 var detailMap = {}
79 detailMap[QtContacts.ContactDetail.Name] = nameMap
80 detailMap[QtContacts.ContactDetail.PhoneNumber] = phoneMap
81 detailMap[QtContacts.ContactDetail.Email] = emailMap
82 detailMap[QtContacts.ContactDetail.Address] = addressMap
83 detailMap[QtContacts.ContactDetail.OnlineAccount] = imMap
84 detailMap[QtContacts.ContactDetail.Organization] = organizationMap
85 detailMap[QtContacts.ContactDetail.SyncTarget] = syncTargetMap
86
87 // detail name
88 var detailNameMap = {}
89 detailNameMap[QtContacts.ContactDetail.Name] = "name"
90 detailNameMap[QtContacts.ContactDetail.PhoneNumber] = "phoneNumber"
91 detailNameMap[QtContacts.ContactDetail.Email] = "email"
92 detailNameMap[QtContacts.ContactDetail.Address] = "address"
93 detailNameMap[QtContacts.ContactDetail.OnlineAccount] = "onlineAccount"
94 detailNameMap[QtContacts.ContactDetail.SyncTarget] = "syncTarget"
95 detailNameMap[QtContacts.ContactDetail.Birthday] = "birthday"
96
97 if ((detail in detailMap) && (field in detailMap[detail])) {
98 return detailMap[detail][field]
99 } else if ((detail in detailNameMap) && (field == -1)){
100 return detailNameMap[detail]
101 } else {
102 return "unknown"
103 }
104 }
105
106 Rectangle {
107 id: highlight
108
109 anchors.fill: parent
110 visible: root.activeFocus || root.editing
111 color: Theme.palette.selected.background
112 z: -1
113 }
114
115 MouseArea {
116 anchors.fill: parent
117
118 onClicked: {
119 if (action) {
120 action.triggered(action)
121 }
122 root.clicked()
123 }
124 }
125
126 // prevent binding loop, note that onContactChanged is not fired when on edition mode,
127 Connections {
128 target: root.contact
129 enabled: root.detailType > 0
130 function onContactChanged() {
131 root.detail = root.contact.detail(root.detailType)
132 }
133 }
134
135 onContactChanged: {
136 if (root.contact && root.detailType > 0) {
137 root.detail = root.contact.detail(root.detailType)
138 }
139 }
140 }