Merge lp:~donadigo/switchboard-plug-pantheon-shell/fix-wallpaper-permissions into lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 404
Merged at revision: 402
Proposed branch: lp:~donadigo/switchboard-plug-pantheon-shell/fix-wallpaper-permissions
Merge into: lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk
Diff against target: 246 lines (+127/-41)
2 files modified
set-wallpaper-contract/set-wallpaper.vala (+53/-14)
src/Wallpaper.vala (+74/-27)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-pantheon-shell/fix-wallpaper-permissions
Reviewer Review Type Date Requested Status
The Lemon Man (community) code Approve
Danielle Foré ux Approve
elementary Pantheon team code Pending
Review via email: mp+276153@code.launchpad.net

Commit message

* Sets right permissions for wallpapers to have them visible in the greeter (finally)
* Various code optimizations

Description of the change

The branch fixes some issues and makes optimizations to current wallpaper
* Sets right permissions for wallpapers to have them visible in the greeter (finally)
* Various code optimizations

To post a comment you must log in.
Revision history for this message
The Lemon Man (lemonboy) wrote :

Hmm, I'd be against chmod'ing the user files.

Revision history for this message
Akshay Shekher (voldyman) wrote :

Why don't you ask the user if they want switchboard to fix the file permissions if they are not 0644?

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

voldyman: Why we would 'ask' to fix the 'file permissions' to just change the wallpaper? No one is doing that and it seems reduntant to ask user for these things.

Revision history for this message
Danielle Foré (danrabbit) wrote :

I don't think using a symlink is a good idea. Now you're giving me something to remember: not to delete that wallpaper that's in a random location on my file system. Or worse, it could be on an external drive and now I can't unmount that drive without losing my wallpaper. Copying ensures that the wallpaper won't be removed accidentally.

I do think we should change the permissions without asking. It's a wallpaper, I think it'll be okay. Users expect this feature to work and I don't think we should have to bother less experienced users knowing what permissions even are and why they're needed for this feature.

review: Needs Fixing
Revision history for this message
Danielle Foré (danrabbit) wrote :

I can confirm however that this fixes the issue :D

394. By Adam Bieńkowski

Copy the wallpaper to directory

395. By Adam Bieńkowski

Fix not changing wallpaper in greeter

396. By Adam Bieńkowski

Add missing permission line

397. By Adam Bieńkowski

Fixed: when choosing external source in the plug it does not change it in the greeter

Revision history for this message
Danielle Foré (danrabbit) wrote :

Hey right on. I can confirm that it works both with the contract and with the plug. Nice work :D

review: Approve (ux)
Revision history for this message
Danielle Foré (danrabbit) wrote :

Hrm, I found an issue. Set a non-default wall in the plug. Close the plug. Open it again. Gala background plugin crashes.

review: Needs Fixing
Revision history for this message
kay van der Zander (kay20) wrote :

If the plug creates a copy of the wallpaper the user wants. Why not only change the copy his permissions. The original wallpaper will be untouched (besides copying).

currently the original wallpaper is changed and the copy isn't
and why change all wallpapers there premissions (diff line 68)

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

kay: line 68 is there to e.g: if you choose wallpaper directly from the plug, permissions won't be changed, and it will not be visible in the plug.

398. By Adam Bieńkowski

Simplify wallpaper path's to one local path for both dbus and gsettings; wallpaper folder now in .config

399. By Adam Bieńkowski

Fix some issues

400. By Adam Bieńkowski

Copy requested wallpaper to /var/lib/lightdm-data/user/wallpaper

401. By Adam Bieńkowski

Move greeter_file variable

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Updated.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Okay alright, it seems to be working as expected. I can confirm that:
* walls are copied into .local/share/backgrounds
* The current wall is copied to /var/lib/lightdm-data/user/wallpaper
* LightDM is able to read the wall
* This works both with the contract and with Drag N Drop
* I can't reproduce any of the other issues/crashes we had previously experienced

Good work :)

review: Approve (ux)
Revision history for this message
Akshay Shekher (voldyman) wrote :

please use const's and not hardcoded strings so that they can easily be changed later, we don't want to grep throught the code to find all the mentions of /usr/share/backgrounds, etc.

402. By Adam Bieńkowski

Replace /usr/share/backgrounds with constant variable

403. By Adam Bieńkowski

Access specifier

Revision history for this message
The Lemon Man (lemonboy) wrote :

Some nitpicks have been outlined in the inline comments.

review: Needs Fixing (code)
404. By Adam Bieńkowski

Single build_filename call; use SYSTEM_BACKGROUNDS_PATH variable everywhere

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Updated.

Revision history for this message
The Lemon Man (lemonboy) wrote :

Code-wise it's ok. There's some code that could be factored out but let's get the ball rolling.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'set-wallpaper-contract/set-wallpaper.vala'
--- set-wallpaper-contract/set-wallpaper.vala 2015-09-21 16:34:26 +0000
+++ set-wallpaper-contract/set-wallpaper.vala 2015-11-15 21:44:26 +0000
@@ -19,6 +19,8 @@
19 </transition>19 </transition>
20 """;20 """;
2121
22 const string SYSTEM_BACKGROUNDS_PATH = "/usr/share/backgrounds";
23
22 private int delay_value = 60;24 private int delay_value = 60;
2325
24 [DBus (name = "org.freedesktop.Accounts.User")]26 [DBus (name = "org.freedesktop.Accounts.User")]
@@ -100,16 +102,43 @@
100 return folder;102 return folder;
101 }103 }
102104
103 private bool copy_to_local_folder (File source) {105 private File? copy_for_library (File source) {
104 try {106 File? dest = null;
105 var dest = File.new_for_path (get_local_bg_location () + source.get_basename ());107
106 source.copy (dest, FileCopyFlags.OVERWRITE|FileCopyFlags.NOFOLLOW_SYMLINKS);108 try {
107 } catch (Error e) {109 dest = File.new_for_path (get_local_bg_location () + source.get_basename ());
108 warning ("%s\n", e.message);110 source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
109 return false;111 } catch (Error e) {
112 warning ("%s\n", e.message);
113 }
114
115 return dest;
116 }
117
118 private File? copy_for_greeter (File source) {
119 File? dest = null;
120 try {
121 string greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper");
122
123 var folder = File.new_for_path (greeter_data_dir);
124 if (folder.query_exists ()) {
125 var enumerator = folder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
126 FileInfo? info = null;
127 while ((info = enumerator.next_file ()) != null) {
128 enumerator.get_child (info).@delete ();
129 }
130 } else {
131 folder.make_directory_with_parents ();
132 }
133
134 dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ()));
135 source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
136 } catch (Error e) {
137 warning ("%s\n", e.message);
138 return null;
110 }139 }
111140
112 return true;141 return dest;
113 }142 }
114143
115 public static int main (string[] args) {144 public static int main (string[] args) {
@@ -129,17 +158,27 @@
129 var files = new List<File> ();158 var files = new List<File> ();
130 for (var i = 1; i < args.length; i++) {159 for (var i = 1; i < args.length; i++) {
131 var file = File.new_for_path (args[i]);160 var file = File.new_for_path (args[i]);
132 var localfile = File.new_for_path (get_local_bg_location () + file.get_basename ());
133161
134 if (file != null) {162 if (file != null) {
135 if (copy_to_local_folder (file)) {163
136 files.append (localfile);164 string path = file.get_path ();
137 } else {165 File append_file = file;
138 files.append (file);166 if (!path.has_prefix (SYSTEM_BACKGROUNDS_PATH)) {
167 var local_file = copy_for_library (file);
168 if (local_file != null) {
169 append_file = local_file;
170 }
171 }
172
173 files.append (append_file);
174
175 var greeter_file = copy_for_greeter (file);
176 if (greeter_file != null) {
177 path = greeter_file.get_path ();
139 }178 }
140179
141 try {180 try {
142 accounts_service.set_background_file (file.get_path ());181 accounts_service.set_background_file (path);
143 } catch (Error e) {182 } catch (Error e) {
144 warning ("%s\n", e.message);183 warning ("%s\n", e.message);
145 } 184 }
146185
=== modified file 'src/Wallpaper.vala'
--- src/Wallpaper.vala 2015-10-29 20:50:16 +0000
+++ src/Wallpaper.vala 2015-11-15 21:44:26 +0000
@@ -96,7 +96,9 @@
9696
97 //name of the default-wallpaper-link that we can prevent loading it again97 //name of the default-wallpaper-link that we can prevent loading it again
98 //(assumes that the defaultwallpaper is also in the system wallpaper directory)98 //(assumes that the defaultwallpaper is also in the system wallpaper directory)
99 static string default_link = "file:///usr/share/backgrounds/elementaryos-default";99 static string default_link = "file://%s/elementaryos-default".printf (SYSTEM_BACKGROUNDS_PATH);
100
101 const string SYSTEM_BACKGROUNDS_PATH = "/usr/share/backgrounds";
100102
101 public Wallpaper (Switchboard.Plug _plug) {103 public Wallpaper (Switchboard.Plug _plug) {
102 plug = _plug;104 plug = _plug;
@@ -201,8 +203,23 @@
201 */203 */
202 try {204 try {
203 var file = File.new_for_uri (current_wallpaper_path);205 var file = File.new_for_uri (current_wallpaper_path);
204206 string uri = file.get_uri ();
205 accountsservice.set_background_file (file.get_path ());207 string path = file.get_path ();
208
209 if (!path.has_prefix (SYSTEM_BACKGROUNDS_PATH)) {
210 var localfile = copy_for_library (file);
211 if (localfile != null) {
212 uri = localfile.get_uri ();
213 }
214 }
215
216 var greeter_file = copy_for_greeter (file);
217 if (greeter_file != null) {
218 path = greeter_file.get_path ();
219 }
220
221 settings.set_string ("picture-uri", uri);
222 accountsservice.set_background_file (path);
206 } catch (Error e) {223 } catch (Error e) {
207 warning (e.message);224 warning (e.message);
208 }225 }
@@ -213,7 +230,6 @@
213230
214 if (!(children is SolidColorContainer)) {231 if (!(children is SolidColorContainer)) {
215 current_wallpaper_path = children.uri;232 current_wallpaper_path = children.uri;
216 settings.set_string ("picture-uri", current_wallpaper_path);
217 update_accountsservice ();233 update_accountsservice ();
218234
219 if (active_wallpaper == solid_color) {235 if (active_wallpaper == solid_color) {
@@ -296,8 +312,8 @@
296 } else if (folder_combo.get_active () == 1) {312 } else if (folder_combo.get_active () == 1) {
297 clean_wallpapers ();313 clean_wallpapers ();
298314
299 var system_uri = "file:///usr/share/backgrounds";315 var system_uri = "file://" + SYSTEM_BACKGROUNDS_PATH;
300 var user_uri = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds").get_uri ();316 var user_uri = GLib.File.new_for_path (get_local_bg_location ()).get_uri ();
301317
302 load_wallpapers (system_uri, cancellable);318 load_wallpapers (system_uri, cancellable);
303 load_wallpapers (user_uri, cancellable);319 load_wallpapers (user_uri, cancellable);
@@ -447,6 +463,52 @@
447 Cache.clear ();463 Cache.clear ();
448 }464 }
449465
466 private string get_local_bg_location () {
467 return Path.build_filename (Environment.get_user_data_dir (), "backgrounds") + "/";
468 }
469
470 private File? copy_for_library (File source) {
471 File? dest = null;
472
473 try {
474 dest = File.new_for_path (get_local_bg_location () + source.get_basename ());
475 source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
476 } catch (Error e) {
477 warning ("%s\n", e.message);
478 }
479
480 return dest;
481 }
482
483 private File? copy_for_greeter (File source) {
484 File? dest = null;
485 try {
486 string greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper");
487 if (greeter_data_dir == "") {
488 greeter_data_dir = Path.build_filename ("/var/lib/lightdm-data/", Environment.get_user_name (), "wallpaper");
489 }
490
491 var folder = File.new_for_path (greeter_data_dir);
492 if (folder.query_exists ()) {
493 var enumerator = folder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
494 FileInfo? info = null;
495 while ((info = enumerator.next_file ()) != null) {
496 enumerator.get_child (info).@delete ();
497 }
498 } else {
499 folder.make_directory_with_parents ();
500 }
501
502 dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ()));
503 source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
504 } catch (Error e) {
505 warning ("%s\n", e.message);
506 return null;
507 }
508
509 return dest;
510 }
511
450 void on_drag_data_received (Widget widget, Gdk.DragContext ctx, int x, int y, SelectionData sel, uint information, uint timestamp) {512 void on_drag_data_received (Widget widget, Gdk.DragContext ctx, int x, int y, SelectionData sel, uint information, uint timestamp) {
451 if (sel.get_length () > 0) {513 if (sel.get_length () > 0) {
452 File file = File.new_for_uri (sel.get_uris ()[0]);514 File file = File.new_for_uri (sel.get_uris ()[0]);
@@ -457,29 +519,14 @@
457 return;519 return;
458 }520 }
459521
460522 string local_uri = file.get_uri ();
461 string display_name = Filename.display_basename (file.get_path ());523 var dest = copy_for_library (file);
462524 if (dest != null) {
463 var dest_folder = File.new_for_path (Environment.get_user_data_dir () + "/backgrounds");525 local_uri = dest.get_uri ();
464 var dest = File.new_for_path (Environment.get_user_data_dir () + "/backgrounds/" + display_name);526 }
465 if (!dest_folder.query_exists ()) {
466 try {
467 dest_folder.make_directory ();
468 } catch (Error e) {
469 warning ("Creating local wallpaper directory failed: %s", e.message);
470 }
471 }
472
473 try {
474 file.copy (dest, 0);
475 } catch (Error e) {
476 warning ("Copying wallpaper to local directory failed: %s", e.message);
477 }
478
479 string uri = dest.get_uri ();
480527
481 // Add the wallpaper name and thumbnail to the IconView528 // Add the wallpaper name and thumbnail to the IconView
482 var wallpaper = new WallpaperContainer (uri);529 var wallpaper = new WallpaperContainer (local_uri);
483 wallpaper_view.add (wallpaper);530 wallpaper_view.add (wallpaper);
484 wallpaper.show_all ();531 wallpaper.show_all ();
485532

Subscribers

People subscribed via source and target branches

to all changes: