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