~paulliu/unity8/noninteractive20140804

« back to all changes in this revision

Viewing changes to qml/Shell.qml

  • Committer: Ying-Chun Liu
  • Date: 2014-10-14 14:37:20 UTC
  • mfrom: (1109.60.129 unity8)
  • Revision ID: paul.liu@canonical.com-20141014143720-xnqhcgv8xq9aj8lz
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    property url background
54
54
    readonly property real panelHeight: panel.panelHeight
55
55
 
56
 
    readonly property bool locked: LightDM.Greeter.active && !LightDM.Greeter.authenticated
 
56
    readonly property bool locked: LightDM.Greeter.active && !LightDM.Greeter.authenticated && !forcedUnlock
 
57
    readonly property bool forcedUnlock: edgeDemo.running
 
58
    onForcedUnlockChanged: if (forcedUnlock) lockscreen.hide()
57
59
 
58
60
    property bool sideStageEnabled: shell.width >= units.gu(100)
59
61
    readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
87
89
        }
88
90
    }
89
91
 
90
 
    function setFakeActiveForApp(app) {
91
 
        if (shell.locked) {
92
 
            greeter.fakeActiveForApp = app
93
 
            lockscreen.hide()
 
92
    function startLockedApp(app) {
 
93
        if (!shell.locked) {
 
94
            console.warn("Called startLockedApp(%1) when not locked, ignoring".arg(app))
 
95
            return
94
96
        }
 
97
        greeter.lockedApp = app
 
98
        shell.activateApplication(app)
95
99
    }
96
100
 
97
101
    Binding {
169
173
        Connections {
170
174
            target: ApplicationManager
171
175
            onFocusRequested: {
172
 
                if (appId === "dialer-app") {
173
 
                    // Always let the dialer-app through.  Either user asked
174
 
                    // for an emergency call or accepted an incoming call.
175
 
                    setFakeActiveForApp(appId)
176
 
                } else if (greeter.fakeActiveForApp !== "" && greeter.fakeActiveForApp !== appId) {
177
 
                    lockscreen.show();
 
176
                if (greeter.narrowMode) {
 
177
                    if (appId === "dialer-app" && callManager.hasCalls) {
 
178
                        // If we are in the middle of a call, make dialer lockedApp and show it.
 
179
                        // This can happen if user backs out of dialer back to greeter, then
 
180
                        // launches dialer again.
 
181
                        greeter.lockedApp = appId;
 
182
                    }
 
183
                    if (greeter.hasLockedApp) {
 
184
                        if (appId === greeter.lockedApp) {
 
185
                            lockscreen.hide() // show locked app
 
186
                        } else {
 
187
                            greeter.startUnlock() // show lockscreen if necessary
 
188
                        }
 
189
                    }
 
190
                    greeter.hide();
 
191
                } else {
 
192
                    if (LightDM.Greeter.active) {
 
193
                        greeter.startUnlock()
 
194
                    }
178
195
                }
179
 
                greeter.hide();
180
196
            }
181
197
 
182
198
            onFocusedApplicationIdChanged: {
183
 
                if (greeter.fakeActiveForApp !== "" && greeter.fakeActiveForApp !== ApplicationManager.focusedApplicationId) {
184
 
                    lockscreen.show();
 
199
                if (greeter.hasLockedApp && greeter.lockedApp !== ApplicationManager.focusedApplicationId) {
 
200
                    greeter.startUnlock()
185
201
                }
186
202
                panel.indicators.hide();
187
203
            }
188
204
 
189
205
            onApplicationAdded: {
190
206
                if (greeter.shown && appId != "unity8-dash") {
191
 
                    greeter.hide();
 
207
                    greeter.startUnlock()
192
208
                }
193
 
                if (appId === "dialer-app") {
194
 
                    // Always let the dialer-app through.  Either user asked
195
 
                    // for an emergency call or accepted an incoming call.
196
 
                    setFakeActiveForApp(appId)
 
209
                if (greeter.narrowMode && greeter.hasLockedApp && appId === greeter.lockedApp) {
 
210
                    lockscreen.hide() // show locked app
197
211
                }
198
212
                launcher.hide();
199
213
            }
201
215
 
202
216
        Loader {
203
217
            id: applicationsDisplayLoader
 
218
            objectName: "applicationsDisplayLoader"
204
219
            anchors.fill: parent
205
220
 
206
 
            source: shell.sideStageEnabled ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
 
221
            // When we have a locked app, we only want to show that one app.
 
222
            // FIXME: do this in a less traumatic way.  We currently only allow
 
223
            // locked apps in phone mode (see FIXME in Lockscreen component in
 
224
            // this same file).  When that changes, we need to do something
 
225
            // nicer here.  But this code is currently just to prevent a
 
226
            // theoretical attack where user enters lockedApp mode, then makes
 
227
            // the screen larger (maybe connects to monitor) and tries to enter
 
228
            // tablet mode.
 
229
            property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
 
230
            source: tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
207
231
 
208
232
            Binding {
209
233
                target: applicationsDisplayLoader.item
229
253
            Binding {
230
254
                target: applicationsDisplayLoader.item
231
255
                property: "spreadEnabled"
232
 
                value: edgeDemo.stagesEnabled && greeter.fakeActiveForApp === "" // to support emergency dialer hack
 
256
                value: edgeDemo.stagesEnabled && !greeter.hasLockedApp
233
257
            }
234
258
            Binding {
235
259
                target: applicationsDisplayLoader.item
304
328
        // and wider screens are tablets which don't.  When we do allow this
305
329
        // on devices with a side stage and a SIM, work should be done to
306
330
        // ensure that the main stage is disabled while the dialer is present
307
 
        // in the side stage.
 
331
        // in the side stage.  See the FIXME in the stage loader in this file.
308
332
        showEmergencyCallButton: !shell.sideStageEnabled
309
333
 
310
334
        onEntered: LightDM.Greeter.respond(passphrase);
311
335
        onCancel: greeter.show()
312
 
        onEmergencyCall: shell.activateApplication("dialer-app") // will automatically enter fake-active mode
313
 
 
314
 
        onShownChanged: if (shown) greeter.fakeActiveForApp = ""
 
336
        onEmergencyCall: startLockedApp("dialer-app")
 
337
 
 
338
        onShownChanged: if (shown) greeter.lockedApp = ""
 
339
 
 
340
        function maybeShow() {
 
341
            if (!shell.forcedUnlock) {
 
342
                show()
 
343
            }
 
344
        }
315
345
 
316
346
        Timer {
317
347
            id: forcedDelayTimer
355
385
                    lockscreen.errorText = i18n.tr("Sorry, incorrect %1").arg(text.toLowerCase())
356
386
                }
357
387
 
358
 
                lockscreen.show();
 
388
                lockscreen.maybeShow();
359
389
            }
360
390
        }
361
391
 
362
392
        onPromptlessChanged: {
363
 
            if (LightDM.Greeter.promptless && LightDM.Greeter.authenticated) {
364
 
                lockscreen.hide()
365
 
            } else {
366
 
                lockscreen.reset();
367
 
                lockscreen.show();
 
393
            if (greeter.narrowMode) {
 
394
                if (LightDM.Greeter.promptless && LightDM.Greeter.authenticated) {
 
395
                    lockscreen.hide()
 
396
                } else {
 
397
                    lockscreen.reset();
 
398
                    lockscreen.maybeShow();
 
399
                }
368
400
            }
369
401
        }
370
402
 
414
446
    Binding {
415
447
        target: LightDM.Greeter
416
448
        property: "active"
417
 
        value: greeter.shown || lockscreen.shown || greeter.fakeActiveForApp != ""
 
449
        value: greeter.shown || lockscreen.shown || greeter.hasLockedApp
418
450
    }
419
451
 
420
452
    Rectangle {
426
458
    Item {
427
459
        // Just a tiny wrapper to adjust greeter's x without messing with its own dragging
428
460
        id: greeterWrapper
429
 
        x: launcher.progress
 
461
        objectName: "greeterWrapper"
 
462
        x: greeter.narrowMode ? launcher.progress : 0
430
463
        y: panel.panelHeight
431
464
        width: parent.width
432
465
        height: parent.height - panel.panelHeight
439
472
        property bool fullyShown: showProgress === 1.0
440
473
        onFullyShownChanged: {
441
474
            // Wait until the greeter is completely covering lockscreen before resetting it.
442
 
            if (fullyShown && !LightDM.Greeter.authenticated) {
 
475
            if (greeter.narrowMode && fullyShown && !LightDM.Greeter.authenticated) {
443
476
                lockscreen.reset();
444
 
                lockscreen.show();
 
477
                lockscreen.maybeShow();
445
478
            }
446
479
        }
447
480
 
448
481
        readonly property real showProgress: MathUtils.clamp((1 - x/width) + greeter.showProgress - 1, 0, 1)
449
482
        onShowProgressChanged: {
450
483
            if (showProgress === 0) {
451
 
                if (LightDM.Greeter.authenticated) {
 
484
                if ((LightDM.Greeter.promptless && LightDM.Greeter.authenticated) || shell.forcedUnlock) {
452
485
                    greeter.login()
453
486
                } else if (greeter.narrowMode) {
454
487
                    lockscreen.clear(false) // to reset focus if necessary
462
495
 
463
496
            signal sessionStarted() // helpful for tests
464
497
 
465
 
            property string fakeActiveForApp: ""
 
498
            property string lockedApp: ""
 
499
            property bool hasLockedApp: lockedApp !== ""
466
500
 
467
501
            available: true
468
502
            hides: [launcher, panel.indicators]
469
503
            shown: true
470
504
            loadContent: required || lockscreen.required // keeps content in memory for quick show()
471
505
 
 
506
            locked: shell.locked
 
507
 
472
508
            defaultBackground: shell.background
473
509
 
474
510
            width: parent.width
476
512
 
477
513
            dragHandleWidth: shell.edgeSize
478
514
 
 
515
            function startUnlock() {
 
516
                if (narrowMode) {
 
517
                    if (!LightDM.Greeter.authenticated) {
 
518
                        lockscreen.maybeShow()
 
519
                    }
 
520
                    hide()
 
521
                } else {
 
522
                    show()
 
523
                    tryToUnlock()
 
524
                }
 
525
            }
 
526
 
479
527
            function login() {
480
528
                enabled = false;
481
529
                if (LightDM.Greeter.startSessionSync()) {
491
539
                if (shown) {
492
540
                    if (greeter.narrowMode) {
493
541
                        LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
 
542
                    } else {
 
543
                        reset()
494
544
                    }
495
 
                    greeter.fakeActiveForApp = "";
 
545
                    greeter.lockedApp = "";
496
546
                    greeter.forceActiveFocus();
497
547
                }
498
548
            }
521
571
    }
522
572
 
523
573
    Connections {
 
574
        id: callConnection
 
575
        target: callManager
 
576
 
 
577
        onHasCallsChanged: {
 
578
            if (shell.locked && callManager.hasCalls) {
 
579
                // We just received an incoming call while locked.  The
 
580
                // indicator will have already launched dialer-app for us, but
 
581
                // there is a race between "hasCalls" changing and the dialer
 
582
                // starting up.  So in case we lose that race, we'll start/
 
583
                // focus the dialer ourselves here too.  Even if the indicator
 
584
                // didn't launch the dialer for some reason (or maybe a call
 
585
                // started via some other means), if an active call is
 
586
                // happening, we want to be in the dialer.
 
587
                startLockedApp("dialer-app")
 
588
            }
 
589
        }
 
590
    }
 
591
 
 
592
    Connections {
524
593
        id: powerConnection
525
594
        target: Powerd
526
595
 
537
606
        }
538
607
 
539
608
        if (LightDM.Greeter.active) {
540
 
            if (!LightDM.Greeter.authenticated) {
541
 
                lockscreen.show()
542
 
            }
543
 
            greeter.hide()
 
609
            greeter.startUnlock()
544
610
        }
545
611
 
546
612
        var animate = !LightDM.Greeter.active && !stages.shown
549
615
    }
550
616
 
551
617
    function showDash() {
552
 
        if (greeter.fakeActiveForApp !== "") { // just in case user gets here
 
618
        if (greeter.hasLockedApp || // just in case user gets here
 
619
            (!greeter.narrowMode && shell.locked)) {
553
620
            return
554
621
        }
555
622
 
576
643
            anchors.fill: parent //because this draws indicator menus
577
644
            indicators {
578
645
                hides: [launcher]
579
 
                available: edgeDemo.panelEnabled && (!shell.locked || AccountsService.enableIndicatorsWhileLocked) && greeter.fakeActiveForApp === ""
 
646
                available: edgeDemo.panelEnabled && (!shell.locked || AccountsService.enableIndicatorsWhileLocked) && !greeter.hasLockedApp
580
647
                contentEnabled: edgeDemo.panelContentEnabled
581
648
                width: parent.width > units.gu(60) ? units.gu(40) : parent.width
582
649
                panelHeight: units.gu(3)
587
654
                    ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
588
655
 
589
656
            fullscreenMode: (topmostApplicationIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
590
 
                            || greeter.fakeActiveForApp !== ""
 
657
                            || greeter.hasLockedApp
591
658
        }
592
659
 
593
660
        Launcher {
600
667
            anchors.bottom: parent.bottom
601
668
            width: parent.width
602
669
            dragAreaWidth: shell.edgeSize
603
 
            available: edgeDemo.launcherEnabled && (!shell.locked || AccountsService.enableLauncherWhileLocked) && greeter.fakeActiveForApp === ""
 
670
            available: edgeDemo.launcherEnabled && (!shell.locked || AccountsService.enableLauncherWhileLocked) && !greeter.hasLockedApp
604
671
 
605
672
            onShowDashHome: showHome()
606
673
            onDash: showDash()
610
677
                }
611
678
            }
612
679
            onLauncherApplicationSelected: {
613
 
                if (greeter.fakeActiveForApp !== "") {
614
 
                    lockscreen.show()
 
680
                if (greeter.hasLockedApp) {
 
681
                    greeter.startUnlock()
615
682
                }
616
683
                if (!edgeDemo.running)
617
684
                    shell.activateApplication(appId)
691
758
 
692
759
    EdgeDemo {
693
760
        id: edgeDemo
 
761
        objectName: "edgeDemo"
694
762
        z: alphaDisclaimerLabel.z + 10
695
763
        paused: Powerd.status === Powerd.Off // Saves power
696
764
        greeter: greeter