1/*
2    SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
3
4    SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7import QtQuick 2.2
8import QtQuick.Controls 2.10
9import QtQuick.Layouts 1.1
10import org.kde.kirigami 2.12 as Kirigami
11import org.kde.kquickcontrolsaddons 2.0 as KQCA
12import Ubuntu.OnlineAccounts 0.1 as OA
13
14ColumnLayout
15{
16    id: root
17
18    property var folder: folderField.text
19    property var accountName
20    property var urls
21    property var mimeType
22
23    Kirigami.Heading {
24        text: i18nd("kio5_gdrive", "Select an account:")
25        visible: list.count !== 0
26    }
27
28    ScrollView {
29        id: scroll
30
31        Layout.fillWidth: true
32        Layout.fillHeight: true
33
34        Component.onCompleted: scroll.background.visible = true
35
36        ListView {
37            id: list
38
39            clip: true
40
41            model: OA.AccountServiceModel {
42                id: serviceModel
43                serviceType: "google-drive"
44            }
45
46            delegate: Kirigami.BasicListItem {
47                text: model.displayName
48            }
49
50            onCurrentIndexChanged: {
51                if (currentIndex === -1) {
52                    root.accountName = undefined
53                    return
54                }
55
56                root.accountName = serviceModel.get(list.currentIndex, "displayName")
57            }
58
59            Kirigami.PlaceholderMessage {
60                anchors.centerIn: parent
61                width: parent.width - (Kirigami.Units.largeSpacing * 4)
62                visible: list.count === 0
63                text: i18nd("kio5_gdrive", "No account configured")
64            }
65        }
66    }
67
68    Button {
69        Layout.alignment: Qt.AlignRight
70
71        text: i18nd("kio5_gdrive", "Configure Accounts")
72        icon.name: "applications-internet"
73        onClicked: KQCA.KCMShell.openSystemSettings("kcm_kaccounts")
74    }
75
76    Label {
77        Layout.fillWidth: true
78        text: i18nd("kio5_gdrive", "Upload to folder:")
79    }
80
81    TextField {
82        id: folderField
83        Layout.fillWidth: true
84        text: "/"
85        onTextChanged: {
86            // Setting folder to undefined disables the Run button
87            root.folder = text !== "" ? text : undefined
88        }
89    }
90}
91