Main.qml 18.6 KB
Newer Older
David Edmundson's avatar
David Edmundson committed
1
/*
David Edmundson's avatar
David Edmundson committed
2
 *   Copyright 2016 David Edmundson <davidedmundson@kde.org>
David Edmundson's avatar
David Edmundson committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 or
 *   (at your option) any later version.
 *
 *   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 Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

20
import QtQuick 2.8
21

David Edmundson's avatar
David Edmundson committed
22
import QtQuick.Layouts 1.1
Luca Beltrame's avatar
Luca Beltrame committed
23
import QtQuick.Controls 2.0
24
import QtGraphicalEffects 1.0
David Edmundson's avatar
David Edmundson committed
25
26
27

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
28
import org.kde.plasma.extras 2.0 as PlasmaExtras
David Edmundson's avatar
David Edmundson committed
29

30
31
import "components"

32
PlasmaCore.ColorScope {
David Edmundson's avatar
David Edmundson committed
33
    id: root
34
35
36
37
38

    // If we're using software rendering, draw outlines instead of shadows
    // See https://bugs.kde.org/show_bug.cgi?id=398317
    readonly property bool softwareRendering: GraphicsInfo.api === GraphicsInfo.Software

39
    colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
40
    readonly property bool lightBackground: Math.max(PlasmaCore.ColorScope.backgroundColor.r, PlasmaCore.ColorScope.backgroundColor.g, PlasmaCore.ColorScope.backgroundColor.b) > 0.5
David Edmundson's avatar
David Edmundson committed
41

42
43
    width: 1600
    height: 900
David Edmundson's avatar
David Edmundson committed
44

David Edmundson's avatar
David Edmundson committed
45
46
    property string notificationMessage

47
48
49
    LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
    LayoutMirroring.childrenInherit: true

50
51
52
53
54
55
    PlasmaCore.DataSource {
        id: keystateSource
        engine: "keystate"
        connectedSources: "Caps Lock"
    }

56
57
58
59
60
61
62
63
64
65
66
67
    Item {
        id: wallpaper
        anchors.fill: parent
        Repeater {
            model: screenModel

            Background {
                x: geometry.x; y: geometry.y; width: geometry.width; height: geometry.height
                sceneBackgroundType: config.type
                sceneBackgroundColor: config.color
                sceneBackgroundImage: config.background
            }
68
69
70
        }
    }

71
72
73
74
75
    MouseArea {
        id: loginScreenRoot
        anchors.fill: parent

        property bool uiVisible: true
Laurent Montel's avatar
Laurent Montel committed
76
        property bool blockUI: mainStack.depth > 1 || userListComponent.mainPasswordBox.text.length > 0 || inputPanel.keyboardActive || config.type !== "image"
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

        hoverEnabled: true
        drag.filterChildren: true
        onPressed: uiVisible = true;
        onPositionChanged: uiVisible = true;
        onUiVisibleChanged: {
            if (blockUI) {
                fadeoutTimer.running = false;
            } else if (uiVisible) {
                fadeoutTimer.restart();
            }
        }
        onBlockUIChanged: {
            if (blockUI) {
                fadeoutTimer.running = false;
                uiVisible = true;
            } else {
                fadeoutTimer.restart();
            }
David Edmundson's avatar
David Edmundson committed
96
        }
97

98
99
100
101
102
        Keys.onPressed: {
            uiVisible = true;
            event.accepted = false;
        }

103
        //takes one full minute for the ui to disappear
104
        Timer {
105
            id: fadeoutTimer
106
            running: true
107
108
109
110
111
112
113
114
            interval: 60000
            onTriggered: {
                if (!loginScreenRoot.blockUI) {
                    loginScreenRoot.uiVisible = false;
                }
            }
        }
        WallpaperFader {
Laurent Montel's avatar
Laurent Montel committed
115
            visible: config.type === "image"
116
117
118
119
120
121
122
123
            anchors.fill: parent
            state: loginScreenRoot.uiVisible ? "on" : "off"
            source: wallpaper
            mainStack: mainStack
            footer: footer
            clock: clock
        }

124
125
126
127
128
129
130
131
132
133
        DropShadow {
            id: clockShadow
            anchors.fill: clock
            source: clock
            visible: !softwareRendering
            horizontalOffset: 1
            verticalOffset: 1
            radius: 6
            samples: 14
            spread: 0.3
134
            color: root.lightBackground ? PlasmaCore.ColorScope.backgroundColor : "black" // black matches Breeze window decoration and desktopcontainment
135
136
137
138
139
140
141
142
            Behavior on opacity {
                OpacityAnimator {
                    duration: 1000
                    easing.type: Easing.InOutQuad
                }
            }
        }

143
144
145
        Clock {
            id: clock
            visible: y > 0
146
            property Item shadow: clockShadow
147
148
149
            y: (userListComponent.userList.y + mainStack.y)/2 - height/2
            anchors.horizontalCenter: parent.horizontalCenter
        }
David Edmundson's avatar
David Edmundson committed
150

151
152
153
154
155
156
        StackView {
            id: mainStack
            anchors {
                left: parent.left
                right: parent.right
            }
157
            height: root.height + units.gridUnit * 3
158
159
160
161
162
163
164
165
166
167
168
169

            focus: true //StackView is an implicit focus scope, so we need to give this focus so the item inside will have it

            Timer {
                //SDDM has a bug in 0.13 where even though we set the focus on the right item within the window, the window doesn't have focus
                //it is fixed in 6d5b36b28907b16280ff78995fef764bb0c573db which will be 0.14
                //we need to call "window->activate()" *After* it's been shown. We can't control that in QML so we use a shoddy timer
                //it's been this way for all Plasma 5.x without a huge problem
                running: true
                repeat: false
                interval: 200
                onTriggered: mainStack.forceActiveFocus()
170
            }
171

172
173
174
            initialItem: Login {
                id: userListComponent
                userListModel: userModel
175
                loginScreenUiVisible: loginScreenRoot.uiVisible
176
177
178
179
180
181
182
                userListCurrentIndex: userModel.lastIndex >= 0 ? userModel.lastIndex : 0
                lastUserName: userModel.lastUser
                showUserList: {
                    if ( !userListModel.hasOwnProperty("count")
                    || !userListModel.hasOwnProperty("disableAvatarsThreshold"))
                        return (userList.y + mainStack.y) > 0

Laurent Montel's avatar
Laurent Montel committed
183
                    if ( userListModel.count === 0 ) return false
184

185
186
                    if ( userListModel.hasOwnProperty("containsAllUsers") && !userListModel.containsAllUsers ) return false

187
                    return userListModel.count <= userListModel.disableAvatarsThreshold && (userList.y + mainStack.y) > 0
David Edmundson's avatar
David Edmundson committed
188
189
                }

190
191
192
193
194
195
196
197
198
199
                notificationMessage: {
                    var text = ""
                    if (keystateSource.data["Caps Lock"]["Locked"]) {
                        text += i18nd("plasma_lookandfeel_org.kde.lookandfeel","Caps Lock is on")
                        if (root.notificationMessage) {
                            text += ""
                        }
                    }
                    text += root.notificationMessage
                    return text
200
                }
201

202
203
204
                actionItems: [
                    ActionButton {
                        iconSource: "system-suspend"
205
                        text: i18ndc("plasma_lookandfeel_org.kde.lookandfeel","Suspend to RAM","Sleep")
206
207
208
209
210
211
212
213
214
215
216
217
218
                        onClicked: sddm.suspend()
                        enabled: sddm.canSuspend
                        visible: !inputPanel.keyboardActive
                    },
                    ActionButton {
                        iconSource: "system-reboot"
                        text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Restart")
                        onClicked: sddm.reboot()
                        enabled: sddm.canReboot
                        visible: !inputPanel.keyboardActive
                    },
                    ActionButton {
                        iconSource: "system-shutdown"
219
                        text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Shut Down")
220
221
222
223
224
                        onClicked: sddm.powerOff()
                        enabled: sddm.canPowerOff
                        visible: !inputPanel.keyboardActive
                    },
                    ActionButton {
225
                        iconSource: "system-user-prompt"
226
                        text: i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "For switching to a username and password prompt", "Other...")
227
228
229
230
231
232
233
234
235
                        onClicked: mainStack.push(userPromptComponent)
                        enabled: true
                        visible: !userListComponent.showUsernamePrompt && !inputPanel.keyboardActive
                    }]

                onLoginRequest: {
                    root.notificationMessage = ""
                    sddm.login(username, password, sessionButton.currentIndex)
                }
236
            }
237

238
239
240
241
            Behavior on opacity {
                OpacityAnimator {
                    duration: units.longDuration
                }
242
            }
243
        }
David Edmundson's avatar
David Edmundson committed
244

245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
        Loader {
            id: inputPanel
            state: "hidden"
            property bool keyboardActive: item ? item.active : false
            onKeyboardActiveChanged: {
                if (keyboardActive) {
                    state = "visible"
                } else {
                    state = "hidden";
                }
            }
            source: "components/VirtualKeyboard.qml"
            anchors {
                left: parent.left
                right: parent.right
260
261
            }

262
263
            function showHide() {
                state = state == "hidden" ? "visible" : "hidden";
264
            }
265
266
267
268
269
270
271

            states: [
                State {
                    name: "visible"
                    PropertyChanges {
                        target: mainStack
                        y: Math.min(0, root.height - inputPanel.height - userListComponent.visibleBoundary)
272
                    }
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
                    PropertyChanges {
                        target: inputPanel
                        y: root.height - inputPanel.height
                        opacity: 1
                    }
                },
                State {
                    name: "hidden"
                    PropertyChanges {
                        target: mainStack
                        y: 0
                    }
                    PropertyChanges {
                        target: inputPanel
                        y: root.height - root.height/4
                        opacity: 0
289
290
                    }
                }
291
292
293
294
295
296
297
298
299
300
301
            ]
            transitions: [
                Transition {
                    from: "hidden"
                    to: "visible"
                    SequentialAnimation {
                        ScriptAction {
                            script: {
                                inputPanel.item.activated = true;
                                Qt.inputMethod.show();
                            }
302
                        }
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
                        ParallelAnimation {
                            NumberAnimation {
                                target: mainStack
                                property: "y"
                                duration: units.longDuration
                                easing.type: Easing.InOutQuad
                            }
                            NumberAnimation {
                                target: inputPanel
                                property: "y"
                                duration: units.longDuration
                                easing.type: Easing.OutQuad
                            }
                            OpacityAnimator {
                                target: inputPanel
                                duration: units.longDuration
                                easing.type: Easing.OutQuad
                            }
321
322
                        }
                    }
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
                },
                Transition {
                    from: "visible"
                    to: "hidden"
                    SequentialAnimation {
                        ParallelAnimation {
                            NumberAnimation {
                                target: mainStack
                                property: "y"
                                duration: units.longDuration
                                easing.type: Easing.InOutQuad
                            }
                            NumberAnimation {
                                target: inputPanel
                                property: "y"
                                duration: units.longDuration
                                easing.type: Easing.InQuad
                            }
                            OpacityAnimator {
                                target: inputPanel
                                duration: units.longDuration
                                easing.type: Easing.InQuad
                            }
                        }
                        ScriptAction {
                            script: {
                                Qt.inputMethod.hide();
                            }
351
352
353
                        }
                    }
                }
354
355
356
            ]
        }

357

358
359
360
361
362
        Component {
            id: userPromptComponent
            Login {
                showUsernamePrompt: true
                notificationMessage: root.notificationMessage
363
                loginScreenUiVisible: loginScreenRoot.uiVisible
364

365
366
367
368
369
370
371
372
373
374
                // using a model rather than a QObject list to avoid QTBUG-75900
                userListModel: ListModel {
                    ListElement {
                        name: ""
                        iconSource: ""
                    }
                    Component.onCompleted: {
                        // as we can't bind inside ListElement
                        setProperty(0, "name", i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Type in Username and Password"));
                    }
375
376
377
378
379
380
                }

                onLoginRequest: {
                    root.notificationMessage = ""
                    sddm.login(username, password, sessionButton.currentIndex)
                }
David Edmundson's avatar
David Edmundson committed
381

382
383
                actionItems: [
                    ActionButton {
384
                        iconSource: "system-suspend"
385
                        text: i18ndc("plasma_lookandfeel_org.kde.lookandfeel","Suspend to RAM","Sleep")
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
                        onClicked: sddm.suspend()
                        enabled: sddm.canSuspend
                        visible: !inputPanel.keyboardActive
                    },
                    ActionButton {
                        iconSource: "system-reboot"
                        text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Restart")
                        onClicked: sddm.reboot()
                        enabled: sddm.canReboot
                        visible: !inputPanel.keyboardActive
                    },
                    ActionButton {
                        iconSource: "system-shutdown"
                        text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","Shut Down")
                        onClicked: sddm.powerOff()
                        enabled: sddm.canPowerOff
                        visible: !inputPanel.keyboardActive
                    },
                    ActionButton {
405
                        iconSource: "system-user-list"
406
                        text: i18nd("plasma_lookandfeel_org.kde.lookandfeel","List Users")
407
                        onClicked: mainStack.pop()
408
                        visible: !inputPanel.keyboardActive
409
410
                    }
                ]
David Edmundson's avatar
David Edmundson committed
411
            }
412
        }
David Edmundson's avatar
David Edmundson committed
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
        Image {
            id: logo
            visible: config.showlogo == "shown"
            source: config.logo
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom: footer.top
            anchors.bottomMargin: units.largeSpacing
            asynchronous: true
            sourceSize.height: height
            opacity: loginScreenRoot.uiVisible ? 0 : 1
            fillMode: Image.PreserveAspectFit
            height: Math.round(units.gridUnit * 3.5)
            Behavior on opacity {
                OpacityAnimator {
                    duration: units.longDuration
                    easing.type: Easing.InOutQuad
                }
            }
        }

        DropShadow {
            id: logoShadow
            anchors.fill: logo
Yunhe Guo's avatar
Yunhe Guo committed
437
            source: logo
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
            visible: !softwareRendering && config.showlogo == "shown"
            horizontalOffset: 1
            verticalOffset: 1
            radius: 6
            samples: 14
            spread: 0.3
            color: "black" // matches Breeze window decoration and desktopcontainment
            opacity: loginScreenRoot.uiVisible ? 0 : 1
            Behavior on opacity {
                OpacityAnimator {
                    duration: units.longDuration
                    easing.type: Easing.InOutQuad
                }
            }
        }

454
455
456
457
458
459
460
461
        //Footer
        RowLayout {
            id: footer
            anchors {
                bottom: parent.bottom
                left: parent.left
                right: parent.right
                margins: units.smallSpacing
David Edmundson's avatar
David Edmundson committed
462
463
            }

464
465
466
            Behavior on opacity {
                OpacityAnimator {
                    duration: units.longDuration
David Edmundson's avatar
David Edmundson committed
467
                }
468
            }
David Edmundson's avatar
David Edmundson committed
469

470
471
            PlasmaComponents.ToolButton {
                text: i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Button to show/hide virtual keyboard", "Virtual Keyboard")
472
                font.pointSize: config.fontSize
473
474
475
                iconName: inputPanel.keyboardActive ? "input-keyboard-virtual-on" : "input-keyboard-virtual-off"
                onClicked: inputPanel.showHide()
                visible: inputPanel.status == Loader.Ready
David Edmundson's avatar
David Edmundson committed
476
            }
David Edmundson's avatar
David Edmundson committed
477

478
479
            KeyboardButton {
            }
480

481
482
483
            SessionButton {
                id: sessionButton
            }
David Edmundson's avatar
David Edmundson committed
484

485
486
487
            Item {
                Layout.fillWidth: true
            }
David Edmundson's avatar
David Edmundson committed
488

489
            Battery { }
David Edmundson's avatar
David Edmundson committed
490
491
        }
    }
492

David Edmundson's avatar
David Edmundson committed
493
494
495
496
    Connections {
        target: sddm
        onLoginFailed: {
            notificationMessage = i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Login Failed")
497
498
499
            footer.enabled = true
            mainStack.enabled = true
            userListComponent.userList.opacity = 1
500
        }
David Edmundson's avatar
David Edmundson committed
501
502
503
504
505
506
        onLoginSucceeded: {
            //note SDDM will kill the greeter at some random point after this
            //there is no certainty any transition will finish, it depends on the time it
            //takes to complete the init
            mainStack.opacity = 0
            footer.opacity = 0
507
        }
David Edmundson's avatar
David Edmundson committed
508
    }
David Edmundson's avatar
David Edmundson committed
509

David Edmundson's avatar
David Edmundson committed
510
511
512
    onNotificationMessageChanged: {
        if (notificationMessage) {
            notificationResetTimer.start();
513
        }
David Edmundson's avatar
David Edmundson committed
514
    }
David Edmundson's avatar
David Edmundson committed
515
516
517
518
519
520

    Timer {
        id: notificationResetTimer
        interval: 3000
        onTriggered: notificationMessage = ""
    }
David Edmundson's avatar
David Edmundson committed
521
}