~phablet-team/address-book-service/contact-demo-app

« back to all changes in this revision

Viewing changes to ContactList.qml

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2013-06-17 21:57:47 UTC
  • Revision ID: renato.filho@canonical.com-20130617215747-fgxak6ikmuidxrg5
Added support for sort and display other fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
    ContactModel {
15
15
        id: contactsModel
16
16
 
 
17
        property string titleField : "First name"
 
18
        property string subTitleField: "Phone"
 
19
        property alias sortOrderField: sortOrder.field
 
20
 
17
21
        manager: "galera"
18
22
        sortOrders: [
19
23
            SortOrder {
 
24
                id: sortOrder
 
25
 
20
26
                detail: ContactDetail.Name
21
27
                field: Name.FirstName
22
28
                direction: Qt.AscendingOrder
26
32
            if (manager == "memory")
27
33
                contactsModel.importContacts(Qt.resolvedUrl("example.vcf"))
28
34
        }
 
35
 
 
36
        function getContactDetails(contact, fieldName) {
 
37
            if (contact) {
 
38
                if (fieldName === "First name") {
 
39
                    return contact.name.firstName
 
40
                } else if (fieldName === "Middle name") {
 
41
                    return contact.name.middleName
 
42
                } else if (fieldName === "Last name") {
 
43
                    return contact.name.lastName
 
44
                } else if (fieldName === "Full name") {
 
45
                    return contact.displayLabel.label
 
46
                } else if (fieldName === "Nickname") {
 
47
                    return contact.nickname.nickname
 
48
                } else if (fieldName === "Phone") {
 
49
                    return contact.phoneNumber.number
 
50
                } else if (fieldName === "e-mail") {
 
51
                    return contact.email.emailAddress
 
52
                } else {
 
53
                    return "null"
 
54
                }
 
55
            } else {
 
56
                return ""
 
57
            }
 
58
        }
29
59
    }
30
60
 
31
61
 
44
74
            property string contactId: contact.contactId
45
75
 
46
76
            icon: Qt.resolvedUrl("avatar.png")
47
 
            text: contact ? contact.name.firstName : ""
48
 
            subText: contact ? contact.phoneNumber.number : ""
 
77
            text: contactsModel.titleField ? contactsModel.getContactDetails(contact, contactsModel.titleField) : ""
 
78
            subText: contactsModel.subTitleField ? contactsModel.getContactDetails(contact, contactsModel.subTitleField) : ""
49
79
            selected: listView.currentIndex === index
50
80
 
51
81
            onClicked: {
62
92
 
63
93
    tools: ToolbarActions {
64
94
        Action {
 
95
            text: i18n.tr("Settings")
 
96
            iconSource: Qt.resolvedUrl("settings.png")
 
97
            onTriggered: pageStack.push(Qt.resolvedUrl("ContactSettings.qml"), {model: contactsModel})
 
98
        }
 
99
 
 
100
        Action {
65
101
            text: i18n.tr("Edit")
66
102
            iconSource: Qt.resolvedUrl("edit.png")
67
103
            onTriggered: pageStack.push(Qt.resolvedUrl("ContactEditor.qml"), {model: contactsModel, contact: listView.currentItem.contactObject})