ContactsPage.qml 4.72 KB
Newer Older
1 2


3 4 5
/*
 * Copyright 2015  Martin Klapetek <mklapetek@kde.org>
 * Copyright 2019  Linus Jahn <lnj@kaidan.im>
6
 * Copyright 2019  Jonah Brüchert <jbb@kaidan.im>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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/>.
 */
24 25 26
import QtQuick 2.7
import QtQuick.Controls 2.0 as Controls
import QtQuick.Layouts 1.7
27 28

import org.kde.plasma.core 2.0 as PlasmaCore
29
import org.kde.kirigami 2.6 as Kirigami
30
import org.kde.people 1.0 as KPeople
31

32 33 34 35 36 37 38 39 40 41 42 43
Kirigami.ScrollablePage {
    title: i18n("Address book")

    // Brighter background color
    Kirigami.Theme.colorSet: Kirigami.Theme.View
    background: Rectangle {
        color: Kirigami.Theme.backgroundColor
    }

    FormPage {
        id: form
    }
44 45 46

    actions {
        main: Kirigami.Action {
47
            icon.name: "contact-new-symbolic"
48
            onTriggered: {
49
                form.state = "create"
50
                form.open()
51 52 53 54
            }
        }
    }

55
    Controls.Label {
56 57
        anchors.centerIn: parent
        text: i18n("No contacts")
58
        visible: contactsModel.count === 0
59 60
    }

61 62 63 64 65 66 67 68 69 70 71 72
    header: Rectangle {
        clip: true
        id: header
        height: searchField.implicitHeight + 2 * Kirigami.Units.largeSpacing
        width: root.width

        Controls.TextField {
            id: searchField
            placeholderText: i18n("Search")
            anchors.centerIn: parent
            anchors.margins: Kirigami.Units.largeSpacing
            width: parent.width - 2 * Kirigami.Units.largeSpacing
73
        }
74
    }
75

76 77
    ListView {
        id: contactsList
78

79 80
        property bool delegateSelected: false
        property string numberToCall
81

82 83 84 85 86
        section.property: "display"
        section.criteria: ViewSection.FirstCharacter
        clip: true
        model: PlasmaCore.SortFilterModel {
            sourceModel: KPeople.PersonsSortFilterProxyModel {
87
                sourceModel: KPeople.PersonsModel {
88
                    id: contactsModel
89
                }
90 91 92 93 94 95
            }
            sortRole: "display"
            filterRole: "display"
            filterRegExp: ".*" + searchField.text + ".*"
            sortOrder: Qt.AscendingOrder
        }
96

97 98 99 100 101
        // model.display, model.decoration, model.phoneNumber
        delegate: ContactListItem {
            height: Kirigami.Units.gridUnit * 3
            name: model.display
            icon: model.decoration
Jonah Brüchert's avatar
Jonah Brüchert committed
102
            personUri: model.personUri
103

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
            actions: [
                Kirigami.Action {
                    icon.name: "mail-message"
                    onTriggered: {
                        personActions.triggerAction(KPeople.TextChatAction)
                    }
                },
                Kirigami.Action {
                    icon.name: "call-start"
                    onTriggered: {
                        personActions.triggerAction(KPeople.AudioCallAction)
                    }
                },
                Kirigami.Action {
                    icon.name: "list-remove"
                    onTriggered: {
                        phonebook.deleteContact(personUri)
                    }
                },
                Kirigami.Action {
                    icon.name: "document-edit"
                    onTriggered: {
                        form.state = "update"
                        form.personUri = personUri
                        form.open()
                    }
                }
            ]

133
            onClicked: {
134
                console.log(phonebook.getContact(personUri))
135
                pageStack.push(detailPage, {
Jonah Brüchert's avatar
Jonah Brüchert committed
136
                                    personUri: model.personUri
137 138
                               })
            }
139
        }
140

141 142 143 144
        function toggleOverlayButtons(show) {
            if (show) {
                settingsRect.parent = contactsList.currentItem
                settingsRect.visible = true
145

146 147 148 149 150
                callRect.parent = contactsList.currentItem
                callRect.visible = true
            } else {
                settingsRect.visible = false
                callRect.visible = false
151 152 153 154
            }
        }
    }
}