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