1
/****************************************************************************
3
** Copyright (C) 2013 Canonical Ltd
5
****************************************************************************/
8
import Ubuntu.Components 0.1
9
import Ubuntu.Components.ListItems 0.1 as ListItem
11
import "ContactList.js" as Sections
16
property var startTime
18
Component.onCompleted: mainPage.startTime = new Date()
23
property string titleField : "First name"
24
property string subTitleField: "Phone"
25
property alias sortOrderField: sortOrder.field
32
detail: ContactDetail.Name
34
direction: Qt.AscendingOrder
38
fetchHint: FetchHint {
39
detailTypesHint: [ContactDetail.Avatar,
41
ContactDetail.PhoneNumber]
44
Component.onCompleted: {
45
if (manager == "memory")
46
contactsModel.importContacts(Qt.resolvedUrl("example.vcf"))
49
function getContactDetails(contact, fieldNames) {
53
var fieldNameList = fieldNames.split(",")
54
for (var fieldNameIndex in fieldNameList) {
55
var fieldName = fieldNameList[fieldNameIndex]
57
if (fieldName === "First name") {
58
value = contact.name.firstName
59
} else if (fieldName === "Middle name") {
60
value = contact.name.middleName
61
} else if (fieldName === "Last name") {
62
value = contact.name.lastName
63
} else if (fieldName === "Full name") {
64
value = contact.displayLabel.label
65
} else if (fieldName === "Nickname") {
66
value = contact.nickname.nickname
67
} else if (fieldName === "Phone") {
68
value = contact.phoneNumber.number
69
} else if (fieldName === "e-mail") {
70
value = contact.email.emailAddress
74
if (fullValue.length != 0)
86
property string selectedLetter: contactListView.contentY > 0 ? contactListView.itemAt(0, contactListView.contentY).sectionName : "A"
95
orientation: ListView.Horizontal
97
model: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ]
100
font.bold: alphabetView.selectedLetter == text
101
horizontalAlignment: Text.AlignHCenter
108
contactListView.scroolToSection(modelData)
118
property string title
121
snapMode: ListView.NoSnap
123
property: "contact.name.firstName"
124
criteria: ViewSection.FirstCharacter
125
delegate: ListItem.Header {
134
top: alphabetView.bottom
137
bottom: parent.bottom
140
header: ListItem.Header {
141
text: contactListView.title
146
if (mainPage.startTime) {
147
var currentTime = new Date();
148
var elapsed = currentTime.getTime() - mainPage.startTime.getTime()
149
contactListView.title = "Elapsed time to load " + count + " contacts: " + (elapsed/1000) + " secs"
153
delegate: ListItem.Subtitled {
154
property variant contactObject: contact
155
property string contactId: contact.contactId
156
property string sectionName: ListView.section
158
icon: contact && contact.avatar && (contact.avatar.imageUrl != "") ? Qt.resolvedUrl(contact.avatar.imageUrl) : "artwork:/avatar.png"
159
text: contactsModel.titleField ? contactsModel.getContactDetails(contact, contactsModel.titleField) : ""
160
subText: contactsModel.subTitleField ? contactsModel.getContactDetails(contact, contactsModel.subTitleField) : ""
161
selected: contactListView.currentIndex === index
166
contactListView.currentIndex = index
169
editContactPriv.contactId = contactListView.currentItem.contactObject.contactId
174
UbuntuNumberAnimation { id: scroolToSectionAnimation; target: contactListView; property: "contentY"; }
175
function scroolToSection(targetSection) {
176
scroolToSectionAnimation.from = contactListView.contentY
177
contactListView.positionViewAtIndex(Sections.getIndexFor(targetSection), ListView.Beginning)
178
scroolToSectionAnimation.to = contactListView.contentY
179
scroolToSectionAnimation.running = true
182
// function used to build the section cache by "ContactList.js"
183
function sectionValueForContact(contact) {
185
return contact.name && contact.name.firstName ? contact.name.firstName[0] : ""
199
Sections.initSectionData(contactListView)
206
property bool pageIsBusy: false
208
running: contactListView.count == 0 || pageIsBusy
210
anchors.centerIn: contactListView
213
tools: ToolbarActions {
215
text: i18n.tr("Settings")
216
iconSource: "artwork:/settings.png"
217
onTriggered: pageStack.push(Qt.resolvedUrl("ContactSettings.qml"), {model: contactsModel})
221
text: i18n.tr("Edit")
222
iconSource: "artwork:/edit.png"
224
editContactPriv.contactId = contactListView.currentItem.contactObject.contactId
229
iconSource: "artwork:/add.png"
230
onTriggered: pageStack.push(Qt.resolvedUrl("ContactEditor.qml"), {model: contactsModel})
233
text: i18n.tr("Delete")
234
iconSource: "artwork:/delete.png"
236
contactsModel.removeContact(contactListView.currentItem.contactId);
244
property string contactId
245
property int currentQueryId: -1
249
target: contactsModel
251
if (requestId == editContactPriv.currentQueryId) {
252
busyIndicator.pageIsBusy = false
253
pageStack.push(Qt.resolvedUrl("ContactEditor.qml"),
254
{model: contactsModel, contact: fetchedContacts[0]})
259
onContactIdChanged: {
260
if (!contactId || (currentQueryId != -1)) {
264
busyIndicator.pageIsBusy = true
266
currentQueryId = contactsModel.fetchContacts([contactId])
267
if (currentQueryId == -1) {
268
busyIndicator.pageIsBusy = false