LoginView.qml 10.8 KB
Newer Older
Leander Schulten's avatar
Leander Schulten committed
1
2
3
4
5
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.2
import custom.licht 1.0
Leander Schulten's avatar
Leander Schulten committed
6
import "components"
Leander Schulten's avatar
Leander Schulten committed
7
8
9

Item{
    property alias currentItem : listView.currentItem
10
11
12
13
14
15
16
17
18
19
20
21
22
    ColumnLayout{
        anchors.fill: parent
        ListView{
            id:listView
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.preferredHeight: model.rowCount() * 50
            clip: true
            highlightMoveDuration: 100
            highlightResizeDuration: 100
            model:userModel
            highlight: Rectangle{
                color: "lightblue"
Leander Schulten's avatar
Leander Schulten committed
23
            }
24
25
26
27
28
29
30
31
32
33
34
35
            highlightFollowsCurrentItem: true
            delegate:
                SwipeDelegate{
                swipe.left: Label {
                    id: deleteLabel
                    text: qsTr("Delete")
                    color: "white"
                    verticalAlignment: Label.AlignVCenter
                    padding: 12
                    height: parent.height
                    //SwipeDelegate.onClicked:
                    background: Rectangle {
36
37
38
39
40
41
42
                        color: deleteMouseArea.pressed ? Qt.darker("tomato", 1.1) : "tomato"
                    }
                    MouseArea{
                        id: deleteMouseArea
                        anchors.fill: parent
                        acceptedButtons: Qt.LeftButton
                        onClicked: askToDeletePopup.deleteUser(modelData)
43
                    }
Leander Schulten's avatar
Leander Schulten committed
44
                }
45
46
47
48
                Timer{
                    id:closeTimer
                    interval: 2000
                    onTriggered: parent.swipe.close()
Leander Schulten's avatar
Leander Schulten committed
49
                }
50
51
52
                swipe.onOpened: {
                    closeTimer.running = true;
                }
53
                swipe.enabled: modelData !== UserManagment.defaultUser && UserManagment.currentUser.havePermission(Permission.Admin);
54
55
56
57
                anchors.margins: 5
                clip:true
                width: parent.width
                Component.onCompleted: {
58
                    background.color = Qt.binding(function(){return UserManagment.currentUser === modelData?"lightblue":"white";});
59
60
61
62
63
                }
                Behavior on height {
                    NumberAnimation{
                        duration: 500
                        easing.type: Easing.OutQuart
Leander Schulten's avatar
Leander Schulten committed
64
65
                    }
                }
66
67
68
                TextInputField{
                    anchors.verticalCenter: parent.contentItem.verticalCenter
                    x: parent.contentItem.x + 10
69
                    text: modelData.name
70
                    width: Math.max(implicitWidth+20,70)
71
                    enabled: (UserManagment.currentUser.havePermission(Permission.Admin) || modelData === UserManagment.currentUser)&&modelData!==UserManagment.getDefaultUser()
72
73
74
                }
                Button{
                    visible: UserManagment.currentUser.havePermission(Permission.Admin);
75
                    text:"Change Permissions and Auto-Login"
76
77
78
79
80
                    anchors.right: buttonChangePassword.left
                    anchors.top: buttonChangePassword.top
                    anchors.bottom: buttonChangePassword.bottom
                    anchors.rightMargin: 5
                    onClicked: {
81
                        userSettingsPopup.show(modelData);
82
83
84
85
                    }
                }
                Button{
                    id:buttonChangePassword
86
                    visible: modelData === UserManagment.currentUser && modelData !== UserManagment.defaultUser;
87
88
89
90
91
92
93
94
95
                    text: "Change Password"
                    anchors.right: buttonLogin.left
                    anchors.top: buttonLogin.top
                    anchors.bottom: buttonLogin.bottom
                    anchors.rightMargin: 5
                }
                Button{
                    width: 80
                    id:buttonLogin
96
97
                    enabled: !(modelData===UserManagment.defaultUser&&modelData===UserManagment.currentUser)
                    text: modelData===UserManagment.currentUser?"Logout":"Login"
98
99
100
101
102
                    anchors.right: parent.right
                    anchors.top:parent.top
                    anchors.bottom: parent.bottom
                    anchors.rightMargin: 5
                    onClicked: {
103
                        if(modelData===UserManagment.getDefaultUser()){
104
                            UserManagment.logout();
105
                        }else if(modelData===UserManagment.currentUser){
106
107
                            UserManagment.logout()
                        }else{
108
                            dialog.user = modelData;
109
110
111
112
113
                            dialog.visible = true;
                        }
                    }
                }
                onClicked: listView.currentIndex = index
Leander Schulten's avatar
Leander Schulten committed
114
115
116
            }
        }

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
        Button{
            Layout.fillWidth: true
            Layout.leftMargin: 5
            Layout.rightMargin: 5
            id: buttonAdd
            text:"+"
            font.pixelSize: 15
            onClicked: addUserDialog.visible=true;
            enabled: UserManagment.currentUser.havePermission(Permission.Admin);
        }
        Label{
            Layout.topMargin: 10
            Layout.leftMargin: 5
            text: "Known Spotify Accounts"
            font.pixelSize: 18
        }
        Rectangle{
            color: "lightgrey"
            Layout.fillWidth: true
            height: 1
        }
Leander Schulten's avatar
Leander Schulten committed
138
139


140
141
142
143
144
145
        SpotifyLoginView{
            id: spotifyLoginView
            Layout.fillHeight: true
            Layout.fillWidth: true
            implicitHeight: 200;
        }
Leander Schulten's avatar
Leander Schulten committed
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    }


    function login(){

        if(UserManagment.login(dialog.user,password.text)){
            dialog.visible = false;
        }else{
            password.underlineColor = "red";
            cosAni.from = dialog.x+30;
            cosAni.to = dialog.x-30;
            fromToAni.to = dialog.x;
            cosAni.start();
            fromToAni.start();
        }

    }
    NumberAnimation {
        id:cosAni
        target: dialog
        property: "x"
        duration: 150
        easing.type: Easing.CosineCurve
        onStopped: if(from!==to)running=true
    }
    NumberAnimation {
        id:fromToAni
        target: cosAni
        properties: "to,from"
        duration: 500
        easing.type: Easing.Linear
    }

    Dialog{
        modality: Qt.WindowModal
        id:dialog
        title: "Enter Password"
        width:300
        property var user;
        onVisibleChanged: {
            if(visible)
                password.forceActiveFocus()
            password.text="";
        }
        contentItem:Pane{
            ColumnLayout{
                anchors.fill: parent
                RowLayout{
                    Label{
                        text:"Passwort:"
                    }
                    TextInputField{
                        echoMode: TextInput.Password
                        Layout.fillWidth: true
                        id: password
                        onAccepted: login();
                        KeyNavigation.tab:  loginButton
                    }
                }
                RowLayout{
                    Button{
                        Layout.fillWidth: true
                        text:"Abbrechen"
                        onClicked: dialog.visible = false
                    }
                    Button{
                        id:loginButton
                        Layout.fillWidth: true
                        text:"Einloggen"
                        onClicked: login()
                    }
                }
            }
        }
    }
    Dialog{
        modality: Qt.WindowModal
        id:addUserDialog
        title: "Create new user."
        width:300
        onVisibleChanged:{
            if(visible){
                username.text = "";;
                password1.text = "";
                password2.text = "";
            }
        }
        contentItem:
            Pane{
            GridLayout{
                anchors.fill: parent
                columns: 2
                Label{
                    text:"Username : "
                }
                TextInputField{
                    Layout.fillWidth: true
                    id:username
                    KeyNavigation.tab: password1
                    onAccepted: password1.forceActiveFocus()
                }
                Label{
                    text:"Password : "
                }
                TextInputField{
                    Layout.fillWidth: true
                    id:password1
                    echoMode: TextInput.Password
                    KeyNavigation.tab: password2
                    onAccepted: password2.forceActiveFocus()
                }
                Label{
                    text:"Password : "
                }
                TextInputField{
                    Layout.fillWidth: true
                    id:password2
                    echoMode: TextInput.Password
                    KeyNavigation.tab: createUser
                    onAccepted: createUser.forceActiveFocus()
                }

                Button{
                    id:dontCreateUser
                    text:"Abbrechen"
                    KeyNavigation.tab: createUser
                    onClicked: addUserDialog.visible = false
                }
                Button{
                    id:createUser
                    KeyNavigation.tab: dontCreateUser
                    Layout.fillWidth: true
                    text:"Create"
                    onClicked:{
                        if(username.text.length<3){
                            username.underlineColor = "red";
                            return;
                        }else{
                            username.underlineColor = "lightgreen";
                        }
                        if(password1.length<5){
                            password1.underlineColor = "red";
                            return;
                        }else{
                            password1.underlineColor="lightgreen";
                        }
                        if(password1.text!==password2.text){
                            password2.underlineColor="red";
                            return;
                        }else{
                            password2.underlineColor="lightgreen";
                        }
                        UserManagment.addUser(username.text,password1.text);
                        addUserDialog.visible=false;
                    }
                }
            }
        }
    }

306
307
308
309
310
311
312
313
314
315
    AskWhenRemovePopup{
        id: askToDeletePopup
        property var _user
        text: "Do you really want to delete the user " + (_user ? '"' + _user.name + '"' : "error")
        function deleteUser(user){
            _user = user;
            open();
        }
        onYesClicked: UserManagment.removeUser(_user);
    }
Leander Schulten's avatar
Leander Schulten committed
316

317
318
    UserSettingsPopup{
        id: userSettingsPopup
Leander Schulten's avatar
Leander Schulten committed
319
320
321
    }

}