2
* Copyright (C) 2012-2013 Canonical, Ltd.
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.
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.
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/>.
19
import Ubuntu.Components 0.1
20
import Ubuntu.Components.ListItems 0.1 as ListItem
23
\qmltype ContactSimpleListView
24
\inqmlmodule Ubuntu.Contacts 0.1
26
\brief The ContactSimpleListView provides a simple contact list view
28
The ContactSimpleListView provide a easy way to show the contact list view
29
with all default visuals defined by Ubuntu system.
33
import Ubuntu.Contacts 0.1
35
ContactSimpleListView {
37
onContactClicked: console.debug("Contact ID:" + contactId)
46
\qmlproperty bool showAvatar
48
This property holds if the contact avatar will appear on the list or not.
49
By default this is set to true.
51
property bool showAvatar: true
53
\qmlproperty int titleDetail
55
This property holds the contact detail which will be used to display the contact title in the delegate
56
By default this is set to ContactDetail.Name.
58
property int titleDetail: ContactDetail.Name
60
\qmlproperty list<int> titleFields
62
This property holds the list of all fields which will be used to display the contact title in the delegate
63
By default this is set to [ Name.FirstName, Name.LastName ]
65
property variant titleFields: [ Name.FirstName, Name.LastName ]
67
\qmlproperty int subTitleDetail
69
This property holds the contact detail which will be used to display the contact subtitle in the delegate
70
By default this is set to ContactDetail.Organization
72
property int subTitleDetail: ContactDetail.Organization
74
\qmlproperty list<int> subTitleFields
76
This property holds the list of all fields which will be used to display the contact subtitle in the delegate
77
By default this is set to [ Organization.Name ]
79
property variant subTitleFields: [ Organization.Name ]
81
\qmlproperty list<SortOrder> sortOrders
83
This property holds a list of sort orders used by the contacts model.
86
property alias sortOrders: contactsModel.sortOrders
88
\qmlproperty FetchHint fetchHint
90
This property holds the fetch hint instance used by the contact model.
94
property alias fetchHint: contactsModel.fetchHint
96
\qmlproperty Filter filter
98
This property holds the filter instance used by the contact model.
102
property alias filter: contactsModel.filter
104
\qmlproperty bool loading
106
This property holds when the model still loading new contacts
108
readonly property bool loading: busyIndicator.busy
110
This handler is called when any error occurs in the contact model
112
signal error(string message)
114
This handler is called when any contact int the list receives a click.
116
signal contactClicked(string contactId)
118
function formatToDisplay(contact, contactDetail, detailFields) {
123
var detail = contact.detail(contactDetail)
125
for (var i=0; i < detailFields.length; i++) {
126
if (i > 0 && detail) {
130
values += detail.value(detailFields[i])
138
snapMode: ListView.NoSnap
140
property: "contact.name.firstName"
141
criteria: ViewSection.FirstCharacter
142
delegate: ListItem.Header {
154
delegate: ListItem.Subtitled {
155
icon: contactListView.showAvatar && contact && contact.avatar && (contact.avatar.imageUrl != "") ?
156
Qt.resolvedUrl(contact.avatar.imageUrl) :
157
"artwork:/avatar-default.png"
158
text: contactListView.formatToDisplay(contact, contactListView.titleDetail, contactListView.titleFields)
159
subText: contactListView.formatToDisplay(contact, contactListView.subTitleDetail, contactListView.subTitleFields)
162
contactListView.currentIndex = index
163
contactListView.contactClicked(contact.contactId)
175
detail: ContactDetail.Name
176
field: Name.FirstName
177
direction: Qt.AscendingOrder
181
fetchHint: FetchHint {
182
detailTypesHint: root.showAvatar ? [contactListView.titleDetail, contactListView.subTitleDetail, ContactDetail.Avatar] :
183
[contactListView.titleDetail, contactListView.subTitleDetail]
188
busyIndicator.busy = false
189
contactListView.error(error)
194
// This is a workaround to make sure the spinner will disappear if the model is empty
195
// FIXME: implement a model property to say if the model still busy or not
199
property bool busy: false
215
onTriggered: busyIndicator.busy = false