Merge lp:~laney/ubuntu-system-settings/background-toggle into lp:ubuntu-system-settings

Proposed by Iain Lane
Status: Superseded
Proposed branch: lp:~laney/ubuntu-system-settings/background-toggle
Merge into: lp:ubuntu-system-settings
Diff against target: 199 lines (+86/-25)
5 files modified
debian/ubuntu-system-settings.postrm (+9/-0)
plugins/background/MainPage.qml (+16/-18)
plugins/background/background.cpp (+53/-5)
plugins/background/background.h (+4/-0)
plugins/background/utilities.js (+4/-2)
To merge this branch: bzr merge lp:~laney/ubuntu-system-settings/background-toggle
Reviewer Review Type Date Requested Status
Ubuntu Touch System Settings Pending
Review via email: mp+222297@code.launchpad.net

This proposal has been superseded by a proposal from 2014-06-06.

Commit message

Inline the setUpImages() function as it's only called from one place.

Description of the change

Inline setUpImages(), otherwise the function call doesn't do anything.

No, I don't know why this helps. QML :(

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'debian/ubuntu-system-settings.postrm'
2--- debian/ubuntu-system-settings.postrm 1970-01-01 00:00:00 +0000
3+++ debian/ubuntu-system-settings.postrm 2014-06-06 09:36:48 +0000
4@@ -0,0 +1,9 @@
5+#!/bin/sh
6+set -e
7+
8+if [ "$1" = "purge" ] ; then
9+ rm -rf /var/lib/lightdm-data/*/ubuntu-system-settings/
10+fi
11+
12+#DEBHELPER#
13+exit 0
14
15=== modified file 'plugins/background/MainPage.qml'
16--- plugins/background/MainPage.qml 2014-02-18 14:18:27 +0000
17+++ plugins/background/MainPage.qml 2014-06-06 09:36:48 +0000
18@@ -248,30 +248,28 @@
19 }
20
21 function setUpImages() {
22- var mostRecent = (systemSettingsSettings.backgroundSetLast === "home") ?
23- testHomeImage : testWelcomeImage;
24- var leastRecent = (mostRecent === testHomeImage) ?
25- testWelcomeImage : testHomeImage;
26-
27- if (systemSettingsSettings.backgroundDuplicate) { //same
28- /* save value of least recently changed to restore later */
29- systemSettingsSettings.backgroundPreviouslySetValue =
30- leastRecent.source;
31- /* copy most recently changed to least recently changed */
32- leastRecent.update(mostRecent.source);
33- } else { // different
34- /* restore least recently changed to previous value */
35- leastRecent.update(
36- systemSettingsSettings.backgroundPreviouslySetValue);
37- }
38 }
39
40 GSettings {
41 id: systemSettingsSettings
42 schema.id: "com.ubuntu.touch.system-settings"
43 onChanged: {
44- if (key == "backgroundDuplicate")
45- setUpImages();
46+ if (key == "backgroundDuplicate") {
47+ var mostRecent = (backgroundSetLast === "home")
48+ ? testHomeImage : testWelcomeImage;
49+ var leastRecent = (mostRecent === testHomeImage) ?
50+ testWelcomeImage : testHomeImage;
51+
52+ if (backgroundDuplicate) { //same
53+ /* save value of least recently changed to restore later */
54+ backgroundPreviouslySetValue = leastRecent.source;
55+ /* copy most recently changed to least recently changed */
56+ leastRecent.update(mostRecent.source);
57+ } else { // different
58+ /* restore least recently changed to previous value */
59+ leastRecent.update(backgroundPreviouslySetValue);
60+ }
61+ }
62 }
63 Component.onCompleted: {
64 if (systemSettingsSettings.backgroundDuplicate)
65
66=== modified file 'plugins/background/background.cpp'
67--- plugins/background/background.cpp 2014-02-18 14:18:27 +0000
68+++ plugins/background/background.cpp 2014-06-06 09:36:48 +0000
69@@ -89,10 +89,10 @@
70 void Background::updateCustomBackgrounds()
71 {
72 m_customBackgrounds.clear();
73- QString customPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"/Pictures";
74- QDir dir(customPath);
75- dir.setFilter(QDir::Files | QDir::NoSymLinks);
76- QFileInfoList tmpList = dir.entryInfoList();
77+ QFileInfoList tmpList;
78+ tmpList << getCustomBackgroundFolder().entryInfoList(QDir::Files | QDir::NoSymLinks);
79+ if (getCustomBackgroundFolder() != getContentHubFolder())
80+ tmpList << getContentHubFolder().entryInfoList(QDir::Files | QDir::NoSymLinks);
81 if (!tmpList.isEmpty())
82 {
83 foreach (QFileInfo f, tmpList)
84@@ -101,6 +101,54 @@
85 Q_EMIT customBackgroundsChanged();
86 }
87
88+QUrl Background::prepareBackgroundFile(const QUrl &url, bool shareWithGreeter)
89+{
90+ QUrl prepared = url;
91+
92+ if (getCustomBackgroundFolder() != getContentHubFolder() &&
93+ url.path().startsWith(getContentHubFolder().path()))
94+ {
95+ QDir backgroundFolder = getCustomBackgroundFolder();
96+ QUrl newPath = QUrl::fromLocalFile(backgroundFolder.path() + "/" + url.fileName());
97+
98+ if (QFile(newPath.path()).exists())
99+ {
100+ // The file already exists in the shared greeter data folder...
101+ // Likely we just pulled the same file from ContentHub again.
102+ // We don't want to show both versions in the picker grid, so just
103+ // promote it to greeter location so we still just have one copy.
104+ if (QFile(newPath.path()).remove())
105+ shareWithGreeter = true;
106+ }
107+
108+ // Move file from local ContentHub dump to shared greeter data folder
109+ if (shareWithGreeter &&
110+ QDir::root().mkpath(backgroundFolder.path()) &&
111+ QFile::rename(url.path(), newPath.path()))
112+ {
113+ updateCustomBackgrounds();
114+ prepared = newPath;
115+ }
116+ }
117+
118+ return prepared;
119+}
120+
121+QDir Background::getCustomBackgroundFolder()
122+{
123+ // We want a location we can share with the greeter
124+ QString dataDir(qgetenv("XDG_GREETER_DATA_DIR"));
125+ if (dataDir.isEmpty())
126+ return getContentHubFolder();
127+ else
128+ return dataDir + "/ubuntu-system-settings/Pictures";
129+}
130+
131+QDir Background::getContentHubFolder()
132+{
133+ return QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/Pictures";
134+}
135+
136 QStringList Background::ubuntuArt()
137 {
138 return m_ubuntuArt;
139@@ -132,7 +180,7 @@
140 if (file.isEmpty() || file.isNull())
141 return;
142
143- if (!file.contains(QStandardPaths::writableLocation(QStandardPaths::DataLocation)))
144+ if (!file.contains(getCustomBackgroundFolder().path()) && !file.contains(getContentHubFolder().path()))
145 return;
146
147 QUrl fileUri(file);
148
149=== modified file 'plugins/background/background.h'
150--- plugins/background/background.h 2014-02-18 14:18:27 +0000
151+++ plugins/background/background.h 2014-06-06 09:36:48 +0000
152@@ -24,6 +24,7 @@
153 #include "accountsservice.h"
154
155 #include <QDBusInterface>
156+#include <QDir>
157 #include <QObject>
158 #include <QProcess>
159 #include <QUrl>
160@@ -49,6 +50,7 @@
161 ~Background();
162 QString backgroundFile();
163 void setBackgroundFile(QUrl backgroundFile);
164+ Q_INVOKABLE QUrl prepareBackgroundFile(const QUrl &url, bool shareWithGreeter);
165 Q_INVOKABLE bool fileExists(const QString &file);
166 Q_INVOKABLE void rmFile(const QString &file);
167 QStringList customBackgrounds();
168@@ -70,6 +72,8 @@
169 void updateUbuntuArt();
170 QString m_backgroundFile;
171 QString getBackgroundFile();
172+ QDir getCustomBackgroundFolder();
173+ QDir getContentHubFolder();
174 };
175
176 #endif // BACKGROUND_H
177
178=== modified file 'plugins/background/utilities.js'
179--- plugins/background/utilities.js 2013-12-06 19:20:15 +0000
180+++ plugins/background/utilities.js 2014-06-06 09:36:48 +0000
181@@ -34,14 +34,16 @@
182 }
183
184 function updateWelcome(uri) {
185- backgroundPanel.backgroundFile = uri;
186+ backgroundPanel.backgroundFile = backgroundPanel.prepareBackgroundFile(uri, true);
187 }
188
189 function updateHome(uri) {
190- background.pictureUri = uri;
191+ background.pictureUri = backgroundPanel.prepareBackgroundFile(uri, false);
192 }
193
194 function updateBoth(uri) {
195+ // multiple prepares on a uri is fine
196+ uri = backgroundPanel.prepareBackgroundFile(uri, true);
197 updateWelcome(uri);
198 updateHome(uri);
199 }

Subscribers

People subscribed via source and target branches