AvailableAccounts.qml 4.08 KB
Newer Older
1
/*
2 3
 *   SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
 *   SPDX-FileCopyrightText: 2020 Dan Leinir Turthra Jensen <admin@leinir.dk>
4
 *
5
 *   SPDX-License-Identifier: LGPL-2.0-or-later
6 7
 */

8 9 10 11
import QtQuick 2.12
import QtQuick.Controls 2.12 as Controls
import QtQuick.Layouts 1.12

12 13 14
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kcm 1.2

15 16
import org.kde.kaccounts 1.2 as KAccounts

17 18
ScrollViewKCM {
    id: root
19
    title: i18n("Add New Account")
20

21 22 23 24 25 26 27
    header: Kirigami.InlineMessage {
        id: errorMessage
        type: Kirigami.MessageType.Error
        showCloseButton: true
        visible: false
    }

28
    view: ListView {
Nicolas Fella's avatar
Nicolas Fella committed
29 30 31

        clip: true

32 33 34 35 36
        model: KAccounts.ProvidersModel {}
        delegate: Kirigami.AbstractListItem {
            id: accountDelegate
            width: ListView.view.width
            enabled: model.supportsMultipleAccounts === true || model.accountsCount === 0
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
            contentItem: RowLayout {
                implicitWidth: accountDelegate.ListView.view.width
                implicitHeight: Kirigami.Units.iconSizes.large + Kirigami.Units.smallSpacing * 2
                spacing: Kirigami.Units.smallSpacing
                Kirigami.Icon {
                    source: model.iconName
                    Layout.preferredWidth: Kirigami.Units.iconSizes.large
                    Layout.preferredHeight: Kirigami.Units.iconSizes.large
                    Item {
                        visible: model.accountsCount > 0
                        anchors {
                            bottom: parent.bottom
                            right: parent.right
                        }
                        height: parent.height / 3
                        width: height
                        Rectangle {
                            anchors.fill: parent
                            radius: height / 2
                            color: Kirigami.Theme.highlightColor
                            border {
                                width: 1
                                color: Kirigami.Theme.highlightedTextColor
                            }
                        }
                        Controls.Label {
                            anchors.fill: parent
                            horizontalAlignment: Text.AlignHCenter
                            verticalAlignment: Text.AlignVCenter
                            color: Kirigami.Theme.highlightedTextColor
                            text: model.accountsCount
                        }
                    }
                }
72 73 74

                ColumnLayout {
                    spacing: 0
75
                    Layout.fillWidth: true
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
                    Layout.alignment: Qt.AlignVCenter

                    Controls.Label {
                        Layout.fillWidth: true
                        text: model.displayName
                        color: accountDelegate.pressed || accountDelegate.highlighted ? accountDelegate.activeTextColor : accountDelegate.textColor
                        elide: Text.ElideRight
                    }

                    Controls.Label {
                        Layout.fillWidth: true
                        text: model.description
                        color: accountDelegate.pressed || accountDelegate.highlighted ? accountDelegate.activeTextColor : accountDelegate.textColor
                        elide: Text.ElideRight
                        font: Kirigami.Theme.smallFont
                        opacity: 0.7
                        visible: text.length > 0
                    }
94 95
                }
            }
96
            onClicked: {
97
                var job = jobComponent.createObject(root, { "providerName": model.name })
98 99 100 101 102 103 104
                job.start()
            }
        }
    }

    Component {
        id: jobComponent
105
        KAccounts.CreateAccountJob {
106 107 108 109 110 111 112 113 114
            onFinished: {
                // Don't close when there is an error to show an error message
                if (error == 0) {
                    kcm.pop()
                } else {
                    errorMessage.text = errorText
                    errorMessage.visible = true
                }
            }
115 116 117
        }
    }
}