ContactsPage.qml 4.45 KB
Newer Older
1 2 3
/*
 * Copyright 2015  Martin Klapetek <mklapetek@kde.org>
 * Copyright 2019  Linus Jahn <lnj@kaidan.im>
4
 * Copyright 2019  Jonah Brüchert <jbb@kaidan.im>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * 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 General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
22

23 24 25
import QtQuick 2.7
import QtQuick.Controls 2.0 as Controls
import QtQuick.Layouts 1.7
26
import QtQuick.Dialogs 1.0
27

Jonah Brüchert's avatar
Jonah Brüchert committed
28
import org.kde.kirigami 2.9 as Kirigami
29
import org.kde.people 1.0 as KPeople
30

31 32 33
import org.kde.phonebook 1.0


34 35 36
Kirigami.ScrollablePage {
    title: i18n("Address book")

37 38 39 40 41 42 43 44 45 46 47
    FileDialog {
        id: importFileDialog
        selectMultiple: false
        selectExisting: true
        onAccepted: importer.importVCards(fileUrl)
    }

    ContactImporter {
        id: importer
    }

48 49 50 51 52 53
    // Brighter background color
    Kirigami.Theme.colorSet: Kirigami.Theme.View
    background: Rectangle {
        color: Kirigami.Theme.backgroundColor
    }

54 55
    actions {
        main: Kirigami.Action {
56
            icon.name: "contact-new-symbolic"
57
            text: i18n("Create new")
58
            onTriggered: {
59
                pageStack.push(Qt.resolvedUrl("AddContactPage.qml"), {state: "create"})
60 61
            }
        }
62 63 64 65 66 67 68 69 70 71

        contextualActions: [
            Kirigami.Action {
                icon.name: "document-import"
                text: i18n("Import contacts")
                onTriggered: {
                    importFileDialog.open()
                }
            }
        ]
72 73
    }

74
    Controls.Label {
75 76
        anchors.centerIn: parent
        text: i18n("No contacts")
77
        visible: contactsList.count === 0
78 79
    }

80 81 82
    header: Rectangle {
        clip: true
        id: header
83
        color: Kirigami.Theme.backgroundColor
84 85 86
        height: searchField.implicitHeight + 2 * Kirigami.Units.largeSpacing
        width: root.width

Jonah Brüchert's avatar
Jonah Brüchert committed
87
        Kirigami.SearchField {
88 89 90 91
            id: searchField
            anchors.centerIn: parent
            anchors.margins: Kirigami.Units.largeSpacing
            width: parent.width - 2 * Kirigami.Units.largeSpacing
92
            onTextChanged: filterModel.setFilterFixedString(text)
93
        }
94
    }
95

96 97
    ListView {
        id: contactsList
98

99 100
        property bool delegateSelected: false
        property string numberToCall
101

102 103 104
        section.property: "display"
        section.criteria: ViewSection.FirstCharacter
        clip: true
105 106 107
        model: KPeople.PersonsSortFilterProxyModel {
            id: filterModel
            filterRole: Qt.DisplayRole
108
            filterCaseSensitivity: Qt.CaseInsensitive
109 110 111

            sourceModel: KPeople.PersonsModel {
                id: contactsModel
112 113
            }
        }
114

115 116 117 118 119 120 121
        Component {
            id: contactListDelegate
            ContactListItem {
                height: Kirigami.Units.gridUnit * 3
                name: model.display
                icon: model.decoration
                personUri: model.personUri
122

123 124 125 126 127 128 129 130 131 132 133 134
                actions: [
                    Kirigami.Action {
                        icon.name: "mail-message"
                        onTriggered: {
                            personActions.triggerAction(KPeople.TextChatAction)
                        }
                    },
                    Kirigami.Action {
                        icon.name: "call-start"
                        onTriggered: {
                            personActions.triggerAction(KPeople.AudioCallAction)
                        }
135
                    }
136
                ]
137

138 139 140 141 142
                onClicked: {
                    pageStack.push(detailPage, {
                                        personUri: model.personUri
                                   })
                }
143
            }
144
        }
145 146 147 148 149

        delegate: Kirigami.DelegateRecycler {
            width: parent.width
            sourceComponent: contactListDelegate
        }
150 151
    }
}