ContactsList.qml 4.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *   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.
 */

import QtQuick 2.0
21
import QtQuick.Controls 2.2 as Controls
22
import QtQuick.Layouts 1.1
23
import org.kde.kirigami 2.8 as Kirigami
24 25 26
import org.kde.people 1.0 as KPeople
import org.kde.plasma.core 2.0 as PlasmaCore

27

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

    ColumnLayout {
        anchors.fill: parent
37

38
        Kirigami.SearchField {
39
            id: searchField
40 41 42
            Layout.fillWidth: true
        }

43 44
        Controls.ScrollView {
            id: contactScrollView
45 46
            Layout.fillWidth: true
            Layout.fillHeight: true
47
            Controls.ScrollBar.vertical.policy: Controls.ScrollBar.AlwaysOn
48 49 50 51

            contentItem: ListView {
                id: contactsList

52
                property string numberToCall
53 54 55 56

                section.property: "display"
                section.criteria: ViewSection.FirstCharacter
                clip: true
57
                model: PlasmaCore.SortFilterModel {
58
                    sourceModel: KPeople.PersonsSortFilterProxyModel {
59
                        sourceModel: KPeople.PersonsModel {
60 61 62 63 64 65
                            id: contactsModel
                        }
                        requiredProperties: "phoneNumber"
                    }
                    sortRole: "display"
                    filterRole: "display"
66
                    filterRegExp: ".*" + searchField.text + ".*"
67 68 69 70 71 72 73 74 75 76
                    sortOrder: Qt.AscendingOrder
                }

        //         PlasmaCore.SortFilterModel {
        //             sortRole: "display"
        //             sourceModel:
        //         }

                boundsBehavior: Flickable.StopAtBounds

77 78
                delegate: Kirigami.SwipeListItem {
                    height: Kirigami.Units.gridUnit * 6
79 80 81 82
                    enabled: true
                    clip: true

                    onClicked: {
83
                            contactsList.numberToCall = model.phoneNumber;
84 85
                    }

86 87 88 89 90 91 92 93
                    actions: [
                        Kirigami.Action {
                            icon.name: "call-start"
                            text: i18n("Call")
                            onTriggered: call(contactsList.numberToCall)
                        },
                        Kirigami.Action {
                            icon.name: "configure-shortcuts"
Pino Toscano's avatar
Pino Toscano committed
94
                            text: i18n("Send Message")
95 96 97
                        }
                    ]

98 99 100 101

                    RowLayout {
                        id: mainLayout
                        anchors.fill: parent
102
                        spacing: 10
103

104 105 106 107
                        RoundImage {
                            id: avatar
                            source: model.decoration
                            isRound: true
108

109 110
                            Layout.preferredHeight: parent.height - Kirigami.Units.gridUnit
                            Layout.preferredWidth: parent.height - Kirigami.Units.gridUnit
111 112 113
                        }

                        ColumnLayout {
114 115
                            // contact name
                            Kirigami.Heading {
116 117
                                id: nickLabel
                                text: model.display
118
                                textFormat: Text.PlainText
119
                                elide: Text.ElideRight
120 121 122
                                maximumLineCount: 1
                                level: 3
                                Layout.fillWidth: true
123 124
                            }

125
                            Controls.Label {
126 127
                                id: dataLabel
                                text: model.phoneNumber
128

129
                                elide: Text.ElideRight
130
                                visible: dataLabel.text !== nickLabel.text
131 132 133 134 135 136 137 138 139 140 141 142
                            }
                        }
                    }
                }

                CustomSectionScroller {
                    listView: contactsList
                }
            }
        }
    }
}