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
=== added file 'debian/ubuntu-system-settings.postrm'
--- debian/ubuntu-system-settings.postrm 1970-01-01 00:00:00 +0000
+++ debian/ubuntu-system-settings.postrm 2014-06-06 09:36:48 +0000
@@ -0,0 +1,9 @@
1#!/bin/sh
2set -e
3
4if [ "$1" = "purge" ] ; then
5 rm -rf /var/lib/lightdm-data/*/ubuntu-system-settings/
6fi
7
8#DEBHELPER#
9exit 0
010
=== modified file 'plugins/background/MainPage.qml'
--- plugins/background/MainPage.qml 2014-02-18 14:18:27 +0000
+++ plugins/background/MainPage.qml 2014-06-06 09:36:48 +0000
@@ -248,30 +248,28 @@
248 }248 }
249249
250 function setUpImages() {250 function setUpImages() {
251 var mostRecent = (systemSettingsSettings.backgroundSetLast === "home") ?
252 testHomeImage : testWelcomeImage;
253 var leastRecent = (mostRecent === testHomeImage) ?
254 testWelcomeImage : testHomeImage;
255
256 if (systemSettingsSettings.backgroundDuplicate) { //same
257 /* save value of least recently changed to restore later */
258 systemSettingsSettings.backgroundPreviouslySetValue =
259 leastRecent.source;
260 /* copy most recently changed to least recently changed */
261 leastRecent.update(mostRecent.source);
262 } else { // different
263 /* restore least recently changed to previous value */
264 leastRecent.update(
265 systemSettingsSettings.backgroundPreviouslySetValue);
266 }
267 }251 }
268252
269 GSettings {253 GSettings {
270 id: systemSettingsSettings254 id: systemSettingsSettings
271 schema.id: "com.ubuntu.touch.system-settings"255 schema.id: "com.ubuntu.touch.system-settings"
272 onChanged: {256 onChanged: {
273 if (key == "backgroundDuplicate")257 if (key == "backgroundDuplicate") {
274 setUpImages();258 var mostRecent = (backgroundSetLast === "home")
259 ? testHomeImage : testWelcomeImage;
260 var leastRecent = (mostRecent === testHomeImage) ?
261 testWelcomeImage : testHomeImage;
262
263 if (backgroundDuplicate) { //same
264 /* save value of least recently changed to restore later */
265 backgroundPreviouslySetValue = leastRecent.source;
266 /* copy most recently changed to least recently changed */
267 leastRecent.update(mostRecent.source);
268 } else { // different
269 /* restore least recently changed to previous value */
270 leastRecent.update(backgroundPreviouslySetValue);
271 }
272 }
275 }273 }
276 Component.onCompleted: {274 Component.onCompleted: {
277 if (systemSettingsSettings.backgroundDuplicate)275 if (systemSettingsSettings.backgroundDuplicate)
278276
=== modified file 'plugins/background/background.cpp'
--- plugins/background/background.cpp 2014-02-18 14:18:27 +0000
+++ plugins/background/background.cpp 2014-06-06 09:36:48 +0000
@@ -89,10 +89,10 @@
89void Background::updateCustomBackgrounds()89void Background::updateCustomBackgrounds()
90{90{
91 m_customBackgrounds.clear();91 m_customBackgrounds.clear();
92 QString customPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"/Pictures";92 QFileInfoList tmpList;
93 QDir dir(customPath);93 tmpList << getCustomBackgroundFolder().entryInfoList(QDir::Files | QDir::NoSymLinks);
94 dir.setFilter(QDir::Files | QDir::NoSymLinks);94 if (getCustomBackgroundFolder() != getContentHubFolder())
95 QFileInfoList tmpList = dir.entryInfoList();95 tmpList << getContentHubFolder().entryInfoList(QDir::Files | QDir::NoSymLinks);
96 if (!tmpList.isEmpty())96 if (!tmpList.isEmpty())
97 {97 {
98 foreach (QFileInfo f, tmpList)98 foreach (QFileInfo f, tmpList)
@@ -101,6 +101,54 @@
101 Q_EMIT customBackgroundsChanged();101 Q_EMIT customBackgroundsChanged();
102}102}
103103
104QUrl Background::prepareBackgroundFile(const QUrl &url, bool shareWithGreeter)
105{
106 QUrl prepared = url;
107
108 if (getCustomBackgroundFolder() != getContentHubFolder() &&
109 url.path().startsWith(getContentHubFolder().path()))
110 {
111 QDir backgroundFolder = getCustomBackgroundFolder();
112 QUrl newPath = QUrl::fromLocalFile(backgroundFolder.path() + "/" + url.fileName());
113
114 if (QFile(newPath.path()).exists())
115 {
116 // The file already exists in the shared greeter data folder...
117 // Likely we just pulled the same file from ContentHub again.
118 // We don't want to show both versions in the picker grid, so just
119 // promote it to greeter location so we still just have one copy.
120 if (QFile(newPath.path()).remove())
121 shareWithGreeter = true;
122 }
123
124 // Move file from local ContentHub dump to shared greeter data folder
125 if (shareWithGreeter &&
126 QDir::root().mkpath(backgroundFolder.path()) &&
127 QFile::rename(url.path(), newPath.path()))
128 {
129 updateCustomBackgrounds();
130 prepared = newPath;
131 }
132 }
133
134 return prepared;
135}
136
137QDir Background::getCustomBackgroundFolder()
138{
139 // We want a location we can share with the greeter
140 QString dataDir(qgetenv("XDG_GREETER_DATA_DIR"));
141 if (dataDir.isEmpty())
142 return getContentHubFolder();
143 else
144 return dataDir + "/ubuntu-system-settings/Pictures";
145}
146
147QDir Background::getContentHubFolder()
148{
149 return QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/Pictures";
150}
151
104QStringList Background::ubuntuArt()152QStringList Background::ubuntuArt()
105{153{
106 return m_ubuntuArt;154 return m_ubuntuArt;
@@ -132,7 +180,7 @@
132 if (file.isEmpty() || file.isNull())180 if (file.isEmpty() || file.isNull())
133 return;181 return;
134182
135 if (!file.contains(QStandardPaths::writableLocation(QStandardPaths::DataLocation)))183 if (!file.contains(getCustomBackgroundFolder().path()) && !file.contains(getContentHubFolder().path()))
136 return;184 return;
137185
138 QUrl fileUri(file);186 QUrl fileUri(file);
139187
=== modified file 'plugins/background/background.h'
--- plugins/background/background.h 2014-02-18 14:18:27 +0000
+++ plugins/background/background.h 2014-06-06 09:36:48 +0000
@@ -24,6 +24,7 @@
24#include "accountsservice.h"24#include "accountsservice.h"
2525
26#include <QDBusInterface>26#include <QDBusInterface>
27#include <QDir>
27#include <QObject>28#include <QObject>
28#include <QProcess>29#include <QProcess>
29#include <QUrl>30#include <QUrl>
@@ -49,6 +50,7 @@
49 ~Background();50 ~Background();
50 QString backgroundFile();51 QString backgroundFile();
51 void setBackgroundFile(QUrl backgroundFile);52 void setBackgroundFile(QUrl backgroundFile);
53 Q_INVOKABLE QUrl prepareBackgroundFile(const QUrl &url, bool shareWithGreeter);
52 Q_INVOKABLE bool fileExists(const QString &file);54 Q_INVOKABLE bool fileExists(const QString &file);
53 Q_INVOKABLE void rmFile(const QString &file);55 Q_INVOKABLE void rmFile(const QString &file);
54 QStringList customBackgrounds();56 QStringList customBackgrounds();
@@ -70,6 +72,8 @@
70 void updateUbuntuArt();72 void updateUbuntuArt();
71 QString m_backgroundFile;73 QString m_backgroundFile;
72 QString getBackgroundFile();74 QString getBackgroundFile();
75 QDir getCustomBackgroundFolder();
76 QDir getContentHubFolder();
73};77};
7478
75#endif // BACKGROUND_H79#endif // BACKGROUND_H
7680
=== modified file 'plugins/background/utilities.js'
--- plugins/background/utilities.js 2013-12-06 19:20:15 +0000
+++ plugins/background/utilities.js 2014-06-06 09:36:48 +0000
@@ -34,14 +34,16 @@
34}34}
3535
36function updateWelcome(uri) {36function updateWelcome(uri) {
37 backgroundPanel.backgroundFile = uri;37 backgroundPanel.backgroundFile = backgroundPanel.prepareBackgroundFile(uri, true);
38}38}
3939
40function updateHome(uri) {40function updateHome(uri) {
41 background.pictureUri = uri;41 background.pictureUri = backgroundPanel.prepareBackgroundFile(uri, false);
42}42}
4343
44function updateBoth(uri) {44function updateBoth(uri) {
45 // multiple prepares on a uri is fine
46 uri = backgroundPanel.prepareBackgroundFile(uri, true);
45 updateWelcome(uri);47 updateWelcome(uri);
46 updateHome(uri);48 updateHome(uri);
47}49}

Subscribers

People subscribed via source and target branches