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
1=== modified file 'src/Wallpaper.vala'
2--- src/Wallpaper.vala 2013-11-24 00:08:31 +0000
3+++ src/Wallpaper.vala 2014-07-31 11:21:57 +0000
4@@ -62,7 +62,6 @@
5 }
6
7 class Wallpaper : EventBox {
8- string WALLPAPER_DIR = "/usr/share/backgrounds";
9
10 GLib.Settings settings;
11
12@@ -74,6 +73,7 @@
13 ComboBoxText folder_combo;
14 ColorButton color;
15 string current_wallpaper_path;
16+ Cancellable last_cancellable;
17
18 Switchboard.Plug plug;
19
20@@ -214,19 +214,23 @@
21 }
22
23 void update_wallpaper_folder () {
24+ if (last_cancellable != null)
25+ last_cancellable.cancel ();
26+
27+ var cancellable = new Cancellable ();
28+ last_cancellable = cancellable;
29 if (folder_combo.get_active () == 0) {
30 clean_wallpapers ();
31- var picture_file = GLib.File.new_for_path (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES));
32- WALLPAPER_DIR = picture_file.get_uri ();
33- load_wallpapers.begin ();
34+ var picture_dir = GLib.File.new_for_path (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES));
35+ load_wallpapers (picture_dir.get_uri (), cancellable);
36 } else if (folder_combo.get_active () == 1) {
37 clean_wallpapers ();
38- WALLPAPER_DIR = "file:///usr/share/backgrounds";
39- load_wallpapers.begin (() => {
40- var backgrounds_file = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds");
41- WALLPAPER_DIR = backgrounds_file.get_uri ();
42- load_wallpapers.begin ();
43- });
44+
45+ var system_uri = "file:///usr/share/backgrounds";
46+ var user_uri = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds").get_uri ();
47+
48+ load_wallpapers (system_uri, cancellable);
49+ load_wallpapers (user_uri, cancellable);
50 } else if (folder_combo.get_active () == 2) {
51 var dialog = new Gtk.FileChooserDialog (_("Select a folder"), null, FileChooserAction.SELECT_FOLDER);
52 dialog.add_button (_("Cancel"), ResponseType.CANCEL);
53@@ -235,8 +239,7 @@
54
55 if (dialog.run () == ResponseType.ACCEPT) {
56 clean_wallpapers ();
57- WALLPAPER_DIR = dialog.get_file ().get_uri ();
58- load_wallpapers.begin ();
59+ load_wallpapers (dialog.get_file ().get_uri (), cancellable);
60 dialog.destroy ();
61 } else {
62 dialog.destroy ();
63@@ -244,10 +247,15 @@
64 }
65 }
66
67- async void load_wallpapers () {
68+ async void load_wallpapers (string basefolder, Cancellable cancellable) {
69+ if (cancellable.is_cancelled () == true) {
70+ return;
71+ }
72+
73 folder_combo.set_sensitive (false);
74
75- var directory = File.new_for_uri (WALLPAPER_DIR);
76+ var directory = File.new_for_uri (basefolder);
77+
78 // The number of wallpapers we've added so far
79 double done = 0.0;
80
81@@ -262,6 +270,9 @@
82 var e = yield directory.enumerate_children_async (FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE + "," + FileAttribute.STANDARD_CONTENT_TYPE, 0, Priority.DEFAULT);
83
84 while (true) {
85+ if (cancellable.is_cancelled () == true) {
86+ return;
87+ }
88 // Grab a batch of 10 wallpapers
89 var files = yield e.next_files_async (10, Priority.DEFAULT);
90 // Stop the loop if we've run out of wallpapers
91@@ -270,14 +281,23 @@
92 }
93 // Loop through and add each wallpaper in the batch
94 foreach (var info in files) {
95+ if (cancellable.is_cancelled () == true) {
96+ return;
97+ }
98 // We're going to add another wallpaper
99 done++;
100- // Skip the file if it's not a picture
101- if (!IOHelper.is_valid_file_type(info)) {
102+
103+ if (info.get_file_type () == FileType.DIRECTORY) {
104+ // Spawn off another loader for the subdirectory
105+ load_wallpapers (basefolder + "/" + info.get_name (), cancellable);
106+ } else if (!IOHelper.is_valid_file_type (info)) {
107+ // Skip non-picture files
108 continue;
109 }
110- var file = File.new_for_uri (WALLPAPER_DIR + "/" + info.get_name ());
111+
112+ var file = File.new_for_uri (basefolder + "/" + info.get_name ());
113 string filename = file.get_path ();
114+
115 // Skip the default_wallpaper as seen in the description of the
116 // default_link variable
117 if (filename == default_link) {
118@@ -373,4 +393,4 @@
119 Gtk.drag_finish (ctx, false, false, timestamp);
120 return;
121 }
122-}
123+}
124\ No newline at end of file

Subscribers

People subscribed via source and target branches