on xenial help sign in
If AccountsService.backgroundFile is unset, fallback to the background in gsettings
c1b8bc7Michael Terry
Greeter/Greeter.qml+2
@@ -26,6 +26,8 @@ Showable {
26 enabled: shown
26 enabled: shown
27 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready
27 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready
28
28
29+ property url defaultBackground
30+
29 // 1 when fully shown and 0 when fully hidden
31 // 1 when fully shown and 0 when fully hidden
30 property real showProgress: MathLocal.clamp((width + x) / width, 0, 1)
32 property real showProgress: MathLocal.clamp((width + x) / width, 0, 1)
31
33
Greeter/GreeterContent.qml+4−3
@@ -40,11 +40,12 @@ MouseArea {
40 color: "black"
40 color: "black"
41 }
41 }
42
42
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
44 onBackgroundValueChanged: wallpaper.source = backgroundValue
44 onBackgroundValueChanged: wallpaper.source = backgroundValue
45
45
46 CrossFadeImage {
46 CrossFadeImage {
47 id: wallpaper
47 id: wallpaper
48+ objectName: "wallpaper"
48 anchors.fill: parent
49 anchors.fill: parent
49 fadeInFirst: false
50 fadeInFirst: false
50 }
51 }
@@ -58,8 +59,8 @@ MouseArea {
58 sourceSize.height: 0
59 sourceSize.height: 0
59 sourceSize.width: 0
60 sourceSize.width: 0
60 onStatusChanged: {
61 onStatusChanged: {
61− if (status == Image.Error && source != shell.defaultBackground) {
62+ if (status == Image.Error && source != greeter.defaultBackground) {
62− wallpaper.source = shell.defaultBackground
63+ wallpaper.source = greeter.defaultBackground
63 }
64 }
64 }
65 }
65 }
66 }
Shell.qml+2
@@ -460,6 +460,8 @@ FocusScope {
460 hides: [launcher, panel.indicators, hud]
460 hides: [launcher, panel.indicators, hud]
461 shown: true
461 shown: true
462
462
463+ defaultBackground: shell.background
464+
463 y: panel.panelHeight
465 y: panel.panelHeight
464 width: parent.width
466 width: parent.width
465 height: parent.height - panel.panelHeight
467 height: parent.height - panel.panelHeight
tests/mocks/AccountsService/AccountsService.cpp+9−2
@@ -19,7 +19,8 @@
19#include "AccountsService.h"
19#include "AccountsService.h"
20
20
21AccountsService::AccountsService(QObject* parent)
21AccountsService::AccountsService(QObject* parent)
22− : QObject(parent)
22+ : QObject(parent),
23+ m_backgroundFile(TOP_SRCDIR "/graphics/phone_background.jpg")
23{
24{
24}
25}
25
26
@@ -45,5 +46,11 @@ void AccountsService::setDemoEdges(bool demoEdges)
45
46
46QString AccountsService::getBackgroundFile()
47QString AccountsService::getBackgroundFile()
47{
48{
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();
49}
56}
tests/mocks/AccountsService/AccountsService.h+5
@@ -37,6 +37,7 @@ class AccountsService: public QObject
37 NOTIFY demoEdgesChanged)
37 NOTIFY demoEdgesChanged)
38 Q_PROPERTY (QString backgroundFile
38 Q_PROPERTY (QString backgroundFile
39 READ getBackgroundFile
39 READ getBackgroundFile
40+ WRITE setBackgroundFile // only available in mock
40 NOTIFY backgroundFileChanged)
41 NOTIFY backgroundFileChanged)
41
42
42public:
43public:
@@ -47,11 +48,15 @@ public:
47 bool getDemoEdges();
48 bool getDemoEdges();
48 void setDemoEdges(bool demoEdges);
49 void setDemoEdges(bool demoEdges);
49 QString getBackgroundFile();
50 QString getBackgroundFile();
51+ void setBackgroundFile(const QString &backgroundFile);
50
52
51Q_SIGNALS:
53Q_SIGNALS:
52 void userChanged();
54 void userChanged();
53 void demoEdgesChanged();
55 void demoEdgesChanged();
54 void backgroundFileChanged();
56 void backgroundFileChanged();
57+
58+private:
59+ QString m_backgroundFile;
55};
60};
56
61
57#endif
62#endif
tests/qmltests/Greeter/tst_Phone.qml+19−1
@@ -18,8 +18,8 @@ import QtQuick 2.0
18import QtTest 1.0
18import QtTest 1.0
19import ".."
19import ".."
20import "../../../Greeter"
20import "../../../Greeter"
21+import AccountsService 0.1
21import Ubuntu.Components 0.1
22import Ubuntu.Components 0.1
22−import LightDM 0.1 as LightDM
23import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
24
24
25Item {
25Item {
@@ -32,6 +32,8 @@ Item {
32 height: parent.height
32 height: parent.height
33 x: 0; y: 0
33 x: 0; y: 0
34
34
35+ defaultBackground: "../../../graphics/phone_background.jpg"
36+
35 property int minX: 0
37 property int minX: 0
36
38
37 onXChanged: {
39 onXChanged: {
@@ -102,5 +104,21 @@ Item {
102 // Wait until we're back to 0
104 // Wait until we're back to 0
103 tryCompareFunction(function() { return greeter.x;}, 0);
105 tryCompareFunction(function() { return greeter.x;}, 0);
104 }
106 }
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+ }
105 }
123 }
106}
124}