2 * Copyright (C) 2013-2015 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/>.
18 import QtQuick.Window 2.0
19 import AccountsService 0.1
21 import Unity.Application 0.1
22 import Ubuntu.Components 0.1
23 import Ubuntu.Components.Popups 1.0
24 import Ubuntu.Gestures 0.1
25 import Ubuntu.Telephony 0.1 as Telephony
26 import Unity.Connectivity 0.1
27 import Unity.Launcher 0.1
28 import GlobalShortcut 1.0 // has to be before Utils, because of WindowKeysFilter
31 import SessionBroadcast 0.1
36 import "Notifications"
40 import Unity.Notifications 1.0 as NotificationBackend
41 import Unity.Session 0.1
42 import Unity.DashCommunicator 0.1
43 import Unity.Indicators 0.1 as Indicators
49 // to be set from outside
50 property int orientationAngle: 0
51 property int orientation
52 property int primaryOrientation
53 property int nativeOrientation
54 property real nativeWidth
55 property real nativeHeight
56 property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
57 property bool beingResized
58 property string usageScenario: "phone" // supported values: "phone", "tablet" or "desktop"
59 property string mode: "full-greeter"
60 function updateFocusedAppOrientation() {
61 applicationsDisplayLoader.item.updateFocusedAppOrientation();
63 function updateFocusedAppOrientationAnimated() {
64 applicationsDisplayLoader.item.updateFocusedAppOrientationAnimated();
66 property bool hasMouse
68 // to be read from outside
69 readonly property int mainAppWindowOrientationAngle:
70 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindowOrientationAngle : 0
72 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
73 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
74 && (!greeter || !greeter.animating)
76 readonly property bool showingGreeter: greeter && greeter.shown
78 property bool startingUp: true
79 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
81 property int supportedOrientations: {
83 // Ensure we don't rotate during start up
84 return Qt.PrimaryOrientation;
85 } else if (greeter && greeter.shown) {
86 return Qt.PrimaryOrientation;
88 return mainApp.supportedOrientations;
91 return Qt.PortraitOrientation
92 | Qt.LandscapeOrientation
93 | Qt.InvertedPortraitOrientation
94 | Qt.InvertedLandscapeOrientation;
98 // For autopilot consumption
99 readonly property string focusedApplicationId: ApplicationManager.focusedApplicationId
101 // internal props from here onwards
102 readonly property var mainApp:
103 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
105 // Disable everything while greeter is waiting, so that the user can't swipe
106 // the greeter or launcher until we know whether the session is locked.
107 enabled: greeter && !greeter.waiting
109 property real edgeSize: units.gu(2)
110 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
111 property url background: asImageTester.status == Image.Ready ? asImageTester.source
112 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
114 readonly property alias greeter: greeterLoader.item
116 function activateApplication(appId) {
117 if (ApplicationManager.findApplication(appId)) {
118 ApplicationManager.requestFocusApplication(appId);
120 var execFlags = shell.usageScenario === "phone" ? ApplicationManager.ForceMainStage
121 : ApplicationManager.NoFlag;
122 ApplicationManager.startApplication(appId, execFlags);
126 function startLockedApp(app) {
127 if (greeter.locked) {
128 greeter.lockedApp = app;
130 shell.activateApplication(app);
133 // This is a dummy image to detect if the custom AS set wallpaper loads successfully.
136 source: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : ""
144 id: backgroundSettings
145 schema.id: "org.gnome.desktop.background"
148 // This is a dummy image to detect if the custom GSettings set wallpaper loads successfully.
151 source: backgroundSettings.pictureUri && backgroundSettings.pictureUri.length > 0 ? backgroundSettings.pictureUri : ""
159 target: LauncherModel
160 property: "applicationManager"
161 value: ApplicationManager
164 Component.onCompleted: {
165 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
166 if (ApplicationManager.count > 0) {
167 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
169 finishStartUpTimer.start();
172 LightDM{id: lightDM} // Provide backend access
175 indicators: panel.indicators
180 objectName: "dashCommunicator"
184 id: physicalKeysMapper
185 objectName: "physicalKeysMapper"
187 onPowerKeyLongPressed: dialogs.showPowerDialog();
188 onVolumeDownTriggered: volumeControl.volumeDown();
189 onVolumeUpTriggered: volumeControl.volumeUp();
190 onScreenshotTriggered: screenGrabber.capture();
199 // dummy shortcut to force creation of GlobalShortcutRegistry before WindowKeyFilter
203 Keys.onPressed: physicalKeysMapper.onKeyPressed(event);
204 Keys.onReleased: physicalKeysMapper.onKeyReleased(event);
208 onActivated: { launcher.fadeOut(); shell.showHome(); }
215 height: parent.height
218 target: ApplicationManager
220 // This signal is also fired when we try to focus the current app
221 // again. We rely on this!
222 onFocusedApplicationIdChanged: {
223 var appId = ApplicationManager.focusedApplicationId;
225 if (tutorial.running && appId != "" && appId != "unity8-dash") {
226 // If this happens on first boot, we may be in edge
227 // tutorial or wizard while receiving a call. But a call
228 // is more important than wizard so just bail out of those.
233 if (appId === "dialer-app" && callManager.hasCalls && greeter.locked) {
234 // If we are in the middle of a call, make dialer lockedApp and show it.
235 // This can happen if user backs out of dialer back to greeter, then
236 // launches dialer again.
237 greeter.lockedApp = appId;
239 greeter.notifyAppFocused(appId);
241 panel.indicators.hide();
244 onApplicationAdded: {
250 id: applicationsDisplayLoader
251 objectName: "applicationsDisplayLoader"
254 // When we have a locked app, we only want to show that one app.
255 // FIXME: do this in a less traumatic way. We currently only allow
256 // locked apps in phone mode (see FIXME in Lockscreen component in
257 // this same file). When that changes, we need to do something
258 // nicer here. But this code is currently just to prevent a
259 // theoretical attack where user enters lockedApp mode, then makes
260 // the screen larger (maybe connects to monitor) and tries to enter
263 property string usageScenario: shell.usageScenario === "phone" || greeter.hasLockedApp
265 : shell.usageScenario
267 if(shell.mode === "greeter") {
268 return "Stages/ShimStage.qml"
269 } else if (applicationsDisplayLoader.usageScenario === "phone") {
270 return "Stages/PhoneStage.qml";
271 } else if (applicationsDisplayLoader.usageScenario === "tablet") {
272 return "Stages/TabletStage.qml";
274 return "Stages/DesktopStage.qml";
278 property bool interactive: tutorial.spreadEnabled
279 && (!greeter || !greeter.shown)
280 && panel.indicators.fullyClosed
281 && launcher.progress == 0
282 && !notifications.useModal
284 onInteractiveChanged: { if (interactive) { focus = true; } }
287 target: applicationsDisplayLoader.item
288 property: "objectName"
292 target: applicationsDisplayLoader.item
293 property: "dragAreaWidth"
294 value: shell.edgeSize
297 target: applicationsDisplayLoader.item
298 property: "maximizedAppTopMargin"
299 // Not just using panel.panelHeight as that changes depending on the focused app.
300 value: panel.indicators.minimizedPanelHeight + units.dp(2) // dp(2) for orange line
303 target: applicationsDisplayLoader.item
304 property: "interactive"
305 value: applicationsDisplayLoader.interactive
308 target: applicationsDisplayLoader.item
309 property: "spreadEnabled"
310 value: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
313 target: applicationsDisplayLoader.item
314 property: "inverseProgress"
315 value: greeter && greeter.locked ? 0 : launcher.progress
318 target: applicationsDisplayLoader.item
319 property: "shellOrientationAngle"
320 value: shell.orientationAngle
323 target: applicationsDisplayLoader.item
324 property: "shellOrientation"
325 value: shell.orientation
328 target: applicationsDisplayLoader.item
329 property: "background"
330 value: shell.background
333 target: applicationsDisplayLoader.item
334 property: "shellPrimaryOrientation"
335 value: shell.primaryOrientation
338 target: applicationsDisplayLoader.item
339 property: "nativeOrientation"
340 value: shell.nativeOrientation
343 target: applicationsDisplayLoader.item
344 property: "nativeWidth"
345 value: shell.nativeWidth
348 target: applicationsDisplayLoader.item
349 property: "nativeHeight"
350 value: shell.nativeHeight
353 target: applicationsDisplayLoader.item
354 property: "beingResized"
355 value: shell.beingResized
358 target: applicationsDisplayLoader.item
359 property: "keepDashRunning"
360 value: launcher.shown || launcher.dashSwipe
363 target: applicationsDisplayLoader.item
364 property: "suspended"
368 target: applicationsDisplayLoader.item
369 property: "altTabPressed"
370 value: physicalKeysMapper.altTabPressed
376 objectName: "tutorial"
379 // EdgeDragAreas don't work with mice. So to avoid trapping the user,
380 // we skip the tutorial on the Desktop to avoid using them. The
381 // Desktop doesn't use the same spread design anyway. The tutorial is
382 // all a bit of a placeholder on non-phone form factors right now.
383 // When the design team gives us more guidance, we can do something
385 active: usageScenario != "desktop" && AccountsService.demoEdges
387 paused: lightDM.greeter.active
390 edgeSize: shell.edgeSize
393 AccountsService.demoEdges = false;
394 active = false; // for immediate response / if AS is having problems
401 objectName: "inputMethod"
402 anchors { fill: parent; topMargin: panel.panelHeight }
403 z: notifications.useModal || panel.indicators.shown || wizard.active ? overlay.z + 1 : overlay.z - 1
407 target: SessionManager
409 if (!session.parentSession && !session.application) {
410 // nothing is using it. delete it right away
419 anchors.topMargin: panel.panelHeight
420 sourceComponent: shell.mode != "shell" ? integratedGreeter :
421 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
423 item.objectName = "greeter"
428 id: integratedGreeter
431 hides: [launcher, panel.indicators]
432 tabletMode: shell.usageScenario != "phone"
433 launcherOffset: launcher.progress
434 forcedUnlock: tutorial.running
435 background: shell.background
437 // avoid overlapping with Launcher's edge drag area
438 // FIXME: Fix TouchRegistry & friends and remove this workaround
439 // Issue involves launcher's DDA getting disabled on a long
441 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
448 if (!tutorial.running) {
453 onEmergencyCall: startLockedApp("dialer-app")
458 // See powerConnection for why this is useful
459 id: showGreeterDelayed
471 if (greeter.locked && callManager.hasCalls && greeter.lockedApp !== "dialer-app") {
472 // We just received an incoming call while locked. The
473 // indicator will have already launched dialer-app for us, but
474 // there is a race between "hasCalls" changing and the dialer
475 // starting up. So in case we lose that race, we'll start/
476 // focus the dialer ourselves here too. Even if the indicator
477 // didn't launch the dialer for some reason (or maybe a call
478 // started via some other means), if an active call is
479 // happening, we want to be in the dialer.
480 startLockedApp("dialer-app")
490 if (Powerd.status === Powerd.Off && reason !== Powerd.Proximity &&
491 !callManager.hasCalls && !tutorial.running) {
492 // We don't want to simply call greeter.showNow() here, because
493 // that will take too long. Qt will delay button event
494 // handling until the greeter is done loading and may think the
495 // user held down the power button the whole time, leading to a
496 // power dialog being shown. Instead, delay showing the
497 // greeter until we've finished handling the event. We could
498 // make the greeter load asynchronously instead, but that
499 // introduces a whole host of timing issues, especially with
500 // its animations. So this is simpler.
501 showGreeterDelayed.start();
506 function showHome() {
507 if (tutorial.running) {
511 greeter.notifyAboutToFocusApp("unity8-dash");
513 var animate = !lightDM.greeter.active && !stages.shown
514 dash.setCurrentScope(0, animate, false)
515 ApplicationManager.requestFocusApplication("unity8-dash")
518 function showDash() {
519 if (greeter.notifyShowingDashFromDrag()) {
523 if (!greeter.locked && ApplicationManager.focusedApplicationId != "unity8-dash") {
524 ApplicationManager.requestFocusApplication("unity8-dash")
538 anchors.fill: parent //because this draws indicator menus
541 available: tutorial.panelEnabled
542 && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
543 && (!greeter || !greeter.hasLockedApp)
544 contentEnabled: tutorial.panelContentEnabled
545 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
547 minimizedPanelHeight: units.gu(3)
548 expandedPanelHeight: units.gu(7)
550 indicatorsModel: Indicators.IndicatorsModel {
551 // tablet and phone both use the same profile
552 profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
553 Component.onCompleted: load();
558 greeterShown: greeter.shown
561 property bool topmostApplicationIsFullscreen:
562 ApplicationManager.focusedApplicationId &&
563 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
565 fullscreenMode: (topmostApplicationIsFullscreen && !lightDM.greeter.active && launcher.progress == 0)
566 || greeter.hasLockedApp
571 objectName: "launcher"
573 readonly property bool dashSwipe: progress > 0
575 anchors.top: parent.top
576 anchors.topMargin: inverted ? 0 : panel.panelHeight
577 anchors.bottom: parent.bottom
579 dragAreaWidth: shell.edgeSize
580 available: tutorial.launcherEnabled
581 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
582 && !greeter.hasLockedApp
583 inverted: shell.usageScenario !== "desktop"
584 shadeBackground: !tutorial.running
586 onShowDashHome: showHome()
588 onDashSwipeChanged: {
590 dash.setCurrentScope(0, false, true)
593 onLauncherApplicationSelected: {
594 if (!tutorial.running) {
595 greeter.notifyAboutToFocusApp(appId);
596 shell.activateApplication(appId)
601 panel.indicators.hide()
610 background: shell.background
612 function unlockWhenDoneWithWizard() {
614 Connectivity.unlockAllModems();
618 Component.onCompleted: unlockWhenDoneWithWizard()
619 onActiveChanged: unlockWhenDoneWithWizard()
623 id: modalNotificationBackground
625 visible: notifications.useModal
638 model: NotificationBackend.Model
640 hasMouse: shell.hasMouse
642 y: topmostIsFullscreen ? 0 : panel.panelHeight
643 height: parent.height - (topmostIsFullscreen ? 0 : panel.panelHeight)
648 when: overlay.width <= units.gu(60)
650 target: notifications
651 anchors.left: parent.left
652 anchors.right: parent.right
657 when: overlay.width > units.gu(60)
659 target: notifications
660 anchors.left: undefined
661 anchors.right: parent.right
663 PropertyChanges { target: notifications; width: units.gu(38) }
671 objectName: "dialogs"
674 usageScenario: shell.usageScenario
676 shutdownFadeOutRectangle.enabled = true;
677 shutdownFadeOutRectangle.visible = true;
678 shutdownFadeOut.start();
683 target: SessionBroadcast
684 onShowHome: showHome()
688 id: shutdownFadeOutRectangle
689 z: screenGrabber.z + 10
695 NumberAnimation on opacity {
700 if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
701 DBusUnitySessionService.shutdown();