aboutsummaryrefslogtreecommitdiff
path: root/qml/ConfigurePage.qml
blob: 70babb24429b55bbc3e75b2afcbbef4aa86e34cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQml.Models 2.1
import QtQuick.Dialogs 1.3
import org.kde.kirigami 2.12 as Kirigami

import DeltaChat 1.0

Kirigami.Page {
    title: qsTr("Configure account")
    id: configurePage

    required property DcContext context
    required property DcAccountsEventEmitter eventEmitter

    contextualActions: [
        Kirigami.Action {
            text: "Import backup"
            iconName: "document-import"
            onTriggered: importBackupDialog.open()
        }
    ]

    FileDialog {
        id: importBackupDialog
        title: "Import backup"
        folder: shortcuts.home
        onAccepted: {
            var url = importBackupDialog.fileUrl.toString()
            if (url.startsWith("file://")) {
                var filename = url.substring(7)
                console.log("Importing " + filename)
                configurePage.context.importBackup(filename)
            }
        }
    }

    Kirigami.FormLayout {
        anchors.fill: parent

        TextField {
            id: addressField

            Kirigami.FormData.label: "Address: "
        }
        TextField {
            id: passwordField

            Kirigami.FormData.label: "Password: "

            echoMode: TextInput.PasswordEchoOnEdit
        }

        Kirigami.Separator {
            Kirigami.FormData.isSection: true
            Kirigami.FormData.label: "Advanced settings"
        }
        TextField {
            id: imapLoginField

            Kirigami.FormData.label: "IMAP login: "
        }
        TextField {
            id: imapHostnameField

            Kirigami.FormData.label: "IMAP server: "
        }
        TextField {
            id: imapPortField

            Kirigami.FormData.label: "IMAP port: "
        }

        ListModel {
            id: securityModel
            ListElement { text: "Automatic"; value: 0 }
            ListElement { text: "SSL/TLS"; value: 1 }
            ListElement { text: "StartTLS"; value: 2 }
            ListElement { text: "Off"; value: 3 }
        }

        ComboBox {
            id: imapSecurity

            Kirigami.FormData.label: "IMAP security: "

            model: securityModel
            textRole: "text"
        }

        TextField {
            id: smtpLoginField

            Kirigami.FormData.label: "SMTP login: "
        }
        TextField {
            id: smtpPasswordField

            Kirigami.FormData.label: "SMTP password: "

            echoMode: TextInput.PasswordEchoOnEdit
        }
        TextField {
            id: smtpHostnameField

            Kirigami.FormData.label: "SMTP server: "
        }
        TextField {
            id: smtpPortField

            Kirigami.FormData.label: "SMTP port: "
        }
        ComboBox {
            id: smtpSecurity

            Kirigami.FormData.label: "SMTP security: "

            model: securityModel
            textRole: "text"
        }

        ComboBox {
            id: certificateChecks

            Kirigami.FormData.label: "Certificate checks: "

            model: ListModel {
                id: certificateChecksModel
                ListElement { text: "Automatic"; value: 0 }
                ListElement { text: "Strict"; value: 1 }
                ListElement { text: "Accept invalid certificates"; value: 2 }
            }
            textRole: "text"
        }

        ProgressBar {
            id: progressBar
            value: 0.0
        }
        Button {
            text: "Login"
            onClicked: {
                console.log("Login")
                configurePage.context.stopIo()
                configurePage.context.setConfig("addr", addressField.text)
                configurePage.context.setConfig("mail_pw", passwordField.text)
                configurePage.context.setConfig("mail_user", imapLoginField.text)
                configurePage.context.setConfig("mail_server", imapHostnameField.text)
                configurePage.context.setConfig("mail_port", imapPortField.text)
                configurePage.context.setConfig("mail_security", securityModel.get(imapSecurity.currentIndex).value)
                configurePage.context.setConfig("send_user", smtpLoginField.text)
                configurePage.context.setConfig("send_pw", smtpPasswordField.text)
                configurePage.context.setConfig("send_server", smtpHostnameField.text)
                configurePage.context.setConfig("send_port", smtpPortField.text)
                configurePage.context.setConfig("send_security", securityModel.get(smtpSecurity.currentIndex).value)
                let certificate_checks = certificateChecks.model.get(certificateChecks.currentIndex).value;
                configurePage.context.setConfig("imap_certificate_checks", certificate_checks)
                configurePage.context.setConfig("smtp_certificate_checks", certificate_checks)
                configurePage.context.configure()
            }
        }
    }

    Connections {
        target: configurePage.eventEmitter
        function onConfigureProgress(accountId, progress, comment) {
            progressBar.value = progress / 1000.0
        }
    }
}