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

Subscribers

People subscribed via source and target branches