on xenial help sign in
When AccountsService.backgroundFile is unset/invalid, have the greeter fall back to whatever the shell background is.

Approved by Michael Zanetti, PS Jenkins bot.

commit51792d540509ee0a10e072186e0824acb6904c1a authorMichael Terry <michael.terry@canonical.com> dateMon 16 Sep 2013, 15:19 (13 years ago) parent29181afc1b8bc7
6 files changed+41−6
Greeter/Greeter.qml+2 Greeter/GreeterContent.qml+4−3 Shell.qml+2 tests/mocks/AccountsService/AccountsService.cpp+9−2 tests/mocks/AccountsService/AccountsService.h+5 tests/qmltests/Greeter/tst_Phone.qml+19−1
Greeter/Greeter.qml+2
@@ -26,6 +26,8 @@ Showable {
2626 enabled: shown
2727 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready
2828
29+ property url defaultBackground
30+
2931 // 1 when fully shown and 0 when fully hidden
3032 property real showProgress: MathLocal.clamp((width + x) / width, 0, 1)
3133
Greeter/GreeterContent.qml+4−3
@@ -40,11 +40,12 @@ MouseArea {
4040 color: "black"
4141 }
4242
43− property url backgroundValue: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : shell.defaultBackground
43+ property url backgroundValue: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : greeter.defaultBackground
4444 onBackgroundValueChanged: wallpaper.source = backgroundValue
4545
4646 CrossFadeImage {
4747 id: wallpaper
48+ objectName: "wallpaper"
4849 anchors.fill: parent
4950 fadeInFirst: false
5051 }
@@ -58,8 +59,8 @@ MouseArea {
5859 sourceSize.height: 0
5960 sourceSize.width: 0
6061 onStatusChanged: {
61− if (status == Image.Error && source != shell.defaultBackground) {
62− wallpaper.source = shell.defaultBackground
62+ if (status == Image.Error && source != greeter.defaultBackground) {
63+ wallpaper.source = greeter.defaultBackground
6364 }
6465 }
6566 }
Shell.qml+2
@@ -460,6 +460,8 @@ FocusScope {
460460 hides: [launcher, panel.indicators, hud]
461461 shown: true
462462
463+ defaultBackground: shell.background
464+
463465 y: panel.panelHeight
464466 width: parent.width
465467 height: parent.height - panel.panelHeight
tests/mocks/AccountsService/AccountsService.cpp+9−2
@@ -19,7 +19,8 @@
1919#include "AccountsService.h"
2020
2121AccountsService::AccountsService(QObject* parent)
22− : QObject(parent)
22+ : QObject(parent),
23+ m_backgroundFile(TOP_SRCDIR "/graphics/phone_background.jpg")
2324{
2425}
2526
@@ -45,5 +46,11 @@ void AccountsService::setDemoEdges(bool demoEdges)
4546
4647QString AccountsService::getBackgroundFile()
4748{
48− return TOP_SRCDIR "/graphics/phone_background.jpg";
49+ return m_backgroundFile;
50+}
51+
52+void AccountsService::setBackgroundFile(const QString &backgroundFile)
53+{
54+ m_backgroundFile = backgroundFile;
55+ backgroundFileChanged();
4956}
tests/mocks/AccountsService/AccountsService.h+5
@@ -37,6 +37,7 @@ class AccountsService: public QObject
3737 NOTIFY demoEdgesChanged)
3838 Q_PROPERTY (QString backgroundFile
3939 READ getBackgroundFile
40+ WRITE setBackgroundFile // only available in mock
4041 NOTIFY backgroundFileChanged)
4142
4243public:
@@ -47,11 +48,15 @@ public:
4748 bool getDemoEdges();
4849 void setDemoEdges(bool demoEdges);
4950 QString getBackgroundFile();
51+ void setBackgroundFile(const QString &backgroundFile);
5052
5153Q_SIGNALS:
5254 void userChanged();
5355 void demoEdgesChanged();
5456 void backgroundFileChanged();
57+
58+private:
59+ QString m_backgroundFile;
5560};
5661
5762#endif
tests/qmltests/Greeter/tst_Phone.qml+19−1
@@ -18,8 +18,8 @@ import QtQuick 2.0
1818import QtTest 1.0
1919import ".."
2020import "../../../Greeter"
21+import AccountsService 0.1
2122import Ubuntu.Components 0.1
22−import LightDM 0.1 as LightDM
2323import Unity.Test 0.1 as UT
2424
2525Item {
@@ -32,6 +32,8 @@ Item {
3232 height: parent.height
3333 x: 0; y: 0
3434
35+ defaultBackground: "../../../graphics/phone_background.jpg"
36+
3537 property int minX: 0
3638
3739 onXChanged: {
@@ -102,5 +104,21 @@ Item {
102104 // Wait until we're back to 0
103105 tryCompareFunction(function() { return greeter.x;}, 0);
104106 }
107+
108+ function test_wallpaper_data() {
109+ return [
110+ {tag: "set", accounts: "../tests/data/unity/backgrounds/blue.png", expected: "blue.png"},
111+ {tag: "unset", accounts: "", expected: "background.jpg"},
112+ {tag: "invalid", accounts: "invalid", expected: "background.jpg"},
113+ ]
114+ }
115+
116+ function test_wallpaper(data) {
117+ var loader = findChild(greeter, "greeterContentLoader")
118+ var wallpaper = findChild(loader.item, "wallpaper")
119+ AccountsService.backgroundFile = data.accounts
120+ tryCompareFunction(function() { return wallpaper.source.toString().indexOf(data.expected) !== -1; }, true)
121+ tryCompare(wallpaper, "status", Image.Ready)
122+ }
105123 }
106124}