File: GreeterView.qml

package info (click to toggle)
lomiri 0.5.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,088 kB
  • sloc: cpp: 39,498; python: 2,559; javascript: 1,426; ansic: 1,012; sh: 289; xml: 252; makefile: 69
file content (535 lines) | stat: -rw-r--r-- 17,377 bytes parent folder | download | duplicates (2)
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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/*
 * Copyright (C) 2015-2016 Canonical, Ltd.
 * Copyright (C) 2021 UBports Foundation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * 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 General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.15
import QtQuick.Window 2.2
import QtGraphicalEffects 1.12
import Lomiri.Components 1.3
import Lomiri.Telephony 0.1 as Telephony
import "../Components"

FocusScope {
    id: root
    objectName: "GreeterView"

    focus: true

    property url background
    property real backgroundSourceSize
    property real panelHeight
    property bool hasCustomBackground
    property alias dragHandleLeftMargin: coverPage.dragHandleLeftMargin
    property var infographicModel
    property alias launcherOffset: coverPage.launcherOffset
    property alias currentIndex: loginList.currentIndex
    property alias delayMinutes: delayedLockscreen.delayMinutes // TODO
    property alias alphanumeric: loginList.alphanumeric
    property alias hasKeyboard: loginList.hasKeyboard
    property bool locked
    property bool waiting
    property var userModel // Set from outside
    property bool multiUser: false
    property int orientation
    property bool isLandscape: root.orientation == Qt.LandscapeOrientation ||
                               root.orientation == Qt.InvertedLandscapeOrientation ||
                               usageMode == "desktop"
    property bool isPortrait: (root.orientation == Qt.PortraitOrientation ||
                              root.orientation == Qt.InvertedPortraitOrientation) &&
                              usageMode != "desktop"

    property string usageMode

    readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
    readonly property bool fullyShown: coverPage.showProgress === 1 || lockscreen.shown
    readonly property bool required: coverPage.required || lockscreen.required
    readonly property alias sessionToStart: loginList.currentSession

    property rect inputMethodRect

    signal selected(int index)
    signal responded(string response)
    signal tease()
    signal emergencyCall() // unused

    function notifyAuthenticationFailed() {
        loginList.showError();
    }

    function forceShow() {
        coverPage.show();
    }

    function tryToUnlock(toTheRight) {
        var coverChanged = coverPage.shown;
        if (toTheRight) {
            coverPage.hideRight();
        } else {
            coverPage.hide();
        }
        if (root.locked) {
            lockscreen.show();
            loginList.tryToUnlock();
            return false;
        } else {
            root.responded("");
            return coverChanged;
        }
    }

    function hide() {
        if (coverPage.visible) {
            lockscreen.hideNow();
        } else {
            lockscreen.hide();
        }
        coverPage.hide();
    }

    function showFakePassword() {
        loginList.showFakePassword();
    }

    function showErrorMessage(msg) {
        coverPage.showErrorMessage(msg);
    }

    onLockedChanged: changeLockscreenState()
    onMultiUserChanged: changeLockscreenState()

    function changeLockscreenState() {
        if (locked || multiUser) {
            lockscreen.maybeShow();
        } else {
            lockscreen.hide();
        }
    }

    Keys.onSpacePressed: coverPage.hide();
    Keys.onReturnPressed: coverPage.hide();
    Keys.onEnterPressed: coverPage.hide();

    CoverPage {
        id: lockscreen
        objectName: "lockscreen"
        height: parent.height
        width: parent.width
        draggable: false
        state: "LoginList"

        background: root.background
        backgroundSourceSize: root.backgroundSourceSize
        panelHeight: root.panelHeight
        hasCustomBackground: root.hasCustomBackground
        backgroundShadeOpacity: 0.6

        showInfographic: isLandscape && root.usageMode != "phone" && (root.usageMode != "tablet" || root.multiUser) && !delayedLockscreen.visible
        infographicModel: root.infographicModel

        shown: false
        opacity: 0

        showAnimation: StandardAnimation { property: "opacity"; to: 1 }
        hideAnimation:  SequentialAnimation {
            StandardAnimation { target: loginList; property: "opacity"; to: 0 }
            StandardAnimation { property: "opacity"; to: 0.5 }
        }

        infographicsTopMargin: parent.height * 0.125
        infographicsBottomMargin: parent.height * 0.125
        infographicsLeftMargin: loginList.x + loginList.width

        onTease: root.tease()

        onShowProgressChanged: {
            if (showProgress === 0 && !root.locked) {
                root.responded("");
            }
        }

        LoginList {
            id: loginList
            objectName: "loginList"

            width: units.gu(40)
            anchors {
                top: parent.top
                bottom: parent.bottom
            }

            boxVerticalOffset: (height - highlightedHeight -
                               inputMethodRect.height) / 2
            Behavior on boxVerticalOffset { LomiriNumberAnimation {} }

            enabled: !coverPage.shown && visible
            visible: !delayedLockscreen.visible

            model: coverPage.visible ? null : root.userModel
            onResponded: root.responded(response)
            onSelected: root.selected(index)
            onSessionChooserButtonClicked: parent.state = "SessionsList"
            onCurrentIndexChanged: setCurrentSession()

            locked: root.locked
            waiting: root.waiting

            Keys.forwardTo: [sessionChooserLoader.item]

            Component.onCompleted: setCurrentSession()

            function setCurrentSession() {
                currentSession = LightDMService.users.data(currentIndex, LightDMService.userRoles.SessionRole);
            }
        }

        DelayedLockscreen {
            id: delayedLockscreen
            objectName: "delayedLockscreen"
            anchors.fill: parent
            visible: delayMinutes > 0
            alphaNumeric: loginList.alphanumeric
        }

        function maybeShow() {
            if ((root.locked || root.multiUser) && !shown) {
                showNow();
            }
        }

        Loader {
            id: sessionChooserLoader

            height: loginList.height
            width: loginList.width

            anchors {
                left: parent.left
                leftMargin: Math.min(parent.width * 0.16, units.gu(20))
                top: parent.top
            }

            active: false

            onLoaded: sessionChooserLoader.item.forceActiveFocus();
            onActiveChanged: {
                if (!active) return;
                item.updateHighlight(loginList.currentSession);
            }

            Connections {
                target: sessionChooserLoader.item
                function onSessionSelected(sessionKey) { loginList.currentSession = sessionKey }
                function onShowLoginList() {
                    lockscreen.state = "LoginList"
                    loginList.tryToUnlock();
                }
                ignoreUnknownSignals: true
            }
        }

        // Use an AbstractButton due to icon limitations with Button
        AbstractButton {
            id: sessionChooser
            objectName: "sessionChooserButton"

            readonly property url icon: LightDMService.sessions.iconUrl(loginList.currentSession)

            visible: LightDMService.sessions.count > 1 &&
                !LightDMService.users.data(loginList.currentUserIndex, LightDMService.userRoles.LoggedInRole)

            height: units.gu(3.5)
            width: units.gu(3.5)

            activeFocusOnTab: true
            anchors {
                right: parent.right
                rightMargin: units.gu(2)

                bottom: parent.bottom
                bottomMargin: units.gu(1.5)
            }

            Rectangle {
                id: badgeHighlight

                anchors.fill: parent
                visible: parent.activeFocus
                color: "transparent"
                border.color: theme.palette.normal.focus
                border.width: units.dp(1)
                radius: 3
            }

            Icon {
                id: badge
                anchors.fill: parent
                anchors.margins: units.dp(3)
                keyColor: "#ffffff" // icon providers give us white icons
                color: theme.palette.normal.raisedSecondaryText
                source: sessionChooser.icon
            }

            Keys.onReturnPressed: {
                parent.state = "SessionsList";
            }

            onClicked: {
                parent.state = "SessionsList";
            }

            // Refresh the icon path if looking at different places at runtime
            // this is mainly for testing
            Connections {
                target: LightDMService.sessions
                function onIconSearchDirectoriesChanged() {
                    badge.source = LightDMService.sessions.iconUrl(root.currentSession)
                }
            }
        }

        states: [
            State {
                name: "SessionsList"
                PropertyChanges { target: loginList; opacity: 0 }
                PropertyChanges { target: sessionChooserLoader;
                                  active: true;
                                  opacity: 1
                                  source: "SessionsList.qml"
                                }
            },

            State {
                name: "LoginList"
                PropertyChanges { target: loginList; opacity: 1 }
                PropertyChanges { target: sessionChooserLoader;
                                  active: false;
                                  opacity: 0
                                  source: "";
                                }
            }
        ]

        transitions: [
            Transition {
                from: "*"
                to: "*"
                LomiriNumberAnimation {
                    property: "opacity";
                }
            }
        ]

        Component.onCompleted: if (root.multiUser) showNow()
    }

    Rectangle {
        anchors.fill: parent
        color: "black"
        opacity: coverPage.showProgress * 0.8
    }

    CoverPage {
        id: coverPage
        objectName: "coverPage"
        height: parent.height
        width: parent.width
        background: root.background
        hasCustomBackground: root.hasCustomBackground
        backgroundShadeOpacity: 0.4
        panelHeight: root.panelHeight
        draggable: !root.waiting
        onTease: root.tease()
        onClicked: hide()
        backgroundSourceSize: root.backgroundSourceSize
        infographicModel: root.infographicModel

        showInfographic: !root.multiUser && root.usageMode != "desktop"

        onShowProgressChanged: {
            if (showProgress === 0) {
                if (lockscreen.shown) {
                    loginList.tryToUnlock();
                } else {
                    root.responded("");
                }
            }
        }

        Clock {
            id: clock
            anchors.centerIn: parent
        }

        states: [
            State {
                name: "landscape-with-infographics"
                when: isLandscape && coverPage.showInfographic
                AnchorChanges {
                    target: clock
                    anchors.top: undefined
                    anchors.horizontalCenter: undefined
                    anchors.verticalCenter: undefined
                }
                PropertyChanges {
                    target: clock;
                    anchors.topMargin: undefined
                    anchors.centerIn: coverPage
                    anchors.horizontalCenterOffset: - coverPage.width / 2 + clock.width / 2 + units.gu(8)
                }
                PropertyChanges {
                    target: coverPage
                    infographicsLeftMargin: clock.width + units.gu(8)
                }
            },
            State {
                name: "portrait"
                when: isPortrait && coverPage.showInfographic
                AnchorChanges {
                    target: clock;
                    anchors.top: coverPage.top
                    anchors.horizontalCenter: coverPage.horizontalCenter
                    anchors.verticalCenter: undefined
                }
                PropertyChanges {
                    target: clock;
                    anchors.topMargin: units.gu(2) + panelHeight
                    anchors.centerIn: undefined
                    anchors.horizontalCenterOffset: 0
                }
                PropertyChanges {
                    target: coverPage
                    infographicsLeftMargin: 0
                }
            },
            State {
                name: "without-infographics"
                when: !coverPage.showInfographic
                AnchorChanges {
                    target: clock
                    anchors.top: undefined
                    anchors.horizontalCenter: coverPage.horizontalCenter
                    anchors.verticalCenter: coverPage.verticalCenter
                }
                PropertyChanges {
                    target: clock;
                    anchors.topMargin: 0
                    anchors.centerIn: undefined
                    anchors.horizontalCenterOffset: 0
                }
                PropertyChanges {
                    target: coverPage
                    infographicsLeftMargin: 0
                }
            }
        ]
    }

    StyledItem {
        id: bottomBar
        visible: usageMode == "phone" && lockscreen.shown
        height: units.gu(4)

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.bottom
        anchors.topMargin: - height * (1 - coverPage.showProgress)
                           - ( inputMethodRect.height )

        Label {
            text: i18n.tr("Cancel")
            anchors.left: parent.left
            anchors.leftMargin: units.gu(2)
            anchors.top: parent.top
            anchors.bottom: parent.bottom
            verticalAlignment: Text.AlignVCenter
            font.weight: Font.Light
            fontSize: "small"
            color: theme.palette.normal.raisedSecondaryText

            AbstractButton {
                anchors.fill: parent
                anchors.leftMargin: -units.gu(2)
                anchors.rightMargin: -units.gu(2)
                onClicked: coverPage.show()
            }
        }

        Label {
            objectName: "emergencyCallLabel"
            text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency")
            anchors.right: parent.right
            anchors.rightMargin: units.gu(2)
            anchors.top: parent.top
            anchors.bottom: parent.bottom
            verticalAlignment: Text.AlignVCenter
            font.weight: Font.Light
            fontSize: "small"
            color: theme.palette.normal.raisedSecondaryText
            // TODO: uncomment once bug 1616538 is fixed
            // visible: telepathyHelper.ready && telepathyHelper.emergencyCallsAvailable
            enabled: visible

            AbstractButton {
                anchors.fill: parent
                anchors.leftMargin: -units.gu(2)
                anchors.rightMargin: -units.gu(2)
                onClicked: root.emergencyCall()
            }
        }
    }

    states: [
        State {
            name: "phone"
            when: root.usageMode == "phone" || (root.usageMode == "tablet" && isPortrait)
            AnchorChanges {
                target: loginList;
                anchors.horizontalCenter: lockscreen.horizontalCenter;
                anchors.left: undefined;
            }
            PropertyChanges {
                target: loginList;
                anchors.leftMargin: 0;
            }
        },
        State {
            name: "tablet"
            when: root.usageMode == "tablet" && isLandscape
            AnchorChanges {
                target: loginList;
                anchors.horizontalCenter: undefined;
                anchors.left: lockscreen.left;
            }
            PropertyChanges {
                target: loginList;
                anchors.leftMargin: Math.min(lockscreen.width * 0.16, units.gu(8));
            }
        },
        State {
            name: "desktop"
            when: root.usageMode == "desktop"
            AnchorChanges {
                target: loginList;
                anchors.horizontalCenter: undefined;
                anchors.left: lockscreen.left;
            }
            PropertyChanges {
                target: loginList;
                anchors.leftMargin: Math.min(lockscreen.width * 0.16, units.gu(20));
            }
        }
    ]
}