diff --git a/src/Views/Wallpaper.vala b/src/Views/Wallpaper.vala index 09fa32db..43b79678 100644 --- a/src/Views/Wallpaper.vala +++ b/src/Views/Wallpaper.vala @@ -406,30 +406,21 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage { return; } - try { - var info = file.query_info (string.joinv (",", REQUIRED_FILE_ATTRS), 0); - var thumb_path = info.get_attribute_as_string (FileAttribute.THUMBNAIL_PATH); - var thumb_valid = info.get_attribute_boolean (FileAttribute.THUMBNAIL_IS_VALID); - var wallpaper = new WallpaperContainer (uri, thumb_path, thumb_valid); - wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function); - - wallpaper.trash.connect (() => { - send_undo_toast (); - mark_for_removal (wallpaper); - }); - - // Select the wallpaper if it is the current wallpaper - if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") { - this.wallpaper_view.select_child ((Gtk.FlowBoxChild) wallpaper.get_parent ()); - // Set the widget activated without activating it - wallpaper.checked = true; - active_wallpaper = wallpaper; - } - } catch (Error e) { - critical ("Unable to add wallpaper: %s", e.message); - } + var wallpaper = new WallpaperContainer (uri); + wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function); - wallpaper_view.invalidate_sort (); + wallpaper.trash.connect (() => { + send_undo_toast (); + mark_for_removal (wallpaper); + }); + + // Select the wallpaper if it is the current wallpaper + if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") { + this.wallpaper_view.select_child ((Gtk.FlowBoxChild) wallpaper.get_parent ()); + // Set the widget activated without activating it + wallpaper.checked = true; + active_wallpaper = wallpaper; + } } public void cancel_thumbnail_generation () { diff --git a/src/Widgets/WallpaperContainer.vala b/src/Widgets/WallpaperContainer.vala index 90da0452..593295c3 100644 --- a/src/Widgets/WallpaperContainer.vala +++ b/src/Widgets/WallpaperContainer.vala @@ -25,12 +25,11 @@ public class PantheonShell.WallpaperContainer : Granite.Bin { protected const int THUMB_HEIGHT = 144; protected Gtk.Picture image; - private Gtk.Box card_box; private Gtk.Revealer check_revealer; - public string? thumb_path { get; construct set; } - public bool thumb_valid { get; construct; } - public string uri { get; construct; } + private string? thumb_path = null; + + public string? uri { get; construct; default = null; } public uint64 creation_date = 0; public bool checked { @@ -49,8 +48,8 @@ public class PantheonShell.WallpaperContainer : Granite.Bin { } } - public WallpaperContainer (string uri, string? thumb_path, bool thumb_valid) { - Object (uri: uri, thumb_path: thumb_path, thumb_valid: thumb_valid); + public WallpaperContainer (string uri) { + Object (uri: uri); } construct { @@ -95,6 +94,15 @@ public class PantheonShell.WallpaperContainer : Granite.Bin { var file = File.new_for_uri (uri); try { var info = file.query_info ("*", FileQueryInfoFlags.NONE); + + thumb_path = info.get_attribute_as_string (FileAttribute.THUMBNAIL_PATH); + + if (thumb_path != null && info.get_attribute_boolean (FileAttribute.THUMBNAIL_IS_VALID)) { + update_thumb.begin (); + } else { + generate_and_load_thumb (); + } + creation_date = info.get_attribute_uint64 (GLib.FileAttribute.TIME_CREATED); remove_wallpaper_action.set_enabled (info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE)); } catch (Error e) { @@ -124,21 +132,6 @@ public class PantheonShell.WallpaperContainer : Granite.Bin { add_controller (secondary_click_gesture); } - - try { - if (uri != null) { - if (thumb_path != null && thumb_valid) { - update_thumb.begin (); - } else { - generate_and_load_thumb (); - } - } else { - image.set_filename (thumb_path); - } - } catch (Error e) { - critical ("Failed to load wallpaper thumbnail: %s", e.message); - return; - } } private void generate_and_load_thumb () {