Debian Codegraph @

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

raw
1 /*
2 * Copyright (C) 2014 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.4
18 import Lomiri.Components 1.3
19 import QtContacts 5.0
20 import Lomiri.Contacts 0.1
21
22 ContactDetailGroupWithTypeView {
23 id: root
24
25 // does not show the field if there is only one addressbook
26 function filterDetails(details) {
27 var result = []
28
29 if (sourceModel.contacts.length <= 1) {
30 return result;
31 }
32
33 for(var d in details) {
34 var isEmpty = true
35 for(var f in root.fields) {
36 var fieldValue = details[d].value(root.fields[f])
37 if (fieldValue && (String(fieldValue) !== "")) {
38 isEmpty = false
39 break;
40 }
41 }
42 if (!isEmpty) {
43 result.push(details[d])
44 }
45 }
46 return result
47 }
48
49 title: i18n.dtr("lomiri-addressbook-app", "Addressbook")
50 defaultIcon: "image://theme/contact-group"
51 detailType: ContactDetail.SyncTarget
52 typeModel: null
53 activeFocusOnTab: false
54
55 fields: [ SyncTarget.SyncTarget ]
56
57 ContactModel {
58 id: sourceModel
59
60 manager: ContactManager.manager()
61 filter: DetailFilter {
62 detail: ContactDetail.Type
63 field: Type.TypeField
64 value: Type.Group
65 matchFlags: DetailFilter.MatchExactly
66 }
67 autoUpdate: false
68 }
69
70 detailDelegate: ContactDetailWithTypeView {
71 property variant detailType: detail && root.contact && root.typeModelReady ? root.getType(detail) : ""
72
73 action: root.defaultAction
74 contact: root.contact
75 fields: root.fields
76 typeLabel: detailType ? detailType.label : ""
77
78 height: implicitHeight
79 width: root.width
80 activeFocusOnTab: false
81 onClicked: root.actionTrigerred(root.defaultAction.name, detail)
82
83 function overrideValue(detail, field)
84 {
85 if (detail.value(field + 1) == "system-address-book") {
86 return detail.value(field)
87 } else if (detail.value(field + 2) == "0") {
88 return i18n.dtr("lomiri-addressbook-app", "Personal - %1").arg(detail.value(field))
89 } else {
90 return detail.value(field)
91 }
92 }
93 }
94
95 Component.onCompleted: sourceModel.update()
96 }