Merge lp:~elementary-dev-community/switchboard-plug-pantheon-shell/fix-1182413 into lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk

Proposed by Cameron Norman
Status: Merged
Merged at revision: 219
Proposed branch: lp:~elementary-dev-community/switchboard-plug-pantheon-shell/fix-1182413
Merge into: lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk
Diff against target: 124 lines (+38/-18)
1 file modified
src/Wallpaper.vala (+38/-18)
To merge this branch: bzr merge lp:~elementary-dev-community/switchboard-plug-pantheon-shell/fix-1182413
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+227667@code.launchpad.net

Description of the change

Based on Richard Stromer's branch, just rebased on current trunk.

One notable change is that it gets rid of the WALLPAPER_DIR variable completely. The directory to load is just given to the load_wallpapers function directly.

Otherwise, it is the same as Stromer's work.

To post a comment you must log in.
218. By Launchpad Translations on behalf of elementary-apps

Launchpad automatic translations update.

219. By Cameron Norman

Remerged and corrected conflicts.

220. By Corentin Noël

Added cancellable as searching recursively can take time.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Wallpaper.vala'
--- src/Wallpaper.vala 2013-11-24 00:08:31 +0000
+++ src/Wallpaper.vala 2014-07-31 11:21:57 +0000
@@ -62,7 +62,6 @@
62}62}
6363
64class Wallpaper : EventBox {64class Wallpaper : EventBox {
65 string WALLPAPER_DIR = "/usr/share/backgrounds";
6665
67 GLib.Settings settings;66 GLib.Settings settings;
6867
@@ -74,6 +73,7 @@
74 ComboBoxText folder_combo;73 ComboBoxText folder_combo;
75 ColorButton color;74 ColorButton color;
76 string current_wallpaper_path;75 string current_wallpaper_path;
76 Cancellable last_cancellable;
7777
78 Switchboard.Plug plug;78 Switchboard.Plug plug;
7979
@@ -214,19 +214,23 @@
214 }214 }
215215
216 void update_wallpaper_folder () {216 void update_wallpaper_folder () {
217 if (last_cancellable != null)
218 last_cancellable.cancel ();
219
220 var cancellable = new Cancellable ();
221 last_cancellable = cancellable;
217 if (folder_combo.get_active () == 0) {222 if (folder_combo.get_active () == 0) {
218 clean_wallpapers ();223 clean_wallpapers ();
219 var picture_file = GLib.File.new_for_path (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES));224 var picture_dir = GLib.File.new_for_path (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES));
220 WALLPAPER_DIR = picture_file.get_uri ();225 load_wallpapers (picture_dir.get_uri (), cancellable);
221 load_wallpapers.begin ();
222 } else if (folder_combo.get_active () == 1) {226 } else if (folder_combo.get_active () == 1) {
223 clean_wallpapers ();227 clean_wallpapers ();
224 WALLPAPER_DIR = "file:///usr/share/backgrounds";228
225 load_wallpapers.begin (() => {229 var system_uri = "file:///usr/share/backgrounds";
226 var backgrounds_file = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds");230 var user_uri = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds").get_uri ();
227 WALLPAPER_DIR = backgrounds_file.get_uri ();231
228 load_wallpapers.begin ();232 load_wallpapers (system_uri, cancellable);
229 });233 load_wallpapers (user_uri, cancellable);
230 } else if (folder_combo.get_active () == 2) {234 } else if (folder_combo.get_active () == 2) {
231 var dialog = new Gtk.FileChooserDialog (_("Select a folder"), null, FileChooserAction.SELECT_FOLDER);235 var dialog = new Gtk.FileChooserDialog (_("Select a folder"), null, FileChooserAction.SELECT_FOLDER);
232 dialog.add_button (_("Cancel"), ResponseType.CANCEL);236 dialog.add_button (_("Cancel"), ResponseType.CANCEL);
@@ -235,8 +239,7 @@
235239
236 if (dialog.run () == ResponseType.ACCEPT) {240 if (dialog.run () == ResponseType.ACCEPT) {
237 clean_wallpapers ();241 clean_wallpapers ();
238 WALLPAPER_DIR = dialog.get_file ().get_uri ();242 load_wallpapers (dialog.get_file ().get_uri (), cancellable);
239 load_wallpapers.begin ();
240 dialog.destroy ();243 dialog.destroy ();
241 } else {244 } else {
242 dialog.destroy ();245 dialog.destroy ();
@@ -244,10 +247,15 @@
244 }247 }
245 }248 }
246249
247 async void load_wallpapers () {250 async void load_wallpapers (string basefolder, Cancellable cancellable) {
251 if (cancellable.is_cancelled () == true) {
252 return;
253 }
254
248 folder_combo.set_sensitive (false);255 folder_combo.set_sensitive (false);
249256
250 var directory = File.new_for_uri (WALLPAPER_DIR);257 var directory = File.new_for_uri (basefolder);
258
251 // The number of wallpapers we've added so far259 // The number of wallpapers we've added so far
252 double done = 0.0;260 double done = 0.0;
253261
@@ -262,6 +270,9 @@
262 var e = yield directory.enumerate_children_async (FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE + "," + FileAttribute.STANDARD_CONTENT_TYPE, 0, Priority.DEFAULT);270 var e = yield directory.enumerate_children_async (FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE + "," + FileAttribute.STANDARD_CONTENT_TYPE, 0, Priority.DEFAULT);
263271
264 while (true) {272 while (true) {
273 if (cancellable.is_cancelled () == true) {
274 return;
275 }
265 // Grab a batch of 10 wallpapers276 // Grab a batch of 10 wallpapers
266 var files = yield e.next_files_async (10, Priority.DEFAULT);277 var files = yield e.next_files_async (10, Priority.DEFAULT);
267 // Stop the loop if we've run out of wallpapers278 // Stop the loop if we've run out of wallpapers
@@ -270,14 +281,23 @@
270 }281 }
271 // Loop through and add each wallpaper in the batch282 // Loop through and add each wallpaper in the batch
272 foreach (var info in files) {283 foreach (var info in files) {
284 if (cancellable.is_cancelled () == true) {
285 return;
286 }
273 // We're going to add another wallpaper287 // We're going to add another wallpaper
274 done++;288 done++;
275 // Skip the file if it's not a picture289
276 if (!IOHelper.is_valid_file_type(info)) {290 if (info.get_file_type () == FileType.DIRECTORY) {
291 // Spawn off another loader for the subdirectory
292 load_wallpapers (basefolder + "/" + info.get_name (), cancellable);
293 } else if (!IOHelper.is_valid_file_type (info)) {
294 // Skip non-picture files
277 continue;295 continue;
278 }296 }
279 var file = File.new_for_uri (WALLPAPER_DIR + "/" + info.get_name ());297
298 var file = File.new_for_uri (basefolder + "/" + info.get_name ());
280 string filename = file.get_path ();299 string filename = file.get_path ();
300
281 // Skip the default_wallpaper as seen in the description of the301 // Skip the default_wallpaper as seen in the description of the
282 // default_link variable302 // default_link variable
283 if (filename == default_link) {303 if (filename == default_link) {
@@ -373,4 +393,4 @@
373 Gtk.drag_finish (ctx, false, false, timestamp);393 Gtk.drag_finish (ctx, false, false, timestamp);
374 return;394 return;
375 }395 }
376}396}
377\ No newline at end of file397\ No newline at end of file

Subscribers

People subscribed via source and target branches