ContactsList.qml 2.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 *   Copyright 2015 Martin Klapetek <mklapetek@kde.org>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

Nicolas Fella's avatar
Nicolas Fella committed
20
import QtQuick 2.7
21
import QtQuick.Controls 2.2 as Controls
22
import QtQuick.Layouts 1.1
Nicolas Fella's avatar
Nicolas Fella committed
23
import org.kde.kirigami 2.10 as Kirigami
24
import org.kde.people 1.0 as KPeople
25

26
Item {
27
    Controls.Label {
28 29
        anchors.centerIn: parent
        text: i18n("No contacts")
Nicolas Fella's avatar
Nicolas Fella committed
30
        visible: contactsList.count === 0
31 32 33 34
    }

    ColumnLayout {
        anchors.fill: parent
35

36
        Kirigami.SearchField {
37
            id: searchField
38
            Layout.fillWidth: true
Nicolas Fella's avatar
Nicolas Fella committed
39
            onTextChanged: contactsProxyModel.setFilterFixedString(text)
40 41
        }

Nicolas Fella's avatar
Nicolas Fella committed
42 43
        ListView {
            id: contactsList
44 45 46
            Layout.fillWidth: true
            Layout.fillHeight: true

Nicolas Fella's avatar
Nicolas Fella committed
47 48 49 50
            section.property: "display"
            section.criteria: ViewSection.FirstCharacter
            section.delegate: Kirigami.ListSectionHeader {text: section}
            clip: true
51

Nicolas Fella's avatar
Nicolas Fella committed
52 53 54 55
            model: KPeople.PersonsSortFilterProxyModel {
                id: contactsProxyModel
                sourceModel: KPeople.PersonsModel {
                    id: contactsModel
56
                }
Nicolas Fella's avatar
Nicolas Fella committed
57 58 59 60 61 62
                requiredProperties: "phoneNumber"
                filterRole: Qt.DisplayRole
                sortRole: Qt.DisplayRole
                filterCaseSensitivity: Qt.CaseInsensitive
                Component.onCompleted: sort(0)
            }
63

Nicolas Fella's avatar
Nicolas Fella committed
64
            boundsBehavior: Flickable.StopAtBounds
65

Nicolas Fella's avatar
Nicolas Fella committed
66 67
            Component {
                id: contactListDelegate
68

Nicolas Fella's avatar
Nicolas Fella committed
69 70 71 72
                Kirigami.BasicListItem {
                    icon: model.decoration
                    label: model.display
//                     onClicked: dialerUtils.dial(model.phoneNumber)
73
                }
Nicolas Fella's avatar
Nicolas Fella committed
74
            }
75

Nicolas Fella's avatar
Nicolas Fella committed
76 77 78
            delegate: Kirigami.DelegateRecycler {
                width: parent.width
                sourceComponent: contactListDelegate
79 80 81 82
            }
        }
    }
}