Merge lp:~elementary-pantheon/switchboard-plug-pantheon-shell/fix-1102623 into lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk

Proposed by Danielle Foré
Status: Rejected
Rejected by: Cody Garver
Proposed branch: lp:~elementary-pantheon/switchboard-plug-pantheon-shell/fix-1102623
Merge into: lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk
Diff against target: 415 lines (+164/-113)
3 files modified
CMakeLists.txt (+5/-1)
data/schema/org.pantheon.switchboard.plug.shell.gschema.xml (+15/-0)
src/Wallpaper.vala (+144/-112)
To merge this branch: bzr merge lp:~elementary-pantheon/switchboard-plug-pantheon-shell/fix-1102623
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Review via email: mp+245403@code.launchpad.net

Commit message

Saves the selected picture source (and the most recent 'custom' path) fixes lp:1102623

Description of the change

This is a manual merge of KJ's old branch into trunk. Everything appears to work

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Actually it looks like it still needs fixing. It merges cleanly now, but this would revert the view from a flowbox :p

review: Needs Fixing

Unmerged revisions

300. By Danielle Foré

merge kj's old branch into trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-12-21 18:38:47 +0000
+++ CMakeLists.txt 2014-12-27 22:12:25 +0000
@@ -48,6 +48,10 @@
48include (CPack)48include (CPack)
49add_custom_target (dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)49add_custom_target (dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
5050
51
52include(GSettings)
53add_schema("data/schema/org.pantheon.switchboard.plug.shell.gschema.xml")
54
51# Files55# Files
52file (GLOB resources "${CMAKE_CURRENT_SOURCE_DIR}/data/*.png")56file (GLOB resources "${CMAKE_CURRENT_SOURCE_DIR}/data/*.png")
5357
@@ -58,4 +62,4 @@
58# Info-plug62# Info-plug
59install (FILES ${resources} DESTINATION ${PKGDATADIR})63install (FILES ${resources} DESTINATION ${PKGDATADIR})
6064
61add_subdirectory(src)65add_subdirectory(src)
62\ No newline at end of file66\ No newline at end of file
6367
=== added directory 'data/schema'
=== added file 'data/schema/org.pantheon.switchboard.plug.shell.gschema.xml'
--- data/schema/org.pantheon.switchboard.plug.shell.gschema.xml 1970-01-01 00:00:00 +0000
+++ data/schema/org.pantheon.switchboard.plug.shell.gschema.xml 2014-12-27 22:12:25 +0000
@@ -0,0 +1,15 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<schemalist>
3 <schema path="/org/pantheon/switchboard/plug/shell/" id="org.pantheon.switchboard.plug.shell" gettext-domain="switchboard">
4 <key name="custom-wallpaper-path" type="s">
5 <default>""</default>
6 <summary>Saves the custom background images path.</summary>
7 <description>Saves the custom background images path.</description>
8 </key>
9 <key name="selected-wallpaper-path" type="s">
10 <default>""</default>
11 <summary>Saves the selected background path item.</summary>
12 <description>Saves the selected background path item.</description>
13 </key>
14 </schema>
15</schemalist>
0\ No newline at end of file16\ No newline at end of file
117
=== modified file 'src/Wallpaper.vala'
--- src/Wallpaper.vala 2014-11-16 12:33:17 +0000
+++ src/Wallpaper.vala 2014-12-27 22:12:25 +0000
@@ -63,31 +63,19 @@
6363
64class Wallpaper : EventBox {64class Wallpaper : EventBox {
6565
66 class WallpaperContainer : Gtk.FlowBoxChild {
67 public string uri { get; construct; }
68
69 Gtk.Image image;
70
71 public WallpaperContainer (string uri) {
72 Object (uri: uri);
73
74 try {
75 image = new Gtk.Image.from_pixbuf (new Gdk.Pixbuf.from_file_at_scale (GLib.Filename.from_uri (uri), 150, 100, false));
76 add (image);
77 } catch (Error e) {
78 warning ("Failed to load wallpaper thumbnail: %s", e.message);
79 }
80 }
81 }
82
83 GLib.Settings settings;66 GLib.Settings settings;
67 GLib.Settings plug_settings;
8468
85 Gtk.FlowBox wallpaper_view;69 ListStore store;
70 GLib.List <TreeIter?> iters = new GLib.List <TreeIter?> ();
71 Gtk.TreeIter selected_plug;
72 IconView wallpaper_view;
86 ComboBoxText combo;73 ComboBoxText combo;
87 ComboBoxText folder_combo;74 ComboBoxText folder_combo;
88 ColorButton color;75 ColorButton color;
89 string current_wallpaper_path;76 string current_wallpaper_path;
90 Cancellable last_cancellable;77 string custom_wallpaper_path;
78 string selected_wallpaper_path;
9179
92 Switchboard.Plug plug;80 Switchboard.Plug plug;
9381
@@ -102,16 +90,36 @@
102 plug = _plug;90 plug = _plug;
10391
104 settings = new GLib.Settings ("org.gnome.desktop.background");92 settings = new GLib.Settings ("org.gnome.desktop.background");
93 plug_settings = new GLib.Settings ("org.pantheon.switchboard.plug.shell");
94
95 store = new Gtk.ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
10596
106 var vbox = new Box (Orientation.VERTICAL, 4);97 var vbox = new Box (Orientation.VERTICAL, 4);
10798
108 wallpaper_view = new Gtk.FlowBox ();99 string icon_style = """
109 wallpaper_view.activate_on_single_click = true;100 .wallpaper-view {
110 wallpaper_view.column_spacing = wallpaper_view.row_spacing = 6;101 background-color: @background_color;
111 wallpaper_view.margin = 12;102 }
112 wallpaper_view.homogeneous = true;103 .wallpaper-view:selected {
113 wallpaper_view.selection_mode = Gtk.SelectionMode.SINGLE;104 background-color: shade (#DEDEDE, 0.80);
114 wallpaper_view.child_activated.connect (update_wallpaper);105 color: #323232;
106 }
107 """;
108 var icon_view_style = new Gtk.CssProvider ();
109
110 try {
111 icon_view_style.load_from_data (icon_style, -1);
112 } catch (Error e) {
113 warning (e.message);
114 }
115
116 wallpaper_view = new IconView ();
117 wallpaper_view.set_selection_mode (Gtk.SelectionMode.SINGLE);
118 wallpaper_view.set_pixbuf_column (0);
119 wallpaper_view.set_model (this.store);
120 wallpaper_view.selection_changed.connect (update_wallpaper);
121 wallpaper_view.get_style_context ().add_class ("wallpaper-view");
122 wallpaper_view.get_style_context ().add_provider (icon_view_style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
115123
116 TargetEntry e = {"text/uri-list", 0, 0};124 TargetEntry e = {"text/uri-list", 0, 0};
117 wallpaper_view.drag_data_received.connect (on_drag_data_received);125 wallpaper_view.drag_data_received.connect (on_drag_data_received);
@@ -123,11 +131,7 @@
123 vbox.pack_start (scrolled, true, true, 5);131 vbox.pack_start (scrolled, true, true, 5);
124132
125 folder_combo = new ComboBoxText ();133 folder_combo = new ComboBoxText ();
126 folder_combo.append ("pic", _("Pictures"));
127 folder_combo.append ("sys", _("Backgrounds"));
128 folder_combo.append ("cus", _("Custom…"));
129 folder_combo.changed.connect (update_wallpaper_folder);134 folder_combo.changed.connect (update_wallpaper_folder);
130 folder_combo.set_active (1);
131135
132 combo = new ComboBoxText ();136 combo = new ComboBoxText ();
133 combo.append ("none", _("Solid Color"));137 combo.append ("none", _("Solid Color"));
@@ -142,6 +146,7 @@
142 color.color_set.connect (update_color);146 color.color_set.connect (update_color);
143147
144 load_settings ();148 load_settings ();
149 build_paths_menu (selected_wallpaper_path);
145150
146 var hbox = new Box (Orientation.HORIZONTAL, 0);151 var hbox = new Box (Orientation.HORIZONTAL, 0);
147152
@@ -181,12 +186,37 @@
181 color.set_color (c);186 color.set_color (c);
182187
183 current_wallpaper_path = settings.get_string ("picture-uri");188 current_wallpaper_path = settings.get_string ("picture-uri");
184 }189 custom_wallpaper_path = plug_settings.get_string ("custom-wallpaper-path");
185190 selected_wallpaper_path = plug_settings.get_string ("selected-wallpaper-path");
186 void update_wallpaper (Gtk.FlowBox box, Gtk.FlowBoxChild child) {191 }
187 var selected = (WallpaperContainer) wallpaper_view.get_selected_children ().data;192
188 current_wallpaper_path = selected.uri;193 void build_paths_menu (string select_item = "") {
189 settings.set_string ("picture-uri", current_wallpaper_path);194 folder_combo.remove_all ();
195 folder_combo.append ("pic", _("Pictures"));
196 folder_combo.append ("sys", _("Backgrounds"));
197
198 if (custom_wallpaper_path.length > 0) {
199 var saved_file = GLib.File.new_for_path (custom_wallpaper_path);
200 folder_combo.append ("save", saved_file.get_basename ());
201 }
202
203 folder_combo.append ("cus", _("Custom…"));
204 folder_combo.set_active_id ((select_item.length > 0) ? select_item : "sys");
205 }
206
207 void update_wallpaper () {
208 var selected = wallpaper_view.get_selected_items ();
209 if (selected.length() == 1) {
210 GLib.Value filename;
211 // Get the filename of the selected wallpaper.
212 var item = selected.nth_data(0);
213 this.store.get_iter(out this.selected_plug, item);
214 this.store.get_value(this.selected_plug, 1, out filename);
215
216 current_wallpaper_path = filename.get_string();
217
218 settings.set_string ("picture-uri", filename.get_string ());
219 }
190 }220 }
191221
192 void update_color () {222 void update_color () {
@@ -200,47 +230,50 @@
200 }230 }
201231
202 void update_wallpaper_folder () {232 void update_wallpaper_folder () {
203 if (last_cancellable != null)233 switch (folder_combo.active_id) {
204 last_cancellable.cancel ();234 case "pic":
205235 var picture_file = GLib.File.new_for_path (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES));
206 var cancellable = new Cancellable ();236 load_wallpapers.begin (picture_file.get_uri ());
207 last_cancellable = cancellable;237 break;
208 if (folder_combo.get_active () == 0) {238 case "sys":
209 clean_wallpapers ();239 load_wallpapers.begin ("file:///usr/share/backgrounds", true, () => {
210 var picture_dir = GLib.File.new_for_path (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES));240 var backgrounds_file = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds");
211 load_wallpapers (picture_dir.get_uri (), cancellable);241 load_wallpapers.begin (backgrounds_file.get_uri (), false);
212 } else if (folder_combo.get_active () == 1) {242 });
213 clean_wallpapers ();243 break;
214244 case "save":
215 var system_uri = "file:///usr/share/backgrounds";245 var saved_file = GLib.File.new_for_uri (custom_wallpaper_path);
216 var user_uri = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds").get_uri ();246 load_wallpapers.begin (saved_file.get_uri ());
217247 break;
218 load_wallpapers (system_uri, cancellable);248 case "cus":
219 load_wallpapers (user_uri, cancellable);249 var dialog = new Gtk.FileChooserDialog (_("Select a folder"), null, FileChooserAction.SELECT_FOLDER);
220 } else if (folder_combo.get_active () == 2) {250 dialog.add_button (_("Cancel"), ResponseType.CANCEL);
221 var dialog = new Gtk.FileChooserDialog (_("Select a folder"), null, FileChooserAction.SELECT_FOLDER);251 dialog.add_button (_("Open"), ResponseType.ACCEPT);
222 dialog.add_button (_("Cancel"), ResponseType.CANCEL);252 dialog.set_default_response (ResponseType.ACCEPT);
223 dialog.add_button (_("Open"), ResponseType.ACCEPT);253
224 dialog.set_default_response (ResponseType.ACCEPT);254 if (dialog.run () == ResponseType.ACCEPT) {
225255 custom_wallpaper_path = dialog.get_file ().get_uri ();
226 if (dialog.run () == ResponseType.ACCEPT) {256 plug_settings.set_string ("custom-wallpaper-path", custom_wallpaper_path);
227 clean_wallpapers ();257 build_paths_menu ("save");
228 load_wallpapers (dialog.get_file ().get_uri (), cancellable);258 load_wallpapers.begin (custom_wallpaper_path);
229 dialog.destroy ();259 } else {
230 } else {260 build_paths_menu (selected_wallpaper_path);
231 dialog.destroy ();261 }
232 }262
263 dialog.destroy ();
264 break;
233 }265 }
266
267 plug_settings.set_string ("selected-wallpaper-path", (folder_combo.active_id == "cus") ? "save" : folder_combo.active_id);
234 }268 }
235269
236 async void load_wallpapers (string basefolder, Cancellable cancellable) {270 async void load_wallpapers (string path, bool clear_wallpapers = true) {
237 if (cancellable.is_cancelled () == true) {271 if (clear_wallpapers)
238 return;272 clean_wallpapers ();
239 }
240273
241 folder_combo.set_sensitive (false);274 folder_combo.set_sensitive (false);
242275
243 var directory = File.new_for_uri (basefolder);276 var directory = File.new_for_uri (path);
244277
245 // The number of wallpapers we've added so far278 // The number of wallpapers we've added so far
246 double done = 0.0;279 double done = 0.0;
@@ -256,9 +289,6 @@
256 var e = yield directory.enumerate_children_async (FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE + "," + FileAttribute.STANDARD_CONTENT_TYPE, 0, Priority.DEFAULT);289 var e = yield directory.enumerate_children_async (FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE + "," + FileAttribute.STANDARD_CONTENT_TYPE, 0, Priority.DEFAULT);
257290
258 while (true) {291 while (true) {
259 if (cancellable.is_cancelled () == true) {
260 return;
261 }
262 // Grab a batch of 10 wallpapers292 // Grab a batch of 10 wallpapers
263 var files = yield e.next_files_async (10, Priority.DEFAULT);293 var files = yield e.next_files_async (10, Priority.DEFAULT);
264 // Stop the loop if we've run out of wallpapers294 // Stop the loop if we've run out of wallpapers
@@ -267,40 +297,35 @@
267 }297 }
268 // Loop through and add each wallpaper in the batch298 // Loop through and add each wallpaper in the batch
269 foreach (var info in files) {299 foreach (var info in files) {
270 if (cancellable.is_cancelled () == true) {
271 return;
272 }
273 // We're going to add another wallpaper300 // We're going to add another wallpaper
274 done++;301 done++;
275302 // Skip the file if it's not a picture
276 if (info.get_file_type () == FileType.DIRECTORY) {303 if (!IOHelper.is_valid_file_type(info)) {
277 // Spawn off another loader for the subdirectory
278 load_wallpapers (basefolder + "/" + info.get_name (), cancellable);
279 continue;
280 } else if (!IOHelper.is_valid_file_type (info)) {
281 // Skip non-picture files
282 continue;304 continue;
283 }305 }
284306 var file = File.new_for_uri (directory.get_uri () + "/" + info.get_name ());
285 var file = File.new_for_uri (basefolder + "/" + info.get_name ());307 string filename = file.get_path ();
286 string uri = file.get_uri ();
287
288 // Skip the default_wallpaper as seen in the description of the308 // Skip the default_wallpaper as seen in the description of the
289 // default_link variable309 // default_link variable
290 if (uri == default_link) {310 if (filename == default_link) {
291 continue;311 continue;
292 }312 }
293313
294 try {314 try {
295 var wallpaper = new WallpaperContainer (uri);315 // Create a thumbnail of the image and load it into the IconView
296 wallpaper_view.add (wallpaper);316 var image = new Gdk.Pixbuf.from_file_at_scale(filename, 150, 100, false);
297 wallpaper.show_all ();317 // Add the wallpaper name and thumbnail to the IconView
318 Gtk.TreeIter root;
319 this.store.append(out root);
320 this.store.set(root, 0, image, -1);
321 this.store.set(root, 1, filename, -1);
298322
299 // Select the wallpaper if it is the current wallpaper323 // Select the wallpaper if it is the current wallpaper
300 if (current_wallpaper_path.has_suffix (uri)) {324 if (current_wallpaper_path.has_suffix (filename)) {
301 this.wallpaper_view.select_child (wallpaper);325 this.wallpaper_view.select_path (this.store.get_path (root));
302 }326 }
303327
328 this.iters.append (root);
304 // Have GTK update the UI even while we're busy329 // Have GTK update the UI even while we're busy
305 // working on file IO.330 // working on file IO.
306 while(Gtk.events_pending ()) {331 while(Gtk.events_pending ()) {
@@ -322,20 +347,12 @@
322 }347 }
323348
324 void clean_wallpapers () {349 void clean_wallpapers () {
325 foreach (var child in wallpaper_view.get_children ())350 store.clear ();
326 child.destroy ();
327 }351 }
328352
329 void on_drag_data_received (Widget widget, Gdk.DragContext ctx, int x, int y, SelectionData sel, uint information, uint timestamp) {353 void on_drag_data_received (Widget widget, Gdk.DragContext ctx, int x, int y, SelectionData sel, uint information, uint timestamp) {
330 if (sel.get_length () > 0) {354 if (sel.get_length () > 0) {
331 File file = File.new_for_uri (sel.get_uris ()[0]);355 File file = File.new_for_uri (sel.get_uris ()[0]);
332 var info = file.query_info (FileAttribute.STANDARD_TYPE + "," + FileAttribute.STANDARD_CONTENT_TYPE, 0);
333
334 if (!IOHelper.is_valid_file_type (info)) {
335 Gtk.drag_finish (ctx, false, false, timestamp);
336 return;
337 }
338
339356
340 string display_name = Filename.display_basename (file.get_path ());357 string display_name = Filename.display_basename (file.get_path ());
341358
@@ -345,22 +362,37 @@
345 try {362 try {
346 dest_folder.make_directory ();363 dest_folder.make_directory ();
347 } catch (Error e) {364 } catch (Error e) {
348 warning ("Creating local wallpaper directory failed: %s", e.message);365 warning (e.message);
349 }366 }
350 }367 }
351368
352 try {369 try {
353 file.copy (dest, 0);370 file.copy (dest, 0);
354 } catch (Error e) {371 } catch (Error e) {
355 warning ("Copying wallpaper to local directory failed: %s", e.message);372 warning (e.message);
356 }373 }
357374
358 string uri = dest.get_uri ();375 string filename = dest.get_uri ();
359376
377 string extension = display_name.split (".")[display_name.split (".").length - 1];
378
379 if (extension != "jpg" && extension != "png" && extension != "jpeg" && extension != "gif") {
380 Gtk.drag_finish (ctx, false, false, timestamp);
381 return;
382 }
383
384 // Create a thumbnail of the image and load it into the IconView
385 Gdk.Pixbuf image = null;
386 try {
387 image = new Gdk.Pixbuf.from_file_at_scale(filename, 180, 120, false);
388 } catch (Error e) {
389 warning (e.message);
390 }
360 // Add the wallpaper name and thumbnail to the IconView391 // Add the wallpaper name and thumbnail to the IconView
361 var wallpaper = new WallpaperContainer (uri);392 Gtk.TreeIter root;
362 wallpaper_view.add (wallpaper);393 this.store.append(out root);
363 wallpaper.show_all ();394 this.store.set(root, 0, image, -1);
395 this.store.set(root, 1, filename, -1);
364396
365 Gtk.drag_finish (ctx, true, false, timestamp);397 Gtk.drag_finish (ctx, true, false, timestamp);
366 return;398 return;

Subscribers

People subscribed via source and target branches