From 84d661d37814eb4039c4edafedb869e2b47bda95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 14 Jan 2026 10:48:29 -0800 Subject: [PATCH] Wallpaper: DRY add_wallpaper_from_file --- src/IOHelper.vala | 5 +++-- src/Views/Wallpaper.vala | 42 +++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/IOHelper.vala b/src/IOHelper.vala index 6c33e4887..abe614cae 100644 --- a/src/IOHelper.vala +++ b/src/IOHelper.vala @@ -17,11 +17,12 @@ */ public class PantheonShell.IOHelper : GLib.Object { private const string[] ACCEPTED_TYPES = { + "image/gif", + "image/heic", "image/jpeg", "image/png", - "image/tiff", "image/svg+xml", - "image/gif" + "image/tiff" }; // Check if the filename has a picture file extension. diff --git a/src/Views/Wallpaper.vala b/src/Views/Wallpaper.vala index 09fa32db2..400bd2a3c 100644 --- a/src/Views/Wallpaper.vala +++ b/src/Views/Wallpaper.vala @@ -157,13 +157,7 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage { continue; } - var local_uri = file.get_uri (); - var dest = WallpaperOperation.copy_for_library (file); - if (dest != null) { - local_uri = dest.get_uri (); - } - - add_wallpaper_from_file (file, local_uri); + add_wallpaper_from_file (file); } } }); @@ -329,15 +323,10 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage { var subdir = directory.resolve_relative_path (file_info.get_name ()); yield load_wallpapers (subdir.get_path (), cancellable, false); continue; - } else if (!IOHelper.is_valid_file_type (file_info)) { - // Skip non-picture files - continue; } var file = directory.resolve_relative_path (file_info.get_name ()); - string uri = file.get_uri (); - - add_wallpaper_from_file (file, uri); + add_wallpaper_from_file (file); } if (toplevel_folder) { @@ -387,20 +376,15 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage { private bool on_drag_data_received (Value val, double x, double y) { var file_list = (Gdk.FileList) val; foreach (var file in file_list.get_files ()) { - var local_uri = file.get_uri (); - - var dest = WallpaperOperation.copy_for_library (file); - if (dest != null) { - local_uri = dest.get_uri (); - } - - add_wallpaper_from_file (file, local_uri); + add_wallpaper_from_file (file); } return true; } - private void add_wallpaper_from_file (GLib.File file, string uri) { + private void add_wallpaper_from_file (GLib.File file) { + var uri = file.get_uri (); + // don't load 'removed' wallpaper on plug reload if (wallpaper_for_removal != null && wallpaper_for_removal.uri == uri) { return; @@ -408,9 +392,23 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage { try { var info = file.query_info (string.joinv (",", REQUIRED_FILE_ATTRS), 0); + + if (!IOHelper.is_valid_file_type (info)) { + Gdk.Display.get_default ().beep (); + return; + } + + if (!WallpaperOperation.get_is_file_in_bg_dir (file)) { + var local_file = WallpaperOperation.copy_for_library (file); + if (local_file != null) { + uri = local_file.get_uri (); + } + } + 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 (() => {