Debian Codegraph @

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

raw ◀ ▶
4 Debian patches touch this file
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.4
18 import QtContacts 5.0
19
20 import Lomiri.Components 1.3
21 import Lomiri.Components.Popups 1.3
22 import Lomiri.Contacts 0.1
•23 import Lomiri.AddressBook.Base 0.1
24
25 Page {
26 id: root
27
28 property QtObject contact: null
•29 property QtObject contactMainConstituent: null
30 property var constituents: []
31 property string contactId
32 property alias extensions: extensionsContents.children
33 property alias model: contactFetch.model
•34 property alias editable: addressBookDetail.editable
35 property alias headerActions: trailingBar.actions
36
37 signal contactFetched(QtObject contact)
38 signal contactRemoved()
39 signal actionTrigerred(string action, QtObject contact, QtObject detail)
40
•41 function _ensureFullContact() {
42 if (contact) contactId = contact.contactId
43 else if (contactId == "") return
44 if (contact == null || constituents.length == 0) {
45 contactFetch.fetchContactFull(contactId)
46 }
47 }
48
49 header: PageHeader {
50 id: pageHeader
51
52 flickable: flickable
53 title: contact ? ContactsJS.formatToDisplay(contact, i18n.dtr("lomiri-addressbook-app", "No name")) : ""
54 trailingActionBar {
55 id: trailingBar
56 }
57 }
58
59 Connections {
60 target: contact
61 function onContactChanged() {
62 pageHeader.title = ContactsJS.formatToDisplay(contact, i18n.dtr("lomiri-addressbook-app", "No name"))
63 }
64 }
65
66 onContactChanged: {
67 if (!contact) {
•68 // Pop page if the contact get removed
69 root.contactRemoved()
•70 } else {
71 _ensureFullContact()
72 }
73 }
74
75 onActiveChanged: {
76 if (active) {
77 //WORKAROUND: to correct scroll back the page
78 flickable.returnToBounds()
79 }
80 }
81
82 ActivityIndicator {
83 id: busyIndicator
84
85 parent: root
86 running: (root.contact === null) && contactFetch.running
87 visible: running
88 anchors.centerIn: parent
89 }
90
91 ContactFetch {
92 id: contactFetch
93
94 onContactRemoved: root.contactRemoved()
95 onContactNotFound: PopupUtils.open(Qt.resolvedUrl("ContactFetchError.qml"), root)
96 onContactFetched: {
97 root.contact = contact
•98 root.contactMainConstituent = mainConstituent
99 root.constituents = constituents
100 root.contactFetched(root.contact)
101 }
102 }
103
104
105 Flickable {
106 id: flickable
107
108 flickableDirection: Flickable.VerticalFlick
109 anchors.fill: parent
110 clip: true
111 //WORKAROUND: There is a bug on SDK page that causes the page to appear flicked with small contents
112 // see bug #1223050
113 contentHeight: Math.max(contents.height, parent.height) + units.gu(2)
114 contentWidth: parent.width
115
116 Column {
117 id: contents
118
119 height: childrenRect.height
120 anchors {
121 top: parent.top
122 left: parent.left
123 right: parent.right
124 }
125
126 ContactDetailAvatarView {
127 id: contactDetailAvatar
128 objectName: "avatar"
129
130 contact: root.contact
•131 editable: root.editable
132 anchors.left: parent.left
133 height: implicitHeight
•134 width: implicitWidth
135
136 constituents: root.constituents
137 }
138
139 ContactDetailPhoneNumbersView {
140 objectName: "phones"
141
142 contact: root.contact
143 anchors {
144 left: parent.left
145 right: parent.right
146 }
147 height: implicitHeight
148 onActionTrigerred: root.actionTrigerred(actionName, root.contact, detail)
149 }
150
151 ContactDetailEmailsView {
152 objectName: "emails"
153
154 contact: root.contact
155 anchors {
156 left: parent.left
157 right: parent.right
158 }
159 height: implicitHeight
160 onActionTrigerred: root.actionTrigerred(actionName, root.contact, detail)
161 }
162
163 ContactDetailUrlView {
164 objectName: "emails"
165
166 contact: root.contact
167 anchors {
168 left: parent.left
169 right: parent.right
170 }
171 height: implicitHeight
172 }
173
174 ContactDetailOnlineAccountsView {
175 contact: root.contact
176 anchors {
177 left: parent.left
178 right: parent.right
179 }
180 height: implicitHeight
181 onActionTrigerred: root.actionTrigerred(actionName, root.contact, detail)
182 }
183
184 ContactDetailAddressesView {
185 objectName: "addresses"
186
187 contact: root.contact
188 anchors {
189 left: parent.left
190 right: parent.right
191 }
192 height: implicitHeight
193 onActionTrigerred: root.actionTrigerred(actionName, root.contact, detail)
194 }
195
196 ContactDetailBirthdayView {
197 objectName: "birthday"
198
199 contact: root.contact
200 anchors {
201 left: parent.left
202 right: parent.right
203 }
204 height: implicitHeight
205 }
206
207 ContactDetailOrganizationsView {
208 objectName: "organizations"
209
210 contact: root.contact
211 anchors {
212 left: parent.left
213 right: parent.right
214 }
215 height: implicitHeight
216 onActionTrigerred: root.actionTrigerred(actionName, root.contact, detail)
217 }
218
219 ContactDetailNoteView {
220 objectName: "note"
221
222 contact: root.contact
223 anchors {
224 left: parent.left
225 right: parent.right
226 }
227 height: implicitHeight
228 }
229
230 ContactDetailRingtoneView {
231 objectName: "ringtone"
232
233 contact: root.contact
234 anchors {
235 left: parent.left
236 right: parent.right
237 }
238 height: implicitHeight
239 }
240
•241 ContactDetailAddressBooksView {
•242 id: addressBookDetail
•243 objectName: "addressBookDetail"
244 model: root.model
245 constituents: root.constituents
246
247 anchors {
248 left: parent.left
249 right: parent.right
250 }
251 height: implicitHeight
252
253 }
254
255 Item {
256 id: extensionsContents
257
258 anchors {
259 left: parent.left
260 right: parent.right
261 }
262 height: childrenRect.height
263 }
264 }
265 }
266
•267 Component.onCompleted: _ensureFullContact()
268 onContactIdChanged: _ensureFullContact()
269 onModelChanged: _ensureFullContact()
270 }