2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18import QtQuick.Window 2.0
19import AccountsService 0.1
21import Unity.Application 0.1
22import Ubuntu.Components 0.1
23import Ubuntu.Components.Popups 1.0
24import Ubuntu.Gestures 0.1
25import Ubuntu.SystemImage 0.1
26import Ubuntu.Telephony 0.1 as Telephony
27import Unity.Connectivity 0.1
28import Unity.Launcher 0.1
30import LightDM 0.1 as LightDM
32import SessionBroadcast 0.1
39import "Panel/Indicators"
40import Unity.Notifications 1.0 as NotificationBackend
41import Unity.Session 0.1
42import Unity.DashCommunicator 0.1
47 // this is only here to select the width / height of the window if not running fullscreen
48 property bool tablet: false
49 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
50 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
52 property real edgeSize: units.gu(2)
53 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
54 property url background: asImageTester.status == Image.Ready ? asImageTester.source
55 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
56 readonly property real panelHeight: panel.panelHeight
58 readonly property bool locked: LightDM.Greeter.active && !LightDM.Greeter.authenticated && !forcedUnlock
59 readonly property alias hasLockedApp: greeter.hasLockedApp
60 readonly property bool forcedUnlock: edgeDemo.running
61 onForcedUnlockChanged: if (forcedUnlock) lockscreen.hide()
63 property bool sideStageEnabled: shell.width >= units.gu(100)
64 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
66 property int maxFailedLogins: -1 // disabled by default for now, will enable via settings in future
67 property int failedLoginsDelayAttempts: 7 // number of failed logins
68 property int failedLoginsDelayMinutes: 5 // minutes of forced waiting
70 property int orientation
71 readonly property int deviceOrientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
72 onDeviceOrientationAngleChanged: {
73 if (!OrientationLock.enabled) {
74 orientation = Screen.orientation;
77 readonly property bool orientationLockEnabled: OrientationLock.enabled
78 onOrientationLockEnabledChanged: {
79 if (orientationLockEnabled) {
80 OrientationLock.savedOrientation = Screen.orientation;
82 orientation = Screen.orientation;
86 function activateApplication(appId) {
87 if (ApplicationManager.findApplication(appId)) {
88 ApplicationManager.requestFocusApplication(appId);
90 var execFlags = shell.sideStageEnabled ? ApplicationManager.NoFlag : ApplicationManager.ForceMainStage;
91 ApplicationManager.startApplication(appId, execFlags);
95 function startLockedApp(app) {
97 greeter.lockedApp = app;
99 shell.activateApplication(app);
102 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
105 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
113 id: backgroundSettings
114 schema.id: "org.gnome.desktop.background"
117 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
120 source: backgroundSettings.pictureUri != undefined && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
128 id: usageModeSettings
129 schema.id: "com.canonical.Unity8"
133 target: LauncherModel
134 property: "applicationManager"
135 value: ApplicationManager
138 Component.onCompleted: {
139 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
140 if (ApplicationManager.count > 0) {
141 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
143 if (orientationLockEnabled) {
144 orientation = OrientationLock.savedOrientation;
154 objectName: "dashCommunicator"
160 enabled: Powerd.status === Powerd.On
164 target: ApplicationManager
165 property: "forceDashActive"
166 value: launcher.shown || launcher.dashSwipe
171 onVolumeDownPressed: volumeControl.volumeDown()
172 onVolumeUpPressed: volumeControl.volumeUp()
173 onBothVolumeKeysPressed: screenGrabber.capture()
178 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
179 dialogs.onPowerKeyPressed();
180 event.accepted = true;
182 volumeKeyFilter.onKeyPressed(event.key);
183 event.accepted = false;
188 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
189 dialogs.onPowerKeyReleased();
190 event.accepted = true;
192 volumeKeyFilter.onKeyReleased(event.key);
193 event.accepted = false;
202 height: parent.height
203 visible: !ApplicationManager.empty
206 target: ApplicationManager
208 if (greeter.narrowMode) {
209 if (appId === "dialer-app" && callManager.hasCalls && shell.locked) {
210 // If we are in the middle of a call, make dialer lockedApp and show it.
211 // This can happen if user backs out of dialer back to greeter, then
212 // launches dialer again.
213 greeter.lockedApp = appId;
215 if (greeter.hasLockedApp) {
216 if (appId === greeter.lockedApp) {
217 lockscreen.hide() // show locked app
219 greeter.startUnlock() // show lockscreen if necessary
224 if (LightDM.Greeter.active) {
225 greeter.startUnlock()
230 onFocusedApplicationIdChanged: {
231 if (greeter.hasLockedApp && greeter.lockedApp !== ApplicationManager.focusedApplicationId) {
232 greeter.startUnlock()
234 panel.indicators.hide();
237 onApplicationAdded: {
238 if (greeter.shown && appId != "unity8-dash") {
239 greeter.startUnlock()
241 if (greeter.narrowMode && greeter.hasLockedApp && appId === greeter.lockedApp) {
242 lockscreen.hide() // show locked app
249 id: applicationsDisplayLoader
250 objectName: "applicationsDisplayLoader"
253 // When we have a locked app, we only want to show that one app.
254 // FIXME: do this in a less traumatic way. We currently only allow
255 // locked apps in phone mode (see FIXME in Lockscreen component in
256 // this same file). When that changes, we need to do something
257 // nicer here. But this code is currently just to prevent a
258 // theoretical attack where user enters lockedApp mode, then makes
259 // the screen larger (maybe connects to monitor) and tries to enter
261 property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
262 source: usageModeSettings.usageMode === "Windowed" ? "Stages/DesktopStage.qml"
263 : tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
266 target: applicationsDisplayLoader.item
267 property: "objectName"
271 target: applicationsDisplayLoader.item
272 property: "dragAreaWidth"
273 value: shell.edgeSize
276 target: applicationsDisplayLoader.item
277 property: "maximizedAppTopMargin"
278 // Not just using panel.panelHeight as that changes depending on the focused app.
279 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
282 target: applicationsDisplayLoader.item
283 property: "interactive"
284 value: edgeDemo.stagesEnabled && !greeter.shown && !lockscreen.shown && panel.indicators.fullyClosed && launcher.progress == 0 && !notifications.useModal
287 target: applicationsDisplayLoader.item
288 property: "spreadEnabled"
289 value: edgeDemo.stagesEnabled && !greeter.hasLockedApp
292 target: applicationsDisplayLoader.item
293 property: "inverseProgress"
294 value: launcher.progress
297 target: applicationsDisplayLoader.item
298 property: "orientation"
299 value: shell.orientation
306 objectName: "inputMethod"
307 anchors { fill: parent; topMargin: panel.panelHeight }
308 z: notifications.useModal || panel.indicators.shown ? overlay.z + 1 : overlay.z - 1
312 target: SurfaceManager
314 if (surface.type == MirSurfaceItem.InputMethod) {
315 inputMethod.surface = surface;
319 onSurfaceDestroyed: {
320 if (inputMethod.surface == surface) {
321 inputMethod.surface = null;
322 surface.parent = null;
324 if (!surface.parent) {
325 // there's no one displaying it. delete it right away
331 target: SessionManager
333 if (!session.parentSession && !session.application) {
334 // nothing is using it. delete it right away
342 objectName: "lockscreen"
344 hides: [launcher, panel.indicators]
347 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
348 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
352 height: parent.height - panel.panelHeight
353 background: shell.background
354 darkenBackground: 0.4
355 alphaNumeric: AccountsService.passwordDisplayHint === AccountsService.Keyboard
359 // FIXME: We *should* show emergency dialer if there is a SIM present,
360 // regardless of whether the side stage is enabled. But right now,
361 // the assumption is that narrow screens are phones which have SIMs
362 // and wider screens are tablets which don't. When we do allow this
363 // on devices with a side stage and a SIM, work should be done to
364 // ensure that the main stage is disabled while the dialer is present
365 // in the side stage. See the FIXME in the stage loader in this file.
366 showEmergencyCallButton: !shell.sideStageEnabled
368 onEntered: LightDM.Greeter.respond(passphrase);
369 onCancel: greeter.show()
370 onEmergencyCall: startLockedApp("dialer-app")
372 onShownChanged: if (shown) greeter.lockedApp = ""
374 function maybeShow() {
375 if (!shell.forcedUnlock) {
384 if (lockscreen.delayMinutes > 0) {
385 lockscreen.delayMinutes -= 1
386 if (lockscreen.delayMinutes > 0) {
393 Component.onCompleted: {
394 if (greeter.narrowMode) {
395 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
401 target: LightDM.Greeter
403 onShowGreeter: greeter.show()
404 onHideGreeter: greeter.login()
407 shell.enabled = true;
408 if (!LightDM.Greeter.active) {
409 return; // could happen if hideGreeter() comes in before we prompt
411 if (greeter.narrowMode) {
412 if (isDefaultPrompt) {
413 if (lockscreen.alphaNumeric) {
414 lockscreen.infoText = i18n.tr("Enter passphrase")
415 lockscreen.errorText = i18n.tr("Sorry, incorrect passphrase") + "\n" +
416 i18n.tr("Please re-enter")
418 lockscreen.infoText = i18n.tr("Enter passcode")
419 lockscreen.errorText = i18n.tr("Sorry, incorrect passcode")
422 lockscreen.infoText = i18n.tr("Enter %1").arg(text.toLowerCase())
423 lockscreen.errorText = i18n.tr("Sorry, incorrect %1").arg(text.toLowerCase())
426 lockscreen.maybeShow();
430 onPromptlessChanged: {
431 if (!LightDM.Greeter.active) {
432 return; // could happen if hideGreeter() comes in before we prompt
434 if (greeter.narrowMode) {
435 if (LightDM.Greeter.promptless && LightDM.Greeter.authenticated) {
439 lockscreen.maybeShow();
444 onAuthenticationComplete: {
445 shell.enabled = true;
446 if (LightDM.Greeter.authenticated) {
447 AccountsService.failedLogins = 0
449 // Else only penalize user for a failed login if they actually were
450 // prompted for a password. We do this below after the promptless
453 if (LightDM.Greeter.promptless) {
457 if (LightDM.Greeter.authenticated) {
460 AccountsService.failedLogins++
461 if (maxFailedLogins >= 2) { // require at least a warning
462 if (AccountsService.failedLogins === maxFailedLogins - 1) {
463 var title = lockscreen.alphaNumeric ?
464 i18n.tr("Sorry, incorrect passphrase.") :
465 i18n.tr("Sorry, incorrect passcode.")
466 var text = i18n.tr("This will be your last attempt.") + " " +
467 (lockscreen.alphaNumeric ?
468 i18n.tr("If passphrase is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted.") :
469 i18n.tr("If passcode is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted."))
470 lockscreen.showInfoPopup(title, text)
471 } else if (AccountsService.failedLogins >= maxFailedLogins) {
472 SystemImage.factoryReset() // Ouch!
475 if (failedLoginsDelayAttempts > 0 && AccountsService.failedLogins % failedLoginsDelayAttempts == 0) {
476 lockscreen.delayMinutes = failedLoginsDelayMinutes
477 forcedDelayTimer.start()
480 lockscreen.clear(true);
481 if (greeter.narrowMode) {
482 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
489 target: LightDM.Greeter
491 value: greeter.shown || lockscreen.shown || greeter.hasLockedApp
497 opacity: greeterWrapper.showProgress * 0.8
501 // Just a tiny wrapper to adjust greeter's x without messing with its own dragging
503 objectName: "greeterWrapper"
504 x: greeter.narrowMode ? launcher.progress : 0
507 height: parent.height - panel.panelHeight
510 enabled: !launcher.dashSwipe
514 property bool fullyShown: showProgress === 1.0
515 onFullyShownChanged: {
516 // Wait until the greeter is completely covering lockscreen before resetting it.
517 if (greeter.narrowMode && fullyShown && !LightDM.Greeter.authenticated) {
519 lockscreen.maybeShow();
523 readonly property real showProgress: MathUtils.clamp((1 - x/width) + greeter.showProgress - 1, 0, 1)
524 onShowProgressChanged: {
525 if (showProgress === 0) {
526 if ((LightDM.Greeter.promptless && LightDM.Greeter.authenticated) || shell.forcedUnlock) {
528 } else if (greeter.narrowMode) {
529 lockscreen.clear(false) // to reset focus if necessary
536 objectName: "greeter"
538 signal sessionStarted() // helpful for tests
540 property string lockedApp: ""
541 property bool hasLockedApp: lockedApp !== ""
544 hides: [launcher, panel.indicators]
546 loadContent: required || lockscreen.required // keeps content in memory for quick show()
550 background: shell.background
553 height: parent.height
555 dragHandleWidth: shell.edgeSize
557 function startUnlock() {
559 if (!LightDM.Greeter.authenticated) {
560 lockscreen.maybeShow()
571 if (LightDM.Greeter.startSessionSync()) {
582 // Disable everything so that user can't swipe greeter or
583 // launcher until we get first prompt/authenticate, which
584 // will re-enable the shell.
585 shell.enabled = false;
587 if (greeter.narrowMode) {
588 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
592 greeter.lockedApp = "";
593 greeter.forceActiveFocus();
597 Component.onCompleted: {
598 Connectivity.unlockAllModems()
601 onUnlocked: greeter.hide()
603 // Update launcher items for new user
604 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
605 AccountsService.user = user;
606 LauncherModel.setUser(user);
609 onTease: launcher.tease()
612 target: ApplicationManager
613 property: "suspended"
614 value: (greeter.shown && greeterWrapper.showProgress == 1) || lockscreen.shown
624 if (shell.locked && callManager.hasCalls) {
625 // We just received an incoming call while locked. The
626 // indicator will have already launched dialer-app for us, but
627 // there is a race between "hasCalls" changing and the dialer
628 // starting up. So in case we lose that race, we'll start/
629 // focus the dialer ourselves here too. Even if the indicator
630 // didn't launch the dialer for some reason (or maybe a call
631 // started via some other means), if an active call is
632 // happening, we want to be in the dialer.
633 startLockedApp("dialer-app")
643 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
644 !callManager.hasCalls && !edgeDemo.running) {
650 function showHome() {
651 if (edgeDemo.running) {
655 if (LightDM.Greeter.active) {
656 greeter.startUnlock()
659 var animate = !LightDM.Greeter.active && !stages.shown
660 dash.setCurrentScope(0, animate, false)
661 ApplicationManager.requestFocusApplication("unity8-dash")
664 function showDash() {
665 if (greeter.hasLockedApp || // just in case user gets here
666 (!greeter.narrowMode && shell.locked)) {
675 if (ApplicationManager.focusedApplicationId != "unity8-dash") {
676 ApplicationManager.requestFocusApplication("unity8-dash")
690 anchors.fill: parent //because this draws indicator menus
693 available: edgeDemo.panelEnabled && (!shell.locked || AccountsService.enableIndicatorsWhileLocked) && !greeter.hasLockedApp
694 contentEnabled: edgeDemo.panelContentEnabled
695 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
697 minimizedPanelHeight: units.gu(3)
698 expandedPanelHeight: units.gu(7)
700 indicatorsModel: visibleIndicators.model
704 id: visibleIndicators
705 // TODO: This should be sourced by device type (eg "desktop", "tablet", "phone"...)
706 Component.onCompleted: initialise(indicatorProfile)
709 greeterShown: greeter.shown || lockscreen.shown
712 property bool topmostApplicationIsFullscreen:
713 ApplicationManager.focusedApplicationId &&
714 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
716 fullscreenMode: (topmostApplicationIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
717 || greeter.hasLockedApp
722 objectName: "launcher"
724 readonly property bool dashSwipe: progress > 0
726 anchors.top: parent.top
727 anchors.topMargin: inverted ? 0 : panel.panelHeight
728 anchors.bottom: parent.bottom
730 dragAreaWidth: shell.edgeSize
731 available: edgeDemo.launcherEnabled && (!shell.locked || AccountsService.enableLauncherWhileLocked) && !greeter.hasLockedApp
732 inverted: usageModeSettings.usageMode === "Staged"
734 onShowDashHome: showHome()
736 onDashSwipeChanged: {
738 dash.setCurrentScope(0, false, true)
741 onLauncherApplicationSelected: {
742 if (greeter.hasLockedApp) {
743 greeter.startUnlock()
745 if (!edgeDemo.running)
746 shell.activateApplication(appId)
750 panel.indicators.hide()
756 id: modalNotificationBackground
758 visible: notifications.useModal && (notifications.state == "narrow")
771 model: NotificationBackend.Model
774 y: topmostIsFullscreen ? 0 : panel.panelHeight
776 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
781 when: overlay.width <= units.gu(60)
782 AnchorChanges { target: notifications; anchors.left: parent.left }
786 when: overlay.width > units.gu(60)
787 AnchorChanges { target: notifications; anchors.left: undefined }
788 PropertyChanges { target: notifications; width: units.gu(38) }
799 shutdownFadeOutRectangle.enabled = true;
800 shutdownFadeOutRectangle.visible = true;
801 shutdownFadeOut.start();
807 objectName: "edgeDemo"
809 paused: Powerd.status === Powerd.Off // Saves power
817 target: SessionBroadcast
818 onShowHome: showHome()
822 id: shutdownFadeOutRectangle
829 NumberAnimation on opacity {
834 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
835 DBusUnitySessionService.Shutdown();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list